Skip to content

[pull] master from bitcoin:master#1671

Merged
pull[bot] merged 17 commits into
All-Blockchains:masterfrom
bitcoin:master
Jun 4, 2026
Merged

[pull] master from bitcoin:master#1671
pull[bot] merged 17 commits into
All-Blockchains:masterfrom
bitcoin:master

Conversation

@pull

@pull pull Bot commented Jun 4, 2026

Copy link
Copy Markdown

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.4)

Can you help keep this open source service alive? 💖 Please sponsor : )

murchandamus and others added 17 commits April 9, 2026 16:37
The expected iteration count demonstrates how the following improvements
reduce iterations will help catch any regressions in the future.
In the original implementation of BnB, the state of the search is
backtracked by explicitly walking back to the omission branch and then
testing again. This retests an equivalent candidate set as before, e.g.,
after backtracking from {ABC}, it would evaluate {AB_}, before trying
{AB_D}, but {AB_} is equivalent to {AB} which was tested before.

CoinGrinder tracks the state of the search instead by remembering which
UTXO was last added and explicitly shifting from that UTXO directly to
the next, so after {ABC}, it will immediately move on to {AB_D}. We
replicate this approach here.

The description of the two optimizations is removed from the
documentation as they will only be implented in a later commit.
BnB may not be able to exhaustively search all potentially interesting
combinations for large UTXO pools, so we keep track of whether the
search was terminated by the iteration limit.
At high feerates adding more inputs will increase the waste score. If
the current waste is already higher than the best selection’s we cannot
improve upon the best selection. All solutions that include the current
selection with more additional inputs must be worse than the best
selection so far: SHIFT

This optimization only works at high feerates, because at low feerates,
adding more inputs decreases waste, so this condition would exit
prematurely. We would never attempt input sets with higher weight than
the prior best selection, even though we would prefer those at low
feerates.
Introduces a dedicated data structure to track the total
effective_value available in the remaining UTXOs at each index of the
UTXO pool. In contrast to the original approach in BnB, this allows us
to immediately jump to a lower index instead of visiting every UTXO to
add back their eff_value to the lookahead.
When two successive UTXOs match in effective value and weight, we can
skip the second if the prior is not selected: adding it would create an
equivalent input set to a previously evaluated.

E.g. if we have three UTXOs with effective values {5, 3, 3} of the same
weight each, we want to evaluate
{5, _, _}, {5, 3, _}, {5, 3, 3}, {_, 3, _}, {_, 3, 3},
but skip {5, _, 3}, and {_, _, 3}, because the first 3 is not selected,
and we therefore do not need to evaluate the second 3 at the same
position in the input set.

If we reach the end of the branch, we must SHIFT the previously selected
UTXO group instead.
When two successive UTXOs differ in waste but match in effective value,
we can skip the second if the first is not selected, because all input
sets we can generate by swapping out a less wasteful UTXOs with a more
wastefull UTXO of matching effective value would be strictly worse.

Also expand documentation of Branch and Bound.
This encapsulates the soft fork configuration logic as set by the `-testactivationheight` (for
buried deployments) and `-vbparams` (for version bits deployments) options which for the moment
are regtest-only, in order to make them available on other networks as well in the next commit.

Can be reviewed using git's `--color-moved` option with `--color-moved-ws=allow-indentation-change`.
…orks

This allows unit tests to set `-testactivationheight` and `-vbparams` on
all networks instead of exclusively on regtest. Those are kept
test-network-only when used as startup parameters.
For consistency with the overloads introduced in the previous commit,
and because there is already a few places where they are useful.
… BIP323

Test bits are conserved. This only has an effect on the warnings.

Co-Authored-By: Antoine Poinsot <mail@antoinep.com>
Co-Authored-by: Anthony Towns <aj@erisian.com.au>
…aviour

Co-Authored-by: Anthony Towns <aj@erisian.com.au>
107d417 versionbits: update VersionBitsCache doc comment to match current behaviour (Antoine Poinsot)
94e3ac0 doc: release notes and bips doc update for #34779 (Antoine Poinsot)
1d52405 qa: test we don't warn for ignored unknown version bits deployments (Antoine Poinsot)
f802edf versionbits: Limit live activation params and activation warnings per BIP323 (Anthony Towns)

