aboutsummaryrefslogtreecommitdiffstats
path: root/src/federation/vote.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-25 15:27:53 +0000
committertv <tv@krebsco.de>2026-11-25 15:27:53 +0000
commite22f2e5c38baa1866793338fc7abde8c8e53b635 (patch)
treef6e7225e05bc35467b638416fa8487d538d02fed /src/federation/vote.rs
parent46fc2ab070b5f8d3cd6c8bd0d6bd15c624a061e5 (diff)
continuum-party vote: asks its node first whether a true is taken
A party's client recorded its vote, sent it, and only warned where its node refused it: a true every node refuses, its party's earlier one not dead where it builds, stayed in the record and bound the party, though no node held it. Taking it back out on the node's word would let a node that lies have its party vote twice. So it asks before it signs: POST /events/back names the party, the proposal and the events the vote would build on, and a node answers by what it asks itself before it casts one (vote::takes_true). Nothing signed is sent, so a node gets nothing it could pass on. Told it isn't taken, the client casts and records nothing; a node that doesn't answer, one before this, it says so of, and goes on as it did.
Diffstat (limited to 'src/federation/vote.rs')
-rw-r--r--src/federation/vote.rs34
1 files changed, 29 insertions, 5 deletions
diff --git a/src/federation/vote.rs b/src/federation/vote.rs
index 0bad500..9219656 100644
--- a/src/federation/vote.rs
+++ b/src/federation/vote.rs
@@ -234,6 +234,29 @@ pub(crate) fn backs_checkpoint(
}
}
+/// Whether `store` takes a `true` of `party` on the proposal of hash `proposal` on its
+/// current version, built on the events `on`, as far as the party's other votes go: at
+/// that history, none of its `true`s on another proposal but on one that is dead there
+/// (`State::may_back`). Why not, where it doesn't, or holds one of `on` not. A node asks
+/// before it casts one (`builds_on`), and answers a party's client asking before it signs
+/// one (`POST /events/back`): nothing signed goes to the node for that.
+pub(crate) fn takes_true(
+ store: &Store<Federation>,
+ party: &str,
+ proposal: &Id,
+ on: &[Id],
+) -> Result<(), String> {
+ if let Some(lacking) = on.iter().find(|id| !store.holds(id)) {
+ return Err(format!(
+ "this node holds no event {lacking}, which the vote builds on"
+ ));
+ }
+ store
+ .state_at(on)
+ .may_back(party, proposal, store.state().current())
+ .map_err(|why| format!("no store takes that vote: {}", why.0))
+}
+
/// 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
@@ -267,10 +290,7 @@ pub(crate) fn builds_on(
.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))?;
+ takes_true(store, party, proposal, &on)?;
}
Ok(on)
}
@@ -711,7 +731,11 @@ mod tests {
.any(|act| matches!(act, Act::Vote { yes: true, .. })),
"{acts:?}"
);
- // What it would have cast, its store refuses.
+ // As it answers a client that asks first; and what it would have cast, its store
+ // refuses.
+ assert!(takes_true(&store, "makefu", &checkpoint.hash(), &[proposal]).is_err());
+ assert!(takes_true(&store, "lass", &checkpoint.hash(), &[proposal]).is_ok());
+ assert!(takes_true(&store, "lass", &checkpoint.hash(), &[Id::of(b"none")]).is_err());
assert!(matches!(
store.offer(makefu.vote(&[proposal], on, checkpoint.hash(), true)),
Offered::Refused(_)