From 233a48fffdd42f6700b71a45b87e89c337bdd648 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 17 Nov 2026 02:42:26 +0000 Subject: 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. --- src/simtest/mod.rs | 76 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 66 insertions(+), 10 deletions(-) (limited to 'src/simtest/mod.rs') 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 { 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, +) -> 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 = ballot + .proposals + .iter() + .filter_map(party) + .map(|(party, _)| party) + .collect(); + let votes: Vec = 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 { let mut heads = node.doc.read().await.heads().to_vec(); heads.sort_unstable(); -- cgit v1.3.1