From 8c0a7225e52dd2dabb353337909e2edeb9663e4b Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 4 Feb 2021 18:48:09 +0300 Subject: [PATCH 1/2] consensus: only use previous proposal if it has something in it It might just be uninitialized it doesn't really make sense using zero-length previous proposal anyway. --- pkg/consensus/consensus.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/consensus/consensus.go b/pkg/consensus/consensus.go index 1af47538d..12d8be085 100644 --- a/pkg/consensus/consensus.go +++ b/pkg/consensus/consensus.go @@ -580,7 +580,7 @@ func (s *service) getVerifiedTx() []block.Transaction { var txx []*transaction.Transaction - if s.dbft.ViewNumber > 0 { + if s.dbft.ViewNumber > 0 && len(s.lastProposal) > 0 { txx = make([]*transaction.Transaction, 0, len(s.lastProposal)) for i := range s.lastProposal { if tx, ok := pool.TryGetValue(s.lastProposal[i]); ok { From 43bfc909ebd5577e8b5b1fd5baad02514c5b2bbd Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 4 Feb 2021 18:54:01 +0300 Subject: [PATCH 2/2] consensus: flush previous proposal on new block Reusing proposals from previous blocks doesn't make sense. And reduce some code duplication along the way. --- pkg/consensus/consensus.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/consensus/consensus.go b/pkg/consensus/consensus.go index 12d8be085..2eeaac4cc 100644 --- a/pkg/consensus/consensus.go +++ b/pkg/consensus/consensus.go @@ -320,9 +320,7 @@ func (s *service) handleChainBlock(b *coreb.Block) { s.log.Debug("new block in the chain", zap.Uint32("dbft index", s.dbft.BlockIndex), zap.Uint32("chain index", s.Chain.BlockHeight())) - if s.lastTimestamp < b.Timestamp { - s.lastTimestamp = b.Timestamp - } + s.postBlock(b) s.dbft.InitializeConsensus(0) } } @@ -527,9 +525,14 @@ func (s *service) processBlock(b block.Block) { s.log.Warn("error on add block", zap.Error(err)) } } - if s.lastTimestamp < bb.Timestamp { - s.lastTimestamp = bb.Timestamp + s.postBlock(bb) +} + +func (s *service) postBlock(b *coreb.Block) { + if s.lastTimestamp < b.Timestamp { + s.lastTimestamp = b.Timestamp } + s.lastProposal = nil } func (s *service) getBlockWitness(b *coreb.Block) *transaction.Witness {