From facc05316e2b350d7b7bbd7dfd0c013cc167f341 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 29 Nov 2026 03:51:14 +0000 Subject: document: taking changes fetched as a blob is the document's document::passing::take_bulk: the changes a peer offered as a blob, fetched, judged and applied with their signatures, and all the heads offered held after. swarm::sync keeps the fetch, the epoch check, and what is counted and noted of the peer. --- src/swarm/sync.rs | 52 +++++++++++++++------------------------------------- 1 file changed, 15 insertions(+), 37 deletions(-) (limited to 'src/swarm/sync.rs') diff --git a/src/swarm/sync.rs b/src/swarm/sync.rs index 18e5653..006df9d 100644 --- a/src/swarm/sync.rs +++ b/src/swarm/sync.rs @@ -812,47 +812,25 @@ async fn download_and_apply_delta( if replica.epoch != epoch { bail!("the epoch changed during the download"); } - let heads_before = replica.heads().to_vec(); - { - // Its signatures wait for its changes (`Signatures::offer`), each checked as - // they are judged (`document::screen`), whether this document has a policy yet - // or not. - let epoch_seq = replica.epoch_seq; - let replica = &mut *replica; - replica.signatures.offer(&replica.doc, signatures); - let outcome = crate::document::screen::apply_bytes( - &mut replica.doc, - epoch, - epoch_seq, - &bytes, - &screening, - Some(&mut replica.signatures), - &mut crate::document::PatchLog::inactive(), - )?; - if let Some(actor) = outcome.fresh_actor { - own_writers.add(actor); - } - } - replica.refresh_heads(); - // Signatures waiting for what it brought (`Signatures::offer`). - { - let replica = &mut *replica; - replica.signatures.offer(&replica.doc, Vec::new()); - } - let missing = crate::document::changes::missing(&replica.doc, &spec.to).len(); - if missing > 0 { - bail!("{missing} of the offered heads are still missing after loading"); + let (fresh_actor, bulk) = crate::document::passing::take_bulk( + &mut replica, + &bytes, + signatures, + &spec.to, + &screening, + measure_propagation, + ); + if let Some(actor) = fresh_actor { + own_writers.add(actor); } - stats.heads_seen(replica.heads().len()); - let changed = replica.heads() != heads_before.as_slice(); + let bulk = bulk?; + stats.heads_seen(bulk.heads); + let changed = bulk.changed; + let heads_before = bulk.heads_before; if changed && measure_propagation { // As in `receive`; a delta goes along no writer's tree. let now_ms = clock.now_millis().as_u64() as i64 - ahead_ms; - let delays: Vec = - crate::document::changes::commit_times(&replica.doc, &heads_before) - .into_iter() - .map(|time| now_ms - time) - .collect(); + let delays: Vec = bulk.times.into_iter().map(|time| now_ms - time).collect(); stats.off_tree(&delays); stats.propagated(delays); } -- cgit v1.3.1