Commit Graph

48578 Commits

Author SHA1 Message Date
Ava Chow
58dccd27e1 Merge bitcoin/bitcoin#34858: test: Use NodeClockContext in more tests
faad08e59c test: Use NodeClockContext in more tests (MarcoFalke)
fa8fe0941e fuzz: Use NodeClockContext (MarcoFalke)
fa9f434df8 test: Allow time_point in boost checks (MarcoFalke)

Pull request description:

  Currently mocktime is written to a global, which may leak between sub-tests (albeit some tests try to reset the mocktime on a best-effort basis). Also, when advancing it, one has to keep a counter variable around.

  Fix both issues by using the recently added `NodeClockContext`, which resets the mocktime once it goes out of scope. Also, it has a method to advance the mocktime by a delta.

ACKs for top commit:
  achow101:
    ACK faad08e59c
  seduless:
    Tested ACK faad08e59c
  frankomosh:
    Tested ACK faad08e59c. Ran all relevant tests, all clean. Also verified that the default-constructor call sites in orphanage_tests and addrman_tests behave identically to the explicit `{Now<NodeSeconds>()}` form.
  ryanofsky:
    Code review ACK faad08e59c but had a question about dropping +1 in one test below.

Tree-SHA512: bd56931970eed02bfcf3f3593ef64a61a8a1d8cc8adf190d6903b35df0fd7e6d865678c7d5bd23ce53d074cb2cf53a0a19212fdeb593b047dac5561859bc86b0
2026-04-09 14:33:30 -07:00
Ava Chow
fe3d2be1d6 Merge bitcoin/bitcoin#32757: net: Fix Discover() not running when using -bind=0.0.0.0:port
bb00fd2142 test: use dynamic ports and add coverage in feature_bind_port_discover (b-l-u-e)
4f19508ae7 test: dont connect nodes in feature_bind_port_discover (b-l-u-e)
b8827ce619 net: Fix Discover() not running when using -bind=0.0.0.0:port (b-l-u-e)

