diff options
| author | tv <tv@krebsco.de> | 2026-11-25 15:27:53 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-25 15:27:53 +0000 |
| commit | e22f2e5c38baa1866793338fc7abde8c8e53b635 (patch) | |
| tree | f6e7225e05bc35467b638416fa8487d538d02fed /src/api | |
| parent | 46fc2ab070b5f8d3cd6c8bd0d6bd15c624a061e5 (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/api')
| -rw-r--r-- | src/api/access.rs | 6 | ||||
| -rw-r--r-- | src/api/events.rs | 31 |
2 files changed, 35 insertions, 2 deletions
diff --git a/src/api/access.rs b/src/api/access.rs index 339d9de..9e8a018 100644 --- a/src/api/access.rs +++ b/src/api/access.rs @@ -452,7 +452,8 @@ fn federated(state: &AppState, request: &Request<Body>, user: &str) -> Option<Re } /// Whether a request is federation work: reading the events API (`GET` and `HEAD` of -/// `/events` and below), checking a fork (`POST /events/fork`), and keeping a session +/// `/events` and below), checking a fork (`POST /events/fork`), asking whether a `true` is +/// taken (`POST /events/back`), and keeping a session /// (`GET /auth/whoami`, `POST /auth/refresh`, `POST /auth/logout`); with `puts`, putting /// an event (`POST /events`) too. Nothing of the document (`/store`, `/stream`), the /// node (`/peers`, `/admin/…`), nor what a node's operator does to its store @@ -463,7 +464,7 @@ fn federation_work(method: &Method, path: &str, puts: bool) -> bool { let posts = *method == Method::POST; match path { "/auth/whoami" => reads, - "/auth/refresh" | "/auth/logout" | "/events/fork" => posts, + "/auth/refresh" | "/auth/logout" | "/events/fork" | "/events/back" => posts, "/events" => reads || (puts && posts), _ => reads && path.starts_with("/events/"), } @@ -493,6 +494,7 @@ mod tests { assert!(work(Method::GET, "/events/counts", false)); assert!(work(Method::HEAD, "/events/0c7e", false)); assert!(work(Method::POST, "/events/fork", false)); + assert!(work(Method::POST, "/events/back", false)); assert!(work(Method::POST, "/auth/refresh", false)); assert!(work(Method::GET, "/auth/whoami", false)); assert!(!work(Method::POST, "/events", false)); diff --git a/src/api/events.rs b/src/api/events.rs index 1d275f9..55b29f1 100644 --- a/src/api/events.rs +++ b/src/api/events.rs @@ -32,6 +32,7 @@ pub(super) fn router() -> Router<AppState> { .route("/events/counts", get(counts)) .route("/events/refused", get(refused)) .route("/events/fork", post(check_fork)) + .route("/events/back", post(check_back)) .route("/events/{id}", get(event)) .route("/admin/events/drop", post(drop_taken)) .route("/admin/events/allow", post(allow)) @@ -486,6 +487,36 @@ async fn make_fork(State(state): State<AppState>, Json(forking): Json<Forking>) } } +/// A `true` a party's client is about to sign: its party, the proposal's hash, and the +/// events it would build on. +#[derive(Deserialize)] +struct Backing { + party: String, + proposal: String, + on: Vec<String>, +} + +/// `POST /events/back`: whether this node takes a `true` of `party` on the proposal of +/// hash `proposal` on the current version, built on the events `on`, as far as the party's +/// other votes go (`vote::takes_true`); `why` where it doesn't. A party's client asks +/// before it signs and records one: nothing signed comes here, so the node gets nothing +/// to pass on, and a vote every node would refuse is never cast. +async fn check_back(State(state): State<AppState>, Json(backing): Json<Backing>) -> Response { + let Some(proposal) = Id::from_hex(&backing.proposal) else { + return error_response(StatusCode::BAD_REQUEST, "not a proposal's hash", None); + }; + let on = match read_ids(&backing.on) { + Ok(on) => on, + Err(error) => return error.into_response(), + }; + with_store(&state, |store| { + match crate::federation::vote::takes_true(store, &backing.party, &proposal, &on) { + Ok(()) => json!({"takes": true, "why": null}), + Err(why) => json!({"takes": false, "why": why}), + } + }) +} + /// `POST /events/fork`: what this node finds of the fork whose root is the body's first /// line, as the file its founders start from holds it: whether it builds that root at /// its heads, and why not; what it holds that those heads lack; what the fork's version |
