Commit Graph

47604 Commits

Author SHA1 Message Date
MarcoFalke
fa0677d131 refactor: Use SpanReader over DataStream
This refactor does not change behavior. However, it avoids a vector
copy, which can lead to a minimal speed-up of 1%-5%, depending on the
call-site. This is mostly relevant for the fuzz tests and utils that
read large blobs of data (like a full block).
2026-02-06 07:56:57 +01:00
MarcoFalke
fad3eb3956 refactor: Use SpanReader over DataStream
The mutable temporary strValue can be re-used to apply the obfuscation,
which allows to avoid a redundant copy of the value.
2026-02-02 18:42:44 +01:00
MarcoFalke
fa06e26764 refactor: [qt] Use SpanReader to avoid two vector copies 2026-02-02 18:41:38 +01:00
MarcoFalke
fabd4d2e2e refactor: Avoid UB in SpanReader::ignore
Currently std::span::subspan is called without checking the size first.

This is UB, unless the std lib is hardened.

With a hardened stdlib, the program aborts:

> include/c++/v1/span:512: libc++ Hardening assertion __offset <= size()
> failed: span<T>::subspan(offset, count): offset out of range

Fix the UB and the abort by using the implementation from DataStream,
which throws when hitting end-of-data.

This commit should not change any behavior, because the UB is currently
unreachable. Also, the newly added throw should properly be caught by
any code that calls any streams function.
2026-02-02 18:41:03 +01:00
MarcoFalke
fa20bc2ec2 refactor: Use empty() over eof() in the streams interface
End-of-file does not really make sense for streams that wrap buffers. So
replace it by the equivalent empty() checks.
2026-02-02 17:55:10 +01:00
MarcoFalke
fa879db735 test: Read debug log for self-checking comment
The DataStream comment was a bit stale, because it was using
CDataStream.

Fix it by using assert_debug_log for a self-documenting and
self-checking test code.
2026-02-02 16:38:12 +01:00
merge-script
9f8764c814 Merge bitcoin/bitcoin#34475: ci: Treat SHA1 LLVM signing key as warning
3c8f5e48f7 ci: Treat SHA1 LLVM signing key as warning (will)

Pull request description:

  The current SHA1 LLVM signing key is considered not secure since
  2026-02-01T00:00:00Z which makes this run fail when downloading
  packages.

  See: https://github.com/llvm/llvm-project/issues/153385

  Apply the fix from the issue to temporarily to treat this error as a
  warning, until the upstream key can be updated.

  This PR should be reverted once the upstream key is updated.

ACKs for top commit:
  hebasto:
    ACK 3c8f5e48f7, tested by running the "iwyu" CI job locally on Ubuntu 25.10 after burning all podman's caches.

Tree-SHA512: fbccf98bfd73cb338670f1ceea994d277d746acbc88b9b90a403d9a59d82abda0f3ba34c4d484b70926340c2d0c873259f930c36ccd4f9d18bb1d22d49ee70c4
2026-02-02 12:32:27 +00:00
will
3c8f5e48f7 ci: Treat SHA1 LLVM signing key as warning
The current SHA1 LLVM signing key is considered not secure since
2026-02-01T00:00:00Z which makes this run fail when downloading
packages.

See: https://github.com/llvm/llvm-project/issues/153385

Apply the fix from the issue to temporarily to treat this error as a
warning, until the upstream key can be updated.

This PR should be reverted once the upstream key is updated.
2026-02-02 11:55:01 +00:00
merge-script
5cb4cf9b42 Merge bitcoin/bitcoin#34036: contrib: update macOS SDK to Xcode-26.1.1-17B100
a89e1618dd contrib: update macOS SDK to Xcode-26.1.1-17B100 (fanquake)
57a778ed25 depends: use -Xclang -fno-cxx-modules in macOS cross build (fanquake)

Pull request description:

  Updates the macOS SDK used for Guix builds to `Xcode-26.1.1-17B100`.
  Closes #34034.

ACKs for top commit:
  hebasto:
    ACK a89e1618dd.
  sedited:
    ACK a89e1618dd
  janb84:
    concept ACK a89e1618dd

Tree-SHA512: 4f8f9afee6fca594a0d30fbb3c150f5ed120b40f707954678ff69951bc806acc154aed4b5986d8642160f7b37523933c87c5734f296ff881555093188e29549e
2026-02-02 10:45:06 +00:00
merge-script
41034a032f Merge bitcoin/bitcoin#34396: fuzz: pull the latest FuzzedDataProvider.h from upstream
dfb9364609 fuzz: pull latest FuzzedDataProvider.h from upstream (b-l-u-e)

Pull request description:

  Pulls down the latest version of https://github.com/llvm/llvm-project/blob/main/compiler-rt/include/fuzzer/FuzzedDataProvider.h, after https://github.com/llvm/llvm-project/pull/177794 was merged upstream.

ACKs for top commit:
  fanquake:
    ACK dfb9364609 - updated the PR description.

Tree-SHA512: 36d003a1d92158537811d044bf4b79d63f0ec79e5b0da9e26a73a869c81578f9597ababcb79bb1949689db506c25341255c59979214ee28343fa08f85e2c3466
2026-02-02 09:55:46 +00:00
merge-script
ff09583928 Merge bitcoin/bitcoin#34432: test: Turn ElapseSteady into SteadyClockContext
facb2aab26 test: Turn ElapseSteady into SteadyClockContext (MarcoFalke)

Pull request description:

  `ElapseSteady` was introduced a while back, but is only used in one place. It makes more sense if this were a context manager, so that mocktime does not leak from one test into the next.

  So turn it into a context manager, rename it and allow easy time advancement via e.g. `steady_ctx += 1h`.

ACKs for top commit:
  l0rinc:
    ACK facb2aab26
  ismaelsadeeq:
    utACK facb2aab26
  sedited:
    ACK facb2aab26

Tree-SHA512: 1df9cc9685d9be4d3ab8deafd99ac1a5ff752064ae54b83bacd6f44ba2c198b091558a306d49d8b1e2200ac669e95915cc792d589fb3a63b2bef7891d325a1e0
2026-02-02 10:44:55 +01:00
merge-script
81e67d9aa1 Merge bitcoin/bitcoin#34179: refactor: Enable transparent lookup for setBlockIndexCandidates to remove const_cast
3bd98b4508 refactor: use transparent comparator for setBlockIndexCandidates lookups (joaonevess)

