From e57e74692f80f2ed1a7cc02cbaa16cbeaf64a8b9 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Mon, 6 Mar 2023 18:27:09 +0300 Subject: [PATCH] consensus: drain block notification channel after each message Make blockchain lock less possible. --- pkg/consensus/consensus.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/consensus/consensus.go b/pkg/consensus/consensus.go index a4229e536..ee447e9cb 100644 --- a/pkg/consensus/consensus.go +++ b/pkg/consensus/consensus.go @@ -337,11 +337,16 @@ events: case b := <-s.blockEvents: s.handleChainBlock(b) } - // Always process block event if there is any, we can add one above. - select { - case b := <-s.blockEvents: - s.handleChainBlock(b) - default: + // Always process block event if there is any, we can add one above or external + // services can add several blocks during message processing. + syncLoop: + for { + select { + case b := <-s.blockEvents: + s.handleChainBlock(b) + default: + break syncLoop + } } } drainLoop: