diff options
Diffstat (limited to 'vendor/github.com/dexon-foundation/dexon-consensus/core/blockchain.go')
-rw-r--r-- | vendor/github.com/dexon-foundation/dexon-consensus/core/blockchain.go | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/blockchain.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/blockchain.go index aacb65de2..b6c8b1da5 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/blockchain.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/blockchain.go @@ -311,21 +311,23 @@ func (bc *blockChain) addBlock(b *types.Block) error { return nil } +func (bc *blockChain) shouldAddRandomness(r *types.BlockRandomnessResult) bool { + bc.lock.RLock() + defer bc.lock.RUnlock() + if bc.lastDelivered != nil && + bc.lastDelivered.Position.Newer(r.Position) { + return false + } + _, exists := bc.pendingRandomnesses[r.Position] + if exists { + return false + } + b := bc.findPendingBlock(r.Position) + return b == nil || len(b.Finalization.Randomness) == 0 +} + func (bc *blockChain) addRandomness(r *types.BlockRandomnessResult) error { - if func() bool { - bc.lock.RLock() - defer bc.lock.RUnlock() - if bc.lastDelivered != nil && - bc.lastDelivered.Position.Newer(r.Position) { - return true - } - _, exists := bc.pendingRandomnesses[r.Position] - if exists { - return true - } - b := bc.findPendingBlock(r.Position) - return b != nil && len(b.Finalization.Randomness) > 0 - }() { + if !bc.shouldAddRandomness(r) { return nil } ok, err := bc.verifyRandomness(r.BlockHash, r.Position.Round, r.Randomness) |