diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-11-13 15:34:22 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-12 17:27:18 +0800 |
commit | 08ec9c78c4acfc09f24ddd0f864504fc58cb07e2 (patch) | |
tree | 6f197a58383c922bc541d27e3dff36083d145036 /vendor/github.com/dexon-foundation/dexon-consensus/core/compaction-chain.go | |
parent | aec90eae15b9ad106e3443fc5c5ab6f285e131a0 (diff) | |
download | go-tangerine-08ec9c78c4acfc09f24ddd0f864504fc58cb07e2.tar go-tangerine-08ec9c78c4acfc09f24ddd0f864504fc58cb07e2.tar.gz go-tangerine-08ec9c78c4acfc09f24ddd0f864504fc58cb07e2.tar.bz2 go-tangerine-08ec9c78c4acfc09f24ddd0f864504fc58cb07e2.tar.lz go-tangerine-08ec9c78c4acfc09f24ddd0f864504fc58cb07e2.tar.xz go-tangerine-08ec9c78c4acfc09f24ddd0f864504fc58cb07e2.tar.zst go-tangerine-08ec9c78c4acfc09f24ddd0f864504fc58cb07e2.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 } |