diff options
Diffstat (limited to 'src/federation/client.rs')
| -rw-r--r-- | src/federation/client.rs | 21 |
1 files changed, 17 insertions, 4 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)] @@ -213,9 +216,18 @@ 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()) |
