From dcd2d701b5b8afd68fba5eed7265f8fa5d169a86 Mon Sep 17 00:00:00 2001 From: Sarlor Date: Fri, 8 Feb 2019 15:25:53 +0800 Subject: [PATCH] mining: Optimize get the block's votes tx. The optimizes to check the height of the next block is greater than the threshold first since it is more likely in the NewBlockTemplate function. --- mining.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/mining.go b/mining.go index 36e4a944..355934dd 100644 --- a/mining.go +++ b/mining.go @@ -1589,25 +1589,25 @@ mempoolLoop: voters := 0 var voteBitsVoters []uint16 - for _, tx := range blockTxns { - msgTx := tx.MsgTx() - if nextBlockHeight < stakeValidationHeight { - break // No SSGen should be present before this height. - } + // Have SSGen should be present after this height. + if nextBlockHeight >= stakeValidationHeight { + for _, tx := range blockTxns { + msgTx := tx.MsgTx() - if stake.IsSSGen(msgTx) { - txCopy := dcrutil.NewTxDeepTxIns(msgTx) - if maybeInsertStakeTx(g.blockManager, txCopy, !knownDisapproved) { - vb := stake.SSGenVoteBits(txCopy.MsgTx()) - voteBitsVoters = append(voteBitsVoters, vb) - blockTxnsStake = append(blockTxnsStake, txCopy) - voters++ + if stake.IsSSGen(msgTx) { + txCopy := dcrutil.NewTxDeepTxIns(msgTx) + if maybeInsertStakeTx(g.blockManager, txCopy, !knownDisapproved) { + vb := stake.SSGenVoteBits(txCopy.MsgTx()) + voteBitsVoters = append(voteBitsVoters, vb) + blockTxnsStake = append(blockTxnsStake, txCopy) + voters++ + } } - } - // Don't let this overflow, although probably it's impossible. - if voters >= math.MaxUint16 { - break + // Don't let this overflow, although probably it's impossible. + if voters >= math.MaxUint16 { + break + } } }