-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat: add retry mechanism #1035
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great UX and overall approach! I have a small consideration regarding the logic itself.
When designing a retry mechanism for anything with a notion of “network call” in some way, I like implementing a delay to allow the network to self-regulate its throughput when congested and often requiring less attempts overall.
I usually go for exponential backoff - delays start off small and ramp up steadily. There are crates like backon
and backoff
with full support of sync/async functions.
Extra considerations:
- what are acceptable minimum/maximum delays for our use case?
Alternatives:
- hand-roll our own delayed retrying (only if adding a dependency is a problem)
- skip having delays altogether (I hereby request your comments on it)
I will use one of the crates you recommended or similar. If that's a problem, I'll implement `exponential backoff'. let mut delay = Duration::from_secs(1);
for _ in 0..retries {
sleep(delay).await;
delay *= 2;
} will be enough. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not all errors benefit from retrying. Usually, you want to wait out a transient error (network or some other kind) and not actually offer a fully-fledged retry mechanism to the user especially when retrying again so fast.
For example, if the tx is out of gas it will be reverted and you'll retry again most probably changing nothing (and more importantly - wasting gas).
You are right, I understand you but will we waste gas if we fail? |
Yep. You lose the gas used to execute the contract up until the point of reverting. The rest will be refunded if you provided an adequate change output. |
1 similar comment
Yep. You lose the gas used to execute the contract up until the point of reverting. The rest will be refunded if you provided an adequate change output. |
Thanks for your consideration @Salka1988! I agree with @segfault-magnet - saving on gas is important, and a proper |
Yea! I forgot about |
# Conflicts: # docs/src/wallets/mnemonic-wallet.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed and gave feedback live with @Salka1988 .
@segfault-magnet creativity and expertise truly elevated the outcome. Thanx! |
# Conflicts: # Cargo.toml # packages/fuels-code-gen/src/program_bindings/abigen/bindings/contract.rs # packages/fuels-code-gen/src/program_bindings/abigen/bindings/script.rs # packages/fuels-core/src/codec/logs.rs # packages/fuels-programs/src/contract.rs # packages/fuels-programs/src/script_calls.rs # packages/fuels/tests/scripts.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work!
Closes #1020.
This code is an implementation of a retry mechanism that allows a function to be retried a certain number of times with a specified interval between attempts.
RetryConfig
: This is a configuration struct that holds the retry configuration. It contains the following fields:retry<Fut, T, ShouldRetry>
: This is the main function responsible for implementing the retry logic.This function takes several parameters:
RetryConfig
struct that specifies the retry behavior.Aditional Work:
I've separated sending a transaction from getting back its value:
Added
RetryableClient
a wrapper around theFuelClient
that provides a convenient way to interact with a remote service. It also enables automatic retry functionality in scenarios where network issues may occur.Checklist