@@ -2457,13 +2457,57 @@ impl Wallet {
2457
2457
self . stage . merge ( indexed_graph_changeset. into ( ) ) ;
2458
2458
}
2459
2459
2460
- /// Apply evictions of the given txids with their associated timestamps.
2460
+ /// Apply evictions of the given transaction IDs with their associated timestamps.
2461
2461
///
2462
- /// This means that any pending unconfirmed tx in this set will no longer be canonical by
2463
- /// default. Note that an evicted tx can become canonical if it is later seen again or
2464
- /// observed on-chain.
2462
+ /// This function is used to mark specific unconfirmed transactions as evicted from the mempool.
2463
+ /// Eviction means that these transactions are no longer considered canonical by default, which
2464
+ /// implies that they are not part of the wallet's [`transactions`] set. This can happen, for
2465
+ /// example, when a transaction is dropped from the mempool due to low fees or conflicts
2466
+ /// with another transaction.
2465
2467
///
2466
- /// This stages the changes which need to be persisted.
2468
+ /// Only transactions that are currently unconfirmed and canonical will be considered for
2469
+ /// eviction. Transactions that are not relevant to the wallet are ignored. Note that an
2470
+ /// evicted transaction can become canonical again if it is later observed on-chain or seen in
2471
+ /// the mempool with a higher priority (e.g., due to a fee bump).
2472
+ ///
2473
+ /// ### Parameters
2474
+ ///
2475
+ /// - `evicted_txs`: An iterator of `(Txid, u64)` tuples, where:
2476
+ /// - `Txid`: The transaction ID of the transaction to be evicted.
2477
+ /// - `u64`: The timestamp indicating when the transaction was evicted from the mempool. This
2478
+ /// will usually correspond to the time of the latest chain sync. See docs for
2479
+ /// [`start_sync_with_revealed_spks`].
2480
+ ///
2481
+ /// ### Example
2482
+ ///
2483
+ /// ```rust,no_run
2484
+ /// # use bitcoin::hashes::Hash;
2485
+ /// use std::time::{SystemTime, UNIX_EPOCH};
2486
+ /// # let mut wallet = bdk_wallet::doctest_wallet!();
2487
+ /// # let txid_to_evict = bitcoin::Txid::all_zeros();
2488
+ ///
2489
+ /// let timestamp = SystemTime::now()
2490
+ /// .duration_since(UNIX_EPOCH)
2491
+ /// .unwrap()
2492
+ /// .as_secs();
2493
+ ///
2494
+ /// wallet.apply_evicted_txs(vec![(txid_to_evict, timestamp)]);
2495
+ /// ```
2496
+ ///
2497
+ /// ### Note
2498
+ ///
2499
+ /// - This function is particularly useful when syncing with a blockchain backend that provides
2500
+ /// mempool eviction notifications.
2501
+ /// - The changes are staged in the wallet's internal state and must be persisted to ensure they
2502
+ /// are retained across wallet restarts. Use [`Wallet::take_staged`] to retrieve the staged
2503
+ /// changes and persist them to your database of choice.
2504
+ /// - Evicted transactions are removed from the wallet's canonical transaction set, but the data
2505
+ /// remains in the wallet's internal transaction graph for historical purposes.
2506
+ /// - Ensure that the timestamps provided are accurate and monotonically increasing, as they
2507
+ /// influence the wallet's canonicalization logic.
2508
+ ///
2509
+ /// [`transactions`]: Wallet::transactions
2510
+ /// [`start_sync_with_revealed_spks`]: Wallet::start_sync_with_revealed_spks
2467
2511
pub fn apply_evicted_txs ( & mut self , evicted_txs : impl IntoIterator < Item = ( Txid , u64 ) > ) {
2468
2512
let chain = & self . chain ;
2469
2513
let canon_txids: Vec < Txid > = self
@@ -2671,7 +2715,7 @@ macro_rules! floating_rate {
2671
2715
/// Macro for getting a wallet for use in a doctest
2672
2716
macro_rules! doctest_wallet {
2673
2717
( ) => { {
2674
- use $crate:: bitcoin:: { BlockHash , Transaction , absolute, TxOut , Network , hashes:: Hash } ;
2718
+ use $crate:: bitcoin:: { transaction , Amount , BlockHash , Transaction , absolute, TxOut , Network , hashes:: Hash } ;
2675
2719
use $crate:: chain:: { ConfirmationBlockTime , BlockId , TxGraph , tx_graph} ;
2676
2720
use $crate:: { Update , KeychainKind , Wallet } ;
2677
2721
use $crate:: test_utils:: * ;
0 commit comments