aboutsummaryrefslogtreecommitdiffstats
path: root/src/federation/fold.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-19 01:48:57 +0000
committertv <tv@krebsco.de>2026-11-19 03:18:34 +0100
commitf24063e90d02ef76d87401d6e74cf8c9f489ff7d (patch)
tree313fa30d2610a248f5132dfe1c2d3a37ce73f624 /src/federation/fold.rs
parentc0bb757df50fe4aa025ba2e6ac021e179291c78b (diff)
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`).
Diffstat (limited to 'src/federation/fold.rs')
-rw-r--r--src/federation/fold.rs27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/federation/fold.rs b/src/federation/fold.rs
index 3ebeebf..2e3fc56 100644
--- a/src/federation/fold.rs
+++ b/src/federation/fold.rs
@@ -186,28 +186,35 @@ impl State {
.copied()
}
- /// The key set, or node list, of `party` that counts by `current`: one written under a
- /// version numbered at least the `since` it gives the party's.
+ /// The key set, or node list, of `party` that counts by `current`: of those written
+ /// under a version numbered at least the `since` it gives the party's, those written
+ /// under the latest version, and of those the latest (`latest`). So one a stolen key
+ /// writes at a history from before the version that named its party's keys anew
+ /// replaces nothing the party wrote under that version.
fn list(&self, party: &str, current: &Version, list: List) -> Option<Id> {
let given = current.parties.get(party)?;
let since = match list {
List::Keys => given.keys_since,
List::Nodes => given.nodes_since,
};
- let candidates: Vec<Id> = self
+ let candidates: Vec<(Id, u64)> = self
.signed()
- .filter(|(_, signed, under)| {
- signed.party == party
+ .filter_map(|(id, signed, under)| {
+ let number = self.versions.get(under)?.number;
+ (signed.party == party
&& matches!(
(&signed.does, list),
(Does::Keys(_), List::Keys) | (Does::Nodes(_), List::Nodes)
)
- && self
- .versions
- .get(under)
- .is_some_and(|version| version.number >= since)
+ && number >= since)
+ .then_some((*id, number))
})
- .map(|(id, _, _)| *id)
+ .collect();
+ let latest = candidates.iter().map(|(_, number)| *number).max()?;
+ let candidates: Vec<Id> = candidates
+ .into_iter()
+ .filter(|(_, number)| *number == latest)
+ .map(|(id, _)| id)
.collect();
self.latest(&candidates)
}