diff --git a/Cargo.lock b/Cargo.lock index bbafe38b608e0..75a633c10ce09 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15517,6 +15517,7 @@ dependencies = [ "asset-hub-westend-runtime", "bridge-hub-rococo-runtime", "bridge-hub-westend-runtime", + "clap", "collectives-westend-runtime", "color-eyre", "coretime-rococo-runtime", diff --git a/cumulus/polkadot-omni-node/lib/src/cli.rs b/cumulus/polkadot-omni-node/lib/src/cli.rs index 8b8e83de44a67..996ce2deb2614 100644 --- a/cumulus/polkadot-omni-node/lib/src/cli.rs +++ b/cumulus/polkadot-omni-node/lib/src/cli.rs @@ -36,6 +36,75 @@ use std::{ marker::PhantomData, path::PathBuf, }; + +// Seal the trait `StatementStoreDefault` to prevent external implementations. +mod seal { + pub trait Sealed {} + impl Sealed for super::EnableStatementStoreByDefault {} + impl Sealed for super::DisableStatementStoreByDefault {} +} + +/// Enable the statement store by default in the CLI. +/// +/// This is a flag type that implements the trait [`StatementStoreDefault`]. +pub struct EnableStatementStoreByDefault; + +/// Disable the statement store by default in the CLI. +/// +/// This is a flag type that implements the trait [`StatementStoreDefault`]. +pub struct DisableStatementStoreByDefault; + +/// Type used to provide the CLI arguments when statmeent store is enabled by default. +#[derive(clap::Parser)] +pub struct EnableStatementStoreByDefaultCliArg { + /// Disable the statement store. + /// + /// The statement store is an off-chain data-store for signed statements accessible via RPC + /// and OCW. + /// It uses the runtime api to get the allowance associated to an account. + #[arg(long)] + disable_statement_store: bool, +} + +/// Type used to provide the CLI arguments when statmeent store is disabled by default. +#[derive(clap::Parser)] +pub struct DisableStatementStoreByDefaultCliArg { + /// Enable the statement store. + /// + /// The statement store is an off-chain data-store for signed statements accessible via RPC + /// and OCW. + /// It uses the runtime api to get the allowance associated to an account. + #[arg(long)] + enable_statement_store: bool, +} + +/// Trait to specify the default statement store configuration. +/// +/// Either [`EnableStatementStoreByDefault`] or [`DisableStatementStoreByDefault`]. +pub trait StatementStoreDefault: seal::Sealed { + /// The CLI arguments type that is used in the node CLI. + type CliArgs: FromArgMatches + clap::Args; + + /// The final statement store configuration from the CLI. + fn enable_statement_store(cli_args: &Self::CliArgs) -> bool; +} + +impl StatementStoreDefault for DisableStatementStoreByDefault { + type CliArgs = EnableStatementStoreByDefaultCliArg; + + fn enable_statement_store(cli_args: &Self::CliArgs) -> bool { + !cli_args.disable_statement_store + } +} + +impl StatementStoreDefault for EnableStatementStoreByDefault { + type CliArgs = DisableStatementStoreByDefaultCliArg; + + fn enable_statement_store(cli_args: &Self::CliArgs) -> bool { + cli_args.enable_statement_store + } +} + /// Trait that can be used to customize some of the customer-facing info related to the node binary /// that is being built using this library. /// @@ -66,6 +135,10 @@ pub trait CliConfig { /// The starting copyright year of the resulting node binary. fn copyright_start_year() -> u16; + + /// The default statement store configuration: [`EnableStatementStoreByDefault`] or + /// [`DisableStatementStoreByDefault`]. + type StatementStoreDefault: StatementStoreDefault; } /// Sub-commands supported by the collator. @@ -206,6 +279,11 @@ pub struct Cli { #[arg(raw = true)] pub relay_chain_args: Vec, + /// Statement store cli args. + // Note: this doc doesn't show up in the CLI, because `flatten` is used. TODO TODO: double check + #[clap(flatten)] + pub statement_store: ::CliArgs, + #[arg(skip)] pub(crate) _phantom: PhantomData, } @@ -239,7 +317,9 @@ impl Cli { .then(|| AuthoringPolicy::SlotBased) .unwrap_or(self.authoring), export_pov: self.export_pov_to_path.clone(), - disable_statement_store: self.disable_statement_store, + enable_statement_store: Config::StatementStoreDefault::enable_statement_store( + &self.statement_store, + ), max_pov_percentage: self.run.experimental_max_pov_percentage, } } diff --git a/cumulus/polkadot-omni-node/lib/src/common/mod.rs b/cumulus/polkadot-omni-node/lib/src/common/mod.rs index c0ba10fb93d56..98b31b6b844cf 100644 --- a/cumulus/polkadot-omni-node/lib/src/common/mod.rs +++ b/cumulus/polkadot-omni-node/lib/src/common/mod.rs @@ -116,8 +116,8 @@ pub struct NodeExtraArgs { /// If set, each `PoV` build by the node will be exported to this folder. pub export_pov: Option, - /// Disable the statement store. - pub disable_statement_store: bool, + /// Enable the statement store. + pub enable_statement_store: bool, /// The maximum percentage of the maximum PoV size that the collator can use. /// It will be removed once is fixed. diff --git a/cumulus/polkadot-omni-node/lib/src/common/spec.rs b/cumulus/polkadot-omni-node/lib/src/common/spec.rs index 71bd4fba3f0db..fc0672b436657 100644 --- a/cumulus/polkadot-omni-node/lib/src/common/spec.rs +++ b/cumulus/polkadot-omni-node/lib/src/common/spec.rs @@ -286,7 +286,7 @@ pub(crate) trait NodeSpec: BaseNodeSpec { .await .map_err(|e| sc_service::Error::Application(Box::new(e) as Box<_>))?; - let statement_store = if !node_extra_args.disable_statement_store { + let statement_store = if node_extra_args.enable_statement_store { let statement_store = sc_statement_store::Store::new_shared( ¶chain_config.data_path, Default::default(), diff --git a/cumulus/polkadot-omni-node/src/main.rs b/cumulus/polkadot-omni-node/src/main.rs index a20073c54c45e..88f782e61ea22 100644 --- a/cumulus/polkadot-omni-node/src/main.rs +++ b/cumulus/polkadot-omni-node/src/main.rs @@ -22,8 +22,8 @@ #![warn(unused_extern_crates)] use polkadot_omni_node_lib::{ - chain_spec::DiskChainSpecLoader, run, runtime::DefaultRuntimeResolver, CliConfig as CliConfigT, - RunConfig, NODE_VERSION, + chain_spec::DiskChainSpecLoader, cli::DisableStatementStoreByDefault, run, + runtime::DefaultRuntimeResolver, CliConfig as CliConfigT, RunConfig, NODE_VERSION, }; struct CliConfig; @@ -45,6 +45,8 @@ impl CliConfigT for CliConfig { fn copyright_start_year() -> u16 { 2017 } + + type StatementStoreDefault = DisableStatementStoreByDefault; } fn main() -> color_eyre::eyre::Result<()> { diff --git a/cumulus/polkadot-parachain/Cargo.toml b/cumulus/polkadot-parachain/Cargo.toml index 071bf682c705a..584b0001abe27 100644 --- a/cumulus/polkadot-parachain/Cargo.toml +++ b/cumulus/polkadot-parachain/Cargo.toml @@ -17,6 +17,7 @@ name = "polkadot-parachain" path = "src/main.rs" [dependencies] +clap = { features = ["derive"], workspace = true } color-eyre = { workspace = true } hex-literal = { workspace = true, default-features = true } log = { workspace = true, default-features = true } diff --git a/cumulus/polkadot-parachain/src/main.rs b/cumulus/polkadot-parachain/src/main.rs index f00a7430fabf8..1cc2d2b73f93a 100644 --- a/cumulus/polkadot-parachain/src/main.rs +++ b/cumulus/polkadot-parachain/src/main.rs @@ -21,7 +21,9 @@ mod chain_spec; -use polkadot_omni_node_lib::{run, CliConfig as CliConfigT, RunConfig, NODE_VERSION}; +use polkadot_omni_node_lib::{ + cli::EnableStatementStoreByDefault, run, CliConfig as CliConfigT, RunConfig, NODE_VERSION, +}; struct CliConfig; @@ -42,6 +44,8 @@ impl CliConfigT for CliConfig { fn copyright_start_year() -> u16 { 2017 } + + type StatementStoreDefault = EnableStatementStoreByDefault; } fn main() -> color_eyre::eyre::Result<()> {