Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monitor EVM transactions #2206

Open
sveitser opened this issue Oct 23, 2024 · 0 comments
Open

Monitor EVM transactions #2206

sveitser opened this issue Oct 23, 2024 · 0 comments

Comments

@sveitser
Copy link
Collaborator

We currently do have some retry logic but I think it's not enough in case we send a mispriced transaction. Unfortunately doing robust EVM transaction monitoring and re-submission is not exactly straightforward and I have so far not found an existing solution that seems viable.

async fn wait_for_transaction_to_be_mined<P: JsonRpcClient>(
provider: &Provider<P>,
hash: H256,
) -> bool {
let retries = 10;
// It's common to have to try a few times before the transactions is mined. It is too noisy if
// we log every retry. However, if it is not mined after several retries, something might be
// wrong, and it would be useful to start logging.
let log_retries = 5;
let interval = provider.get_interval();
for i in 0..retries {
match provider.get_transaction(hash).await {
Err(err) => {
if i >= log_retries {
tracing::warn!("contract call {hash:?} (retry {i}/{retries}): error getting transaction status: {err}");
}
}
Ok(None) => {
if i >= log_retries {
tracing::warn!(
"contract call {hash:?} (retry {i}/{retries}): missing from mempool"
);
}
}
Ok(Some(tx)) if tx.block_number.is_none() => {
if i >= log_retries {
tracing::warn!("contract call {hash:?} (retry {i}/{retries}): pending");
}
}
Ok(Some(_)) => return true,
}
sleep(interval).await;
}
tracing::error!("contract call {hash:?}: not mined after {retries} retries");
false
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant