Skip to content

Commit 0b1a59f

Browse files
devin-ai-integration[bot]Jayant Krishnamurthy
andauthored
feat(fortuna): extract RETRY_PREVIOUS_BLOCKS into EthereumConfig (#2713)
* feat(fortuna): extract RETRY_PREVIOUS_BLOCKS into EthereumConfig Co-Authored-By: Jayant Krishnamurthy <jayant@dourolabs.xyz> * style: format keeper.rs Co-Authored-By: Jayant Krishnamurthy <jayant@dourolabs.xyz> * refactor: remove RETRY_PREVIOUS_BLOCKS constant as requested in PR feedback Co-Authored-By: Jayant Krishnamurthy <jayant@dourolabs.xyz> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Jayant Krishnamurthy <jayant@dourolabs.xyz>
1 parent 19e8abb commit 0b1a59f

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

apps/fortuna/src/config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ pub struct EthereumConfig {
189189
/// at each specified delay. For example: [5, 10, 20].
190190
#[serde(default = "default_block_delays")]
191191
pub block_delays: Vec<u64>,
192+
193+
#[serde(default = "default_retry_previous_blocks")]
194+
pub retry_previous_blocks: u64,
192195
}
193196

194197
fn default_sync_fee_only_on_register() -> bool {
@@ -199,6 +202,10 @@ fn default_block_delays() -> Vec<u64> {
199202
vec![5]
200203
}
201204

205+
fn default_retry_previous_blocks() -> u64 {
206+
100
207+
}
208+
202209
fn default_priority_fee_multiplier_pct() -> u64 {
203210
100
204211
}

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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ const RETRY_INTERVAL: Duration = Duration::from_secs(5);
3030
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);
33-
/// Retry last N blocks
34-
const RETRY_PREVIOUS_BLOCKS: u64 = 100;
3533

3634
#[derive(Debug, Clone)]
3735
pub struct BlockRange {
@@ -196,13 +194,15 @@ pub async fn watch_blocks_wrapper(
196194
chain_state: BlockchainState,
197195
latest_safe_block: BlockNumber,
198196
tx: mpsc::Sender<BlockRange>,
197+
retry_previous_blocks: u64,
199198
) {
200199
let mut last_safe_block_processed = latest_safe_block;
201200
loop {
202201
if let Err(e) = watch_blocks(
203202
chain_state.clone(),
204203
&mut last_safe_block_processed,
205204
tx.clone(),
205+
retry_previous_blocks,
206206
)
207207
.in_current_span()
208208
.await
@@ -221,6 +221,7 @@ pub async fn watch_blocks(
221221
chain_state: BlockchainState,
222222
last_safe_block_processed: &mut BlockNumber,
223223
tx: mpsc::Sender<BlockRange>,
224+
retry_previous_blocks: u64,
224225
) -> Result<()> {
225226
tracing::info!("Watching blocks to handle new events");
226227

@@ -229,7 +230,7 @@ pub async fn watch_blocks(
229230

230231
let latest_safe_block = get_latest_safe_block(&chain_state).in_current_span().await;
231232
if latest_safe_block > *last_safe_block_processed {
232-
let mut from = latest_safe_block.saturating_sub(RETRY_PREVIOUS_BLOCKS);
233+
let mut from = latest_safe_block.saturating_sub(retry_previous_blocks);
233234

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

0 commit comments

Comments
 (0)