Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit eb59a8b

Browse files
committed
fix: error handling
1 parent 41760d9 commit eb59a8b

File tree

4 files changed

+39
-12
lines changed

4 files changed

+39
-12
lines changed

mutiny-core/src/error.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,10 @@ pub enum MutinyError {
171171
/// Token already spent.
172172
#[error("Token has been already spent.")]
173173
TokenAlreadySpent,
174-
#[error("Fedimint external note reissuance failed.")]
174+
#[error("Fedimint external note re-issuance failed.")]
175175
FedimintReissueFailed,
176+
#[error("Fedimint external note re-issuance resulted in stale outcome state.")]
177+
FedimintReissueStaleState,
176178
#[error(transparent)]
177179
Other(#[from] anyhow::Error),
178180
}

mutiny-core/src/federation.rs

+32-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99
get_payment_info, list_payment_info, persist_payment_info, MutinyStorage, VersionedValue,
1010
},
1111
utils::sleep,
12-
HTLCStatus, MutinyInvoice, DEFAULT_PAYMENT_TIMEOUT, DEFAULT_REISSUE_TIMEOUT,
12+
HTLCStatus, MutinyInvoice, DEFAULT_PAYMENT_TIMEOUT,
1313
};
1414
use async_trait::async_trait;
1515
use bip39::Mnemonic;
@@ -72,6 +72,12 @@ use std::{
7272
sync::atomic::{AtomicU32, Ordering},
7373
};
7474

75+
// The amount of time in milliseconds to wait for
76+
// checking the status of a fedimint OOB re-issuance. This
77+
// is to work around their stream status checking
78+
// when wanting just the current status.
79+
const FEDIMINT_OOB_REISSUE_TIMEOUT_CHECK_MS: u64 = 30;
80+
7581
// The amount of time in milliseconds to wait for
7682
// checking the status of a fedimint payment. This
7783
// is to work around their stream status checking
@@ -616,15 +622,31 @@ impl<S: MutinyStorage> FederationClient<S> {
616622
// Reissue `OOBNotes`
617623
let operation_id = mint_module.reissue_external_notes(oob_notes, ()).await?;
618624

619-
// TODO: (@leonardo) re-think about the results and errors that we need/want
620-
match process_reissue_outcome(&mint_module, operation_id, self.logger.clone()).await? {
621-
ReissueExternalNotesState::Created | ReissueExternalNotesState::Failed(_) => {
622-
log_trace!(self.logger, "re-issuance of OOBNotes failed!");
625+
match process_reissue_outcome(
626+
&mint_module,
627+
operation_id,
628+
FEDIMINT_OOB_REISSUE_TIMEOUT_CHECK_MS,
629+
self.logger.clone(),
630+
)
631+
.await?
632+
{
633+
ReissueExternalNotesState::Done => {
634+
log_trace!(self.logger, "re-issuance of OOBNotes was successful!");
635+
Ok(())
636+
}
637+
ReissueExternalNotesState::Failed(reason) => {
638+
log_trace!(
639+
self.logger,
640+
"re-issuance of OOBNotes failed explicitly, reason: {reason}"
641+
);
623642
Err(MutinyError::FedimintReissueFailed)
624643
}
625644
_ => {
626-
log_trace!(self.logger, "re-issuance of OOBNotes was successful!");
627-
Ok(())
645+
log_trace!(
646+
self.logger,
647+
"re-issuance of OOBNotes explicitly failed, due to outcome with a stale state!"
648+
);
649+
Err(MutinyError::FedimintReissueStaleState)
628650
}
629651
}
630652
}
@@ -889,21 +911,22 @@ where
889911
async fn process_reissue_outcome(
890912
mint_module: &MintClientModule,
891913
operation_id: OperationId,
914+
timeout: u64,
892915
logger: Arc<MutinyLogger>,
893916
) -> Result<ReissueExternalNotesState, MutinyError> {
894-
// Subscribe/Process the outcome based on `ReissueExternalNotesState`
917+
// Subscribe to the outcome based on `ReissueExternalNotesState`
895918
let stream_or_outcome = mint_module
896919
.subscribe_reissue_external_notes(operation_id)
897920
.await
898921
.map_err(MutinyError::Other)?;
899922

923+
// Process the outcome based on `ReissueExternalNotesState`
900924
match stream_or_outcome {
901925
UpdateStreamOrOutcome::Outcome(outcome) => {
902926
log_trace!(logger, "outcome received {:?}", outcome);
903927
Ok(outcome)
904928
}
905929
UpdateStreamOrOutcome::UpdateStream(mut stream) => {
906-
let timeout = DEFAULT_REISSUE_TIMEOUT;
907930
let timeout_fut = sleep(timeout as i32);
908931
pin_mut!(timeout_fut);
909932

mutiny-core/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ use crate::utils::parse_profile_metadata;
119119
use mockall::{automock, predicate::*};
120120

121121
const DEFAULT_PAYMENT_TIMEOUT: u64 = 30;
122-
const DEFAULT_REISSUE_TIMEOUT: u64 = 50;
123122
const MAX_FEDERATION_INVOICE_AMT: u64 = 200_000;
124123
const SWAP_LABEL: &str = "SWAP";
125124
const MELT_CASHU_TOKEN: &str = "Cashu Token Melt";

mutiny-wasm/src/error.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,10 @@ pub enum MutinyJsError {
168168
/// Token already spent.
169169
#[error("Token has been already spent.")]
170170
TokenAlreadySpent,
171-
#[error("Fedimint external note reissuance failed.")]
171+
#[error("Fedimint external note re-issuance failed.")]
172172
FedimintReissueFailed,
173+
#[error("Fedimint external note re-issuance resulted in stale outcome state.")]
174+
FedimintReissueStaleState,
173175
/// Unknown error.
174176
#[error("Unknown Error")]
175177
UnknownError,
@@ -241,6 +243,7 @@ impl From<MutinyError> for MutinyJsError {
241243
MutinyError::PayjoinCreateRequest => MutinyJsError::PayjoinCreateRequest,
242244
MutinyError::PayjoinResponse(e) => MutinyJsError::PayjoinResponse(e.to_string()),
243245
MutinyError::FedimintReissueFailed => MutinyJsError::FedimintReissueFailed,
246+
MutinyError::FedimintReissueStaleState => MutinyJsError::FedimintReissueStaleState,
244247
}
245248
}
246249
}

0 commit comments

Comments
 (0)