From c85e4efec5bf8c5d83401816b6de4f46fbedd99e Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 6 Nov 2026 04:32:20 +0100 Subject: one grace wait per peer --- src/swarm/relay.rs | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'src/swarm/relay.rs') diff --git a/src/swarm/relay.rs b/src/swarm/relay.rs index 31df0d3..0f8a697 100644 --- a/src/swarm/relay.rs +++ b/src/swarm/relay.rs @@ -325,21 +325,25 @@ pub(crate) async fn lacks(state: &AppState, heads: &HeadsSummary) -> bool { /// most; at once if we know none). While writes go on, the newest of them are usually /// on their way to us along their writers' trees, as fast as the STATUS: they come /// meanwhile, and pulling them would only fetch them twice. What is still missing then -/// was missed. +/// was missed. One wait per peer: a STATUS that comes meanwhile is the one judged at the +/// end (`PeerState::pull_pending`). pub(crate) async fn pull_after_grace(state: &AppState, peer: &str, remote: &transport::Status) { - if HeadsSummary::of(state.stamp.borrow().heads.to_vec()) == remote.heads { - return; - } - let grace = state - .lock_rtt() - .effective(peer, Instant::now(), state.timing.rtt_fresh_for()) - .map(|rtt| rtt.min(PULL_GRACE_MAX)); - if let Some(grace) = grace - && lacks(state, &remote.heads).await - { - tokio::time::sleep(grace).await; + if HeadsSummary::of(state.stamp.borrow().heads.to_vec()) != remote.heads { + let grace = state + .lock_rtt() + .effective(peer, Instant::now(), state.timing.rtt_fresh_for()) + .map(|rtt| rtt.min(PULL_GRACE_MAX)); + if let Some(grace) = grace + && lacks(state, &remote.heads).await + { + tokio::time::sleep(grace).await; + } } - pull_if_behind(state, peer, remote).await; + let latest = match state.get_peer_state(peer).await { + Some(peer_state) => peer_state.lock().await.pull_pending.take(), + None => None, + }; + pull_if_behind(state, peer, latest.as_ref().unwrap_or(remote)).await; } /// If `peer` has heads we lack (as its STATUS `remote` says), pull them (one peer at a -- cgit v1.3.1