diff options
| author | tv <tv@krebsco.de> | 2026-11-17 02:42:26 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-17 03:43:44 +0100 |
| commit | 233a48fffdd42f6700b71a45b87e89c337bdd648 (patch) | |
| tree | 0bf8b4bab3d877ec1d0736512e024858e275947c /src/simtest/mod.rs | |
| parent | 2068eb238a8a5d8042de4cb5ac5ab584054bfb0f (diff) | |
simtest: show a store's refusals and ballots in a failed simulation's dump
For a node holding a store, the dump shows each event it refused and why,
the proposals on the current version with the parties proposing them and
their votes, whether each passes there, and the version events it took.
Diffstat (limited to 'src/simtest/mod.rs')
| -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(); |
