-
Notifications
You must be signed in to change notification settings - Fork 482
chore: add CPU features check during install and start of celestia-appd #5969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
rach-id
wants to merge
14
commits into
celestiaorg:main
Choose a base branch
from
rach-id:rachid/chore/cpu-features-check
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+162
−1
Draft
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
613bf70
chore: check for gfni and sha_ni during install and start
rach-id 04ca5f4
chore: add note
rach-id 319f364
Apply suggestion from @rach-id
rach-id 2d943f8
chore: golangci
rach-id c0fe944
Update cmd/celestia-appd/cmd/cpu_features.go
rach-id 03c44f2
Update cmd/celestia-appd/cmd/cpu_features.go
rach-id 8d3058c
Update cmd/celestia-appd/cmd/cpu_features.go
rach-id e1c9966
Update scripts/check_cpu_features.sh
rach-id 0d4fc23
Update scripts/check_cpu_features.sh
rach-id 81c1a2c
chore: rename to --force-no-cpu-features
rach-id f6e9b5a
Merge remote-tracking branch 'origin/rachid/chore/cpu-features-check'…
rach-id d5f1f17
chore: rename to --force-no-cpu-features
rach-id b3293bf
chore: rename to --force-no-cpu-features
rach-id c708c50
Merge branch 'main' into rachid/chore/cpu-features-check
rach-id File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "os" | ||
| "runtime" | ||
| "strings" | ||
|
|
||
| "cosmossdk.io/log" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| const FlagTestingEnvironment = "testing-environment" | ||
|
|
||
| // checkCPUFeatures checks if CPU supports GFNI and SHA_NI extensions. | ||
| func checkCPUFeatures(command *cobra.Command, logger log.Logger) error { | ||
| const ( | ||
| warning = ` | ||
| CPU Performance Warning: Missing hardware acceleration features | ||
|
|
||
| Your CPU does not support one or more of the following hardware acceleration features: | ||
| - GFNI (Galois Field New Instructions) | ||
| - SHA_NI (Secure Hash Algorithm New Instructions) | ||
|
|
||
| These features significantly improve cryptographic performance for blockchain operations. | ||
|
|
||
| Note: These features are not required for the 32MB/6s block configuration but will become | ||
| essential when the network transitions to 128MB/6s blocks. Validators should prepare by upgrading | ||
| their hardware to ensure optimal performance during future network upgrades. | ||
|
|
||
| To check what features your CPU supports: | ||
| grep -o -E 'sha_ni|gfni' /proc/cpuinfo | ||
|
|
||
| Modern Intel CPUs (10th gen+) and AMD CPUs (Zen 4+) typically support these features. | ||
| If you are running this node, consider upgrading to a CPU with these features. | ||
|
|
||
| This node will continue to run, but may experience reduced performance for cryptographic operations. | ||
| If you need to bypass this check, use the --testing-environment flag. | ||
| ` | ||
| ) | ||
|
|
||
| testingEnvironment, err := command.Flags().GetBool(FlagTestingEnvironment) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if testingEnvironment { | ||
| return nil | ||
| } | ||
|
|
||
| // Only check on Linux where /proc/cpuinfo is available | ||
| if runtime.GOOS != "linux" { | ||
| // Skip check silently for non-Linux OSes (e.g., macOS, Windows, BSD) | ||
| return nil | ||
| } | ||
|
|
||
| file, err := os.ReadFile("/proc/cpuinfo") | ||
| if err != nil { | ||
| logger.Warn(warning) | ||
| // TODO: enable when we want to start enforcing the new CPU features. | ||
| // return fmt.Errorf("failed to read file '/proc/cpuinfo' %w", err) | ||
| return nil | ||
| } | ||
|
|
||
| cpuInfo := string(file) | ||
| hasGFNI := strings.Contains(cpuInfo, "gfni") | ||
| hasSHANI := strings.Contains(cpuInfo, "sha_ni") | ||
|
|
||
| if !hasGFNI || !hasSHANI { | ||
| missingFeatures := []string{} | ||
| if !hasGFNI { | ||
| missingFeatures = append(missingFeatures, "GFNI") | ||
| } | ||
| if !hasSHANI { | ||
| missingFeatures = append(missingFeatures, "SHA_NI") | ||
| } | ||
| logger.Warn(warning, "missing_features", strings.Join(missingFeatures, ", ")) | ||
| } | ||
|
|
||
| if !hasGFNI { | ||
| // TODO: enable when we want to start enforcing the new CPU features. | ||
| // return fmt.Errorf("missing GFNI") | ||
| return nil | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Script to check CPU features for celestia-app | ||
| # Checks for GFNI and SHA_NI CPU features that improve cryptographic performance | ||
|
|
||
| check_cpu_features() { | ||
| local warning=" | ||
| CPU Performance Warning: Missing hardware acceleration features | ||
|
|
||
| Your CPU does not support one or more of the following hardware acceleration features: | ||
| - GFNI (Galois Field New Instructions) | ||
| - SHA_NI (Secure Hash Algorithm New Instructions) | ||
|
|
||
| These features significantly improve cryptographic performance for blockchain operations. | ||
|
|
||
| Note: These features are not required for the 32MB/6s block configuration but will become | ||
| essential when the network transitions to 128MB/6s blocks. Validators should prepare by upgrading | ||
| their hardware to ensure optimal performance during future network upgrades. | ||
|
|
||
| To check what features your CPU supports: | ||
| grep -o -E 'sha_ni|gfni' /proc/cpuinfo | ||
|
|
||
| Modern Intel CPUs (10th gen+) and AMD CPUs (Zen 3+) typically support these features. | ||
| If you are running this node in production, consider upgrading to a CPU with these features. | ||
|
|
||
| This node will continue to run, but may experience reduced performance for cryptographic operations. | ||
| " | ||
|
|
||
| # Only check on Linux where /proc/cpuinfo is available | ||
| if [[ "$OSTYPE" != "linux-gnu"* ]]; then | ||
| # Skip check silently for non-Linux OSes (e.g., macOS, Windows, BSD) | ||
| return 0 | ||
| fi | ||
|
|
||
| # Check if /proc/cpuinfo exists and is readable | ||
| if [[ ! -f /proc/cpuinfo ]] || [[ ! -r /proc/cpuinfo ]]; then | ||
| echo "Warning: Could not read /proc/cpuinfo to check CPU features" | ||
| return 0 | ||
| fi | ||
|
|
||
| # Check for CPU features | ||
| local cpu_features | ||
| cpu_features=$(grep -o -E 'sha_ni|gfni' /proc/cpuinfo 2>/dev/null | sort -u) | ||
|
|
||
| local has_gfni=false | ||
| local has_sha_ni=false | ||
| local missing_features=() | ||
|
|
||
| if echo "$cpu_features" | grep -q "gfni"; then | ||
| has_gfni=true | ||
| else | ||
| missing_features+=("GFNI") | ||
| fi | ||
|
|
||
| if echo "$cpu_features" | grep -q "sha_ni"; then | ||
| has_sha_ni=true | ||
| else | ||
| missing_features+=("SHA_NI") | ||
| fi | ||
|
|
||
| # If any features are missing, show warning | ||
| if [[ ${#missing_features[@]} -gt 0 ]]; then | ||
| echo "$warning" | ||
| printf "Missing features: %s\n\n" "$(IFS=', '; echo "${missing_features[*]}")" | ||
| fi | ||
|
|
||
| return 0 | ||
| } | ||
|
|
||
| # Run the check if script is executed directly | ||
| if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then | ||
| check_cpu_features | ||
| fi |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[uber nit][not blocking]
--testing-environmentsounds like it could disable multiple checks like:if this check only overrides the CPU requirement, maybe it could be renamed to something more specific. For bbr we have
--force-no-bbrso maybe--force-no-new-cpu.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea: 81c1a2c