Skip to content

Commit a2e3c86

Browse files
authored
Merge pull request #78 from utxostack/fix-vss-error
fix: handle FailedParsingVssValue when wait device lock syncing
2 parents b0e27b6 + 87c381e commit a2e3c86

File tree

6 files changed

+33
-11
lines changed

6 files changed

+33
-11
lines changed

Diff for: Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: mutiny-core/src/error.rs

+2
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ pub enum MutinyError {
176176
/// Failed to authenticate using JWT
177177
#[error("Failed to authenticate using JWT.")]
178178
JwtAuthFailure,
179+
#[error("Failed to parse VSS value from getObject response.")]
180+
FailedParsingVssValue,
179181
#[error(transparent)]
180182
Other(anyhow::Error),
181183
}

Diff for: mutiny-core/src/lib.rs

+25-8
Original file line numberDiff line numberDiff line change
@@ -840,19 +840,36 @@ impl<S: MutinyStorage> MutinyWalletBuilder<S> {
840840
let device_id = self.storage.get_device_id()?;
841841
let max_retries = 10;
842842
let mut retries = 0;
843-
while !self
844-
.storage
845-
.fetch_device_lock()
846-
.await?
847-
.is_some_and(|lock| lock.is_last_locker(&device_id))
848-
{
843+
while retries <= max_retries {
849844
log_info!(logger, "Waiting device lock syncing... {retries}");
845+
846+
match self.storage.fetch_device_lock().await {
847+
Ok(lock_option) => {
848+
if let Some(lock) = lock_option {
849+
if lock.is_last_locker(&device_id) {
850+
break;
851+
}
852+
}
853+
}
854+
Err(MutinyError::FailedParsingVssValue) => {
855+
log_info!(logger, "Failed to parse VSS value, retrying... {retries}");
856+
}
857+
Err(e) => {
858+
log_error!(logger, "Error fetching device lock: {:?}", e);
859+
return Err(e);
860+
}
861+
}
862+
850863
retries += 1;
864+
851865
if retries > max_retries {
852-
log_error!(logger, "Can't syncing device lock to VSS");
866+
log_error!(
867+
logger,
868+
"Can't sync device lock to VSS after {max_retries} attempts"
869+
);
853870
return Err(MutinyError::AlreadyRunning);
854871
}
855-
sleep(300).await
872+
sleep(300).await;
856873
}
857874
}
858875
log_debug!(logger, "finished checking device lock");

Diff for: mutiny-core/src/vss.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl MutinyVssClient {
168168
.await
169169
.map_err(|e| {
170170
log_error!(self.logger, "Error parsing get objects response: {e}");
171-
MutinyError::Other(anyhow!("Error parsing get objects response: {e}"))
171+
MutinyError::FailedParsingVssValue
172172
})?;
173173

174174
result.decrypt(&self.encryption_key)

Diff for: mutiny-wasm/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cargo-features = ["per-package-target"]
22

33
[package]
44
name = "mutiny-wasm"
5-
version = "1.10.25"
5+
version = "1.10.26"
66
edition = "2021"
77
authors = ["utxostack"]
88
forced-target = "wasm32-unknown-unknown"

Diff for: mutiny-wasm/src/error.rs

+3
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ pub enum MutinyJsError {
186186
InvalidHex,
187187
#[error("JWT Auth Failure")]
188188
JwtAuthFailure,
189+
#[error("Failed to parse VSS value from getObject response.")]
190+
FailedParsingVssValue,
189191
/// Unknown error.
190192
#[error("Unknown Error")]
191193
UnknownError,
@@ -252,6 +254,7 @@ impl From<MutinyError> for MutinyJsError {
252254
MutinyError::InvalidPsbt => MutinyJsError::InvalidPsbt,
253255
MutinyError::InvalidHex => MutinyJsError::InvalidHex,
254256
MutinyError::JwtAuthFailure => MutinyJsError::JwtAuthFailure,
257+
MutinyError::FailedParsingVssValue => MutinyJsError::FailedParsingVssValue,
255258
}
256259
}
257260
}

0 commit comments

Comments
 (0)