diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-10-25 15:47:36 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-25 15:47:36 +0800 |
commit | 233f1e8de99bf2a0023f05d1c67e48cc770621df (patch) | |
tree | d60fa19092db7a113ab35d94cae4cddaa91283ce /core | |
parent | 98c53bffc1045eb22ef640984088e5e592989593 (diff) | |
download | tangerine-consensus-233f1e8de99bf2a0023f05d1c67e48cc770621df.tar.gz tangerine-consensus-233f1e8de99bf2a0023f05d1c67e48cc770621df.tar.zst tangerine-consensus-233f1e8de99bf2a0023f05d1c67e48cc770621df.zip |
core: handle round 0 randomness in processFinalizedBlock (#256)
Diffstat (limited to 'core')
-rw-r--r-- | core/compaction-chain.go | 32 | ||||
-rw-r--r-- | core/compaction-chain_test.go | 6 |
2 files changed, 26 insertions, 12 deletions
diff --git a/core/compaction-chain.go b/core/compaction-chain.go index 451cb13..50056a9 100644 --- a/core/compaction-chain.go +++ b/core/compaction-chain.go @@ -148,6 +148,11 @@ func (cc *compactionChain) processFinalizedBlock(block *types.Block) { return } + // Block of round 0 should not have randomness. + if block.Position.Round == 0 && len(block.Finalization.Randomness) != 0 { + return + } + cc.lock.Lock() defer cc.lock.Unlock() heap.Push(cc.pendingFinalizedBlocks, block) @@ -191,18 +196,21 @@ func (cc *compactionChain) extractFinalizedBlocks() []*types.Block { continue } round := b.Position.Round - v, ok, err := cc.tsigVerifier.UpdateAndGet(round) - if err != nil { - continue - } - if !ok { - toPending = append(toPending, b) - continue - } - if ok := v.VerifySignature(b.Hash, crypto.Signature{ - Type: "bls", - Signature: b.Finalization.Randomness}); !ok { - continue + if round != 0 { + // Randomness is not available at round 0. + v, ok, err := cc.tsigVerifier.UpdateAndGet(round) + if err != nil { + continue + } + if !ok { + toPending = append(toPending, b) + continue + } + if ok := v.VerifySignature(b.Hash, crypto.Signature{ + Type: "bls", + Signature: b.Finalization.Randomness}); !ok { + continue + } } // Fork resolution: choose block with smaller hash. if prevBlock.Finalization.Height == b.Finalization.Height { diff --git a/core/compaction-chain_test.go b/core/compaction-chain_test.go index 3e588b3..710c88b 100644 --- a/core/compaction-chain_test.go +++ b/core/compaction-chain_test.go @@ -262,6 +262,9 @@ func (s *CompactionChainTestSuite) TestSyncFinalizedBlock() { hash := common.NewRandomHash() cc.processFinalizedBlock(&types.Block{ Hash: hash, + Position: types.Position{ + Round: uint64(1), + }, Finalization: types.FinalizationResult{ Height: uint64(3), }, @@ -292,6 +295,9 @@ func (s *CompactionChainTestSuite) TestSyncFinalizedBlock() { cc.processFinalizedBlock(blocks[5]) cc.processFinalizedBlock(&types.Block{ Hash: hash, + Position: types.Position{ + Round: uint64(1), + }, Finalization: types.FinalizationResult{ Height: uint64(5), }, |