Skip to content

Commit

Permalink
cleanup: simplify recovery, build a set of unspent outputs first and …
Browse files Browse the repository at this point in the history
…only then retrieve the ecash notes
  • Loading branch information
joschisan committed Oct 23, 2023
1 parent 905d548 commit 21da635
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 1,183 deletions.
2 changes: 1 addition & 1 deletion gateway/ln-gateway/src/state_machine/mod.rs
Expand Up @@ -338,7 +338,7 @@ impl GatewayClientExt for Client {
.create_funding_incoming_contract_output_from_swap(swap_params)
.await?;
let tx = TransactionBuilder::new().with_output(output.into_dyn(instance.id));
let operation_meta_gen = |_: TransactionId, _: Option<OutPoint>| GatewayMeta::Receive;
let operation_meta_gen = |_: TransactionId, _: Vec<OutPoint>| GatewayMeta::Receive;
self.finalize_and_submit_transaction(operation_id, KIND.as_str(), operation_meta_gen, tx)
.await?;
Ok(operation_id)
Expand Down
18 changes: 8 additions & 10 deletions modules/fedimint-mint-client/src/backup.rs
Expand Up @@ -4,11 +4,11 @@ use fedimint_core::api::{DynGlobalApi, GlobalFederationApi};
use fedimint_core::core::ModuleInstanceId;
use fedimint_core::db::ModuleDatabaseTransaction;
use fedimint_core::encoding::{Decodable, Encodable};
use fedimint_core::{OutPoint, Tiered, TieredMulti};
use fedimint_core::{Amount, OutPoint, Tiered, TieredMulti};
use serde::{Deserialize, Serialize};

use super::MintClientModule;
use crate::output::{MintOutputStateMachine, MultiNoteIssuanceRequest};
use crate::output::{MintOutputStateMachine, NoteIssuanceRequest};
use crate::{MintClientStateMachines, NoteIndex, SpendableNote};

pub mod recovery;
Expand All @@ -19,8 +19,8 @@ pub mod recovery;
/// by avoiding scanning the whole history.
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Encodable, Decodable)]
pub struct EcashBackup {
notes: TieredMulti<SpendableNote>,
pending_notes: Vec<(OutPoint, MultiNoteIssuanceRequest)>,
spendable_notes: TieredMulti<SpendableNote>,
pending_notes: Vec<(OutPoint, Amount, NoteIssuanceRequest)>,
epoch_count: u64,
next_note_idx: Tiered<NoteIndex>,
}
Expand All @@ -29,7 +29,7 @@ impl EcashBackup {
/// An empty backup with, like a one created by a newly created client.
pub fn new_empty() -> Self {
Self {
notes: TieredMulti::default(),
spendable_notes: TieredMulti::default(),
pending_notes: vec![],
epoch_count: 0,
next_note_idx: Tiered::default(),
Expand All @@ -50,7 +50,7 @@ impl MintClientModule {

let notes = Self::get_all_spendable_notes(dbtx).await;

let pending_notes: Vec<(OutPoint, MultiNoteIssuanceRequest)> = executor
let pending_notes: Vec<(OutPoint, Amount, NoteIssuanceRequest)> = executor
.get_active_states()
.await
.into_iter()
Expand All @@ -68,9 +68,7 @@ impl MintClientModule {
match state {
MintClientStateMachines::Output(MintOutputStateMachine { common, state }) => {
match state {
crate::output::MintOutputStates::Created(state) => Some((common.out_point, MultiNoteIssuanceRequest{
notes: TieredMulti::from_iter([(state.amount, state.issuance_request)])
})),
crate::output::MintOutputStates::Created(state) => Some((common.out_point, state.amount, state.issuance_request)),
crate::output::MintOutputStates::Succeeded(_) => None /* we back these via get_all_spendable_notes */,
_ => None,
}
Expand All @@ -87,7 +85,7 @@ impl MintClientModule {
let next_note_idx = Tiered::from_iter(idxes);

Ok(EcashBackup {
notes,
spendable_notes: notes,
pending_notes,
next_note_idx,
epoch_count: fedimint_block_count,
Expand Down

0 comments on commit 21da635

Please sign in to comment.