diff --git a/cmd/state_validator.go b/cmd/state_validator.go index ded52df..20b0fe3 100644 --- a/cmd/state_validator.go +++ b/cmd/state_validator.go @@ -7,7 +7,6 @@ import ( "os/signal" "sync" - "github.com/ethereum/go-ethereum/statediff" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -34,20 +33,7 @@ func stateValidator() { logWithCommand.Fatal(err) } - height := viper.GetUint64("validate.block-height") - if height < 1 { - logWithCommand.Fatalf("block height cannot be less the 1") - } - trail := viper.GetUint64("validate.trail") - sleepInterval := viper.GetUint("validate.sleepInterval") - - chainConfigPath := viper.GetString("ethereum.chainConfig") - chainCfg, err := statediff.LoadConfig(chainConfigPath) - if err != nil { - logWithCommand.Fatal(err) - } - - service := validator.NewService(cfg.DB, height, trail, sleepInterval, chainCfg, nil) + service := validator.NewService(cfg, nil) wg := new(sync.WaitGroup) wg.Add(1) diff --git a/pkg/validator/config.go b/pkg/validator/config.go index 068f10d..6ca8966 100644 --- a/pkg/validator/config.go +++ b/pkg/validator/config.go @@ -6,6 +6,7 @@ import ( "time" "github.com/ethereum/go-ethereum/params" + "github.com/ethereum/go-ethereum/statediff" "github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres" "github.com/jmoiron/sqlx" "github.com/spf13/viper" @@ -59,11 +60,35 @@ var TestChainConfig = ¶ms.ChainConfig{ type Config struct { dbConfig postgres.Config DB *sqlx.DB + + ChainCfg *params.ChainConfig + + BlockNum, Trail uint64 + SleepInterval uint } func NewConfig() (*Config, error) { cfg := new(Config) - return cfg, cfg.setupDB() + err := cfg.setupDB() + if err != nil { + return nil, err + } + + cfg.BlockNum = viper.GetUint64("validate.block-height") + if cfg.BlockNum < 1 { + return nil, fmt.Errorf("block height cannot be less the 1") + } + + cfg.Trail = viper.GetUint64("validate.trail") + cfg.SleepInterval = viper.GetUint("validate.sleepInterval") + + chainConfigPath := viper.GetString("ethereum.chainConfig") + cfg.ChainCfg, err = statediff.LoadConfig(chainConfigPath) + if err != nil { + return nil, err + } + + return cfg, nil } func (c *Config) setupDB() error { diff --git a/pkg/validator/validator.go b/pkg/validator/validator.go index e844cc5..5c6cac5 100644 --- a/pkg/validator/validator.go +++ b/pkg/validator/validator.go @@ -40,14 +40,14 @@ type service struct { progressChan chan uint64 } -func NewService(db *sqlx.DB, blockNum, trailNum uint64, sleepInterval uint, chainCfg *params.ChainConfig, progressChan chan uint64) *service { +func NewService(cfg *Config, progressChan chan uint64) *service { return &service{ - db: db, - blockNum: blockNum, - trail: trailNum, - sleepInterval: sleepInterval, + db: cfg.DB, + blockNum: cfg.BlockNum, + trail: cfg.Trail, + sleepInterval: cfg.SleepInterval, logger: log.New(), - chainCfg: chainCfg, + chainCfg: cfg.ChainCfg, quitChan: make(chan bool), progressChan: progressChan, } diff --git a/test/README.md b/test/README.md index 0f8b5ad..30715fa 100644 --- a/test/README.md +++ b/test/README.md @@ -6,18 +6,18 @@ - Clone [stack-orchestrator](https://github.com/vulcanize/stack-orchestrator) and [go-ethereum](https://github.com/vulcanize/go-ethereum) repositories. - - Checkout [v3 release](https://github.com/vulcanize/go-ethereum/releases/tag/v1.10.17-statediff-3.2.1) in go-ethereum repo. + - Checkout [v3 release](https://github.com/vulcanize/go-ethereum/releases/tag/v1.10.18-statediff-3.2.2) in go-ethereum repo. ```bash # In go-ethereum repo. - git checkout v1.10.17-statediff-3.2.1 + git checkout v1.10.18-statediff-3.2.2 ``` - Checkout working commit in stack-orchestrator repo. ```bash # In stack-orchestrator repo. - git checkout 3bb1796a59827fb755410c5ce69fac567a0f832b + git checkout main ``` ## Run diff --git a/test/integration_test.go b/test/integration_test.go index 9101a6a..8da58a9 100644 --- a/test/integration_test.go +++ b/test/integration_test.go @@ -16,6 +16,7 @@ import ( ) const ( + blockNum = 1 trail = 0 validatorSleepInterval = uint(5) ) @@ -44,8 +45,15 @@ var _ = Describe("Integration test", func() { timeout := 4 * time.Second db := shared.SetupDB() + cfg := validator.Config{ + DB: db, + BlockNum: blockNum, + Trail: trail, + SleepInterval: validatorSleepInterval, + ChainCfg: validator.IntegrationTestChainConfig, + } validationProgressChan := make(chan uint64) - service := validator.NewService(db, 1, trail, validatorSleepInterval, validator.IntegrationTestChainConfig, validationProgressChan) + service := validator.NewService(&cfg, validationProgressChan) wg := new(sync.WaitGroup)