diff options
Diffstat (limited to 'src/config')
| -rw-r--r-- | src/config/file.rs | 12 | ||||
| -rw-r--r-- | src/config/mod.rs | 59 |
2 files changed, 57 insertions, 14 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. |
