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 log.Info("The voting reward allocation tool is an open-source project, please check the transaction carefully before sending the allocation reward, the transaction error will not be responsible!")
39 startTime := time.Now()
40 config := &cfg.Config{}
41 if err := cfg.LoadConfigFile(configFile, config); err != nil {
42 log.WithFields(log.Fields{"module": logModule, "config": configFile, "error": err}).Fatal("Failded to load config file.")
45 if err := consensus.InitActiveNetParams(config.ChainID); err != nil {
46 log.WithFields(log.Fields{"module": logModule, "error": err}).Fatal("Init ActiveNetParams.")
48 if rewardStartHeight >= rewardEndHeight || rewardStartHeight%consensus.ActiveNetParams.RoundVoteBlockNums != 0 || rewardEndHeight%consensus.ActiveNetParams.RoundVoteBlockNums != 0 {
49 log.Fatal("Please check the height range, which must be multiple of the number of block rounds.")
52 db, err := common.NewMySQLDB(config.MySQLConfig)
54 log.WithFields(log.Fields{"module": logModule, "error": err}).Fatal("Failded to initialize mysql db.")
57 sync, err := synchron.NewChainKeeper(db, config, rewardEndHeight)
59 log.WithFields(log.Fields{"module": logModule, "error": err}).Fatal("Failded to initialize NewChainKeeper.")
62 if err := sync.SyncBlock(); err != nil {
63 log.WithFields(log.Fields{"module": logModule, "error": err}).Fatal("Failded to sync block.")
66 s := settlementvotereward.NewSettlementReward(db, config, rewardStartHeight, rewardEndHeight)
68 if err := s.Settlement(); err != nil {
69 log.WithFields(log.Fields{"module": logModule, "error": err}).Fatal("Settlement vote rewards failure.")
72 log.WithFields(log.Fields{
74 "duration": time.Since(startTime),
75 }).Info("Settlement vote reward complete")
81 cmd := cli.PrepareBaseCmd(RootCmd, "REWARD", "./")