Use LoadConfig from ipld-eth-server

This commit is contained in:
nabarun 2022-05-17 18:36:08 +05:30
parent c468b494dc
commit f4c1ca4ebe
3 changed files with 6 additions and 31 deletions

View File

@ -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
}

View File

@ -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 {

View File

@ -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
make integrationtest