OSDN Git Service

fix bug (#160)
[bytom/vapor.git] / protocol / consensus_node_manager.go
index 5bd9ee3..136fb6a 100644 (file)
@@ -87,7 +87,7 @@ func (c *consensusNodeManager) getConsensusNodes(prevBlockHash *bc.Hash) (map[st
                return nil, errNotFoundBlockNode
        }
 
-       preSeq := state.CalcVoteSeq(prevBlockNode.Height + 1) - 1
+       preSeq := state.CalcVoteSeq(prevBlockNode.Height+1) - 1
        if bestSeq := state.CalcVoteSeq(c.blockIndex.BestNode().Height); preSeq > bestSeq {
                preSeq = bestSeq
        }
@@ -106,10 +106,15 @@ func (c *consensusNodeManager) getConsensusNodes(prevBlockHash *bc.Hash) (map[st
                return nil, err
        }
 
-       if len(voteResult.NumOfVote) == 0 {
-               return federationNodes(), nil
+       result, err := voteResult.ConsensusNodes()
+       if err != nil {
+               return nil, err
+       }
+
+       if len(result) != 0 {
+               return result, nil
        }
-       return voteResult.ConsensusNodes()
+       return federationNodes(), nil
 }
 
 func (c *consensusNodeManager) getBestVoteResult() (*state.VoteResult, error) {
@@ -131,7 +136,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