Pull request description:

  This PR fixes two related issues with address discovery when using explicit bind addresses in Bitcoin Core:

    -  #31293
    -  #31336

  When using `-bind=0.0.0.0:port` (or `-bind=::`), the `Discover()` function was not being executed because the code only checked the `bind_on_any` flag. This led to two problems:
  - The node would not discover its own local addresses if an explicit "any" bind was used.
  - The functional test `feature_bind_port_discover.py` would fail, as it expects local addresses to be discovered in these cases.

  This PR:
  1. Checks both `bind_on_any` and any bind addresses using `IsBindAny()`
     Ensures `Discover()` runs when binding to 0.0.0.0 or ::, even if specified explicitly.
  2. Ensures correct address discovery
     The node will now discover its own addresses when using explicit "any" binds, matching user expectations and fixing the test.
  3. Maintains backward compatibility
     The semantic meaning of `bind_on_any` is preserved as defined in `net.h`:
     > "True if the user did not specify -bind= or -whitebind= and thus we should bind on 0.0.0.0 (IPv4) and :: (IPv6)"
  4. Updates the test to use dynamic ports
     The functional test `feature_bind_port_discover.py` is updated to use dynamic ports instead of hardcoded ones, improving reliability.

  References

  - Implementation follows the approach proposed in my [review comment on #31492](https://github.com/bitcoin/bitcoin/pull/31492#issuecomment-2941773645).

  Closes #31293

  The #31336 has the overall test failure and requires both this PR and #33362 to be fully resolved.

ACKs for top commit:
  NicolaLS:
    tested ACK bb00fd2142
  pinheadmz:
    ACK bb00fd2142
  vasild:
    ACK bb00fd2142
  achow101:
    ACK bb00fd2142

Tree-SHA512: 6f1b0b29cc539e4b49b3594f9ad70be90cfff28e31497a8b85e11d8a2509faaa8ca803e542ea3280588ece5a065c4c54193cec87cad221f1abae34d8b13cfdc5
2026-04-09 14:26:40 -07:00
Ava Chow
7015f70920 Merge bitcoin/bitcoin#34886: test: Rework Single Random Draw coin selection tests
858a0a9c96 test: Add SRD maximum weight tests (Murch)
fe9f53bf0b test: Add SRD success tests (Murch)
2840f041c5 test: Rework SRD insufficient balance test (Murch)
64ab97466f Test: Add new minimum to tested feerates (Murch)
65900f8dc6 test: Init coin selection params with feerate (Murch)

Pull request description:

  This transfers the tests from the old coin selection test framework that was based on ignoring fees to the new coin selection framework that tests the coin selection algorithms with realistic feerates and fees.

  The PR also includes a minor improvement of the test framework to allow the CoinSelectionParams used by the tests to be initialized with other feerates, and adds some feerates around the new minimum feerate to the tested feerates.

ACKs for top commit:
  achow101:
    ACK 858a0a9c96
  w0xlt:
    ACK 858a0a9c96
  brunoerg:
    reACK 858a0a9c96

Tree-SHA512: cbd7ed3169d225a0b0f751481ca936a10939ff899c345e9469821d46083b04e835d164c50a72f18851544314611c3d596eb4956c1d86903c22e8b4996b8eb861
2026-04-09 14:07:04 -07:00
Ava Chow
7c6f1ab654 Merge bitcoin/bitcoin#35032: net_processing: don't modify addrman for private broadcast connections
1ed1a12402 net_processing: don't modify addrman for private broadcast connections (Vasil Dimov)

Pull request description:

  It is best if the internal addrman database is not modified with information coming from private broadcast connections because that information can potentially later be sent via other connections.

  instagibbs suggested this change, thank you!

ACKs for top commit:
  l0rinc:
    code review ACK 1ed1a12402
  instagibbs:
    ACK 1ed1a12402
  achow101:
    ACK 1ed1a12402
  andrewtoth:
    ACK 1ed1a12402
  danielabrozzoni:
    tACK 1ed1a12402

Tree-SHA512: 13845778445e56e3015a569f3b4165a749011e9dd67dcab38e960a368a0f5d3822173af5e3cb950998326549a021d1c8df644ce6d761cd46dd7597106b9ceec9
2026-04-09 13:25:46 -07:00
Ava Chow
94f1d35145 Merge bitcoin/bitcoin#34922: test: Use BasicTestingSetup when sufficient
2af003ae37 test: Use BasicTestingSetup when TestingSetup is not necessary (Hodlinator)
9ee77701dd refactor(test): Only specify TestChain100Setup in test cases (Hodlinator)

Pull request description:

  Improves run-times (4 warmups + 60 runs each):

  | test | improvement |
  |:---|---:|
  | checkqueue_tests | 1.12 |
  | merkle_tests | 1.14 |
  | orphanage_tests | 1.48 |
  | prevector_tests | 1.07 |
  | rbf_tests | 1.01 |
  | validation_tests | 1.60 |

  ---
  Removed overhead is barely measurable on full test suite runtime sequential `test_bitcoin`or parallel `ctest --test-dir build`.

  ---
  Initial version of PR also extracted a `DataDirTestingSetup` from `BasicTestingSetup`, making the latter not use the disk, but the added complexity didn't deliver sufficient speedups to clearly justify itself (at least not while running on NVMe).

  ---

  Follow-up to https://github.com/bitcoin/bitcoin/pull/34562#discussion_r2918752158
  Arguably in a similar vein as #22086.

ACKs for top commit:
  l0rinc:
    ACK 2af003ae37
  achow101:
    ACK 2af003ae37
  ryanofsky:
    Code review ACK 2af003ae37. Changes seem good: switching to minimum required test fixtures and avoiding expensive `TestChain100Setup` usage for whole fixtures.
  w0xlt:
    ACK 2af003ae37

Tree-SHA512: 56eba7595647447fd1940f205dac37605ae4b88f4947d542f1fc1c6c66791a7dbde244d4943f699dc11463e805725991d9d4db7f9be8c7f4d7054ca9dc2d79e1
2026-04-09 13:00:44 -07:00
Ryan Ofsky
141fbe4d53 Merge bitcoin/bitcoin#34884: validation: remove unused code in FindMostWorkChain
ba01b00d45 refactor: use for loops in FindMostWorkChain (stratospher)
aa0eef735b test: add InvalidateBlock/ReconsiderBlock asymmetry test (stratospher)
1b0b3e2c2c validation: remove redundant marking in FindMostWorkChain (stratospher)

Pull request description:

  recent PRs like #31405, #30666 mark all `m_block_index` descendants as invalid immediately whenever an invalid block is encountered in `SetBlockFailureFlags`. so by the time we reach `FindMostWorkChain`, the block in `setBlockIndexCandidates` already has `BLOCK_FAILED_VALID` set on it - not just on its ancestor. this means `pindexTest = pindexFailed` whenever `fFailedChain` fires, and the inner `while (pindexTest != pindexFailed)` loop body is never reached!

  I think we can remove it but I've just replaced it with `Assume` in this PR for safety + good to document this invariant in case the code changes in future. (noticed by @ stickies-v in https://github.com/bitcoin/bitcoin/pull/32950#discussion_r2815053885)

  the second commit is unrelated and adds a unit test for the situation in https://github.com/bitcoin/bitcoin/issues/32173

ACKs for top commit:
  fjahr:
    re-ACK ba01b00d45
  optout21:
    crACK ba01b00d45
  w0xlt:
    ACK ba01b00d45
  ryanofsky:
    Code review ACK ba01b00d45, just tweaking comment and for loop condition since last review.

Tree-SHA512: a8be3c30b1c41b76690d16d850e87e9e71fa6a1ecaa8b90ec997ffee1aace48b336a7009a480cd016103759d79c964b3d761a13ae936523808b2930beb68dae5
2026-04-09 09:11:22 -04:00
Vasil Dimov
1ed1a12402 net_processing: don't modify addrman for private broadcast connections
It is best if the internal addrman database is not modified with
information coming from private broadcast connections because that
information can potentially later be sent via other connections.

Co-authored-by: Greg Sanders <gsanders87@gmail.com>
Co-authored-by: Lőrinc <pap.lorinc@gmail.com>
2026-04-09 14:56:33 +02:00
merge-script
2b541eeb36 Merge bitcoin/bitcoin#34495: Replace boost signals with minimal compatible implementation
242b0ebb5c btcsignals: use a single shared_ptr for liveness and callback (Cory Fields)
b12f43a0a8 signals: remove boost::signals2 from depends and vcpkg (Cory Fields)
a4b1607983 signals: remove boost::signals2 mentions in linters and docs (Cory Fields)
375397ebd9 signals: remove boost includes where possible (Cory Fields)
091736a153 signals: re-add forward-declares to interface headers (Cory Fields)
9958f4fe49 Revert "signals: Temporarily add boost headers to bitcoind and bitcoin-node builds" (Cory Fields)
34eabd77a2 signals: remove boost compatibility guards (Cory Fields)
e60a0b9a22 signals: Add a simplified boost-compatible implementation (Cory Fields)
63c68e2a3f signals: add signals tests (Cory Fields)
edc2978058 signals: use an alias for the boost::signals2 namespace (Cory Fields)
9ade3929aa signals: remove forward-declare for signals (Cory Fields)
037e58b57b signals: use forwarding header for boost signals (Cory Fields)
2150153f37 signals: Temporarily add boost headers to bitcoind and bitcoin-node builds (Cory Fields)
fd5e9d9904 signals: Use a lambda to avoid connecting a signal to another signal (Cory Fields)

Pull request description:

  This drops our dependency on `boost::signals2`, leaving `boost::multi_index` as the only remaining boost dependency for bitcoind.

  `boost::signals2` is a complex beast, but we only use a small portion of it. Namely: it's a way for multiple subscribers to connect to the same event, and the ability to later disconnect individual subscribers from that event.

  `btcsignals` adheres to the subset of the `boost::signals2` API that we currently use, and thus is a drop-in replacement. Rather than implementing a complex `slot` tracking class that we never used anyway (and which was much more useful in the days before std::function existed), callbacks are simply wrapped directly in `std::function`s.

  The new tests work with either `boost::signals2` or the new `btcsignals` implementation. Reviewers can verify
  functional equivalency by running the tests in the commit that introduces them against `boost::signals2`, then again with `btcsignals`.

  The majority of the commits in this PR are preparation and cleanup. Once `boost::signals2` is no longer needed, it is removed from depends. Additionally, a few CMake targets no longer need boost includes as they were previously only required for signals.

  I think this is actually pretty straightforward to review. I kept things simple, including keeping types unmovable/uncopyable where possible rather than trying to define those semantics. In doing so, the new implementation has even fewer type requirements than boost, which I believe is due to a boost bug. I've opened a PR upstream for that to attempt to maintain parity between the implementations.

  See individual commits for more details.

  Closes #26442.

ACKs for top commit:
  fjahr:
    Code review ACK 242b0ebb5c
  maflcko:
    re-review ACK 242b0ebb5c 🎯
  w0xlt:
    reACK 242b0ebb5c

Tree-SHA512: 9a472afa4f655624fa44493774a63b57509ad30fb61bf1d89b6d0b52000cb9a1409a5b8d515a99c76e0b26b2437c30508206c29a7dd44ea96eb1979d572cd4d4
2026-04-09 16:25:47 +08:00
merge-script
f8ab0b778c Merge bitcoin/bitcoin#34905: Update string and net utils for future HTTP operations
0e712b3812 Make DynSock accepted sockets queue optional, with precise lifetime (Matthew Zipkin)
3de02abf3f util/test: Add string_view constructor to LineReader and remove StringToBuffer (Matthew Zipkin)
b0ca400612 string: replace AsciiCaseInsensitiveKeyEqual with CaseInsensitiveEqual (Matthew Zipkin)
8172099293 util: get number of bytes consumed from buffer by LineReader (Matthew Zipkin)

Pull request description:

  This is a follow-up to #34242 and is the first few commits of #32061

  As review and refinement of the replacement HTTP server progresses, some new utilities were needed and added. This PR updates those utilities as work continues on #32061.

  ### LineReader

  In order to enforce strict limits on the total size of headers in HTTPRequest, we add a method to `LineReader` to give us the total amount of data that has been read from the buffer so far. See https://github.com/bitcoin/bitcoin/pull/32061#discussion_r2949287329

  ### CaseInsensitiveEqual

  HTTP headers are case-insensitive. An early version of #32061 used an unordered_map for this and therefore we needed a comparator struct. However that unordered_map was replaced by a simpler `std::vector` of `std::pair` so we can remove the struct and use methods that already exist in the codebase.

  ### StringToBytes

  `StringToBuffer` was introduced in #34242 to test LineReader but review of #32061 indicated that it would be more optimal to return a span of bytes instead of a vector. See https://github.com/bitcoin/bitcoin/pull/32061#discussion_r2892431378

  ### Split DynSock constructor for two usecases: listening / accepting sockets

  See https://github.com/bitcoin/bitcoin/pull/32061#discussion_r2895891437. DynSock was introduced in #30988 and is not used anywhere in master yet. If it's used as a listening socket, it provides connected sockets. If it's used as a connected socket, it provides I/O pipes. By making the queue of connected sockets optional we can clean up the ownership / lifetime if the class members.

ACKs for top commit:
  fjahr:
    Code review ACK 0e712b3812
  vasild:
    ACK 0e712b3812

Tree-SHA512: 234c79a00c03cb3952dce2a3c5e59859bd0cbfc5f0a552ad2065e998320a12b533b06adbe294745c690a9e19c2f5f79bca3aa5a44342ee1820037342799566f2
2026-04-09 13:43:44 +08:00
merge-script
ab304b0ef2 Merge bitcoin/bitcoin#35031: ci: Match VCPKG_HOST_TRIPLET to VCPKG_TARGET_TRIPLET
c74c6cfd84 ci: Match `VCPKG_HOST_TRIPLET` to `VCPKG_TARGET_TRIPLET` (Hennadii Stepanov)

Pull request description:

  Using a non-default target triplet in https://github.com/bitcoin/bitcoin/pull/34883 introduced a [regression](https://github.com/bitcoin/bitcoin/pull/34883#issuecomment-4204744932) because packages with `"host": true` in their vcpkg configurations were still picking up the default `x64-windows` triplet, effectively building both release and debug packages.

  This PR fixes this regression by setting `VCPKG_HOST_TRIPLET` explicitly.

  Upstream issue: https://github.com/microsoft/vcpkg/issues/50927.

ACKs for top commit:
  hodlinator:
    utACK c74c6cfd84

Tree-SHA512: ee17d800a2db16eccfd2751da296c0c30d4d41f60e94513098be96116aedd83efe258349be824ff1f571c11adffac6a72e4a0c9b8b7278ab736d453ff7c089d6
2026-04-09 10:21:37 +08:00
Ava Chow
80572c7555 Merge bitcoin/bitcoin#34158: torcontrol: Remove libevent usage
1401011f71 test: Add test for exceeding max line length in torcontrol (Fabian Jahr)
84c1f32071 test: Add torcontrol coverage for PoW defense enablement (Fabian Jahr)
7dff9ec298 test: Add test for partial message handling in torcontrol (Fabian Jahr)
569383356e test: Add simple functional test for torcontrol (Fabian Jahr)
4117b92e67 fuzz: Improve torcontrol fuzz test (Fabian Jahr)
b1869e9a2d torcontrol: Move tor controller into node context (Fabian Jahr)
eae193e750 torcontrol: Remove libevent usage (Fabian Jahr)
8444efbd4a refactor: Get rid of unnecessary newlines in logs (Fabian Jahr)
6bcb60354e refactor: Modernize member variable names in torcontrol (Fabian Jahr)
a36591d194 refactor: Use constexpr in torcontrol where possible (Fabian Jahr)

Pull request description:

  This is part of the effort to remove the libevent dependency from our code base: https://github.com/bitcoin/bitcoin/issues/31194

  The current approach tries to reuse existing code and follows roughly similar design decisions. It replaces the libevent-based async I/O with blocking I/O utilizing the existing `Sock` and `CThreadInterrupt`. The controller runs in a dedicated thread.

  There are some optional code modernizations thrown in made along the way (namings, constexpr etc.). These are not strictly necessary but make the end result with the new code more consistent.

ACKs for top commit:
  achow101:
    ACK 1401011f71
  janb84:
    re ACK 1401011f71
  pinheadmz:
    ACK 1401011f71

Tree-SHA512: 167f1d98a634524568cb1d723e7bdb7234bade2c5686586caf2accea58c3308f83a32e0705edc570d6db691ae578a91e474ae4773f126ec2e1619d3adf7df622
2026-04-08 15:15:12 -07:00
Matthew Zipkin
0e712b3812 Make DynSock accepted sockets queue optional, with precise lifetime
When DynSock is used to represent a connected socket (e.g. a client)
the data I/O pipes are needed but not the m_accepted_sockets Queue,
because connected sockets do not create more connected sockets.

When DynSock is used to represent a listening socket, the Queue
is necessary to create connected sockets upon mocked connection, but
the Queue does not need to be a std::shared_ptr as long as it
is guaranteed to live as long as the DynSock.

Co-Authored by: Hodlinator <172445034+hodlinator@users.noreply.github.com>
2026-04-08 16:08:55 -04:00
Matthew Zipkin
3de02abf3f util/test: Add string_view constructor to LineReader and remove StringToBuffer
Co-Authored by: Hodlinator <172445034+hodlinator@users.noreply.github.com>
2026-04-08 16:08:55 -04:00
Matthew Zipkin
b0ca400612 string: replace AsciiCaseInsensitiveKeyEqual with CaseInsensitiveEqual
This reverts commit eea38787b9 from PR #34242

We do not need comparators for HTTPHeaders since it is not using unordered_map anymore.
We only need a simple, locale-independent, ascii-only compare function for
a vector of key-value pairs of strings.

We have CaseInsensitiveEqual already in test utils, this commit moves
it to the strencodings module for use in the application code.
2026-04-08 16:08:54 -04:00
Matthew Zipkin
8172099293 util: get number of bytes consumed from buffer by LineReader 2026-04-08 16:08:54 -04:00
stratospher
ba01b00d45 refactor: use for loops in FindMostWorkChain
Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
2026-04-08 23:11:21 +05:30
stratospher
aa0eef735b test: add InvalidateBlock/ReconsiderBlock asymmetry test
InvalidateBlock propagates to all descendants in m_block_index,
but ReconsiderBlock only clears blocks on the same chain as the
reconsidered block (its direct ancestors and descendants).
Blocks on sibling forks are not cleared. This asymmetry can
lead to edge cases like in issue #32173 (fixed in 37bc207).

Add a unit test for this scenario to safeguard against future
regressions.
2026-04-08 23:11:20 +05:30
stratospher
1b0b3e2c2c validation: remove redundant marking in FindMostWorkChain
since ed764ea, all descendants in m_block_index are required to be
marked BLOCK_FAILED_VALID when an invalid block is encountered,
as enforced by a CheckBlockIndex assert.

remove the now-redundant marking in FindMostWorkChain's inner loop,
so it is only responsible for cleaning up setBlockIndexCandidates,
not for modifying block validity state
2026-04-08 23:11:19 +05:30
Hennadii Stepanov
c74c6cfd84 ci: Match VCPKG_HOST_TRIPLET to VCPKG_TARGET_TRIPLET
Using a non-default target triplet introduced a regression because
packages with `"host": true` in their vcpkg configurations were still
picking up the default `x64-windows` triplet, effectively building both
release and debug packages.

Fix this regression by setting `VCPKG_HOST_TRIPLET` explicitly.
2026-04-08 10:24:03 +01:00
Ava Chow
d2844c6a4f Merge bitcoin/bitcoin#35014: test: remove macOS REDUCE_EXPORTS exception workaround
b555a0b789 test: remove macOS REDUCE_EXPORTS exception workaround (Alfonso Roman Zubeldia)

Pull request description:

  Fixes #34723.

    The underlying fix was merged in #34977 (subtree update from bitcoin-core/libmultiprocess#268). This PR
    removes the test workaround that accepted the degraded unknown non-KJ exception of type: `kj::Exception`
    error message on Darwin.

    Tested: `interface_ipc_mining.py` passes on macOS (arm64) with REDUCE_EXPORTS=ON.

ACKs for top commit:
  achow101:
    ACK b555a0b789
  ryanofsky:
    Code review ACK b555a0b789. Thanks for the fixes!
  w0xlt:
    ACK b555a0b789

Tree-SHA512: fa5a316db2ed9ce67dabbd7c529818664dfca01faeb7aff9c5cbb9a1b876de3f498f675eae4bdb74de71e73b7b8cf8cc85c44f520e59f9e3e7a6d6c442ea8273
2026-04-07 15:50:49 -07:00
Murch
858a0a9c96 test: Add SRD maximum weight tests
Also:
- Add weight check to Success cases.

Per the introduction of TRUC transactions, it is more likely that we
will attempt to build transactions of limited weight (e.g., TRUC child
transactions may not exceed 4000 WU). When SRD exceeds the input weight
limit, it evicts the OutputGroup with the lowest effective value before
selecting additional UTXOs: we test that SRD will find a solution that
depends on the eviction working correctly, and that it fails as expected
when no solution is possible.
2026-04-07 15:48:30 -07:00
Murch
fe9f53bf0b test: Add SRD success tests
Previously, SRD had only failure and edge-case coverage, so we add a few
simple coin selection targets that should quickly succeed, including one
that will create a minimal change output.
2026-04-07 15:48:29 -07:00
Murch
2840f041c5 test: Rework SRD insufficient balance test
This refactor is part of the effort to move the coin selection tests to
a framework that can use non-zero, realistic feerates. The insufficient
funds failure case is extended with a few additional similar variants of
the failure.
2026-04-07 15:48:27 -07:00
Murch
64ab97466f Test: Add new minimum to tested feerates
The default minimum feerate was lowered from 1000 s/kvB to 100 s/kvB.
This adjusts the set of feerates used in the tests to accommodate that
new feerate and to cover other potential special cases:
- zero: 0 s/kvB
- minimum non-zero s/kvB: 1 s/kvB
- just below the new default minimum feerate: 99 s/kvB
- new default minimum feerate: 100 s/kvB
- old default minimum feerate: 1000 s/kvB
- a few non-round realistic feerates around default minimum feerate,
dust feerate, and default LTFRE: 315 s/kvB, 2345 s/kvB, and
10'292 s/kvB
- a high feerate that has been exceeded occassionally: 59'764 s/kvB
- a huge feerate that is extremely uncommon: 1'500'000 s/kvB
2026-04-07 15:48:25 -07:00
Murch
65900f8dc6 test: Init coin selection params with feerate
The most frequent change to CoinSelectionParams so far seems to be
amendments to the feerate, and the feerate propagates to other members
of the CoinSelectionParams, so we add it as an input parameter.

This also adds the CoinSelectionParams to the BnBFail tests, which
previously were always run with the default CoinSelectionParams.
2026-04-07 15:48:23 -07:00
Ryan Ofsky
82235bbf2b Merge bitcoin/bitcoin#34988: rpc: fix initialization-order-fiasco by lazy-init of decodepsbt_inputs
d517fa0a94 rpc: fix initialization-order-fiasco by lazy-init of decodepsbt_inputs (Eugene Siegel)

Pull request description:

  Prior to this commit, `decodepsbt_inputs` would call `TxDoc` during initialization which lives in another TLU. `TxDoc` relies on `CURRENCY_UNIT` to be initialized when it may not have been (note this is different from the TLU containing `decodepsbt_inputs` which also has a `CURRENCY_UNIT`). Fix this by lazy initializing `decodepsbt_inputs`. Also prevent the issue in the future by doing the same for `decodepsbt_outputs` and `getblock_vin`.

  Curious why the CI missed this, it broke fuzzamoto. It was introduced in fadf901fd4. I was able to trigger this with clang-21 and `ASAN_OPTIONS="detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1"`:

  ```
  =================================================================
  ==926804==ERROR: AddressSanitizer: initialization-order-fiasco on address 0x5631e5784288 at pc 0x5631e3309f9c bp 0x7ffdb6abc7b0 sp 0x7ffdb6abc7a8
  READ of size 8 at 0x5631e5784288 thread T0
      #0 0x5631e3309f9b in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::size() const /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/basic_string.h:1064:16
      #1 0x5631e3309f9b in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> std::operator+<char, std::char_traits<char>, std::allocator<char>>(char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/bits/basic_string.tcc:618:35
      #2 0x5631e4238948 in TxDoc(TxDocOptions const&) /root/bitcoin/src/rpc/rawtransaction_util.cpp:382:76
      #3 0x5631e316945e in __cxx_global_var_init.9 /root/bitcoin/src/rpc/rawtransaction.cpp:784:17
      #4 0x5631e3186355 in _GLOBAL__sub_I_rawtransaction.cpp /root/bitcoin/src/rpc/rawtransaction.cpp
      #5 0x7fa6ca046375 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x27375) (BuildId: 79005c16293efa45b441fed45f4f29b138557e9e)
      #6 0x5631e31cf160 in _start (/root/bitcoin/build/bin/bitcoind+0x25b160)

  0x5631e5784288 is located 56 bytes before global variable 'CURRENCY_ATOM[abi:cxx11]' defined in '/root/bitcoin/src/policy/feerate.h:20' (0x5631e57842c0) of size 32
    registered at:
      #0 0x5631e31e5738 in __asan_register_globals /root/llvm-project/compiler-rt/lib/asan/asan_globals.cpp:431:3
      #1 0x5631e31e68a9 in __asan_register_elf_globals /root/llvm-project/compiler-rt/lib/asan/asan_globals.cpp:414:3

  0x5631e5784288 is located 8 bytes inside of global variable 'CURRENCY_UNIT[abi:cxx11]' defined in '/root/bitcoin/src/policy/feerate.h:19' (0x5631e5784280) of size 32
    registered at:
      #0 0x5631e31e5738 in __asan_register_globals /root/llvm-project/compiler-rt/lib/asan/asan_globals.cpp:431:3
      #1 0x5631e31e68a9 in __asan_register_elf_globals /root/llvm-project/compiler-rt/lib/asan/asan_globals.cpp:414:3

  SUMMARY: AddressSanitizer: initialization-order-fiasco /root/bitcoin/src/rpc/rawtransaction_util.cpp:382:76 in TxDoc(TxDocOptions const&)
  Shadow bytes around the buggy address:
    0x5631e5784000: f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6
    0x5631e5784080: f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6
    0x5631e5784100: f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6
    0x5631e5784180: f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6
    0x5631e5784200: f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6
  =>0x5631e5784280: f6[f6]f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6
    0x5631e5784300: f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6
    0x5631e5784380: f6 f6 f6 f6 01 f9 f9 f9 f6 f6 f6 f6 f6 f6 f6 f6
    0x5631e5784400: f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6
    0x5631e5784480: f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6
    0x5631e5784500: f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 f6 00 00 00 00
  Shadow byte legend (one shadow byte represents 8 application bytes):
    Addressable:           00
    Partially addressable: 01 02 03 04 05 06 07
    Heap left redzone:       fa
    Freed heap region:       fd
    Stack left redzone:      f1
    Stack mid redzone:       f2
    Stack right redzone:     f3
    Stack after return:      f5
    Stack use after scope:   f8
    Global redzone:          f9
    Global init order:       f6
    Poisoned by user:        f7
    Container overflow:      fc
    Array cookie:            ac
    Intra object redzone:    bb
    ASan internal:           fe
    Left alloca redzone:     ca
    Right alloca redzone:    cb
  ==926804==ABORTING

  ```

  Can be reviewed with `git diff HEAD~1 -w` since it's mostly indentation.

ACKs for top commit:
  davidgumberg:
    crACK d517fa0a94
  nervana21:
    tACK d517fa0a94
  dergoegge:
    tACK d517fa0a94

Tree-SHA512: cfcaf4baccbb5748ab10ba5537cfacf38d7137b7ff051ccb9aba0f673718be1532487586b4f4e6d2f4526ca1786733009bd73a870d79a966b9c1fb38f7aaf5cc
2026-04-07 16:53:57 -04:00
Alfonso Roman Zubeldia
b555a0b789 test: remove macOS REDUCE_EXPORTS exception workaround
The underlying issue was fixed in bitcoin-core/libmultiprocess#268.

Remove the workaround that accepted degraded error messages on Darwin.
2026-04-07 17:40:43 -03:00
Ava Chow
1d7edee34c Merge bitcoin/bitcoin#34977: Update libmultiprocess subtree to fix test timeout
7a6d210989 Squashed 'src/ipc/libmultiprocess/' changes from 70f632bda8..3edbe8f67c (Sjors Provoost)

Pull request description:

  - https://github.com/bitcoin-core/libmultiprocess/pull/266
  - https://github.com/bitcoin-core/libmultiprocess/pull/267
  - https://github.com/bitcoin-core/libmultiprocess/pull/268

  Branch is based on 613a548648 from #34804 for easy backport.

  Fixes #34975.

ACKs for top commit:
  achow101:
    ACK 66b4e30ec8
  ryanofsky:
    Code review ACK 66b4e30ec8. Reviewed changes and verified subtree matches. Since this branch is based on 613a548648 it can be merged into both 31.x and master branches (if another PR is opened for 31.x).

Tree-SHA512: 63449236b206f07541f7ea295111eef9a2ddfd1da986b8ce2068c59201e92c36f30f9bde5478bf4b704208e71b10352140649a54b7671e1d8af4869917125f47
2026-04-07 13:33:11 -07:00
Hodlinator
2af003ae37 test: Use BasicTestingSetup when TestingSetup is not necessary 2026-04-07 22:00:16 +02:00
Hodlinator
9ee77701dd refactor(test): Only specify TestChain100Setup in test cases
Reduces risk for accidental use of costly TestChain100Setup in later added test cases.
2026-04-07 22:00:16 +02:00
Ryan Ofsky
d868667fdc Merge bitcoin/bitcoin#34985: fuzz: remove GetDescriptorChecksum from string harness
91cd0e3aaa fuzz: remove GetDescriptorChecksum from string harness (Bruno Garcia)

Pull request description:

  This function is already strongly fuzzed by other harness. E.g: descriptor_parse calls it several times during parsing and serialization. Also, calling GetDescriptorChecksum with a string of length 32 is not effective to exercise it.

ACKs for top commit:
  frankomosh:
    utACK 91cd0e3aaa
  sipa:
    ACK 91cd0e3aaa. I don't think this tests anything useful.

Tree-SHA512: ac5e5c3f04669d4f7c24c25390565b02350ac2d4b1044aa1b3b9b83b3a70e57b3a109bd8d58298e722ce97d4a76efc62f11b31147a810a65db7ac592606acc3c
2026-04-07 13:55:42 -04:00
Sjors Provoost
66b4e30ec8 Merge commit '7a6d210989af56a03d7efa79f1f3a90047bb88fe' into 2026/04/libmultiprocess-subtree 2026-04-07 17:01:45 +02:00
Sjors Provoost
7a6d210989 Squashed 'src/ipc/libmultiprocess/' changes from 70f632bda8..3edbe8f67c
3edbe8f67c Merge bitcoin-core/libmultiprocess#268: Use throwRecoverableException instead of raw throw for stored exceptions
23be44b0d3 Use throwRecoverableException instead of raw throw for stored exceptions
75c2a2764c Merge bitcoin-core/libmultiprocess#266: test: increase spawn test child timeout to 30 seconds
8b5f805301 Merge bitcoin-core/libmultiprocess#267: doc: Bump version 9 > 10
cc0b23fc32 test: increase spawn test child timeout to 30 seconds
050f878db8 doc: Improve versions.md descriptions and formatting
c6a288a889 doc: Bump version 9 > 10

git-subtree-dir: src/ipc/libmultiprocess
git-subtree-split: 3edbe8f67c182dde91c0050065d79ae268722489
2026-04-07 17:01:45 +02:00
merge-script
485ebad1ee Merge bitcoin/bitcoin#33385: contrib: Add bash completion for new bitcoin command
39668f1eeb contrib: Add bash completion for new bitcoin command (CaesarCoder)

Pull request description:

  Adds a bash completion script for the new bitcoin command-line tool (introduced in #31375), which unifies the main Bitcoin Core executables under a single interface. This feature improves usability, reduces errors, and makes the command-line tools more easily discoverable for users working in a Linux bash environment.

  The completion script dynamically lists available commands and options by parsing `bitcoin --help` and `bitcoin help`. It also incorporates the existing bash completions for `bitcoind`, `bitcoin-cli`, and `bitcoin-tx`, depending on the argument provided (`node`, `gui`, `rpc`, or `tx`). This ensures that all relevant completions are available seamlessly through a single interface without modifying core functionality.

  **Key points:**
  - Improves developer and user experience on the command line.
  - Does not modify or replace existing functionality.
  - Placed under `contrib/` for easy installation by users and distributions.

ACKs for top commit:
  willcl-ark:
    ACK 39668f1eeb
  BrandonOdiwuor:
    Tested ACK 39668f1eeb

Tree-SHA512: a84cd53adefbdf69ec510584d6117b70e1b6131686502170c53b6a3a23bc5431244a47e72a323111c5a07aa75d267aaeaa52bab0837901431db1c8b1d266723e
2026-04-07 22:25:09 +08:00
merge-script
996e4f7edd Merge bitcoin/bitcoin#35001: validation: Remove stale BlockManager param from ContextualCheckBlockHeader
851152e42a validation: Remove stale BlockManager param in ContextualCheckBlockHeader (ismaelsadeeq)

Pull request description:

  The `BlockManager`  reference in `ContextualCheckBlockHeader`  is unused.

  Fix this by removing it from the function parameter list.
  Remove `BlockManager`  reference argument in `ContextualCheckBlockHeader` invocations.

ACKs for top commit:
  maflcko:
    lgtm ACK 851152e42a
  stratospher:
    ACK 851152e. not used anymore since checkpoints were removed in 3c5d1a4.

Tree-SHA512: 4d4c32cfc8c280774271ab1b5daff32b330030c3c4f275713836d7d2030c1842cab8a6f7758318fbe760c9158938a49d772246e1e328302ad2f8505e44e55695
2026-04-07 16:50:42 +08:00
Ava Chow
b730dc3301 Merge bitcoin/bitcoin#34208: bench: add fluent API for untimed setup steps in nanobench
8825051e08 refactor: improve benchmark setup and execution for various tests (Lőrinc)
83b8528ddb bench: add fluent API for untimed setup steps in `nanobench` (Lőrinc)

Pull request description:

  ### Context
  As described in https://github.com/martinus/nanobench/issues/130, we have a few benchmarks where we have to reset the state between runs; otherwise, the repetitions will do something different than the first iteration.

  ### Upstream
  I have opened a PR to `nanobench` to introduce an untimed setup phase, see: https://github.com/martinus/nanobench/pull/136

  ### Tests

  Tests were only added upstream. It would be a bit awkward to wire them into `nanobench.h` outside the benchmarking setup:
  58350cfe59 (diff-88160f647ce57661afe7d755fa70a5fa342a2b79d72d3511596878e69ed5cdc3)

  ### Fix
  I have moved the changes here as well and applied them to a few simple benchmarks as a demonstration.
  We can revert the ones that are controversial and add others in follow-ups. This PR is mostly meant to add the `setup` feature.

  ### Benchmarks
  Most benchmarks show a modest "speedup"; others a "slowdown" - but it's only the effect of the setup that's not measured anymore - and a `run` phase that does the same operation in each epoch iteration (wallet benchmark changes were reverted for simplicity):
  <img width="1496" height="882" alt="image" src="https://github.com/user-attachments/assets/34c14565-f3df-41e5-9a86-95b2ca21703a" />

ACKs for top commit:
  achow101:
    ACK 8825051e08
  janb84:
    re ACK 8825051e08
  sedited:
    ACK 8825051e08

Tree-SHA512: b3e385abcfca013a21b3785b0b837c2b61e302d71a098dadcd8d2f0cb42f6bbf4a222299771443f095962d1b24e696d5684f2b8efdb6f63f2f939699961cdf0d
2026-04-06 13:55:13 -07:00
merge-script
74e7518088 Merge bitcoin/bitcoin#34989: doc: remove stale shortid collision TODO
fc9987dfc6 doc: remove stale shortid collision TODO (w0xlt)

Pull request description:

  `PartiallyDownloadedBlock::InitData()` already treats duplicate short IDs in a compact block as `READ_STATUS_FAILED`.

  For an honest peer, block-level short-ID collisions are rare enough that failing the compact block early is preferable to scanning the mempool or attempting selective recovery (see https://github.com/bitcoin/bitcoin/pull/34932#issuecomment-4139177024)

  This removes the old TODO suggesting that both collided transactions should be requested, since that comment no longer matches the intended handling.

  No behavior change. Comment-only cleanup.

ACKs for top commit:
  l0rinc:
    ACK fc9987dfc6
  instagibbs:
    ACK fc9987dfc6

Tree-SHA512: 46d8a64076e29b6dd6b6ccbfc74101da00dea0c7e88a94b10136585b8df82bb328a4922aa9ac1cd0dfc7f9d491b3fff59492e2d445d91e48668fe0c375a70a85
2026-04-06 20:52:58 +08:00
merge-script
8edb13dbdd Merge bitcoin/bitcoin#34967: doc: Discourage trailing doxygen comments, and fix the broken ones
facaeb9c76 doc: Discourage trailing doxygen comments, and fix the broken ones (MarcoFalke)

Pull request description:

  The trailing doxygen comments are problematic:

  * They are often wrong and need to be fixed up manually, see e.g https://github.com/bitcoin/bitcoin/pull/7793, https://github.com/bitcoin/bitcoin/pull/14331, ..., and this pull
  * Also, changing any type or name in a way that changes the max line length may require reflowing the whole struct with clang-format.
  * Also, once they become multi-line, they will read even more confusingly.

  Fix all issues by tolerating them, but favoring descriptions before the described item.

  Also, fix the broken ones.

  Example doxygen rendering: https://doxygen.bitcoincore.org/struct_private_broadcast_1_1_send_status.html (broken before this pull, fixed in this pull)

ACKs for top commit:
  l0rinc:
    ACK facaeb9c76
  stickies-v:
    ACK facaeb9c76

Tree-SHA512: db725140bd907ac61f2fe58681d4a23f392ef712ef8772564f3a3d83ed446e068bb390907ee30c2015d8b396a42a31817f56b8dcb2d86d1314aed9208a86e2bd
2026-04-06 18:42:26 +08:00
ismaelsadeeq
851152e42a validation: Remove stale BlockManager param in ContextualCheckBlockHeader 2026-04-04 02:36:33 +01:00
Ava Chow
a7c30da1f6 Merge bitcoin/bitcoin#34873: net: fix premature stale flagging of unpicked private broadcast txs
325afe664d net: delay stale evaluation and expose time_added in private broadcast (Mccalabrese)
999d18ab1c net: introduce TxSendStatus internal state container (Mccalabrese)

Pull request description:

  **Motivation**
  Currently, freshly added transactions in `private_broadcast` are almost immediately flagged and logged as stale by the `resend-stale` job.

  **The Bug**
  `m_transactions` maps a transaction to a `std::vector<SendStatus>`. When `try_emplace` adds a new transaction, this vector is empty. When `GetStale()` runs, `DerivePriority()` evaluates the empty vector and returns a default `Priority` struct where `last_confirmed` evaluates to the Unix Epoch (Jan 1, 1970). The stale checker sees a 50-year-old timestamp and flags it on the next resend-stale cycle.

  **The Fix**
  Rather than modifying the transient `Priority` struct or creating a "Zombie Transaction" edge case by ignoring transactions with 0 picks, this PR modifies the state container:
  * Wraps the `SendStatus` vector in a new `TxSendStatus` struct inside `private_broadcast.h`.
  * `TxSendStatus` automatically captures `time_added` upon emplace.
  * `GetStale()` now checks `p.num_confirmed == 0` to measure age against `time_added` using a new 5-minute `INITIAL_STALE_DURATION` grace period, falling back to `last_confirmed` and the standard 1-minute `STALE_DURATION` once network interaction begins.

  **Additional Polish**
  * Exposed `time_added` via the `getprivatebroadcastinfo`  RPC endpoint so users can see when a transaction entered the queue.
  * Added a dedicated `stale_unpicked_tx` test case and updated `private_broadcast_tests.cpp` to properly mock the passage of time for the new grace period.
  Closes #34862

ACKs for top commit:
  achow101:
    ACK 325afe664d
  andrewtoth:
    ACK 325afe664d
  vasild:
    ACK 325afe664d

Tree-SHA512: b7790aa5468f7c161ed93e99e9a6d8b4db39ff7d6d6a920764afd18825e08d83bc30b3fb0debeb6175730b5d2496c6be67f3be8674be93f4d07b1e77d17b4a14
2026-04-03 17:46:32 -07:00
Fabian Jahr
1401011f71 test: Add test for exceeding max line length in torcontrol
Also deduplicates the repetitive tor mock setup for each test case a bit.

Co-authored-by: janb84 <githubjanb.drainer976@passmail.net>
2026-04-03 22:00:30 +02:00
Fabian Jahr
84c1f32071 test: Add torcontrol coverage for PoW defense enablement 2026-04-03 22:00:29 +02:00
Fabian Jahr
7dff9ec298 test: Add test for partial message handling in torcontrol 2026-04-03 22:00:29 +02:00
Fabian Jahr
569383356e test: Add simple functional test for torcontrol 2026-04-03 22:00:29 +02:00
Fabian Jahr
4117b92e67 fuzz: Improve torcontrol fuzz test
Gets rid of the Dummy class and adds coverage of get_socks_cb.

Also explicitly handles an exception case within Torcontrol rather than
relying on a guard in the fuzz test.
2026-04-03 22:00:29 +02:00
Fabian Jahr
b1869e9a2d torcontrol: Move tor controller into node context
Co-authored-by: sedited <seb.kung@gmail.com>
2026-04-03 22:00:29 +02:00
Fabian Jahr
eae193e750 torcontrol: Remove libevent usage
Replace libevent-based approach with using the Sock class and CThreadInterrupt.
2026-04-03 22:00:26 +02:00
Cory Fields
242b0ebb5c btcsignals: use a single shared_ptr for liveness and callback
This simplifies the implementation and eliminates an unnecessary shared_ptr.

Suggested by Marco Falke.

<Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>
2026-04-03 18:25:30 +00:00
Cory Fields
b12f43a0a8 signals: remove boost::signals2 from depends and vcpkg 2026-04-03 18:20:50 +00:00
Cory Fields
a4b1607983 signals: remove boost::signals2 mentions in linters and docs
The documented example is no longer relevant, so remove it rather than updating
it to mention btcsignals.
2026-04-03 18:20:50 +00:00