Skip to content

Commit

Permalink
use cpuid implementation for cpu flags check
Browse files Browse the repository at this point in the history
  • Loading branch information
ssd04 committed Jan 19, 2024
1 parent 639da41 commit 0db2dc0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 37 deletions.
3 changes: 0 additions & 3 deletions cmd/node/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@
# 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
24 changes: 5 additions & 19 deletions cmd/node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"runtime"
"time"

"github.com/klauspost/cpuid/v2"
"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/core/check"
"github.com/multiversx/mx-chain-go/cmd/node/factory"
"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/common/hostParameters"
"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/config/overridableConfig"
"github.com/multiversx/mx-chain-go/node"
Expand Down 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(cfgs.GeneralConfig.HardwareRequirements)
err = checkHardwareRequirements()
if err != nil {
return fmt.Errorf("Hardware Requirements checks failed: %s", err.Error())
}
Expand Down Expand Up @@ -308,24 +308,10 @@ func attachFileLogger(log logger.Logger, flagsConfig *config.ContextFlagsConfig)
return fileLogging, nil
}

func checkHardwareRequirements(cfg config.HardwareRequirementsConfig) error {
hpg := hostParameters.NewHostParameterGetter("")
hostInfo := hpg.GetHostInfo()

for _, cpuFlag := range cfg.CPUFlags {
if !contains(hostInfo.CPUFlags, cpuFlag) {
return fmt.Errorf("CPU Flag %s not available", cpuFlag)
}
func checkHardwareRequirements() error {
if !cpuid.CPU.Supports(cpuid.SSE4, cpuid.SSE42) {
return fmt.Errorf("CPU Flags: Streaming SIMD Extensions 4 requied")
}

return nil
}

func contains(list []string, s string) bool {
for _, item := range list {
if item == s {
return true
}
}
return false
}
24 changes: 9 additions & 15 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,15 @@ 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
HardwareRequirements HardwareRequirementsConfig
Antiflood AntifloodConfig
WebServerAntiflood WebServerAntifloodConfig
ResourceStats ResourceStatsConfig
HeartbeatV2 HeartbeatV2Config
ValidatorStatistics ValidatorStatisticsConfig
GeneralSettings GeneralSettingsConfig
Consensus ConsensusConfig
StoragePruning StoragePruningConfig
LogsAndEvents LogsAndEventsConfig

NTPConfig NTPConfig
HeadersPoolConfig HeadersPoolConfig
Expand Down Expand Up @@ -286,11 +285,6 @@ 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 0db2dc0

Please sign in to comment.