Skip to content

Commit

Permalink
Do not create new error variables
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoximenes committed Jul 10, 2024
1 parent f79973b commit 4924fad
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 14 deletions.
6 changes: 2 additions & 4 deletions cmd/nitro/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ import (
"github.com/offchainlabs/nitro/cmd/genericconf"
"github.com/offchainlabs/nitro/cmd/util/confighelpers"
"github.com/offchainlabs/nitro/das"
"github.com/offchainlabs/nitro/execution/gethexec"
"github.com/offchainlabs/nitro/util/colors"
"github.com/offchainlabs/nitro/util/testhelpers"
"github.com/pkg/errors"

"github.com/r3labs/diff/v3"
flag "github.com/spf13/pflag"
Expand Down Expand Up @@ -67,15 +65,15 @@ func TestInvalidCachingStateSchemeForValidator(t *testing.T) {
validatorArgsWithPathScheme := fmt.Sprintf("%s --execution.caching.state-scheme path", validatorArgs)
args := strings.Split(validatorArgsWithPathScheme, " ")
_, _, err := ParseNode(context.Background(), args)
if !errors.Is(err, invalidCachingStateSchemeForValidator) {
if !strings.Contains(err.Error(), "path cannot be used as execution.caching.state-scheme when validator is required") {
Fail(t, "failed to detect invalid state scheme for validator")
}
}

func TestInvalidArchiveConfig(t *testing.T) {
args := strings.Split("--execution.caching.archive --execution.caching.state-scheme path --persistent.chain /tmp/data --init.dev-init --node.parent-chain-reader.enable=false --parent-chain.id 5 --chain.id 421613 --node.staker.parent-chain-wallet.pathname /l1keystore --node.staker.parent-chain-wallet.password passphrase --http.addr 0.0.0.0 --ws.addr 0.0.0.0 --node.staker.enable --node.staker.strategy MakeNodes --node.staker.staker-interval 10s --execution.forwarding-target null", " ")
_, _, err := ParseNode(context.Background(), args)
if !errors.Is(err, gethexec.InvalidStateSchemeForArchive) {
if !strings.Contains(err.Error(), "archive cannot be set when using path as the state-scheme") {
Fail(t, "failed to detect invalid state scheme for archive")
}
}
Expand Down
6 changes: 1 addition & 5 deletions cmd/nitro/nitro.go
Original file line number Diff line number Diff line change
Expand Up @@ -825,10 +825,6 @@ func (c *NodeConfig) CanReload(new *NodeConfig) error {
return err
}

var (
invalidCachingStateSchemeForValidator = errors.New("path cannot be used as execution.caching.state-scheme when validator is required")
)

func (c *NodeConfig) Validate() error {
if c.Init.RecreateMissingStateFrom > 0 && !c.Execution.Caching.Archive {
return errors.New("recreate-missing-state-from enabled for a non-archive node")
Expand All @@ -849,7 +845,7 @@ func (c *NodeConfig) Validate() error {
return err
}
if c.Node.ValidatorRequired() && (c.Execution.Caching.StateScheme == rawdb.PathScheme) {
return invalidCachingStateSchemeForValidator
return errors.New("path cannot be used as execution.caching.state-scheme when validator is required")
}
return c.Persistent.Validate()
}
Expand Down
6 changes: 1 addition & 5 deletions execution/gethexec/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ var TestCachingConfig = CachingConfig{
StateScheme: env.GetTestStateScheme(),
}

var (
InvalidStateSchemeForArchive = errors.New("archive cannot be set when using path as the state-scheme")
)

// TODO remove stack from parameters as it is no longer needed here
func DefaultCacheConfigFor(stack *node.Node, cachingConfig *CachingConfig) *core.CacheConfig {
baseConf := ethconfig.Defaults
Expand Down Expand Up @@ -131,7 +127,7 @@ func (c *CachingConfig) validateStateScheme() error {
case rawdb.HashScheme:
case rawdb.PathScheme:
if c.Archive {
return InvalidStateSchemeForArchive
return errors.New("archive cannot be set when using path as the state-scheme")
}
default:
return errors.New("Invalid StateScheme")
Expand Down

0 comments on commit 4924fad

Please sign in to comment.