diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/compaction-chain.go | 3 | ||||
-rw-r--r-- | core/compaction-chain_test.go | 37 | ||||
-rw-r--r-- | core/consensus.go | 6 |
3 files changed, 45 insertions, 1 deletions
diff --git a/core/compaction-chain.go b/core/compaction-chain.go index c176f65..6803661 100644 --- a/core/compaction-chain.go +++ b/core/compaction-chain.go @@ -80,7 +80,8 @@ func (cc *compactionChain) extractBlocks() []*types.Block { cc.blocksLock.Lock() defer cc.blocksLock.Unlock() for len(cc.pendingBlocks) != 0 && - len(cc.pendingBlocks[0].Finalization.Randomness) != 0 { + (len(cc.pendingBlocks[0].Finalization.Randomness) != 0 || + cc.pendingBlocks[0].Position.Round == 0) { var block *types.Block block, cc.pendingBlocks = cc.pendingBlocks[0], cc.pendingBlocks[1:] delete(cc.blocks, block.Hash) diff --git a/core/compaction-chain_test.go b/core/compaction-chain_test.go index 3366d5f..f91f1a1 100644 --- a/core/compaction-chain_test.go +++ b/core/compaction-chain_test.go @@ -84,6 +84,9 @@ func (s *CompactionChainTestSuite) TestExtractBlocks() { for idx := range blocks { blocks[idx] = &types.Block{ Hash: common.NewRandomHash(), + Position: types.Position{ + Round: 1, + }, } s.Require().False(cc.blockRegistered(blocks[idx].Hash)) cc.registerBlock(blocks[idx]) @@ -155,6 +158,40 @@ func (s *CompactionChainTestSuite) TestExtractBlocks() { } } +func (s *CompactionChainTestSuite) TestExtractBlocksRound0() { + cc := s.newCompactionChain() + blocks := make([]*types.Block, 10) + for idx := range blocks { + blocks[idx] = &types.Block{ + Hash: common.NewRandomHash(), + Position: types.Position{ + Round: 0, + }, + } + s.Require().False(cc.blockRegistered(blocks[idx].Hash)) + cc.registerBlock(blocks[idx]) + s.Require().True(cc.blockRegistered(blocks[idx].Hash)) + } + // Round 0 should be able to be extracted without randomness. + for i := 0; i < 3; i++ { + s.Require().NoError(cc.processBlock(blocks[i])) + } + delivered := cc.extractBlocks() + s.Require().Len(delivered, 3) + + // Round 0 should be able to be extracted without randomness. + for i := 3; i < 10; i++ { + s.Require().NoError(cc.processBlock(blocks[i])) + } + delivered = append(delivered, cc.extractBlocks()...) + s.Require().Len(delivered, 10) + + // The delivered order should be the same as processing order. + for i, block := range delivered { + s.Equal(block.Hash, blocks[i].Hash) + } +} + func TestCompactionChain(t *testing.T) { suite.Run(t, new(CompactionChainTestSuite)) } diff --git a/core/consensus.go b/core/consensus.go index 90a8f09..b5cb445 100644 --- a/core/consensus.go +++ b/core/consensus.go @@ -553,6 +553,9 @@ func (con *Consensus) ProcessVote(vote *types.Vote) (err error) { // ProcessAgreementResult processes the randomness request. func (con *Consensus) ProcessAgreementResult( rand *types.AgreementResult) error { + if rand.Round == 0 { + return nil + } if !con.ccModule.blockRegistered(rand.BlockHash) { return nil } @@ -625,6 +628,9 @@ func (con *Consensus) ProcessAgreementResult( // ProcessBlockRandomnessResult processes the randomness result. func (con *Consensus) ProcessBlockRandomnessResult( rand *types.BlockRandomnessResult) error { + if rand.Round == 0 { + return nil + } if !con.ccModule.blockRegistered(rand.BlockHash) { return nil } |