29946 Commits

Author SHA1 Message Date
Ava Chow
47c9297172
Merge bitcoin/bitcoin#32420: mining, ipc: omit dummy extraNonce from coinbase
d511adb664edcfb97be44bc0738f49b679240504 [miner] omit dummy extraNonce via IPC (Sjors Provoost)
bf3b5d6d069a0bbb39af0c487fd597257f862f31 test: clarify getCoinbaseRawTx() comparison (Sjors Provoost)
78df9003d63414e4a17b686af7647aeefd706ec5 [doc] Update comments on dummy extraNonces in tests (Anthony Towns)

Pull request description:

  This PR changes the Mining IPC interface to stop including a dummy `extraNonce` in the coinbase `scriptSig` by default, exposing only the consensus-required BIP34 height. This simplifies downstream mining software (including Stratum v2), avoids forcing clients to strip or ignore data we generate, and reduces the risk of incompatibilities if future soft forks add required commitments to the `scriptSig`.

  Existing behavior is preserved for RPCs, tests, regtest, and internal mining by explicitly opting in to the dummy `extraNonce` where needed (e.g. to satisfy `bad-cb-length` at low heights), so consensus rules and test coverage are unchanged. The remainder of the PR consists of small comment fixes, naming clarifications, and test cleanups to make the intent and behavior clearer.

ACKs for top commit:
  achow101:
    ACK d511adb664edcfb97be44bc0738f49b679240504
  ryanofsky:
    Code review ACK d511adb664edcfb97be44bc0738f49b679240504. Just rebased since last review and make suggested tweaks. I'd really like to see this PR merged for the cleanups and sanity it brings to this code. Needs another reviewer though.
  sedited:
    ACK d511adb664edcfb97be44bc0738f49b679240504

Tree-SHA512: d41fa813eb6b5626f4f475d8abc506b29090f4a2d218f2d6824db58b5ebe2ed7c584a903b44de18ccec142bb79c257b0aba6d6da073f56175aec88df96aaaaba
2026-02-02 15:21:16 -08:00
merge-script
8799eb7440
Merge bitcoin/bitcoin#33878: refactor, docs: Embedded ASMap [2/3]: Refactor asmap internals and add documentation
4fec726c4d352daf2fb4a7e5ed463e44c8815ddb refactor: Simplify Interpret asmap function (Fabian Jahr)
79e97d45c16f043d23ba318a661cc39ec53cf760 doc: Add more extensive docs to asmap implementation (Fabian Jahr)
cf4943fdcdd167a56c278ba094cecb0fa241a8f8 refactor: Use span instead of vector for data in util/asmap (Fabian Jahr)
385c34a05261846dac2b42d47f69b317f534dd40 refactor: Unify asmap version calculation and naming (Fabian Jahr)
fa41fc6a1a7d492b894e206f83e0c9786b44a2f0 refactor: Operate on bytes instead of bits in Asmap code (Fabian Jahr)

Pull request description:

  This is a second slice carved out of #28792. It contains the following changes that are crucial for the embedding of asmap data which is added the following PR in the series (probably this will remain in #28792).

  The changes are:
  - Modernizes and simplifies the asmap code by operating on `std::byte` instead of bits
  - Unifies asmap version calculation and naming (previously it was called version and checksum interchangeably)
  - Operate on a `span` rather than a vector in the asmap internal to prevent holding the asmap data in memory twice
  - Add more extensive documentation to the asmap implementation
  - Unify asmap casing in implemetation function names

  The first three commits were already part of #28792, the others are new.

  The documentation commit came out of feedback gathered at the latest CoreDev. The primary input for the documentation was the documentation that already existed in the Python implementation (`contrib/asmap/asmap.py`) but there are several other comments as well. Please note: I have also asked several LLMs to provide suggestions on how to explain pieces of the implementation and better demonstrate how the parts work together. I have copied bits and pieces that I liked but everything has been edited further by me and obviously all mistakes here are my own.

ACKs for top commit:
  hodlinator:
    re-ACK 4fec726c4d352daf2fb4a7e5ed463e44c8815ddb
  sipa:
    ACK 4fec726c4d352daf2fb4a7e5ed463e44c8815ddb
  sedited:
    Re-ACK 4fec726c4d352daf2fb4a7e5ed463e44c8815ddb

