aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm/sync.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/swarm/sync.rs')
-rw-r--r--src/swarm/sync.rs52
1 files changed, 15 insertions, 37 deletions
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<i64> =
- crate::document::changes::commit_times(&replica.doc, &heads_before)
- .into_iter()
- .map(|time| now_ms - time)
- .collect();
+ let delays: Vec<i64> = bulk.times.into_iter().map(|time| now_ms - time).collect();
stats.off_tree(&delays);
stats.propagated(delays);
}