2022-01-18 06:23:01 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2022-05-31 06:29:49 +00:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"sync"
|
2022-01-18 06:23:01 +00:00
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
|
2022-05-06 11:21:11 +00:00
|
|
|
"github.com/vulcanize/ipld-eth-db-validator/pkg/validator"
|
2022-01-18 06:23:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// stateValidatorCmd represents the stateValidator command
|
|
|
|
var stateValidatorCmd = &cobra.Command{
|
|
|
|
Use: "stateValidator",
|
|
|
|
Short: "Validate ethereum state",
|
|
|
|
Long: `Usage ./ipld-eth-db-validator stateValidator --config={path to toml config file}`,
|
|
|
|
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
subCommand = cmd.CalledAs()
|
|
|
|
logWithCommand = *log.WithField("SubCommand", subCommand)
|
|
|
|
stateValidator()
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func stateValidator() {
|
|
|
|
cfg, err := validator.NewConfig()
|
|
|
|
if err != nil {
|
|
|
|
logWithCommand.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2022-06-03 13:28:02 +00:00
|
|
|
service := validator.NewService(cfg, nil)
|
2022-01-18 06:23:01 +00:00
|
|
|
|
2022-05-31 06:29:49 +00:00
|
|
|
wg := new(sync.WaitGroup)
|
|
|
|
wg.Add(1)
|
|
|
|
go service.Start(context.Background(), wg)
|
2022-01-18 06:23:01 +00:00
|
|
|
|
2022-05-31 06:29:49 +00:00
|
|
|
shutdown := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(shutdown, os.Interrupt)
|
|
|
|
<-shutdown
|
|
|
|
service.Stop()
|
|
|
|
wg.Wait()
|
2022-01-18 06:23:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rootCmd.AddCommand(stateValidatorCmd)
|
|
|
|
|
|
|
|
stateValidatorCmd.PersistentFlags().String("block-height", "1", "block height to initiate state validation")
|
2022-05-31 06:29:49 +00:00
|
|
|
stateValidatorCmd.PersistentFlags().String("trail", "16", "trail of block height to validate")
|
|
|
|
stateValidatorCmd.PersistentFlags().String("sleep-interval", "10", "sleep interval in seconds after validator has caught up to (head-trail) height")
|
2022-01-18 06:23:01 +00:00
|
|
|
|
2022-05-17 13:06:08 +00:00
|
|
|
stateValidatorCmd.PersistentFlags().String("chain-config", "", "path to chain config")
|
2022-05-17 04:29:23 +00:00
|
|
|
|
2022-01-18 06:23:01 +00:00
|
|
|
_ = viper.BindPFlag("validate.block-height", stateValidatorCmd.PersistentFlags().Lookup("block-height"))
|
|
|
|
_ = viper.BindPFlag("validate.trail", stateValidatorCmd.PersistentFlags().Lookup("trail"))
|
2022-05-31 06:29:49 +00:00
|
|
|
_ = viper.BindPFlag("validate.sleepInterval", stateValidatorCmd.PersistentFlags().Lookup("sleep-interval"))
|
2022-05-17 04:29:23 +00:00
|
|
|
|
2022-05-17 13:06:08 +00:00
|
|
|
_ = viper.BindPFlag("ethereum.chainConfig", stateValidatorCmd.PersistentFlags().Lookup("chain-config"))
|
2022-01-18 06:23:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func initConfig() {
|
|
|
|
if cfgFile != "" {
|
|
|
|
viper.SetConfigFile(cfgFile)
|
|
|
|
if err := viper.ReadInConfig(); err == nil {
|
|
|
|
log.Printf("Using config file: %s", viper.ConfigFileUsed())
|
|
|
|
} else {
|
|
|
|
log.Fatal(fmt.Sprintf("Couldn't read config file: %s", err.Error()))
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
log.Warn("No config file passed with --config flag")
|
|
|
|
}
|
|
|
|
}
|