Pull request description:

  This implements bitcoin/bips#2116, which repurposes 24 version bits as extra nonce space for miners rather than soft fork deployment coordination. 24 bits allows a miner to perform up to 72 PH before needing a fresh job from its controller. The current 16 bits in use by miners only allow up to 280 TH, which [apparently led some ASIC designers to start rolling the timestamp field](bitaxeorg/ESP-Miner#1553 (comment)) on their beefier machines.

  Mailing list discussion available [here](https://gnusha.org/pi/bitcoindev/6fa0cb45-37d6-4b41-9ff8-03730fd96d6e@mattcorallo.com/). A previous shot at this is #13972 (with a smaller extranonce space).

  This change only affects the warning logic.

ACKs for top commit:
  ajtowns:
    ACK 107d417
  achow101:
    ACK 107d417
  sedited:
    Re-ACK 107d417
  optout21:
    ACK 107d417

Tree-SHA512: cfaf5d7de1e8c020a4d7f4b1096b6c3e0e3b41ea840a4652ebcdabc345c5c557161c8304f1d7d6de541a2bf1df3c855ad7b64e49dd8c8af3937876d134bb5aba
…est in unit tests

801e3bf chainparams: add overloads for RegTest and SigNet with no options (Antoine Poinsot)
4995c00 chainparams: make deployment configuration available on all test networks (Antoine Poinsot)
df7ed5f chainparams: encapsulate deployment configuration logic (Antoine Poinsot)

Pull request description:

  It's sometimes useful to test a deployment on other networks than regtest. This may be e.g. because regtest lacks a property relevant for the test, or simply because the test aims to be portable while regtest is Bitcoin Core specific.

  This PR makes it possible to set the `-vbparams` and `-testactivationheight` options on any network in unit tests, and on any **test** network as a startup option.

  This is preparatory work for a BIP 54 implementation, but may be useful separately.

ACKs for top commit:
  edilmedeiros:
    utACK 801e3bf
  achow101:
    ACK 801e3bf
  sedited:
    ACK 801e3bf
  instagibbs:
    ACK 801e3bf

Tree-SHA512: 10649dc9bbc70a830bb0c4b1c965de5bf2e6be1a6c2832bdf11e9248dacb4a1f60421b410d0284213e88de6c54218252ae5de423b4c6e659d10bab1cbe7e7e87
7249b37 opt: Skip UTXOs with worse waste, same eff_value (Murch)
5204291 opt: Skip evaluation of equivalent input sets (Murch)
ba1807b coinselection: Track effective_value lookahead (Murch)
fa226ab coinselection: BnB skip exploring high waste (Murch)
7ecea1d coinselection: Track whether BnB completed (Murch)
3ca0f36 coinselection: rewrite BnB in CoinGrinder-style (Murch)
2e73739 coinselection: Track BnB iteration count in result (Murch)

Pull request description:

  This PR rewrites the implementation of the BnB coinselection algorithm
  to skip the duplicate evaluation of previously visited input selections.

  In the original implementation of BnB, the state of the search is
  backtracked by explicitly walking back to the omission branch and then
  testing again. This retests an equivalent candidate set as before, e.g.,
  after backtracking from {ABC}, it would evaluate {AB_}, before trying
  {AB_D}, but {AB_} is equivalent to {AB} which was tested before.

  CoinGrinder tracks the state of the search instead by remembering which
  UTXO was last added and explicitly shifting from that UTXO directly to
  the next, so after {ABC}, it will immediately move on to {AB_D}. We
  replicate this approach here.

  As fewer nodes are visited, this approach will enumerate more possible
  combinations than the original implementation given the same limit for
  iterations.

ACKs for top commit:
  achow101:
    ACK 7249b37
  w0xlt:
    reACK 7249b37

Tree-SHA512: fd5851ceea3a3a4699fc062254fa5438daa4275b4d52325983e63670040cf0ba35112be9e63813d8f30b38993c031f3df343b2152eb8c068d272fbff72d1881a
@pull pull Bot locked and limited conversation to collaborators Jun 4, 2026
@pull pull Bot added the ⤵️ pull label Jun 4, 2026
@pull pull Bot merged commit a5050dd into All-Blockchains:master Jun 4, 2026
1 of 6 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants