wallet: make coinbase that will mature on the next block available for selection #32123

pull luisschwab wants to merge 1 commits into bitcoin:master from luisschwab:fix/off-by-one-coinbase changing 13 files +67 −47
  1. luisschwab commented at 9:31 pm on March 22, 2025: contributor

    Closes #32098.

    Currently, only coinbase UTXOs that are mature at height h are available for coin selection. This PR makes UTXOs that mature at height h+1 available for selection.

    Since a transaction spending this output will be accepted by the mempool, it should be available for selection.

    BDK implements this logic1, which I believe to be the correct one.

     0$ bitcoin-cli -regtest createwallet wallet
     1{
     2  "name": "wallet"
     3}
     4
     5$ export DESCRIPTOR=$(bitcoin-cli -regtest -rpcwallet=wallet listdescriptors | jq -r '.descriptors[] | select(.internal==false and (.desc | startswith("wpkh"))) | .desc')
     6
     7$ export ADDRESS=$(bitcoin-cli -regtest -rpcwallet=wallet getnewaddress)
     8
     9$ bitcoin-cli -regtest generatetoaddress 101 $ADDRESS
    10[
    11  "467fd440d0ed89d0cad64fa64d0320968b33a32c681b6c3f5a5ed1d1c016f45a",
    12  "1b2246eaa35689710acc5d1bb2923197993233fb9186f0bd561cb546c7667ca7",
    13  ...
    14  "5d5ee44ada395ab1d978a77596ed3893be750840229e7234a85a01984057798a",
    15  "7f8a573a6824edc5342cf86e5e7c0a6ea5664305ef21808456fc98b2621b41cf"
    16]
    17
    18$ bitcoin-cli -regtest -rpcwallet=wallet getbalance
    19- 50.00000000
    20+ 100.00000000
    
  2. DrahtBot commented at 9:31 pm on March 22, 2025: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32123.

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

  3. DrahtBot added the label Wallet on Mar 22, 2025
  4. DrahtBot added the label CI failed on Mar 22, 2025
  5. luisschwab force-pushed on Mar 22, 2025
  6. luisschwab force-pushed on Mar 22, 2025
  7. luisschwab force-pushed on Mar 23, 2025
  8. wallet: make coinbase that will mature on the next block available for selection 35b2f01c7d
  9. luisschwab force-pushed on Mar 23, 2025
  10. fjahr commented at 12:03 pm on March 23, 2025: contributor

    I understand what you are saying about correctness but @sipa ’s concerns with propagation issues are also hard to ignore. Bitcoin Core just tends to be on the more conservative side when it comes to protecting users and BDK might leave protections like this to be handled by the actual wallet implemeters that use BDK.

    A potential middle ground could be that current behavior is maintained but users get a useful hint in return why they can’t spend their funds yet. Then there could be a flag added that allows to spend the funds (-f for force or so). Still not sure if this would achieve enough conceptual agreement but I think the chances are higher than with the current change.

  11. sipa commented at 12:17 pm on March 23, 2025: member

    @luisschwab There are other examples of coins which the Bitcoin Core wallet won’t let users spend, for example, unconfirmed coins (unless they are self-created/change). Just like here, that’s not a protocol rule, but it’s a bad idea, and it’s perfectly possible to bypass by using raw transactions.

    Now, given how unlikely it is in 2025 for any user to use the Bitcoin Core wallet directly for mining payouts, the odds that this is still actually protecting anyone are probably negligible. So @fjahr , I think offering a way to disable this behavior would be huge overkill. It probably doesn’t matter either way in practice.

    But on the other hand, I just see no reason to change this. If direct user mining payouts were common, this would be a useful rule. There is nothing incorrect about the current behavior, and I categorically disagree that the wallet should just allow anything that’s legal in the protocol without question. If someone really wants to bypass this, they can always use raw transactions.

  12. luisschwab commented at 4:19 pm on March 25, 2025: contributor
    What do you think @murchandamus?

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-03-28 15:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me