Skip to content

Commit d950b9e

Browse files
node: Add max contracts option and value validations
Signed-off-by: Maksim Dimitrov <[email protected]>
1 parent d340ca8 commit d950b9e

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

node/src/bin/manager.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,11 @@ pub enum CallCacheCommand {
565565
#[clap(long, conflicts_with_all = &["from", "to"])]
566566
remove_entire_cache: bool,
567567
/// Remove the cache for contracts that have not been accessed in the last <TTL_DAYS> days
568-
#[clap(long, conflicts_with_all = &["from", "to", "remove-entire-cache"])]
568+
#[clap(long, conflicts_with_all = &["from", "to", "remove-entire-cache"], value_parser = clap::value_parser!(i32).range(1..))]
569569
ttl_days: Option<i32>,
570+
/// Limits the number of contracts to consider for cache removal when using --ttl_days
571+
#[clap(long, conflicts_with_all = &["remove-entire-cache", "to", "from"], requires = "ttl_days", value_parser = clap::value_parser!(i64).range(1..))]
572+
ttl_max_contracts: Option<i64>,
570573
/// Starting block number
571574
#[clap(long, short, conflicts_with = "remove-entire-cache", requires = "to")]
572575
from: Option<i32>,
@@ -1477,12 +1480,14 @@ async fn main() -> anyhow::Result<()> {
14771480
to,
14781481
remove_entire_cache,
14791482
ttl_days,
1483+
ttl_max_contracts,
14801484
} => {
14811485
let chain_store = ctx.chain_store(&chain_name)?;
14821486
if let Some(ttl_days) = ttl_days {
14831487
return commands::chain::clear_stale_call_cache(
14841488
chain_store,
14851489
ttl_days,
1490+
ttl_max_contracts,
14861491
)
14871492
.await;
14881493
}

node/src/manager/commands/chain.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,15 @@ pub async fn clear_call_cache(
8484
pub async fn clear_stale_call_cache(
8585
chain_store: Arc<ChainStore>,
8686
ttl_days: i32,
87+
ttl_max_contracts: Option<i64>,
8788
) -> Result<(), Error> {
8889
println!(
8990
"Removing stale entries from the call cache for `{}`",
9091
chain_store.chain
9192
);
92-
chain_store.clear_stale_call_cache(ttl_days).await?;
93+
chain_store
94+
.clear_stale_call_cache(ttl_days, ttl_max_contracts)
95+
.await?;
9396
Ok(())
9497
}
9598

0 commit comments

Comments
 (0)