//generate the reward config file
config := cfg.DefaultConfig(isVoteReward)
configFilePath := cfg.ConfigFile()
- if _, err := os.Stat(configFilePath); os.IsNotExist(err) {
- if err := cfg.ExportFederationFile(configFilePath, config); err != nil {
- log.WithFields(log.Fields{"module": logModule, "config": configFilePath, "error": err}).Fatal("fail on export reward file")
- }
- } else {
+ if _, err := os.Stat(configFilePath); !os.IsNotExist(err) {
log.WithFields(log.Fields{"module": logModule, "config": configFilePath}).Fatal("Already exists config file.")
}
+ if err := cfg.ExportFederationFile(configFilePath, config); err != nil {
+ log.WithFields(log.Fields{"module": logModule, "config": configFilePath, "error": err}).Fatal("fail on export reward file")
+ }
+
log.WithFields(log.Fields{"module": logModule, "config": configFilePath}).Info("Initialized reward")
}
var coinBasePeriod uint64
-var runRewardCmd = &cobra.Command{
- Use: "reward",
- Short: "Run the reward",
- RunE: runReward,
-}
+var (
+ RootCmd = &cobra.Command{
+ Use: "reward",
+ Short: "distribution of reward.",
+ }
-var RootCmd = &cobra.Command{
- Use: "reward",
- Short: "distribution of reward.",
-}
+ runRewardCmd = &cobra.Command{
+ Use: "reward",
+ Short: "Run the reward",
+ RunE: runReward,
+ }
+)
func init() {
-
runRewardCmd.Flags().Uint64Var(&coinBasePeriod, "coin_base_period", 1, "Consensus cycle")
+
RootCmd.AddCommand(runRewardCmd)
}
func runReward(cmd *cobra.Command, args []string) error {
+ if coinBasePeriod <= 1 {
+ cmn.Exit("Counting the vote reward from the second round of consensus")
+ }
startTime := time.Now()
configFilePath := cfg.ConfigFile()
config := &cfg.Config{}
go sync.Run()
quit := make(chan struct{})
- r := reward.NewReward(db, config, coinBasePeriod, quit)
+ r := reward.NewReward(db, config, coinBasePeriod-1, quit)
r.Start()
select {
"github.com/vapor/errors"
"github.com/vapor/protocol/bc"
- util "github.com/vapor/toolbar/common"
+ "github.com/vapor/toolbar/common"
)
// Node can invoke the api which provide by the full node server
hostPort string
}
-// Node create a api client with target server
+// NewNode create a api client with target server
func NewNode(hostPort string) *Node {
return &Node{hostPort: hostPort}
}
func (n *Node) request(path string, payload []byte, respData interface{}) error {
resp := &response{}
- if err := util.Post(n.hostPort+path, payload, resp); err != nil {
+ if err := common.Post(n.hostPort+path, payload, resp); err != nil {
return err
}