From c7566c2a0150e405883f4101927ef4ae03400100 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Wed, 15 Mar 2023 17:45:56 +0300 Subject: [PATCH] consensus: perform batched chain's block sync If there are several blocks from chain, then initialize consensus only for the latest one. --- pkg/consensus/consensus.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/consensus/consensus.go b/pkg/consensus/consensus.go index fb11bdea3..915b51629 100644 --- a/pkg/consensus/consensus.go +++ b/pkg/consensus/consensus.go @@ -345,15 +345,18 @@ events: } // Always process block event if there is any, we can add one above or external // services can add several blocks during message processing. + var latestBlock *coreb.Block syncLoop: for { select { - case b := <-s.blockEvents: - s.handleChainBlock(b) + case latestBlock = <-s.blockEvents: default: break syncLoop } } + if latestBlock != nil { + s.handleChainBlock(latestBlock) + } } drainLoop: for {