From: Paladz Date: Wed, 31 Jul 2019 12:02:54 +0000 (+0800) Subject: add logs (#371) X-Git-Tag: v1.0.5~64 X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=commitdiff_plain;h=22033be3d5956e6a973ae7137c349606385c8850 add logs (#371) --- diff --git a/cmd/consensusreward/main.go b/cmd/consensusreward/main.go index b7185116..b38d07a5 100644 --- a/cmd/consensusreward/main.go +++ b/cmd/consensusreward/main.go @@ -15,9 +15,9 @@ import ( const logModule = "consensusereward" var ( - rewardStartHeight uint64 - rewardEndHeight uint64 - configFile string + startHeight uint64 + endHeight uint64 + configFile string ) var RootCmd = &cobra.Command{ @@ -27,8 +27,8 @@ var RootCmd = &cobra.Command{ } func init() { - 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") - 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") + RootCmd.Flags().Uint64Var(&startHeight, "start_height", 0, "The starting height of the distributive income reward interval, It is a multiple of the dpos consensus cycle(1200). example: 1200") + RootCmd.Flags().Uint64Var(&endHeight, "end_height", 0, "The end height of the distributive income reward interval, It is a multiple of the dpos consensus cycle(1200). example: 2400") RootCmd.Flags().StringVar(&configFile, "config_file", "reward.json", "config file. default: reward.json") } @@ -38,11 +38,11 @@ func runReward(cmd *cobra.Command, args []string) error { if err := cfg.LoadConfigFile(configFile, config); err != nil { log.WithFields(log.Fields{"module": logModule, "config": configFile, "error": err}).Fatal("Failded to load config file.") } - if rewardStartHeight >= rewardEndHeight || rewardStartHeight%consensus.ActiveNetParams.RoundVoteBlockNums != 0 || rewardEndHeight%consensus.ActiveNetParams.RoundVoteBlockNums != 0 { + if startHeight >= endHeight || startHeight%consensus.ActiveNetParams.RoundVoteBlockNums != 0 || endHeight%consensus.ActiveNetParams.RoundVoteBlockNums != 0 { log.Fatal("Please check the height range, which must be multiple of the number of block rounds.") } - s := consensusreward.NewStandbyNodeReward(config, rewardStartHeight, rewardEndHeight) + s := consensusreward.NewStandbyNodeReward(config, startHeight, endHeight) if err := s.Settlement(); err != nil { log.WithFields(log.Fields{"module": logModule, "error": err}).Fatal("Standby node rewards failure.") } diff --git a/toolbar/apinode/transaction.go b/toolbar/apinode/transaction.go index 82ff3c95..52208898 100644 --- a/toolbar/apinode/transaction.go +++ b/toolbar/apinode/transaction.go @@ -44,8 +44,8 @@ func (c *ControlAddressAction) MarshalJSON() ([]byte, error) { }) } -func (n *Node) BatchSendBTM(accountID, password string, outputs map[string]uint64) error { - totalBTM := uint64(10000000) +func (n *Node) BatchSendBTM(accountID, password string, outputs map[string]uint64) (string, error) { + totalBTM := uint64(1000000) actions := []interface{}{} for address, amount := range outputs { actions = append(actions, &ControlAddressAction{ @@ -62,16 +62,15 @@ func (n *Node) BatchSendBTM(accountID, password string, outputs map[string]uint6 tpl, err := n.buildTx(actions) if err != nil { - return err + return "", err } tpl, err = n.signTx(tpl, password) if err != nil { - return err + return "", err } - _, err = n.SubmitTx(tpl.Transaction) - return err + return n.SubmitTx(tpl.Transaction) } type buildTxReq struct { diff --git a/toolbar/consensusreward/consensusreward.go b/toolbar/consensusreward/consensus_reward.go similarity index 85% rename from toolbar/consensusreward/consensusreward.go rename to toolbar/consensusreward/consensus_reward.go index 327bf024..8e3de025 100644 --- a/toolbar/consensusreward/consensusreward.go +++ b/toolbar/consensusreward/consensus_reward.go @@ -3,6 +3,8 @@ package consensusreward import ( "math/big" + log "github.com/sirupsen/logrus" + "github.com/vapor/consensus" "github.com/vapor/errors" "github.com/vapor/toolbar/apinode" @@ -57,6 +59,7 @@ func (s *StandbyNodeReward) Settlement() error { return err } } + rewards := map[string]uint64{} for _, item := range s.cfg.RewardConf.Node { if reward, ok := s.xpubRewards[item.XPub]; ok { @@ -67,5 +70,14 @@ func (s *StandbyNodeReward) Settlement() error { if len(rewards) == 0 { return nil } - return s.node.BatchSendBTM(s.cfg.RewardConf.AccountID, s.cfg.RewardConf.Password, rewards) + + txID, err := s.node.BatchSendBTM(s.cfg.RewardConf.AccountID, s.cfg.RewardConf.Password, rewards) + if err == nil { + log.WithFields(log.Fields{ + "tx_hash": txID, + "start_height": s.startHeight, + "end_height": s.endHeight, + }).Info("success on submit consensus reward transaction") + } + return err } diff --git a/toolbar/vote_reward/settlementvotereward/settlementreward.go b/toolbar/vote_reward/settlementvotereward/settlementreward.go index 92d37eef..e110b95e 100644 --- a/toolbar/vote_reward/settlementvotereward/settlementreward.go +++ b/toolbar/vote_reward/settlementvotereward/settlementreward.go @@ -86,7 +86,8 @@ func (s *SettlementReward) Settlement() error { } // send transactions - return s.node.BatchSendBTM(s.rewardCfg.AccountID, s.rewardCfg.Password, s.rewards) + _, err := s.node.BatchSendBTM(s.rewardCfg.AccountID, s.rewardCfg.Password, s.rewards) + return err } func (s *SettlementReward) getStandbyNodeReward(height uint64) (uint64, error) {