Skip to content

Commit 9f59e2c

Browse files
Statement Store: Introduce new CLI args (#11407)
Closes #11265 In addition to introducing new CLI args, this PR reworks the statement store configuration, consolidating all parameters into a single structure. --------- Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 1866a5d commit 9f59e2c

File tree

14 files changed

+191
-83
lines changed

14 files changed

+191
-83
lines changed

cumulus/polkadot-omni-node/lib/src/cli.rs

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ pub struct Cli<Config: CliConfig> {
226226
/// Number of concurrent workers for statement validation from the network.
227227
///
228228
/// Only relevant when `--enable-statement-store` is used.
229-
#[arg(long, default_value_t = 1)]
229+
#[arg(long, default_value_t = sc_statement_store::DEFAULT_NETWORK_WORKERS)]
230230
pub statement_network_workers: usize,
231231

232232
/// Maximum statements per second per peer before rate limiting kicks in.
@@ -235,9 +235,33 @@ pub struct Cli<Config: CliConfig> {
235235
/// while enforcing the average rate over time.
236236
///
237237
/// Only relevant when `--enable-statement-store` is used.
238-
#[arg(long, default_value_t = 50_000)]
238+
#[arg(long, default_value_t = sc_statement_store::DEFAULT_RATE_LIMIT)]
239239
pub statement_rate_limit: u32,
240240

241+
/// Maximum number of statements the statement store can hold.
242+
///
243+
/// Once this limit is reached, lower-priority statements may be evicted.
244+
///
245+
/// Only relevant when `--enable-statement-store` is used.
246+
#[arg(long, default_value_t = sc_statement_store::DEFAULT_MAX_TOTAL_STATEMENTS)]
247+
pub statement_store_max_total_statements: usize,
248+
249+
/// Maximum total data size (in bytes) the statement store can hold.
250+
///
251+
/// Once this limit is reached, lower-priority statements may be evicted.
252+
///
253+
/// Only relevant when `--enable-statement-store` is used.
254+
#[arg(long, default_value_t = sc_statement_store::DEFAULT_MAX_TOTAL_SIZE)]
255+
pub statement_store_max_total_size: usize,
256+
257+
/// Number of seconds for which removed statements won't be allowed to be added back.
258+
///
259+
/// This prevents old statements from being re-propagated on the network.
260+
///
261+
/// Only relevant when `--enable-statement-store` is used.
262+
#[arg(long, default_value_t = sc_statement_store::DEFAULT_PURGE_AFTER_SEC)]
263+
pub statement_store_purge_after_sec: u64,
264+
241265
#[arg(skip)]
242266
pub(crate) _phantom: PhantomData<Config>,
243267
}
@@ -282,9 +306,15 @@ impl<Config: CliConfig> Cli<Config> {
282306
.unwrap_or(self.authoring),
283307
export_pov: self.export_pov_to_path.clone(),
284308
max_pov_percentage: self.run.experimental_max_pov_percentage,
285-
enable_statement_store: self.enable_statement_store,
286-
statement_network_workers: self.statement_network_workers,
287-
statement_rate_limit: self.statement_rate_limit,
309+
statement_store_config: self.enable_statement_store.then_some(
310+
sc_statement_store::Config {
311+
max_total_statements: self.statement_store_max_total_statements,
312+
max_total_size: self.statement_store_max_total_size,
313+
purge_after_sec: self.statement_store_purge_after_sec,
314+
network_workers: self.statement_network_workers,
315+
rate_limit: self.statement_rate_limit,
316+
},
317+
),
288318
storage_monitor: self.storage_monitor.clone(),
289319
}
290320
}

cumulus/polkadot-omni-node/lib/src/common/mod.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,9 @@ pub struct NodeExtraArgs {
124124
/// It will be removed once <https://github.com/paritytech/polkadot-sdk/issues/6020> is fixed.
125125
pub max_pov_percentage: Option<u32>,
126126

127-
/// If true then the statement store will be enabled.
128-
pub enable_statement_store: bool,
129-
130-
/// Number of concurrent workers for statement validation from the network.
131-
pub statement_network_workers: usize,
132-
133-
/// Maximum statements per second per peer before rate limiting kicks in.
134-
pub statement_rate_limit: u32,
127+
/// Statement store and network handler configuration.
128+
/// `None` disables the statement store.
129+
pub statement_store_config: Option<sc_statement_store::Config>,
135130

136131
/// Parameters for storage monitoring.
137132
pub storage_monitor: sc_storage_monitor::StorageMonitorParams,

cumulus/polkadot-omni-node/lib/src/common/spec.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,14 @@ pub(crate) trait NodeSpec: BaseNodeSpec {
383383
parachain_config.prometheus_config.as_ref().map(|config| &config.registry),
384384
);
385385

386-
let statement_handler_proto = node_extra_args.enable_statement_store.then(|| {
387-
new_statement_handler_proto(&*client, &parachain_config, &metrics, &mut net_config)
386+
let statement_handler_proto = node_extra_args.statement_store_config.map(|config| {
387+
let proto = new_statement_handler_proto(
388+
&*client,
389+
&parachain_config,
390+
&metrics,
391+
&mut net_config,
392+
);
393+
(proto, config)
388394
});
389395

390396
let (network, system_rpc_tx, tx_handler_controller, sync_service) =
@@ -405,7 +411,7 @@ pub(crate) trait NodeSpec: BaseNodeSpec {
405411
let peer_id = network.local_peer_id();
406412

407413
let statement_store = statement_handler_proto
408-
.map(|statement_handler_proto| {
414+
.map(|(statement_handler_proto, config)| {
409415
build_statement_store(
410416
&parachain_config,
411417
&mut task_manager,
@@ -414,8 +420,7 @@ pub(crate) trait NodeSpec: BaseNodeSpec {
414420
sync_service.clone(),
415421
params.keystore_container.local_keystore(),
416422
statement_handler_proto,
417-
node_extra_args.statement_network_workers,
418-
node_extra_args.statement_rate_limit,
423+
config,
419424
)
420425
})
421426
.transpose()?;

cumulus/polkadot-omni-node/lib/src/common/statement_store.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,11 @@ pub(crate) fn build_statement_store<
6363
sync_service: Arc<sc_network_sync::service::syncing_service::SyncingService<Block>>,
6464
local_keystore: Arc<sc_keystore::LocalKeystore>,
6565
statement_handler_proto: sc_network_statement::StatementHandlerPrototype,
66-
statement_network_workers: usize,
67-
statement_rate_limit: u32,
66+
config: sc_statement_store::Config,
6867
) -> sc_service::error::Result<Arc<Store>> {
6968
let statement_store = sc_statement_store::Store::new_shared(
7069
&parachain_config.data_path,
71-
Default::default(),
70+
config,
7271
client,
7372
local_keystore,
7473
parachain_config.prometheus_registry(),
@@ -87,8 +86,8 @@ pub(crate) fn build_statement_store<
8786
statement_store.clone(),
8887
parachain_config.prometheus_registry(),
8988
statement_protocol_executor,
90-
statement_network_workers,
91-
statement_rate_limit,
89+
config.network_workers,
90+
config.rate_limit,
9291
)?;
9392
task_manager.spawn_handle().spawn(
9493
"network-statement-handler",

prdoc/pr_11407.prdoc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
title: 'Statement Store: Introduce new CLI args'
2+
doc:
3+
- audience: [Node Dev, Node Operator]
4+
description: |-
5+
Introduce new CLI args to control statement store parameters.
6+
Rework the statement store configuration, consolidating all parameters into a single structure.
7+
crates:
8+
- name: polkadot-omni-node-lib
9+
bump: major
10+
- name: sc-statement-store
11+
bump: major
12+
- name: staging-node-cli
13+
bump: major
14+
- name: sp-statement-store
15+
bump: major

substrate/bin/node/cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ node-inspect = { optional = true, workspace = true, default-features = true }
179179
polkadot-sdk = { features = [
180180
"frame-benchmarking-cli",
181181
"sc-cli",
182+
"sc-statement-store",
182183
"sc-storage-monitor",
183184
"substrate-build-script-utils",
184185
], optional = true, workspace = true, default-features = true }

substrate/bin/node/cli/benches/block_production.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase {
117117
config,
118118
None,
119119
false,
120-
1,
121-
sc_network_statement::config::DEFAULT_STATEMENTS_PER_SECOND,
120+
Default::default(),
122121
|_, _| (),
123122
)
124123
.expect("creating a full node doesn't fail")

substrate/bin/node/cli/benches/transaction_pool.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase {
104104
config,
105105
None,
106106
false,
107-
1,
108-
sc_network_statement::config::DEFAULT_STATEMENTS_PER_SECOND,
107+
Default::default(),
109108
|_, _| (),
110109
)
111110
.expect("Creates node")

substrate/bin/node/cli/src/chain_spec.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,7 @@ pub(crate) mod tests {
472472
config,
473473
None,
474474
false,
475-
1,
476-
sc_network_statement::config::DEFAULT_STATEMENTS_PER_SECOND,
475+
Default::default(),
477476
|_, _| (),
478477
)?;
479478
Ok(sc_service_test::TestNetComponents::new(

substrate/bin/node/cli/src/cli.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub struct Cli {
4646
/// Number of concurrent workers for statement validation from the network.
4747
///
4848
/// Only relevant when `--enable-statement-store` is used.
49-
#[arg(long, default_value_t = 1)]
49+
#[arg(long, default_value_t = sc_statement_store::DEFAULT_NETWORK_WORKERS)]
5050
pub statement_network_workers: usize,
5151

5252
/// Maximum statements per second per peer before rate limiting kicks in.
@@ -55,9 +55,33 @@ pub struct Cli {
5555
/// while enforcing the average rate over time.
5656
///
5757
/// Only relevant when `--enable-statement-store` is used.
58-
#[arg(long, default_value_t = 50_000)]
58+
#[arg(long, default_value_t = sc_statement_store::DEFAULT_RATE_LIMIT)]
5959
pub statement_rate_limit: u32,
6060

61+
/// Maximum number of statements the statement store can hold.
62+
///
63+
/// Once this limit is reached, lower-priority statements may be evicted.
64+
///
65+
/// Only relevant when `--enable-statement-store` is used.
66+
#[arg(long, default_value_t = sc_statement_store::DEFAULT_MAX_TOTAL_STATEMENTS)]
67+
pub statement_store_max_total_statements: usize,
68+
69+
/// Maximum total data size (in bytes) the statement store can hold.
70+
///
71+
/// Once this limit is reached, lower-priority statements may be evicted.
72+
///
73+
/// Only relevant when `--enable-statement-store` is used.
74+
#[arg(long, default_value_t = sc_statement_store::DEFAULT_MAX_TOTAL_SIZE)]
75+
pub statement_store_max_total_size: usize,
76+
77+
/// Number of seconds for which removed statements won't be allowed to be added back.
78+
///
79+
/// This prevents old statements from being re-propagated on the network.
80+
///
81+
/// Only relevant when `--enable-statement-store` is used.
82+
#[arg(long, default_value_t = sc_statement_store::DEFAULT_PURGE_AFTER_SEC)]
83+
pub statement_store_purge_after_sec: u64,
84+
6185
#[allow(missing_docs)]
6286
#[clap(flatten)]
6387
pub storage_monitor: sc_storage_monitor::StorageMonitorParams,

0 commit comments

Comments
 (0)