From f4c1ca4ebe46facf44952f3acff957594b46693d Mon Sep 17 00:00:00 2001 From: nabarun Date: Tue, 17 May 2022 18:36:08 +0530 Subject: [PATCH] Use LoadConfig from ipld-eth-server --- cmd/state_validator.go | 33 ++++----------------------------- pkg/validator/validator.go | 1 - scripts/run_integration_test.sh | 3 ++- 3 files changed, 6 insertions(+), 31 deletions(-) diff --git a/cmd/state_validator.go b/cmd/state_validator.go index 07deb55..0ccda2f 100644 --- a/cmd/state_validator.go +++ b/cmd/state_validator.go @@ -2,16 +2,14 @@ package cmd import ( "context" - "encoding/json" "fmt" - "os" - "github.com/ethereum/go-ethereum/params" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" "github.com/vulcanize/ipld-eth-db-validator/pkg/validator" + "github.com/vulcanize/ipld-eth-server/pkg/eth" ) // stateValidatorCmd represents the stateValidator command @@ -40,8 +38,7 @@ func stateValidator() { trail := viper.GetUint64("validate.trail") chainConfigPath := viper.GetString("ethereum.chainConfig") - chainCfg, err := LoadConfig(chainConfigPath) - fmt.Println("chainCfg", chainCfg) + chainCfg, err := eth.LoadConfig(chainConfigPath) if err != nil { logWithCommand.Fatal(err) } @@ -62,12 +59,12 @@ func init() { stateValidatorCmd.PersistentFlags().String("block-height", "1", "block height to initiate state validation") stateValidatorCmd.PersistentFlags().String("trail", "0", "trail of block height to validate") - stateValidatorCmd.PersistentFlags().String("chainConfig", "", "path to chain config") + stateValidatorCmd.PersistentFlags().String("chain-config", "", "path to chain config") _ = viper.BindPFlag("validate.block-height", stateValidatorCmd.PersistentFlags().Lookup("block-height")) _ = viper.BindPFlag("validate.trail", stateValidatorCmd.PersistentFlags().Lookup("trail")) - _ = viper.BindPFlag("ethereum.chainConfig", stateValidatorCmd.PersistentFlags().Lookup("chainConfig")) + _ = viper.BindPFlag("ethereum.chainConfig", stateValidatorCmd.PersistentFlags().Lookup("chain-config")) } func initConfig() { @@ -82,25 +79,3 @@ func initConfig() { log.Warn("No config file passed with --config flag") } } - -// LoadConfig loads chain config from json file -func LoadConfig(chainConfigPath string) (*params.ChainConfig, error) { - file, err := os.Open(chainConfigPath) - if err != nil { - log.Error(fmt.Sprintf("Failed to read chain config file: %v", err)) - - return nil, err - } - defer file.Close() - - chainConfig := new(params.ChainConfig) - if err := json.NewDecoder(file).Decode(chainConfig); err != nil { - log.Error(fmt.Sprintf("invalid chain config file: %v", err)) - - return nil, err - } - - log.Info(fmt.Sprintf("Using chain config from %s file. Content %+v", chainConfigPath, chainConfig)) - - return chainConfig, nil -} diff --git a/pkg/validator/validator.go b/pkg/validator/validator.go index abcf82a..5f2fc78 100644 --- a/pkg/validator/validator.go +++ b/pkg/validator/validator.go @@ -86,7 +86,6 @@ func (s *service) Start(ctx context.Context) (uint64, error) { headBlock, _ := api.B.BlockByNumber(ctx, rpc.LatestBlockNumber) headBlockNum := headBlock.NumberU64() - fmt.Println("#########", headBlockNum, s.trail, idxBlockNum) for headBlockNum-s.trail >= idxBlockNum { validateBlock, err := api.B.BlockByNumber(ctx, rpc.BlockNumber(idxBlockNum)) if err != nil { diff --git a/scripts/run_integration_test.sh b/scripts/run_integration_test.sh index 2d55d14..c2d3c11 100755 --- a/scripts/run_integration_test.sh +++ b/scripts/run_integration_test.sh @@ -17,7 +17,8 @@ export DATABASE_USER=vdbm export DATABASE_PORT=8077 export DATABASE_PASSWORD=password export DATABASE_HOSTNAME=127.0.0.1 +export DATABASE_NAME=vulcanize_testing # Wait for containers to be up and execute the integration test. while [ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:8545)" != "200" ]; do echo "waiting for geth-statediff..." && sleep 5; done && \ - make integrationtest \ No newline at end of file + make integrationtest