- return nil, err
- }
-
- if err := c.reorganizeVoteResult(voteResult, lastBlockNode); err != nil {
- return nil, err
- }
-
- if len(voteResult.NumOfVote) == 0 {
- return initConsensusNodes(), nil
- }
- return voteResult.ConsensusNodes()
-}
-
-func (c *consensusNodeManager) reorganizeVoteResult(voteResult *state.VoteResult, forkChainNode *state.BlockNode) error {
- mainChainNode := c.blockIndex.GetNode(&voteResult.LastBlockHash)
- var attachNodes []*state.BlockNode
- var detachNodes []*state.BlockNode
- for mainChainNode != forkChainNode {
- if forkChainNode.Height == mainChainNode.Height {
- detachNodes = append(detachNodes, mainChainNode)
- mainChainNode = mainChainNode.Parent
- }
- attachNodes = append([]*state.BlockNode{forkChainNode}, attachNodes...)
- forkChainNode = forkChainNode.Parent