OSDN Git Service

fix the solo net
authorpaladz <453256728@qq.com>
Tue, 4 Jun 2019 19:17:28 +0000 (03:17 +0800)
committerpaladz <453256728@qq.com>
Tue, 4 Jun 2019 19:17:28 +0000 (03:17 +0800)
proposal/blockproposer/blockproposer.go
protocol/consensus_node_manager.go

index cd84e70..13ebf17 100644 (file)
@@ -57,8 +57,13 @@ func (b *BlockProposer) generateBlocks() {
                        nextBlockTime = minNextBlockTime
                }
 
-               if isBlocker, err := b.chain.IsBlocker(&bestBlockHash, xpubStr, nextBlockTime); !isBlocker {
-                       log.WithFields(log.Fields{"module": logModule, "error": err, "pubKey": xpubStr}).Debug("fail on check is next blocker")
+               isBlocker, err := b.chain.IsBlocker(&bestBlockHash, xpubStr, nextBlockTime)
+               if err != nil {
+                       log.WithFields(log.Fields{"module": logModule, "error": err, "pubKey": xpubStr}).Error("fail on check is next blocker")
+                       continue
+               }
+
+               if !isBlocker {
                        continue
                }
 
index dd98cff..8d008fb 100644 (file)
@@ -88,7 +88,7 @@ func (c *consensusNodeManager) getConsensusNodes(prevBlockHash *bc.Hash) (map[st
        }
 
        seqHeight := prevBlockNode.Height + 1
-       if bestHeight := c.blockIndex.BestNode().Height; bestHeight < seqHeight {
+       if bestHeight := c.blockIndex.BestNode().Height; bestHeight < seqHeight && bestHeight != 0 {
                seqHeight = bestHeight
        }
 
@@ -115,6 +115,10 @@ func (c *consensusNodeManager) getConsensusNodes(prevBlockHash *bc.Hash) (map[st
 
 func (c *consensusNodeManager) getBestVoteResult() (*state.VoteResult, error) {
        blockNode := c.blockIndex.BestNode()
+       if blockNode.Height == 0 {
+               return c.store.GetVoteResult(0)
+       }
+
        seq := (blockNode.Height-1)/consensus.RoundVoteBlockNums + 1
        voteResult, err := c.store.GetVoteResult(seq)
        if err != nil {