Skip to content

Commit

Permalink
reorg cache fix (#3495)
Browse files Browse the repository at this point in the history
* reorg cache period configurable

* fix comment

* u32 type

Co-authored-by: deevope <you@example.com>
  • Loading branch information
deevope and deevope committed Nov 25, 2020
1 parent 3efe382 commit fd5dfaa
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
9 changes: 9 additions & 0 deletions config/src/comments.rs
Expand Up @@ -327,6 +327,15 @@ fn comments() -> HashMap<String, 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(
"max_pool_size".to_string(),
"
Expand Down
9 changes: 9 additions & 0 deletions pool/src/types.rs
Expand Up @@ -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,
Expand All @@ -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(),
Expand All @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions pool/tests/common.rs
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion servers/src/common/adapters.rs
Expand Up @@ -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);
}

Expand Down

0 comments on commit fd5dfaa

Please sign in to comment.