1
0
Fork 0
mirror of https://forgejo.ellis.link/continuwuation/continuwuity.git synced 2025-09-21 18:16:56 +00:00

fix(hydra): Use an enum instead of a float for stateres version

This commit is contained in:
nexy7574 2025-09-17 20:57:22 +01:00
parent c4a2773230
commit 6840ec45f7
No known key found for this signature in database
4 changed files with 33 additions and 30 deletions

22
Cargo.lock generated
View file

@ -4107,7 +4107,7 @@ checksum = "88f8660c1ff60292143c98d08fc6e2f654d722db50410e3f3797d40baaf9d8f3"
[[package]] [[package]]
name = "ruma" name = "ruma"
version = "0.10.1" 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 = [ dependencies = [
"assign", "assign",
"js_int", "js_int",
@ -4127,7 +4127,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-appservice-api" name = "ruma-appservice-api"
version = "0.10.0" 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 = [ dependencies = [
"js_int", "js_int",
"ruma-common", "ruma-common",
@ -4139,7 +4139,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-client-api" name = "ruma-client-api"
version = "0.18.0" 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 = [ dependencies = [
"as_variant", "as_variant",
"assign", "assign",
@ -4162,7 +4162,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-common" name = "ruma-common"
version = "0.13.0" 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 = [ dependencies = [
"as_variant", "as_variant",
"base64 0.22.1", "base64 0.22.1",
@ -4194,7 +4194,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-events" name = "ruma-events"
version = "0.28.1" 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 = [ dependencies = [
"as_variant", "as_variant",
"indexmap 2.11.1", "indexmap 2.11.1",
@ -4219,7 +4219,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-federation-api" name = "ruma-federation-api"
version = "0.9.0" 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 = [ dependencies = [
"bytes", "bytes",
"headers", "headers",
@ -4241,7 +4241,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identifiers-validation" name = "ruma-identifiers-validation"
version = "0.9.5" 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 = [ dependencies = [
"js_int", "js_int",
"thiserror 2.0.16", "thiserror 2.0.16",
@ -4250,7 +4250,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identity-service-api" name = "ruma-identity-service-api"
version = "0.9.0" 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 = [ dependencies = [
"js_int", "js_int",
"ruma-common", "ruma-common",
@ -4260,7 +4260,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-macros" name = "ruma-macros"
version = "0.13.0" 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 = [ dependencies = [
"cfg-if", "cfg-if",
"proc-macro-crate", "proc-macro-crate",
@ -4275,7 +4275,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-push-gateway-api" name = "ruma-push-gateway-api"
version = "0.9.0" 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 = [ dependencies = [
"js_int", "js_int",
"ruma-common", "ruma-common",
@ -4287,7 +4287,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-signatures" name = "ruma-signatures"
version = "0.15.0" 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 = [ dependencies = [
"base64 0.22.1", "base64 0.22.1",
"ed25519-dalek", "ed25519-dalek",

View file

@ -351,7 +351,7 @@ version = "0.1.2"
# Used for matrix spec type definitions and helpers # Used for matrix spec type definitions and helpers
[workspace.dependencies.ruma] [workspace.dependencies.ruma]
git = "https://forgejo.ellis.link/continuwuation/ruwuma" git = "https://forgejo.ellis.link/continuwuation/ruwuma"
rev = "63279013b2d64e668b8eac09c4889a33f07a3f93" rev = "d18823471ab3c09e77ff03eea346d4c07e572654"
features = [ features = [
"compat", "compat",
"rand", "rand",

View file

@ -38,6 +38,7 @@ pub use self::{
use crate::{ use crate::{
debug, debug_error, debug, debug_error,
matrix::{Event, StateKey}, matrix::{Event, StateKey},
state_res::room_version::StateResolutionVersion,
trace, trace,
utils::stream::{BroadbandExt, IterStream, ReadyExt, TryBroadbandExt, WidebandExt}, utils::stream::{BroadbandExt, IterStream, ReadyExt, TryBroadbandExt, WidebandExt},
warn, warn,
@ -94,8 +95,8 @@ where
{ {
use RoomVersionId::*; use RoomVersionId::*;
let stateres_version = match room_version { let stateres_version = match room_version {
| V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 | V11 => 2.0, | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 | V11 => StateResolutionVersion::V2,
| _ => 2.1, | _ => StateResolutionVersion::V2_1,
}; };
debug!(version = ?stateres_version, "State resolution starting"); debug!(version = ?stateres_version, "State resolution starting");
@ -112,15 +113,14 @@ where
debug!(count = conflicting.len(), "conflicting events"); debug!(count = conflicting.len(), "conflicting events");
trace!(map = ?conflicting, "conflicting events"); trace!(map = ?conflicting, "conflicting events");
let conflicted_state_subgraph: HashSet<_> = match stateres_version {
let conflicted_state_subgraph: HashSet<_> = if stateres_version >= 2.1 { | StateResolutionVersion::V2_1 =>
calculate_conflicted_subgraph(&conflicting, event_fetch) calculate_conflicted_subgraph(&conflicting, event_fetch)
.await .await
.ok_or_else(|| { .ok_or_else(|| {
Error::InvalidPdu("Failed to calculate conflicted subgraph".to_owned()) Error::InvalidPdu("Failed to calculate conflicted subgraph".to_owned())
})? })?,
} else { | _ => HashSet::new(),
HashSet::new()
}; };
debug!(count = conflicted_state_subgraph.len(), "conflicted subgraph"); debug!(count = conflicted_state_subgraph.len(), "conflicted subgraph");
trace!(set = ?conflicted_state_subgraph, "conflicted subgraph"); trace!(set = ?conflicted_state_subgraph, "conflicted subgraph");
@ -169,7 +169,7 @@ where
// Sequentially auth check each control event. // Sequentially auth check each control event.
let resolved_control = iterative_auth_check( let resolved_control = iterative_auth_check(
&room_version, &room_version,
stateres_version, &stateres_version,
sorted_control_levels.iter().stream().map(AsRef::as_ref), sorted_control_levels.iter().stream().map(AsRef::as_ref),
clean.clone(), clean.clone(),
&event_fetch, &event_fetch,
@ -210,7 +210,7 @@ where
let mut resolved_state = iterative_auth_check( let mut resolved_state = iterative_auth_check(
&room_version, &room_version,
stateres_version, &stateres_version,
sorted_left_events.iter().stream().map(AsRef::as_ref), sorted_left_events.iter().stream().map(AsRef::as_ref),
resolved_control.clone(), // The control events are added to the final resolved state resolved_control.clone(), // The control events are added to the final resolved state
&event_fetch, &event_fetch,
@ -220,7 +220,7 @@ where
// Add unconflicted state to the resolved state // Add unconflicted state to the resolved state
// We priorities the unconflicting state // We priorities the unconflicting state
resolved_state.extend(clean); resolved_state.extend(clean);
if stateres_version == 2.1 { if stateres_version == StateResolutionVersion::V2_1 {
resolved_state.extend(resolved_control); resolved_state.extend(resolved_control);
// TODO(hydra): this feels disgusting and wrong but it allows // TODO(hydra): this feels disgusting and wrong but it allows
// the state to resolve properly? // the state to resolve properly?
@ -592,7 +592,7 @@ where
#[tracing::instrument(level = "trace", skip_all)] #[tracing::instrument(level = "trace", skip_all)]
async fn iterative_auth_check<'a, E, F, Fut, S>( async fn iterative_auth_check<'a, E, F, Fut, S>(
room_version: &RoomVersion, room_version: &RoomVersion,
stateres_version: f32, stateres_version: &StateResolutionVersion,
events_to_check: S, events_to_check: S,
unconflicted_state: StateMap<OwnedEventId>, unconflicted_state: StateMap<OwnedEventId>,
fetch_event: &F, fetch_event: &F,
@ -638,7 +638,7 @@ where
let auth_events = &auth_events; let auth_events = &auth_events;
let mut resolved_state = match stateres_version { let mut resolved_state = match stateres_version {
| 2.1 => StateMap::new(), | StateResolutionVersion::V2_1 => StateMap::new(),
| _ => unconflicted_state, | _ => unconflicted_state,
}; };
for event in events_to_check { for event in events_to_check {
@ -995,6 +995,7 @@ mod tests {
use crate::{ use crate::{
debug, debug,
matrix::{Event, EventTypeExt, Pdu as PduEvent}, matrix::{Event, EventTypeExt, Pdu as PduEvent},
state_res::room_version::StateResolutionVersion,
utils::stream::IterStream, utils::stream::IterStream,
}; };
@ -1027,7 +1028,7 @@ mod tests {
let resolved_power = super::iterative_auth_check( let resolved_power = super::iterative_auth_check(
&RoomVersion::V6, &RoomVersion::V6,
2.0, &StateResolutionVersion::V2,
sorted_power_events.iter().map(AsRef::as_ref).stream(), sorted_power_events.iter().map(AsRef::as_ref).stream(),
HashMap::new(), // unconflicted events HashMap::new(), // unconflicted events
&fetcher, &fetcher,

View file

@ -22,13 +22,15 @@ pub enum EventFormatVersion {
V3, V3,
} }
#[derive(Debug)] #[derive(Debug, PartialEq)]
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub enum StateResolutionVersion { pub enum StateResolutionVersion {
/// State resolution for rooms at version 1. /// State resolution for rooms at version 1.
V1, V1,
/// State resolution for room at version 2 or later. /// State resolution for room at version 2 or later.
V2, V2,
/// State resolution for room at version 12 or later.
V2_1,
} }
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]