bitcoindevkit / bitcoindevkit/bdk
`TxGraph::insert_txout` overwrites existing floating txout but returns empty `ChangeSet`
- Dominant language
- Rust
- Stars
- 1.1k
- Forks
- 483
- Avg merge
- 20d 3h
- Merged PRs (30d)
- 3
Description
**Describe the bug**
`TxGraph::insert_txout` on an outpoint already present as a floating txout overwrites it in memory but returns an empty `ChangeSet`.
- Debug: panics.
- Release: live graph holds the new `TxOut`, changeset is empty, so persisted state keeps the old one. `IndexedTxGraph::insert_txout` forwards the empty changeset, so the indexer never sees the replacement.
Contradicts the doc comment ("`ChangeSet` result will be empty if the `outpoint` ... already existed") and the assert's own message ("txout of the same outpoint should never change").
**To Reproduce**
Run with `--release` (debug panics on the assert instead):
```rust
use bdk_chain::{tx_graph::TxGraph, Merge};
use bitcoin::{hashes::Hash, Amount, OutPoint, ScriptBuf, TxOut, Txid};
let op = OutPoint::new(Txid::all_zeros(), 0);
let a = TxOut { value: Amount::from_sat(1_000), script_pubkey: ScriptBuf::new() };
let b = TxOut { value: Amount::from_sat(2_000), script_pubkey: ScriptBuf::new() };
let mut graph: TxGraph = TxGraph::default();
let _ = graph.insert_txout(op, a.clone());
let cs = graph.insert_txout(op, b);
assert!(cs.is_empty()); // passes: reports "no change"
assert_eq!(graph.get_txout(op), Some(&a)); // FAILS: graph now holds `b`
```
**Expected behavior**
First insert wins: an existing outpoint is never overwritten, and an empty changeset truthfully means no change.
**Build environment**
- BDK tag/commit: acc06e53
**Which backend(s) are relevant (if any)?**
- [x] None / not backend-related (e.g. `bdk_chain`, `bdk_core`)
**Is this blocking production use?**
- [x] No
Contributor guide
Assessment
This issue has not been assessed yet.