Skip to content

Commit be8846c

Browse files
devin-ai-integration[bot]Jayant Krishnamurthy
andcommitted
feat(fortuna): extract RETRY_PREVIOUS_BLOCKS into EthereumConfig
Co-Authored-By: Jayant Krishnamurthy <[email protected]>
1 parent 3292f62 commit be8846c

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

apps/fortuna/src/config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,19 @@ pub struct EthereumConfig {
184184
/// at each specified delay. For example: [5, 10, 20].
185185
#[serde(default = "default_block_delays")]
186186
pub block_delays: Vec<u64>,
187+
188+
#[serde(default = "default_retry_previous_blocks")]
189+
pub retry_previous_blocks: u64,
187190
}
188191

189192
fn default_block_delays() -> Vec<u64> {
190193
vec![5]
191194
}
192195

196+
fn default_retry_previous_blocks() -> u64 {
197+
100
198+
}
199+
193200
fn default_priority_fee_multiplier_pct() -> u64 {
194201
100
195202
}

apps/fortuna/src/keeper.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,15 @@ pub async fn run_keeper_threads(
105105

106106
let (tx, rx) = mpsc::channel::<BlockRange>(1000);
107107
// 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.
108-
spawn(watch_blocks_wrapper(chain_state.clone(), latest_safe_block, tx).in_current_span());
108+
spawn(
109+
watch_blocks_wrapper(
110+
chain_state.clone(),
111+
latest_safe_block,
112+
tx,
113+
chain_eth_config.retry_previous_blocks,
114+
)
115+
.in_current_span(),
116+
);
109117

110118
// Spawn a thread for block processing with configured delays
111119
spawn(

apps/fortuna/src/keeper/block.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const BLOCK_BATCH_SIZE: u64 = 100;
3131
/// How much to wait before polling the next latest block
3232
const POLL_INTERVAL: Duration = Duration::from_secs(2);
3333
/// Retry last N blocks
34+
#[allow(dead_code)]
3435
const RETRY_PREVIOUS_BLOCKS: u64 = 100;
3536

3637
#[derive(Debug, Clone)]
@@ -196,13 +197,15 @@ pub async fn watch_blocks_wrapper(
196197
chain_state: BlockchainState,
197198
latest_safe_block: BlockNumber,
198199
tx: mpsc::Sender<BlockRange>,
200+
retry_previous_blocks: u64,
199201
) {
200202
let mut last_safe_block_processed = latest_safe_block;
201203
loop {
202204
if let Err(e) = watch_blocks(
203205
chain_state.clone(),
204206
&mut last_safe_block_processed,
205207
tx.clone(),
208+
retry_previous_blocks,
206209
)
207210
.in_current_span()
208211
.await
@@ -221,6 +224,7 @@ pub async fn watch_blocks(
221224
chain_state: BlockchainState,
222225
last_safe_block_processed: &mut BlockNumber,
223226
tx: mpsc::Sender<BlockRange>,
227+
retry_previous_blocks: u64,
224228
) -> Result<()> {
225229
tracing::info!("Watching blocks to handle new events");
226230

@@ -229,7 +233,7 @@ pub async fn watch_blocks(
229233

230234
let latest_safe_block = get_latest_safe_block(&chain_state).in_current_span().await;
231235
if latest_safe_block > *last_safe_block_processed {
232-
let mut from = latest_safe_block.saturating_sub(RETRY_PREVIOUS_BLOCKS);
236+
let mut from = latest_safe_block.saturating_sub(retry_previous_blocks);
233237

234238
// In normal situation, the difference between latest and last safe block should not be more than 2-3 (for arbitrum it can be 10)
235239
// TODO: add a metric for this in separate PR. We need alerts

0 commit comments

Comments
 (0)