X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=blobdiff_plain;f=protocol%2Fstate%2Fconsensus_result.go;h=d392e1c796aa7632fd72f254d0197d829b43952e;hp=53bdbeb1242a2e1e0052c9b66f5863a18b4aa672;hb=e2c1a2332391eb4111e3158127f87d6f5f249d3c;hpb=1b35511b58dac0acdc5ca3f4f539a00d73a42430 diff --git a/protocol/state/consensus_result.go b/protocol/state/consensus_result.go index 53bdbeb1..d392e1c7 100644 --- a/protocol/state/consensus_result.go +++ b/protocol/state/consensus_result.go @@ -4,6 +4,8 @@ import ( "encoding/hex" "sort" + log "github.com/sirupsen/logrus" + "github.com/vapor/common/arithmetic" "github.com/vapor/config" "github.com/vapor/consensus" @@ -14,6 +16,8 @@ import ( "github.com/vapor/protocol/bc/types" ) +const logModule = "state/consensus" + // fedConsensusPath is used to derive federation root xpubs for signing blocks var fedConsensusPath = [][]byte{ []byte{0xff, 0xff, 0xff, 0xff}, @@ -69,7 +73,11 @@ func CalCoinbaseReward(block *types.Block) (*CoinbaseReward, error) { return nil, errors.Wrap(checked.ErrOverflow, "calculate transaction fee") } - result.Amount += txFee + ok := false + result.Amount, ok = checked.AddUint64(result.Amount, txFee) + if !ok { + return nil, checked.ErrOverflow + } } return result, nil } @@ -180,7 +188,9 @@ func (c *ConsensusResult) ConsensusNodes() (map[string]*ConsensusNode, error) { if voteNum >= consensus.ActiveNetParams.MinConsensusNodeVoteNum { var xpub chainkd.XPub if err := xpub.UnmarshalText([]byte(pubkey)); err != nil { - return nil, err + log.WithFields(log.Fields{"module": logModule, "err": err, "XPub": xpub.String()}).Debug("failed on unmarshal XPub") + delete(c.NumOfVote, pubkey) + continue } nodes = append(nodes, &ConsensusNode{XPub: xpub, VoteNum: voteNum}) @@ -251,16 +261,6 @@ func (c *ConsensusResult) DetachBlock(block *types.Block) error { // DetachCoinbaseReward detach coinbase reward func (c *ConsensusResult) DetachCoinbaseReward(block *types.Block) error { - if block.Height%consensus.ActiveNetParams.RoundVoteBlockNums == 0 { - for i, output := range block.Transactions[0].Outputs { - if i == 0 { - continue - } - program := output.ControlProgram() - c.CoinbaseReward[hex.EncodeToString(program)] = output.AssetAmount().Amount - } - } - reward, err := CalCoinbaseReward(block) if err != nil { return err @@ -275,6 +275,17 @@ func (c *ConsensusResult) DetachCoinbaseReward(block *types.Block) error { if c.CoinbaseReward[program] == 0 { delete(c.CoinbaseReward, program) } + + if block.Height%consensus.ActiveNetParams.RoundVoteBlockNums == 1 { + c.CoinbaseReward = map[string]uint64{} + for i, output := range block.Transactions[0].Outputs { + if i == 0 { + continue + } + program := output.ControlProgram() + c.CoinbaseReward[hex.EncodeToString(program)] = output.AssetAmount().Amount + } + } return nil }