30178 Commits

Author SHA1 Message Date
Pieter Wuille
63b06d5523 clusterlin: keep track of active children (optimization)
This means we can iterate over all active dependencies in a
cluster/chunk in O(ntx) time rather than O(ndeps) (*), as the number of
active dependencies in a set of transactions of size is at most ntx-1.

(*) Asymptotically, this is not actually true, as for large transaction
counts, iterating over a BitSet still scales with ntx. In practice
however, where BitSets are represented by a constant number of integers,
it holds.
2026-02-17 09:04:36 -05:00
Pieter Wuille
ae16485aa9 clusterlin: special-case self-merges (optimization)
After a split, if the top part has a dependency on the bottom part, the
first MergeSequence will always perform this merge and then stop. This
is referred to as a self-merge.

We can special case these by detecting self-merges early, and avoiding
the overhead of a full MergeSequence which involves two
PickMergeCandidate calls (a succesful and an unsuccesful one).
2026-02-17 09:04:36 -05:00
Pieter Wuille
3221f1a074 clusterlin: make MergeSequence take SetIdx (simplification)
Future changes will rely on knowing the chunk indexes of the two created
chunks after a split. It is natural to return this information from
Deactivate, which also simplifies MergeSequence.
2026-02-17 09:04:36 -05:00
Pieter Wuille
7194de3f7c clusterlin: precompute reachable sets (optimization)
Instead of computing the set of reachable transactions inside
PickMergeCandidate, make the information precomputed, and updated in
Activate (by merging the two chunks' reachable sets) and Deactivate (by
recomputing).

This is a small performance gain on itself, but also a preparation for
future optimizations that rely on quickly testing whether dependencies
between chunks exist.
2026-02-17 09:04:36 -05:00
Pieter Wuille
6f898dbb8b clusterlin: simplify PickMergeCandidate (optimization)
The current process consists of iterating over the transactions of the
chunk one by one, and then for each figuring out which of its
parents/children are in unprocessed chunks.

Simplify this (and speed it up slightly) by splitting this process into
two phases: first determine the union of all parents/children, and then
find which chunks those belong to.
2026-02-17 09:04:36 -05:00
Pieter Wuille
dcf458ffb9 clusterlin: split up OptimizeStep (refactor) 2026-02-17 09:04:36 -05:00
Pieter Wuille
cbd684a471 clusterlin: abstract out functions from MergeStep (refactor)
This is a simple refactor to make the code more readable.
2026-02-17 09:04:36 -05:00
Pieter Wuille
b75574a653 clusterlin: improve TxData::dep_top_idx type (optimization)
The combined size of TxData::dep_top_idx can be 16 KiB with 64
transactions and SetIdx = uint32_t. Use a smaller type where possible to
reduce memory footprint and improve cache locality of m_tx_data.

Also switch from an std::vector to an std::array, reducing allocation
overhead and indirections.
2026-02-17 09:04:36 -05:00
Pieter Wuille
73cbd15d45 clusterlin: get rid of DepData (optimization)
With the earlier change to pool SetInfo objects, there is little need
for DepData anymore. Use parent/child TxIdxs to refer to dependencies,
and find their top set by having a child TxIdx-indexed vector in each
TxData, rather than a list of dependencies. This makes code for
iterating over dependencies more natural and simpler.
2026-02-17 09:04:36 -05:00
Pieter Wuille
7c6f63a8a9 clusterlin: pool SetInfos (preparation)
This significantly changes the data structures used in SFL, based on the
observation that the DepData::top_setinfo fields are quite wasteful:
there is one per dependency (up to n^2/4), but we only ever need one per
active dependency (of which there at most n-1). In total, the number of
chunks plus the number of active dependencies is always exactly equal to
the number of transactions, so it makes sense to have a shared pool of
SetInfos, which are used for both chunks and top sets.

To that effect, introduce a separate m_set_info variable, which stores a
SetInfo per transaction. Some of these are used for chunk sets, and some
for active dependencies' top sets. Every activation transforms the
parent's chunk into the top set for the new dependency. Every
deactivation transforms the top set into the new parent chunk.

