OSDN Git Service

fix coinbase calculate
authoroys <oys@oysdeMBP.localdomain>
Wed, 3 Jul 2019 02:33:17 +0000 (10:33 +0800)
committeroys <oys@oysdeMBP.localdomain>
Wed, 3 Jul 2019 02:33:17 +0000 (10:33 +0800)
protocol/block.go
protocol/state/consensus_result.go

index bb73919..e692602 100644 (file)
@@ -162,6 +162,14 @@ func (c *Chain) reorganizeChain(blockHeader *types.BlockHeader) error {
                        return err
                }
 
+               if detachBlockHeader.Height%consensus.RoundVoteBlockNums == 0 {
+                       hash := detachBlockHeader.Hash()
+                       consensusResult, err = c.GetConsensusResultByHash(&hash)
+                       if err != nil {
+                               return err
+                       }
+               }
+
                if err := consensusResult.DetachBlock(b); err != nil {
                        return err
                }
@@ -227,7 +235,7 @@ func (c *Chain) saveBlock(block *types.Block) error {
        }
 
        rewards := []validation.CoinbaseReward{}
-       if (parent.Height+1)%consensus.RoundVoteBlockNums == 0 {
+       if block.Height%consensus.RoundVoteBlockNums == 0 {
                consensusResult, err := c.getBestConsensusResult()
                if err != nil {
                        return err
index ac4c049..92ee8ef 100644 (file)
@@ -67,6 +67,10 @@ func (c *ConsensusResult) ApplyBlock(block *types.Block) error {
                return err
        }
 
+       if c.IsFinalize() {
+               c.RewardOfCoinbase = map[string]uint64{}
+       }
+
        program := hex.EncodeToString(reward.ControlProgram)
        c.RewardOfCoinbase[program], ok = checked.AddUint64(c.RewardOfCoinbase[program], reward.Amount)
        if !ok {