OSDN Git Service

modify format
authormars <mars@bytom.io>
Fri, 19 Jul 2019 01:42:30 +0000 (09:42 +0800)
committermars <mars@bytom.io>
Fri, 19 Jul 2019 01:42:30 +0000 (09:42 +0800)
cmd/reward/command/init.go
cmd/reward/command/run.go
toolbar/common/service/node.go

index c748cbc..f7e3f8a 100644 (file)
@@ -27,13 +27,13 @@ func initFiles(cmd *cobra.Command, args []string) {
        //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")
 }
index d5213cd..fda0484 100644 (file)
@@ -18,24 +18,29 @@ const logModule = "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{}
@@ -55,7 +60,7 @@ func runReward(cmd *cobra.Command, args []string) error {
        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 {
index 9c74027..9b5a856 100644 (file)
@@ -5,7 +5,7 @@ import (
 
        "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
@@ -13,7 +13,7 @@ type Node struct {
        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}
 }
@@ -66,7 +66,7 @@ type response struct {
 
 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
        }