Tree-SHA512: 950a591c3fcc9ddb28fcfdc3164ad3fbd325fa5004533c4a8b670fbf8b956060a0daeedd1fc2fced1f761ac49cd992b79cabe12ef46bc60b2559a7a613d0e166
2026-02-02 18:22:31 +01:00
merge-script
41034a032f
Merge bitcoin/bitcoin#34396: fuzz: pull the latest FuzzedDataProvider.h from upstream
dfb93646093f8d71be455fc95e2e06ff73fb9211 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 dfb93646093f8d71be455fc95e2e06ff73fb9211 - 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
facb2aab26dffbc1e46809ac776ed43b9eaa9ad4 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 facb2aab26dffbc1e46809ac776ed43b9eaa9ad4
  ismaelsadeeq:
    utACK facb2aab26dffbc1e46809ac776ed43b9eaa9ad4
  sedited:
    ACK facb2aab26dffbc1e46809ac776ed43b9eaa9ad4

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
3bd98b45084d3029465110a99e2486d48944ded8 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 3bd98b45084d3029465110a99e2486d48944ded8 🚪
  frankomosh:
    ACK 3bd98b45084d3029465110a99e2486d48944ded8. Good use of transparent comparator to eliminate `const_cast` in this specific code path.
  sedited:
    ACK 3bd98b45084d3029465110a99e2486d48944ded8

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

Pull request description:

  It was introduced in ab9edbd6b6eb3efbca11f16fa467c3c0ef905708 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 51abf7d15b1da5b74d58a381ced662dc0f70b4b0
  sedited:
    ACK 51abf7d15b1da5b74d58a381ced662dc0f70b4b0
  theStack:
    ACK 51abf7d15b1da5b74d58a381ced662dc0f70b4b0

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()
eeb4d2814803c09af602ca5c9810438dd5e987fb 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 eeb4d2814803c09af602ca5c9810438dd5e987fb
  mzumsande:
    utACK eeb4d2814803c09af602ca5c9810438dd5e987fb

Tree-SHA512: 110cf5b03dc4f4cf6e61563ef69da6368e43009cf0fe1b10870cb4f55203c347444c8623aae7357d0ee5ba3f4b10da535b440a5871c9c5a4f7f8f88c2accd1f1
2026-02-02 07:57:34 +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
07af50f7896a36a82efc19b5030779ab36302fa4 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 07af50f7896a36a82efc19b5030779ab36302fa4 🤺
  w0xlt:
    crACK 07af50f789

Tree-SHA512: 388f627e9d9c8b80834ba562034cd6aa44ba37d9156e13cdd6cbcfa93b19fcbf3222228d671784ca363e06fda3c978778f62f4530c3eb4ae3ff96adf91c2d789
2026-01-31 11:32:34 +01:00
merge-script
1eed88a3ec
Merge bitcoin/bitcoin#34460: iwyu: Update mappings
9c839aa9e3db30e2fa7d45b087a13bdd86b2a085 iwyu: Document mappings for libc symbols (Hennadii Stepanov)
91824646c58afade176d6c0003c892ceca855ba9 iwyu: Add temporary mapping to work around upstream bug (Hennadii Stepanov)
37de7d19107c350e5ff0b8fc0cb5551830bdb6cb 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 9c839aa9e3db30e2fa7d45b087a13bdd86b2a085
  sedited:
    ACK 9c839aa9e3db30e2fa7d45b087a13bdd86b2a085

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
efcbf794484ecc02cae05e520120df9d1aa8c93a 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 efcbf794484ecc02cae05e520120df9d1aa8c93a 🐼
  janb84:
    re ACK efcbf794484ecc02cae05e520120df9d1aa8c93a
  sedited:
    ACK efcbf794484ecc02cae05e520120df9d1aa8c93a

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
b189a345574460f10165862eca9cc40ff3337dca 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 b189a345574460f10165862eca9cc40ff3337dca
  murchandamus:
    ACK b189a345574460f10165862eca9cc40ff3337dca

