bitcoindevkit / bitcoindevkit/bdk_wallet

The `TxGraph.list_chain_txs()` method doesn't behave as you'd expect from the docs

Open
#113 9 comments 0 reactions 0 assignees View on GitHub
documentation good first issue
Dominant language
Rust
Stars
59
Forks
105
Avg merge
10d 9h
Merged PRs (30d)
1

Description

When calling the `TxGraph.list_chain_txs(chain, chain_tip)` method, if you pass a `chain_tip` that does not belong in the `chain`, the method will simply return all transactions in your transaction graph, and transactions wil appear to be unconfirmed rather than the method letting your know that your chain_tip and chain are not currently compatible. The API docs for the method read:
> List graph transactions that are in `chain` with `chain_tip`.

Consider the following example:
```rust
fn main() -> () {
pub const RAW_TX_1: &str = "0200000000010116d6174da7183d70d0a7d4dc314d517a7d135db79ad63515028b293a76f4f9d10000000000feffffff023a21fc8350060000160014531c405e1881ef192294b8813631e258bf98ea7a1027000000000000225120a60869f0dbcf1dc659c9cecbaf8050135ea9e8cdc487053f1dc6880949dc684c024730440220591b1a172a122da49ba79a3e79f98aaa03fd7a372f9760da18890b6a327e6010022013e82319231da6c99abf8123d7c07e13cf9bd8d76e113e18dc452e5024db156d012102318a2d558b2936c52e320decd6d92a88d7f530be91b6fe0af5caf41661e77da3ef2e0100";
let tx: Transaction = tx_from_hex(RAW_TX_1);

let mut graph = TxGraph::::default();
graph.insert_tx(tx.clone());

let confirmation_time_height_anchor2 = ConfirmationTimeHeightAnchor {
anchor_block: BlockId {
height: 2,
hash: Hash::hash("second".as_bytes()),
},
confirmation_height: 2,
confirmation_time: 100,
};

let chain = LocalChain::from_blocks(
[
(0, Hash::hash("zero".as_bytes())),
(1, Hash::hash("first".as_bytes())),
(2, Hash::hash("second".as_bytes())),
(3, Hash::hash("third".as_bytes())),
]
.into_iter()
.collect::>(),
).unwrap();

graph.insert_anchor(
tx.txid(),
confirmation_time_height_anchor2
);

let block_4 = BlockId {
height: 4,
hash: Hash::hash("fourth".as_bytes()),
};

let txs = graph.list_chain_txs(&chain, block_4);
println!("Transactions: {:#?}\n", txs.collect::>());
}
```

This example will print to the console
```rust
Transactions: [
CanonicalTx {
chain_position: Unconfirmed(
0,
),
tx_node: TxNode {
txid: 0xd6f6c49aadcc8f5a3d5997b8e564acf443af0dd7d6bb2e5b34d68d9ea90c9838,
tx: Transaction {
version: 2,
lock_time: Blocks(
Height(
77551,
),
),
input: ...
```

instead of warning the user that they provided a chain tip that does not exist in the chain.

I opened this issue to ask whether this is intended behaviour (and we can modify the docs to reflect that) or whether this might be a small bug.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.