Skip to content

Commit ffb4633

Browse files
musitdevnicholasflintwillow
authored andcommitted
fix: Add retry on DA connection (#1054)
1 parent 07da9d4 commit ffb4633

File tree

6 files changed

+38
-14
lines changed

6 files changed

+38
-14
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protocol-units/da/movement/protocol/client/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ tower = { workspace = true }
2020
http-body-util = { workspace = true }
2121
bytes = { workspace = true }
2222
anyhow = { workspace = true }
23+
tracing = { workspace = true }
2324

2425

2526
[lints]

protocol-units/da/movement/protocol/client/src/lib.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,34 @@ pub enum MovementDaLightNodeClient {
1515
impl MovementDaLightNodeClient {
1616
/// Creates an http1 connection to the light node service.
1717
pub fn try_http1(connection_string: &str) -> Result<Self, anyhow::Error> {
18-
Ok(Self::Http1(http1::Http1::try_new(connection_string)?))
18+
for _ in 0..5 {
19+
match http1::Http1::try_new(connection_string) {
20+
Ok(result) => return Ok(Self::Http1(result)),
21+
Err(err) => {
22+
tracing::warn!("DA Http1 connection failed: {}. Retrying in 5s...", err);
23+
std::thread::sleep(std::time::Duration::from_secs(5));
24+
}
25+
}
26+
}
27+
return Err(
28+
anyhow::anyhow!("Error DA Http1 connection failed more than 5 time aborting.",),
29+
);
1930
}
2031

2132
/// Creates an http2 connection to the light node service.
2233
pub async fn try_http2(connection_string: &str) -> Result<Self, anyhow::Error> {
23-
Ok(Self::Http2(http2::Http2::connect(connection_string).await?))
34+
for _ in 0..5 {
35+
match http2::Http2::connect(connection_string).await {
36+
Ok(result) => return Ok(Self::Http2(result)),
37+
Err(err) => {
38+
tracing::warn!("DA Http2 connection failed: {}. Retrying in 5s...", err);
39+
std::thread::sleep(std::time::Duration::from_secs(5));
40+
}
41+
}
42+
}
43+
return Err(
44+
anyhow::anyhow!("Error DA Http2 connection failed more than 5 time aborting.",),
45+
);
2446
}
2547

2648
/// Stream reads from a given height.

util/godfig/src/backend/config_file/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl ConfigFile {
4444
}
4545

4646
let json: serde_json::Value = serde_json::from_str(&contents)
47-
.map_err(|e| GodfigBackendError::TypeContractMismatch(e.to_string()))?;
47+
.map_err(|e| GodfigBackendError::ConfigDeserializationError(e.to_string()))?;
4848

4949
let keys = key.into();
5050
let mut current = &json;

util/godfig/src/backend/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use thiserror::Error;
77

88
#[derive(Debug, Error)]
99
pub enum GodfigBackendError {
10-
#[error("Type Contract Mismatch")]
11-
TypeContractMismatch(String),
10+
#[error("An error occurs during config deserialization: {0}")]
11+
ConfigDeserializationError(String),
1212
#[error("Backend Error: {0}")]
1313
BackendError(#[from] anyhow::Error),
1414
#[error("IO Error: {0}")]

util/signing/interface/src/key/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,18 +220,18 @@ impl TryFromCanonicalString for Key {
220220
/// Example canonical string: "movement/prod/full_node/mcr_settlement/signer/validator/0"
221221
fn try_from_canonical_string(s: &str) -> Result<Self, String> {
222222
let parts: Vec<&str> = s.split('/').collect();
223-
if parts.len() != 7 {
224-
return Err(format!("invalid key: {}", s));
223+
if parts.len() != 8 {
224+
return Err(format!("invalid key, bad number of elements {:?}: '{}'", parts, s));
225225
}
226226

227227
Ok(Self {
228-
org: Organization::try_from_canonical_string(parts[0])?,
229-
environment: Environment::try_from_canonical_string(parts[1])?,
230-
software_unit: SoftwareUnit::try_from_canonical_string(parts[2])?,
231-
usage: Usage::try_from_canonical_string(parts[3])?,
232-
allowed_roles: AllowedRoles::try_from_canonical_string(parts[4])?,
233-
key_name: parts[5].to_string(),
234-
app_replica: Some(parts[6].to_string()),
228+
org: Organization::try_from_canonical_string(parts[1])?,
229+
environment: Environment::try_from_canonical_string(parts[2])?,
230+
software_unit: SoftwareUnit::try_from_canonical_string(parts[3])?,
231+
usage: Usage::try_from_canonical_string(parts[4])?,
232+
allowed_roles: AllowedRoles::try_from_canonical_string(parts[5])?,
233+
key_name: parts[6].to_string(),
234+
app_replica: Some(parts[7].to_string()),
235235
})
236236
}
237237
}

0 commit comments

Comments
 (0)