Tree-SHA512: 1df0b6e29ae219edbeed14cfa97f0ad4688d6bf97ed946719ba3c3b69e004f3dee82991578eb5aceb554914b70c5b68feff9e321283c1fc8bc0fedf08df2cb4c
2026-01-30 18:26:07 -08:00
Ava Chow
5ad94cf6b7
Merge bitcoin/bitcoin#34381: script: return proper error for CScriptNum errors
6f7b4323cb46687ba9df7073a9cde427985d2dfc test: remove UNKNOWN_ERROR from script_tests (Bruno Garcia)
bd31a92d671610e1173a4e6f0c761d94724441ae script: use SCRIPT_ERR_SCRIPTNUM for CScriptNum errors (Bruno Garcia)
0ca4dcd78665bc5258a2b9cfcef0dcdf971a88c3 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 6f7b4323cb46687ba9df7073a9cde427985d2dfc
  w0xlt:
    ACK 6f7b4323cb
  darosior:
    ACK 6f7b4323cb46687ba9df7073a9cde427985d2dfc

Tree-SHA512: e656d9992251fbc95d33966fa18ce64bf714179d51ba6a7f429e5a55bc58e7fc08827e4ab71ace0dd385dac7e1feaea621b49503387793a30eae7a7e44aa6b0f
2026-01-30 16:22:43 -08:00
Ava Chow
4f85b05131
Merge bitcoin/bitcoin#31713: miniscript refactor: Remove unique_ptr-indirection
964c44cdcd6be5f39aed1aeda9c305803eb3b25f test(miniscript): Prove avoidance of stack overflow (Hodlinator)
198bbaee4959119a63b4038cd0dbb519f4daf6f0 refactor(miniscript): Destroy nodes one full subs-vector at a time (Hodlinator)
50cab8570e8f7553a94e750f66ad9228a728e72e refactor(miniscript): Remove NodeRef & MakeNodeRef() (Hodlinator)
15fb34de41cb069e2bad93a64722bdb32ff00690 refactor(miniscript): Remove superfluous unique_ptr-indirection (Hodlinator)
e55b23c170eb1a80a71e2de8b48cf8a0aebda843 refactor(miniscript): Remove Node::subs mutability (Hodlinator)
c6f798b22247bc092e72eed9e9f69a0cbaca5134 refactor(miniscript): Make fields non-const & private (Hodlinator)
22e4115312b929502574ba3681ee2c3b3fd14d96 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 09a1875ad8cddeb17c19af34b8282d37fed0937e 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 964c44cdcd6be5f39aed1aeda9c305803eb3b25f
  darosior:
    Code review ACK 964c44cdcd6be5f39aed1aeda9c305803eb3b25f
  l0rinc:
    ACK 964c44cdcd6be5f39aed1aeda9c305803eb3b25f

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
516be10bb56db80aa95b3afbf9773ecd7f167284 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 516be10bb56db80aa95b3afbf9773ecd7f167284
  achow101:
    ACK 516be10bb56db80aa95b3afbf9773ecd7f167284

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
91824646c5
iwyu: Add temporary mapping to work around upstream bug 2026-01-30 11:50:17 +00:00
merge-script
01651324f4
Merge bitcoin/bitcoin#34434: miniscript: correct and_v() properties
4fab35cf88c048d2784fe6d71d3f83cc4e420879 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 4fab35cf88c048d2784fe6d71d3f83cc4e420879. Fuzzed for 2 months worth of CPU time.
  achow101:
    ACK 4fab35cf88c048d2784fe6d71d3f83cc4e420879

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
d3e681bc06758fe0686cd96fcfd4a1c4c5af62b4 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 d3e681bc06758fe0686cd96fcfd4a1c4c5af62b4
  dergoegge:
    utACK d3e681bc06758fe0686cd96fcfd4a1c4c5af62b4

