Commit Graph

6607 Commits

Author SHA1 Message Date
merge-script
44ac0c32b9 Merge bitcoin/bitcoin#34401: kernel: add serialization method for btck_BlockHeader API
577a3e74c8 test: Add check for return type in `HasToBytes` concept (yuvicc)
1ad551281a kernel: Add Block Header serialization method (yuvicc)
86662623ec Add `SpanWriter` class for zero-allocation stream writing (yuvicc)

Pull request description:

  This adds serialization for `btck_BlockHeader` API. Also, updated the `CheckHandle` to compare the byte content instead of size.

  The changes here is done in two commits. First commit adds the `SpanWriter` class and next one moves the block header serialization to `SpanWriter`. See commit message for more details.

  Follow-up to #33822 .

ACKs for top commit:
  stickies-v:
    re-ACK 577a3e74c8
  alexanderwiederin:
    ACK 577a3e74c8
  theStack:
    Code-review ACK 577a3e74c8
  w0xlt:
    ACK 577a3e74c8

Tree-SHA512: 1eda5b204588ccb23e9357f68c5529474e7d248736a371c47d8db71ba6ca95e121869514478ad7a519d190e4c30725f64fd1ef4dd9f97d2627dc4441e51458e0
2026-04-15 15:47:33 +01:00
yuvicc
577a3e74c8 test: Add check for return type in HasToBytes concept
Add return type check for `ToBytes()` which should be convertible to
`std::span<const std::byte>`.
2026-04-14 19:19:41 +05:30
yuvicc
1ad551281a kernel: Add Block Header serialization method
Add `btck_block_header_to_bytes` serialization method to serialize a
`btck_BlockHeader` into an 80-byte buffer using `SpanWriter` to ensure
zero-allocation serialization.
2026-04-14 19:19:41 +05:30
yuvicc
86662623ec Add SpanWriter class for zero-allocation stream writing
Co-authored-by: stickies-v <stickies-v@protonmail.com>
2026-04-14 19:19:37 +05:30
Ryan Ofsky
976985eccd Merge bitcoin/bitcoin#34124: validation: make CCoinsView a pure virtual interface
8783cc8056 refactor: inline `CCoinsViewBacked` implementation (Lőrinc)
86296f276d coins: make `CCoinsView` methods pure virtual (Lőrinc)
b637566c8d coins: add explicit `CoinsViewEmpty` noop backend (Lőrinc)
90c635c01c fuzz: keep backend assertions aligned to active backend (Lőrinc)
a9f92e3497 refactor: normalize CCoinsView whitespace and signatures (Lőrinc)
38a99f3344 scripted-diff: normalize `CCoinsView` naming (Lőrinc)
06172ef0d5 refactor: rename `hashBlock` to `m_block_hash` to avoid shadowing (Lőrinc)

Pull request description:

  ### Problem
  `CCoinsView` is the coins view interface, but historically it also provided built-in no-op behavior:

  * It provided default no-op implementations (returning `std::nullopt`, `uint256()`, `false`, or `nullptr`) instead of being pure virtual.
  * Callers could instantiate a bare `CCoinsView` and get silent no-op behavior.
  * Mixing the interface definition with a built-in dummy implementation blurred the abstraction boundary.

  ### Context
  This is part of the ongoing coins caching cleanup in #34280.

  ### Fix
  This PR separates the interface from no-op behavior and makes `CCoinsView` pure virtual in incremental steps:
  * Add `CoinsViewEmpty` as an explicit no-op coins view for tests, benchmarks, and temporary backends.
  * Replace direct bare-`CCoinsView` test and dummy instantiations with `CoinsViewEmpty`.
  * Make all `CCoinsView` methods pure virtual (`PeekCoin`, `GetCoin`, `HaveCoin`, `GetBestBlock`, `GetHeadBlocks`, `BatchWrite`, `Cursor`, `EstimateSize`).
  * Remove the legacy default implementations from `coins.cpp`.
  * Update fuzz and dummy backends to use `CoinsViewEmpty` explicitly.

