aboutsummaryrefslogtreecommitdiffstats
path: root/src/federation/properties.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/federation/properties.rs')
-rw-r--r--src/federation/properties.rs60
1 files changed, 50 insertions, 10 deletions
diff --git a/src/federation/properties.rs b/src/federation/properties.rs
index d42509b..02c7799 100644
--- a/src/federation/properties.rs
+++ b/src/federation/properties.rs
@@ -15,6 +15,7 @@ use super::event::{Checkpoint, Does, Event};
use super::fold::Federation;
use super::harness::{self, Party, Spec};
use super::held::Holding;
+use super::jcs::Json;
use super::model::{Model, Verdict};
use super::store::memory::{Offered, Refusal, Store};
use super::store::{Fold, Id};
@@ -82,12 +83,14 @@ impl History {
}
}
-/// How a history is written: whether an adversary takes part, and whether versions name
-/// checkpoints.
+/// How a history is written: whether an adversary takes part, whether versions name
+/// checkpoints, and whether parties propose versions this continuum doesn't read, at
+/// which a store stops, which events then take in the order they come.
#[derive(Clone, Copy)]
struct Kind {
adversary: bool,
checkpoints: bool,
+ unread: bool,
}
/// One of `ids`, of the latest five more often than not.
@@ -169,10 +172,27 @@ fn generate(rng: &mut Rng, kind: Kind) -> History {
next.rules
.push((format!("names/x{step}"), harness::str(&party.name)));
}
- let bytes = party.propose(&deps, &next.json());
- proposals.push((Id::of(&bytes), next.hash(), current.hash, named));
- specs.insert(next.hash(), next);
- bytes
+ if kind.unread && rng.chance(0.5) {
+ // A field this continuum doesn't know: none here.
+ let Json::Object(mut members) = next.json() else {
+ unreachable!("a version is an object")
+ };
+ members.push(("later".to_owned(), Json::Bool(true)));
+ let later = Json::object(members).expect("names once each");
+ let bytes = party.propose(&deps, &later);
+ proposals.push((
+ Id::of(&bytes),
+ Id::of(&later.bytes()),
+ current.hash,
+ named,
+ ));
+ bytes
+ } else {
+ let bytes = party.propose(&deps, &next.json());
+ proposals.push((Id::of(&bytes), next.hash(), current.hash, named));
+ specs.insert(next.hash(), next);
+ bytes
+ }
}
}
} else if roll < 85 {
@@ -297,19 +317,28 @@ fn verdict(offered: &Offered) -> Verdict {
Offered::Held => Verdict::Held,
Offered::Waiting => Verdict::Waiting,
Offered::Refused(_) => Verdict::Refused,
- // The harness proposes only versions this continuum reads: none stops the store.
- Offered::Stopped => unreachable!("the store stopped"),
+ Offered::Stopped => Verdict::Stopped,
}
}
+/// Where parties propose versions this continuum doesn't read too, the store stops where
+/// the model does: written in order, events come after what they build on, and both stop
+/// at the same event, taking the same before it.
#[test]
fn the_store_judges_and_reads_as_the_model() {
- for adversary in [false, true] {
+ let stopped = std::cell::Cell::new(0);
+ for (adversary, unread, cases) in [
+ (false, false, 48),
+ (true, false, 48),
+ (false, true, 32),
+ (true, true, 32),
+ ] {
check(
- 48,
+ cases,
Kind {
adversary,
checkpoints: false,
+ unread,
},
|history| {
let mut model = Model::new(&history.root);
@@ -325,6 +354,9 @@ fn the_store_judges_and_reads_as_the_model() {
));
}
}
+ if store.stopped().is_some() {
+ stopped.set(stopped.get() + 1);
+ }
if reads(&store) != model_reads(&model) {
return Err(format!(
"the store reads {:?}, the model {:?}",
@@ -336,6 +368,7 @@ fn the_store_judges_and_reads_as_the_model() {
},
);
}
+ assert!(stopped.get() > 0, "no history stopped a store");
}
#[test]
@@ -345,6 +378,7 @@ fn what_builds_on_a_refused_event_is_refused() {
Kind {
adversary: true,
checkpoints: true,
+ unread: false,
},
|history| {
let (store, _) = history.store(&history.written());
@@ -369,6 +403,7 @@ fn honest_parties_read_the_same_whatever_order_events_come_in() {
Kind {
adversary: false,
checkpoints: true,
+ unread: false,
},
|history| {
let held = holds(&history.store(&history.written()).0);
@@ -401,6 +436,7 @@ fn a_store_read_from_its_document_holds_what_one_given_the_events_alone_holds()
Kind {
adversary: false,
checkpoints: true,
+ unread: false,
},
|history| {
let alone = holds(&history.store(&history.written()).0);
@@ -456,6 +492,7 @@ fn after_a_checkpoint_the_store_judges_and_reads_as_the_whole_history() {
Kind {
adversary: false,
checkpoints: true,
+ unread: false,
},
|history| {
let (store, _) = history.store(&history.written());
@@ -533,6 +570,7 @@ fn every_version_a_store_takes_was_passed_by_two_thirds_in_its_history() {
Kind {
adversary: true,
checkpoints: false,
+ unread: false,
},
|history| {
let (store, _) = history.store(&history.written());
@@ -610,6 +648,7 @@ fn without_a_party_voting_twice_no_two_versions_change_one() {
Kind {
adversary: false,
checkpoints: true,
+ unread: false,
},
|history| {
let (store, _) = history.store(&history.written());
@@ -632,6 +671,7 @@ fn a_fork_keeps_what_counts_at_its_heads_and_takes_nothing_of_the_other() {
Kind {
adversary: false,
checkpoints: false,
+ unread: false,
},
|history| {
let (mut whole, _) = history.store(&history.written());