Skip to content
Draft
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ endif
## install-standalone: Build and install the celestia-appd binary into the $GOPATH/bin directory. This target does not install the multiplexer.
install-standalone:
@echo "--> Installing celestia-appd"
@bash scripts/check_cpu_features.sh
@go install $(BUILD_FLAGS_STANDALONE) ./cmd/celestia-appd
.PHONY: install-standalone

## install: Build and install the multiplexer version of celestia-appd into the $GOPATH/bin directory.
# TODO: Improve logic here and in goreleaser to make it future proof and less expensive.
install: download-v3-binaries download-v4-binaries download-v5-binaries
@echo "--> Installing celestia-appd with multiplexer support"
@bash scripts/check_cpu_features.sh
@go install $(BUILD_FLAGS_MULTIPLEXER) ./cmd/celestia-appd
.PHONY: install

Expand Down
85 changes: 85 additions & 0 deletions cmd/celestia-appd/cmd/cpu_features.go
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.
Copy link
Collaborator

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-environment sounds like it could disable multiple checks like:

  • this CPU check
  • bbr
  • override the default block time from 6 seconds to 1 second

if this check only overrides the CPU requirement, maybe it could be renamed to something more specific. For bbr we have --force-no-bbr so maybe --force-no-new-cpu.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea: 81c1a2c

`
)

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
}
3 changes: 2 additions & 1 deletion cmd/celestia-appd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func initRootCommand(rootCommand *cobra.Command, capp *app.App) {
modifyRootCommand(rootCommand)

// Add hooks run prior to the start command
if err := addPreStartHooks(rootCommand, checkBBR); err != nil {
if err := addPreStartHooks(rootCommand, checkBBR, checkCPUFeatures); err != nil {
panic(fmt.Errorf("failed to add pre-start hooks: %w", err))
}
}
Expand All @@ -155,6 +155,7 @@ func addStartFlags(startCmd *cobra.Command) {

startCmd.Flags().Duration(DelayedPrecommitTimeoutFlag, 0, "Override the DelayedPrecommitTimeout to control block time. Note: only for testing purposes.")
startCmd.Flags().Bool(FlagForceNoBBR, false, "bypass the requirement to use bbr locally")
startCmd.Flags().Bool(FlagTestingEnvironment, false, "bypass CPU feature checks for testing environments")
}

// replaceLogger optionally replaces the logger with a file logger if the flag
Expand Down
73 changes: 73 additions & 0 deletions scripts/check_cpu_features.sh
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