From 1d1837c973845f767b322e79d637fa6018e2e8f0 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Fri, 19 Jul 2024 15:17:55 +0000 Subject: [PATCH] Revert "beefy: Avoid double lock wrt live peers and cache reset" This reverts commit 7c77d4e0ec1f5f9a0b7c6abd7d144ea523814b52. Signed-off-by: Alexandru Vasile --- .../outgoing_requests_engine.rs | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/substrate/client/consensus/beefy/src/communication/request_response/outgoing_requests_engine.rs b/substrate/client/consensus/beefy/src/communication/request_response/outgoing_requests_engine.rs index c7fce028d42b..95ecf35557a5 100644 --- a/substrate/client/consensus/beefy/src/communication/request_response/outgoing_requests_engine.rs +++ b/substrate/client/consensus/beefy/src/communication/request_response/outgoing_requests_engine.rs @@ -98,17 +98,12 @@ impl OnDemandJustificationsEngine>) -> Option { - let live = self.live_peers.lock(); - - if let Some(reset) = reset_cache { - self.peers_cache = live.further_than(reset); - } + fn reset_peers_cache_for_block(&mut self, block: NumberFor) { + self.peers_cache = self.live_peers.lock().further_than(block); + } + fn try_next_peer(&mut self) -> Option { + let live = self.live_peers.lock(); while let Some(peer) = self.peers_cache.pop_front() { if live.contains(&peer) { return Some(peer); @@ -147,10 +142,11 @@ impl OnDemandJustificationsEngine OnDemandJustificationsEngine { // No valid justification received, try next peer in our set. - if let Some(peer) = self.try_next_peer(None) { + if let Some(peer) = self.try_next_peer() { self.request_from_peer(peer, req_info); } else { metric_inc!(