Skip to content

Commit

Permalink
chore: improve tx fetcher error handling (#39)
Browse files Browse the repository at this point in the history
Instead of skipping a tx when encountering an issue, wait until it is successful.
  • Loading branch information
zeapoz authored Nov 6, 2023
1 parent eeeb464 commit d457b88
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions state-reconstruct-fetcher/src/l1_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ use crate::{
const MAX_RETRIES: u8 = 5;
/// The interval in seconds in which to poll for new blocks.
const LONG_POLLING_INTERVAL_S: u64 = 120;
/// The interval in seconds to wait before retrying to fetch a previously failed transaction.
const FAILED_FETCH_RETRY_INTERVAL_S: u64 = 10;
/// The interval in seconds in which to print metrics.
const METRICS_PRINT_INTERVAL_S: u64 = 10;

Expand Down Expand Up @@ -302,13 +304,27 @@ impl L1Fetcher {
tokio::spawn({
async move {
while let Some(hash) = hash_rx.recv().await {
let Ok(Some(tx)) = L1Fetcher::retry_call(
|| provider.get_transaction(hash),
L1FetchError::GetTx,
)
.await
else {
continue;
let tx = loop {
match L1Fetcher::retry_call(
|| provider.get_transaction(hash),
L1FetchError::GetTx,
)
.await
{
Ok(Some(tx)) => {
break tx;
}
_ => {
tracing::error!(
"failed to get transaction for hash: {}, retrying in a bit...",
hash
);
tokio::time::sleep(Duration::from_secs(
FAILED_FETCH_RETRY_INTERVAL_S,
))
.await;
}
};
};

if let Some(current_block) = tx.block_number {
Expand Down

0 comments on commit d457b88

Please sign in to comment.