aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/remake/delta.rs55
1 files changed, 51 insertions, 4 deletions
diff --git a/src/remake/delta.rs b/src/remake/delta.rs
index c8e07c0..78a8097 100644
--- a/src/remake/delta.rs
+++ b/src/remake/delta.rs
@@ -148,7 +148,7 @@ pub(crate) fn replay_newest(
// written at the same time (it may decide who may write that).
let mut links: BTreeMap<(i64, usize), (Vec<String>, String, String)> = BTreeMap::new();
for place in signed {
- match chain(src, &changes, &place, dst) {
+ match chain(src, after, &changes, &place, dst) {
Chain::Links(chain) => {
// In their order, whatever their clocks say.
let mut at = i64::MIN;
@@ -404,13 +404,23 @@ enum Chain {
}
/// The chain of envelopes `src` holds at `place` (written by `changes`) that leads from
-/// what `dst` holds there to what `src` reads there, following `prev`.
-fn chain(src: &Document, changes: &[ChangeHash], place: &[String], dst: &Document) -> Chain {
+/// what `dst` holds there to what `src` reads there at `after`, where the replay ends,
+/// following `prev`.
+fn chain(
+ src: &Document,
+ after: &[ChangeHash],
+ changes: &[ChangeHash],
+ place: &[String],
+ dst: &Document,
+) -> Chain {
let raw = |doc: &dyn Fn() -> Option<serde_json::Value>| match doc() {
Some(serde_json::Value::String(text)) => Some(text),
_ => None,
};
- let Some(target) = raw(&|| store::read_path(src, place).ok().flatten()) else {
+ let Some(end) = At::new(src, after) else {
+ return Chain::Broken("the replay's end isn't in the old document".to_owned());
+ };
+ let Some(target) = raw(&|| store::read_path(&end, place).ok().flatten()) else {
return Chain::Broken("no value its user signed is there to replay".to_owned());
};
let Ok(payload) = envelope::read(&target) else {
@@ -1179,6 +1189,43 @@ mod tests {
assert!(stats.quarantined.is_empty());
}
+ /// Replayed in two parts, as a rejoin does (what was written before it began, then
+ /// what was written during it): each part's chain leads to what the old document
+ /// reads where that part ends.
+ #[test]
+ fn signed_values_replay_in_parts() {
+ let key = ed25519_dalek::SigningKey::from_bytes(&[7; 32]);
+ let mut old = strict_with(&key);
+ let first = signed_after(&key, None, 1);
+ alice_writes(&mut old, 5, &first);
+ let base = old.get_heads();
+ let mut replayed = old.clone().with_actor(automerge::ActorId::random());
+ let second = signed_after(&key, Some(&first), 2);
+ alice_writes(&mut old, 10, &second);
+ let began = old.get_heads();
+ let third = signed_after(&key, Some(&second), 3);
+ alice_writes(&mut old, 20, &third);
+ let fourth = signed_after(&key, Some(&third), 4);
+ alice_writes(&mut old, 30, &fourth);
+ for (from, to) in [(&base, &began), (&began, &old.get_heads())] {
+ let stats = replay_newest(
+ &old,
+ from,
+ to,
+ &mut replayed,
+ crate::document::replica::Epoch::GENESIS,
+ "node",
+ &Translator::default(),
+ Superseded::Drop,
+ );
+ assert!(stats.quarantined.is_empty(), "{:?}", stats.quarantined);
+ }
+ assert_eq!(
+ store::read_candidates(&replayed, &["config".to_owned()]).unwrap(),
+ [json!(fourth)]
+ );
+ }
+
/// The first group refused: those after it still replayed, still the node's (a
/// fork, taking the refused one back, has no author of its own).
#[test]