-
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
613bf70
04ca5f4
319f364
2d943f8
c0fe944
03c44f2
8d3058c
e1c9966
0d4fc23
81c1a2c
f6e9b5a
d5f1f17
b3293bf
c708c50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 (SHA Extensions) | ||
|
|
||
| These features significantly improve cryptographic performance for blockchain operations. | ||
|
|
||
| Note: These features are not required for the current 32MB/6s block configuration but will become | ||
rach-id marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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 in production, consider upgrading to a CPU with these features. | ||
rach-id marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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 | ||
| } | ||
| 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 (SHA Extensions) | ||
rach-id marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| These features significantly improve cryptographic performance for blockchain operations. | ||
|
|
||
| Note: These features are not required for the current 32MB/6s block configuration but will become | ||
rach-id marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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 | ||
Uh oh!
There was an error while loading. Please reload this page.