OSDN Git Service

Fix get consensus edge case (#147)
authormuscle_boy <shenao.78@163.com>
Mon, 10 Jun 2019 07:09:24 +0000 (15:09 +0800)
committerPaladz <yzhu101@uottawa.ca>
Mon, 10 Jun 2019 07:09:24 +0000 (15:09 +0800)
* fix get consensus node edge case

* fix get consensus node edge case

* fix get consensus node edge case

protocol/consensus_node_manager.go

index 99693ab..5bd9ee3 100644 (file)
@@ -87,12 +87,11 @@ func (c *consensusNodeManager) getConsensusNodes(prevBlockHash *bc.Hash) (map[st
                return nil, errNotFoundBlockNode
        }
 
-       seqHeight := prevBlockNode.Height + 1
-       if bestHeight := c.blockIndex.BestNode().Height; bestHeight < seqHeight && bestHeight != 0 {
-               seqHeight = bestHeight
+       preSeq := state.CalcVoteSeq(prevBlockNode.Height + 1) - 1
+       if bestSeq := state.CalcVoteSeq(c.blockIndex.BestNode().Height); preSeq > bestSeq {
+               preSeq = bestSeq
        }
 
-       preSeq := state.CalcVoteSeq(seqHeight) - 1
        voteResult, err := c.store.GetVoteResult(preSeq)
        if err != nil {
                return nil, err