docs: Document TxUpdate temporal context requirements (supports Wizardsardine audit recommendation)#2135
Conversation
| /// - [`anchors`]: for confirmed transactions. | ||
| /// - [`seen_ats`]: for unconfirmed transactions. | ||
| /// | ||
| /// The built-in chain (`bdk_electrum`, `bdk_esplora`, `bdk_bitcoind_rpc`) handle this |
There was a problem hiding this comment.
| /// The built-in chain (`bdk_electrum`, `bdk_esplora`, `bdk_bitcoind_rpc`) handle this | |
| /// The built-in chain-source crates (`bdk_electrum`, `bdk_esplora`, `bdk_bitcoind_rpc`) handle this |
| /// | ||
| /// The built-in chain (`bdk_electrum`, `bdk_esplora`, `bdk_bitcoind_rpc`) handle this | ||
| /// automatically. Transactions lacking temporal context are stored but ignored by canonicalization. | ||
| /// Custom chain sources must populate these fields. |
There was a problem hiding this comment.
| /// Custom chain sources must populate these fields. |
Can remove this line. All chain sources should populate those fields.
| /// provide the `seen_at` value. | ||
| /// | ||
| /// Note: this is a `HashSet<(Txid, u64)>`, not a `HashMap`. | ||
| /// Insert with `.insert((txid, timestamp))`, not `.insert(txid, timestamp)`. |
There was a problem hiding this comment.
The HashSet hint is unnecessary. The type signature is right there on the field.
| /// - [`anchors`]: for confirmed transactions. | ||
| /// - [`seen_ats`]: for unconfirmed transactions. |
There was a problem hiding this comment.
These don't look like valid doc links. I'm assuming they should be [`Self::anchors`] and [`Self::seen_ats`].
Run cargo doc to make sure.
|
Addressed all four review points:
Verified with |
evanlinjin
left a comment
There was a problem hiding this comment.
Added docs look good. Can we merge the two commits?
Happy to squash! Just to confirm — do you want me to squash into a single commit before you merge, or would you prefer to squash-merge from your side? |
|
@rafaelturon can you squash into single commit please. |
4d9300f to
8ca6c43
Compare
|
@evanlinjin Done! Squashed into a single commit. |
f035858 to
fee292c
Compare
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>
fee292c to
b69d7bf
Compare
There was a problem hiding this comment.
ACK b69d7bf
@rafaelturon I forced push to add more context to the apply_update docs.
Closes #2133
This introduces clear temporal context documentation to the
TxUpdatestruct, explicitly stating that entries must have eitheranchorsorseen_atsto be considered canonical and contribute to wallet balances.It also explicitly documents the
seen_atsHashSet signature to prevent usage errors when writing custom chain sources.This fulfills the recommendation outlined in the Wizardsardine BDK Audit Report (Q4 2024).
Description
This primarily affects developers building custom chain sources — anyone constructing
Updatestructs outside ofbdk_electrum/bdk_esplora/bdk_bitcoind_rpc.As the ecosystem grows (streaming Electrum, Nostr relay sync, compact block filters, custom backends), more developers will encounter this undocumented contract.
What I Changed
1. Doc comment on
TxUpdatestructanchorsorseen_atsare stored in the graph but do not affect the balance.seen_atscollection type:TxUpdate::seen_atsis aBTreeSet<(Txid, u64)>, requiring.insert((txid, timestamp)).2. Doc comment on
Wallet::apply_update()apply_update: transactions without temporal context note.apply_update: transactions without temporal context note.Impact
This is just a documentation fix - no code changes, no breaking changes.
Checklists
All Submissions: