diff options
| author | tv <tv@krebsco.de> | 2026-11-15 20:18:16 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-15 20:18:16 +0000 |
| commit | 2c64def2981354c341cae2bcbf871456876b8ea3 (patch) | |
| tree | 3fc136a773e94c742f36166a42fe3ad1c961a97a /src/document | |
| parent | 9ebdd9011d086bc74351c527f6626fe403ef3348 (diff) | |
rules: the changes that turned a swarm strict found once for its heads
Every change judged under a policy that isn't strict, in a strict
document, walked back to the changes that turned it strict, each step
reading every change the document holds. Only changes from the time
before reach it in an honest swarm, but a member can send crafted ones
at an old history, each costing every node a walk.
The changes are now read once per walk (`store::made`), and what the
walk finds is kept for the document's heads (`Reads::turned_now`), as
whether its policy is strict is.
Diffstat (limited to 'src/document')
| -rw-r--r-- | src/document/store.rs | 52 |
1 files changed, 38 insertions, 14 deletions
diff --git a/src/document/store.rs b/src/document/store.rs index 1f26053..27edf49 100644 --- a/src/document/store.rs +++ b/src/document/store.rs @@ -281,11 +281,40 @@ fn signs_values(doc: &impl ReadDoc) -> bool { .is_some_and(|json| crate::access::policy::read(&json).strict()) } -/// The changes that wrote what `path` holds as `view` (of `doc`) 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. +/// 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( - doc: &Automerge, + made: &Made, view: &impl ReadDoc, path: &[String], ) -> Vec<(automerge::ChangeHash, Vec<automerge::ChangeHash>)> { @@ -295,18 +324,13 @@ pub(crate) fn writers( { operations_within(view, &maps, leaf.as_str().into(), &mut ids); } - if ids.is_empty() { - return Vec::new(); - } - doc.get_changes(&[]) - .into_iter() - .filter(|change| { - let start = change.start_op().get(); - let made = start..start + change.len() as u64; + made.0 + .iter() + .filter(|(actor, ops, _, _)| { ids.iter() - .any(|(counter, actor)| change.actor_id() == actor && made.contains(counter)) + .any(|(counter, by)| by == actor && ops.contains(counter)) }) - .map(|change| (change.hash(), change.deps().to_vec())) + .map(|(_, _, hash, deps)| (*hash, deps.clone())) .collect() } |
