From fd5dfaaec47019f7a66bcbdac5a7a379a73237a8 Mon Sep 17 00:00:00 2001 From: deevope <69693985+deevope@users.noreply.github.com> Date: Wed, 25 Nov 2020 17:59:37 +0000 Subject: [PATCH] reorg cache fix (#3495) * reorg cache period configurable * fix comment * u32 type Co-authored-by: deevope --- config/src/comments.rs | 9 +++++++++ pool/src/types.rs | 9 +++++++++ pool/tests/common.rs | 1 + servers/src/common/adapters.rs | 2 +- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/config/src/comments.rs b/config/src/comments.rs index 8744425a4..ac71c0cd0 100644 --- a/config/src/comments.rs +++ b/config/src/comments.rs @@ -327,6 +327,15 @@ fn comments() -> HashMap { .to_string(), ); + retval.insert( + "reorg_cache_period".to_string(), + " +#reorg cache retention period in minute. +#the reorg cache repopulates local mempool in a reorg scenario. +" + .to_string(), + ); + retval.insert( "max_pool_size".to_string(), " diff --git a/pool/src/types.rs b/pool/src/types.rs index 9f6eea428..f32bdf4a4 100644 --- a/pool/src/types.rs +++ b/pool/src/types.rs @@ -107,6 +107,11 @@ pub struct PoolConfig { #[serde(default = "default_accept_fee_base")] pub accept_fee_base: u64, + // Reorg cache retention period in minute. + // The reorg cache repopulates local mempool in a reorg scenario. + #[serde(default = "default_reorg_cache_period")] + pub reorg_cache_period: u32, + /// Maximum capacity of the pool in number of transactions #[serde(default = "default_max_pool_size")] pub max_pool_size: usize, @@ -126,6 +131,7 @@ impl Default for PoolConfig { fn default() -> PoolConfig { PoolConfig { accept_fee_base: default_accept_fee_base(), + reorg_cache_period: default_reorg_cache_period(), max_pool_size: default_max_pool_size(), max_stempool_size: default_max_stempool_size(), mineable_max_weight: default_mineable_max_weight(), @@ -136,6 +142,9 @@ impl Default for PoolConfig { fn default_accept_fee_base() -> u64 { consensus::MILLI_GRIN } +fn default_reorg_cache_period() -> u32 { + 30 +} fn default_max_pool_size() -> usize { 50_000 } diff --git a/pool/tests/common.rs b/pool/tests/common.rs index 52ef16a89..a6c7c85a7 100644 --- a/pool/tests/common.rs +++ b/pool/tests/common.rs @@ -167,6 +167,7 @@ where TransactionPool::new( PoolConfig { accept_fee_base: 0, + reorg_cache_period: 30, max_pool_size: 50, max_stempool_size: 50, mineable_max_weight: 10_000, diff --git a/servers/src/common/adapters.rs b/servers/src/common/adapters.rs index e9b51ed68..662c282c0 100644 --- a/servers/src/common/adapters.rs +++ b/servers/src/common/adapters.rs @@ -767,7 +767,7 @@ where let _ = tx_pool.reconcile_block(b); // First "age out" any old txs in the reorg_cache. - let cutoff = Utc::now() - Duration::minutes(30); + let cutoff = Utc::now() - Duration::minutes(tx_pool.config.reorg_cache_period as i64); tx_pool.truncate_reorg_cache(cutoff); }