With indexes into m_set_data (SetIdx) becoming bounded by the number of
transactions, we can use a SetType to represent sets of SetIdxs.
Specifically, an m_chunk_idxs is added which contains all SetIdx
referring to chunks. This leads to a much more natural way of iterating
over chunks.

Also use this opportunity to normalize many variable names.
2026-02-17 09:04:36 -05:00
Pieter Wuille
20e2f3e96d scripted-diff: rename _rep -> _idx in SFL
This is a preparation for the next commit, where chunks will no longer
be identified using a representative transaction, but using a set index.
Reduce the load of line changes by doing this rename ahead of time.

-BEGIN VERIFY SCRIPT-
sed --in-place 's/_rep/_idx/g' src/cluster_linearize.h
-END VERIFY SCRIPT-
2026-02-17 09:04:36 -05:00
Pieter Wuille
268fcb6a53 clusterlin: add more Assumes and sanity checks (tests) 2026-02-17 09:04:36 -05:00
Pieter Wuille
d69c9f56ea clusterlin: count chunk deps without loop (optimization)
This small optimization avoids the need to loop over the parents of each
transaction when initializing the dependency-counting structures inside
GetLinearization().
2026-02-17 09:04:36 -05:00
Pieter Wuille
f66fa69ce0 clusterlin: split tx/chunk dep counting (preparation)
This splits the chunk_deps variable in LoadLinearization in two, one for
tracking tx dependencies and one for chunk dependencies. This is a
preparation for a later commit, where chunks won't be identified anymore
by a representative transaction in them, but by a separate index. With
that, it seems weird to keep them both in the same structure if they
will be indexed in an unrelated way.

Note that the changes in src/test/util/cluster_linearize.h to the table
of worst observed iteration counts are due to switching to a different
data set, and are unrelated to the changes in this commit.
2026-02-17 09:04:36 -05:00
Pieter Wuille
900e459778 clusterlin: avoid depgraph argument in SanityCheck (cleanup)
Since the deterministic ordering change, SpanningForestState holds a
reference to the DepGraph it is linearizing. So this means we do not
need to pass it to SanityCheck() as an argument anymore.
2026-02-17 09:04:36 -05:00
Pieter Wuille
666b37970f clusterlin: fix type to count dependencies 2026-02-17 09:04:36 -05:00
merge-script
a7c29df0e5
Merge bitcoin/bitcoin#34552: fees: refactor: separate feerate format from fee estimate mode
c1355493e2c26b613109bfac3dcd898b3acca75a refactor: fees: split fee rate format from fee estimate mode (ismaelsadeeq)
922ebf96ed6674ae7acc6f0cde4d7b064f759834 refactor: move-only: move `FeeEstimateMode` enum to `util/fees.h` (ismaelsadeeq)

Pull request description:

  ### Motivation

  Part of #34075

  - The `FeeEstimateMode` enum was responsible for both selecting the fee estimation algorithm and specifying the fee rate' format.

  ####  Changes in this PR:
     * The `FeeEstimateMode` enum (`UNSET`, `ECONOMICAL`, `CONSERVATIVE`) is moved to a new util/fees.h header.
     * A new `FeeRateFormat `enum (`BTC_KVB`, `SAT_VB`) is introduced in `policy/feerate.h` for feerate formatting.
     * The `CFeeRate::ToString()` method is updated to use `FeeRateFormat`.
     * All relevant function calls have been updated to use the new `FeeRateFormat` enum for formatting and `FeeEstimateMode` for fee estimation mode.

   This refactoring separates these unrelated responsibilities to improve code clarity.

