Skip to content

Conversation

@ValuedMammal
Copy link
Collaborator

@ValuedMammal ValuedMammal commented Jun 23, 2025

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:

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
  • I'm linking the issue being fixed by this PR

@coveralls
Copy link

coveralls commented Jun 23, 2025

Pull Request Test Coverage Report for Build 16681094633

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 84.888%

Totals Coverage Status
Change from base Build 16660250657: 0.0%
Covered Lines: 6651
Relevant Lines: 7835

💛 - Coveralls

@ValuedMammal ValuedMammal moved this to In Progress in BDK Wallet Jul 3, 2025
@ValuedMammal ValuedMammal added this to the Wallet 2.1.0 milestone Jul 3, 2025
@ValuedMammal ValuedMammal force-pushed the doc/apply-evicted-txs branch from 0121e0f to 9284767 Compare July 7, 2025 20:30
@ValuedMammal ValuedMammal moved this from In Progress to Needs Review in BDK Wallet Jul 7, 2025
@ValuedMammal ValuedMammal added the documentation Improvements or additions to documentation label Jul 7, 2025
@ValuedMammal ValuedMammal self-assigned this Jul 7, 2025
@ValuedMammal ValuedMammal marked this pull request as ready for review July 7, 2025 20:31
Copy link
Contributor

@tvpeter tvpeter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Mammal for the excellent documentation.

ACK 9284767

I left a suggestion for including an example if it won't become too lengthy.

/// influence the wallet's canonicalization logic.
///
/// [`transactions`]: Wallet::transactions
/// [`start_sync_with_revealed_spks`]: Wallet::start_sync_with_revealed_spks
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be great to also include an example here:

Suggested change
/// [`start_sync_with_revealed_spks`]: Wallet::start_sync_with_revealed_spks
/// [`start_sync_with_revealed_spks`]: Wallet::start_sync_with_revealed_spks
/// ## Example
///
/// ```rust
/// use bdk_wallet::{Wallet, bitcoin::Txid};
/// use std::collections::HashSet;
///
/// let unconfirmed_txids: HashSet<Txid> = wallet
/// .transactions()
/// .filter(|tx| tx.chain_position.is_unconfirmed())
/// .map(|tx| tx.tx_node.txid)
/// .collect();
///
/// let mut evicted_txs = Vec::new();
/// for txid in unconfirmed_txids {
/// let tx_node = wallet.tx_graph().full_txs().find(|tx| tx.txid == txid);
/// let wallet_tx = wallet.get_tx(txid);
/// let is_evicted = wallet_tx.map_or(true, |tx| {
/// !tx.chain_position.is_unconfirmed() && !tx.chain_position.is_confirmed()
/// });
/// if is_evicted {
/// let last_seen = tx_node.map_or(0, |tx| tx.last_seen.unwrap_or(0));
/// evicted_txs.push((txid, last_seen));
/// }
/// }
///
/// if !evicted_txs.is_empty() {
/// wallet.apply_evicted_txs(evicted_txs)?;
/// wallet.persist(&mut db)?;
/// }

///
/// ## Notes
///
/// - This function is particularly useful when syncing with a blockchain backend that provides
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me if or when a user needs to use this function. Don't the bdk_* chain clients already evict tx when they notice it missing from the mempool?

@ValuedMammal
Copy link
Collaborator Author

@tvpeter @notmandatory One usage example that I know of is in the example_wallet_rpc.

@ValuedMammal ValuedMammal moved this from Needs Review to In Progress in BDK Wallet Jul 14, 2025
Copy link
Member

@notmandatory notmandatory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK c1e7fcc

Can add examples later, either way this PR adds valuable info.

@notmandatory notmandatory moved this from In Progress to Needs Review in BDK Wallet Jul 31, 2025
Copy link
Contributor

@oleonardolima oleonardolima left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK c1e7fcc

@ValuedMammal ValuedMammal force-pushed the doc/apply-evicted-txs branch from c1e7fcc to 05e1f4a Compare August 1, 2025 17:17
@notmandatory notmandatory merged commit 648766f into bitcoindevkit:master Aug 4, 2025
20 checks passed
@github-project-automation github-project-automation bot moved this from Needs Review to Done in BDK Wallet Aug 4, 2025
@ValuedMammal ValuedMammal deleted the doc/apply-evicted-txs branch August 9, 2025 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

docs: Have a section explaining mempool eviction detection.

5 participants