From 35e459d86e33a07c66befd47b1d4be431ead313a Mon Sep 17 00:00:00 2001 From: Charles Hall Date: Thu, 7 Nov 2024 18:42:10 -0500 Subject: [PATCH] state-res: fix tiebreaking comparisons `node` needs to be swapped with `parent` here, otherwise the `power_level` and `age` in a `TieBreaker` inserted on the following line are always equal, because both sides are the values for `node` rather than a different value of `parent` on each iteration, and so the only thing that could possibly be different is the `event_id` because that's correctly set to `parent`. This is why I was observing tiebreaks always being sorted by `event_id` and experiencing incorrectly resolved states. --- crates/ruma-state-res/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ruma-state-res/src/lib.rs b/crates/ruma-state-res/src/lib.rs index 36c06e3b..ea3b4bd5 100644 --- a/crates/ruma-state-res/src/lib.rs +++ b/crates/ruma-state-res/src/lib.rs @@ -340,7 +340,7 @@ where // Only push on the heap once older events have been cleared out.remove(node.borrow()); if out.is_empty() { - let (power_level, age) = key_fn(node.clone()).await?; + let (power_level, age) = key_fn(parent.clone()).await?; heap.push(Reverse(TieBreaker { inv_power_level: -power_level, age,