diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-11-13 15:34:22 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-09 21:32:53 +0800 |
commit | ef24d59fe79fd57a88ff886afdc3a01be1d49e55 (patch) | |
tree | 3ad7843e3c5115e966b23203fbc3d4404c371664 /vendor/github.com/dexon-foundation/dexon-consensus/core/compaction-chain.go | |
parent | 5f2bcc7fba1d247763892c35d694f61e12676969 (diff) | |
download | dexon-ef24d59fe79fd57a88ff886afdc3a01be1d49e55.tar dexon-ef24d59fe79fd57a88ff886afdc3a01be1d49e55.tar.gz dexon-ef24d59fe79fd57a88ff886afdc3a01be1d49e55.tar.bz2 dexon-ef24d59fe79fd57a88ff886afdc3a01be1d49e55.tar.lz dexon-ef24d59fe79fd57a88ff886afdc3a01be1d49e55.tar.xz dexon-ef24d59fe79fd57a88ff886afdc3a01be1d49e55.tar.zst dexon-ef24d59fe79fd57a88ff886afdc3a01be1d49e55.zip |
vendor: sync to latest core (#16)
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 } |