From 34b04932601b2fbcbb3ecd9e4a83450be4c2eecd Mon Sep 17 00:00:00 2001 From: Brendon Fish Date: Thu, 14 Dec 2023 12:58:50 -0500 Subject: [PATCH] poll for current proposal on view sync timeout --- .../traits/networking/web_server_network.rs | 36 ++++++++++++------- crates/task-impls/src/view_sync.rs | 4 +++ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/crates/hotshot/src/traits/networking/web_server_network.rs b/crates/hotshot/src/traits/networking/web_server_network.rs index ad0b2dd078..c7270ac0ae 100644 --- a/crates/hotshot/src/traits/networking/web_server_network.rs +++ b/crates/hotshot/src/traits/networking/web_server_network.rs @@ -139,6 +139,9 @@ struct Inner { /// Task map for transactions txn_task_map: Arc>>>>, + /// Task polling for current propsal + current_proposal_task: + Arc>>>>, } impl Inner { @@ -502,6 +505,7 @@ impl WebServerNetwork { view_sync_cert_task_map: Arc::default(), view_sync_vote_task_map: Arc::default(), txn_task_map: Arc::default(), + current_proposal_task: Arc::default(), }); inner.connected.store(true, Ordering::Relaxed); @@ -848,23 +852,29 @@ impl ConnectedNetwork, TYPES::Signatur } } ConsensusIntentEvent::PollForCurrentProposal => { - // create new task - let (_, receiver) = unbounded(); - - async_spawn({ - let inner_clone = self.inner.clone(); - async move { - if let Err(e) = inner_clone - .poll_web_server(receiver, MessagePurpose::CurrentProposal, 1) - .await - { - warn!( + let mut proposal_task = self.inner.current_proposal_task.write().await; + if proposal_task.is_none() { + // create new task + let (sender, receiver) = unbounded(); + *proposal_task = Some(sender); + + async_spawn({ + let inner_clone = self.inner.clone(); + async move { + if let Err(e) = inner_clone + .poll_web_server(receiver, MessagePurpose::CurrentProposal, 1) + .await + { + warn!( "Background receive proposal polling encountered an error: {:?}", e ); + } + let mut proposal_task = inner_clone.current_proposal_task.write().await; + *proposal_task = None; } - } - }); + }); + } } ConsensusIntentEvent::PollForVotes(view_number) => { let mut task_map = self.inner.vote_task_map.write().await; diff --git a/crates/task-impls/src/view_sync.rs b/crates/task-impls/src/view_sync.rs index cae79db753..63763b5cbb 100644 --- a/crates/task-impls/src/view_sync.rs +++ b/crates/task-impls/src/view_sync.rs @@ -865,6 +865,10 @@ impl, A: ConsensusApi + && relay == self.relay && last_seen_certificate == self.phase { + // Keep tyring to get a more recent proposal to catch up to + self.network + .inject_consensus_info(ConsensusIntentEvent::PollForCurrentProposal) + .await; self.relay += 1; match self.phase { ViewSyncPhase::None => {