diff --git a/api/server/utils.go b/api/server/utils.go index 501aad1..300a072 100644 --- a/api/server/utils.go +++ b/api/server/utils.go @@ -29,7 +29,33 @@ func ValidateArg[ArgType any](name string, args url.Values, impl ArgValidator[Ar return nil } -// Validates an argument representing a batch of inputs, ensuring it exists and the inputs can be converted to the required type +// Validates an optional argument, converting to the required type if it exists +func ValidateOptionalArg[ArgType any](name string, args url.Values, impl ArgValidator[ArgType], result_Out *ArgType, exists_Out *bool) error { + // Make sure it exists + arg, exists := args[name] + if !exists { + if exists_Out != nil { + *exists_Out = false + } + return nil + } + + // Run the parser + result, err := impl(name, arg[0]) + if err != nil { + return err + } + + // Set the result + *result_Out = result + if exists_Out != nil { + *exists_Out = true + } + return nil +} + +// Validates an argument representing a batch of inputs, ensuring it exists and the inputs can be converted to the required type. +// Use a limit of 0 for no limit. func ValidateArgBatch[ArgType any](name string, args url.Values, batchLimit int, impl ArgValidator[ArgType], result_Out *[]ArgType) error { // Make sure it exists arg, exists := args[name] @@ -44,7 +70,7 @@ func ValidateArgBatch[ArgType any](name string, args url.Values, batchLimit int, } // Make sure there aren't too many entries - if len(result) > batchLimit { + if batchLimit > 0 && len(result) > batchLimit { return fmt.Errorf("too many inputs in arg %s (provided %d, max = %d)", name, len(result), batchLimit) } @@ -53,8 +79,9 @@ func ValidateArgBatch[ArgType any](name string, args url.Values, batchLimit int, return nil } -// Validates an optional argument, converting to the required type if it exists -func ValidateOptionalArg[ArgType any](name string, args url.Values, impl ArgValidator[ArgType], result_Out *ArgType, exists_Out *bool) error { +// Validates an optional argument representing a batch of inputs, converting them to the required type if it exists. +// Use a limit of 0 for no limit. +func ValidateOptionalArgBatch[ArgType any](name string, args url.Values, batchLimit int, impl ArgValidator[ArgType], result_Out *[]ArgType, exists_Out *bool) error { // Make sure it exists arg, exists := args[name] if !exists { @@ -65,11 +92,16 @@ func ValidateOptionalArg[ArgType any](name string, args url.Values, impl ArgVali } // Run the parser - result, err := impl(name, arg[0]) + result, err := input.ValidateBatch[ArgType](name, arg[0], impl) if err != nil { return err } + // Make sure there aren't too many entries + if batchLimit > 0 && len(result) > batchLimit { + return fmt.Errorf("too many inputs in arg %s (provided %d, max = %d)", name, len(result), batchLimit) + } + // Set the result *result_Out = result if exists_Out != nil { diff --git a/config/besu-config.go b/config/besu-config.go index 50d66d0..112697d 100644 --- a/config/besu-config.go +++ b/config/besu-config.go @@ -7,8 +7,8 @@ import ( // Constants const ( // Tags - besuTagTest string = "hyperledger/besu:24.5.2" - besuTagProd string = "hyperledger/besu:24.5.2" + besuTagTest string = "hyperledger/besu:24.6.0" + besuTagProd string = "hyperledger/besu:24.6.0" ) // Configuration for Besu diff --git a/config/geth-config.go b/config/geth-config.go index 0323f73..b4de1a5 100644 --- a/config/geth-config.go +++ b/config/geth-config.go @@ -10,8 +10,8 @@ import ( // Constants const ( // Tags - gethTagProd string = "ethereum/client-go:v1.14.3" - gethTagTest string = "ethereum/client-go:v1.14.3" + gethTagProd string = "ethereum/client-go:v1.14.5" + gethTagTest string = "ethereum/client-go:v1.14.5" ) // Configuration for Geth diff --git a/config/lighthouse-bn-config.go b/config/lighthouse-bn-config.go index 5759335..f93c3e8 100644 --- a/config/lighthouse-bn-config.go +++ b/config/lighthouse-bn-config.go @@ -2,15 +2,12 @@ package config import ( "github.com/rocket-pool/node-manager-core/config/ids" - "github.com/rocket-pool/node-manager-core/utils/sys" ) const ( // Tags - lighthouseBnTagPortableTest string = "sigp/lighthouse:v5.1.3" - lighthouseBnTagPortableProd string = "sigp/lighthouse:v5.1.3" - lighthouseBnTagModernTest string = "sigp/lighthouse:v5.1.3-modern" - lighthouseBnTagModernProd string = "sigp/lighthouse:v5.1.3-modern" + lighthouseBnTagProd string = "sigp/lighthouse:v5.2.0" + lighthouseBnTagTest string = "sigp/lighthouse:v5.2.0" ) // Configuration for the Lighthouse BN @@ -69,8 +66,8 @@ func NewLighthouseBnConfig() *LighthouseBnConfig { OverwriteOnUpgrade: true, }, Default: map[Network]string{ - Network_Mainnet: getLighthouseBnTagProd(), - Network_Holesky: getLighthouseBnTagTest(), + Network_Mainnet: lighthouseBnTagProd, + Network_Holesky: lighthouseBnTagTest, }, }, @@ -109,21 +106,3 @@ func (cfg *LighthouseBnConfig) GetParameters() []IParameter { func (cfg *LighthouseBnConfig) GetSubconfigs() map[string]IConfigSection { return map[string]IConfigSection{} } - -// Get the appropriate LH default tag for production -func getLighthouseBnTagProd() string { - missingFeatures := sys.GetMissingModernCpuFeatures() - if len(missingFeatures) > 0 { - return lighthouseBnTagPortableProd - } - return lighthouseBnTagModernProd -} - -// Get the appropriate LH default tag for testnets -func getLighthouseBnTagTest() string { - missingFeatures := sys.GetMissingModernCpuFeatures() - if len(missingFeatures) > 0 { - return lighthouseBnTagPortableTest - } - return lighthouseBnTagModernTest -} diff --git a/config/lighthouse-vc-config.go b/config/lighthouse-vc-config.go index 38b6d82..cc9d3ee 100644 --- a/config/lighthouse-vc-config.go +++ b/config/lighthouse-vc-config.go @@ -2,15 +2,12 @@ package config import ( "github.com/rocket-pool/node-manager-core/config/ids" - "github.com/rocket-pool/node-manager-core/utils/sys" ) const ( // Tags - lighthouseVcTagPortableTest string = lighthouseBnTagPortableTest - lighthouseVcTagPortableProd string = lighthouseBnTagPortableProd - lighthouseVcTagModernTest string = lighthouseBnTagModernTest - lighthouseVcTagModernProd string = lighthouseBnTagModernProd + lighthouseVcTagProd string = lighthouseBnTagProd + lighthouseVcTagTest string = lighthouseBnTagTest ) // Configuration for the Lighthouse VC @@ -35,8 +32,8 @@ func NewLighthouseVcConfig() *LighthouseVcConfig { OverwriteOnUpgrade: true, }, Default: map[Network]string{ - Network_Mainnet: getLighthouseVcTagProd(), - Network_Holesky: getLighthouseVcTagTest(), + Network_Mainnet: lighthouseVcTagProd, + Network_Holesky: lighthouseVcTagTest, }, }, @@ -73,21 +70,3 @@ func (cfg *LighthouseVcConfig) GetParameters() []IParameter { func (cfg *LighthouseVcConfig) GetSubconfigs() map[string]IConfigSection { return map[string]IConfigSection{} } - -// Get the appropriate LH default tag for production -func getLighthouseVcTagProd() string { - missingFeatures := sys.GetMissingModernCpuFeatures() - if len(missingFeatures) > 0 { - return lighthouseVcTagPortableProd - } - return lighthouseVcTagModernProd -} - -// Get the appropriate LH default tag for testnets -func getLighthouseVcTagTest() string { - missingFeatures := sys.GetMissingModernCpuFeatures() - if len(missingFeatures) > 0 { - return lighthouseVcTagPortableTest - } - return lighthouseVcTagModernTest -} diff --git a/config/lodestar-bn-config.go b/config/lodestar-bn-config.go index aa11f33..a4c2403 100644 --- a/config/lodestar-bn-config.go +++ b/config/lodestar-bn-config.go @@ -5,8 +5,8 @@ import ( ) const ( - lodestarBnTagTest string = "chainsafe/lodestar:v1.18.1" - lodestarBnTagProd string = "chainsafe/lodestar:v1.18.1" + lodestarBnTagTest string = "chainsafe/lodestar:v1.19.0" + lodestarBnTagProd string = "chainsafe/lodestar:v1.19.0" ) // Configuration for the Lodestar BN diff --git a/config/reth-config.go b/config/reth-config.go index c3132a6..8e0d6c3 100644 --- a/config/reth-config.go +++ b/config/reth-config.go @@ -9,8 +9,8 @@ import ( // Constants const ( - rethTagProd string = "ghcr.io/paradigmxyz/reth:v0.2.0-beta.6" - rethTagTest string = "ghcr.io/paradigmxyz/reth:v0.2.0-beta.6" + rethTagProd string = "ghcr.io/paradigmxyz/reth:v0.2.0-beta.9" + rethTagTest string = "ghcr.io/paradigmxyz/reth:v0.2.0-beta.9" ) // Configuration for Reth diff --git a/log/logger.go b/log/logger.go index c8cc50f..1bdd6df 100644 --- a/log/logger.go +++ b/log/logger.go @@ -17,7 +17,7 @@ type Logger struct { path string } -// Creates a new logger +// Creates a new logger that writes out to a log file on disk. func NewLogger(logFilePath string, options LoggerOptions) (*Logger, error) { // Make the file err := os.MkdirAll(filepath.Dir(logFilePath), logDirMode) @@ -58,6 +58,14 @@ func NewLogger(logFilePath string, options LoggerOptions) (*Logger, error) { }, nil } +// Creates a new logger that uses the slog default logger, which writes to the terminal instead of a file. +// Operations like rotation don't apply to this logger. +func NewDefaultLogger() *Logger { + return &Logger{ + Logger: slog.Default(), + } +} + // Get the path of the file this logger is writing to func (l *Logger) GetFilePath() string { return l.path @@ -65,7 +73,10 @@ func (l *Logger) GetFilePath() string { // Rotate the log file, migrating the current file to an old backup and starting a new one func (l *Logger) Rotate() error { - return l.logFile.Rotate() + if l.logFile != nil { + return l.logFile.Rotate() + } + return nil } // Closes the log file diff --git a/node/wallet/address-manager.go b/node/wallet/address-manager.go index f23ee07..825d8da 100644 --- a/node/wallet/address-manager.go +++ b/node/wallet/address-manager.go @@ -29,6 +29,9 @@ func newAddressManager(path string) *addressManager { // Gets the address saved on disk. Returns false if the address file doesn't exist. func (m *addressManager) LoadAddress() (common.Address, bool, error) { + m.address = common.Address{} + m.isLoaded = false + _, err := os.Stat(m.path) if errors.Is(err, fs.ErrNotExist) { return common.Address{}, false, nil diff --git a/node/wallet/wallet.go b/node/wallet/wallet.go index 0c283cb..85b5688 100644 --- a/node/wallet/wallet.go +++ b/node/wallet/wallet.go @@ -113,6 +113,8 @@ func (w *Wallet) Reload(logger *slog.Logger) error { } else if walletMgr != nil { w.walletManager = walletMgr } + } else { + w.walletManager = nil } // Load the node address