Skip to content

Commit

Permalink
refactor(blockifier_reexecution): add more expected string error
Browse files Browse the repository at this point in the history
  • Loading branch information
AvivYossef-starkware committed Nov 10, 2024
1 parent 377045e commit 17fbecd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ use crate::state_reader::utils::{

pub const DEFAULT_RETRY_COUNT: usize = 3;
pub const DEFAULT_RETRY_WAIT_TIME: u64 = 1000;
pub const DEFAULT_EXPECTED_ERROR_STRING: &str = "Connection error";
pub const DEFAULT_EXPECTED_ERROR_STRINGS: [&str; 3] =
["Connection error", "RPCError", "429 Too Many Requests"];
pub const DEFAULT_RETRY_FAILURE_MESSAGE: &str = "Failed to connect to the RPC node.";

pub type ReexecutionResult<T> = Result<T, ReexecutionError>;
Expand Down Expand Up @@ -143,7 +144,7 @@ impl From<SerializableOfflineReexecutionData> for OfflineReexecutionData {
pub struct RetryConfig {
pub(crate) n_retries: usize,
pub(crate) retry_interval_milliseconds: u64,
pub(crate) expected_error_string: &'static str,
pub(crate) expected_error_strings: Vec<&'static str>,
pub(crate) retry_failure_message: &'static str,
}

Expand All @@ -152,7 +153,7 @@ impl Default for RetryConfig {
Self {
n_retries: DEFAULT_RETRY_COUNT,
retry_interval_milliseconds: DEFAULT_RETRY_WAIT_TIME,
expected_error_string: DEFAULT_EXPECTED_ERROR_STRING,
expected_error_strings: DEFAULT_EXPECTED_ERROR_STRINGS.to_vec(),
retry_failure_message: DEFAULT_RETRY_FAILURE_MESSAGE,
}
}
Expand Down
10 changes: 8 additions & 2 deletions crates/blockifier_reexecution/src/state_reader/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ macro_rules! retry_request {
match $closure() {
Ok(value) => retry::OperationResult::Ok(value),
// If the error contains the expected_error_string , we want to retry.
Err(e) if e.to_string().contains($retry_config.expected_error_string) => {
Err(e)
if $retry_config
.expected_error_strings
.iter()
.any(|s| e.to_string().contains(s)) =>
{
retry::OperationResult::Retry(e)
}
// For all other errors, do not retry and return immediately.
Expand All @@ -130,7 +135,8 @@ macro_rules! retry_request {
},
)
.map_err(|e| {
if e.error.to_string().contains($retry_config.expected_error_string) {
if $retry_config.expected_error_strings.iter().any(|s| e.error.to_string().contains(s))
{
panic!("{}: {:?}", $retry_config.retry_failure_message, e.error);
}
e.error
Expand Down

0 comments on commit 17fbecd

Please sign in to comment.