OSDN Git Service

fix reorganize vote result fix_reorganize_vote_result
authorshenao78 <shenao.78@163.com>
Mon, 10 Jun 2019 09:53:28 +0000 (17:53 +0800)
committershenao78 <shenao.78@163.com>
Mon, 10 Jun 2019 09:53:28 +0000 (17:53 +0800)
protocol/block.go
protocol/consensus_node_manager.go

index 45a5f2b..cd002d1 100644 (file)
@@ -17,7 +17,8 @@ var (
        ErrBadBlock = errors.New("invalid block")
        // ErrBadStateRoot is returned when the computed assets merkle root
        // disagrees with the one declared in a block header.
-       ErrBadStateRoot = errors.New("invalid state merkle root")
+       ErrBadStateRoot           = errors.New("invalid state merkle root")
+       errBelowIrreversibleBlock = errors.New("the height of block below the height of irreversible block")
 )
 
 // BlockExist check is a block in chain or orphan
@@ -284,11 +285,12 @@ func (c *Chain) blockProcesser() {
 
 // ProcessBlock is the entry for handle block insert
 func (c *Chain) processBlock(block *types.Block) (bool, error) {
+       blockHash := block.Hash()
        if block.Height <= c.bestIrreversibleNode.Height {
-               return false, errors.New("the height of block below the height of irreversible block")
+               log.WithFields(log.Fields{"module": logModule, "hash": blockHash.String(), "height": block.Height}).Info(errBelowIrreversibleBlock.Error())
+               return false, errBelowIrreversibleBlock
        }
 
-       blockHash := block.Hash()
        if c.BlockExist(&blockHash) {
                log.WithFields(log.Fields{"module": logModule, "hash": blockHash.String(), "height": block.Height}).Info("block has been processed")
                return c.orphanManage.BlockExist(&blockHash), nil
index 5bd9ee3..9d842d0 100644 (file)
@@ -131,7 +131,7 @@ func (c *consensusNodeManager) reorganizeVoteResult(voteResult *state.VoteResult
        mainChainNode := c.blockIndex.GetNode(&voteResult.BlockHash)
        var attachNodes []*state.BlockNode
        var detachNodes []*state.BlockNode
-       for forkChainNode := node; mainChainNode != forkChainNode; node = node.Parent {
+       for forkChainNode := node; mainChainNode != forkChainNode; forkChainNode = forkChainNode.Parent {
                if forkChainNode.Height == mainChainNode.Height {
                        detachNodes = append(detachNodes, mainChainNode)
                        mainChainNode = mainChainNode.Parent