6 log "github.com/sirupsen/logrus"
7 "github.com/spf13/cobra"
8 "github.com/tendermint/tmlibs/cli"
10 "github.com/vapor/consensus"
11 "github.com/vapor/toolbar/common"
12 cfg "github.com/vapor/toolbar/vote_reward/config"
13 "github.com/vapor/toolbar/vote_reward/settlementvotereward"
14 "github.com/vapor/toolbar/vote_reward/synchron"
17 const logModule = "reward"
20 rewardStartHeight uint64
21 rewardEndHeight uint64
25 var RootCmd = &cobra.Command{
27 Short: "distribution of reward.",
32 RootCmd.Flags().Uint64Var(&rewardStartHeight, "reward_start_height", 0, "The starting height of the distributive income reward interval, It is a multiple of the dpos consensus cycle(1200). example: 1200")
33 RootCmd.Flags().Uint64Var(&rewardEndHeight, "reward_end_height", 0, "The end height of the distributive income reward interval, It is a multiple of the dpos consensus cycle(1200). example: 2400")
34 RootCmd.Flags().StringVar(&configFile, "config_file", "reward.json", "config file. default: reward.json")
37 func runReward(cmd *cobra.Command, args []string) error {
38 startTime := time.Now()
39 config := &cfg.Config{}
40 if err := cfg.LoadConfigFile(configFile, config); err != nil {
41 log.WithFields(log.Fields{"module": logModule, "config": configFile, "error": err}).Fatal("Failded to load config file.")
44 if err := consensus.InitActiveNetParams(config.ChainID); err != nil {
45 log.WithFields(log.Fields{"module": logModule, "error": err}).Fatal("Init ActiveNetParams.")
47 if rewardStartHeight >= rewardEndHeight || rewardStartHeight%consensus.ActiveNetParams.RoundVoteBlockNums != 0 || rewardEndHeight%consensus.ActiveNetParams.RoundVoteBlockNums != 0 {
48 log.Fatal("Please check the height range, which must be multiple of the number of block rounds.")
51 db, err := common.NewMySQLDB(config.MySQLConfig)
53 log.WithFields(log.Fields{"module": logModule, "error": err}).Fatal("Failded to initialize mysql db.")
56 sync, err := synchron.NewChainKeeper(db, config, rewardEndHeight)
58 log.WithFields(log.Fields{"module": logModule, "error": err}).Fatal("Failded to initialize NewChainKeeper.")
61 if err := sync.SyncBlock(); err != nil {
62 log.WithFields(log.Fields{"module": logModule, "error": err}).Fatal("Failded to sync block.")
65 s := settlementvotereward.NewSettlementReward(db, config, rewardStartHeight, rewardEndHeight)
67 if err := s.Settlement(); err != nil {
68 log.WithFields(log.Fields{"module": logModule, "error": err}).Fatal("Settlement vote rewards failure.")
71 log.WithFields(log.Fields{
73 "duration": time.Since(startTime),
74 }).Info("Settlement vote reward complete")
80 cmd := cli.PrepareBaseCmd(RootCmd, "REWARD", "./")