Used RPC commands to reproduce the issue (leveraged the unit test too)
Steps
- MINER_WALLET=$(./bitcoin-cli -named createwallet wallet_name="miner" | jq -r '.name')
- ./bitcoin-cli -rpcwallet=$MINER_WALLET -generate 101
- TEST_WALLET=$(./bitcoin-cli -named createwallet wallet_name="36284" disable_private_keys=false blank=false passphrase="" avoid_reuse=true | jq -r '.name')
- TEST_WALLET_ADDR1=$(./bitcoin-cli -rpcwallet=$TEST_WALLET getnewaddress)
- ./bitcoin-cli -rpcwallet=$MINER_WALLET sendtoaddress $TEST_WALLET_ADDR1 0.3
- ./bitcoin-cli -rpcwallet=$MINER_WALLET -generate 1
- for i in $(seq 1 25); do
ADDR_N=$(./bitcoin-cli -rpcwallet=$TEST_WALLET getnewaddress)
LAST_TXID=$(./bitcoin-cli -rpcwallet=$TEST_WALLET sendall "["$ADDR_N"]")
echo "[$i/25] ADDR_N=$ADDR_N LAST_TXID=$LAST_TXID"
done
- ./bitcoin-cli getmempoolentry $LAST_TXID
- TEST_WALLET_ADDR2=$(./bitcoin-cli -rpcwallet=$TEST_WALLET getnewaddress)
- MINER_WALLET_TXID=$(./bitcoin-cli -rpcwallet=$MINER_WALLET sendtoaddress $TEST_WALLET_ADDR2 0.7)
- MINER_WALLET_ADDR1=$(./bitcoin-cli -rpcwallet=$MINER_WALLET getnewaddress)
- ./bitcoin-cli generateblock $MINER_WALLET_ADDR1 "["$MINER_WALLET_TXID"]"
- MINER_WALLET_ADDR2=$(./bitcoin-cli -rpcwallet=$MINER_WALLET getnewaddress)
- ./bitcoin-cli -rpcwallet=$TEST_WALLET sendtoaddress $MINER_WALLET_ADDR2 0.65
Finding
From the test, it is seen that there is indeed double UTXO counting that leads to the failed sendtoaddress of 0.65 that should be successful since only 0.3 should be 'discarded' instead of twice the amount
Outputs
Before:
ratedg@0xratedg:~/projects/contributions/bitcoin/build/bin$ ./bitcoin-cli -rpcwallet=$TEST_WALLET sendtoaddress $MINER_WALLET_ADDR2 0.65
error code: -6
error message:
Unconfirmed UTXOs are available, but spending them creates a chain of transactions that will be rejected by the mempool
After:
ratedg@0xratedg:~/projects/contributions/bitcoin/build2/bin$ ./bitcoin-cli getmempoolentry 9dcdf2a114a123273d53399469063defb142d37973bbcbaabe10e959963beb6e
{
"vsize_adjusted": 110,
"vsize": 110,
"vsize_bip141": 110,
"weight": 437,
"time": 1790152439,
"height": 102,
"descendantcount": 1,
"descendantsize": 110,
"ancestorcount": 25,
"ancestorsize": 2750,
"wtxid": "a4d3ecebf8e0dc8fa93273664ea61893762a9f59ef4c7821785c01f96ccf6304",
"chunkweight": 437,
"fees": {
"base": 0.00001100,
"modified": 0.00001100,
"ancestor": 0.00027500,
"descendant": 0.00001100,
"chunk": 0.00001100
},
"depends": [
"19a95372d996bb24cbb934c4314bb2100e34b8dfe55ab8b6a370fdde6007443f"
],
"spentby": [
],
"unbroadcast": true
}
ratedg@0xratedg:~/projects/contributions/bitcoin/build2/bin$ TEST_WALLET_ADDR2=$(./bitcoin-cli -rpcwallet=$TEST_WALLET getnewaddress)
ratedg@0xratedg:~/projects/contributions/bitcoin/build2/bin$ MINER_WALLET_TXID=$(./bitcoin-cli -rpcwallet=$MINER_WALLET sendtoaddress $TEST_WALLET_ADDR2 0.7)
ratedg@0xratedg:~/projects/contributions/bitcoin/build2/bin$ MINER_WALLET_ADDR1=$(./bitcoin-cli -rpcwallet=$MINER_WALLET getnewaddress)
ratedg@0xratedg:~/projects/contributions/bitcoin/build2/bin$ ./bitcoin-cli generateblock $MINER_WALLET_ADDR1 "[\"$MINER_WALLET_TXID\"]"
{
"hash": "6886bb18d6b98152d21e53259f7548ceb003878d399d5d3b8f3d24c192386d0f"
}
ratedg@0xratedg:~/projects/contributions/bitcoin/build2/bin$ MINER_WALLET_ADDR2=$(./bitcoin-cli -rpcwallet=$MINER_WALLET getnewaddress)
ratedg@0xratedg:~/projects/contributions/bitcoin/build2/bin$ ./bitcoin-cli -rpcwallet=$TEST_WALLET sendtoaddress $MINER_WALLET_ADDR2 0.65
0b37799db7bbc95014fd17cb0d87df8c6496424bebe3443c3aff2c9d97f964e4
ratedg@0xratedg:~/projects/contributions/bitcoin/build2/bin$