Skip to content
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

[Node] Add retry on DA connection #1054

Merged
merged 3 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions protocol-units/da/movement/protocol/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ tower = { workspace = true }
http-body-util = { workspace = true }
bytes = { workspace = true }
anyhow = { workspace = true }
tracing = { workspace = true }


[lints]
Expand Down
26 changes: 24 additions & 2 deletions protocol-units/da/movement/protocol/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,34 @@ pub enum MovementDaLightNodeClient {
impl MovementDaLightNodeClient {
/// Creates an http1 connection to the light node service.
pub fn try_http1(connection_string: &str) -> Result<Self, anyhow::Error> {
Ok(Self::Http1(http1::Http1::try_new(connection_string)?))
for _ in 0..5 {
match http1::Http1::try_new(connection_string) {
Ok(result) => return Ok(Self::Http1(result)),
Err(err) => {
tracing::warn!("DA Http1 connection failed: {}. Retrying in 5s...", err);
std::thread::sleep(std::time::Duration::from_secs(5));
}
}
}
return Err(
anyhow::anyhow!("Error DA Http1 connection failed more than 5 time aborting.",),
);
}

/// Creates an http2 connection to the light node service.
pub async fn try_http2(connection_string: &str) -> Result<Self, anyhow::Error> {
Ok(Self::Http2(http2::Http2::connect(connection_string).await?))
for _ in 0..5 {
match http2::Http2::connect(connection_string).await {
Ok(result) => return Ok(Self::Http2(result)),
Err(err) => {
tracing::warn!("DA Http2 connection failed: {}. Retrying in 5s...", err);
std::thread::sleep(std::time::Duration::from_secs(5));
}
}
}
return Err(
anyhow::anyhow!("Error DA Http2 connection failed more than 5 time aborting.",),
);
}

/// Stream reads from a given height.
Expand Down
2 changes: 1 addition & 1 deletion util/godfig/src/backend/config_file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl ConfigFile {
}

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

let keys = key.into();
let mut current = &json;
Expand Down
4 changes: 2 additions & 2 deletions util/godfig/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use thiserror::Error;

#[derive(Debug, Error)]
pub enum GodfigBackendError {
#[error("Type Contract Mismatch")]
TypeContractMismatch(String),
#[error("An error occurs during config deserialization: {0}")]
ConfigDeserializationError(String),
#[error("Backend Error: {0}")]
BackendError(#[from] anyhow::Error),
#[error("IO Error: {0}")]
Expand Down
18 changes: 9 additions & 9 deletions util/signing/interface/src/key/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,18 +220,18 @@ impl TryFromCanonicalString for Key {
/// Example canonical string: "movement/prod/full_node/mcr_settlement/signer/validator/0"
fn try_from_canonical_string(s: &str) -> Result<Self, String> {
let parts: Vec<&str> = s.split('/').collect();
if parts.len() != 7 {
return Err(format!("invalid key: {}", s));
if parts.len() != 8 {
return Err(format!("invalid key, bad number of elements {:?}: '{}'", parts, s));
}

Ok(Self {
org: Organization::try_from_canonical_string(parts[0])?,
environment: Environment::try_from_canonical_string(parts[1])?,
software_unit: SoftwareUnit::try_from_canonical_string(parts[2])?,
usage: Usage::try_from_canonical_string(parts[3])?,
allowed_roles: AllowedRoles::try_from_canonical_string(parts[4])?,
key_name: parts[5].to_string(),
app_replica: Some(parts[6].to_string()),
org: Organization::try_from_canonical_string(parts[1])?,
environment: Environment::try_from_canonical_string(parts[2])?,
software_unit: SoftwareUnit::try_from_canonical_string(parts[3])?,
usage: Usage::try_from_canonical_string(parts[4])?,
allowed_roles: AllowedRoles::try_from_canonical_string(parts[5])?,
key_name: parts[6].to_string(),
app_replica: Some(parts[7].to_string()),
})
}
}
Expand Down
Loading