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') 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') 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') 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 51ad13145e729142e0ee11ace42aa6f55533c710 Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 30 Nov 2026 18:24:23 +0000 Subject: scripts/sets-check: a federation moved to sets of events, in real nodes Three nodes of two parties over libp2p on loopback: on the Automerge document, each started again of both kinds, then on its set alone, then all at once from their sets' files, and a fourth joining with the store's ID alone. After each start a value written through the party's client at one node is read at every node, with all written before; no node logs an error. --- docs/development.md | 9 +++ scripts/sets-check | 219 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 228 insertions(+) create mode 100755 scripts/sets-check (limited to 'docs') diff --git a/docs/development.md b/docs/development.md index 0e98af2..7a8f7e6 100644 --- a/docs/development.md +++ b/docs/development.md @@ -144,6 +144,15 @@ tag's nodes log this tree's as such, so their operators know to upgrade. scripts/wire-check v0.0.1 ``` +`scripts/sets-check` runs a federation of this tree on this host, over libp2p on +loopback, and moves it from Automerge documents to sets of events as its operators +would ([`operations.md`](operations.md), +[Moving to sets of events](operations.md#moving-to-sets-of-events)): three nodes of +two parties on the document, each started again of both kinds, then on its set alone, +then all at once from their sets' files, and a fourth joining with the store's ID +alone. After each start a value written through the party's client at one node is +read at every node, with all that was written before, and no node logs an error. + A change to the wire format is a new version (`wire::VERSION`) beside the ones the build speaks already: the messages of the version before keep their types, frozen, and are encoded and decoded in `transport/wire.rs` beside the newest's, and `golden_bytes` keeps diff --git a/scripts/sets-check b/scripts/sets-check new file mode 100755 index 0000000..8deb7fe --- /dev/null +++ b/scripts/sets-check @@ -0,0 +1,219 @@ +#!/bin/sh +# Runs a federation of this tree's continuum on this host, over libp2p on loopback, and +# moves it from Automerge documents to sets of events node by node, as its operators +# would (docs/operations.md: Moving to sets of events), through the nodes' API and the +# party's client all along: +# +# * a and b of tv, c of lass, each holding the store in its Automerge document; +# * each started again of both kinds (--store-document, --store-both); +# * each started again on its set alone; +# * all stopped, and started from their sets' files; +# * d, which tv lists then, joining with nothing but the store's ID. +# +# After each start, a value written at one node is read at every other, and what was +# written before is still read. No node logs an error. +# +# scripts/sets-check +# +# Built with CONTINUUM_FEATURES (`most` unless given; libp2p and federation among +# them). The nodes listen from CONTINUUM_SETS_CHECK_PORT on (47700 unless given), eight +# ports. + +set -eu + +cd "$(git rev-parse --show-toplevel)" + +features=${CONTINUUM_FEATURES:-most} +port=${CONTINUUM_SETS_CHECK_PORT:-47700} +say() { echo "sets-check: $*" >&2; } + +work=$(mktemp -d) +failed=false +clean() { + for pid in "$work"/*/pid; do + [ -f "$pid" ] && kill "$(cat "$pid")" 2>/dev/null || true + done + wait 2>/dev/null || true + if $failed; then + for log in "$work"/*/log; do + [ -f "$log" ] || continue + say "the last of $(basename "$(dirname "$log")")'s log:" + tail -n 25 "$log" >&2 + done + fi + rm -rf "$work" +} +trap clean EXIT +trap 'exit 130' INT TERM +fail() { + failed=true + say "$*" + exit 1 +} + +say "building this tree (features $features)" +cargo build -q --features "$features" --bin continuum --bin continuum-party +bin=${CARGO_TARGET_DIR:-$(pwd)/target}/debug +node=$bin/continuum +party=$bin/continuum-party + +number() { # NAME: a 0, b 1, c 2, d 3 + case $1 in a) echo 0 ;; b) echo 1 ;; c) echo 2 ;; d) echo 3 ;; esac +} +http() { echo $((port + $(number "$1"))); } +p2p() { echo $((port + 4 + $(number "$1"))); } +seed() { echo "libp2p:/ip4/127.0.0.1/tcp/$(p2p "$1")"; } +party_of() { + case $1 in c) echo lass ;; *) echo tv ;; esac +} + +# Keys of the parties, and of the nodes, whose IDs the first version names. +for name in tv lass; do + ssh-keygen -q -t ed25519 -N '' -f "$work/$name.key" +done +for name in a b c d; do + mkdir "$work/$name" + "$node" node-id --create "$work/$name/node.key" >"$work/$name/id" 2>/dev/null +done +id_of() { tail -n 1 "$work/$1/id"; } +"$party" found --name sets-check "tv=$work/tv.key.pub" "lass=$work/lass.key.pub" \ + --nodes "tv=$(id_of a),$(id_of b)" --nodes "lass=$(id_of c)" >"$work/first.json" +"$party" root "$work/first.json" >"$work/root" +# The store's ID: the SHA-256 of the root, the file's first line. +store=$(printf '%s' "$(head -n 1 "$work/root")" | sha256sum | cut -d' ' -f1) +# Each party's record of its votes, which its client writes by. +for name in tv lass; do + "$party" --record "$work/$name.record" init "$name" --root "$work/root" >/dev/null +done +say "the federation $store: a and b of tv, c of lass" + +start() { # NAME [OPTION...]: the node, with what every start of it has + name=$1 + shift + (cd "$work/$name" && exec "$node" --bind-addr "127.0.0.1:$(http "$name")" \ + --user-header X-User --node-key-file node.key --state-file state.json \ + --libp2p-enable --libp2p-listen "/ip4/127.0.0.1/tcp/$(p2p "$name")" \ + --store-party "$(party_of "$name")" "$@" >>log 2>&1) & + echo $! >"$work/$name/pid" +} +stop() { # NAME + kill "$(cat "$work/$1/pid")" 2>/dev/null || true + wait "$(cat "$work/$1/pid")" 2>/dev/null || true + rm -f "$work/$1/pid" +} +# Whether the command $2... succeeds within $1 seconds, tried every second. +within() { + seconds=$1 + shift + while ! "$@" >/dev/null 2>&1; do + seconds=$((seconds - 1)) + [ "$seconds" -gt 0 ] || return 1 + sleep 1 + done +} +ready() { curl -sf "http://127.0.0.1:$(http "$1")/ready"; } +# The party's client at a node, as that node's party: it logs in by the party's key. +client() { # NAME COMMAND... + name=$1 + shift + "$party" --node "http://127.0.0.1:$(http "$name")" \ + --key "$work/$(party_of "$name").key" \ + --record "$work/$(party_of "$name").record" "$@" +} +reads() { # NAME PATH VALUE: whether the node reads the value there + [ "$(client "$1" read "$2" 2>/dev/null)" = "$3" ] +} +written="" +# Writes a value at NAME, as its party, and waits until every node of $nodes reads it, +# and everything written before. +write_and_read() { # NAME KEY + path="home/$(party_of "$1")/$2" + within 30 client "$1" write "$path" "\"$2\"" || { + client "$1" write "$path" "\"$2\"" >&2 || true + fail "$1 takes no write at $path" + } + written="$written $path=$2" + for at in $nodes; do + for pair in $written; do + within 60 reads "$at" "${pair%%=*}" "\"${pair##*=}\"" || + fail "$at doesn't read ${pair%%=*} (written at $1)" + done + done + say "written at $1, read at$(printf ' %s' $nodes): $path" +} +kind() { # NAME: the kinds the node says it holds, as its log has them + grep -c "as a set of events\|Going on with the store's document\|Begun the store's set" \ + "$work/$1/log" || true +} + +# On the Automerge document: a from the root, b and c by the store's ID. +automerge() { # NAME + case $1 in + a) start a --store-root "$work/root" --store-file store.json --document-file document ;; + *) start "$1" --store-id "$store" --store-file store.json --document-file document \ + --seeds "$(seed a)" ;; + esac +} +nodes="a b c" +for name in $nodes; do + automerge "$name" + within 60 ready "$name" || fail "$name isn't ready on its Automerge document" +done +write_and_read a first +write_and_read c second + +# Of both kinds, one at a time, everything else as it was. +for name in $nodes; do + stop "$name" + case $name in + a) start a --store-root "$work/root" --store-file store.json --document-file document \ + --store-document set.events --store-both ;; + *) start "$name" --store-id "$store" --store-file store.json --document-file document \ + --seeds "$(seed a)" --store-document set.events --store-both ;; + esac + within 60 ready "$name" || fail "$name isn't ready of both kinds" + write_and_read "$name" "both-$name" +done +for name in $nodes; do + within 30 test -s "$work/$name/set.events" || fail "$name wrote no file of its set" +done + +# On its set alone, one at a time, from the set's file. +alone() { # NAME + case $1 in + a) start a --store-id "$store" --store-document set.events --seeds "$(seed b)" ;; + *) start "$1" --store-id "$store" --store-document set.events --seeds "$(seed a)" ;; + esac +} +for name in $nodes; do + stop "$name" + alone "$name" + within 60 ready "$name" || fail "$name isn't ready on its set alone" + write_and_read "$name" "set-$name" +done + +# All down, and up again from their sets' files. +for name in $nodes; do + stop "$name" +done +for name in $nodes; do + alone "$name" +done +for name in $nodes; do + within 60 ready "$name" || fail "$name isn't ready again" +done +write_and_read b again + +# A node tv lists then, with nothing but the store's ID. +client a nodes --add "$(id_of d)" >/dev/null 2>&1 || fail "tv doesn't list d" +start d --store-id "$store" --store-document set.events --seeds "$(seed a)" +within 60 ready d || fail "d isn't ready: it didn't begin its set from what members gave" +nodes="a b c d" +write_and_read d joined + +if grep -l ' ERROR \|panicked' "$work"/*/log >/dev/null 2>&1; then + failed=true + grep -h ' ERROR \|panicked' "$work"/*/log | head -n 10 >&2 + fail "a node logged an error" +fi +say "moved to sets of events, node by node: every write read everywhere, at every step" -- cgit v1.3.1 From 3bc200a2fdae7b928c68b4a1f8bfee9a919e8ff8 Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 30 Nov 2026 19:22:34 +0000 Subject: docs: the federation guides, on sets of events A federation starts on sets (--store-document); what is of the Automerge document alone (the store file, putting again, remakes, a pinned checkpoint found in the document) is said apart, for federations that keep their store there until they moved. --- docs/guides/federation/README.md | 6 +- docs/guides/federation/building-on-the-api.md | 5 +- docs/guides/federation/checkpoints.md | 17 +-- docs/guides/federation/forking-and-following.md | 2 +- docs/guides/federation/getting-started.md | 25 +++-- docs/guides/federation/promises.md | 7 +- docs/guides/federation/refusals-and-drops.md | 25 +++-- docs/guides/federation/remakes.md | 7 ++ docs/guides/federation/running-a-node.md | 132 ++++++++++++++++-------- docs/guides/federation/upgrades.md | 8 +- docs/guides/federation/watching.md | 6 +- docs/guides/federation/when-things-go-wrong.md | 22 ++-- 12 files changed, 167 insertions(+), 95 deletions(-) (limited to 'docs') diff --git a/docs/guides/federation/README.md b/docs/guides/federation/README.md index 104a04c..c9b0205 100644 --- a/docs/guides/federation/README.md +++ b/docs/guides/federation/README.md @@ -28,9 +28,9 @@ by them, in its words. * [`voting-by-itself.md`](voting-by-itself.md): a node voting and proposing for its party by its operator's rules: its key, its record, following, proposing checkpoints. * [`refusals-and-drops.md`](refusals-and-drops.md): what a node refuses and what of it - is its own, the store file, dropping events and taking them back. -* [`remakes.md`](remakes.md): compactions only, the electorate, the snapshot, putting - again after a switch, two epochs for one, and rejoining. + is its own, what is kept across restarts, dropping events and taking them back. +* [`remakes.md`](remakes.md): in the Automerge document, compactions only, the electorate, + the snapshot, putting again after a switch, two epochs for one, and rejoining. * [`upgrades.md`](upgrades.md): upgrading the nodes of a federated swarm, what the federation's number and its revision say, and moving to a later revision. * [`watching.md`](watching.md): what a node's API and its log say that needs an operator diff --git a/docs/guides/federation/building-on-the-api.md b/docs/guides/federation/building-on-the-api.md index 45394ed..1f01954 100644 --- a/docs/guides/federation/building-on-the-api.md +++ b/docs/guides/federation/building-on-the-api.md @@ -91,5 +91,6 @@ already: a write is an event every node keeps until a checkpoint leaves it out. ## Not through the store API -A node of a federated swarm refuses writes through the store API (`/store`): the document -takes events and each node's own protocol data only. +A node of a federated swarm refuses writes through the store API (`/store`), which holds +nothing of the store where it is a set of events: a federation takes events and each +node's own protocol data only. diff --git a/docs/guides/federation/checkpoints.md b/docs/guides/federation/checkpoints.md index 072fc80..12d08a9 100644 --- a/docs/guides/federation/checkpoints.md +++ b/docs/guides/federation/checkpoints.md @@ -114,10 +114,15 @@ Votes and proposals aren't signed again: their version is behind. ## Nodes that weren't there -A node reads its store at every start from its document's checkpoint, or from the one -its operator pins (`--store-checkpoint`), which it finds in its document. Until a remake -leaves out what a checkpoint forgot, the document holds what came before, and a node -that was away builds the checkpoint from it as any. After such a remake, a node away -across it, or joining, takes the checkpoint only where its operator pins it: ask a node -you trust for it (`checkpoint` in `GET /events`) +A node that was away across a move builds the checkpoint itself, as any: the others keep +what the checkpoint forgot for a while (`--store-keeps-forgotten`, 30 days unless +given), and give it what it lacks. A node away for longer, or joining, starts from the +checkpoint only where its operator pins it (`--store-checkpoint`), with nothing of the +store yet: ask a node you trust for it (`checkpoint` in `GET /events`) ([`running-a-node.md`](running-a-node.md), [Joining](running-a-node.md#joining)). + +A node keeping its store in the Automerge document reads it at every start from its +document's checkpoint, or from the one its operator pins, which it finds in its +document. Until a remake leaves out what a checkpoint forgot, the document holds what +came before, and a node that was away builds the checkpoint from it; after such a +remake, it takes the checkpoint only where its operator pins it. diff --git a/docs/guides/federation/forking-and-following.md b/docs/guides/federation/forking-and-following.md index 63b7c40..441f4f9 100644 --- a/docs/guides/federation/forking-and-following.md +++ b/docs/guides/federation/forking-and-following.md @@ -48,7 +48,7 @@ go. The rules are the design's ([`federation.md`](../../federation.md), `--at 4a1d 9e30` names the heads for the others. The fork is named by its root's ID, the SHA-256 of its root (the file's first line), which nobody can steer. 4. **Start it**: a node carries one swarm, so the founders start the fork's nodes with - files of their own (state, document, store file), from the root + files of their own (state, the set of events), from the root (`--store-root fork-root`), or by its ID through one of them (`--store-id`), each with its party (`--store-party`). 5. **Begin a record there**: a fork is a store of its own, and a party that never voted diff --git a/docs/guides/federation/getting-started.md b/docs/guides/federation/getting-started.md index 33f9181..8b7e5f3 100644 --- a/docs/guides/federation/getting-started.md +++ b/docs/guides/federation/getting-started.md @@ -107,11 +107,12 @@ Keep it: a party that loses its record casts nothing on the current version ## Starting -tv's node starts the federation from the root: +tv's node starts the federation from the root, and holds it in a set of events, kept in +a file (`--store-document`): ```sh -continuum --store-root root --store-party tv --store-file store.json \ - --state-file state.json --document-file document --node-key-file node.key \ +continuum --store-root root --store-party tv --store-document events \ + --state-file state.json --node-key-file node.key \ --htpasswd htpasswd --mycelium-enable curl -s -u tv:secret localhost:3000/events # {"checkpoint":"6d1e…","heads":["6d1e…"],"party":"tv","store":"6d1e…","taken":0, @@ -122,15 +123,21 @@ lass's node joins it by its ID, through tv's node, one of whose addresses it is (`addresses` in `GET /admin/stats` there): ```sh -continuum --store-id 6d1e… --store-party lass --store-file store.json \ - --seeds mycelium:… --state-file state.json --document-file document \ +continuum --store-id 6d1e… --store-party lass --store-document events \ + --seeds mycelium:… --state-file state.json \ --node-key-file node.key --htpasswd htpasswd --mycelium-enable ``` -Nodes sync with the nodes the parties list, and with no others: both are in the first -version. A party lists another node of its own by itself, without a vote +It asks tv's node for the root by its ID, and for everything after. Nodes sync with the +nodes the parties list, and with no others: both are in the first version. A party lists +another node of its own by itself, without a vote ([`common-changes.md`](common-changes.md#what-a-party-does-by-itself)). +A federation that keeps its store in the Automerge document (`--document-file`, +`--store-file`, no `--store-document`) goes on so, and moves to sets of events node by +node ([`operations.md`](../../operations.md), +[Moving to sets of events](../../operations.md#moving-to-sets-of-events)). + ## Writing and reading tv writes in its namespace, through its node: @@ -209,8 +216,8 @@ continuum-party --node http://lass:secret@localhost:3000 --key lass.key \ Once a node holds both votes, it writes the version, and every node takes it: `continuum-party status` says version 1. makefu's node, started with -`--store-id 6d1e… --store-party makefu` and a seed, is a member now: the others sync -with it, and makefu writes in its namespace as tv did. +`--store-id 6d1e… --store-party makefu --store-document events` and a seed, is a member +now: the others sync with it, and makefu writes in its namespace as tv did. ## What next diff --git a/docs/guides/federation/promises.md b/docs/guides/federation/promises.md index 733c713..c6ba2eb 100644 --- a/docs/guides/federation/promises.md +++ b/docs/guides/federation/promises.md @@ -40,8 +40,9 @@ to whom. A party whose machine is taken over whole is the adversary from then on * **Good votes**: a party may vote badly; a `true` binds it while its proposal can pass, and only other parties' nays free it: parties that never vote hold it there. * **Delivery**: what a party's nodes withhold reaches nobody through them. -* **Speed and uptime**: a party that floods the store, or keeps remakes from committing, - makes nodes slow or runs them out of memory, never wrong. The others fork away from it. +* **Speed and uptime**: a party that floods the store, or, where it is kept in the + Automerge document, keeps remakes from committing, makes nodes slow or runs them out of + memory, never wrong. The others fork away from it. * **One swarm where keys voted twice**: each node keeps the version it took, and nodes part, until their operators choose ([`when-things-go-wrong.md`](when-things-go-wrong.md)). @@ -59,7 +60,7 @@ to whom. A party whose machine is taken over whole is the adversary from then on ([`keys.md`](keys.md), [`proposing-and-voting.md`](proposing-and-voting.md)); vote from one client; back only what you mean to, as a `true` binds. * **An operator**: give your node seeds you trust, pin checkpoints you got from nodes you - trust, and keep its store file ([`running-a-node.md`](running-a-node.md)). + trust, and keep the file of its set ([`running-a-node.md`](running-a-node.md)). * **An application**: read from a node you trust, as what it answers is its word; check the events yourself where that matters ([`writing-and-reading.md`](writing-and-reading.md), diff --git a/docs/guides/federation/refusals-and-drops.md b/docs/guides/federation/refusals-and-drops.md index 1d29df1..40f37de 100644 --- a/docs/guides/federation/refusals-and-drops.md +++ b/docs/guides/federation/refusals-and-drops.md @@ -26,17 +26,21 @@ curl -s -u tv:secret localhost:3000/events/refused or larger than it allows), `judged` (refused at its history), `builtOn` (built on `on`, refused), `notAbove` (not above the checkpoint's heads, as a move refuses it). -A change of another node that a node refuses doesn't take its events with it: the store -takes them as from anywhere (`Took events a refused change carried`), and the node puts -them again. - ## Kept across restarts -A node reads its store anew from its document at every start; what it refused of its -own, and what it dropped, it keeps in its store file (`--store-file`), written whenever -it changes. Without the file, a restart may take what it refused; a file that doesn't -read stops the node from starting; one it can't write it logs (`Couldn't write the store -file`). +What a node refused of its own, and what it dropped, is in its set's file +(`--store-document`) with the events, written where the set changed, every five seconds +and as the node stops; started again, the node goes on from it. Without the file, the +node joins anew, and may take what it refused; a file that doesn't read stops the node +from starting; one it can't write it logs (`Couldn't write the store's document`). + +A node keeping its store in the Automerge document reads it anew from that document at +every start, and keeps what it refused of its own and what it dropped in its store file +(`--store-file`), written whenever it changes: without it, a restart may take what it +refused, and one that doesn't read stops the node from starting (`Couldn't write the +store file`, where it can't write it). A change of another node that such a node refuses +doesn't take its events with it: the store takes them as from anywhere (`Took events a +refused change carried`), and the node puts them again. ## Dropping @@ -57,7 +61,8 @@ events from whoever brings them, and any version event naming a version among th whoever wrote it anew; it writes none itself, though it holds the votes passing it, and keeps so across restarts. Not what its checkpoint keeps or holds by ID: every event after it builds on that. A move to a checkpoint is undone -only by a checkpoint its operator pins (`--store-checkpoint`). +only by starting from a checkpoint its operator pins (`--store-checkpoint`), anew +([`running-a-node.md`](running-a-node.md), [Joining](running-a-node.md#joining)). ## Taking back diff --git a/docs/guides/federation/remakes.md b/docs/guides/federation/remakes.md index 05c27ab..5897ba4 100644 --- a/docs/guides/federation/remakes.md +++ b/docs/guides/federation/remakes.md @@ -1,5 +1,12 @@ # Remakes under a federation +A node holding its store in a set of events (`--store-document`) has nothing to remake: +it holds no changes, no writers and no epochs, and what it holds shrinks by the +federation's checkpoints alone ([`checkpoints.md`](checkpoints.md)). This guide is for a +federation that keeps its store in the Automerge document, until it moved +([`operations.md`](../../operations.md), +[Moving to sets of events](../../operations.md#moving-to-sets-of-events)). + A remake moves a swarm to a new document, for Automerge's sake only: the store needs none, and its events stay what they are. A federated swarm takes compactions only. How a remake runs is as in any swarm ([`remakes.md`](../../remakes.md)); this guide says what is diff --git a/docs/guides/federation/running-a-node.md b/docs/guides/federation/running-a-node.md index 27ee3a0..2392578 100644 --- a/docs/guides/federation/running-a-node.md +++ b/docs/guides/federation/running-a-node.md @@ -1,29 +1,37 @@ # Running a node of a federation -A node of a federated swarm runs as any continuum node: its node key, its state and -document files, its transports, a supervisor ([`operations.md`](../../operations.md)). -This guide says what is otherwise: the options of a swarm holding a store, who syncs, -what its API lets in, and joining. +A node of a federated swarm runs as any continuum node: its node key, its state file, +its transports, a supervisor ([`operations.md`](../../operations.md)). This guide says +what is otherwise: the options of a swarm holding a store, who syncs, what its API lets +in, and joining. + +A node holds its store in a set of events, kept in a file (`--store-document`), which +this guide describes; or in the Automerge document any swarm syncs, as federations +started before sets did, and do until they move +([In the Automerge document](#in-the-automerge-document), below). Nodes of the one and +nodes of the other don't sync with each other. ## Its options * `--store-root FILE` starts the swarm from its root, or goes on with it: the file the founders made (`continuum-party root`), the root on its first line and, for a fork, - the events the root keeps, a line each. The node builds the changes founding the - swarm from it, as every node given the file builds them, and is ready at once. -* `--store-id ID` joins the swarm by its ID, the root's SHA-256, through `--seeds`. - Joining with an empty document, the node takes as its root that store's genesis change - only. + the events the root keeps, a line each. The node begins its set from it, as every + node given the file does, and is ready at once. +* `--store-id ID` joins the swarm by its ID, the root's SHA-256, through `--seeds` + ([Joining](#joining), below). * `--store-party NAME`, which both need: the party the node is of, named in its entry and its handshakes. It is a member once that party's node list names it ([Who syncs](#who-syncs)). -* `--store-file PATH`: what is the node's own, written whenever it changes: the events - it refused by what it took before (of two versions changing one, the second it judged) - and those its operator had it drop. A node reads its store anew from its document - whenever it starts: without the file, it may then take what it refused. Keep it beside - the document file; one that doesn't read stops the node from starting. -* `--store-checkpoint ID`: a checkpoint the node reads its store from whenever it starts, - instead of from the document's checkpoint, by its ID ([Joining](#joining), below). +* `--store-document PATH`: the file of the node's set of events, written where the set + changed, every five seconds and as the node stops: the store's events, what the node + refused by what it took before (of two versions changing one, the second it judged), + what its operator had it drop, and the members' entries. Started again, the node goes + on from it. One that doesn't read, or is of another store, stops the node from + starting. +* `--store-checkpoint ID`: the checkpoint a node joining with nothing begins its set + from, instead of the root, by its ID ([Joining](#joining), below). +* `--store-keeps-forgotten DURATION` (30 days unless given): for how long the node keeps + what a checkpoint its store moved to forgot, for nodes still before that checkpoint. * `--store-neighbour-parties NAME,…`: parties among whose members, with its own party's, the node keeps some of its neighbours. * `--store-vote-key PATH` and the options with it: the node votes and proposes for its @@ -37,10 +45,11 @@ node refuses to start with them. ## Its files Beside those of every node ([`lifecycle.md`](../../lifecycle.md), -[What the files are for](../../lifecycle.md#what-the-files-are-for)), the store file. Back -up the node key, as every node's: its node ID is what its party lists, and a new key is a -new node, which the party lists anew. The document file and the store file go together: -the store file says what the node refuses of what the document holds. +[What the files are for](../../lifecycle.md#what-the-files-are-for)), the file of its +set, and no document file: the document a swarm syncs otherwise stays empty. Back up the +node key, as every node's: its node ID is what its party lists, and a new key is a new +node, which the party lists anew. Back up the set's file too: a node without it joins +anew, and may then take what it refused. ## Who syncs @@ -90,50 +99,83 @@ alone, so that a party listing many nodes can't be all of a node's neighbours. (whether it takes a `true` a party is about to cast); and its operator's: `POST /admin/events/drop`, `/admin/events/allow`, `/admin/events/vote`, `/admin/events/fork`. Each answers `404` while the node holds no store. -* **The store API** (`/store`) reads the document, where events are bytes at - `_continuum/events/`; what counts is read at `GET /events/counts`. A write through - it is refused (`403`): the document takes events and each node's own protocol data - only. +* **The store API** (`/store`) holds nothing: events are read at `GET /events/{id}`, + what counts at `GET /events/counts`. A write through it is refused (`403`): the set + takes events and each node's own entry only. So is a remake (`/admin/remakes`, `400`: + `this node's document is a set of events: there is nothing to remake`). ## Joining -A node with an empty document joins by the store's ID (`--store-id`) through a member -(`--seeds`), and holds its store once it has read the document: `GET /events` answers -then. It learns of other members as it syncs, and needs none of its seeds once it has: -they may go away. Before a checkpoint passed, it reads from the root: of two versions -changing one, which keys voting twice wrote, it takes the first it judges, as any node, -and reports the other (`own` in `GET /events/refused`), for you to choose +A node with nothing of the store joins by its ID (`--store-id`) through a member +(`--seeds`): it asks the members it reaches for the root by its ID, takes what hashes to +it, and holds its store then (`Begun the store's set from what peers gave by name`): +`GET /events` answers. Everything after it catches up on as it syncs. It learns of other +members so, and needs none of its seeds once it has: they may go away. Before a +checkpoint passed, it reads from the root: of two versions changing one, which keys +voting twice wrote, it takes the first it judges, as any node, and reports the other +(`own` in `GET /events/refused`), for you to choose ([`when-things-go-wrong.md`](when-things-go-wrong.md)). Once the store moved to a checkpoint, a node joining starts from that checkpoint, which its operator pins by its ID (`--store-checkpoint`): ask a node you trust for it -(`checkpoint` in `GET /events`). The node finds it in its document, built from what the -document holds as any node builds it, and holds no store until then (`The pinned -checkpoint isn't in the document (yet)`). It takes no epoch whose snapshot holds a -checkpoint it neither builds nor has pinned: from the root, it would take what was grown -anew from it since, by keys of versions long replaced. - -A node that was away across a move to a checkpoint builds that checkpoint from its -document, which holds what came before until a remake leaves it out; after such a remake, -it takes the checkpoint only where its operator pins it. Pin it, and restart the node. +(`checkpoint` in `GET /events`). The node asks the members it reaches for the checkpoint +by that ID, and for the events it keeps, and holds no store until it has them all. From +the root, it would take what was grown anew from it since, by keys of versions long +replaced. The pin counts only while the node has no file of its set: with one, it goes on +from there. + +A node that was away across a move to a checkpoint builds that checkpoint itself, from +what the others keep of what the checkpoint forgot (`--store-keeps-forgotten`). Away for +longer than they keep it, it stays before the checkpoint, and the others refuse what it +writes: start it anew, without its set's file and with the checkpoint pinned. It then +holds none of what it refused of its own or dropped +([`refusals-and-drops.md`](refusals-and-drops.md)). ## What it writes by itself * **A version that passed**, as soon as it holds the votes passing it (`Writing a version that passed`): any node may write it, and the same version written by several is one. -* **Events its document lacks**, that its store would take and that it has: after a - remake, a rejoin, or a change of another node it refused (`Put again events the - document lacked`). * **Merge events**, under a revision with them, where its party lists it and its store holds more heads than an event may name (64): signed with its node key, a random wait after there first were (`Merged heads beyond what an event may name`). They count for nothing, and gather the heads apart, so that what is written after builds on them all. -* **Its own protocol data**: its entry, its acks of remakes, and the remakes it - coordinates. Remakes are compactions only, acked by the members - ([`remakes.md`](../../remakes.md)). +* **Its own entry**: where it is reached, its party, and what else a member says of + itself, signed with its node key and counted, the latest taken. It refuses events as every node does, and some by what it took before: of two versions changing the one it reads, the second it judged (`Refused an event its history takes, by what this node took before: kept so`). `GET /events/refused` lists them apart (`own`): tell its party, which decides what the node keeps. + +## In the Automerge document + +A federation started before sets of events keeps its store in the document every swarm +syncs: its nodes run without `--store-document`, and move there node by node, through +`--store-both` ([`operations.md`](../../operations.md), +[Moving to sets of events](../../operations.md#moving-to-sets-of-events)). Until then, +what is otherwise at such a node: + +* **Its options and files**: `--document-file`, as any node's, and `--store-file PATH`, + what is the node's own, written whenever it changes: the events it refused by what it + took before, and those its operator had it drop. The node reads its store anew from + its document whenever it starts: without the store file, it may then take what it + refused. The two go together; a store file that doesn't read stops the node from + starting. +* **Starting and joining**: given the root, the node builds the changes founding the + swarm from it; joining with an empty document, it takes as its root that store's + genesis change only, and holds its store once it has read the document. A pinned + checkpoint (`--store-checkpoint`) it finds in its document, built from what the + document holds, at every start, and holds no store until then (`The pinned checkpoint + isn't in the document (yet)`). +* **A node that was away** across a move to a checkpoint builds it from its document, + which holds what came before until a remake leaves it out; after such a remake, it + takes the checkpoint only where its operator pins it. Pin it, and restart the node. +* **The store API** (`/store`) reads the document, where events are bytes at + `_continuum/events/`; a write through it is refused (`403`): the document takes + events and each node's own protocol data only. +* **What it writes by itself** besides: events its document lacks, that its store would + take and that it has, after a remake, a rejoin, or a change of another node it refused + (`Put again events the document lacked`); and its acks of remakes, and the remakes it + coordinates. Remakes are compactions only, acked by the members + ([`remakes.md`](remakes.md)). diff --git a/docs/guides/federation/upgrades.md b/docs/guides/federation/upgrades.md index 92cedc4..4cec3af 100644 --- a/docs/guides/federation/upgrades.md +++ b/docs/guides/federation/upgrades.md @@ -12,10 +12,10 @@ A node of a federated swarm upgrades as any node does restarted with its files, and a release's version says how: a patch or a minor release one node at a time, a major one every node close together. Nodes write each other the newest wire version both speak; where two releases share none, a major one, upgraded nodes and -the others don't talk, and the swarm is split until all are upgraded. A remake needs the -same Automerge on every node, and one with another rejoins instead of switching. Before -1.0.0, the first part of the version that isn't 0 counts as the major one (`0.2.0` after -`0.1.1` is a flag day). +the others don't talk, and the swarm is split until all are upgraded. Where the store is +kept in the Automerge document, a remake needs the same Automerge on every node, and one +with another rejoins instead of switching. Before 1.0.0, the first part of the version +that isn't 0 counts as the major one (`0.2.0` after `0.1.1` is a flag day). Nobody runs every node of a federated swarm: each party's operators upgrade its nodes. A patch or minor release each party takes when it likes; for a major one, agree on when, diff --git a/docs/guides/federation/watching.md b/docs/guides/federation/watching.md index a60b1ab..f3e8ccb 100644 --- a/docs/guides/federation/watching.md +++ b/docs/guides/federation/watching.md @@ -107,10 +107,12 @@ At warn or error: takes events again` once its operator had it drop that event; * `This node isn't a member of its store, as it reads now: its party doesn't list it, and members don't sync with it`; -* `The pinned checkpoint isn't in the document (yet): holding no store until it is`; +* `The pinned checkpoint isn't in the document (yet): holding no store until it is`, at + a node keeping its store in the Automerge document; * `The document's root is no store's: not reading it`, `Reading the store from the document failed`; -* `Couldn't write the store file: a restart may take what this node refused`: a full or +* `Couldn't write the store's document: a restart goes on from what the file holds`, + `Couldn't write the store file: a restart may take what this node refused`: a full or read-only disk; * `Couldn't vote by itself`, `Voting by itself, without its party's record: votes none`; * `Couldn't put what it signed for its party: put again later`, `Couldn't write a version diff --git a/docs/guides/federation/when-things-go-wrong.md b/docs/guides/federation/when-things-go-wrong.md index 8326f72..13df07d 100644 --- a/docs/guides/federation/when-things-go-wrong.md +++ b/docs/guides/federation/when-things-go-wrong.md @@ -11,7 +11,7 @@ rules are the design's ([`federation.md`](../../federation.md), Two versions changing one are written only where keys voted twice: a party's `true` and `false` on one proposal, each shown to some, or its `true` on two. Each node takes the first it judges and refuses the other, with everything built on it, and keeps so across -restarts (`--store-file`); its log says so (`Refused an event its history takes, by what +restarts; its log says so (`Refused an event its history takes, by what this node took before: kept so`), `continuum-party status` says so, and `GET /events/refused` lists it under `own`: @@ -61,7 +61,8 @@ curl -u tv:secret -X POST -H 'Content-Type: application/json' \ The node refuses what it dropped from then on, from whoever brings it, and writes no version naming what it dropped, until it is allowed again. A node drops only what it took after its checkpoint: a version that moved it to a checkpoint it undoes only by -taking a checkpoint its operator pins (`--store-checkpoint`). +starting from a checkpoint its operator pins (`--store-checkpoint`), anew, without its +set's file ([`running-a-node.md`](running-a-node.md), [Joining](running-a-node.md#joining)). The parties answer keys that voted twice by forking, without the party that voted twice (`continuum-party fork remove lass`) or with its keys named anew (`fork keys lass @@ -75,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 still writes into the document +nothing by itself or by hand; what is put through it, it holds back (`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: @@ -94,7 +95,7 @@ makes a version none ([`proposing-and-voting.md`](proposing-and-voting.md), Upgrade the node to a continuum that reads it: restarted, it reads its store anew and takes it. Where none does (two thirds passed a proposal that is no version), have the node drop that event: it goes on under the version before, refuses the event and any writing -that version, and keeps so (`--store-file`): +that version, and keeps so across restarts: ```sh curl -u tv:secret -X POST -H 'Content-Type: application/json' \ @@ -103,10 +104,11 @@ curl -u tv:secret -X POST -H 'Content-Type: application/json' \ ``` Allowed again (`/admin/events/allow`), it stops there once more. A node that stopped -keeps none of it in its store file: restarted, it stops there again. What it holds back -it leaves out of nothing, as it can't tell which will be taken: it puts it 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. +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 +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. ## A node doing less than it should @@ -119,8 +121,8 @@ of what was put since. (`continuum-party nodes --add`), through any member. * **An event waits** (`waiting` when put): the node lacks an event it builds on. It takes it once that one arrives. -* **It doesn't start**: its store file doesn't read, or an option of a swarm that isn't - federated is set ([`running-a-node.md`](running-a-node.md), +* **It doesn't start**: the file of its set doesn't read, or an option of a swarm that + isn't federated is set ([`running-a-node.md`](running-a-node.md), [Its options](running-a-node.md#its-options)). * **A write is refused**: [`writing-and-reading.md`](writing-and-reading.md), [Why a write is refused](writing-and-reading.md#why-a-write-is-refused). -- 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') 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