Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ serde = "1.0"
futures = "0.3.5"
pretty_env_logger = "0.4"
bit-set = "0.5.2"
stateright = "0.9.0"
num_cpus = "1.13.0"
stateright = "0.10.0"
num_cpus = "1.13.0"
20 changes: 13 additions & 7 deletions src/stateright_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type ObjLE = pergola::LatticeElt<ObjLD>;
type Msg = Message<ObjLD, Id>;
type Part = Participant<ObjLD, Id>;

#[derive(Clone)]
struct ConcordeActor {
// This 'id' field seems a little redundant but we need it to fish the id of
// an actor out of the System<> struct, which doesn't otherwise provide a
Expand Down Expand Up @@ -95,6 +96,7 @@ impl Actor for ConcordeActor {
}
}

#[derive(Clone)]
struct ConcordeSystem {
peer_proposals: BTreeMap<Id, Vec<StateLE<ObjLD, Id>>>
}
Expand Down Expand Up @@ -122,6 +124,7 @@ impl ConcordeSystem {

impl System for ConcordeSystem {
type Actor = ConcordeActor;
type History = ();
fn actors(&self) -> Vec<Self::Actor> {
self.peer_proposals.clone().into_iter()
.map(|(id, proposals_to_make)| ConcordeActor { id, proposals_to_make})
Expand All @@ -134,10 +137,11 @@ impl System for ConcordeSystem {
Property::always("valid", lattice_agreement_validity),
Property::always("consistent", lattice_agreement_consistency),
Property::eventually("live", lattice_agreement_liveness),
Property::sometimes("sends messages", |_, state: &SystemState<ConcordeSystem>| !state.network.is_empty()),
Property::always("trivial", |_, _| true),
]
}
fn within_boundary(&self, state: &SystemState<Self::Actor>) -> bool {
fn within_boundary(&self, state: &SystemState<Self>) -> bool {
lattice_agreement_boundary(self, state)
}

Expand All @@ -152,7 +156,7 @@ impl System for ConcordeSystem {

fn lattice_agreement_validity(
_model: &SystemModel<ConcordeSystem>,
state: &SystemState<ConcordeActor>,
state: &SystemState<ConcordeSystem>,
) -> bool {
let mut all_proposed_added_peers = BTreeSet::new();
let mut all_proposed_removed_peers = BTreeSet::new();
Expand Down Expand Up @@ -197,7 +201,7 @@ fn lattice_agreement_validity(

fn lattice_agreement_consistency(
_model: &SystemModel<ConcordeSystem>,
state: &SystemState<ConcordeActor>,
state: &SystemState<ConcordeSystem>,
) -> bool {
for part in state.actor_states.iter() {
let h = &part.learned_history;
Expand All @@ -220,7 +224,7 @@ fn lattice_agreement_consistency(
// (Luckily this is how the liveness of lattice agreement is specified)
fn lattice_agreement_liveness(
model: &SystemModel<ConcordeSystem>,
state: &SystemState<ConcordeActor>,
state: &SystemState<ConcordeSystem>,
) -> bool {
for part in state.actor_states.iter() {
for actor in model.actors.iter() {
Expand All @@ -238,7 +242,7 @@ fn lattice_agreement_liveness(
// Returning false here means "past the boundary, stop exploring"
fn lattice_agreement_boundary(
system: &ConcordeSystem,
state: &SystemState<ConcordeActor>,
state: &SystemState<ConcordeSystem>,
) -> bool {
for part in state.actor_states.iter() {
match system.peer_proposals.get(&part.id) {
Expand Down Expand Up @@ -287,6 +291,8 @@ fn model_check() {
}
}
}

checker.assert_example("sends messages");
}

//---------------------------------------------------------
Expand Down Expand Up @@ -382,7 +388,7 @@ fn msg_to_string(msg: &Msg) -> String {
}
}

fn print_system_state(state: &SystemState<ConcordeActor>) {
fn print_system_state(state: &SystemState<ConcordeSystem>) {
// println!(" state at depth {}:", state.depth);
for part in state.actor_states.iter() {
println!(" participant {}:", usize::from(part.id));
Expand Down Expand Up @@ -446,7 +452,7 @@ fn print_system_action_opt(action: &Option<SystemAction<Msg>>) {

fn print_path(
path: Path<
SystemState<ConcordeActor>,
SystemState<ConcordeSystem>,
SystemAction<Msg>,
>,
) {
Expand Down