diff --git a/src/cli/get_room_states.rs b/src/cli/get_room_states.rs index eaf55457..d6e9c373 100644 --- a/src/cli/get_room_states.rs +++ b/src/cli/get_room_states.rs @@ -26,6 +26,9 @@ struct Value { /// The edges in the state events' auth chains edges: BTreeSet, + + /// A graphviz representation of the resolved state and auth events + graphviz: String, } /// An edge in the graph of `auth_events` of the resolved state diff --git a/src/cli/get_room_states/cache.rs b/src/cli/get_room_states/cache.rs index 756dc8e7..d950a38a 100644 --- a/src/cli/get_room_states/cache.rs +++ b/src/cli/get_room_states/cache.rs @@ -5,6 +5,7 @@ use std::{ sync::Arc, }; +use petgraph::dot::Dot; use ruma::{OwnedRoomId, RoomId}; use tracing as t; @@ -132,9 +133,12 @@ async fn get_room_value( }) .collect(); + let graphviz = Dot::new(&graph).to_string(); + Some(Value { resolved_state, pdus, edges, + graphviz, }) } diff --git a/src/cli/get_room_states/recompute.rs b/src/cli/get_room_states/recompute.rs index c58cb985..990e6422 100644 --- a/src/cli/get_room_states/recompute.rs +++ b/src/cli/get_room_states/recompute.rs @@ -3,6 +3,7 @@ use std::{ collections::{BTreeMap, BTreeSet, HashMap, HashSet}, error::Error, + fmt, sync::{ atomic::{AtomicUsize, Ordering}, Arc, @@ -10,6 +11,7 @@ use std::{ }; use petgraph::{ + dot::Dot, graph::NodeIndex, visit::{depth_first_search, DfsEvent, Reversed}, Direction, @@ -29,6 +31,12 @@ use crate::{database::KeyValueDatabase, utils, PduEvent}; /// A weightless unit type to use for graphs with unweighted edges pub(crate) struct WeightlessEdge; +impl fmt::Display for WeightlessEdge { + fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result { + Ok(()) + } +} + /// A directed graph with unweighted edges pub(crate) type DiGraph = petgraph::graph::DiGraph; @@ -40,7 +48,7 @@ struct ExtractRoomVersion { } /// Information about a state event node for state resolution -#[derive(Clone)] +#[derive(Clone, Debug)] pub(crate) struct StateResolutionNode { /// This event's ID pub(crate) event_id: Arc, @@ -52,6 +60,12 @@ pub(crate) struct StateResolutionNode { pub(crate) state_key: String, } +impl fmt::Display for StateResolutionNode { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{self:#?}") + } +} + /// Information about a state event's edges for state resolution pub(crate) struct StateResolutionEdges { /// This event's ID @@ -306,10 +320,13 @@ fn resolve_room_state( }) .collect(); + let graphviz = Dot::new(&graph).to_string(); + Some(Value { resolved_state, pdus, edges, + graphviz, }) }