Skip to content

Conversation

@luisschwab
Copy link
Contributor

@luisschwab luisschwab commented Mar 22, 2025

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.

$ bitcoin-cli -regtest createwallet wallet
{
  "name": "wallet"
}

$ export ADDRESS=$(bitcoin-cli -regtest -rpcwallet=wallet getnewaddress)

$ bitcoin-cli -regtest generatetoaddress 101 $ADDRESS
[
  "467fd440d0ed89d0cad64fa64d0320968b33a32c681b6c3f5a5ed1d1c016f45a",
  "1b2246eaa35689710acc5d1bb2923197993233fb9186f0bd561cb546c7667ca7",
  ...
  "5d5ee44ada395ab1d978a77596ed3893be750840229e7234a85a01984057798a",
  "7f8a573a6824edc5342cf86e5e7c0a6ea5664305ef21808456fc98b2621b41cf"
]

$ bitcoin-cli -regtest -rpcwallet=wallet getbalance
- 50.00000000
+ 100.00000000

@DrahtBot
Copy link
Contributor

DrahtBot commented Mar 22, 2025

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.

Type Reviewers
Concept ACK shahsb

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #32349 (test: Increase stack size for "Debug" builds with MSVC by hebasto)
  • #28710 (Remove the legacy wallet and BDB dependency by achow101)
  • #27865 (wallet: Track no-longer-spendable TXOs separately by achow101)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@luisschwab luisschwab force-pushed the fix/off-by-one-coinbase branch 4 times, most recently from f36e683 to 35b2f01 Compare March 23, 2025 04:05
@fjahr
Copy link
Contributor

fjahr commented Mar 23, 2025

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.

@sipa
Copy link
Member

sipa commented Mar 23, 2025

@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.

@luisschwab
Copy link
Contributor Author

What do you think @murchandamus?

@maflcko
Copy link
Member

maflcko commented Apr 1, 2025

#32098 (comment) could be a reason that this is fine to change, but the CI is failing on this pull

@luisschwab luisschwab force-pushed the fix/off-by-one-coinbase branch from 35b2f01 to 913e4ca Compare April 1, 2025 18:23
@luisschwab
Copy link
Contributor Author

luisschwab commented Apr 1, 2025

but the CI is failing on this pull

Not sure what is going on with CI, other PRs are failing on Windows as well.

edit: #32184 fixes it

@DrahtBot DrahtBot removed the CI failed label Apr 1, 2025
@achow101
Copy link
Member

-0

I agree with the rationale given by the others to not make this change.

@shahsb
Copy link

shahsb commented Apr 19, 2025

Concept ACK

@DrahtBot
Copy link
Contributor

🐙 This pull request conflicts with the target branch and needs rebase.

@DrahtBot
Copy link
Contributor

⌛ There hasn't been much activity lately and the patch still needs rebase. What is the status here?

  • Is it still relevant? ➡️ Please solve the conflicts to make it ready for review and to ensure the CI passes.
  • Is it no longer relevant? ➡️ Please close.
  • Did the author lose interest or time to work on this? ➡️ Please close it and mark it 'Up for grabs' with the label, so that it can be picked up in the future.

@luisschwab
Copy link
Contributor Author

Closing as it failed to reach consensus.

@luisschwab luisschwab closed this Jul 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect balance when dealing with coinbase UTXOs that will be mature on h + 1

7 participants