diff --git a/Cargo.lock b/Cargo.lock index f06149c1..a6df470d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4107,7 +4107,7 @@ checksum = "88f8660c1ff60292143c98d08fc6e2f654d722db50410e3f3797d40baaf9d8f3" [[package]] name = "ruma" version = "0.10.1" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=63279013b2d64e668b8eac09c4889a33f07a3f93#63279013b2d64e668b8eac09c4889a33f07a3f93" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d18823471ab3c09e77ff03eea346d4c07e572654#d18823471ab3c09e77ff03eea346d4c07e572654" dependencies = [ "assign", "js_int", @@ -4127,7 +4127,7 @@ dependencies = [ [[package]] name = "ruma-appservice-api" version = "0.10.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=63279013b2d64e668b8eac09c4889a33f07a3f93#63279013b2d64e668b8eac09c4889a33f07a3f93" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d18823471ab3c09e77ff03eea346d4c07e572654#d18823471ab3c09e77ff03eea346d4c07e572654" dependencies = [ "js_int", "ruma-common", @@ -4139,7 +4139,7 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.18.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=63279013b2d64e668b8eac09c4889a33f07a3f93#63279013b2d64e668b8eac09c4889a33f07a3f93" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d18823471ab3c09e77ff03eea346d4c07e572654#d18823471ab3c09e77ff03eea346d4c07e572654" dependencies = [ "as_variant", "assign", @@ -4162,7 +4162,7 @@ dependencies = [ [[package]] name = "ruma-common" version = "0.13.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=63279013b2d64e668b8eac09c4889a33f07a3f93#63279013b2d64e668b8eac09c4889a33f07a3f93" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d18823471ab3c09e77ff03eea346d4c07e572654#d18823471ab3c09e77ff03eea346d4c07e572654" dependencies = [ "as_variant", "base64 0.22.1", @@ -4194,7 +4194,7 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.28.1" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=63279013b2d64e668b8eac09c4889a33f07a3f93#63279013b2d64e668b8eac09c4889a33f07a3f93" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d18823471ab3c09e77ff03eea346d4c07e572654#d18823471ab3c09e77ff03eea346d4c07e572654" dependencies = [ "as_variant", "indexmap 2.11.1", @@ -4219,7 +4219,7 @@ dependencies = [ [[package]] name = "ruma-federation-api" version = "0.9.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=63279013b2d64e668b8eac09c4889a33f07a3f93#63279013b2d64e668b8eac09c4889a33f07a3f93" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d18823471ab3c09e77ff03eea346d4c07e572654#d18823471ab3c09e77ff03eea346d4c07e572654" dependencies = [ "bytes", "headers", @@ -4241,7 +4241,7 @@ dependencies = [ [[package]] name = "ruma-identifiers-validation" version = "0.9.5" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=63279013b2d64e668b8eac09c4889a33f07a3f93#63279013b2d64e668b8eac09c4889a33f07a3f93" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d18823471ab3c09e77ff03eea346d4c07e572654#d18823471ab3c09e77ff03eea346d4c07e572654" dependencies = [ "js_int", "thiserror 2.0.16", @@ -4250,7 +4250,7 @@ dependencies = [ [[package]] name = "ruma-identity-service-api" version = "0.9.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=63279013b2d64e668b8eac09c4889a33f07a3f93#63279013b2d64e668b8eac09c4889a33f07a3f93" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d18823471ab3c09e77ff03eea346d4c07e572654#d18823471ab3c09e77ff03eea346d4c07e572654" dependencies = [ "js_int", "ruma-common", @@ -4260,7 +4260,7 @@ dependencies = [ [[package]] name = "ruma-macros" version = "0.13.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=63279013b2d64e668b8eac09c4889a33f07a3f93#63279013b2d64e668b8eac09c4889a33f07a3f93" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d18823471ab3c09e77ff03eea346d4c07e572654#d18823471ab3c09e77ff03eea346d4c07e572654" dependencies = [ "cfg-if", "proc-macro-crate", @@ -4275,7 +4275,7 @@ dependencies = [ [[package]] name = "ruma-push-gateway-api" version = "0.9.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=63279013b2d64e668b8eac09c4889a33f07a3f93#63279013b2d64e668b8eac09c4889a33f07a3f93" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d18823471ab3c09e77ff03eea346d4c07e572654#d18823471ab3c09e77ff03eea346d4c07e572654" dependencies = [ "js_int", "ruma-common", @@ -4287,7 +4287,7 @@ dependencies = [ [[package]] name = "ruma-signatures" version = "0.15.0" -source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=63279013b2d64e668b8eac09c4889a33f07a3f93#63279013b2d64e668b8eac09c4889a33f07a3f93" +source = "git+https://forgejo.ellis.link/continuwuation/ruwuma?rev=d18823471ab3c09e77ff03eea346d4c07e572654#d18823471ab3c09e77ff03eea346d4c07e572654" dependencies = [ "base64 0.22.1", "ed25519-dalek", diff --git a/Cargo.toml b/Cargo.toml index ce7ab309..54015676 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -351,7 +351,7 @@ version = "0.1.2" # Used for matrix spec type definitions and helpers [workspace.dependencies.ruma] git = "https://forgejo.ellis.link/continuwuation/ruwuma" -rev = "63279013b2d64e668b8eac09c4889a33f07a3f93" +rev = "d18823471ab3c09e77ff03eea346d4c07e572654" features = [ "compat", "rand", diff --git a/src/core/matrix/state_res/mod.rs b/src/core/matrix/state_res/mod.rs index b6496741..5634cf7c 100644 --- a/src/core/matrix/state_res/mod.rs +++ b/src/core/matrix/state_res/mod.rs @@ -38,6 +38,7 @@ pub use self::{ use crate::{ debug, debug_error, matrix::{Event, StateKey}, + state_res::room_version::StateResolutionVersion, trace, utils::stream::{BroadbandExt, IterStream, ReadyExt, TryBroadbandExt, WidebandExt}, warn, @@ -94,8 +95,8 @@ where { use RoomVersionId::*; let stateres_version = match room_version { - | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 | V11 => 2.0, - | _ => 2.1, + | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 | V11 => StateResolutionVersion::V2, + | _ => StateResolutionVersion::V2_1, }; debug!(version = ?stateres_version, "State resolution starting"); @@ -112,15 +113,14 @@ where debug!(count = conflicting.len(), "conflicting events"); trace!(map = ?conflicting, "conflicting events"); - - let conflicted_state_subgraph: HashSet<_> = if stateres_version >= 2.1 { - calculate_conflicted_subgraph(&conflicting, event_fetch) - .await - .ok_or_else(|| { - Error::InvalidPdu("Failed to calculate conflicted subgraph".to_owned()) - })? - } else { - HashSet::new() + let conflicted_state_subgraph: HashSet<_> = match stateres_version { + | StateResolutionVersion::V2_1 => + calculate_conflicted_subgraph(&conflicting, event_fetch) + .await + .ok_or_else(|| { + Error::InvalidPdu("Failed to calculate conflicted subgraph".to_owned()) + })?, + | _ => HashSet::new(), }; debug!(count = conflicted_state_subgraph.len(), "conflicted subgraph"); trace!(set = ?conflicted_state_subgraph, "conflicted subgraph"); @@ -169,7 +169,7 @@ where // Sequentially auth check each control event. let resolved_control = iterative_auth_check( &room_version, - stateres_version, + &stateres_version, sorted_control_levels.iter().stream().map(AsRef::as_ref), clean.clone(), &event_fetch, @@ -210,7 +210,7 @@ where let mut resolved_state = iterative_auth_check( &room_version, - stateres_version, + &stateres_version, sorted_left_events.iter().stream().map(AsRef::as_ref), resolved_control.clone(), // The control events are added to the final resolved state &event_fetch, @@ -220,7 +220,7 @@ where // Add unconflicted state to the resolved state // We priorities the unconflicting state resolved_state.extend(clean); - if stateres_version == 2.1 { + if stateres_version == StateResolutionVersion::V2_1 { resolved_state.extend(resolved_control); // TODO(hydra): this feels disgusting and wrong but it allows // the state to resolve properly? @@ -592,7 +592,7 @@ where #[tracing::instrument(level = "trace", skip_all)] async fn iterative_auth_check<'a, E, F, Fut, S>( room_version: &RoomVersion, - stateres_version: f32, + stateres_version: &StateResolutionVersion, events_to_check: S, unconflicted_state: StateMap, fetch_event: &F, @@ -638,7 +638,7 @@ where let auth_events = &auth_events; let mut resolved_state = match stateres_version { - | 2.1 => StateMap::new(), + | StateResolutionVersion::V2_1 => StateMap::new(), | _ => unconflicted_state, }; for event in events_to_check { @@ -995,6 +995,7 @@ mod tests { use crate::{ debug, matrix::{Event, EventTypeExt, Pdu as PduEvent}, + state_res::room_version::StateResolutionVersion, utils::stream::IterStream, }; @@ -1027,7 +1028,7 @@ mod tests { let resolved_power = super::iterative_auth_check( &RoomVersion::V6, - 2.0, + &StateResolutionVersion::V2, sorted_power_events.iter().map(AsRef::as_ref).stream(), HashMap::new(), // unconflicted events &fetcher, diff --git a/src/core/matrix/state_res/room_version.rs b/src/core/matrix/state_res/room_version.rs index 7fa219f9..87af9f94 100644 --- a/src/core/matrix/state_res/room_version.rs +++ b/src/core/matrix/state_res/room_version.rs @@ -22,13 +22,15 @@ pub enum EventFormatVersion { V3, } -#[derive(Debug)] +#[derive(Debug, PartialEq)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] pub enum StateResolutionVersion { /// State resolution for rooms at version 1. V1, /// State resolution for room at version 2 or later. V2, + /// State resolution for room at version 12 or later. + V2_1, } #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]