]> Untitled Git - bdk/commitdiff
Merge bitcoindevkit/bdk#1839: Introduce `evicted-at`/`last-evicted` timestamps
author志宇 <hello@evanlinjin.me>
Sat, 15 Mar 2025 23:04:12 +0000 (10:04 +1100)
committer志宇 <hello@evanlinjin.me>
Sat, 15 Mar 2025 23:05:10 +0000 (10:05 +1100)
0a20724e30316cbb68f7edf3f62028de15d26277 feat(examples): Update example crates to use `expected_spk_txids` (志宇)
1f8fc173b6aeddbc81a8301346502f9a923554ce feat(core)!: Remove redundant `SyncRequest` methods (志宇)
f42d5a8549df89452d57f1f9cff8f6e8e8c23dbc feat(esplora): Handle spks with expected txids (志宇)
3ab4994139dfa72d65ab0bbe6524af14efd77027 feat(electrum): Handle spks with expected txids (志宇)
64e4100a36f88a154b01706892fbec19edabf6b5 feat(chain): Add `TxGraph` methods that handle expected spk txids (志宇)
b38569fd147f8fe30f55e1c30cdba779247ba856 feat(core): Add expected txids to `SyncRequest` spks (Wei Chen)
a2dfcb9f9c39ef90f808b034731df0edb712e740 feat(chain)!: Change `TxGraph` to understand evicted-at & last-evicted (志宇)
ae0336b205f3b29253b5be3142dff54a4da09232 feat(core): Add `TxUpdate::evicted_ats` (志宇)

Pull request description:

  Partially Fixes #1740.
  Replaces #1765.
  Replaces #1811.

  ### Description

  This PR allows the receiving structures (`bdk_chain`, `bdk_wallet`) to detect and evict incoming transactions that are double spent (cancelled).

  We add a new field to `TxUpdate` (`TxUpdate::evicted_ats`), which in turn, updates the `last_evicted` timestamps that are tracked/persisted by `TxGraph`. This is similar to how `TxUpdate::seen_ats` update the `last_seen` timestamp in `TxGraph`. Transactions with a `last_evicted` timestamp higher than their `last_seen` timestamp are considered evicted.

  `SpkWithExpectedTxids` is introduced in `SpkClient` to track expected `Txid`s for each `spk`. During a sync, if any `Txid`s from `SpkWithExpectedTxids` are not in the current history of an `spk` obtained from the chain source, those `Txid`s are considered missing. Support for `SpkWithExpectedTxids` has been added to both `bdk_electrum` and `bdk_esplora` chain source crates.

  The canonicalization algorithm is updated to disregard transactions with a `last_evicted` timestamp greater than or equal to their `last_seen` timestamp, except in cases where transitivity rules apply.

  ### Notes to the reviewers

  This PR does not fix #1740 for block-by-block chain source (such as `bdk_bitcoind_rpc`). This work is done in a separate PR (#1857).

  ### Changelog notice

  * Add `TxUpdate::evicted_ats` which tracks transactions that have been replaced and are no longer present in mempool.
  * Change `TxGraph` to track `last_evicted` timestamps. This is when a transaction is last marked as missing from the mempool.
  * The canonicalization algorithm now disregards transactions with a `last_evicted` timestamp greater than or equal to it's `last_seen` timestamp, except when a canonical descendant exists due to rules of transitivity.
  * Add `SpkWithExpectedTxids` in `spk_client` which keeps track of expected `Txid`s for each `spk`.
  * Change `bdk_electrum` and `bdk_esplora` to understand `SpkWithExpectedTxids`.
  * Add `SyncRequestBuilder::expected_txids_of_spk` method which adds an association between `txid`s and `spk`s.

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing

  #### New Features:

  * [x] I've added tests for the new feature
  * [x] I've added docs for the new feature

  #### Bugfixes:

  * [x] This pull request breaks the existing API
  * [x] I've added tests to reproduce the issue which are now passing
  * [x] I'm linking the issue being fixed by this PR

ACKs for top commit:
  LLFourn:
    ACK 0a20724e30316cbb68f7edf3f62028de15d26277

Tree-SHA512: 29ef964e4597aa9f4cf02e9997b0d17cb91ec2f0f1187b0e9ade3709636b873c2a7cbe803facbc4686a3050a2abeb3e9cc40f9308f8cded9c9353734dcc5755b


Trivial merge