Skip to content

Commit b69d7bf

Browse files
rafaelturonevanlinjin
authored andcommitted
docs: document TxUpdate temporal context requirements
This introduces clear temporal context documentation to the `TxUpdate` struct, explicitly stating that entries must have either `anchors` or `seen_ats` to be considered canonical and contribute to wallet balances. This fulfills the recommendation outlined in the Wizardsardine BDK Audit Report (Q4 2024). Signed-off-by: Rafael Turon <3598269+rafaelturon@users.noreply.github.com>
1 parent 01d0dd3 commit b69d7bf

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

crates/chain/src/indexed_tx_graph.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ where
178178
///
179179
/// `update` is a [`tx_graph::TxUpdate<A>`] and the resultant changes is returned as
180180
/// [`ChangeSet`].
181+
///
182+
/// **Note**: Transactions in the `update` without temporal context (anchors or seen_ats)
183+
/// will be stored but will not be considered canonical. See [`tx_graph::TxUpdate`] for
184+
/// more details.
181185
pub fn apply_update(&mut self, update: tx_graph::TxUpdate<A>) -> ChangeSet<A, I::ChangeSet> {
182186
let tx_graph = self.graph.apply_update(update);
183187
let indexer = self.index_tx_graph_changeset(&tx_graph);

crates/chain/src/tx_graph.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,9 @@ impl<A: Anchor> TxGraph<A> {
913913
///
914914
/// The returned [`ChangeSet`] is the set difference between `update` and `self` (transactions
915915
/// that exist in `update` but not in `self`).
916+
///
917+
/// **Note**: Transactions in the `update` without temporal context (anchors or seen_ats)
918+
/// will be stored but will not be considered canonical. See [`TxUpdate`] for more details.
916919
pub fn apply_update(&mut self, update: TxUpdate<A>) -> ChangeSet<A> {
917920
let mut changeset = ChangeSet::<A>::default();
918921
for tx in update.txs {

crates/core/src/tx_update.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ use bitcoin::{OutPoint, Transaction, TxOut, Txid};
1818
/// tx_update.txs.push(tx);
1919
/// tx_update.anchors.insert((anchor, txid));
2020
/// ```
21+
/// ## Temporal context
22+
/// To contribute to a wallet's balance, transactions must have an entry in either:
23+
/// - [`Self::anchors`]: for confirmed transactions.
24+
/// - [`Self::seen_ats`]: for unconfirmed transactions.
25+
///
26+
/// The built-in chain-source crates (`bdk_electrum`, `bdk_esplora`, `bdk_bitcoind_rpc`) handle this
27+
/// automatically. Transactions lacking temporal context are stored but ignored by canonicalization.
2128
#[derive(Debug, Clone)]
2229
#[non_exhaustive]
2330
pub struct TxUpdate<A = ()> {

0 commit comments

Comments
 (0)