mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 10:27:59 +00:00
Limit transaction pool size (#1676)
* Avoid excessive hashing. Store extrinsic len. * Implement pool limits. * Fix issues. * Make sure we return error in case it doesn't make into the pool. * Pass parameters from CLI. * Remove redundant todo. * Fix tests.
This commit is contained in:
@@ -48,7 +48,7 @@ use structopt::{StructOpt, clap::AppSettings};
|
||||
pub use structopt::clap::App;
|
||||
use params::{
|
||||
RunCmd, PurgeChainCmd, RevertCmd, ImportBlocksCmd, ExportBlocksCmd, BuildSpecCmd,
|
||||
NetworkConfigurationParams, SharedParams, MergeParameters
|
||||
NetworkConfigurationParams, SharedParams, MergeParameters, TransactionPoolParams,
|
||||
};
|
||||
pub use params::{NoCustom, CoreParams};
|
||||
pub use traits::{GetLogFilter, AugmentClap};
|
||||
@@ -103,7 +103,7 @@ fn generate_node_name() -> String {
|
||||
break node_name
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
@@ -237,6 +237,23 @@ fn parse_node_key(key: Option<String>) -> error::Result<Option<Secret>> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Fill the given `PoolConfiguration` by looking at the cli parameters.
|
||||
fn fill_transaction_pool_configuration<F: ServiceFactory>(
|
||||
options: &mut FactoryFullConfiguration<F>,
|
||||
params: TransactionPoolParams,
|
||||
) -> error::Result<()> {
|
||||
// ready queue
|
||||
options.transaction_pool.ready.count = params.pool_limit;
|
||||
options.transaction_pool.ready.total_bytes = params.pool_kbytes * 1024;
|
||||
|
||||
// future queue
|
||||
let factor = 10;
|
||||
options.transaction_pool.future.count = params.pool_limit / factor;
|
||||
options.transaction_pool.future.total_bytes = params.pool_kbytes * 1024 / factor;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Fill the given `NetworkConfiguration` by looking at the cli parameters.
|
||||
fn fill_network_configuration(
|
||||
cli: NetworkConfigurationParams,
|
||||
@@ -356,6 +373,11 @@ where
|
||||
client_id,
|
||||
)?;
|
||||
|
||||
fill_transaction_pool_configuration::<F>(
|
||||
&mut config,
|
||||
cli.pool_config,
|
||||
)?;
|
||||
|
||||
if let Some(key) = cli.key {
|
||||
config.keys.push(key);
|
||||
}
|
||||
|
||||
@@ -109,6 +109,17 @@ pub struct NetworkConfigurationParams {
|
||||
pub in_peers: u32,
|
||||
}
|
||||
|
||||
/// Parameters used to create the pool configuration.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
pub struct TransactionPoolParams {
|
||||
/// Maximum number of transactions in the transaction pool.
|
||||
#[structopt(long = "pool-limit", value_name = "COUNT", default_value = "512")]
|
||||
pub pool_limit: usize,
|
||||
/// Maximum number of kilobytes of all transactions stored in the pool.
|
||||
#[structopt(long = "pool-kbytes", value_name = "COUNT", default_value="10240")]
|
||||
pub pool_kbytes: usize,
|
||||
}
|
||||
|
||||
/// The `run` command used to run a node.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
pub struct RunCmd {
|
||||
@@ -183,6 +194,10 @@ pub struct RunCmd {
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
pub network_config: NetworkConfigurationParams,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
pub pool_config: TransactionPoolParams,
|
||||
}
|
||||
|
||||
impl_augment_clap!(RunCmd);
|
||||
|
||||
Reference in New Issue
Block a user