-
Notifications
You must be signed in to change notification settings - Fork 417
Closed
Labels
bugSomething isn't workingSomething isn't workingdiscussionThere's still a discussion ongoingThere's still a discussion ongoing
Description
Describe the bug
There is a mismatch between the mature balance that Bitcoin Core and example_wallet_rpc return after generating 101 blocks to an address: 50 BTC vs 100 BTC, respectively.
This looks like an off-by-one error, where the second block is being interpreted as mature by BDK.
To Reproduce
Slight modification on example_wallet_rpc/src/main.rs so it shows all balance kinds:
println!(
"Wallet tip is '{}:{}'",
wallet_tip_end.height(),
wallet_tip_end.hash()
);
//println!("Wallet balance is {}", balance.total());
println!(
"Wallet has {} transactions and {} utxos",
wallet.transactions().count(),
wallet.list_unspent().count()
);
println!("Immature wallet balance is {}", balance.immature);
println!("Trusted pending wallet balance is {}", balance.trusted_pending);
println!("Untrusted pending wallet balance is {}", balance.untrusted_pending);
println!("Confirmed wallet balance is {}", balance.confirmed);
Ok(())
}
Script to mine 101 blocks (only one coinbase is mature):
rm -r ~/.bitcoin/regtest
rm .bdk_wallet_rpc_example.db
bitcoind -regtest -daemon
sleep 2
export WALLET_NAME="example_wallet_rpc"
export RPC_COOKIE=~/.bitcoin/regtest/.cookie
bitcoin-cli -regtest createwallet $WALLET_NAME
export DESCRIPTOR=$(bitcoin-cli -regtest listdescriptors | jq -r '.descriptors[] | select(.internal==false and (.desc | startswith("wpkh"))) | .desc')
export ADDRESS=$(bitcoin-cli -regtest getnewaddress)
bitcoin-cli -regtest generatetoaddress 101 $ADDRESS
bitcoin-cli -regtest getbalance
cargo run --bin example_wallet_rpc $DESCRIPTOR
Bitcoin Core shows a 50 BTC balance:
"21f40ab5a306247034abc5f4089fc122b66c5f159af43417f9e3f3c86ca60156",
"58eccdf9b7b79393abe58d2eef4a017b65d312744cfbfe91e99bbf5ca4ee8727",
"3c06987a7b0e6449b9df1d2a912e1062cce6610568887d3d9c58116b9afba865",
"4329baa4fa1550efa503d661b8c360d2d6006a64611aad991f08f440553c655d",
"4e9d736dc960985c1bfdb08a3739f17905b88c4c628a8e525398c574afcfd145"
]
50.00000000
example_wallet_rpc shows a 100 BTC confirmed balance:
Applied block 4e9d736dc960985c1bfdb08a3739f17905b88c4c628a8e525398c574afcfd145 at height 101 in 0.000219998s
Applied unconfirmed transactions in 0.000009303s
Synced 101 blocks in 0.056750063s
Wallet tip is '101:4e9d736dc960985c1bfdb08a3739f17905b88c4c628a8e525398c574afcfd145'
Wallet has 101 transactions and 101 utxos
Immature wallet balance is 4950 BTC
Trusted pending wallet balance is 0 BTC
Untrusted pending wallet balance is 0 BTC
Confirmed wallet balance is 100 BTC
Expected behavior
Both confirmed balances should be the same.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingdiscussionThere's still a discussion ongoingThere's still a discussion ongoing
Type
Projects
Status
Done