ACKs for top commit:
  l0rinc:
    ACK c1355493e2c26b613109bfac3dcd898b3acca75a
  furszy:
    utACK c1355493e2c26b613109bfac3dcd898b3acca75a
  musaHaruna:
    ACK [c135549](c1355493e2) — reviewed in the context of PR [34075](https://github.com/bitcoin/bitcoin/pull/34075)
  willcl-ark:
    ACK c1355493e2c26b613109bfac3dcd898b3acca75a

Tree-SHA512: 7cbe36350744313d3d688d3fd282a58c441af1818b1e8ad9cddbc911c499a5205f8d4a39c36b21fed60542db1ef763eb69752d141bcef3393bf33c0922018645
2026-02-17 14:15:38 +01:00
MarcoFalke
fa48d42163
test: Stricter unit test
Now that the previous commit fixed a unit test bug, make the test
stricter, to prevent this issue from happening again in the future.
2026-02-17 12:55:28 +01:00
MarcoFalke
fa626bd143
util: Remove brittle and confusing sp::Popen(std::string) 2026-02-17 12:55:26 +01:00
Fabian Jahr
3d7ab7ecb7
rpc, test: Address feedback from #29668 2026-02-17 12:44:23 +01:00
Fabian Jahr
a9a3b29dd6
index: Check availability of undo data for indices 2026-02-17 12:44:21 +01:00
Hennadii Stepanov
746d8cddc1
qt: Use plurals where necessary 2026-02-17 08:32:57 +00:00
MarcoFalke
fa5672dcaf
refactor: [gui] Use SettingTo<int64_t> over deprecated SettingToInt
This refactor does not change any behavior.

Also, remove the now-unused deprecated aliases.
2026-02-16 16:20:11 +01:00
ANAVHEOBA
afea2af139
net: reduce log level for PCP/NAT-PMP NOT_AUTHORIZED failures
Users running on home networks with routers that don't support PCP (Port
Control Protocol) or NAT-PMP port mapping receive frequent warning-level
log messages every few minutes:

  "pcp: Mapping failed with result NOT_AUTHORIZED (code 2)"

This is expected behavior for many consumer routers that have PCP
disabled by default, not an actionable error.

Add explicit constants for the NOT_AUTHORIZED result code (value 2)
for both NAT-PMP and PCP protocols. Log the first NOT_AUTHORIZED
failure at warning level for visibility, then downgrade subsequent
occurrences to LogDebug to avoid log noise. Other failure types
continue to warn unconditionally.

Fixes #34114

Co-authored-by: willcl-ark <will@256k1.dev>
2026-02-16 10:20:56 +00:00
MarcoFalke
fac3ecaf69
rpc: Properly parse -rpcworkqueue/-rpcthreads
Also, remove the trailing unnecessary \n from the two logs.
2026-02-16 09:54:47 +01:00
MarcoFalke
faee36f63b
util: Add SettingTo<Int>() and GetArg<Int>()
Redirect:
* SettingToInt to SettingTo<int64_t>, and
* GetIntArg to GetArg<int64_t>
2026-02-16 09:52:28 +01:00
Hennadii Stepanov
6df4a045f7
qt: Replace three dots with ellipsis 2026-02-14 15:53:32 +00:00
merge-script
84e826ddc1
Merge bitcoin/bitcoin#34511: test: fully reset the state of CConnman in tests
2cb7e99deee1017a6edd94d82de556895138361d test: also reset CConnman::m_private_broadcast in tests (Vasil Dimov)
91b7c874e2b1479ed29f067cd1bef7724aabd951 test: add ConnmanTestMsg convenience method Reset() (Vasil Dimov)

