diff options
| author | tv <tv@krebsco.de> | 2026-11-15 21:43:18 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-15 21:43:18 +0000 |
| commit | 56fbbcf61ae77aed17b1fc04e914ccd3939df26f (patch) | |
| tree | 485f84fa83f043d7556a67435193a0c337cc39f7 /src/document | |
| parent | d2f72861bacf22542ceb29297ccd97dc440a608e (diff) | |
rules: a swarm turns strict only at its start or through a strict remake
A strict policy written into a running swarm left a time before it:
changes written there, beside the turn, were refused by the nodes that
took the turn first and taken by the others where they came first (a
signed policy that isn't strict, among them, unseated the turn there);
and a remake whose base preceded the turn had every switching node
replay the turn as one of its own, each refusing the others'.
A change writing a strict policy where the policy at its history isn't
strict (`"signed"` at its `values`, or an envelope there asking for
signed values) is now refused, in every swarm. A swarm turns strict at
its start (`--bootstrap-policy`) or through a strict remake, each its
epoch's first change: no change of a strict epoch is from before its
policy, and the rule for the time before goes, with the walk that found
the changes that turned a swarm strict and what kept them
(`before_strict`, `turned_strict`, `Reads::strict_now`,
`Reads::turned_now`, `store::writers`, `store::made`,
`changes::in_history`). The strict swarm's simulation starts strict.
access.md says so, and that a strict swarm can't move to a policy its
nodes don't know by writing it.
Diffstat (limited to 'src/document')
| -rw-r--r-- | src/document/changes.rs | 12 | ||||
| -rw-r--r-- | src/document/store.rs | 78 |
2 files changed, 0 insertions, 90 deletions
diff --git a/src/document/changes.rs b/src/document/changes.rs index e1cbe21..800ea19 100644 --- a/src/document/changes.rs +++ b/src/document/changes.rs @@ -28,18 +28,6 @@ pub(crate) fn holds_all(doc: &impl ReadDoc, heads: &[ChangeHash]) -> bool { heads.iter().all(|head| holds(doc, head)) } -/// Whether `hash` is in the history of `heads`, which `doc` holds: one of them, or one -/// they build on. -pub(crate) fn in_history(doc: &Document, hash: &ChangeHash, heads: &[ChangeHash]) -> bool { - heads.contains(hash) - || (holds(doc, hash) - && holds_all(doc, heads) - && !doc - .get_changes(heads) - .iter() - .any(|later| later.hash() == *hash)) -} - /// Whether the history of `theirs` (of them, those `doc` has) holds all of `ours` /// (heads of `doc`): a peer at `theirs` has every change we have. pub(crate) fn covers(doc: &Document, theirs: &[ChangeHash], ours: &[ChangeHash]) -> bool { diff --git a/src/document/store.rs b/src/document/store.rs index a9d4379..77d5c81 100644 --- a/src/document/store.rs +++ b/src/document/store.rs @@ -297,84 +297,6 @@ fn policy_asks(doc: &impl ReadDoc, value: &Value<'_>, id: &ObjId) -> bool { } } -/// Every change a document holds, by its writer and the numbers of its operations, with -/// the changes it builds on: read once for any number of [`writers`]. -pub(crate) struct Made( - Vec<( - ActorId, - std::ops::Range<u64>, - automerge::ChangeHash, - Vec<automerge::ChangeHash>, - )>, -); - -/// What `doc` holds, for [`writers`]. -pub(crate) fn made(doc: &Automerge) -> Made { - Made( - doc.get_changes(&[]) - .into_iter() - .map(|change| { - let start = change.start_op().get(); - ( - change.actor_id().clone(), - start..start + change.len() as u64, - change.hash(), - change.deps().to_vec(), - ) - }) - .collect(), - ) -} - -/// The changes, of those `made` has, that wrote what `path` holds as `view` shows it: -/// each value written there at once and, of a map, every key within it, all the way -/// down; each with the changes it builds on. -pub(crate) fn writers( - made: &Made, - view: &impl ReadDoc, - path: &[String], -) -> Vec<(automerge::ChangeHash, Vec<automerge::ChangeHash>)> { - let mut ids = Vec::new(); - if let Some((leaf, parents)) = path.split_last() - && let Ok(Some(Resolved::Maps(maps))) = resolve_through(view, parents) - { - operations_within(view, &maps, leaf.as_str().into(), &mut ids); - } - made.0 - .iter() - .filter(|(actor, ops, _, _)| { - ids.iter() - .any(|(counter, by)| by == actor && ops.contains(counter)) - }) - .map(|(_, _, hash, deps)| (*hash, deps.clone())) - .collect() -} - -/// The operations that wrote `prop` of `parents` as `view` shows it, and, of a map, -/// every key within it. -fn operations_within( - view: &impl ReadDoc, - parents: &[ObjId], - prop: Prop, - ids: &mut Vec<(u64, ActorId)>, -) { - for parent in parents { - let Ok(all) = view.get_all(parent, prop.clone()) else { - continue; - }; - for (value, id) in all { - if let ObjId::Id(counter, actor, _) = &id { - ids.push((*counter, actor.clone())); - } - if matches!(value, Value::Object(ObjType::Map)) { - for key in view.keys(&id) { - operations_within(view, std::slice::from_ref(&id), key.into(), ids); - } - } - } - } -} - /// What `prop` of `parent` holds as a read shows it, of the values written there at /// once (`candidates`): the value, and its operation's ID. pub(crate) fn shown( |
