From 055e09b3410040e4300238ac5d0a53fdc2726e40 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 25 Nov 2026 12:43:51 +0000 Subject: federation: a node casts no true its own store refuses A node recorded each vote, saved the record, offered the vote to its store, and didn't look at the answer. A party freed by nays cast after a checkpoint's heads were named, with its earlier true in their history, votes on that checkpoint on its proposal alone, as a checkpoint's vote leaves the nays out: there the earlier proposal isn't dead, and every store refuses the vote. Recorded all the same, it bound the party by a vote no node held; and deciding on it each round, the node proposed no checkpoint of its own. The fold's rule for a party's second true is State::may_back now, which a node asks at the history its vote would build on (vote::builds_on), as it decides, by itself or by hand, and as it signs: a vote refused at its own history counts nowhere, so none is cast, and none recorded. --- CHANGELOG.md | 5 +++ src/federation/fold.rs | 53 ++++++++++++++++----------- src/federation/held.rs | 23 ++---------- src/federation/vote.rs | 99 +++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 138 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f7ed62..8bd058f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ it from the release before ([`docs/operations.md`](docs/operations.md), ## Unreleased +* A node casts, and records, no `true` that its own store refuses: freed by nays cast + beside a checkpoint's heads, its vote on that checkpoint was refused by every node, + yet recorded, so the party was bound by a vote no node held, and the node proposed no + checkpoint of its own meanwhile ([`src/federation/vote.rs`](src/federation/vote.rs)). + * A new proposal holds back checkpoints for its while whoever proposes it again: a party with an older proposal proposing it again, byte for byte, ended that at once ([`src/federation/vote.rs`](src/federation/vote.rs)). diff --git a/src/federation/fold.rs b/src/federation/fold.rs index b96cf1f..b590f07 100644 --- a/src/federation/fold.rs +++ b/src/federation/fold.rs @@ -559,33 +559,44 @@ impl State { return Err(Refused::new("its proposal isn't proposed on that version")); } if *yes { - let backed: BTreeSet = self - .signed() - .filter_map(|(_, other, _)| match &other.does { - Does::Vote { - on: voted_on, - proposal: voted, - yes: true, - } if other.party == signed.party - && voted_on == on - && voted != proposal => - { - Some(*voted) - } - _ => None, - }) - .collect(); - if backed.iter().any(|other| !self.tally(current, other).dead) { - return Err(Refused::new( - "its party backs another proposal on that version, not dead", - )); - } + self.may_back(&signed.party, proposal, current)?; } Ok(()) } } } + /// Whether a `true` of `party` on the proposal of hash `proposal` on `current` is + /// taken here, as far as its party's other votes go: none of its `true`s on another + /// proposal on that version but on one dead here. A node asks it at the history its + /// vote would build on (`Store::state_at`), before it casts one. + pub(crate) fn may_back( + &self, + party: &str, + proposal: &Id, + current: &Version, + ) -> Result<(), Refused> { + let backed: BTreeSet = self + .signed() + .filter_map(|(_, other, _)| match &other.does { + Does::Vote { + on, + proposal: voted, + yes: true, + } if other.party == party && *on == current.hash && voted != proposal => { + Some(*voted) + } + _ => None, + }) + .collect(); + if backed.iter().any(|other| !self.tally(current, other).dead) { + return Err(Refused::new( + "its party backs another proposal on that version, not dead", + )); + } + Ok(()) + } + /// Whether a version event is taken here, at its history, `current` the version current /// there. One whose proposal passed but doesn't read as a version, it doesn't refuse: /// a later continuum may read it (`Fold::stops`). diff --git a/src/federation/held.rs b/src/federation/held.rs index 02b94d2..1e1e0d4 100644 --- a/src/federation/held.rs +++ b/src/federation/held.rs @@ -29,7 +29,7 @@ use anyhow::{Context, Result, bail}; use serde::{Deserialize, Serialize}; use tracing::{error, info, warn}; -use super::client::{self, Record}; +use super::client::Record; use super::event::{self, Does, Event, Signed}; use super::fold::Federation; use super::revision::Feature; @@ -756,25 +756,8 @@ impl Holding { // On an event proposing it, of a checkpoint one above the heads it // names, so a version event may be written on it, which the node's // heads, holding what is beside them, may not be; and on the nays that - // freed its party (`client::building`). - let state = store.state(); - let Some(proposing) = - state.proposing(¤t.hash, &proposal).first().copied() - else { - if hand.is_some() { - return Err(format!( - "no event proposing {proposal} is above the heads it names: \ - no version event is written on a vote on it" - )); - } - continue; - }; - let checkpoint = state - .proposal(&proposal) - .and_then(|json| Version::read(json).ok()) - .and_then(|version| version.checkpoint) - .is_some(); - let on = match client::building(proposing, checkpoint, &nays) { + // freed its party: where its store takes it (`vote::builds_on`). + let on = match vote::builds_on(store, party, &proposal, yes, &nays) { Ok(on) => on, Err(why) if hand.is_some() => return Err(why), Err(_) => continue, diff --git a/src/federation/vote.rs b/src/federation/vote.rs index e96cb22..baf8dd0 100644 --- a/src/federation/vote.rs +++ b/src/federation/vote.rs @@ -236,6 +236,47 @@ pub(crate) fn backs_checkpoint( } } +/// What a vote of `party` on the proposal of hash `proposal` builds on in `store`: an +/// event proposing it, of a checkpoint one above the heads it names, so that a version +/// event may be written on the vote; and, but for a checkpoint, the nays that freed its +/// party (`client::building`). Why not, where there is none, or where the store refuses a +/// `true` built so: the party backs another proposal that isn't dead at that history, its +/// nays cast beside a checkpoint's heads, say. Such a vote counts nowhere, so a node +/// casts and records none. +pub(crate) fn builds_on( + store: &Store, + party: &str, + proposal: &Id, + yes: bool, + nays: &[Vec], +) -> Result, String> { + let state = store.state(); + let current = state.current(); + let proposing = state + .proposing(¤t.hash, proposal) + .first() + .copied() + .ok_or_else(|| { + format!( + "no event proposing {proposal} is above the heads it names: no version \ + event is written on a vote on it" + ) + })?; + let checkpoint = state + .proposal(proposal) + .and_then(|json| Version::read(json).ok()) + .and_then(|version| version.checkpoint) + .is_some(); + let on = super::client::building(proposing, checkpoint, nays)?; + if yes { + store + .state_at(&on) + .may_back(party, proposal, current) + .map_err(|why| format!("no store takes that vote: {}", why.0))?; + } + Ok(on) +} + /// Whether a proposal can still pass: not dead by the votes cast. fn alive(current: &Version, proposed: &Proposed) -> bool { let parties = current.parties.len(); @@ -330,7 +371,9 @@ pub(crate) fn decide(seen: &Seen<'_>, rules: &Rules, record: &Record) -> Vec