Pull request description:

  Member variables of `CConnman::m_private_broadcast` (introduced in
  https://github.com/bitcoin/bitcoin/pull/29415) could influence the tests
  which creates non-determinism if the same instance of `CConnman` is used
  for repeated test iterations.

  So, reset the state of `CConnman::m_private_broadcast` from
  `ConnmanTestMsg::Reset()`. Currently this affects the fuzz tests
  `process_message` and `process_messages`.

  Reported in https://github.com/bitcoin/bitcoin/issues/34476#issuecomment-3849088794

ACKs for top commit:
  maflcko:
    review ACK 2cb7e99deee1017a6edd94d82de556895138361d 🚙
  Crypt-iQ:
    tACK 2cb7e99deee1017a6edd94d82de556895138361d
  frankomosh:
    Code Review ACK 2cb7e99deee1017a6edd94d82de556895138361d
  brunoerg:
    code review ACK 2cb7e99deee1017a6edd94d82de556895138361d

Tree-SHA512: 0f4b114542da8dc611689457ce67034c15cbfe409b006b2db72bc74078ee9513f5ce3d0e6e67d37c127cfa0a5170fe72fe3ea45ce2a61d45a358dd11bd1881f8
2026-02-13 11:17:26 +00:00
merge-script
309c51d89d
Merge bitcoin/bitcoin#34546: kernel: Avoid duplicating symbols in the kernel library
eafd530d20326a101be672243de68a67161ef83e kernel: avoid potential duplicate object in shared library/binary (Cory Fields)
24c3b47010036d67e6d777d9aa37ae3ef8146254 build: add kernel-specific warnings (Cory Fields)

Pull request description:

  This is a revival of https://github.com/bitcoin/bitcoin/pull/31807

  Introduces the [-Wunique-object-duplication](https://clang.llvm.org/docs/DiagnosticsReference.html#wunique-object-duplication) warning flag available in clang-21 for usage when building the kernel library. It warns of potential duplicate objects in shared libraries. REDUCE_EXPORTS needs to be ON to trigger it.

  Though we have a C API now that manages exporting symbols, I think it is prudent to also avoid any duplicate symbols on the internal c++ side in case we ever to decide to expose some of its headers. It also not clear that all linkers would handle these cases correctly even in the current internal usage.

ACKs for top commit:
  fanquake:
    ACK eafd530d20326a101be672243de68a67161ef83e
  hebasto:
    ACK eafd530d20326a101be672243de68a67161ef83e.

Tree-SHA512: 81961b50f0268dbe076497e130857f5b4b9151c748d107ec15158d1511dd25bce745e0beeb127b9cea51cb2edd78032735600606a75f7ff8a3fd572acced42e0
2026-02-13 11:11:14 +00:00
Pol Espinasa
331a5279d2
wallet, rpc:remove settxfee and paytxfee 2026-02-13 10:52:25 +01:00
Cory Fields
eafd530d20
kernel: avoid potential duplicate object in shared library/binary
Fixes warning and potential bug whereby init_flag may exist in both
libbitcoinkernel as well as a downstream user, as opposed to being shared as
intended.

src/support/lockedpool.h:224:31:
warning: 'init_flag' may be duplicated when built into a shared library: it is mutable, has hidden visibility, and external linkage [-Wunique-object-duplication]
2026-02-13 08:50:50 +01:00
Cory Fields
24c3b47010
build: add kernel-specific warnings
In some cases, we'll want to be more aggressive or care about different things
when building the kernel. In this case, a warning is added for symbols which
may be duplicated between the kernel and downstream users.

This warning was introduced in clang 21, which is not yet the minimum
supported compiler version. REDUCE_EXPORTS needs to be ON to trigger it.
2026-02-13 08:50:17 +01:00
Andrew Toth
cae6d895f8
fuzz: add target for CoinsViewOverlay
Co-authored-by: l0rinc <pap.lorinc@gmail.com>
2026-02-12 21:31:23 -05:00
Andrew Toth
86eda88c8e
fuzz: move backend mutating block to end of coins_view
Refactor TestCoinsView() to move code that directly modifies
backend_coins_view to the end of the function.
This prepares for a CoinsViewOverlay fuzz target that asserts
the backend_coins_view is not mutated by any methods before
BatchWrite is called.

Co-authored-by: l0rinc <pap.lorinc@gmail.com>
2026-02-12 21:31:23 -05:00
Andrew Toth
89824fb27b
fuzz: pass coins_view_cache to TestCoinsView in coins_view
Refactor TestCoinsView() to accept the cache as a parameter instead of
creating it internally. This prepares for adding a CoinsViewOverlay
fuzz target that needs to pass in a different cache type.

This is a non-functional change.

Co-authored-by: l0rinc <pap.lorinc@gmail.com>
2026-02-12 21:31:23 -05:00
Andrew Toth
73e99a5966
coins: don't mutate main cache when connecting block
Use `CoinsViewOverlay` when connecting blocks in `ConnectTip`.

Add a new integration test to verify that using
CoinsViewOverlay does not mutate the main cache
during validation for an invalid block.

Co-authored-by: l0rinc <pap.lorinc@gmail.com>
2026-02-12 21:31:23 -05:00
Andrew Toth
67c0d1798e
coins: introduce CoinsViewOverlay
Introduce `CoinsViewOverlay`, a `CCoinsViewCache` subclass that reads
coins without mutating the underlying cache via `FetchCoin()`.

Use `PeekCoin()` to look up a Coin through a stack of `CCoinsViewCache` layers without populating parent caches. This prevents the main cache from caching inputs pulled from disk for a block that has not yet been fully validated. Once `Flush()` is called on the view, these inputs will be added as spent to `coinsCache` in the main cache via `BatchWrite()`.

This is the foundation for async input fetching, where worker threads must not
mutate shared state.

Co-authored-by: l0rinc <pap.lorinc@gmail.com>
2026-02-12 21:31:23 -05:00
Andrew Toth
69b01af0eb
coins: add PeekCoin()
Introduce a helper to look up a Coin through a stack of CCoinsViewCache layers without populating parent caches.

This is useful for ephemeral views (e.g. during ConnectBlock) that want to avoid polluting CoinsTip() when validating invalid blocks.

Co-authored-by: l0rinc <pap.lorinc@gmail.com>
Co-authored-by: Pieter Wuille <pieter@wuille.net>
Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
2026-02-12 21:31:23 -05:00
Sjors Provoost
9453c15361 ipc mining: break compatibility with existing clients (version bump)
This increments the field number of the `Init.makeMining` method and makes the
old `makeMining` method return an error, so existing IPC mining clients not
using the latest schema file will get an error and not be able to access the
Mining interface.

Normally, there shouldn't be a need to break compatibility this way, but the
mining interface has evolved a lot since it was first introduced, with old
clients using the original methods less stable and performant than newer
clients. So now is a good time to introduce a cutoff, drop deprecated methods,
and stop supporting old clients which can't function as well.

Bumping the field number is also an opportunity to make other improvements that
would be awkward to implement compatibly, so a few of these were implemented in
commits immediately preceding this one.

Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
2026-02-12 03:34:08 +01:00
Sjors Provoost
70de5cc2d2 ipc mining: pass missing context to BlockTemplate methods (incompatible schema change)
Adding a context parameter ensures that these methods are run in
their own thread and don't block other calls. They were missing
for:

- createNewBlock()
- checkBlock()

The missing parameters were first pointed out by plebhash in
https://github.com/bitcoin/bitcoin/issues/33575#issuecomment-3383290115 and
adding them should prevent possible performance problems and lockups,
especially with #34184 which can make the createNewBlock method block for a
long time before returning. It would be straightforward to make this change in
a backward compatible way
(https://github.com/bitcoin/bitcoin/pull/34184#discussion_r2770232149) but nice
to not need to go through the trouble.

Warning: This is an intermediate, review-only commit. Binaries built from it
should not be distributed or used to connect to other clients or servers. It
makes incompatible changes to the `mining.capnp` schema without updating the
`Init.makeMining` version, causing binaries to advertise support for a schema
they do not actually implement. Mixed versions may therefore exchange garbage
requests/responses instead of producing clear errors. The final commit in this
series bumps the mining interface number to ensure mismatches are detected.

git-bisect-skip: yes

Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
2026-02-12 03:34:08 +01:00
Ryan Ofsky
2278f017af ipc mining: remove deprecated methods (incompatible schema change)
This change removes deprecated methods from the ipc mining interface.

Warning: This is an intermediate, review-only commit. Binaries built from it
should not be distributed or used to connect to other clients or servers. It
makes incompatible changes to the `mining.capnp` schema without updating the
`Init.makeMining` version, causing binaries to advertise support for a schema
they do not actually implement. Mixed versions may therefore exchange garbage
requests/responses instead of producing clear errors. The final commit in this
series bumps the mining interface number to ensure mismatches are detected.

git-bisect-skip: yes
2026-02-11 21:34:08 -05:00
Ryan Ofsky
c6638fa7c5 ipc mining: provide default option values (incompatible schema change)
This change copies default option values from the C++ mining interface to the
Cap'n Proto interface. Currently, no capnp default values are set, so they are
implicitly all false or 0, which is inconvenient for the rust and python
clients and inconsistent with the C++ client.

Warning: This is an intermediate, review-only commit. Binaries built from it
should not be distributed or used to connect to other clients or servers. It
makes incompatible changes to the `mining.capnp` schema without updating the
`Init.makeMining` version, causing binaries to advertise support for a schema
they do not actually implement. Mixed versions may therefore exchange garbage
requests/responses instead of producing clear errors. The final commit in this
series bumps the mining interface number to ensure mismatches are detected.

git-bisect-skip: yes
2026-02-11 21:34:08 -05:00
Ryan Ofsky
a4603ac774 ipc mining: declare constants for default field values
This commit only declares constants without using them. They will be applied in
seperate commit since changing struct default field values in cap'n proto is
not backwards compatible.
2026-02-11 21:34:08 -05:00
Ryan Ofsky
df53a3e5ec rpc refactor: stop using deprecated getCoinbaseCommitment method
There should be no change in behavior

Co-authored-by: Sjors Provoost <sjors@sprovoost.nl>
2026-02-11 21:34:08 -05:00
Ryan Ofsky
0b4cd08fcd
Merge bitcoin/bitcoin#33965: mining: fix -blockreservedweight shadows IPC option
b623fab1ba87ea93dd7e302b8c927e55f2036173 mining: enforce minimum reserved weight for IPC (Sjors Provoost)
d3e49528d479613ebe50088d530a621861463fa4 mining: fix -blockreservedweight shadows IPC option (Sjors Provoost)
418b7995ddfbc88764f1f0ceabf8993808b08bd8 test: have mining template helpers return None (Sjors Provoost)

Pull request description:

  Also enforce `MINIMUM_BLOCK_RESERVED_WEIGHT` for IPC clients.

  The `-blockreservedweight` startup option should only affect RPC code, because IPC clients (currently) do not have a way to signal their intent to use the node default (the `BlockCreateOptions` struct defaults merely document a recommendation for client software).

  Before this PR however, if the user set `-blockreservedweight` then `ApplyArgsManOptions` would cause the `block_reserved_weight` option passed by IPC clients to be ignored. _Users who don't set this value were not affected._

  Fix this by making BlockCreateOptions::block_reserved_weight an std::optional.

  Internal interface users, such as the RPC call sites, don't set a value so -blockreservedweight is used. Whereas IPC clients do set a value which is no longer ignored.

  Test coverage is added, with a preliminary commit that refactors the `create_block_template` and `wait_next_template` helpers.

  `mining_basic.py` already ensured `-blockreservedweight` is enforced by mining RPC methods. The second commit adds coverage for Mining interface IPC clients. It also verifies that `-blockreservedweight` has no effect on them.

  The third commit enforces `MINIMUM_BLOCK_RESERVED_WEIGHT` for IPC clients. Previously lower values were quietly clamped.

  ---

  Merge order preference: #34452 should ideally go first.

ACKs for top commit:
  sedited:
    Re-ACK b623fab1ba87ea93dd7e302b8c927e55f2036173
  ryanofsky:
    Code review ACK b623fab1ba87ea93dd7e302b8c927e55f2036173. Was rebased and test split up and comment updated since last review.
  ismaelsadeeq:
    ACK b623fab1ba87ea93dd7e302b8c927e55f2036173

Tree-SHA512: 9e651a520d8e4aeadb330da86788744b6ecad8060fa21d50dc8e6012a60083e7b262aaa08a64676b9ef18ba65b651bc1272d8383d184030342e4c0f2c6a9866d
2026-02-11 21:22:28 -05:00
Andrew Toth
557260ca14
rpc: Add abortprivatebroadcast
Co-authored-by: l0rinc <pap.lorinc@gmail.com>
2026-02-11 19:46:19 -05:00
Andrew Toth
996f20c18a
rpc: Add getprivatebroadcastinfo
Co-authored-by: Vasil Dimov <vd@freebsd.org>
2026-02-11 19:46:12 -05:00
Andrew Toth
5e64982541
net: Add PrivateBroadcast::GetBroadcastInfo
Co-authored-by: Daniela Brozzoni <danielabrozzoni@protonmail.com>
Co-authored-by: l0rinc <pap.lorinc@gmail.com>
2026-02-11 19:46:12 -05:00
merge-script
55c49ff8f4
Merge bitcoin/bitcoin#34143: build: Prevent system header fallback and include path pollution
65134c7e5f99500baed18d575b576e33a6294ecf depends: Prefix include path for headers-only `systemtap` package (Hennadii Stepanov)
94a692b6aa09d2e5df97bbc9cc810854818f9333 cmake: Add missed `USDT::headers` (Hennadii Stepanov)
b5375c44ed16ed6aae3d46ac6316b3981330f100 depends: Prefix include path for headers-only `boost` package (Hennadii Stepanov)
d73378ffcca2de43a79c4903221e8164cf256469 cmake: Add missed `Boost::headers` (Hennadii Stepanov)

Pull request description:

  Currently, header-only dependencies in the depends subsystem are installed into the standard `include/` subdirectory. This inadvertently exposes their headers to the compiler via `-I` flags brought in by other dependencies (e.g., `libevent` or `sqlite`). This "include path pollution" masks missing dependencies in the build configuration. While the build might succeed by accident due to this overlap, it creates a fragile state. If the overlapping library is removed, the build will break, or, worse, the compiler may silently fall back to the host system's default paths (e.g., `/usr/include`).

  This PR improves build system security and hygiene by enforcing strict, distinguished include paths for header-only dependencies. The missing dependencies revealed by this change (`Boost::headers`, `USDT::headers`) have been fixed in separate commits.

ACKs for top commit:
  theuni:
    re-ACK 65134c7e5f99500baed18d575b576e33a6294ecf
  fanquake:
    ACK 65134c7e5f99500baed18d575b576e33a6294ecf

Tree-SHA512: 41667b46c3bd2f872951a5651b30f7d1468f49f1265196b7868233ed44b2eb0e33f1f69a1af348b55f07a8d1f594e276eb49b724e80b8eae85aed1c9bacae197
2026-02-11 17:43:10 +00:00
merge-script
c134b1a4bc
Merge bitcoin/bitcoin#34257: txgraph: deterministic optimal transaction order
6f113cb1847c6890f1fbd052ff7eb8ea41ccafc5 txgraph: use fallback order to sort chunks (feature) (Pieter Wuille)
0a3351947e736c646a6dfffef24b83d003c569e7 txgraph: use fallback order when linearizing (feature) (Pieter Wuille)
fba004a3df02d8d5d47f1ad0bb1ccbfde01bb2af txgraph: pass fallback_order to TxGraph (preparation) (Pieter Wuille)
941c432a4637efd4e5040259f47f2bfed073af7c txgraph test: subclass TxGraph::Ref like mempool does (preparation) (Pieter Wuille)
39d0052cbf478a729ae0288262003bba9c12690b clusterlin: make optimal linearizations deterministic (feature) (Pieter Wuille)
8bfbba32077cb8682208ef31748a10562be027db txgraph: sort distinct-cluster chunks by equal-feerate-prefix size (feature) (Pieter Wuille)
e0bc73ba9270b860d81e479a7bddcff8cfd8bfb6 clusterlin: sort tx in chunk by feerate and size (feature) (Pieter Wuille)
6c1bcb2c7c1a0017562e99195d74c3a05444633b txgraph: clear cluster's chunk index in ~Ref (preparation) (Pieter Wuille)
7427c7d0983050543f1fc7863121d8e2bf4b1511 txgraph: update chunk index on Compact (preparation) (Pieter Wuille)
3ddafceb9afd9d493b927bc91dae324225ed8e32 txgraph: initialize Ref in AddTransaction (preparation) (Pieter Wuille)

Pull request description:

  Part of #30289.

  TxGraph's fundamental responsibility is deciding the order of transactions in the mempool. It relies on the `cluster_linearize.h` code to optimize it, but there can and often will be many different orderings that are essentially equivalent from a quality perspective, so we have to pick one. At a high level, the solution will involve one or more of:
  * Deciding based on **internal identifiers** (`Cluster::m_sequence`, `DepGraphIndex`). This is very simple, but risks leaking information about transaction receive order.
  * Deciding **randomly**, which is private, but may interfere with relay expectations, block propagation, and ability to monitor network behavior.
  * Deciding **based on txid**, which is private and deterministic, but risks incentivizing grinding to get an edge (though we haven't really seen such behavior).
  * Deciding **based on size** (e.g. prefer smaller transactions), which is somewhat related to quality, but not unconditionally (depending on mempool layout, the ideal ordering might call for smaller transactions first, last, or anywhere in between). It's also not a strong ordering as there can be many identically-sized transactions. However, if it were to encourage grinding behavior, incentivizing smaller transactions is probably not a bad thing.

  As of #32545, the current behavior is primarily picking randomly, though inconsistently, as some code paths also use internal identifiers and size. #33335 sought to change it to use random (preferring size in a few places), with the downsides listed above.

  This PR is an alternative to that, which changes the order to tie-break based on size everywhere possible, and use lowest-txid-first as final fallback. This is fully deterministic: for any given set of mempool transactions, if all linearized optimally, the transaction order exposed by TxGraph is deterministic.

  The transactions within a chunk are sorted according to:
  1. `PostLinearize` (which improves sub-chunk order), using an initial linearization created using the rules 2-5 below.
  2. Topology (parents before children).
  3. Individual transaction feerate (high to low)
  4. Individual transaction weight (small to large)
  5. Txid (low to high txid)

  The chunks within a cluster are sorted according to:
  1. Topology (chunks after their dependencies)
  2. Chunk feerate (high to low)
  3. Chunk weight (small to large)
  4. Max-txid (chunk with lowest maximum-txid first)

  The chunks across clusters are sorted according to:
  1. Feerate (high to low)
  2. Equal-feerate-chunk-prefix weight (small to large)
  3. Max-txid (chunk with lowest maximum-txid first)

  The equal-feerate-chunk-prefix weight of a chunk C is defined as the sum of the weights of all chunks in the same cluster as C, with the same feerate as C, up to and including C itself, in linearization order (but excluding such chunks that appear after C). This is a well-defined approximation of sorting chunks from small to large across clusters, while remaining consistent with intra-cluster linearization order.

ACKs for top commit:
  ajtowns:
    reACK 6f113cb1847c6890f1fbd052ff7eb8ea41ccafc5 it was good before and now it's better
  instagibbs:
    ACK 6f113cb1847c6890f1fbd052ff7eb8ea41ccafc5
  marcofleon:
    light crACK 6f113cb1847c6890f1fbd052ff7eb8ea41ccafc5

Tree-SHA512: 16dc43c62b7e83c81db1ee14c01e068ae2f06c1ffaa0898837d87271fa7179dd98baeb74abc9fe79220e01fdba6876defe60022c2b72badc21d770644a0fe0ac
2026-02-11 17:40:38 +00:00