Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 81 additions & 1 deletion cumulus/polkadot-omni-node/lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -206,6 +279,11 @@ pub struct Cli<Config: CliConfig> {
#[arg(raw = true)]
pub relay_chain_args: Vec<String>,

/// 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: <Config::StatementStoreDefault as StatementStoreDefault>::CliArgs,

#[arg(skip)]
pub(crate) _phantom: PhantomData<Config>,
}
Expand Down Expand Up @@ -239,7 +317,9 @@ impl<Config: CliConfig> Cli<Config> {
.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,
}
}
Expand Down
4 changes: 2 additions & 2 deletions cumulus/polkadot-omni-node/lib/src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>,

/// 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 <https://github.com/paritytech/polkadot-sdk/issues/6020> is fixed.
Expand Down
2 changes: 1 addition & 1 deletion cumulus/polkadot-omni-node/lib/src/common/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
&parachain_config.data_path,
Default::default(),
Expand Down
6 changes: 4 additions & 2 deletions cumulus/polkadot-omni-node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,6 +45,8 @@ impl CliConfigT for CliConfig {
fn copyright_start_year() -> u16 {
2017
}

type StatementStoreDefault = DisableStatementStoreByDefault;
}

fn main() -> color_eyre::eyre::Result<()> {
Expand Down
1 change: 1 addition & 0 deletions cumulus/polkadot-parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
6 changes: 5 additions & 1 deletion cumulus/polkadot-parachain/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -42,6 +44,8 @@ impl CliConfigT for CliConfig {
fn copyright_start_year() -> u16 {
2017
}

type StatementStoreDefault = EnableStatementStoreByDefault;
}

fn main() -> color_eyre::eyre::Result<()> {
Expand Down
Loading