reorg cache fix (#3495)

* reorg cache period configurable

* fix comment

* u32 type

Co-authored-by: deevope <you@example.com>
This commit is contained in:
deevope 2020-11-25 17:59:37 +00:00 committed by GitHub
parent 3efe382e9c
commit fd5dfaaec4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 1 deletions

View file

@ -327,6 +327,15 @@ fn comments() -> HashMap<String, String> {
.to_string(), .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( retval.insert(
"max_pool_size".to_string(), "max_pool_size".to_string(),
" "

View file

@ -107,6 +107,11 @@ pub struct PoolConfig {
#[serde(default = "default_accept_fee_base")] #[serde(default = "default_accept_fee_base")]
pub accept_fee_base: u64, 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 /// Maximum capacity of the pool in number of transactions
#[serde(default = "default_max_pool_size")] #[serde(default = "default_max_pool_size")]
pub max_pool_size: usize, pub max_pool_size: usize,
@ -126,6 +131,7 @@ impl Default for PoolConfig {
fn default() -> PoolConfig { fn default() -> PoolConfig {
PoolConfig { PoolConfig {
accept_fee_base: default_accept_fee_base(), accept_fee_base: default_accept_fee_base(),
reorg_cache_period: default_reorg_cache_period(),
max_pool_size: default_max_pool_size(), max_pool_size: default_max_pool_size(),
max_stempool_size: default_max_stempool_size(), max_stempool_size: default_max_stempool_size(),
mineable_max_weight: default_mineable_max_weight(), mineable_max_weight: default_mineable_max_weight(),
@ -136,6 +142,9 @@ impl Default for PoolConfig {
fn default_accept_fee_base() -> u64 { fn default_accept_fee_base() -> u64 {
consensus::MILLI_GRIN consensus::MILLI_GRIN
} }
fn default_reorg_cache_period() -> u32 {
30
}
fn default_max_pool_size() -> usize { fn default_max_pool_size() -> usize {
50_000 50_000
} }

View file

@ -167,6 +167,7 @@ where
TransactionPool::new( TransactionPool::new(
PoolConfig { PoolConfig {
accept_fee_base: 0, accept_fee_base: 0,
reorg_cache_period: 30,
max_pool_size: 50, max_pool_size: 50,
max_stempool_size: 50, max_stempool_size: 50,
mineable_max_weight: 10_000, mineable_max_weight: 10_000,

View file

@ -767,7 +767,7 @@ where
let _ = tx_pool.reconcile_block(b); let _ = tx_pool.reconcile_block(b);
// First "age out" any old txs in the reorg_cache. // 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); tx_pool.truncate_reorg_cache(cutoff);
} }