From 233f1e8de99bf2a0023f05d1c67e48cc770621df Mon Sep 17 00:00:00 2001 From: Jimmy Hu Date: Thu, 25 Oct 2018 15:47:36 +0800 Subject: core: handle round 0 randomness in processFinalizedBlock (#256) --- core/compaction-chain.go | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'core/compaction-chain.go') 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 { -- cgit v1.2.3