-
Notifications
You must be signed in to change notification settings - Fork 20
feat: add retry strategy to client #512
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
Changes from 1 commit
fc4b48c
5c10d97
71f815e
f408069
3808ba4
b568fd2
cd578ff
b5801a7
9290835
66b537e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| use evm_rpc_types::{MultiRpcResult, ProviderError, RpcError, RpcResult}; | ||
|
|
||
| /// The retry strategy when performing calls to the EVM RPC canister. | ||
| #[derive(Clone, Eq, PartialEq, Debug, Default)] | ||
| pub enum EvmRpcRetryStrategy { | ||
|
||
| /// Do not perform any retries. | ||
| #[default] | ||
| NoRetry, | ||
|
|
||
| /// If a call fails due to insufficient cycles, try again with double the cycles until the | ||
| /// maximum number of allowed retries has been performed. | ||
| DoubleCycles { | ||
| /// The maximum number of retries to perform. | ||
| max_num_retries: u32, | ||
| }, | ||
| } | ||
|
|
||
| pub trait EvmRpcResult { | ||
| fn is_too_few_cycles_error(&self) -> bool; | ||
| } | ||
|
|
||
| impl<T> EvmRpcResult for MultiRpcResult<T> { | ||
| fn is_too_few_cycles_error(&self) -> bool { | ||
| match self { | ||
| MultiRpcResult::Consistent(result) => result.is_too_few_cycles_error(), | ||
| MultiRpcResult::Inconsistent(results) => results | ||
| .iter() | ||
| .any(|(_, result)| result.is_too_few_cycles_error()), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl<T> EvmRpcResult for RpcResult<T> { | ||
| fn is_too_few_cycles_error(&self) -> bool { | ||
| match self { | ||
| Err(err) => matches!( | ||
| err, | ||
| RpcError::ProviderError(ProviderError::TooFewCycles { .. }) | ||
| ), | ||
| _ => false, | ||
| } | ||
| } | ||
| } | ||
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.
The
Clonebounds are needed here to be able to clone the request when retrying.