diff --git a/Cargo.lock b/Cargo.lock index 94880644..33f810e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1765,6 +1765,7 @@ dependencies = [ "serde_with", "sha2", "thiserror 2.0.18", + "tokio-retry", "url", ] diff --git a/common/Cargo.toml b/common/Cargo.toml index f7658304..bf4a0032 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -22,3 +22,4 @@ bytesize.workspace = true base64.workspace = true url.workspace = true logos-blockchain-common-http-client.workspace = true +tokio-retry.workspace = true diff --git a/common/src/sequencer_client.rs b/common/src/sequencer_client.rs index 7e5819ec..f847b865 100644 --- a/common/src/sequencer_client.rs +++ b/common/src/sequencer_client.rs @@ -67,15 +67,24 @@ impl SequencerClient { "Calling method {method} with payload {request:?} to sequencer at {}", self.sequencer_addr ); - let mut call_builder = self.client.post(self.sequencer_addr.clone()); - if let Some(BasicAuth { username, password }) = &self.basic_auth { - call_builder = call_builder.basic_auth(username, password.as_deref()); - } + let strategy = tokio_retry::strategy::FixedInterval::from_millis(10000).take(60); - let call_res = call_builder.json(&request).send().await?; + let response_vall = tokio_retry::Retry::spawn(strategy, || async { + let mut call_builder = self.client.post(self.sequencer_addr.clone()); - let response_vall = call_res.json::().await?; + if let Some(BasicAuth { username, password }) = &self.basic_auth { + call_builder = call_builder.basic_auth(username, password.as_deref()); + } + + let call_res_res = call_builder.json(&request).send().await; + + match call_res_res { + Err(err) => Err(err), + Ok(call_res) => call_res.json::().await, + } + }) + .await?; #[derive(Debug, Clone, Deserialize)] #[allow(dead_code)]