aboutsummaryrefslogtreecommitdiffstats
path: root/src/federation/vote.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-25 12:43:51 +0000
committertv <tv@krebsco.de>2026-11-25 12:43:51 +0000
commit055e09b3410040e4300238ac5d0a53fdc2726e40 (patch)
tree76bc574f812b683a20cc34833a3fd3481845c3c7 /src/federation/vote.rs
parent2085f8fa1b7f4d5c5011479cbf1f3d6fac6545a2 (diff)
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.
Diffstat (limited to 'src/federation/vote.rs')
-rw-r--r--src/federation/vote.rs99
1 files changed, 98 insertions, 1 deletions
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<Federation>,
+ party: &str,
+ proposal: &Id,
+ yes: bool,
+ nays: &[Vec<u8>],
+) -> Result<Vec<Id>, String> {
+ let state = store.state();
+ let current = state.current();
+ let proposing = state
+ .proposing(&current.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<Act
{
continue;
}
- if let Ok(kept) = record.may_vote(&current, proposed.hash, &proposed.json, true, &nays) {
+ if let Ok(kept) = record.may_vote(&current, proposed.hash, &proposed.json, true, &nays)
+ && builds_on(seen.store, &record.party, &proposed.hash, true, &kept).is_ok()
+ {
backed = true;
acts.push(Act::Vote {
proposal: proposed.hash,
@@ -437,6 +480,7 @@ pub(crate) fn by_hand(
.flat_map(|proposed| proposed.votes.iter().cloned())
.collect();
let nays = record.may_vote(&current, proposal, &proposed.json, yes, &nays)?;
+ builds_on(seen.store, &record.party, &proposal, yes, &nays)?;
Ok(Act::Vote {
proposal,
yes,
@@ -684,6 +728,59 @@ mod tests {
assert!(backs_checkpoint(&running, &rules, &current, &version, hour).is_ok());
}
+ /// A node casts no `true` its own store refuses. Its party's earlier `true` is in the
+ /// history of a checkpoint's heads, and the nays that freed it came after they were
+ /// named, beside them: a vote on the checkpoint builds on its proposal alone, where
+ /// the earlier proposal isn't dead, so every store refuses it. Cast and recorded, it
+ /// would bind the party by a vote no node holds.
+ #[test]
+ fn a_node_casts_no_true_its_store_refuses() {
+ let (tv, lass, makefu, first, mut store) = three();
+ let root = store.id();
+ let on = first.hash();
+ let mut change = first.after(on);
+ change
+ .rules
+ .push(("names/x".to_owned(), harness::str("tv")));
+ let asked = taken(&mut store, tv.propose(&[root], &change.json()));
+ let earlier = makefu.vote(&[asked], on, change.hash(), true);
+ let mut record = record(&store, "makefu");
+ record.cast(store.state().current(), &earlier, Vec::new());
+ let earlier = taken(&mut store, earlier);
+ let head = taken(
+ &mut store,
+ tv.write(&[earlier], "home/tv/a", harness::str("1")),
+ );
+ let mut checkpoint = first.after(on);
+ checkpoint.checkpoint = Some(vec![head]);
+ let proposal = taken(&mut store, tv.propose(&[head], &checkpoint.json()));
+ taken(
+ &mut store,
+ tv.vote(&[proposal], on, checkpoint.hash(), true),
+ );
+ for party in [&tv, &lass] {
+ taken(&mut store, party.vote(&[asked], on, change.hash(), false));
+ }
+ let rules = Rules {
+ follow: vec!["tv".to_owned()],
+ held_for: Duration::from_secs(60),
+ ..Rules::default()
+ };
+ let long = |_: &Id| Some(Duration::from_secs(3600));
+ let acts = decide(&seen(&store, &long), &rules, &record);
+ assert!(
+ !acts
+ .iter()
+ .any(|act| matches!(act, Act::Vote { yes: true, .. })),
+ "{acts:?}"
+ );
+ // What it would have cast, its store refuses.
+ assert!(matches!(
+ store.offer(makefu.vote(&[proposal], on, checkpoint.hash(), true)),
+ Offered::Refused(_)
+ ));
+ }
+
#[test]
fn a_node_follows_a_party_on_checkpoints() {
let (tv, lass, _, first, mut store) = three();