Pull request description:

  ### Rationale

  This PR improves code safety by removing a `const_cast` in `src/validation.cpp`.

  Currently, `setBlockIndexCandidates` stores mutable `CBlockIndex*`. However, validation logic (like `CVerifyDB`) often holds `const CBlockIndex*`. Previously, checking for existence in the set required casting away constness. While currently benign, this bypasses compiler safety checks and could mask accidental modifications in future refactors.

  ### Description

  1.  **Enable Heterogeneous Lookup:** Added `using is_transparent = void;` to `CBlockIndexWorkComparator` in `src/node/blockstorage.h`. This allows the `std::set` to natively accept `const CBlockIndex*` for lookup (utilizing C++14 heterogeneous lookup).
  2.  **Remove Cast:** Removed the now unnecessary `const_cast<CBlockIndex*>` in `src/validation.cpp`, allowing the compiler to strictly enforce const-correctness.

  ### Notes

  - **Refactoring only:** No behavioral change.
  - **Verification:** `validation_tests` and `blockmanager_tests` pass.

ACKs for top commit:
  maflcko:
    review ACK 3bd98b4508 🚪
  frankomosh:
    ACK 3bd98b4508. Good use of transparent comparator to eliminate `const_cast` in this specific code path.
  sedited:
    ACK 3bd98b4508

Tree-SHA512: 0f76bdce2a54b759dfec99633afce1e95586e62f4057ecf1e82eed1a073eb8ecb2d659ccbf28a7a139f0aa09a30f058ac6966cafdfbf1f2ee878fa2d86b2c487
2026-02-02 08:49:02 +01:00
merge-script
ec70bead5e Merge bitcoin/bitcoin#34433: script: remove unused SCRIPT_ERR_LAST
51abf7d15b script: remove unused SCRIPT_ERR_LAST (Antoine Poinsot)

Pull request description:

  It was introduced in ab9edbd6b6 and never used since. It seems it might have been intended to be exposed as part of a public library interface, which has since been superseded.

  The only call site uses SCRIPT_ERR_ERROR_COUNT directly.

ACKs for top commit:
  billymcbip:
    tACK 51abf7d15b
  sedited:
    ACK 51abf7d15b
  theStack:
    ACK 51abf7d15b

Tree-SHA512: 983b0523b2b5eba57732223af22746c9f29e4759d23366147825d1101f94a9b10c385f305d1425c439a4e29ab28f5a9245691ba6dc31a13f260d3d03b0bf1885
2026-02-02 08:16:43 +01:00
merge-script
08547ee1b0 Merge bitcoin/bitcoin#34443: validation: follow-up nits for lock-free IsInitialBlockDownload()
eeb4d28148 validation: follow-up nits for lock-free `IsInitialBlockDownload()` (Lőrinc)

Pull request description:

  Innocent follow-up to #34253:
  * Add `AssertLockHeld(cs_main)` to `ChainstateManager::UpdateIBDStatus()` given it's already annotated with `EXCLUSIVE_LOCKS_REQUIRED(cs_main)`.
  * Fix outdated comment about constness of `ChainstateManager::IsInitialBlockDownload()` (compilation and build passes without it).
  * And since we're touching it, we might as well mark `ChainstateManager::IsInitialBlockDownload()` as `noexcept` now.

ACKs for top commit:
  davidgumberg:
    crACK eeb4d28148
  sedited:
    ACK eeb4d28148
  mzumsande:
    utACK eeb4d28148

Tree-SHA512: 110cf5b03dc4f4cf6e61563ef69da6368e43009cf0fe1b10870cb4f55203c347444c8623aae7357d0ee5ba3f4b10da535b440a5871c9c5a4f7f8f88c2accd1f1
2026-02-02 07:57:34 +01:00
merge-script
8bb77f348e Merge bitcoin/bitcoin#34455: ci, iwyu: Fix warnings in src/univalue and treat them as errors
1bf3842223 ci, iwyu: Fix warnings in `src/univalue` and treat them as errors (Hennadii Stepanov)

