From 8cdde74fcdcf31414da0d22222d2cc338df20fa1 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 29 Nov 2026 15:06:04 +0000 Subject: wire: what another kind of document says, in a SYNC's body and a STATUS's stamp From version 53 on, beside Automerge's (SyncBody::Kind, HeadsSummary::Kind): a SYNC's body is one more of its shapes, another kind's bytes; a STATUS's stamp is another kind's bytes after a byte no Automerge stamp begins with. Nothing version 53 said changes, and version 52 says neither (WireError::OtherKind). Two stamps of another kind are the same where their bytes are. A node holding an Automerge document passes over a body of another kind: a peer holding one isn't let near it. --- docs/document.md | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'docs/document.md') diff --git a/docs/document.md b/docs/document.md index 17dca62..13d6cd9 100644 --- a/docs/document.md +++ b/docs/document.md @@ -336,6 +336,14 @@ upgrades node by node. A node that speaks 52 alone says no kind, and is of the k there was then; nodes of different kinds refuse each other in the handshake, saying so, and sync nothing. +What another kind says goes in the same two messages (`SyncBody::Kind`, +`HeadsSummary::Kind`): a SYNC's body is one of Automerge's, or another kind's bytes; a +STATUS's stamp is Automerge's heads, or another kind's bytes after a byte no Automerge +stamp begins with. Version 52 says neither. What a SYNC and a STATUS say beside, that +the sender is ready, when it sent, whose tree a push is along, whom it reaches, is for +every kind; the epoch, a body taken as delivered, heads announced and what vouches for +changes are Automerge's, and a node of another kind says one epoch and leaves the rest. + ### As merged state without a history would give it To see that what is asked isn't Automerge's in other words: -- cgit v1.3.1 From 232d6f19fdefe1384bdd5d4d50b39237be0575fb Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 30 Nov 2026 15:21:50 +0000 Subject: docs: a set of events as built, and in the change log --- CHANGELOG.md | 13 +++++++++++++ docs/document.md | 33 ++++++++++++++++++++++++++++++++- docs/store.md | 5 +++++ 3 files changed, 50 insertions(+), 1 deletion(-) (limited to 'docs/document.md') diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f363c4..7103cb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,19 @@ it from the release before ([`docs/operations.md`](docs/operations.md), ## Unreleased +* A swarm holding a store can hold it in a document of its own kind, a set of events, + instead of in the Automerge document: `--store-document PATH`, beside `--store-root` + or `--store-id`, names the set's file, and such a node syncs with nodes on a set and + no others. There are no changes, writers, epochs or remakes in it: events are passed + on by their names, nodes catch up by ranges of names and their fingerprints, and a + node that starts with nothing asks members for the root, or the checkpoint + `--store-checkpoint` names, by its name. What a checkpoint forgot is kept for + `--store-keeps-forgotten` (30 days). A swarm on Automerge doesn't move to it yet + ([`docs/document.md`](docs/document.md), + [A set of events](docs/document.md#a-set-of-events); + [`src/federation/store/set.rs`](src/federation/store/set.rs), + [`src/swarm/set.rs`](src/swarm/set.rs)). + * Wire version 53, spoken beside 52, so a swarm upgrades node by node: what is the document's of a message (a SYNC's body and what vouches for it, where a STATUS says the sender stands, what a BLOB request asks for in bulk) goes as bytes the wire carries diff --git a/docs/document.md b/docs/document.md index 13d6cd9..dd1a942 100644 --- a/docs/document.md +++ b/docs/document.md @@ -634,7 +634,10 @@ among nodes that don't trust each other, no cut by time holds. ## A set of events -Not built: a kind, `events`, for a swarm holding a store ([`store.md`](store.md)). The +A kind, `events`, for a swarm holding a store ([`store.md`](store.md)): built, but for +the node of both kinds a running swarm moves by +([From an Automerge document to this](#from-an-automerge-document-to-this)); a node +is of it where its operator says so ([As built](#as-built), below). The store asks nothing of what carries its events, and what makes an Automerge document carry them is most of what a swarm holding a store has to get right ([On Automerge](store.md#on-automerge)): the changes that may write an event, the @@ -729,6 +732,34 @@ What the store promises ([What is promised](store.md#what-is-promised)) it promi now; "nothing underneath adds an event or takes one away" is then true by what the document is, not by what is put again. +### As built + +A node holds its store in a set of events where it is given `--store-document`, the +set's file, beside `--store-root` or `--store-id`. It then says `events` for its kind +in its handshakes, and syncs with nodes that say so and no others. + +* **The set** ([`federation/store/set.rs`](../src/federation/store/set.rs)): the store, + and beside it what the store lets go of and the node still gives; the members' + entries ([`entry.rs`](../src/federation/store/entry.rs)); its names, kept as it + changes; its file, written where it changed, every five seconds and as the node + stops. +* **Passing on** ([`federation/store/passing.rs`](../src/federation/store/passing.rs), + [`swarm/set.rs`](../src/swarm/set.rs)): where the node stands goes in its STATUSes, + the checkpoint's and the heads' digest with the fingerprint of all its names; the + rest in SYNCs' bodies: ranges ([`document/ranges.rs`](../src/document/ranges.rs)), + heads, the names it wants, events and entries. What it took goes on to its other + neighbours at once. Nothing is kept of a peer between messages. +* **Starting**: from the file; without one, from the root, where given and no + checkpoint is pinned; else with nothing, asking the members it reaches for the + checkpoint named by the store's ID or by `--store-checkpoint`, and for the events + that one keeps, each taken as what its name says. +* **The node's own entry** is what `swarm::members` writes of a member, put as the + node's next entry; its other writes of protocol data are refused. What reads + members, the policy and the swarm's ID of a document reads them of the set + (`Holding::entries`). +* **The document the node holds beside** is an Automerge document with nothing in it: + nothing syncs it, remakes it or writes to it, and the API's `/store` holds nothing. + ### From an Automerge document to this A store is its root and its events, whatever carries them: a node of this kind reads diff --git a/docs/store.md b/docs/store.md index f1e7586..a72164c 100644 --- a/docs/store.md +++ b/docs/store.md @@ -249,6 +249,11 @@ The store's first home is a swarm's document, which continuum's sync, transports and remakes carry. A swarm holds a store from its genesis change, or not at all, and its document holds nothing but the store and continuum's protocol data. +Its other home is a document of its own kind, a set of events, where a node is given +`--store-document` ([`document.md`](document.md), [A set of events](document.md#a-set-of-events)): +there the store's events are the document, and what this section says of changes, +writers, putting again and remakes isn't. + ### What the document holds | Where | What | -- cgit v1.3.1 From 4deaec75e49b7f0853c2b82bbcce129d19dcff51 Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 30 Nov 2026 18:04:00 +0000 Subject: docs: moving a swarm holding a store to sets of events operations.md says how, step by step; document.md what is built of it; the change log that it is there. --- CHANGELOG.md | 5 ++++- docs/document.md | 26 ++++++++++++++++++++------ docs/operations.md | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 7 deletions(-) (limited to 'docs/document.md') diff --git a/CHANGELOG.md b/CHANGELOG.md index 7103cb2..abdf4c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,10 @@ it from the release before ([`docs/operations.md`](docs/operations.md), on by their names, nodes catch up by ranges of names and their fingerprints, and a node that starts with nothing asks members for the root, or the checkpoint `--store-checkpoint` names, by its name. What a checkpoint forgot is kept for - `--store-keeps-forgotten` (30 days). A swarm on Automerge doesn't move to it yet + `--store-keeps-forgotten` (30 days). A swarm on Automerge moves to it node by node, + each node for a while of both kinds (`--store-both`): it syncs with nodes of either, + and carries between them ([`docs/operations.md`](docs/operations.md), + [Moving to sets of events](docs/operations.md#moving-to-sets-of-events)) ([`docs/document.md`](docs/document.md), [A set of events](docs/document.md#a-set-of-events); [`src/federation/store/set.rs`](src/federation/store/set.rs), diff --git a/docs/document.md b/docs/document.md index dd1a942..07f25b0 100644 --- a/docs/document.md +++ b/docs/document.md @@ -634,10 +634,10 @@ among nodes that don't trust each other, no cut by time holds. ## A set of events -A kind, `events`, for a swarm holding a store ([`store.md`](store.md)): built, but for -the node of both kinds a running swarm moves by -([From an Automerge document to this](#from-an-automerge-document-to-this)); a node -is of it where its operator says so ([As built](#as-built), below). The +A kind, `events`, for a swarm holding a store ([`store.md`](store.md)): built. A node +is of it where its operator says so ([As built](#as-built), below), and a swarm on +Automerge moves to it node by node +([From an Automerge document to this](#from-an-automerge-document-to-this)). The store asks nothing of what carries its events, and what makes an Automerge document carry them is most of what a swarm holding a store has to get right ([On Automerge](store.md#on-automerge)): the changes that may write an event, the @@ -768,8 +768,22 @@ without a new federation and without a vote, by **a node of both kinds for a whi release whose node can hold the store in both at once, a member of both, and takes into each what the other holds, as it puts events again today. Operators move their nodes one at a time; once none is of the old kind, the next release drops it for a swarm -holding a store. From the release that has this kind, no swarm holding a store is -started on Automerge: one that runs there runs on, until it has moved. +holding a store. + +Built: a node given `--store-both` beside `--store-document` holds its store in the +Automerge document and in a set ([`swarm/set.rs`](../src/swarm/set.rs), +`Holding::of_both`). It takes handshakes of either kind and says to each peer the kind +that peer holds; passes the Automerge document on to the ones and its set to the +others; puts into the document what its set took of peers on sets, and passes on to +them what its set took of the document; and writes its entry in both. Its set, without +a file yet, is made of the store as the node reads it of its document, so it begins +where the document does, a checkpoint a remake left among it. Nodes on the document +alone and nodes on a set alone take none of each other's handshakes: what goes between +them goes through the nodes of both +([`operations.md`](operations.md), [Moving to sets of events](operations.md#moving-to-sets-of-events)). + +Not built: that no swarm holding a store is started on Automerge any more. One that +runs there runs on, until it has moved. ## What others do diff --git a/docs/operations.md b/docs/operations.md index e99a914..b12af28 100644 --- a/docs/operations.md +++ b/docs/operations.md @@ -155,6 +155,40 @@ A node upgrades by restarting with its files. What to know: (`automerge` in `--version`), and a release changing it says so in the change log. * **The dashboard** reloads by itself once its node serves another version of it. +## Moving to sets of events + +A swarm holding a store keeps it in the Automerge document, or in a document of the +store's own kind, a set of events ([`document.md`](document.md), +[A set of events](document.md#a-set-of-events)): no changes, writers, epochs or remakes, +and nothing to compact but by the federation's checkpoints. A running swarm moves there +node by node, the federation as it is: its root, its events and its votes are the same. + +Nodes on the document alone and nodes on a set alone don't sync with each other. Nodes +of both kinds do with either, and carry between them, so move every node through that: + +1. **Every node on a release that has sets** (`--version` says wire versions up to 53 + at least), one at a time, as any upgrade. +2. **Every node of both kinds**, one at a time: start it again with `--store-document + PATH`, a new file, and `--store-both`, everything else as it was, its + `--document-file` and `--store-file` among it. It goes on with its document, makes + its set of the store it reads there, and keeps it in the file. +3. **Every node on its set alone**, one at a time, once all are of both: start it + again without `--store-both`, `--document-file` and `--store-file`. It goes on from + the set's file. + +Between the steps, the swarm works as ever: an event put on any node reaches every +node. Within a step, it works as long as the nodes of both kinds reach each other and +every other node reaches one of them; `GET /events` on each node shows whether its +store holds what the others' hold (`heads`). + +A node that joins later is given `--store-id`, `--store-document` and seeds: with +nothing of the store, it asks the members it reaches for the root by its name, or, with +`--store-checkpoint`, for that checkpoint. + +Don't remake while nodes are of both kinds: a node of both follows a remake as any node +on the document, but that it then carries on between the two is not something a test +covers. + ## Behind a reverse proxy The HTTP API speaks plain HTTP on `127.0.0.1:3000`; a reverse proxy in front adds TLS. -- cgit v1.3.1 From 6a06bc4a955cdf2b5a183c9ff21e25c79a4e5d9f Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 30 Nov 2026 19:36:56 +0000 Subject: federation: a stopped node on a set passes on what it holds back A store that stopped at an event it can't judge holds back what comes after, and its set gave none of it to others: what was put through such a node reached nobody, and a restart lost it. The set now names what its store holds back among what it gives, passes it on at once as it does what it took, and keeps it in its file; once the store takes again, it gives of it what the store took, or refused of its own. --- docs/document.md | 4 +- docs/guides/federation/when-things-go-wrong.md | 10 +- src/federation/held.rs | 3 +- src/federation/store/memory.rs | 8 ++ src/federation/store/set.rs | 122 ++++++++++++++++++++++--- src/simtest/holding.rs | 72 +++++++++++++++ 6 files changed, 200 insertions(+), 19 deletions(-) (limited to 'docs/document.md') diff --git a/docs/document.md b/docs/document.md index 07f25b0..07d3420 100644 --- a/docs/document.md +++ b/docs/document.md @@ -667,7 +667,9 @@ held; and where the fold takes it at its history, which every node judges alike. the fold refuses there is held by nobody. One whose history takes it and that the node itself refuses or doesn't read (a node's own: what it took before, its operator's drops, where it stopped) is held and passed on all the same, as the document holds it -today: so that what one node doesn't read still reaches the nodes that do. +today: so that what one node doesn't read still reaches the nodes that do. A node that +stopped holds back what comes after, as it can't tell which of it will be taken, and +passes that on alike, until it takes again: then it holds of it what it took. What builds on such an event, the node can't judge: it holds no history to judge it at. Where nodes took different ones of two versions that changed the same, or an diff --git a/docs/guides/federation/when-things-go-wrong.md b/docs/guides/federation/when-things-go-wrong.md index 13df07d..5bd7f62 100644 --- a/docs/guides/federation/when-things-go-wrong.md +++ b/docs/guides/federation/when-things-go-wrong.md @@ -76,7 +76,7 @@ record. A node stops at a version event writing a version that passed on the version it reads, which its continuum doesn't read: of a later federation, using what a later continuum takes, or none at all. It takes nothing and refuses nothing from then on, and votes -nothing by itself or by hand; what is put through it, it holds back +nothing by itself or by hand; what is put through it, it holds back and passes on (`stopped` when put). Its log says so (`The store stopped at an event this continuum can't judge`), and `GET /events` names the event, why, and how many it holds back: @@ -103,10 +103,10 @@ curl -u tv:secret -X POST -H 'Content-Type: application/json' \ # {"dropped":["9a1e…"]} ``` -Allowed again (`/admin/events/allow`), it stops there once more. A node that stopped -keeps none of it in its set's file: restarted, it stops there again. What it holds back, -it passes on to nobody, and what was put through it since it stopped, no other node has: -put it through another node. A node keeping its store in the Automerge document puts +Allowed again (`/admin/events/allow`), it stops there once more. What a node holds back, +it leaves out of nothing, as it can't tell which will be taken: it passes it on to the +other nodes, which take it where they read that version, and keeps it in its set's file; +restarted, it stops there again. A node keeping its store in the Automerge document puts what it holds back again where its document lacks it, and a remake keeps it, so a remake while nodes are stopped loses none of what was put since. diff --git a/src/federation/held.rs b/src/federation/held.rs index c5527cb..39d6102 100644 --- a/src/federation/held.rs +++ b/src/federation/held.rs @@ -1545,7 +1545,8 @@ pub(crate) async fn write( if state.of_a_set() { let holding = Arc::clone(&state.holding); let _ = tokio::task::spawn_blocking(move || holding.offer(bytes)).await; - let held = state.holding.with(|store| store.get(&id).is_some()); + // What the set gives: taken, or held back by a store that stopped. + let held = state.holding.with_set(|set| set.get(&id).is_some()); if held == Some(true) { crate::swarm::set::wrote(state, vec![id]).await; } diff --git a/src/federation/store/memory.rs b/src/federation/store/memory.rs index 8f099be..6f4ee5d 100644 --- a/src/federation/store/memory.rs +++ b/src/federation/store/memory.rs @@ -332,6 +332,14 @@ impl Store { .map(|(id, why)| (id, why.as_str(), self.held_back.len())) } + /// The events the store holds back, stopped, in the order offered: the one it stopped + /// at, and those offered since. None while it isn't stopped. + pub(crate) fn holds_back(&self) -> impl ExactSizeIterator { + self.held_back + .iter() + .map(|(id, event)| (*id, event.bytes.as_slice())) + } + /// What the store holds back, stopped (`Fold::stops`): the events offered since, and /// those waiting for events it doesn't hold, as it can't tell which will be taken; each /// after those of its dependencies among them, by ID otherwise. Nothing while it isn't diff --git a/src/federation/store/set.rs b/src/federation/store/set.rs index b033927..d0dbe18 100644 --- a/src/federation/store/set.rs +++ b/src/federation/store/set.rs @@ -9,6 +9,8 @@ //! oldest going first: whoever mints events can mint these; //! * what a move to a checkpoint forgot, for as long as the node's operator says: a node //! still before the checkpoint builds it from them. +//! * what the store holds back, stopped at an event it can't judge (`Fold::stops`): the +//! node can't tell which of it will be taken, and a node that judges it takes it. //! //! And each member's entry (`entry`): its node's newest, and none of a node the store //! doesn't name a member as it reads now. @@ -123,6 +125,9 @@ pub(crate) struct Set { /// The unjudged among them, the oldest first, and their bytes in all. unjudged: VecDeque, unjudged_bytes: usize, + /// What the store holds back, stopped, by ID: where among what it holds back + /// (`Store::holds_back`). + held_back: BTreeMap, /// For how long what a checkpoint forgot is kept. keeps_forgotten: Duration, /// Who carries the store, as it reads now (`Fold::members`). @@ -157,6 +162,7 @@ impl Set { beside: BTreeMap::new(), unjudged: VecDeque::new(), unjudged_bytes: 0, + held_back: BTreeMap::new(), keeps_forgotten, members, entries: BTreeMap::new(), @@ -245,12 +251,13 @@ impl Set { /// document keeps as far as it gives it to others. pub(crate) fn offer(&mut self, bytes: Vec, now: Instant) -> Offered { let offered = self.store.offer(bytes); - self.settle(now); + let _ = self.settle(now); offered } /// Offers events to the store, at `now`, as `offer` does each: those the store took - /// by them, in the order taken. + /// by them, in the order taken, and those it holds back since, stopped: what the + /// document gives to others by them. pub(crate) fn offer_all( &mut self, events: impl IntoIterator>, @@ -262,7 +269,7 @@ impl Set { taken.extend(ids); } } - self.settle(now); + taken.extend(self.settle(now)); taken } @@ -289,7 +296,7 @@ impl Set { /// holds them on, for others. pub(crate) fn drop_taken(&mut self, ids: &[Id], now: Instant) -> Result, Refused> { let dropped = self.store.drop_taken(ids); - self.settle(now); + let _ = self.settle(now); dropped } @@ -317,11 +324,12 @@ impl Set { self.store.offer(bytes); } } - self.settle(now); + let _ = self.settle(now); } - /// Takes in what the store let go of. - fn settle(&mut self, now: Instant) { + /// Takes in what the store let go of, and what it holds back, stopped: the events it + /// holds back since last asked, in the order offered. + fn settle(&mut self, now: Instant) -> Vec { let took = self.store.took(); let gone = self.store.let_go(); // Who is a member is the fold's to say of the store's state, and costs what @@ -376,8 +384,42 @@ impl Set { } !held }); + let held_back = self.hold_back(); #[cfg(test)] self.check(); + held_back + } + + /// Follows what the store holds back, stopped: its names among those the document + /// gives, and those held back since last asked, in the order offered. + fn hold_back(&mut self) -> Vec { + let holds = self.store.holds_back().len(); + // The store holds back more, after what it held back: the common case. + let more = holds >= self.held_back.len() + && self.held_back.len().checked_sub(1).is_none_or(|last| { + self.store + .holds_back() + .nth(last) + .is_some_and(|(id, _)| self.held_back.get(&id) == Some(&last)) + }); + let from = if more { self.held_back.len() } else { 0 }; + if !more { + // It takes again, and may have stopped anew: what it held back, it took, + // refused, or holds back again. + for id in std::mem::take(&mut self.held_back).into_keys() { + if self.store.get(&id).is_none() && !self.beside.contains_key(&id) { + self.names.remove(&id.0); + } + } + } + let mut since = Vec::new(); + for (at, (id, _)) in self.store.holds_back().enumerate().skip(from) { + self.held_back.insert(id, at); + if self.names.insert(id.0) { + since.push(id); + } + } + since } /// Whether the store refuses `id` as the node's own, or for building on such: what @@ -423,12 +465,16 @@ impl Set { self.beside.len() != before } - /// The bytes of an event the document gives to others: one its store holds, or one - /// held beside it. + /// The bytes of an event the document gives to others: one its store holds, one + /// held beside it, or one the store holds back. pub(crate) fn get(&self, id: &Id) -> Option<&[u8]> { self.store .get(id) .or_else(|| self.beside.get(id).map(|(bytes, _)| bytes.as_slice())) + .or_else(|| { + let at = *self.held_back.get(id)?; + self.store.holds_back().nth(at).map(|(_, bytes)| bytes) + }) } /// Why the document holds `id` beside its store, where it does. @@ -436,7 +482,8 @@ impl Set { self.beside.get(id).map(|(_, why)| *why) } - /// The document as bytes, at `now`: what its file holds. All it holds but what waits + /// The document as bytes, at `now`: what its file holds, what its store holds back + /// among it. All it holds but what waits /// for what it builds on, which comes again; and what its node refuses of its own, /// which a store read anew is told before anything is offered to it. pub(crate) fn save(&self, now: Instant) -> Vec { @@ -451,6 +498,12 @@ impl Set { .iter() .filter_map(|id| self.store.get(id)) .map(|bytes| bytes.to_vec().into()) + // What the store holds back, after: offered again, it stops there again. + .chain( + self.store + .holds_back() + .map(|(_, bytes)| bytes.to_vec().into()), + ) .collect(), own: own.iter().map(|id| id.0).collect(), dropped: dropped.iter().map(|id| id.0).collect(), @@ -521,7 +574,7 @@ impl Set { for event in saved.taken { set.store.offer(event.into_vec()); } - set.settle(now); + let _ = set.settle(now); for (bytes, why) in saved.beside { let bytes = bytes.into_vec(); let id = Id::of(&bytes); @@ -543,7 +596,7 @@ impl Set { set.names.insert(id.0); set.beside.insert(id, (bytes, why)); } - set.settle(now); + let _ = set.settle(now); set.expire(now); for entry in saved.entries { if let Some(entry) = Entry::decode(&entry) { @@ -595,6 +648,7 @@ impl Set { .map(|id| id.0) .chain(self.store.kept().iter().map(|bytes| Id::of(bytes).0)) .chain(self.beside.keys().map(|id| id.0)) + .chain(self.held_back.keys().map(|id| id.0)) .chain(self.entries.values().map(Entry::name)) .collect() } @@ -998,4 +1052,48 @@ mod tests { assert!(!set.wants(&waiting[WAITS + 4].0)); assert_eq!(set.store().lacks().len(), WAITS); } + + /// What a store that stopped holds back, the document gives to others, as the node + /// can't tell which of it will be taken; its file keeps it; and once the store takes + /// again, the document gives what the store took of it and no more. + #[test] + fn what_a_stopped_store_holds_back_is_given_to_others() { + let mut set = set(); + let now = Instant::now(); + let root = set.store().id(); + let mark = taken(set.offer(testfold::put(&[root], "mark", "1"), now)); + let new = testfold::era(&[mark], 1, "new"); + let at = Id::of(&new); + let later = testfold::put(&[mark], "b", "1"); + let junk = testfold::junk(&[mark]); + let (later_id, junk_id) = (Id::of(&later), Id::of(&junk)); + // Held back, and given: by name, to catch up by, and as what was taken by them. + assert_eq!( + set.offer_all([new.clone(), later.clone(), junk.clone()], now), + vec![at, later_id, junk_id] + ); + assert!(set.store().stopped().is_some()); + for (id, bytes) in [(at, &new), (later_id, &later), (junk_id, &junk)] { + assert_eq!(set.get(&id), Some(bytes.as_slice())); + assert!(set.names().contains(&id.0)); + assert!(!set.wants(&id.0)); + } + // Offered again, nothing is given anew. + assert!(set.offer_all([later.clone()], now).is_empty()); + // Its file keeps what it holds back: read, the store stops there again. + let mut read = Set::::load(&set.save(now), KEEPS, now).expect("it reads"); + assert_eq!(read.store().stopped().map(|(id, _, _)| *id), Some(at)); + assert_eq!(read.named(), set.named()); + assert_eq!(read.get(&later_id), Some(later.as_slice())); + // Its operator has it drop the event it stopped at: what it held back is taken, + // or refused, and what is refused at its history is given no more. + read.drop_taken(&[at], now).expect("dropped"); + assert!(read.store().stopped().is_none()); + assert_eq!(read.store().taken(), &[mark, later_id]); + assert_eq!(read.get(&junk_id), None); + assert!(!read.names().contains(&junk_id.0)); + // What it dropped is the node's own, which others may take. + assert_eq!(read.beside(&at), Some(Beside::Own)); + assert!(read.names().contains(&at.0)); + } } diff --git a/src/simtest/holding.rs b/src/simtest/holding.rs index 8091cfc..8f601dd 100644 --- a/src/simtest/holding.rs +++ b/src/simtest/holding.rs @@ -1807,6 +1807,78 @@ async fn a_swarm_of_sets_passes_entries_and_events_on() { } } +/// On sets of events, a version of a federation this continuum doesn't know passes, and +/// a version event writes it: every node stops there. What is put through one of them +/// meanwhile, it holds back and passes on, as it can't tell what will be taken: the +/// others hold it back too. Their operators have them drop that event: they take again, +/// all alike. +#[tokio::test(flavor = "multi_thread", worker_threads = 4)] +async fn a_stopped_node_of_a_set_passes_on_what_it_holds_back() { + let sim = Sim::with_identity(99); + let (tv, lass, makefu) = three(); + let (first, root, id) = federation(&[(&tv, &["a"]), (&lass, &["b"]), (&makefu, &["c"])]); + let nodes: Vec = [("a", "tv"), ("b", "lass"), ("c", "makefu")] + .into_iter() + .map(|(name, party)| { + let seeds: Vec<&str> = if name == "a" { Vec::new() } else { vec!["a"] }; + let root = root.clone(); + sim.start_with( + name, + &seeds, + Start::FromDocument(Origin::Root), + move |config| { + config.store = Some(id); + config.holding = of_a_set(party, &root); + }, + ) + }) + .collect(); + let members: Vec<&AppState> = nodes.iter().collect(); + let all = &members; + sim.wait_ready(all, SOON).await; + sim.wait_until("each holds the three entries", SOON, move || async move { + all.iter().all(|node| entries(node) == 3) + }) + .await; + + let on = first.hash(); + let text = String::from_utf8(first.after(on).json().bytes()) + .expect("UTF-8") + .replace(r#""federation":1"#, r#""federation":2"#); + let unknown = crate::federation::jcs::read(text.as_bytes()).expect("JCS"); + let hash = Id::of(&unknown.bytes()); + let proposal = tv.propose(&[id], &unknown); + let votes = [&tv, &lass].map(|party| party.vote(&[Id::of(&proposal)], on, hash, true)); + let written = harness::version_event(&[Id::of(&votes[0]), Id::of(&votes[1])], hash); + let at = Id::of(&written); + put(all[0], &[&proposal, &votes[0], &votes[1], &written]).await; + sim.wait_until("every node stopped there", LONG, move || async move { + all.iter().all(|node| stopped(node) == Some(at)) + }) + .await; + + let meanwhile = tv.write(&[id], "home/tv/a", s("1")); + put(all[0], &[&meanwhile]).await; + let meanwhile = Id::of(&meanwhile); + sim.wait_until("every node holds it back", LONG, move || async move { + all.iter() + .all(|node| holds_back(node, &[at, meanwhile], false)) + }) + .await; + + for node in all.iter() { + let dropped = node.holding.drop_taken(&[at]).expect("a store"); + assert_eq!(dropped, Ok(vec![at])); + } + sim.wait_until("every node takes again", LONG, move || async move { + all.iter() + .all(|node| stopped(node).is_none() && holds(node, &[meanwhile])) + }) + .await; + let read: Vec> = all.iter().map(|node| counts(node)).collect(); + assert!(read.iter().all(|counts| counts == &read[0]), "{read:?}"); +} + /// Starts `name`, of `party`, on a set of events `set`, kept in the file at `path` where /// given: the first of them with no seed, the others seeded by `a`. fn start_on_a_set( -- cgit v1.3.1