From 565b27269b598de3e337d732525b2a171a30cb5e Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 5 Nov 2026 16:41:38 +0100 Subject: answering behind counted --- src/swarm/stats.rs | 9 +++++++++ src/swarm/sync.rs | 9 +++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'src/swarm') diff --git a/src/swarm/stats.rs b/src/swarm/stats.rs index 02ccad5..218d5e8 100644 --- a/src/swarm/stats.rs +++ b/src/swarm/stats.rs @@ -166,6 +166,10 @@ pub(crate) struct Relay { /// counting them so (so they weren't what we passed on built on), and later. pub(crate) asked_known_lately: u64, pub(crate) asked_known_later: u64, + /// Messages taken as delivered by their sender, which was behind us: answered with + /// what it lacks (it got changes we had along its tree late, or we got them early by + /// another way). + pub(crate) answering_behind: u64, /// Changes from elsewhere that came not along a writer's tree (pulled, with an /// answer, sent again, fetched as a delta), and their delays summed (as `Propagation`). pub(crate) off_tree: u64, @@ -312,6 +316,11 @@ impl NodeStats { inner.relay.nothing_new_change_bytes += change_bytes as u64; } + /// A message taken as delivered came from a peer behind us (`Relay::answering_behind`). + pub(crate) fn answering_behind(&self) { + self.lock().relay.answering_behind += 1; + } + /// A sync message carried changes that wait for predecessors (`Relay::waiting`). pub(crate) fn waiting(&self) { self.lock().relay.waiting += 1; diff --git a/src/swarm/sync.rs b/src/swarm/sync.rs index c969678..5100b98 100644 --- a/src/swarm/sync.rs +++ b/src/swarm/sync.rs @@ -603,10 +603,15 @@ pub(crate) async fn handle_sync( let heads_after = replica.heads().to_vec(); if delivered { // Level with the sender now, which takes the message as delivered: - // nothing to answer (`SyncSession::answered_as_delivered`). - peer_state + // nothing to answer (`SyncSession::answered_as_delivered`). Unless it is + // behind us: then the answer brings it what it lacks. + let behind = peer_state.sync.peer_behind(&replica.doc, &heads_after); + let answered = peer_state .sync .answered_as_delivered(&replica.doc, &heads_after); + if behind && !answered { + stats.answering_behind(); + } } stats.heads_seen(heads_after.len()); let changed = heads_after != heads_before; -- cgit v1.3.1