OSDN Git Service

send standby node reward (#358)
[bytom/vapor.git] / cmd / consensusreward / main.go
1 package main
2
3 import (
4         "time"
5
6         log "github.com/sirupsen/logrus"
7         "github.com/spf13/cobra"
8         "github.com/tendermint/tmlibs/cli"
9
10         "github.com/vapor/consensus"
11         "github.com/vapor/toolbar/consensusreward"
12         cfg "github.com/vapor/toolbar/consensusreward/config"
13 )
14
15 const logModule = "consensusereward"
16
17 var (
18         rewardStartHeight uint64
19         rewardEndHeight   uint64
20         configFile        string
21 )
22
23 var RootCmd = &cobra.Command{
24         Use:   "consensusreward",
25         Short: "distribution of reward.",
26         RunE:  runReward,
27 }
28
29 func init() {
30         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")
31         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")
32         RootCmd.Flags().StringVar(&configFile, "config_file", "reward.json", "config file. default: reward.json")
33 }
34
35 func runReward(cmd *cobra.Command, args []string) error {
36         startTime := time.Now()
37         config := &cfg.Config{}
38         if err := cfg.LoadConfigFile(configFile, config); err != nil {
39                 log.WithFields(log.Fields{"module": logModule, "config": configFile, "error": err}).Fatal("Failded to load config file.")
40         }
41         if rewardStartHeight >= rewardEndHeight || rewardStartHeight%consensus.ActiveNetParams.RoundVoteBlockNums != 0 || rewardEndHeight%consensus.ActiveNetParams.RoundVoteBlockNums != 0 {
42                 log.Fatal("Please check the height range, which must be multiple of the number of block rounds.")
43         }
44
45         s := consensusreward.NewStandbyNodeReward(config, rewardStartHeight, rewardEndHeight)
46         if err := s.Settlement(); err != nil {
47                 log.WithFields(log.Fields{"module": logModule, "error": err}).Fatal("Standby node rewards failure.")
48         }
49
50         log.WithFields(log.Fields{
51                 "module":   logModule,
52                 "duration": time.Since(startTime),
53         }).Info("Standby node reward complete")
54
55         return nil
56 }
57
58 func main() {
59         cmd := cli.PrepareBaseCmd(RootCmd, "REWARD", "./")
60         cmd.Execute()
61 }