Tree-SHA512: 420373e5f8a63c84797303ba2ef6657dfe9dacf9c2f3d818524421c24681a0e984c212ecb706217d93f67c2ec16b146a2d37fddcbd6918b2e5e9f634f5e13c10
2026-01-30 09:27:28 +00:00
Ava Chow
5401e673d5
Merge bitcoin/bitcoin#33604: p2p: Allow block downloads from peers without snapshot block after assumeutxo validation
7d9e1a810239a65a153c35f0f94490560441db49 test: Verify peer usage after assumeutxo validation completes (stringintech)
0067abe153298ce9f14262a15533033e6e907f2b 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 7d9e1a810239a65a153c35f0f94490560441db49
  achow101:
    ACK 7d9e1a810239a65a153c35f0f94490560441db49
  sedited:
    Re-ACK 7d9e1a810239a65a153c35f0f94490560441db49

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
3e0fd0e4ddd894f0e7db1772f10ceaa1dddfb951 refactor: rename will_reuse_cache to reallocate_cache (Andrew Toth)
44b4ee194d3bdccd86cf5e151b2fc1479aabbb6c validation: reuse same CCoinsViewCache for every ConnectBlock call (Andrew Toth)
8fb6043231ea396aaa1165b36b082c89e10fcafd coins: introduce CCoinsViewCache::ResetGuard (Andrew Toth)
041758f5eda5725daad4ae20f66c7d19ba02d063 coins: use hashBlock setter internally for CCoinsViewCache methods (Andrew Toth)
8dd9200fc9b0d263f8f75943ce581a925d061378 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 3e0fd0e4ddd894f0e7db1772f10ceaa1dddfb951
  achow101:
    ACK 3e0fd0e4ddd894f0e7db1772f10ceaa1dddfb951
  sedited:
    ACK 3e0fd0e4ddd894f0e7db1772f10ceaa1dddfb951

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
c6ca2b85a3e6e73674e210aee4ed69c4af2848e4 validation: do not wipe utxo cache for stats/scans/snapshots (Pieter Wuille)
7099e93d0a80c65a547131d7bab977b09573310c 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 c6ca2b85a3e6e73674e210aee4ed69c4af2848e4
  cedwies:
    reACK c6ca2b8 (trivial)
  achow101:
    ACK c6ca2b85a3e6e73674e210aee4ed69c4af2848e4
  sedited:
    ACK c6ca2b85a3e6e73674e210aee4ed69c4af2848e4

Tree-SHA512: f3525a85dc512db4a0a9c749ad47c0d3fa44085a121aa54cd77646260a719c71f754ec6570ae77779c0ed68a24799116f79c686e7a17ce57a26f6a598f7bf926
2026-01-29 14:43:27 -08: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
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()
557b41a38ccf2929ca1e5271db1701e5fbe781af validation: make `IsInitialBlockDownload()` lock-free (Lőrinc)
b9c0ab3b75a19d7a1f7c01762374ce85f2d0d7be chain: add `CChain::IsTipRecent` helper (Lőrinc)
8d531c6210eb05bc424c971f621bb0b688ff70e6 validation: invert `m_cached_finished_ibd` to `m_cached_is_ibd` (Lőrinc)
8be54e3b19677b02e19d054a4a5b2f1968bb1c46 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 = 595504a43209bead162da54a204df7d140a25f0e)
    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 = 595504a43209bead162da54a204df7d140a25f0e)
          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 = 595504a43209bead162da54a204df7d140a25f0e)
    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 = 595504a43209bead162da54a204df7d140a25f0e)
          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 557b41a38ccf2929ca1e5271db1701e5fbe781af
  sipa:
    utACK 557b41a38ccf2929ca1e5271db1701e5fbe781af
  mzumsande:
    Code Review ACK 557b41a38ccf2929ca1e5271db1701e5fbe781af

Tree-SHA512: 174015b9785846fc3375bd9d6e4ef91de47ffb659a94d645c49d333a33a32986d5c3cb2eb5a0a7245f96580ed6fea4ba5b7f93cac7e42e3b225f0a01538a2e5c
2026-01-29 11:51:41 +01:00
merge-script
8cdf1dcca0
Merge bitcoin/bitcoin#34373: refactor: Remove remaining std::bind, check via clang-tidy
fad042235bd6054d99d3f5a07529276b0138b484 refactor: Remove remaining std::bind, check via clang-tidy (MarcoFalke)

Pull request description:

  `std::bind` has many issues:

  * It is verbose in a meaningless way
  * Overriden args are silently accepted and dropped at runtime without a compile error. Same for accidental duplicates.

  One could use `std::bind_front` similar to commit fa267551c4eaef577db92e248c4b6d31d0c8bc77. Though, I think the remaining cases are better off with lambdas.

  So do that here, and enable the `modernize-avoid-bind` clang-tidy rule to avoid `std::bind` bugs in the future.

ACKs for top commit:
  fjahr:
    Code review ACK fad042235bd6054d99d3f5a07529276b0138b484
  purpleKarrot:
    Code review ACK fad042235bd6054d99d3f5a07529276b0138b484

