From bf896c2a604557a764e889b45e37dbe416c660ba Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 17 Nov 2026 12:59:39 +0000 Subject: client: a record begun from the store's root casts on its first version A record casts nothing on the version current when it began, as a `true` sent before may be held back somewhere. A federation's first version is current from its start, so a record begun at a node casts nothing on it, and with every party's begun so, no proposal on it can pass. `continuum-party init PARTY --root FILE` begins a record from the file the store's swarm starts from, for a party that never voted in it (`Record::before`): nothing was sent before it, and it casts on every version, the first too. A node voting by itself takes such a record as its `--store-vote-record`. --- src/federation/client.rs | 21 +++++++++++++++++---- src/federation/party.rs | 30 +++++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/federation/client.rs b/src/federation/client.rs index 85411fe..9834771 100644 --- a/src/federation/client.rs +++ b/src/federation/client.rs @@ -9,7 +9,9 @@ //! dead, as signed, so that once a checkpoint left them out nothing names its party as //! voting twice; and the events it signed besides, to sign again what a move refused. It //! is written before a vote is sent. A record begins on the version current then, and -//! casts nothing on it, as a `true` sent before it began may be held back somewhere. +//! casts nothing on it, as a `true` sent before it began may be held back somewhere; one +//! begun from the store's root by a party that never voted in it casts on every version, +//! as nothing was sent before it. use std::collections::{BTreeMap, BTreeSet}; use std::path::Path; @@ -133,7 +135,8 @@ pub(crate) struct Record { /// The store it is of, by ID. pub(crate) store: String, pub(crate) party: String, - /// The version current when it began, by hash: it casts nothing on it. + /// The version current when it began, by hash: it casts nothing on it. Empty for one + /// begun from the store's root. pub(crate) began: String, /// The versions it voted on, by hash, each as its JCS text. #[serde(default)] @@ -212,10 +215,19 @@ fn dead_by(on: &Version, proposal: &Id, nays: &[Vec]) -> bool { impl Record { /// A record of `party` of the store `store`, beginning on `current`. pub(crate) fn begin(store: Id, party: &str, current: &Version) -> Self { + Record { + began: current.hash.to_string(), + ..Record::before(store, party) + } + } + + /// A record of `party` of the store `store`, begun from its root by a party that never + /// voted in it: it casts on every version. + pub(crate) fn before(store: Id, party: &str) -> Self { Record { store: store.to_string(), party: party.to_owned(), - began: current.hash.to_string(), + began: String::new(), versions: BTreeMap::new(), votes: Vec::new(), nays: Vec::new(), @@ -508,7 +520,8 @@ mod tests { .may_vote(¤t, one.hash(), &one.json(), true, &[]) .is_err() ); - record.began = Id::of(b"earlier").to_string(); + // Begun from the root: it casts on the first version. + record = Record::before(root, "tv"); assert_eq!( record.may_vote(¤t, one.hash(), &one.json(), true, &[]), Ok(Vec::new()) diff --git a/src/federation/party.rs b/src/federation/party.rs index ecd75a9..cb9eb54 100644 --- a/src/federation/party.rs +++ b/src/federation/party.rs @@ -4,7 +4,9 @@ //! keeps its party's record (`--record`, `client::Record`), by which it votes, written //! before a vote is sent. //! -//! * `init PARTY`: begins a record of `PARTY`, on the version current now; +//! * `init PARTY`: begins a record of `PARTY`, on the version current now; with `--root +//! FILE`, from the file the store's swarm starts from, for a party that never voted in +//! it: the record casts on every version, the first too; //! * `write PATH VALUE`: writes `VALUE` (JSON) at `PATH`; //! * `keys KEY...`, `nodes NODE...`: writes the party's key set (`authorized_keys` lines) //! or node list (node IDs); @@ -76,7 +78,13 @@ fn command() -> Command { .subcommand( Command::new("init") .about("Begins a record") - .arg(id("party")), + .arg(id("party")) + .arg( + Arg::new("root") + .long("root") + .value_name("FILE") + .help("From the file the store's swarm starts from, for a party that never voted in it"), + ), ) .subcommand( Command::new("write") @@ -224,10 +232,22 @@ pub(crate) async fn main() -> Result<()> { bail!("{} holds a record already", path.display()); } let party = sub.get_one::("party").expect("required"); - let (store, _) = node.summary().await?; - let record = Record::begin(store, party, &node.current().await?); + let record = match sub.get_one::("root") { + Some(file) => { + let bytes = std::fs::read(file).with_context(|| format!("Reading {file}"))?; + let (root, kept) = super::fork::read_root_file(&bytes); + if let Err(refused) = Store::::new(root.clone(), kept) { + bail!("no store's root: {}", refused.0); + } + Record::before(Id::of(&root), party) + } + None => { + let (store, _) = node.summary().await?; + Record::begin(store, party, &node.current().await?) + } + }; record.save(&path).map_err(|why| anyhow!(why))?; - println!("began a record of {party}, of the store {store}"); + println!("began a record of {party}, of the store {}", record.store); return Ok(()); } let mut record = Record::load(&path).map_err(|why| anyhow!(why))?; -- cgit v1.3.1