From f24063e90d02ef76d87401d6e74cf8c9f489ff7d Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 19 Nov 2026 01:48:57 +0000 Subject: fold: of a party's lists, those written under the latest version first A key a version names, stolen, could write its party's node list at a history from before the version that named the party's keys anew: written under the version before, it counted, as naming keys anew leaves a list's `since` alone, and beside the list the party wrote under the new version the lower ID won. The thief signed a few, kept the lowest, and did so again after every list the party wrote. Of a party's key sets, and of its node lists, those written under the latest version now come first, then what no other has in its history, then the lowest ID; the model alike. A list the party writes under the version that replaced the key stays, as `federation.md` says. Key sets were safe already, by their `since`; one rule serves both. This changes what counts where two of a party's lists, written under different versions, are beside each other: nodes read them alike only once all run it. Row 69 is tested (`federation_attack_69`). --- src/federation/model.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/federation/model.rs') diff --git a/src/federation/model.rs b/src/federation/model.rs index 2107d9f..8cd189b 100644 --- a/src/federation/model.rs +++ b/src/federation/model.rs @@ -205,7 +205,8 @@ impl Model { }) } - /// The key set, or node list, of `party` that counts in a history by `version`. + /// The key set, or node list, of `party` that counts in a history by `version`: of + /// those written under the latest version, the latest. fn list( &self, history: &BTreeSet, @@ -219,17 +220,23 @@ impl Model { } else { given.nodes_since }; - let ids: Vec = self + let ids: Vec<(Id, u64)> = self .signed(history) - .filter(|(id, signed)| { + .filter(|(_, signed)| { signed.party == party && match signed.does { Does::Keys(_) => keys, Does::Nodes(_) => !keys, _ => false, } - && self.under(id).is_some_and(|under| under.number >= since) }) + .filter_map(|(id, _)| Some((id, self.under(&id)?.number))) + .filter(|(_, number)| *number >= since) + .collect(); + let latest = ids.iter().map(|(_, number)| *number).max()?; + let ids: Vec = ids + .into_iter() + .filter(|(_, number)| *number == latest) .map(|(id, _)| id) .collect(); self.latest(&ids) -- cgit v1.3.1