Skip to content

Commit

Permalink
Merge pull request #78 from utxostack/fix-vss-error
Browse files Browse the repository at this point in the history
fix: handle FailedParsingVssValue when wait device lock syncing
  • Loading branch information
duanyytop authored Dec 27, 2024
2 parents b0e27b6 + 87c381e commit a2e3c86
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 11 deletions.
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

0 comments on commit a2e3c86

Please sign in to comment.