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

fix: handle FailedParsingVssValue when wait device lock syncing #78

Merged
merged 4 commits into from
Dec 27, 2024
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
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 2 additions & 0 deletions mutiny-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ pub enum MutinyError {
/// Failed to authenticate using JWT
#[error("Failed to authenticate using JWT.")]
JwtAuthFailure,
#[error("Failed to parse VSS value from getObject response.")]
FailedParsingVssValue,
#[error(transparent)]
Other(anyhow::Error),
}
Expand Down
33 changes: 25 additions & 8 deletions mutiny-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,19 +840,36 @@ impl<S: MutinyStorage> MutinyWalletBuilder<S> {
let device_id = self.storage.get_device_id()?;
let max_retries = 10;
let mut retries = 0;
while !self
.storage
.fetch_device_lock()
.await?
.is_some_and(|lock| lock.is_last_locker(&device_id))
{
while retries <= max_retries {
log_info!(logger, "Waiting device lock syncing... {retries}");

match self.storage.fetch_device_lock().await {
Ok(lock_option) => {
if let Some(lock) = lock_option {
if lock.is_last_locker(&device_id) {
break;
}
}
}
Err(MutinyError::FailedParsingVssValue) => {
log_info!(logger, "Failed to parse VSS value, retrying... {retries}");
}
Err(e) => {
log_error!(logger, "Error fetching device lock: {:?}", e);
return Err(e);
}
}

retries += 1;

if retries > max_retries {
log_error!(logger, "Can't syncing device lock to VSS");
log_error!(
logger,
"Can't sync device lock to VSS after {max_retries} attempts"
);
return Err(MutinyError::AlreadyRunning);
}
sleep(300).await
sleep(300).await;
}
}
log_debug!(logger, "finished checking device lock");
Expand Down
2 changes: 1 addition & 1 deletion mutiny-core/src/vss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl MutinyVssClient {
.await
.map_err(|e| {
log_error!(self.logger, "Error parsing get objects response: {e}");
MutinyError::Other(anyhow!("Error parsing get objects response: {e}"))
MutinyError::FailedParsingVssValue
})?;

result.decrypt(&self.encryption_key)
Expand Down
2 changes: 1 addition & 1 deletion mutiny-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cargo-features = ["per-package-target"]

[package]
name = "mutiny-wasm"
version = "1.10.25"
version = "1.10.26"
edition = "2021"
authors = ["utxostack"]
forced-target = "wasm32-unknown-unknown"
Expand Down
3 changes: 3 additions & 0 deletions mutiny-wasm/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ pub enum MutinyJsError {
InvalidHex,
#[error("JWT Auth Failure")]
JwtAuthFailure,
#[error("Failed to parse VSS value from getObject response.")]
FailedParsingVssValue,
/// Unknown error.
#[error("Unknown Error")]
UnknownError,
Expand Down Expand Up @@ -252,6 +254,7 @@ impl From<MutinyError> for MutinyJsError {
MutinyError::InvalidPsbt => MutinyJsError::InvalidPsbt,
MutinyError::InvalidHex => MutinyJsError::InvalidHex,
MutinyError::JwtAuthFailure => MutinyJsError::JwtAuthFailure,
MutinyError::FailedParsingVssValue => MutinyJsError::FailedParsingVssValue,
}
}
}
Expand Down
Loading