Pull request description:

  This PR continues the ongoing effort to enforce IWYU warnings.

  See [Developer Notes](https://github.com/bitcoin/bitcoin/blob/master/doc/developer-notes.md#using-iwyu).

ACKs for top commit:
  maflcko:
    review ACK 1bf3842223 🦇
  sedited:
    ACK 1bf3842223

Tree-SHA512: e2b7ad7b318c6c78de9a6b416a2bcb6da3ec9f4f060590db2b4f5f3a9a167891ac60c68efccea889df806f53b803c98303eed1fc24682257a9c37844ee2ee55d
2026-01-31 15:05:44 +01:00
Hennadii Stepanov
1bf3842223 ci, iwyu: Fix warnings in src/univalue and treat them as errors 2026-01-31 10:41:50 +00:00
merge-script
3d180d3c7f Merge bitcoin/bitcoin#34462: util: Drop *BSD headers in batchpriority.cpp
07af50f789 util: Drop *BSD headers in `batchpriority.cpp` (Hennadii Stepanov)

Pull request description:

  Currently, there are issues with headers in `batchpriority.cpp`:
  1. `SCHED_BATCH` is not defined on all supported *BSD platforms.
  2. `pthread.h` is necessary on other platforms.

  This PR addresses both issues and fixes other includes.

ACKs for top commit:
  maflcko:
    review ACK 07af50f789 🤺
  w0xlt:
    crACK 07af50f789

Tree-SHA512: 388f627e9d9c8b80834ba562034cd6aa44ba37d9156e13cdd6cbcfa93b19fcbf3222228d671784ca363e06fda3c978778f62f4530c3eb4ae3ff96adf91c2d789
2026-01-31 11:32:34 +01:00
merge-script
1eed88a3ec Merge bitcoin/bitcoin#34460: iwyu: Update mappings
9c839aa9e3 iwyu: Document mappings for libc symbols (Hennadii Stepanov)
91824646c5 iwyu: Add temporary mapping to work around upstream bug (Hennadii Stepanov)
37de7d1910 iwyu: Drop backported mapping (Hennadii Stepanov)

Pull request description:

  This PR:
  1. Removes mappings that have been [backported](https://github.com/include-what-you-use/include-what-you-use/pull/1706) upstream.
  2. Adds a new temporary mapping to work around upstream [issue](https://github.com/include-what-you-use/include-what-you-use/issues/1616).
  3. Document the existing mappings for libc symbols.

ACKs for top commit:
  maflcko:
    lgtm ACK 9c839aa9e3
  sedited:
    ACK 9c839aa9e3

Tree-SHA512: 691fd9fc6798951ca1a621ee607a617ebef2ed2f43196465c78c6cd7a5ea7f0f0e876e68cd54653edf9b6762ae5fdb704469a1524a5f6f1ab8b0eedbff65cc28
2026-01-31 09:57:38 +01:00
merge-script
101daa4163 Merge bitcoin/bitcoin#34338: ci, iwyu: Fix warnings in src/zmq and treat them as errors
efcbf79448 ci, iwyu: Fix warnings in `src/zmq` and treat them as errors (Hennadii Stepanov)

Pull request description:

  This PR [continues](https://github.com/bitcoin/bitcoin/pull/33725#issuecomment-3466897433) the ongoing effort to enforce IWYU warnings.

  See [Developer Notes](https://github.com/bitcoin/bitcoin/blob/master/doc/developer-notes.md#using-iwyu).

  Additionally, this adds a new include category to `src/.clang-format`.

ACKs for top commit:
  maflcko:
    review ACK efcbf79448 🐼
  janb84:
    re ACK efcbf79448
  sedited:
    ACK efcbf79448

Tree-SHA512: 5396719d4a9f7fff7b57be7284af5b25ff055edbaba417187e29106c9e310f19f361fbeea74e2448ef1e883a8658028762a38664858a863e5019fcb0cbb346a2
2026-01-31 09:37:03 +01:00
b-l-u-e
dfb9364609 fuzz: pull latest FuzzedDataProvider.h from upstream 2026-01-31 08:45:10 +03:00
Ava Chow
705705e5b1 Merge bitcoin/bitcoin#33701: test: add case where TOTAL_TRIES is exceeded yet solution remains
b189a34557 test: add case where `TOTAL_TRIES` is exceeded yet solution remains (yancy)

Pull request description:

  Show that `CoinGrider` halts searching when the number of attempts exceeds `TOTAL_TRIES`.  To do so, show that a solution is found, then add one more entry to the same set of inputs.  Since the search orders by `effective_value`, the solution is constructed such that only values with the lowest `effective_value` have the least weight.  Only the lowest weight values will not exceed the `max_selection_weight`. Therefore, `CoinGrinder` will not evaluate all lowest weight solutions together before exceeding `TOTAL_TRIES` since they are last found.

  This test case was inspired by a similar test for `BnB` currently named `bnb_test`.

ACKs for top commit:
  frankomosh:
    Code review ACK b189a34
  achow101:
    ACK b189a34557
  murchandamus:
    ACK b189a34557

Tree-SHA512: 1df0b6e29ae219edbeed14cfa97f0ad4688d6bf97ed946719ba3c3b69e004f3dee82991578eb5aceb554914b70c5b68feff9e321283c1fc8bc0fedf08df2cb4c
2026-01-30 18:26:07 -08:00
Ava Chow
88f8029835 Merge bitcoin/bitcoin#34100: doc: Use multipath descriptors in descriptors.md and linked test
552bc82b17 doc: Use multipath descriptors in descriptors.md and linked test (Anurag chavan)

Pull request description:

  Updates documentation and `wallet_miniscript_decaying_multisig_descriptor_psbt.py` to use single multipath descriptors with `<0;1>` syntax instead of separate external/internal descriptors.

  ## Changes
  - **doc/descriptors.md**: Update examples (lines 70-71) to use `/<0;1>/*` multipath syntax
  - **doc/descriptors.md**: Update Basic Multisig Example instructions (line 179) to use single multipath descriptor
  - **test/functional/wallet_miniscript_decaying_multisig_descriptor_psbt.py**: Refactor to use single multipath descriptor pattern matching `wallet_multisig_descriptor_psbt.py`

  ## Implementation
  - `_get_xpub()` now extracts external descriptor and converts to multipath format
  - `create_multisig()` imports single descriptor that expands to receive and change addresses
  - Removed fake checksums from documentation examples
  - Added clear comments documenting multipath convention

  Fixes #34086

ACKs for top commit:
  yashbhutwala:
    ACK 552bc82b17
  achow101:
    ACK 552bc82b17
  rkrux:
    lgtm tACK 552bc82

Tree-SHA512: cc99271a3955daa475242d9f4ef8f09f4c94c64e48ec4647ecfd95dceb38bb0cdd91b78ec2d5f033b449d175eaecbdda49d6c766c8a1e1a01fed93be4eb0cfc0
2026-01-30 17:29:47 -08:00
Ava Chow
5ad94cf6b7 Merge bitcoin/bitcoin#34381: script: return proper error for CScriptNum errors
6f7b4323cb test: remove UNKNOWN_ERROR from script_tests (Bruno Garcia)
bd31a92d67 script: use SCRIPT_ERR_SCRIPTNUM for CScriptNum errors (Bruno Garcia)
0ca4dcd786 script: add SCRIPT_ERR_SCRIPTNUM error (Bruno Garcia)

Pull request description:

  When evaluating a script, the current code is bad for analyzing some errors because it returns `SCRIPT_ERR_UNKNOWN_ERROR` for errors that are clearly known.

  `CScriptNum` has two well defined errors: number overflow and non-minimally encoded number. However, for both errors we return as unknown. This PR changes it by adding a new ScriptError that is used for any `CScriptNum` error.

ACKs for top commit:
  achow101:
    ACK 6f7b4323cb
  w0xlt:
    ACK 6f7b4323cb
  darosior:
    ACK 6f7b4323cb

Tree-SHA512: e656d9992251fbc95d33966fa18ce64bf714179d51ba6a7f429e5a55bc58e7fc08827e4ab71ace0dd385dac7e1feaea621b49503387793a30eae7a7e44aa6b0f
2026-01-30 16:22:43 -08:00
Ava Chow
4f85b05131 Merge bitcoin/bitcoin#31713: miniscript refactor: Remove unique_ptr-indirection
964c44cdcd test(miniscript): Prove avoidance of stack overflow (Hodlinator)
198bbaee49 refactor(miniscript): Destroy nodes one full subs-vector at a time (Hodlinator)
50cab8570e refactor(miniscript): Remove NodeRef & MakeNodeRef() (Hodlinator)
15fb34de41 refactor(miniscript): Remove superfluous unique_ptr-indirection (Hodlinator)
e55b23c170 refactor(miniscript): Remove Node::subs mutability (Hodlinator)
c6f798b222 refactor(miniscript): Make fields non-const & private (Hodlinator)
22e4115312 doc(miniscript): Remove mention of shared pointers (Hodlinator)

Pull request description:

  Removes one level of unnecessary indirection, which was a change that originally [aided in finding one issue](https://github.com/bitcoin/bitcoin/pull/30866#pullrequestreview-2434704657) in #30866. Simplifies the code one step further than 09a1875ad8 belonging to aforementioned PR.

  Also adds test which verifies resistance to stack overflow when it comes to `~Node()` and `Node::Clone()`.

  No observed difference when running benchmarks: ExpandDescriptor/WalletIsMineDescriptors/WalletIsMineMigratedDescriptors/WalletLoadingDescriptors.

  Followup to #30866.

ACKs for top commit:
  achow101:
    ACK 964c44cdcd
  darosior:
    Code review ACK 964c44cdcd
  l0rinc:
    ACK 964c44cdcd

Tree-SHA512: 32927e8f0f916fb70372ffd110f7ec7207d9e7a099c21c0a7482a12e96593b673c339719f4ab166ad7c086dc43767315fc1742c5b236a3facc45c4cfeb5872e9
2026-01-30 15:17:59 -08:00
Ava Chow
5d2707307e Merge bitcoin/bitcoin#34454: wallet: Rename RecordType::DELETE to RecordType::DELETE_FLAG
516be10bb5 wallet: Rename `RecordType::DELETE` to `RecordType::DELETE_FLAG` (Hennadii Stepanov)

Pull request description:

  On Windows, the `winnt.h` header defines `DELETE` as a macro for a "Standard Access Right" bitmask (0x00010000L).

  This introduces a fragile dependency on header inclusion order: if Windows headers happen to be included before the `RecordType` enum definition, the preprocessor expands `DELETE` into a numeric literal, causing syntax errors.

  Rename the enumerator to `DELETE_FLAG` to remove this fragility and avoid the collision entirely.

  Split from https://github.com/bitcoin/bitcoin/pull/34448.

ACKs for top commit:
  maflcko:
    re-lgtm ACK 516be10bb5
  achow101:
    ACK 516be10bb5

Tree-SHA512: eba054b395e18c07efb2901b28f542b042b62d85e1a798eeff35f8431530cb667fa791c47c4125cecdb689213b458ba396715495415e9b83bb322509a9376222
2026-01-30 13:21:58 -08:00
Hennadii Stepanov
07af50f789 util: Drop *BSD headers in batchpriority.cpp
Currently, there are issues with headers in `batchpriority.cpp`:
1. `SCHED_BATCH` is not defined on all supported *BSD platforms.
2. `pthread.h` is necessary on other platforms.

This addresses both issues and fixes other includes.
2026-01-30 15:18:05 +00:00
Hennadii Stepanov
516be10bb5 wallet: Rename RecordType::DELETE to RecordType::DELETE_FLAG
On Windows, the `winnt.h` header defines `DELETE` as a macro for a
"Standard Access Right" bitmask (0x00010000L).

This introduces a fragile dependency on header inclusion order: if
Windows headers happen to be included before this enum definition,
the preprocessor expands `DELETE` into a numeric literal, causing
syntax errors.

Rename the enumerator to `DELETE_FLAG` to remove this fragility and
avoid the collision entirely.
2026-01-30 14:21:17 +00:00
Hennadii Stepanov
9c839aa9e3 iwyu: Document mappings for libc symbols 2026-01-30 11:52:49 +00:00
Hennadii Stepanov
91824646c5 iwyu: Add temporary mapping to work around upstream bug 2026-01-30 11:50:17 +00:00
Hennadii Stepanov
37de7d1910 iwyu: Drop backported mapping
See https://github.com/include-what-you-use/include-what-you-use/pull/1706.
2026-01-30 11:39:20 +00:00
merge-script
01651324f4 Merge bitcoin/bitcoin#34434: miniscript: correct and_v() properties
4fab35cf88 miniscript: correct and_v() properties (Antoine Poinsot)

Pull request description:

  `and_v()` must never be 'd'. This is not a bug fix since this was unreachable in valid Miniscripts: the first sub of an `and_v()` must be of type V, which conflicts with (i.e. never has) property 'd'.

ACKs for top commit:
  sipa:
    ACK 4fab35cf88. Fuzzed for 2 months worth of CPU time.
  achow101:
    ACK 4fab35cf88

Tree-SHA512: 8932ad2c9188747299cb9147ff097dca8d078ce7bdd0caefa71ee2724ff81d9bef836664211c2081519a45afd50c539974d67c2a3a1a42a65a3b10b1daef8cbe
2026-01-30 09:45:19 +00:00
merge-script
c7cf2b8f3a Merge bitcoin/bitcoin#34445: fuzz: Use __AFL_SHM_ID for naming test directories
d3e681bc06 fuzz: Use `__AFL_SHM_ID` for naming test directories (marcofleon)

Pull request description:

  During long multicore fuzzing campaigns with AFL++, stale datadirs can eventually accumulate from time outs, resulting in disk running out of space (see https://github.com/bitcoin/bitcoin/issues/28811). The easiest way to reproduce this is by running our `utxo_total_supply` target using multiple cores with AFL++ and observing the crashes that occur because of all the directories in `/tmp/test_common\ bitcoin/utxo_total_supply/`.

  Fix this by using the AFL++ shared memory ID to name the test dirs and cleaning it up before each setup. This ID is unique per AFL++ instance, so multiple cores can run in parallel without conflicts.

  Fixes https://github.com/bitcoin/bitcoin/issues/28811

ACKs for top commit:
  maflcko:
    lgtm ACK d3e681bc06
  dergoegge:
    utACK d3e681bc06

Tree-SHA512: 420373e5f8a63c84797303ba2ef6657dfe9dacf9c2f3d818524421c24681a0e984c212ecb706217d93f67c2ec16b146a2d37fddcbd6918b2e5e9f634f5e13c10
2026-01-30 09:27:28 +00:00
merge-script
0d1d393877 Merge bitcoin/bitcoin#34429: test: Check that redundant verack message is ignored
fafdae46ff test: Check that redundant verack message is ignored (MarcoFalke)

Pull request description:

  The code exists and is uncovered (ref https://maflcko.github.io/b-c-cov/total.coverage/src/net_processing.cpp.gcov.html#L3795), so add a trivial test to cover it.

ACKs for top commit:
  brunoerg:
    ACK fafdae46ff
  sedited:
    ACK fafdae46ff

Tree-SHA512: 157f434c2faa16243890b2344c4ee36bc359e56c80ba8a04f0bba71e9760cf9106c38ed755ff57eff8d1957f35516d20b3d010e0ecb8633b845f5314cc0d050a
2026-01-30 09:40:57 +01:00
merge-script
23a2e3354e Merge bitcoin/bitcoin#34453: ci: Always print low ccache hit rate notice
fad2876ec3 ci: Always print low ccache hit rate notice (MarcoFalke)

Pull request description:

  Looks like the hit rate is low, even on test changes such as https://github.com/bitcoin/bitcoin/actions/runs/21476546461/job/61867393974#step:10:3349

  to make it easier to debug, unconditionally print the low hit rate notice

ACKs for top commit:
  l0rinc:
    ACK fad2876ec3
  sedited:
    ACK fad2876ec3

Tree-SHA512: 0cd85e3572e8465ec424766b1fdb6181d7e607cae991889b46cc66e5f08354772b6040a9f14c0864d36e1f38894628819a3a7458d3ec9ea32e063257177740a0
2026-01-30 09:23:10 +01:00
Ava Chow
5401e673d5 Merge bitcoin/bitcoin#33604: p2p: Allow block downloads from peers without snapshot block after assumeutxo validation
7d9e1a8102 test: Verify peer usage after assumeutxo validation completes (stringintech)
0067abe153 p2p: Allow block downloads from peers without snapshot block after assumeutxo validation (stringintech)

Pull request description:

  Currently, after assumeutxo background validation finishes, the node continues to skip peers that don't have the snapshot block in their best chain until restart. This unnecessarily excludes peers from block downloads even though the background sync has completed and undo data is available.

  The restriction persists because `m_chainman.CurrentChainstate().SnapshotBase()` continues to return the snapshot base block until restart, even after validation completes. Added `m_chainman.CurrentChainstate().m_assumeutxo == Assumeutxo::UNVALIDATED` check to only apply the peer restriction while background validation is ongoing.

  Also added test coverage in `feature_assumeutxo.py` that verifies peers without the snapshot block can be used for block downloads after background validation completes. The test fails without this fix.

ACKs for top commit:
  fjahr:
    Re-ACK 7d9e1a8102
  achow101:
    ACK 7d9e1a8102
  sedited:
    Re-ACK 7d9e1a8102

Tree-SHA512: 5515971da7bf7efc55eecdf03686f44c20c9e52dd168e7cfa119032d6a8ebccee69df7143075e4e9d0a01426cd9ae7202dce5c00919a82478ebf49a15dc0fe19
2026-01-29 15:11:04 -08:00
Ava Chow
6750744eb3 Merge bitcoin/bitcoin#34164: validation: add reusable coins view for ConnectBlock
3e0fd0e4dd refactor: rename will_reuse_cache to reallocate_cache (Andrew Toth)
44b4ee194d validation: reuse same CCoinsViewCache for every ConnectBlock call (Andrew Toth)
8fb6043231 coins: introduce CCoinsViewCache::ResetGuard (Andrew Toth)
041758f5ed coins: use hashBlock setter internally for CCoinsViewCache methods (Andrew Toth)
8dd9200fc9 coins: add Reset on CCoinsViewCache (Andrew Toth)

Pull request description:

  This is the first commit of #31132, which can be merged as an independent change. It has a small benefit on its own, but will help in moving the parent PR forward.

  Add a `Reset()` method to `CCoinsViewCache` that clears `cacheCoins`, `cachedCoinsUsage`, and `hashBlock` without flushing to the `base` view. This allows efficiently reusing a cache instance across multiple blocks.

  Add `CCoinsViewCache::CreateResetGuard` method to return a `CCoinsViewCache::ResetGuard`. The `ResetGuard` automatically calls `Reset()` on destruction. This RAII pattern ensures the cache is always properly reset between blocks.

  Add `m_connect_block_view` as a persistent `CCoinsViewCache` for `ConnectBlock`, avoiding repeated memory allocations.

ACKs for top commit:
  l0rinc:
    ACK 3e0fd0e4dd
  achow101:
    ACK 3e0fd0e4dd
  sedited:
    ACK 3e0fd0e4dd

Tree-SHA512: a95feaa062a9eb7cf7514425a7e7adffd347cd1f7b32b4c1fefcde30002141757c184174702b3104a029dcd33194f8bd734159deebb2e668716089305b42cb00
2026-01-29 14:59:36 -08:00
Ava Chow
4e4fa0199e Merge bitcoin/bitcoin#33680: validation: do not wipe utxo cache for stats/scans/snapshots
c6ca2b85a3 validation: do not wipe utxo cache for stats/scans/snapshots (Pieter Wuille)
7099e93d0a refactor: rename `FlushStateMode::ALWAYS` to `FORCE_FLUSH` (Lőrinc)

Pull request description:

  Revival of https://github.com/bitcoin/bitcoin/pull/30610#issuecomment-3432564955 with the remaining comments applied on top

  > Since #28280, the cost of a non-wiping sync of the UTXO cache is only proportional to the number of dirty entries, rather than proportional to the size of the entire cache. Because of that, there is no reason to perform a wiping flush in case the contents of the cache is still useful.
  >
  > Split the `FlushStateMode::ALWAYS` mode into a FORCE_SYNC (non-wiping) and a FORCE_FLUSH (wiping), and then use the former in `scantxoutset`, `gettxoutsetinfo`, snapshot creation.

  (slightly updated after #30214)

ACKs for top commit:
  optout21:
    reACK c6ca2b85a3
  cedwies:
    reACK c6ca2b8 (trivial)
  achow101:
    ACK c6ca2b85a3
  sedited:
    ACK c6ca2b85a3

Tree-SHA512: f3525a85dc512db4a0a9c749ad47c0d3fa44085a121aa54cd77646260a719c71f754ec6570ae77779c0ed68a24799116f79c686e7a17ce57a26f6a598f7bf926
2026-01-29 14:43:27 -08:00
MarcoFalke
fad2876ec3 ci: Always print low ccache hit rate notice 2026-01-29 21:35:29 +01:00
fanquake
a89e1618dd contrib: update macOS SDK to Xcode-26.1.1-17B100 2026-01-29 16:27:04 +00:00
fanquake
57a778ed25 depends: use -Xclang -fno-cxx-modules in macOS cross build
Newer versions of the macOS SDK, have introduced code like:
```cpp
if defined(__has_feature) && __has_feature(modules)
define USE_CLANG_TYPES 1
else
define USE_CLANG_TYPES 0
endif

if USE_CLANG_TYPES
include <sys/_types/_ptrdiff_t.h>
include <sys/_types/_size_t.h>
include <sys/_types/_va_list.h>
include <sys/_types/_wchar_t.h>
endif
```

which is currently causing compile failures due to undeclared types,
which manifest when C++ modules are enabled. Note that the usage of
"modules" in LLVM is can be a bit ambiguous, see:
https://github.com/llvm/llvm-project/issues/55891.

For now, explcitly disable cxx modules using `-fno-cxx-modules`. This
resolves the include/compilation issues.

Related discussion:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116827
https://github.com/llvm/llvm-project/pull/150349
https://github.com/llvm/llvm-project/issues/57432
2026-01-29 16:27:00 +00:00
Andrew Toth
3e0fd0e4dd refactor: rename will_reuse_cache to reallocate_cache
More accurately reflects the purpose of the parameter, since
we will keep reusing the cache but don't want to reallocate it.
2026-01-29 09:47:10 -05:00
Andrew Toth
44b4ee194d validation: reuse same CCoinsViewCache for every ConnectBlock call
Add m_connect_block_view to ChainState's CoinsViews.
Call CreateResetGuard inside ConnectTip to ensure the view
is Reset after each block, avoiding repeated memory allocations.

Co-authored-by: l0rinc <pap.lorinc@gmail.com>
2026-01-29 09:47:10 -05:00
Andrew Toth
8fb6043231 coins: introduce CCoinsViewCache::ResetGuard
CCoinsViewCache::CreateResetGuard returns a guard that calls
Reset on the cache when the guard goes out of scope.
This RAII pattern ensures the cache is always properly reset
when it leaves current scope.

Co-authored-by: l0rinc <pap.lorinc@gmail.com>
Co-authored-by: sedited <seb.kung@gmail.com>
2026-01-29 09:47:05 -05:00
Andrew Toth
041758f5ed coins: use hashBlock setter internally for CCoinsViewCache methods
Co-authored-by: l0rinc <pap.lorinc@gmail.com>
2026-01-29 09:47:05 -05:00
Andrew Toth
8dd9200fc9 coins: add Reset on CCoinsViewCache
Add a Reset() method to CCoinsViewCache that clears cacheCoins,
cachedCoinsUsage, and hashBlock without flushing to the base view.

Co-authored-by: l0rinc <pap.lorinc@gmail.com>
Co-authored-by: sedited <seb.kung@gmail.com>
2026-01-29 09:46:35 -05:00
Hennadii Stepanov
efcbf79448 ci, iwyu: Fix warnings in src/zmq and treat them as errors 2026-01-29 14:38:35 +00:00
marcofleon
d3e681bc06 fuzz: Use __AFL_SHM_ID for naming test directories
Use the AFL++ shared memory ID environment variable to create
a deterministic datadir path. This prevents accumulation of stale
directories after a fuzz iteration crashes or times out. During
long fuzz campaigns, this accumulation has occasionally resulted
in running out of disk space.
2026-01-29 13:53:42 +00:00
Hennadii Stepanov
f7e0c3d3d3 Merge bitcoin/bitcoin#34346: test: use IP_PORTRANGE_HIGH on FreeBSD for dynamic port allocation
2845f10a2b test: extend FreeBSD ephemeral port range fix to P2P listeners (node)
34bed0ed8c test: use IP_PORTRANGE_HIGH on FreeBSD for dynamic port allocation (woltx)

Pull request description:

  Reopening #34336. I’ve now tested it on FreeBSD and confirmed it works.

  On FreeBSD, the default ephemeral port range (10000-65535) overlaps with the test framework's static port range (11000-26000), possibly causing intermittent "address already in use" failures when tests use dynamic port allocation (`port=0`).

  This PR adds a helper that sets `IP_PORTRANGE_HIGH` via `setsockopt()` before binding, requesting ports from 49152-65535 instead, which avoids the overlap, as suggested in https://github.com/bitcoin/bitcoin/issues/34331#issuecomment-3767161843 by @maflcko .

  From FreeBSD's [sys/netinet/in.h](https://cgit.freebsd.org/src/tree/sys/netinet/in.h):
    ```c
    #define IP_PORTRANGE         19
    #define IP_PORTRANGE_HIGH    1
    #define IPPORT_EPHEMERALFIRST 10000  /* default range start */
    #define IPPORT_HIFIRSTAUTO   49152   /* high range start */
  ```

  See also: FreeBSD https://man.freebsd.org/cgi/man.cgi?query=ip&sektion=4 man page.

  Fixes #34331

ACKs for top commit:
  vasild:
    ACK 2845f10a2b
  hebasto:
    ACK 2845f10a2b, I have reviewed the code and it looks OK.

Tree-SHA512: ce501ce3e8a4023e07bad572df2b85d6829becf133813e4529aebba83e4eba59fa8b48e9d2197ebbb226adaf3054fad720775a787244d6b38c0078ee086102f4
2026-01-29 11:33:35 +00:00
Lőrinc
eeb4d28148 validation: follow-up nits for lock-free IsInitialBlockDownload()
Add `AssertLockHeld(cs_main)` to `ChainstateManager::UpdateIBDStatus()` given `EXCLUSIVE_LOCKS_REQUIRED(cs_main)`.
Fix outdated comment about constness of `ChainstateManager::IsInitialBlockDownload()` (build passes without it).
And since we're touching it, we might as well mark `ChainstateManager::IsInitialBlockDownload()` as `noexcept` now.

Follow-up to #34253.

Co-authored-by: Martin Zumsande <mzumsande@gmail.com>
2026-01-29 12:29:37 +01:00
merge-script
1c2f164d34 Merge bitcoin/bitcoin#34253: validation: cache tip recency for lock-free IsInitialBlockDownload()
557b41a38c validation: make `IsInitialBlockDownload()` lock-free (Lőrinc)
b9c0ab3b75 chain: add `CChain::IsTipRecent` helper (Lőrinc)
8d531c6210 validation: invert `m_cached_finished_ibd` to `m_cached_is_ibd` (Lőrinc)
8be54e3b19 test: cover IBD exit conditions (Lőrinc)

Pull request description:

  This PR is a follow-up to the stale #32885.

  ### Problem
  `ChainstateManager::IsInitialBlockDownload()` currently acquires `cs_main` internally, even though most existing call sites already hold the lock. This becomes relevant for proposals like #34054, which would call `IsInitialBlockDownload()` from the scheduler thread without holding `cs_main`, potentially introducing lock contention.

  ### Fix
  Make `ChainstateManager::IsInitialBlockDownload()` lock-free by caching its result in a single atomic `m_cached_is_ibd` (true while in IBD, latched to false on exit).
  Move the IBD exit checks out of `IsInitialBlockDownload()` (reader-side) into a new `ChainstateManager::UpdateIBDStatus()` (writer-side, called under cs_main).

  Call UpdateIBDStatus() at strategic points where IBD exit conditions may change, after active chain tip updates in `ConnectTip()`, `DisconnectTip()`, and `LoadChainTip()`, and after `ImportBlocks()` returns.

  With this, `IsInitialBlockDownload()` becomes a lock-free atomic read, avoiding internal `cs_main` acquisition on hot paths.

  ### Testing and Benchmarks
  This isn't strictly an optimization (though some usecases might benefit from it), so rather as a sanity check I ran a reindex-chainstate and an `AssumeUTXO` load (without background validation).

  <details>
  <summary>assumeutxo load | 910000 blocks | dbcache 4500 | i9-ssd | x86_64 | Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz | 16 cores | 62Gi RAM | xfs | SSD</summary>

  ```
  COMMITS="595504a43209bead162da54a204df7d140a25f0e 63e822b637f67242e3689adedc0155b34100e651"; \
  CC=gcc; CXX=g++; \
  BASE_DIR="/mnt/my_storage"; DATA_DIR="$BASE_DIR/ShallowBitcoinData"; LOG_DIR="$BASE_DIR/logs"; UTXO_SNAPSHOT_PATH="$BASE_DIR/utxo-910000.dat"; \
  (echo ""; for c in $COMMITS; do git fetch -q origin $c && git log -1 --pretty='%h %s' $c || exit 1; done; echo "") && \
  for DBCACHE in 4500; do \
    (echo "assumeutxo load | 910000 blocks | dbcache ${DBCACHE} | $(hostname) | $(uname -m) | $(lscpu | grep 'Model name' | head -1 | cut -d: -f2 | xargs) | $(nproc) cores | $(free -h | awk '/^Mem:/{print $2}') RAM | $(df -T $BASE_DIR | awk 'NR==2{print $2}') | $(lsblk -no ROTA $(df --output=source $BASE_DIR | tail -1) | grep -q 0 && echo SSD || echo HDD)";) &&\
    hyperfine \
    --sort command \
    --runs 3 \
    --export-json "$BASE_DIR/assumeutxo-$(sed -E 's/(\w{8})\w+ ?/\1-/g;s/-$//'<<<"$COMMITS")-$DBCACHE-$CC-$(date +%s).json" \
    --parameter-list COMMIT ${COMMITS// /,} \
    --prepare "killall -9 bitcoind 2>/dev/null; rm -rf $DATA_DIR/blocks $DATA_DIR/chainstate $DATA_DIR/chainstate_snapshot $DATA_DIR/debug.log; git clean -fxd; git reset --hard {COMMIT} && \
               cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo && ninja -C build bitcoind bitcoin-cli -j2 && \
               ./build/bin/bitcoind -datadir=$DATA_DIR -stopatheight=1 -printtoconsole=0; sleep 20 && \
               ./build/bin/bitcoind -datadir=$DATA_DIR -daemon -blocksonly -connect=0 -dbcache=$DBCACHE -printtoconsole=0; sleep 20" \
     --conclude "build/bin/bitcoin-cli -datadir=$DATA_DIR stop || true; killall bitcoind || true; sleep 10; \
                 echo '{COMMIT} | dbcache=$DBCACHE | chainstate: $(find $DATA_DIR/chainstate_snapshot -type f 2>/dev/null | wc -l) files, $(du -sb $DATA_DIR/chainstate_snapshot 2>/dev/null | cut -f1) bytes' >> $DATA_DIR/debug.log; \
                 cp $DATA_DIR/debug.log $LOG_DIR/debug-assumeutxo-{COMMIT}-dbcache-$DBCACHE-$(date +%s).log" \
      "COMPILER=$CC DBCACHE=$DBCACHE ./build/bin/bitcoin-cli -datadir=$DATA_DIR -rpcclienttimeout=0 loadtxoutset $UTXO_SNAPSHOT_PATH"; \
  done

  595504a432 Merge bitcoin/bitcoin#34236: Add sedited to trusted-keys
  63e822b637 validation: make `IsInitialBlockDownload()` lock-free

  assumeutxo load | 910000 blocks | dbcache 4500 | i9-ssd | x86_64 | Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz | 16 cores | 62Gi RAM | xfs | SSD

  Benchmark 1: COMPILER=gcc DBCACHE=4500 ./build/bin/bitcoin-cli -datadir=/mnt/my_storage/ShallowBitcoinData -rpcclienttimeout=0 loadtxoutset /mnt/my_storage/utxo-910000.dat (COMMIT = 595504a432)
    Time (mean ± σ):     418.452 s ±  0.461 s    [User: 0.001 s, System: 0.001 s]
    Range (min … max):   418.070 s … 418.964 s    3 runs

  Benchmark 2: COMPILER=gcc DBCACHE=4500 ./build/bin/bitcoin-cli -datadir=/mnt/my_storage/ShallowBitcoinData -rpcclienttimeout=0 loadtxoutset /mnt/my_storage/utxo-910000.dat (COMMIT = 63e822b637f67242e3689adedc0155b34100e651)
    Time (mean ± σ):     415.994 s ±  0.294 s    [User: 0.001 s, System: 0.001 s]
    Range (min … max):   415.788 s … 416.330 s    3 runs

  Relative speed comparison
          1.01 ±  0.00  COMPILER=gcc DBCACHE=4500 ./build/bin/bitcoin-cli -datadir=/mnt/my_storage/ShallowBitcoinData -rpcclienttimeout=0 loadtxoutset /mnt/my_storage/utxo-910000.dat (COMMIT = 595504a432)
          1.00          COMPILER=gcc DBCACHE=4500 ./build/bin/bitcoin-cli -datadir=/mnt/my_storage/ShallowBitcoinData -rpcclienttimeout=0 loadtxoutset /mnt/my_storage/utxo-910000.dat (COMMIT = 63e822b637f67242e3689adedc0155b34100e651)
  ```

  </details>

  <details>
  <summary>2026-01-12 | reindex-chainstate | 931139 blocks | dbcache 4500 | i9-ssd | x86_64 | Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz | 16 cores | 62Gi RAM | SSD</summary>

  ```
  for DBCACHE in 4500; do \
    COMMITS="595504a43209bead162da54a204df7d140a25f0e 63e822b637f67242e3689adedc0155b34100e651"; \
    STOP=931139; CC=gcc; CXX=g++; \
    BASE_DIR="/mnt/my_storage"; DATA_DIR="$BASE_DIR/BitcoinData"; LOG_DIR="$BASE_DIR/logs"; \
    (echo ""; for c in $COMMITS; do git fetch -q origin $c && git log -1 --pretty='%h %s' $c || exit 1; done) && \
    (echo "" && echo "$(date -I) | reindex-chainstate | ${STOP} blocks | dbcache ${DBCACHE} | $(hostname) | $(uname -m) | $(lscpu | grep 'Model name' | head -1 | cut -d: -f2 | xargs) | $(nproc) cores | $(free -h | awk '/^Mem:/{print $2}') RAM | SSD"; echo "") &&\
    hyperfine \
      --sort command \
      --runs 1 \
      --export-json "$BASE_DIR/rdx-$(sed -E 's/(\w{8})\w+ ?/\1-/g;s/-$//'<<<"$COMMITS")-$STOP-$DBCACHE-$CC.json" \
      --parameter-list COMMIT ${COMMITS// /,} \
      --prepare "killall -9 bitcoind 2>/dev/null; rm -f $DATA_DIR/debug.log; git clean -fxd; git reset --hard {COMMIT} && \
        cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DENABLE_IPC=OFF && ninja -C build bitcoind -j1 && \
        ./build/bin/bitcoind -datadir=$DATA_DIR -stopatheight=$STOP -dbcache=1000 -printtoconsole=0; sleep 20; rm -f $DATA_DIR/debug.log" \
      --conclude "killall bitcoind || true; sleep 5; grep -q 'height=0' $DATA_DIR/debug.log && grep -q 'Disabling script verification at block #1' $DATA_DIR/debug.log && grep -q 'height=$STOP' $DATA_DIR/debug.log; \
                  cp $DATA_DIR/debug.log $LOG_DIR/debug-{COMMIT}-$(date +%s).log" \
      "COMPILER=$CC ./build/bin/bitcoind -datadir=$DATA_DIR -stopatheight=$STOP -dbcache=$DBCACHE -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0";
  done

  595504a432 Merge bitcoin/bitcoin#34236: Add sedited to trusted-keys
  63e822b637 validation: make `IsInitialBlockDownload()` lock-free

  2026-01-12 | reindex-chainstate | 931139 blocks | dbcache 4500 | i9-ssd | x86_64 | Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz | 16 cores | 62Gi RAM | SSD

  Benchmark 1: COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=931139 -dbcache=4500 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 595504a432)
    Time (abs ≡):        17187.310 s               [User: 33104.415 s, System: 937.548 s]

  Benchmark 2: COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=931139 -dbcache=4500 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 63e822b637f67242e3689adedc0155b34100e651)
    Time (abs ≡):        17240.300 s               [User: 33164.803 s, System: 976.485 s]

  Relative speed comparison
          1.00          COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=931139 -dbcache=4500 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 595504a432)
          1.00          COMPILER=gcc ./build/bin/bitcoind -datadir=/mnt/my_storage/BitcoinData -stopatheight=931139 -dbcache=4500 -reindex-chainstate -blocksonly -connect=0 -printtoconsole=0 (COMMIT = 63e822b637f67242e3689adedc0155b34100e651)
  ```

  </details>

ACKs for top commit:
  sedited:
    ACK 557b41a38c
  sipa:
    utACK 557b41a38c
  mzumsande:
    Code Review ACK 557b41a38c

Tree-SHA512: 174015b9785846fc3375bd9d6e4ef91de47ffb659a94d645c49d333a33a32986d5c3cb2eb5a0a7245f96580ed6fea4ba5b7f93cac7e42e3b225f0a01538a2e5c
2026-01-29 11:51:41 +01:00