diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/config/file.rs | 12 | ||||
| -rw-r--r-- | src/config/mod.rs | 59 | ||||
| -rw-r--r-- | src/federation/vote.rs | 137 | ||||
| -rw-r--r-- | src/lib.rs | 1 | ||||
| -rw-r--r-- | src/simtest/holding.rs | 25 |
5 files changed, 67 insertions, 167 deletions
diff --git a/src/config/file.rs b/src/config/file.rs index ee71133..5984c10 100644 --- a/src/config/file.rs +++ b/src/config/file.rs @@ -79,6 +79,12 @@ fn load_inner( for name in unsets { if spec_in(options, &name).is_none() { + if let Some(why) = super::gone(&name) { + bail!( + "option {name:?} in unset, in {}, is gone: {why}", + canonical.display() + ); + } bail!( "unknown option {name:?} in unset, in {}", canonical.display() @@ -91,8 +97,10 @@ fn load_inner( let mut own = Vec::new(); flatten(&root, "", &dir, &mut own).with_context(|| format!("in {}", canonical.display()))?; for (name, value) in own { - let spec = spec_in(options, &name) - .ok_or_else(|| anyhow!("unknown option {name:?} in {}", canonical.display()))?; + let spec = spec_in(options, &name).ok_or_else(|| match super::gone(&name) { + Some(why) => anyhow!("option {name:?} in {} is gone: {why}", canonical.display()), + None => anyhow!("unknown option {name:?} in {}", canonical.display()), + })?; let (value, sources) = super::resolve_file_value(spec, value, &dir) .with_context(|| format!("option {name} in {}", canonical.display()))?; let entry = Entry { diff --git a/src/config/mod.rs b/src/config/mod.rs index f9663c1..cfc2c76 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -290,14 +290,6 @@ pub(crate) const OPTIONS: &[OptionSpec] = &[ ), #[cfg(feature = "federation")] option( - "store-nay-beside", - Kind::Flag, - "BOOL", - Some("false"), - "With store-vote-key: where it backs a proposal that can still pass, vote `false` on every other one on the current version that only moves to a checkpoint, so that, of two checkpoints proposed at once, the other dies and its backers are free.", - ), - #[cfg(feature = "federation")] - option( "store-propose-events", Kind::Integer, "COUNT", @@ -746,6 +738,39 @@ pub(super) fn spec_in(options: &'static [OptionSpec], name: &str) -> Option<&'st options.iter().find(|spec| spec.name == name) } +/// Options of earlier releases that are gone, each with what to do instead: a node given +/// one, in a configuration file or on its command line, says so and stops, where "unknown +/// option" would leave its operator guessing. +const GONE: &[(&str, &str)] = &[( + "store-nay-beside", + "a node votes `false` by no rule any more, as a party it follows could count on that \ + `false` to pass two checkpoints, voting twice: remove the option; where two checkpoints \ + stay proposed, their parties end one by hand (docs/guides/federation/checkpoints.md, \ + Two proposed at once)", +)]; + +/// Why `name` is no option any more, where it was one (`GONE`). +pub(super) fn gone(name: &str) -> Option<&'static str> { + GONE.iter() + .find(|(gone, _)| *gone == name) + .map(|(_, why)| *why) +} + +/// Stops on an argument naming an option that is gone, saying why, before the command +/// line is read: clap would call it unexpected. +fn refuse_gone(arguments: impl IntoIterator<Item = String>) -> Result<()> { + for argument in arguments { + let Some(name) = argument.strip_prefix("--") else { + continue; + }; + let name = name.split('=').next().unwrap_or(name); + if let Some(why) = gone(name) { + bail!("--{name} is gone: {why}"); + } + } + Ok(()) +} + /// The options of a party's client (`continuum-party`), set as the node's are: on the /// command line, or in configuration files of the same format (`with_options`, /// `merged`). @@ -849,9 +874,6 @@ pub(crate) struct Settings { #[serde(default)] pub(crate) store_follow_any: bool, #[cfg(feature = "federation")] - #[serde(default)] - pub(crate) store_nay_beside: bool, - #[cfg(feature = "federation")] pub(crate) store_propose_events: Option<usize>, #[cfg(feature = "federation")] #[serde( @@ -1401,7 +1423,6 @@ impl Settings { ("store-vote-record", self.store_vote_record.is_some()), ("store-follow", !self.store_follow.is_empty()), ("store-follow-any", self.store_follow_any), - ("store-nay-beside", self.store_nay_beside), ("store-propose-events", self.store_propose_events.is_some()), ("store-propose-every", self.store_propose_every.is_some()), ]; @@ -2173,6 +2194,7 @@ impl Loaded { /// Reads the command line and the configuration files it names. Exits on `--help`, /// `--version` and command-line syntax errors, like any command. pub(crate) fn load() -> Result<Loaded> { + refuse_gone(std::env::args().skip(1))?; let matches = command().get_matches(); let print_only = matches.get_flag(PRINT_CONFIG); let node_id = matches.subcommand_matches(NODE_ID).map(|sub| { @@ -2456,6 +2478,19 @@ mod tests { assert!(with("7h").is_ok()); } + /// An option that is gone is named so, with what to do, on the command line and in a + /// configuration file. + #[test] + fn an_option_that_is_gone_is_said_to_be() { + let why = refuse_gone(["--store-nay-beside".to_owned()]) + .unwrap_err() + .to_string(); + assert!(why.contains("is gone") && why.contains("by hand"), "{why}"); + assert!(refuse_gone(["--store-nay-beside=true".to_owned()]).is_err()); + assert!(refuse_gone(["--store-follow".to_owned(), "tv".to_owned()]).is_ok()); + assert!(gone("store-follow").is_none()); + } + #[test] fn options_and_settings_agree() { // Every option is a Settings field, and every field an option. diff --git a/src/federation/vote.rs b/src/federation/vote.rs index baf8dd0..0bad500 100644 --- a/src/federation/vote.rs +++ b/src/federation/vote.rs @@ -55,8 +55,6 @@ pub(crate) struct Rules { /// How long it holds an event before it holds it for a while: the voters' rule, and how /// long a new proposal holds back a checkpoint. pub(crate) held_for: Duration, - /// Voting `false` on a checkpoint proposed beside one it backs. - pub(crate) nay_beside: bool, /// How long its store holds its checkpoint, or runs, before it backs or proposes a /// later one. pub(crate) back_after: Duration, @@ -382,9 +380,6 @@ pub(crate) fn decide(seen: &Seen<'_>, rules: &Rules, record: &Record) -> Vec<Act }); } } - if rules.nay_beside { - acts.extend(beside(¤t, &all, &acts, record, &nays)); - } if !backed && let Some(version) = checkpoint(seen, rules, ¤t, &all) { let hash = Id::of(&version.bytes()); if record @@ -397,64 +392,6 @@ pub(crate) fn decide(seen: &Seen<'_>, rules: &Rules, record: &Record) -> Vec<Act acts } -/// The votes `false` a node casts beside what it backs: where its party backs a proposal on -/// `current` that can still pass, by its `record` or by `acts`, on every other proposal -/// that only moves to a checkpoint and can still pass, but where it votes already. -fn beside( - current: &Version, - all: &[Proposed], - acts: &[Act], - record: &Record, - nays: &[Vec<u8>], -) -> Vec<Act> { - let voting: BTreeSet<Id> = acts - .iter() - .filter_map(|act| match act { - Act::Vote { proposal, .. } => Some(*proposal), - Act::Propose(_) => None, - }) - .collect(); - let backs: BTreeSet<Id> = record - .backs(¤t.hash) - .into_iter() - .chain(acts.iter().filter_map(|act| match act { - Act::Vote { - proposal, - yes: true, - .. - } => Some(*proposal), - _ => None, - })) - .collect(); - let backing = all - .iter() - .any(|proposed| backs.contains(&proposed.hash) && alive(current, proposed)); - if !backing { - return Vec::new(); - } - all.iter() - .filter(|proposed| { - !backs.contains(&proposed.hash) - && !voting.contains(&proposed.hash) - && alive(current, proposed) - && proposed - .version - .as_ref() - .is_some_and(|version| version.only_moves_on(current)) - }) - .filter(|proposed| { - record - .may_vote(current, proposed.hash, &proposed.json, false, nays) - .is_ok() - }) - .map(|proposed| Act::Vote { - proposal: proposed.hash, - yes: false, - nays: Vec::new(), - }) - .collect() -} - /// A vote by hand, cast through the node that votes for its party, which keeps its /// party's one record: `yes` on the proposal of hash `proposal` on the current version, by /// the record, and with a `true` by the voters' rule; or why not. @@ -1180,78 +1117,4 @@ mod tests { let record = super::tests::record(&apart, "tv"); assert!(decide(&seen(&apart, &held), &rules, &record).is_empty()); } - - /// Two checkpoints proposed at once: a node backing one votes `false` on the other by - /// its rule, and on nothing else; without the rule, on nothing. - #[test] - fn a_node_votes_false_on_a_checkpoint_beside_the_one_it_backs() { - let (tv, lass, _, first, mut store) = three(); - let root = store.id(); - let on = first.hash(); - let here = taken( - &mut store, - tv.write(&[root], "home/tv/a", harness::str("1")), - ); - let there = taken( - &mut store, - lass.write(&[root], "home/lass/b", harness::str("1")), - ); - let (mut one, mut two) = (first.after(on), first.after(on)); - one.checkpoint = Some(vec![here]); - two.checkpoint = Some(vec![there]); - let mut other = first.after(on); - other.rules.push(("names/x".to_owned(), harness::str("tv"))); - let proposing = tv.propose(&[here], &one.json()); - let mut record = record(&store, "tv"); - record.signed(&proposing); - let proposal = taken(&mut store, proposing); - let by_lass = [ - taken(&mut store, lass.propose(&[there], &two.json())), - taken(&mut store, lass.propose(&[root], &other.json())), - ]; - // lass's, held since its proposals came, after tv proposed. - let long = |id: &Id| { - Some(if *id == there || by_lass.contains(id) { - Duration::from_secs(60) - } else { - Duration::from_secs(3600) - }) - }; - let rules = Rules { - nay_beside: true, - ..Rules::default() - }; - // Backing its own, this round: `false` on the other checkpoint, not on the version - // that changes more. - let acts = decide(&seen(&store, &long), &rules, &record); - assert_eq!(acts.len(), 2, "{acts:?}"); - assert!(acts.contains(&Act::Vote { - proposal: one.hash(), - yes: true, - nays: Vec::new() - })); - assert!(acts.contains(&Act::Vote { - proposal: two.hash(), - yes: false, - nays: Vec::new() - })); - let quiet = Rules::default(); - assert_eq!(decide(&seen(&store, &long), &quiet, &record).len(), 1); - // Its `true` recorded and taken: `false` on the other, once. - let yes = tv.vote(&[proposal], on, one.hash(), true); - record.cast(store.state().current(), &yes, Vec::new()); - taken(&mut store, yes); - let acts = decide(&seen(&store, &long), &rules, &record); - assert_eq!( - acts, - vec![Act::Vote { - proposal: two.hash(), - yes: false, - nays: Vec::new() - }] - ); - let no = tv.vote(&[proposal], on, two.hash(), false); - record.cast(store.state().current(), &no, Vec::new()); - assert!(decide(&seen(&store, &long), &rules, &record).is_empty()); - } } @@ -67,7 +67,6 @@ fn voter(args: &config::Settings) -> Result<Option<federation::held::Voter>> { rules: federation::vote::Rules { follow: args.store_follow.clone(), follow_any: args.store_follow_any, - nay_beside: args.store_nay_beside, propose_events: args.store_propose_events, propose_every: args.store_propose_every, propose_versions: (args.store_propose_versions > 0) diff --git a/src/simtest/holding.rs b/src/simtest/holding.rs index 12dac23..16158b1 100644 --- a/src/simtest/holding.rs +++ b/src/simtest/holding.rs @@ -774,10 +774,9 @@ async fn store_attack_10() { /// Two checkpoints proposed at once, by nodes voting by themselves: a for tv and b for /// lass, apart, each propose one once their stores took six events, and back it; c votes -/// for makefu, following tv; each votes `false` on a checkpoint beside the one it backs. -/// a and b, together, vote `false` on each other's: the votes split. With c, tv's passes -/// and every node moves there; lass's is dead by the nays of tv and makefu, which their -/// records hold. +/// for makefu, following tv. a and b, together, hold both, each party's `true` on its own: +/// the votes split, and no node votes `false` by a rule. With c, tv's passes by two +/// thirds and every node moves there; lass's lapses with the move. #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn federation_attack_59() { let sim = Sim::with_identity(89); @@ -786,12 +785,10 @@ async fn federation_attack_59() { let dir = crate::files::scratch_dir("sim-attack-59"); let proposing = Rules { propose_events: Some(6), - nay_beside: true, ..Rules::default() }; let following = Rules { follow: vec!["tv".to_owned()], - nay_beside: true, held_for: Duration::from_secs(3600), ..Rules::default() }; @@ -831,20 +828,18 @@ async fn federation_attack_59() { sim.net.bring_up("a"); sim.net.bring_up("b"); sim.wait_until( - "a and b vote `false` on each other's", + "a and b hold both, each party's `true` on its own", LONG, move || async move { all[..2].iter().all(|node| { - ballot(node, "tv") - .is_some_and(|(_, yes, no)| yes == set(&["tv"]) && no == set(&["lass"])) + ballot(node, "tv").is_some_and(|(_, yes, no)| yes == set(&["tv"]) && no.is_empty()) && ballot(node, "lass") - .is_some_and(|(_, yes, no)| yes == set(&["lass"]) && no == set(&["tv"])) + .is_some_and(|(_, yes, no)| yes == set(&["lass"]) && no.is_empty()) }) }, ) .await; let (passing, _, _) = ballot(&nodes[0], "tv").expect("tv's"); - let (other, _, _) = ballot(&nodes[0], "lass").expect("lass's"); sim.net.bring_up("c"); sim.wait_until( "every node moves to tv's checkpoint", @@ -852,18 +847,18 @@ async fn federation_attack_59() { move || async move { all.iter().all(|node| current(node) == Some(passing)) }, ) .await; - for party in ["tv", "makefu"] { + for party in ["tv", "lass", "makefu"] { let record = Record::load(&dir.join(format!("{party}.json"))).expect("its record"); let nay = record.votes.iter().any(|vote| { matches!( Event::read_taken(vote.as_bytes()), Some(Event::Signed(Signed { - does: Does::Vote { proposal, yes: false, .. }, + does: Does::Vote { yes: false, .. }, .. - })) if proposal == other + })) ) }); - assert!(nay, "{party} voted no `false` on lass's checkpoint"); + assert!(!nay, "{party}'s node voted `false`, by no rule of its"); } } |
