diff options
Diffstat (limited to 'vendor/github.com/dexon-foundation/dexon-consensus/core/compaction-chain.go')
-rw-r--r-- | vendor/github.com/dexon-foundation/dexon-consensus/core/compaction-chain.go | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/compaction-chain.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/compaction-chain.go index 8080a2c78..4a5ba3637 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/compaction-chain.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/compaction-chain.go @@ -42,6 +42,7 @@ type compactionChain struct { chainUnsynced uint32 tsigVerifier *TSigVerifierCache blocks map[common.Hash]*types.Block + blockRandomness map[common.Hash][]byte pendingBlocks []*types.Block pendingFinalizedBlocks *finalizedBlockHeap lock sync.RWMutex @@ -55,6 +56,7 @@ func newCompactionChain(gov Governance) *compactionChain { gov: gov, tsigVerifier: NewTSigVerifierCache(gov, 7), blocks: make(map[common.Hash]*types.Block), + blockRandomness: make(map[common.Hash][]byte), pendingFinalizedBlocks: pendingFinalizedBlocks, } } @@ -131,7 +133,7 @@ func (cc *compactionChain) extractBlocks() []*types.Block { defer cc.lock.Unlock() // cc.pendingBlocks[0] will not be popped and will equal to cc.prevBlock. for len(cc.pendingBlocks) > 1 && - (len(cc.pendingBlocks[1].Finalization.Randomness) != 0 || + (len(cc.blockRandomness[cc.pendingBlocks[1].Hash]) != 0 || cc.pendingBlocks[1].Position.Round == 0) { delete(cc.blocks, cc.pendingBlocks[0].Hash) cc.pendingBlocks = cc.pendingBlocks[1:] @@ -139,6 +141,10 @@ func (cc *compactionChain) extractBlocks() []*types.Block { block := cc.pendingBlocks[0] block.Finalization.ParentHash = prevBlock.Hash block.Finalization.Height = prevBlock.Finalization.Height + 1 + if block.Position.Round != 0 { + block.Finalization.Randomness = cc.blockRandomness[block.Hash] + delete(cc.blockRandomness, block.Hash) + } deliveringBlocks = append(deliveringBlocks, block) prevBlock = block } @@ -260,7 +266,7 @@ func (cc *compactionChain) processBlockRandomnessResult( if !cc.blockRegisteredNoLock(rand.BlockHash) { return ErrBlockNotRegistered } - cc.blocks[rand.BlockHash].Finalization.Randomness = rand.Randomness + cc.blockRandomness[rand.BlockHash] = rand.Randomness return nil } |