diff --git a/apps/fortuna/src/config.rs b/apps/fortuna/src/config.rs index 6ceeff35e4..8e1ca07f69 100644 --- a/apps/fortuna/src/config.rs +++ b/apps/fortuna/src/config.rs @@ -184,12 +184,19 @@ pub struct EthereumConfig { /// at each specified delay. For example: [5, 10, 20]. #[serde(default = "default_block_delays")] pub block_delays: Vec, + + #[serde(default = "default_retry_previous_blocks")] + pub retry_previous_blocks: u64, } fn default_block_delays() -> Vec { vec![5] } +fn default_retry_previous_blocks() -> u64 { + 100 +} + fn default_priority_fee_multiplier_pct() -> u64 { 100 } diff --git a/apps/fortuna/src/keeper.rs b/apps/fortuna/src/keeper.rs index a85e37b6c0..a8cc800d3c 100644 --- a/apps/fortuna/src/keeper.rs +++ b/apps/fortuna/src/keeper.rs @@ -105,7 +105,15 @@ pub async fn run_keeper_threads( let (tx, rx) = mpsc::channel::(1000); // Spawn a thread to watch for new blocks and send the range of blocks for which events has not been handled to the `tx` channel. - spawn(watch_blocks_wrapper(chain_state.clone(), latest_safe_block, tx).in_current_span()); + spawn( + watch_blocks_wrapper( + chain_state.clone(), + latest_safe_block, + tx, + chain_eth_config.retry_previous_blocks, + ) + .in_current_span(), + ); // Spawn a thread for block processing with configured delays spawn( diff --git a/apps/fortuna/src/keeper/block.rs b/apps/fortuna/src/keeper/block.rs index 6df6e32cb6..0546d5bdea 100644 --- a/apps/fortuna/src/keeper/block.rs +++ b/apps/fortuna/src/keeper/block.rs @@ -30,8 +30,6 @@ const RETRY_INTERVAL: Duration = Duration::from_secs(5); const BLOCK_BATCH_SIZE: u64 = 100; /// How much to wait before polling the next latest block const POLL_INTERVAL: Duration = Duration::from_secs(2); -/// Retry last N blocks -const RETRY_PREVIOUS_BLOCKS: u64 = 100; #[derive(Debug, Clone)] pub struct BlockRange { @@ -196,6 +194,7 @@ pub async fn watch_blocks_wrapper( chain_state: BlockchainState, latest_safe_block: BlockNumber, tx: mpsc::Sender, + retry_previous_blocks: u64, ) { let mut last_safe_block_processed = latest_safe_block; loop { @@ -203,6 +202,7 @@ pub async fn watch_blocks_wrapper( chain_state.clone(), &mut last_safe_block_processed, tx.clone(), + retry_previous_blocks, ) .in_current_span() .await @@ -221,6 +221,7 @@ pub async fn watch_blocks( chain_state: BlockchainState, last_safe_block_processed: &mut BlockNumber, tx: mpsc::Sender, + retry_previous_blocks: u64, ) -> Result<()> { tracing::info!("Watching blocks to handle new events"); @@ -229,7 +230,7 @@ pub async fn watch_blocks( let latest_safe_block = get_latest_safe_block(&chain_state).in_current_span().await; if latest_safe_block > *last_safe_block_processed { - let mut from = latest_safe_block.saturating_sub(RETRY_PREVIOUS_BLOCKS); + let mut from = latest_safe_block.saturating_sub(retry_previous_blocks); // In normal situation, the difference between latest and last safe block should not be more than 2-3 (for arbitrum it can be 10) // TODO: add a metric for this in separate PR. We need alerts