Tree-SHA512: 38b17e26eda3ae47d84a8c34298309dc1eeb4ed434fda58b5803ef031c4c2edfb17222f5208f37af727bf340e32b37c7f81784f461d2b65fbc6227f3cd53eea4
2026-01-29 09:50:54 +00:00
MarcoFalke
facb2aab26
test: Turn ElapseSteady into SteadyClockContext 2026-01-29 10:37:43 +01:00
Ava Chow
a6cdc3ec9b
Merge bitcoin/bitcoin#34303: test: addrman: test self-announcement time penalty handling
e770392084aa52e5568cf001da4d537fda1d71b3 test: addrman: test self-announcement time penalty handling (Bruno Garcia)

Pull request description:

  This PR adds a test case for addrman that verifies that addresses announcing themselves (addr == source) are exempt from time penalties, while addresses announced by others receive the expected penalty.

  It fixes the following mutant (https://corecheck.dev/mutation/src/addrman.cpp#L561):
  ```diff
  diff --git a/src/addrman.cpp b/src/addrman.cpp
  index 206b54118e..c6a045fd8d 100644
  --- a/src/addrman.cpp
  +++ b/src/addrman.cpp
  @@ -558,7 +558,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, std::c
       AddrInfo* pinfo = Find(addr, &nId);

       // Do not set a penalty for a source's self-announcement
  -    if (addr == source) {
  +    if (addr != source) {
           time_penalty = 0s;
       }
  ```

ACKs for top commit:
  maflcko:
    review ACK e770392084aa52e5568cf001da4d537fda1d71b3 🐤
  achow101:
    ACK e770392084aa52e5568cf001da4d537fda1d71b3
  fjahr:
    Code review ACK e770392084aa52e5568cf001da4d537fda1d71b3
  naiyoma:
    tACK e770392084aa52e5568cf001da4d537fda1d71b3

Tree-SHA512: ec029d1e1e979f91840af944984cad530a1ce9a0eceb123230817f0ef3b9ad47253eebc4c953d350de2d904b59496fcd4757123c8bd63cf0e09c3581da48fff8
2026-01-28 14:37:29 -08:00
Ava Chow
75ec9001ce
Merge bitcoin/bitcoin#34207: coins/refactor: enforce GetCoin() returns only unspent coins
2ee7f9b259059d59e127852ea898b58183604b46 coins: assume `GetCoin` only returns unspent coins (Andrew Toth)
eec551aaf1dff4cccc15e486d5618a8a44d8314c fuzz: keep `coinscache_sim` backend free of spent coins (Andrew Toth)
3e4155fcefe0aafcc9cb84640e303e05477605a3 test: do not return spent coins from `CCoinsViewTest::GetCoin` (Andrew Toth)
ee1e40f58000921e95f08bcb199a452eb5c4d9b2 txdb: assert `CCoinsViewDB::GetCoin` only returns unspent coins (Lőrinc)

Pull request description:

  This PR is split out from #33018 to keep that PR focused on removing the `FRESH-but-not-DIRTY` cache state.

  ### Problem
  `::GetCoin()` is an interface for querying the UTXO set, so production implementations should only ever return unspent coins. Tests should mimic this to provide useful feedback.

  ### Fix:
  * Add a fail-fast assertion that `CCoinsViewDB::GetCoin()` never returns a spent coin.
  * Align unit tests and fuzz simulations with the production `GetCoin()` contract by never returning spent coins.
  * Replace the unreachable “spent coin returned by parent” handling in `CCoinsViewCache::FetchCoin()` with `Assert(!coin.IsSpent())`, drop outdated `spent+FRESH` docs, and tighten `SanityCheck()` invariants.

  Behavior is unchanged, it just aligns our tests to exercise valid states.

ACKs for top commit:
  andrewtoth:
    re-ACK 2ee7f9b259059d59e127852ea898b58183604b46
  optout21:
    crACK 2ee7f9b259059d59e127852ea898b58183604b46
  achow101:
    ACK 2ee7f9b259059d59e127852ea898b58183604b46
  w0xlt:
    reACK 2ee7f9b259059d59e127852ea898b58183604b46

Tree-SHA512: be21cc09690410fc04ca25e1ba47aae6186bc037e413b3bb1e6e9a04e6364cbfac5a2fcdc49b638fec848cd29243fab0cc0581b9923f34fafe8366828f690ed4
2026-01-28 14:29:17 -08:00
Antoine Poinsot
4fab35cf88 miniscript: correct and_v() properties
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'.
2026-01-28 15:16:49 -05:00
Antoine Poinsot
51abf7d15b script: remove unused SCRIPT_ERR_LAST
It was introduced in ab9edbd6b6eb3efbca11f16fa467c3c0ef905708 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.
2026-01-28 15:09:15 -05:00
Ava Chow
cd1af852fa
Merge bitcoin/bitcoin#34358: wallet: fix removeprunedfunds bug with conflicting transactions
1f60ca360eb83fa7982b1aac402eaaf477294197 wallet: fix removeprunedfunds bug with conflicting transactions (Martin Zumsande)

Pull request description:

  `removeprunedfunds` removes all entries from `mapTxSpends` for the inputs of the pruned tx. However, this is incorrect, because there could be multiple entries from conflicting transactions (that shouldn't be removed as well). This could lead to the wallet creating invalid transactions, trying to double spend utxos.
  The bug persists when the conflicting tx was mined, because the wallet trusts its internal accounting instead of calling `AddToSpends` again.

  The added test should fail on master.

ACKs for top commit:
  achow101:
    ACK 1f60ca360eb83fa7982b1aac402eaaf477294197
  fjahr:
    tACK 1f60ca360eb83fa7982b1aac402eaaf477294197
  furszy:
    utACK 1f60ca360eb83fa7982b1aac402eaaf477294197
  vasild:
    ACK 1f60ca360eb83fa7982b1aac402eaaf477294197

Tree-SHA512: 3cc9ed547530fd53e25721177b76ab2e1eae16ce2c0e63fc01b20fdbf8bd02655dae51167ad56f9dec748d34c61ce65d38f993370820601f8257c73b876a3347
2026-01-28 11:25:28 -08:00
merge-script
d3e8c459e7
Merge bitcoin/bitcoin#34417: log: Print warning about privacy-sensitive log info unconditionally
fa9c92d7b6394194696e014e48346a8b8562e16a log: Print warning about privacy-sensitive log info unconditionally (MarcoFalke)

Pull request description:

  There is a warning about logs containing privacy-sensitive information. However, it is only printed when at least one debug log category is enabled.

  This is confusing, because:

  * Setting (let's say) `-debug=reindex` enables this warning, but it is hard to see what sensitive logs could be contained in reindex debug logs.
  * Dropping `-debug=reindex` again disabled this warning, but the wallet continues to log txids (and other sensitive stuff) at info level.

  So instead of implying the wrong thing, it would be better to remove this log line (because it should be common sense), or log it unconditionally.

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

Tree-SHA512: 42f71b030e7722203f225f04e979143e829dae3556f64e322a791361a3b9c16150d53bb7bb9a99839c975d9052115770b9473138acc58baeee457253526fd892
2026-01-28 18:50:16 +01:00
merge-script
8f9ad534a5
Merge bitcoin/bitcoin#34352: ci, iwyu: Fix warnings in src/primitives and treat them as errors
fdc9fe2da6a8640b11a2871f8b653764652f8c1f ci, iwyu: Fix warnings in `src/primitives` 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).

ACKs for top commit:
  maflcko:
    review ACK fdc9fe2da6a8640b11a2871f8b653764652f8c1f 📀
  janb84:
    ACK fdc9fe2da6a8640b11a2871f8b653764652f8c1f
  sedited:
    ACK fdc9fe2da6a8640b11a2871f8b653764652f8c1f

Tree-SHA512: d290545c7aab477b4a5bf121b694899a78e0526be72efa31fa4205b0fd840e6e8240d32f9134a18c9dc58c5f91e7847d7f20ca34f8d2edc4d541ac858ec0dccc
2026-01-28 17:08:34 +01:00
MarcoFalke
fad042235b
refactor: Remove remaining std::bind, check via clang-tidy 2026-01-28 14:44:22 +01:00
merge-script
d9e651f995
Merge bitcoin/bitcoin#33622: docs: add doc comment for SRD selection algorithm
3400db80401d65ba16b52e5055486c75cd1412ff doc: add missing param description to SRD (yancy)

Pull request description:

  The params documentation is missing `change_fee` and the description is lacking recent changes.

ACKs for top commit:
  murchandamus:
    ACK 3400db80401d65ba16b52e5055486c75cd1412ff
  brunoerg:
    code review ACK 3400db80401d65ba16b52e5055486c75cd1412ff

Tree-SHA512: 8f6fac0d92873c5c9f77b19fbc0c6ecfb425b2a6b3d5f5ad69c82ed706b21cf4627e68c71acbc43661000e6063e8f8dbcd3b8ff60e3c727bdcba497d13ee1383
2026-01-28 14:38:16 +01:00
merge-script
6ae96ed607
Merge bitcoin/bitcoin#34276: Remove empty caption from user interface (noui, gui)
fad7bd9ba3eef03fcdd7cb17011ea0c6e483c767 noui: Remove always empty caption while formatting (MarcoFalke)
fa8ebeb332325604e8ca6080262543e10de4e46c refactor: [gui] Document that the title is always empty for node message (MarcoFalke)
fafe71b743a0637d16812d26430d99464cab0cee refactor: Remove empty caption from ThreadSafeMessageBox (MarcoFalke)
fa8d0088e76d4def59dff92bfb2ebbfc6cd4c195 refactor: Remove empty caption from ThreadSafeQuestion (MarcoFalke)
fa0195499ca611b513d9d1986d79c5e3a58cd0f2 refactor: [gui] Use lambdas over std::bind (MarcoFalke)
eeee1e341fa59b5b0b05f974105104fb2a0df9c3 refactor: Remove trailing semicolon after ADD_SIGNALS_DECL_WRAPPER (MarcoFalke)

Pull request description:

  Currently, the user interface (noui, gui) has a caption for each message. However, the caption has many issues:

  * It is always hard-coded to the empty string.
  * This is confusing and tedious when reading or maintaining the code.
  * It is redundant, because `noui` will ignore the caption and set the logging prefix (error, warning, info) based on the `style`.
  * The gui does prefer to set the title based on the caption, but since it the caption is always empty, the fallback will always be used.

  Fix all issues by removing it.

ACKs for top commit:
  hebasto:
    ACK fad7bd9ba3eef03fcdd7cb17011ea0c6e483c767, I have reviewed the code and it looks OK. Tested on Ubuntu 25.10.
  sedited:
    ACK fad7bd9ba3eef03fcdd7cb17011ea0c6e483c767

Tree-SHA512: 58ef538b9b3e1cfdcf2955f6de9b8cee335edbf6339723cb693cb4d584817904c962dac5199ee44d7e2860a5332dec1a6abf47e621eb5cf919aa1cdae271b55f
2026-01-28 13:43:56 +01:00
merge-script
289d60f5ab
Merge bitcoin/bitcoin#34161: refactor: avoid possible UB from std::distance for nullptr args
477c5504e05f9031449cdbf62bf329eac427cb0c  coins: replace `std::distance` with unambiguous pointer subtraction (Lőrinc)

Pull request description:

  ### Problem

  Calling `std::distance(nullptr, nullptr)` has ambiguous status in the C++ standard [iterator.requirements.general](https://eel.is/c++draft/iterator.requirements.general#7):
  > Iterators can also have singular values that are not associated with any sequence. Results of most expressions are undefined for singular values.

  It seems to work correctly in every implementation we use, but [LWG 1213](https://cplusplus.github.io/LWG/issue1213) ("Meaning of valid and singular iterator underspecified") has been Open since 2009, acknowledging that the standard's wording on this topic is unclear.

  <details>
  <summary>Details</summary>

  The [iterator.requirements.general](https://eel.is/c++draft/iterator.requirements.general#7) states:
  > Iterators can also have singular values that are not associated with any sequence. Results of most expressions are undefined for singular values.

  And [LWG 208](https://cplusplus.github.io/LWG/issue208)'s rationale explicitly confirms:
  > Null pointers are singular.

  Therefore they cannot form a valid range required by [std::distance](https://eel.is/c++draft/iterator.operations#4):
  > Preconditions: last is reachable from first, or InputIterator meets the Cpp17RandomAccessIterator requirements and first is reachable from last.

  </details>

  ### Fix

  A previous version of this PR checked both values for `nullptr`, the current one uses unambiguously well-defined pointer subtraction instead, which is per [expr.add](https://eel.is/c++draft/expr.add#5):
  > If P and Q both evaluate to null pointer values, the value is 0.

  This applies on the first call before any memory is allocated, when both pointers are `nullptr`.
  Using `operator-` directly is simpler and avoids the ambiguity entirely.

ACKs for top commit:
  maflcko:
    review ACK 477c5504e05f9031449cdbf62bf329eac427cb0c 🍶
  optout21:
    ACK 477c5504e05f9031449cdbf62bf329eac427cb0c
  sedited:
    ACK 477c5504e05f9031449cdbf62bf329eac427cb0c

Tree-SHA512: 5edfb19ab4820e2003928f60f20d4a5893bcd3c316afdfe91c9c06e9b465352769b2cddb0d0e2419ea083a906d35f4aada74149e81f4ea0315f8173ac538789f
2026-01-28 11:41:55 +01:00
merge-script
d931b54d13
Merge bitcoin/bitcoin#34412: Update secp256k1 subtree to latest master
2fccbea3c8a0e9a994cf3c49db9c74174f5338fc Squashed 'src/secp256k1/' changes from d543c0d917..14e56970cb (fanquake)

Pull request description:

  Updates the secp256k1 subtree to latest master (14e56970cb).

ACKs for top commit:
  sedited:
    ACK 26fbe10873e727c5f345a6130e819772a321d924
  hebasto:
    ACK 26fbe10873e727c5f345a6130e819772a321d924.
  w0xlt:
    ACK 26fbe10873

Tree-SHA512: 51dbd2e5c4574b85064dd0cea67134727487e1363a822e5116ab92d03e2ebde90aa13eddd0f57df613d393e1741eec974e24c7efb4314254b84d8a994bb5b1ef
2026-01-28 09:30:28 +00:00
yancy
3400db8040 doc: add missing param description to SRD
Co-authored-by: Mark "Murch" Erhardt <murch@murch.one>
2026-01-27 13:55:32 -06:00
merge-script
9260b20ef1
Merge bitcoin/bitcoin#33962: refactor: replace manual promise with SyncWithValidationInterfaceQueue
e71c4df1685131f5ab48aac6ccb07ac944e91e9f refactor: replace manual promise with SyncWithValidationInterfaceQueue (ANtutov)

Pull request description:

  `BroadcastTransaction()` now waits for validation callbacks using the built-in `validation_signals>SyncWithValidationInterfaceQueue()` instead of creating a local `std::promise` and scheduling a lambda. This removes an unnecessary allocation and uses the canonical API.

ACKs for top commit:
  maflcko:
    review ACK e71c4df1685131f5ab48aac6ccb07ac944e91e9f 🌃
  rkrux:
    lgtm ACK e71c4df1685131f5ab48aac6ccb07ac944e91e9f
  sedited:
    ACK e71c4df1685131f5ab48aac6ccb07ac944e91e9f

Tree-SHA512: 602994ba3c2ac91996068aee6eac7e788c3832d7ab949519a9420d2b59e2a67d2d4e67c3c9191ba60e9caa75f1524a95b0851fcd40b6732f6a9956a011b4a120
2026-01-27 18:00:05 +01:00
Sjors Provoost
d511adb664
[miner] omit dummy extraNonce via IPC
Previously the coinbase transaction generated by our miner code was
not used downstream, because the getblocktemplate RPC excludes it.

Since the Mining IPC interface was introduced in #30200 we do expose
this dummy coinbase transaction. In Stratum v2 several parts of it
are communicated downstream, including the scriptSig.

This commit removes the dummy extraNonce from the coinbase scriptSig
in block templates requested via IPC. This limits the scriptSig
to what is essential for consensus (BIP34) and removes the need for
external mining software to remove the dummy, or even ignore
the scriptSig we provide and generate it some other way. This
could cause problems if a future soft fork requires additional
data to be committed here.

A test is added to verify the new IPC behavior.

It achieves this by introducing an include_dummy_extranonce
option which defaults to false with all test code updated to
set it to true. Because this option is not exposed via IPC,
callers will no longer see it.

The caller needs to ensure that for blocks 1 through 16
they pad the scriptSig in order to avoid bad-cb-length.

Co-authored-by: Anthony Towns <aj@erisian.com.au>
2026-01-27 14:45:35 +01:00