From 56f4bcd676ddc2c6adbd4116c68ba23b94888a5f Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 21 May 2025 14:28:09 +0000 Subject: [PATCH 1/3] feat(fortuna): extract RETRY_PREVIOUS_BLOCKS into EthereumConfig Co-Authored-By: Jayant Krishnamurthy --- apps/fortuna/src/config.rs | 7 +++++++ apps/fortuna/src/keeper.rs | 2 +- apps/fortuna/src/keeper/block.rs | 6 +++++- 3 files changed, 13 insertions(+), 2 deletions(-) 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..0bda240d56 100644 --- a/apps/fortuna/src/keeper.rs +++ b/apps/fortuna/src/keeper.rs @@ -105,7 +105,7 @@ 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..3f6cb5b8e0 100644 --- a/apps/fortuna/src/keeper/block.rs +++ b/apps/fortuna/src/keeper/block.rs @@ -31,6 +31,7 @@ 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 +#[allow(dead_code)] const RETRY_PREVIOUS_BLOCKS: u64 = 100; #[derive(Debug, Clone)] @@ -196,6 +197,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 +205,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 +224,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 +233,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 From 5a93116e4eb7a902f6c3f42f6f403bdc3d7c2506 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 21 May 2025 14:34:08 +0000 Subject: [PATCH 2/3] style: format keeper.rs Co-Authored-By: Jayant Krishnamurthy --- apps/fortuna/src/keeper.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/fortuna/src/keeper.rs b/apps/fortuna/src/keeper.rs index 0bda240d56..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, chain_eth_config.retry_previous_blocks).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( From 7646dae601471115188c17e0979f8ea1b9329c13 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 21 May 2025 15:19:38 +0000 Subject: [PATCH 3/3] refactor: remove RETRY_PREVIOUS_BLOCKS constant as requested in PR feedback Co-Authored-By: Jayant Krishnamurthy --- apps/fortuna/src/keeper/block.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/apps/fortuna/src/keeper/block.rs b/apps/fortuna/src/keeper/block.rs index 3f6cb5b8e0..0546d5bdea 100644 --- a/apps/fortuna/src/keeper/block.rs +++ b/apps/fortuna/src/keeper/block.rs @@ -30,9 +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 -#[allow(dead_code)] -const RETRY_PREVIOUS_BLOCKS: u64 = 100; #[derive(Debug, Clone)] pub struct BlockRange {