ACKs for top commit:
  w0xlt:
    reACK 8783cc8056
  ryanofsky:
    Code review ACK 8783cc8056. Just updated comments and variable name since last review. The fuzz test code is much clearer now IMO
  andrewtoth-exo:
    ACK 8783cc8056
  ajtowns:
    ACK 8783cc8056

Tree-SHA512: cfc831578aa309788c1b5dafbfecca3de388cc4215534c3f3df24f90d7770ed37b1fd7aa134df91d611d0a1ca75929accb98d5ed7df7b52851c259e04f08e4a3
2026-04-13 08:40:36 -04:00
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
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
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
Lőrinc
86296f276d coins: make CCoinsView methods pure virtual
`CCoinsView` provided default no-op implementations, which allowed constructing a bare view and silently getting dummy behavior.
Make all interface methods pure virtual and remove the legacy default definitions from `coins.cpp` so callers must choose an explicit implementation.
Move the virtual destructor to the beginning to avoid mixing it between the methods.
No-op backing behavior remains available via `CoinsViewEmpty`.
2026-04-08 22:36:13 +02:00
Lőrinc
b637566c8d coins: add explicit CoinsViewEmpty noop backend
Introduce `CoinsViewEmpty` as an explicit no-op `CCoinsView` implementation, and define its singleton accessor out of line in `coins.cpp` to avoid `-Wunique-object-duplication` in shared-library builds.`
Use it at call sites that intentionally want a no-op backend instead of constructing anonymous placeholder views.

`CCoinsViewTest` and `CoinsViewBottom` now inherit defaults from `CoinsViewEmpty` (e.g. the unused `EstimateSize()`, which now returns 0).

Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
2026-04-08 22:36:13 +02:00
Lőrinc
90c635c01c fuzz: keep backend assertions aligned to active backend
`TestCoinsView` switches the `CCoinsViewCache` backend during fuzzing and then queries the backend for cross-checks.
Pass the backend as a `CCoinsView*` (to make it relocatable) and retarget it when toggling between the original backend and a local empty `CCoinsView` so assertions always refer to the active backend. This will be switched to a singleton in the next commit.

Note that the previous slice-assignment (`backend_coins_view = CCoinsView{}`) was a silent noop for the db target, it only copied base-class members (none) without changing the vtable, so the backend was never actually switched.
The pointer approach makes the switch real for both targets, which revealed that when restoring the original backend after the empty one, the cache must be reset first to avoid carrying FRESH flags that were valid relative to the empty backend but invalid relative to the original (which may already contain those coins).

Co-authored-by: Anthony Towns <aj@erisian.com.au>
Co-authored-by: Andrew Toth <andrewstoth@gmail.com>
Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
Co-authored-by: marcofleon <marleo23@proton.me>
2026-04-08 22:36:12 +02:00
Lőrinc
38a99f3344 scripted-diff: normalize CCoinsView naming
Standardize coins view naming with a mechanical rename pass.
This keeps subsequent commits focused on the interface and behavioral changes.

Co-authored-by: Andrew Toth <andrewstoth@gmail.com>

-BEGIN VERIFY SCRIPT-
git grep -qE '\bin_base\b|\bin_view\b|\bin_block_hash\b|\bblock_hash\b' -- src/coins.cpp src/coins.h src/txdb.cpp src/txdb.h src/test/coins_tests.cpp && { echo "Error: target names already exist in scoped files"; exit 1; }

perl -pi -e '
  s/\bbaseIn\b/in_base/g;
  s/\bhashBlockIn\b/in_block_hash/g;
  s/\bhashBlock\b/block_hash/g;
  s/\bviewIn\b/in_view/g;
  ' src/coins.cpp src/coins.h src/txdb.cpp src/txdb.h src/test/coins_tests.cpp
-END VERIFY SCRIPT-
2026-04-08 22:25:52 +02: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
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
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
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
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
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
34eabd77a2 signals: remove boost compatibility guards
These were necessary to work around unnecessary constraints that have been
fixed in the (upcoming) boost::signals2 version 1.91.

Our implementation's constraints match those of that version.
2026-04-03 18:20:50 +00:00
Cory Fields
63c68e2a3f signals: add signals tests
These tests are compatible with boost::signals2 as well as the replacement
implementation that will be introduced in the next commit.

This is intended to demonstrate some equivalency between the implementations.
2026-04-03 17:11:28 +00:00
Ava Chow
4b98962731 Merge bitcoin/bitcoin#34448: ci, iwyu: Fix warnings in src/util and treat them as errors
8b49e2dd4e ci, iwyu: Fix warnings in `src/util` and treat them as errors (Hennadii Stepanov)
6953363be8 refactor: Move license info into new module (Hennadii Stepanov)
eb750d277b iwyu: Remove workaround for issue that has been fixed upstream (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:
  achow101:
    ACK 8b49e2dd4e
  maflcko:
    review ACK 8b49e2dd4e 👘
  BrandonOdiwuor:
    Code Review ACK 8b49e2dd4e

Tree-SHA512: f6a21d58947f714be7ad3c230857a7c974ac4c1b5099f1e8e8db9b6e3e01ba12270481e39a1c3cb8d93f326cea4f33c662becc65c80e46a38c6b49bb0c2f523f
2026-04-02 15:48:53 -07:00
Ava Chow
59199fa5ea Merge bitcoin/bitcoin#33908: kernel: add context‑free block validation API (btck_check_block_context_free) with POW/Merkle flags
0587c56091 kernel: Expose context-free block validation (w0xlt)
71f827c3c2 kernel: Expose consensus parameters (`btck_ConsensusParams`) (w0xlt)

Pull request description:

  This PR exposes Bitcoin Core’s context‑free block checks to library users via a new C API entry point, `btck_check_block_context_free`.

  Callers can validate a block’s structure (size/weight, coinbase rules, per‑tx context‑free checks) and optionally re‑run Proof‑of‑Work and Merkle‑root verification without touching chainstate, the block index, or the UTXO set.

  Rationale
  Clients embedding the kernel need a pure block sanity check without requiring node state or disk writes (candidate block validation, for example). This API offers that surface in a single call, with optional PoW/Merkle toggles to avoid redundant work when the header has already been validated or when Merkle verification is deferred.

ACKs for top commit:
  yuvicc:
    re-ACK 0587c56091
  achow101:
    ACK 0587c56091
  sedited:
    ACK 0587c56091

Tree-SHA512: 6bd53e4964909335d1f2fee30ff96c95a8dd2c84bcdfe11c50ba369301822e5dea9bbe2376bb6d6b4652875152071eb0446657042b00429f29581da4fcea71a9
2026-04-02 15:28:07 -07:00
Ava Chow
52c3381fa8 Merge bitcoin/bitcoin#33506: test: sock: Enable all socket tests on Windows
9316d96240 test: sock: Enable socket pair tests on Windows (David Gumberg)

Pull request description:

  Some `class Sock`  tests were previously disabled because Windows lacks [`socketpair(2)`](https://man7.org/linux/man-pages/man2/socketpair.2.html) which is used as a helper function in the socket tests, but is not strictly necessary or related to the `Socket` class under testing. This PR adds a `CreateSocketPair()` helper which creates a sender socket and receiver socket with a TCP connection, enabling these test cases for Windows. This also enables future tests that require more granular control over sockets than what `socketpair()` allows for, like using `setsockopt()` before connecting a socket.

  This change is generally an improvement, but is also broken out of a [branch](github.com/davidgumberg/bitcoin/tree/2025-09-02-0xB10C-prefill-rebase) that does compact block prefilling up to the available bytes in the connection's current TCP window (see [delving post](https://delvingbitcoin.org/t/stats-on-compact-block-reconstructions/1052/34)). Creating connected socket pairs is useful for added tests in that branch that validate querying the current TCP window state, and without this change those tests don't run on Windows.

ACKs for top commit:
  achow101:
    ACK 9316d96240
  sedited:
    ACK 9316d96240
  w0xlt:
    reACK 9316d96240

Tree-SHA512: 23ad7070555bb934b0eb18d114e918bd2d50657d20d2221d8c98cd0e558e27e32e5ef89e8074c108a90d7309e539318d23cea43d2ad8eb10e635b114f5f1a87d
2026-04-01 11:22:40 -07:00
Bruno Garcia
91cd0e3aaa fuzz: remove GetDescriptorChecksum from string harness
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.
2026-04-01 10:43:23 -03:00
merge-script
d0ed369b3b Merge bitcoin/bitcoin#34049: rpc: Disallow captures in RPCMethodImpl
5a81d73a81 scripted-diff: rpc: Don't pointlessly capture in RPCMethod lambdas (Anthony Towns)
4e789299af scripted-diff: rpc: Rename RPCHelpMan to RPCMethod (Anthony Towns)

Pull request description:

  When defining `RPCHelpMan` objects, we usually return a lambda, and mostly we define those via `[&](...) { ... }` which explicitly captures any parameters or local variables by reference. If we were to actually use any of those captures (we don't), we would invoke undefined behaviour. So instead, convert all the `[&]` to `[]` to avoid capturing.

  While we're at it, rename `RPCHelpMan` to `RPCMethod`, reflecting its greater responsibility since #19386.

ACKs for top commit:
  maflcko:
    review ACK 5a81d73a81 🏣
  stickies-v:
    ACK 5a81d73a81
  rkrux:
    code review ACK 5a81d73a81

Tree-SHA512: 72e9232857ba5bf4c346fb963a2028047f7c7e9b420ef58b3108669204bfbb6952342cfcfd2e8a06f813a21545abf7fc8b0ad422f00d7ec9c1134626cd1650e6
2026-04-01 00:08:28 +08:00
Hennadii Stepanov
6953363be8 refactor: Move license info into new module 2026-03-30 16:34:48 +01:00
MarcoFalke
fafb0c4cbe refactor: Return std::optional from GetLogCategory 2026-03-30 09:03:03 +02:00
merge-script
e602ad62d0 Merge bitcoin/bitcoin#34919: test: script: boundary at exactly 65535 bytes must use OP_PUSHDATA2
f899674639 test: script: boundary at exactly 65535 bytes must use OP_PUSHDATA2 (Bruno Garcia)

Pull request description:

  I noticed that the following mutant is not killed by any current test (can be tested with: `cmake --build build -j $(nproc) && ./build/bin/test_bitcoin && ./build/test/functional/test_runner.py -j $(nproc) -F`):

  ```diff
  diff --git a/src/script/script.cpp b/src/script/script.cpp
  index 3f764aaf21..5cff51d2cf 100644
  --- a/src/script/script.cpp
  +++ b/src/script/script.cpp
  @@ -387,7 +387,7 @@ bool CheckMinimalPush(const std::vector<unsigned char>& data, opcodetype opcode)
       } else if (data.size() <= 255) {
           // Must have used OP_PUSHDATA.
           return opcode == OP_PUSHDATA1;
  -    } else if (data.size() <= 65535) {
  +    } else if (data.size() < 65535) {
           // Must have used OP_PUSHDATA2.
           return opcode == OP_PUSHDATA2;
       }
  ```

  This PR addresses it by adding a new test case to ensure that the boundary at exactly 65535 bytes must use OP_PUSHDATA2 as well.

ACKs for top commit:
  kevkevinpal:
    tACK [f899674](f899674639)
  danielabrozzoni:
    tACK f899674639
  darosior:
    utACK f899674639
  w0xlt:
    ACK f899674639

Tree-SHA512: ad35cc992aa351d26151cb79d1b1d5d960b1d80a98b3076a709aa19f7b5135edb87a957d2c84f359e86da8a15f7f0196301bfaff5ae554aecc65d81c97f8af3e
2026-03-28 14:55:59 +08:00
merge-script
954374d405 Merge bitcoin/bitcoin#34926: test: Replace DEBUG_LOG_OUT with -printtoconsole=1
261d229455 test: Replace DEBUG_LOG_OUT with -printtoconsole=1 (Hodlinator)

Pull request description:

  `-printtoconsole=1` has the same functionality but works in more cases than `DEBUG_LOG_OUT`, so remove the latter (`-printtoconsole` is already used when fuzzing). This means we can drop `G_TEST_LOG_FUN`.

  ---
  Behavior can be verified through
  ```shell
  ctest --test-dir build --debug
  ```
  and checking for:
  ```
  142: Test command: /home/hodlinator/bc/2/build/bin/test_bitcoin "--run_test=coinselector_tests" "--catch_system_error=no" "--log_level=test_suite" "--" "-printtoconsole=1"
  ...
  142: 2026-03-26T13:40:02.169392Z [test] [../src/kernel/context.cpp:20] [operator()] Using the 'sse4(1way);sse41(4way);avx2(8way)' SHA256 implementation
  ```

  ---
  Inspired by: https://github.com/bitcoin/bitcoin/pull/34918#discussion_r2994780532

ACKs for top commit:
  nkatha23:
    ACK 261d229
  maflcko:
    review ACK 261d229455 📬
  kevkevinpal:
    crACK [261d229](261d229455)
  janb84:
    cr ACK 261d229455

Tree-SHA512: f4c793b4a00730ade113241baeaaef08ae0333df15ada5929dd46aacd1ac875733e58aa341fac8fb5875eb5ebca735d40c664bf0ef62132094e0c993da5b20e5
2026-03-28 14:44:16 +08:00
merge-script
4f8bd396f8 Merge bitcoin/bitcoin#34913: fuzz: Use time helpers in node_eviction
fa1ebde1ad fuzz: Use time helpers in node_eviction (MarcoFalke)

Pull request description:

  The `node_eviction` fuzz test has many issues:

  * It uses the full `int64_t` range (in seconds) as input, which is absurdly large (millions of years) and also violates https://en.cppreference.com/w/cpp/chrono/duration.html:

  > Each of the predefined duration types up to hours covers a range of at least ±292 years.

  * It does not use the existing `ConsumeDuration` and `ConsumeTime` helpers, which makes specifying a proper range difficult.

  So fix all issues by using `ConsumeTime` for time points with default arguments, and `ConsumeDuration` with the same precision, as well as possibly negative values.

ACKs for top commit:
  marcofleon:
    crACK fa1ebde1ad
  brunoerg:
    reACK fa1ebde1ad
  w0xlt:
    ACK fa1ebde1ad

Tree-SHA512: 22045e6c563a9169327737895ea2f3a7b1dcb4fd24fce56d91caa1e132d03a85cbaaa5f78218d23cfa203fe2ee4b147894c02870eb20ae1c232ad55ccdb6f7f7
2026-03-27 08:40:54 +08:00
Ava Chow
21da421b42 Merge bitcoin/bitcoin#34439: qa: Drop recursive deletes from test code, add lint checks.
0d1301b47a test: functional: drop rmtree usage and add lint check (David Gumberg)
8bfb422de8 test: functional: drop unused --keepcache argument (David Gumberg)
a7e4a59d6d qa: Remove all instances of `remove_all` except test cleanup (David Gumberg)

Pull request description:

  Both `fs::remove_all` and `shutil::rmtree()` are a bit dangerous, and most of their uses are not necessary, this PR removes most instances of both.

  `remove_all()` is still used in in `src/test/util/setup_common.cpp` as part of `BasicTestingSetup::BasicTestingSetup`'s constructor and destructor, and it is used in the kernel test code's [`TestDirectory`](4ae00e9a71/src/test/kernel/test_kernel.cpp (L100-L112)):

  734899a4c4/src/test/kernel/test_kernel.cpp (L100-L112)

  In both cases, `remove_all` is likely necessary, but the kernel's test code is RAII, ideally `BasicTestingSetup` could be made similar in a follow-up or in this PR if reviewers think it is important.

  Similarly in the python code, most usage was unnecessary, but there are a few places where `rmtree()` was necessary, I have added sanity checks to make sure these are inside of the `tmpdir` before doing recursive delete there.

ACKs for top commit:
  achow101:
    ACK 0d1301b47a
  hodlinator:
    ACK 0d1301b47a
  sedited:
    ACK 0d1301b47a

Tree-SHA512: da8ca23846b73eff0eaff61a5f80ba1decf63db783dcd86b25f88f4862ae28816fc9e2e9ee71283ec800d73097b1cfae64e3c5ba0e991be69c200c6098f24d6e
2026-03-26 13:05:01 -07:00
Hodlinator
261d229455 test: Replace DEBUG_LOG_OUT with -printtoconsole=1 2026-03-26 14:41:57 +01:00
MarcoFalke
fa1ebde1ad fuzz: Use time helpers in node_eviction 2026-03-25 16:55:18 +01:00
Mccalabrese
325afe664d net: delay stale evaluation and expose time_added in private broadcast 2026-03-25 11:49:05 -04:00
MarcoFalke
fabbfec3b0 fuzz: Remove unused g_setup pointers
These are unused and removing them avoids clang warnings like:

src/test/fuzz/deserialize.cpp:42:26: error: variable g_setup set but not used [-Werror,-Wunused-but-set-variable]
2026-03-25 13:51:01 +01:00
Bruno Garcia
f899674639 test: script: boundary at exactly 65535 bytes must use OP_PUSHDATA2 2026-03-25 09:49:26 -03:00
Anthony Towns
5a81d73a81 scripted-diff: rpc: Don't pointlessly capture in RPCMethod lambdas
-BEGIN VERIFY SCRIPT-
sed -i 's/\[[&]\][(]const RPCMethod[&]/[](const RPCMethod\&/' $(git grep -l '\[\&\](const RPCMethod')
-END VERIFY SCRIPT-
2026-03-25 19:18:11 +10:00
Anthony Towns
4e789299af scripted-diff: rpc: Rename RPCHelpMan to RPCMethod
Since this class defines the functionality of the RPC method, not
just its help text, this better reflects reality.

-BEGIN VERIFY SCRIPT-
sed -i -e 's/\bRPCHelpMan\b/RPCMethod/g' $(git grep -l RPCHelpMan src/)
-END VERIFY SCRIPT-
2026-03-25 19:18:10 +10:00
David Gumberg
a7e4a59d6d qa: Remove all instances of remove_all except test cleanup
Adds a lint check for `remove_all()`

`fs::remove_all()`/`std::filesystem::remove_all()` is extremely
dangerous, all user-facing instances of it have been removed, and it
also deserves to be removed from the places in our test code where it is
being used unnecessarily.
2026-03-24 16:03:02 -07:00
Ava Chow
38886a6710 Merge bitcoin/bitcoin#34786: validation: do not add the snapshot to candidates set of the background chainstate
69baddc910 validation: do not add the snapshot block to candidates of bg chainstate (Martin Zumsande)

Pull request description:

  The snapshot block needs to be added to the candidates set of the assumed-valid chain because it will be the tip of that chainstate right after snapshot activation.

  However, adding it also to the background chainstate is not necessary for anything. Before, the index would be in the set without being connectable. It will be eventually added to the set as part of the normal block download - no extra logic is necessary here.

  This simplifies a unit test which had a comment that having the block in the set is "not intended".
  This was suggested [here](https://github.com/bitcoin/bitcoin/pull/34521#discussion_r2849281299) and [here](https://github.com/bitcoin/bitcoin/pull/34521#discussion_r2883024248) in #34521

  Note that adding the snapshot block was harmless, since `FindMostWorkChain()` lazily removes blocks without data from the set, so this does not fix a bug but just simplifies some code.

ACKs for top commit:
  achow101:
    ACK 69baddc910
  Bortlesboat:
    Concept ACK 69baddc910. Removing `TargetBlock()` correctly limits the snapshot-block special-case to cs2 where it's actually needed — the test's own "not intended" comment was the tell.
  sedited:
    ACK 69baddc910
  fjahr:
    ACK 69baddc910
  stratospher:
    ACK 69baddc.

Tree-SHA512: 8942fc422f1898369dd486e37da11758f2ebd4a488d092aa1637ef5bfb85766c4be9ad0718797fb2080f5e8d61383b2ee932bf2bc2f7abc2fb07fe3d72e070c3
2026-03-24 14:58:05 -07:00