Skip to content

Commit 648766f

Browse files
committed
Merge #270: docs(wallet): expand docs for apply_evicted_txs
05e1f4a docs(wallet): expand docs for `apply_evicted_txs` (valued mammal) Pull request description: ### Description Expand the API docs for `Wallet::apply_evicted_txs`. This can help to fix #254 by having a section explaining the logic of mempool evictions. ### Changelog notice ### Checklists #### All Submissions: * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) #### New Features: * [ ] I've added tests for the new feature * [ ] I've added docs for the new feature #### Bugfixes: * [ ] ~~This pull request breaks the existing API~~ * [ ] I've added tests to reproduce the issue which are now passing * [x] I'm linking the issue being fixed by this PR Top commit has no ACKs. Tree-SHA512: cf2f067ca2a962c891569cd9a9268c25dc693365e1c2325361b02f50547c1e0afd489a9d228717156934f82b605f2cd9e2e6e5f2b12c1445334961f6c5bb6302
2 parents c39ce79 + 05e1f4a commit 648766f

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

wallet/src/wallet/mod.rs

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,13 +2489,44 @@ impl Wallet {
24892489
self.stage.merge(indexed_graph_changeset.into());
24902490
}
24912491

2492-
/// Apply evictions of the given txids with their associated timestamps.
2492+
/// Apply evictions of the given transaction IDs with their associated timestamps.
24932493
///
2494-
/// This means that any pending unconfirmed tx in this set will no longer be canonical by
2495-
/// default. Note that an evicted tx can become canonical if it is later seen again or
2496-
/// observed on-chain.
2494+
/// This function is used to mark specific unconfirmed transactions as evicted from the mempool.
2495+
/// Eviction means that these transactions are not considered canonical by default, and will
2496+
/// no longer be part of the wallet's [`transactions`] set. This can happen for example when
2497+
/// a transaction is dropped from the mempool due to low fees or conflicts with another
2498+
/// transaction.
24972499
///
2498-
/// This stages the changes which need to be persisted.
2500+
/// Only transactions that are currently unconfirmed and canonical are considered for eviction.
2501+
/// Transactions that are not relevant to the wallet are ignored. Note that an evicted
2502+
/// transaction can become canonical again if it is later observed on-chain or seen in the
2503+
/// mempool with a higher priority (e.g., due to a fee bump).
2504+
///
2505+
/// ## Parameters
2506+
///
2507+
/// `evicted_txs`: An iterator of `(Txid, u64)` tuples, where:
2508+
/// - `Txid`: The transaction ID of the transaction to be evicted.
2509+
/// - `u64`: The timestamp indicating when the transaction was evicted from the mempool. This
2510+
/// will usually correspond to the time of the latest chain sync. See docs for
2511+
/// [`start_sync_with_revealed_spks`].
2512+
///
2513+
/// ## Notes
2514+
///
2515+
/// - Not all blockchain backends support automatic mempool eviction handling - this method may
2516+
/// be used in such cases. It can also be used to negate the effect of
2517+
/// [`apply_unconfirmed_txs`] for a particular transaction without the need for an additional
2518+
/// sync.
2519+
/// - The changes are staged in the wallet's internal state and must be persisted to ensure they
2520+
/// are retained across wallet restarts. Use [`Wallet::take_staged`] to retrieve the staged
2521+
/// changes and persist them to your database of choice.
2522+
/// - Evicted transactions are removed from the wallet's canonical transaction set, but the data
2523+
/// remains in the wallet's internal transaction graph for historical purposes.
2524+
/// - Ensure that the timestamps provided are accurate and monotonically increasing, as they
2525+
/// influence the wallet's canonicalization logic.
2526+
///
2527+
/// [`transactions`]: Wallet::transactions
2528+
/// [`apply_unconfirmed_txs`]: Wallet::apply_unconfirmed_txs
2529+
/// [`start_sync_with_revealed_spks`]: Wallet::start_sync_with_revealed_spks
24992530
pub fn apply_evicted_txs(&mut self, evicted_txs: impl IntoIterator<Item = (Txid, u64)>) {
25002531
let chain = &self.chain;
25012532
let canon_txids: Vec<Txid> = self

0 commit comments

Comments
 (0)