Skip to content

Commit

Permalink
add cpu flags to config
Browse files Browse the repository at this point in the history
  • Loading branch information
ssd04 committed Jan 22, 2024
1 parent da2544a commit 685b847
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
3 changes: 3 additions & 0 deletions cmd/node/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
# Make sure that this is greater than the unbonding period!
SetGuardianEpochsDelay = 2 # TODO: for mainnet should be 20, 2 is just for testing

[HardwareRequirements]
CPUFlags = ["sse4_1", "sse4_2"]

[Versions]
DefaultVersion = "default"
VersionsByEpochs = [
Expand Down
28 changes: 25 additions & 3 deletions cmd/node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func startNodeRunner(c *cli.Context, log logger.Logger, baseVersion string, vers
cfgs.FlagsConfig.BaseVersion = baseVersion
cfgs.FlagsConfig.Version = version

err = checkHardwareRequirements()
err = checkHardwareRequirements(cfgs.GeneralConfig.HardwareRequirements)
if err != nil {
return fmt.Errorf("Hardware Requirements checks failed: %s", err.Error())
}
Expand Down Expand Up @@ -308,10 +308,32 @@ func attachFileLogger(log logger.Logger, flagsConfig *config.ContextFlagsConfig)
return fileLogging, nil
}

func checkHardwareRequirements() error {
if !cpuid.CPU.Supports(cpuid.SSE4, cpuid.SSE42) {
func checkHardwareRequirements(cfg config.HardwareRequirementsConfig) error {
cpuFlags, err := parseFeatures(cfg.CPUFlags)
if err != nil {
return err
}

if !cpuid.CPU.Supports(cpuFlags...) {
return fmt.Errorf("CPU Flags: Streaming SIMD Extensions 4 required")
}

return nil
}

func parseFeatures(features []string) ([]cpuid.FeatureID, error) {
flags := make([]cpuid.FeatureID, 0)

for _, cpuFlag := range features {
switch cpuFlag {
case "sse4_1":
flags = append(flags, cpuid.SSE4)
case "sse4_2":
flags = append(flags, cpuid.SSE42)
default:
return nil, fmt.Errorf("CPU Flags: cpu flag %s not found", cpuFlag)
}
}

return flags, nil
}
24 changes: 15 additions & 9 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,16 @@ type Config struct {
PublicKeyPIDSignature CacheConfig
PeerHonesty CacheConfig

Antiflood AntifloodConfig
WebServerAntiflood WebServerAntifloodConfig
ResourceStats ResourceStatsConfig
HeartbeatV2 HeartbeatV2Config
ValidatorStatistics ValidatorStatisticsConfig
GeneralSettings GeneralSettingsConfig
Consensus ConsensusConfig
StoragePruning StoragePruningConfig
LogsAndEvents LogsAndEventsConfig
Antiflood AntifloodConfig
WebServerAntiflood WebServerAntifloodConfig
ResourceStats ResourceStatsConfig
HeartbeatV2 HeartbeatV2Config
ValidatorStatistics ValidatorStatisticsConfig
GeneralSettings GeneralSettingsConfig
Consensus ConsensusConfig
StoragePruning StoragePruningConfig
LogsAndEvents LogsAndEventsConfig
HardwareRequirements HardwareRequirementsConfig

NTPConfig NTPConfig
HeadersPoolConfig HeadersPoolConfig
Expand Down Expand Up @@ -285,6 +286,11 @@ type GeneralSettingsConfig struct {
SetGuardianEpochsDelay uint32
}

// HardwareRequirementsConfig will hold the hardware requirements config
type HardwareRequirementsConfig struct {
CPUFlags []string
}

// FacadeConfig will hold different configuration option that will be passed to the node facade
type FacadeConfig struct {
RestApiInterface string
Expand Down

0 comments on commit 685b847

Please sign in to comment.