Setup validator config and update instructions to run tests locally

This commit is contained in:
Prathamesh Musale 2022-06-02 14:35:59 +05:30
parent 3182a60794
commit 44fb305858
5 changed files with 45 additions and 26 deletions

View File

@ -7,7 +7,6 @@ import (
"os/signal" "os/signal"
"sync" "sync"
"github.com/ethereum/go-ethereum/statediff"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
@ -34,20 +33,7 @@ func stateValidator() {
logWithCommand.Fatal(err) logWithCommand.Fatal(err)
} }
height := viper.GetUint64("validate.block-height") service := validator.NewService(cfg, nil)
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)
wg := new(sync.WaitGroup) wg := new(sync.WaitGroup)
wg.Add(1) wg.Add(1)

View File

@ -6,6 +6,7 @@ import (
"time" "time"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/statediff"
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres" "github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"github.com/spf13/viper" "github.com/spf13/viper"
@ -59,11 +60,35 @@ var TestChainConfig = &params.ChainConfig{
type Config struct { type Config struct {
dbConfig postgres.Config dbConfig postgres.Config
DB *sqlx.DB DB *sqlx.DB
ChainCfg *params.ChainConfig
BlockNum, Trail uint64
SleepInterval uint
} }
func NewConfig() (*Config, error) { func NewConfig() (*Config, error) {
cfg := new(Config) 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 { func (c *Config) setupDB() error {

View File

@ -40,14 +40,14 @@ type service struct {
progressChan chan uint64 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{ return &service{
db: db, db: cfg.DB,
blockNum: blockNum, blockNum: cfg.BlockNum,
trail: trailNum, trail: cfg.Trail,
sleepInterval: sleepInterval, sleepInterval: cfg.SleepInterval,
logger: log.New(), logger: log.New(),
chainCfg: chainCfg, chainCfg: cfg.ChainCfg,
quitChan: make(chan bool), quitChan: make(chan bool),
progressChan: progressChan, progressChan: progressChan,
} }

View File

@ -6,18 +6,18 @@
- Clone [stack-orchestrator](https://github.com/vulcanize/stack-orchestrator) and [go-ethereum](https://github.com/vulcanize/go-ethereum) repositories. - 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 ```bash
# In go-ethereum repo. # 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. - Checkout working commit in stack-orchestrator repo.
```bash ```bash
# In stack-orchestrator repo. # In stack-orchestrator repo.
git checkout 3bb1796a59827fb755410c5ce69fac567a0f832b git checkout main
``` ```
## Run ## Run

View File

@ -16,6 +16,7 @@ import (
) )
const ( const (
blockNum = 1
trail = 0 trail = 0
validatorSleepInterval = uint(5) validatorSleepInterval = uint(5)
) )
@ -44,8 +45,15 @@ var _ = Describe("Integration test", func() {
timeout := 4 * time.Second timeout := 4 * time.Second
db := shared.SetupDB() db := shared.SetupDB()
cfg := validator.Config{
DB: db,
BlockNum: blockNum,
Trail: trail,
SleepInterval: validatorSleepInterval,
ChainCfg: validator.IntegrationTestChainConfig,
}
validationProgressChan := make(chan uint64) validationProgressChan := make(chan uint64)
service := validator.NewService(db, 1, trail, validatorSleepInterval, validator.IntegrationTestChainConfig, validationProgressChan) service := validator.NewService(&cfg, validationProgressChan)
wg := new(sync.WaitGroup) wg := new(sync.WaitGroup)