fedimint_walletv2_client/migrations.rs
1//! Client database migrations.
2
3use fedimint_core::core::OperationId;
4use fedimint_core::db::{DatabaseTransaction, DbMigrationError, IDatabaseTransactionOpsCoreTyped};
5
6use crate::db::{NextOutputIndexKey, ValidAddressIndexPrefix};
7
8/// Address indices are per-account now, and the scanner has to know which
9/// account each one belongs to.
10///
11/// Rather than re-key what is there, this drops the scan cursor and every
12/// derived index and lets the scanner rebuild both from zero. That is cheaper
13/// to get right than a rewrite and it is safe: the federation reports whether
14/// an output is already spent, so a replay from index zero re-derives the same
15/// addresses and claims nothing twice.
16///
17/// The cost is one full re-walk of the federation's output stream and one
18/// address-frontier search per account, both of which the scanner already does
19/// on a fresh join.
20///
21/// The state machines need nothing: they read their account off their
22/// operation rather than carrying it, so the ones in flight keep their shape.
23pub(crate) async fn migrate_to_accounts_v1(
24 dbtx: &mut DatabaseTransaction<'_>,
25 _active_states: Vec<(Vec<u8>, OperationId)>,
26 _inactive_states: Vec<(Vec<u8>, OperationId)>,
27) -> Result<Option<(Vec<(Vec<u8>, OperationId)>, Vec<(Vec<u8>, OperationId)>)>, DbMigrationError> {
28 dbtx.remove_by_prefix(&ValidAddressIndexPrefix).await;
29
30 dbtx.remove_entry(&NextOutputIndexKey).await;
31
32 Ok(None)
33}