diff options
| author | tv <tv@krebsco.de> | 2026-11-24 19:07:35 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-24 19:07:35 +0000 |
| commit | 9c491018933833916d5d72e9185671638cb7e99b (patch) | |
| tree | f094784f23973453281512b42fa449ac1c7326a9 /src/federation/held.rs | |
| parent | fb54044c688e0252b4af54a057151b9c4d4ccf98 (diff) | |
federation: what a node held when it started, it held before any proposal
A node keeps when it took each event in memory, by its own clock: after
a start, everything its document held was stamped at once, a checkpoint's
proposal with the writes it leaves out. The voters' rule asks what was
held for a while before the proposal, which was nothing then, and once
--store-back-after had passed the node backed it, whatever its heads
left out. A followed key left such a proposal pending and gathered its
followers' votes as they restarted, as all do to roll out a revision.
Now what the store holds as the node first reads it counts as held
before any proposal (Inner::from_start, Seen::from_start): the node
backs no checkpoint leaving any of it out. One proposed just before a
restart at heads that left out the writes then under way isn't backed
by that node either; the next one is.
a_node_votes_above_the_heads_of_the_checkpoint_it_votes_on read write,
proposal and vote into a fresh node at once, which is this case: its
node runs before they come now, and a second one, started on all of it,
casts nothing.
Diffstat (limited to 'src/federation/held.rs')
| -rw-r--r-- | src/federation/held.rs | 49 |
1 files changed, 45 insertions, 4 deletions
diff --git a/src/federation/held.rs b/src/federation/held.rs index 9c87995..02b94d2 100644 --- a/src/federation/held.rs +++ b/src/federation/held.rs @@ -143,6 +143,11 @@ struct Inner { /// When, by its own clock, the node took each event its store took after its /// checkpoint, and when the store moved to its checkpoint, or started there. taken_at: HashMap<Id, Instant>, + /// Of those, the ones its store held when the node first read it, at its start: taken + /// some time before, which no clock of this run says. + from_start: HashSet<Id>, + /// Whether the store was read once since the node started (`from_start`). + started: bool, at_checkpoint: Option<(Id, Instant)>, /// Its party's record, voting by itself, once read; and why it isn't, said once. record: Option<Record>, @@ -369,6 +374,12 @@ impl Holding { } let taken: HashSet<&Id> = store.taken().iter().collect(); inner.taken_at.retain(|id, _| taken.contains(id)); + // What the store holds as it is first read was taken before this run's clock. + if !inner.started { + inner.started = true; + inner.from_start = store.taken().iter().copied().collect(); + } + inner.from_start.retain(|id| taken.contains(id)); for id in store.taken() { inner.taken_at.entry(*id).or_insert(now); } @@ -712,9 +723,11 @@ impl Holding { } let now = Instant::now(); let held = |id: &Id| inner.taken_at.get(id).map(|at| now.duration_since(*at)); + let from_start = |id: &Id| inner.from_start.contains(id); let seen = Seen { store, held: &held, + from_start: &from_start, since_move: inner .at_checkpoint .map_or(Duration::ZERO, |(_, at)| now.duration_since(at)), @@ -2431,9 +2444,8 @@ mod tests { let proposal = tv.propose(&[Id::of(&write)], &next.json()); let yes = tv.vote(&[Id::of(&proposal)], on, next.hash(), true); let mut doc = events::started(Federation::NAME, &root, &[]).unwrap(); - for event in [&write, &beside, &proposal, &yes] { - put(&mut doc, event); - } + put(&mut doc, &write); + let events = [&beside, &proposal, &yes]; let dir = crate::files::scratch_dir("held-votes-above"); let record = dir.join("makefu.json"); let version = Version::read(&first.json()).unwrap(); @@ -2450,7 +2462,8 @@ mod tests { .voting(Some(Voter { key: makefu.key.clone(), record, - // Lass's write, just taken, not held for a while: it may be left out. + // Lass's write, taken while it runs and not held for a while: it may be left + // out. (Held when the node started, it may not: `Inner::from_start`.) rules: Rules { follow: vec!["tv".to_owned()], held_for: Duration::from_secs(3600), @@ -2458,6 +2471,10 @@ mod tests { }, })); read(&holding, &doc, 0); + for event in events { + put(&mut doc, event); + } + read(&holding, &doc, 0); let cast = holding.act(); assert_eq!(cast.len(), 1); assert!(matches!( @@ -2470,6 +2487,30 @@ mod tests { holding.with(|store| store.state().current().hash), Some(next.hash()) ); + // A node starting with all of it in its document, as after a restart, held lass's + // write when it started, for however long: it backs no checkpoint leaving it out. + let record = dir.join("restarted.json"); + let mut begun = Record::begin(Id::of(&root), "makefu", &version); + begun.began = Id::of(b"before the federation").to_string(); + begun.save(&record).unwrap(); + let restarted = Holding::open( + None, + Arc::new(Files::default()), + None, + Some("makefu".into()), + ) + .unwrap() + .voting(Some(Voter { + key: makefu.key.clone(), + record, + rules: Rules { + follow: vec!["tv".to_owned()], + held_for: Duration::from_secs(3600), + ..Rules::default() + }, + })); + read(&restarted, &doc, 0); + assert_eq!(restarted.act(), Vec::<Vec<u8>>::new()); } /// Rows whose tests wait: remakes (stage 5), and flooding. |
