From b8a7a38c80cc928749666f1b1d03a5477c26be0d Mon Sep 17 00:00:00 2001 From: muscle_boy Date: Mon, 10 Jun 2019 18:00:34 +0800 Subject: [PATCH] fix reorganize vote result (#151) --- protocol/block.go | 8 +++++--- protocol/consensus_node_manager.go | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/protocol/block.go b/protocol/block.go index 45a5f2be..cd002d10 100644 --- a/protocol/block.go +++ b/protocol/block.go @@ -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 diff --git a/protocol/consensus_node_manager.go b/protocol/consensus_node_manager.go index 5bd9ee3a..9d842d04 100644 --- a/protocol/consensus_node_manager.go +++ b/protocol/consensus_node_manager.go @@ -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 -- 2.11.0