Skip to content
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

New Testing Features and Client Updates #10

Merged
merged 9 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
42 changes: 37 additions & 5 deletions api/server/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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)
}

Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions config/besu-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions config/geth-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 4 additions & 25 deletions config/lighthouse-bn-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
},
},

Expand Down Expand Up @@ -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
}
29 changes: 4 additions & 25 deletions config/lighthouse-vc-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
},
},

Expand Down Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions config/lodestar-bn-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions config/reth-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -58,14 +58,25 @@ 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
}

// 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
Expand Down
3 changes: 3 additions & 0 deletions node/wallet/address-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions node/wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading