diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/simtest/mod.rs | 76 |
1 files changed, 66 insertions, 10 deletions
diff --git a/src/simtest/mod.rs b/src/simtest/mod.rs index c28f8a2..7764f1c 100644 --- a/src/simtest/mod.rs +++ b/src/simtest/mod.rs @@ -425,16 +425,8 @@ impl Sim { } } #[cfg(feature = "federation")] - if let Some(store) = node.holding.with(|store| { - format!( - " store: checkpoint={} current={} taken={} refused={}", - &crate::federation::store::Id::of(store.checkpoint()).to_string()[..8], - &store.state().current().hash.to_string()[..8], - store.taken().len(), - store.refused().count() - ) - }) { - let _ = writeln!(out, "{store}"); + if let Some(store) = node.holding.with(describe_store) { + out.push_str(&store); } for remake in crate::remake::testing::describe(node).await { let _ = writeln!(out, " {remake}"); @@ -499,6 +491,70 @@ pub(crate) async fn read(node: &AppState, at: &str) -> Option<JsonValue> { store::read_path(&node.doc.read().await.doc, &path(at)).expect("read") } +/// What a node's store holds, for a failed simulation's dump: its checkpoint and current +/// version, what it took and refused (and why), and the proposals on the current version +/// with the parties voting on them, and whether they pass there. +#[cfg(feature = "federation")] +fn describe_store( + store: &crate::federation::store::memory::Store<crate::federation::fold::Federation>, +) -> String { + use std::fmt::Write; + + use crate::federation::event::{Does, Event}; + use crate::federation::store::Id; + let short = |id: &Id| id.to_string()[..8].to_owned(); + let state = store.state(); + let current = state.current().hash; + let mut out = format!( + " store: checkpoint={} current={} taken={} refused={}\n", + short(&Id::of(store.checkpoint())), + short(¤t), + store.taken().len(), + store.refused().count() + ); + for (id, refusal) in store.refused() { + let _ = writeln!(out, " refused {}: {refusal:?}", short(id)); + } + let party = |id: &Id| match store.get(id).and_then(Event::read_taken) { + Some(Event::Signed(signed)) => Some((signed.party, signed.does)), + _ => None, + }; + for (hash, ballot) in state.ballots(¤t) { + let proposed: Vec<String> = ballot + .proposals + .iter() + .filter_map(party) + .map(|(party, _)| party) + .collect(); + let votes: Vec<String> = ballot + .votes + .iter() + .filter_map(party) + .map(|(party, does)| match does { + Does::Vote { yes, .. } => format!("{party} {yes}"), + _ => party, + }) + .collect(); + let _ = writeln!( + out, + " proposal {} by {proposed:?}: votes {votes:?}, passes {}", + short(&hash), + state.version_event(&hash).is_some() + ); + } + for id in store.taken() { + if let Some(Event::Version { version, .. }) = store.get(id).and_then(Event::read_taken) { + let _ = writeln!( + out, + " version event {} writes {}", + short(id), + short(&version) + ); + } + } + out +} + pub(crate) async fn heads(node: &AppState) -> Vec<ChangeHash> { let mut heads = node.doc.read().await.heads().to_vec(); heads.sort_unstable(); |
