Commit Graph

48693 Commits

Author SHA1 Message Date
Ava Chow
8a05adc5f8 Merge bitcoin/bitcoin#35138: doc: add missed advisory to 31.0 rel notes
c95968f780 doc: add missed advisory to 31.0 rel notes (fanquake)

Pull request description:

  Generally we don't post-amend release notes, but we can add the missing EOL security advisory here.
  See https://github.com/bitcoin-core/bitcoincore.org/pull/1240 and https://github.com/bitcoin/bitcoin/pull/35132.

ACKs for top commit:
  darosior:
    ACK c95968f780
  achow101:
    ACK c95968f780
  sedited:
    ACK c95968f780

Tree-SHA512: d7269bc088fa1bc577bc200604f7626eede73d2e920186711ecc5120f9b51e01d02f35fda2d1291289e89132280c6cdb050e4a7e423d4f30b45e3949160b5163
2026-04-22 10:16:53 -07:00
fanquake
c95968f780 doc: add missed advisory to 31.0 rel notes
See https://github.com/bitcoin-core/bitcoincore.org/pull/1240 and
https://github.com/bitcoin/bitcoin/pull/35132.
2026-04-22 11:06:35 +01:00
merge-script
3f09a4703f Merge bitcoin/bitcoin#35132: doc: update release process to mention security advisories pre-announcements
4abc0c2e04 doc: update release process to mention security advisories pre-announcements (Antoine Poinsot)

Pull request description:

  We missed a pre-announcement with the release of 31.0. This updates the release process docs to make sure we check those before publishing a major release.

ACKs for top commit:
  achow101:
    ACK 4abc0c2e04
  jonatack:
    ACK 4abc0c2e04

Tree-SHA512: 63d1def3d4144de7992b539d41a496c98bc81b33e2a9c27af55933a696050123a0c967253093728f0553f13aca12acec8a51efbeda0936077646c379c37219d6
2026-04-22 11:04:19 +01:00
merge-script
1a4371cc3d Merge bitcoin/bitcoin#34882: refactor: Use NodeClock::time_point in more places
fa1015bbcb refactor: Use NodeClock::time_point for m_connected (MarcoFalke)
fa244b984c refactor: Use NodeClock::time_point for m_last_send/recv and m_ping_start (MarcoFalke)
fa2605b204 refactor: Use NodeClock::time_point for CNetMessage::m_time (MarcoFalke)
fa644e625b refactor: Use NodeClock::duration for m_last_ping_time/m_min_ping_time/m_ping_wait (MarcoFalke)
333316f6be doc: Fix typo "eviction criterium" -> "eviction criterion" (MarcoFalke)
fa54fb0129 refactor: gui: Accept up to nanoseconds in formatDurationStr, but clarify they are ignored (MarcoFalke)
fab88884b7 refactor: Avoid manual chrono casts with * or / (MarcoFalke)
facfce37f6 util: Add NodeClock::epoch alias (MarcoFalke)
fa41e072b3 refactor: Use NodeClock alias over deprecated GetTime (MarcoFalke)

Pull request description:

  It is a bit confusing to have some code use the deprecated `GetTime`, which returns a duration and not a time point, and other code to use `NodeClock` time points.

  Fix a few more places to properly use time_point types.

ACKs for top commit:
  stickies-v:
    re-ACK fa1015bbcb
  seduless:
    re-ACK fa1015bbcb
  naiyoma:
    ACK fa1015bbcb
  sedited:
    ACK fa1015bbcb

Tree-SHA512: 7c8df1a9025271b08a40fd0d176bcbbf90920bc4d83a6e1c8cfaad2a894632af2b9a1aca5c3c9ddc3803e559dd168244121fd188ef22f399d60075ff194a9140
2026-04-21 22:46:25 +02:00
Antoine Poinsot
4abc0c2e04 doc: update release process to mention security advisories pre-announcements 2026-04-21 11:28:43 -04:00
merge-script
875faa29e1 Merge bitcoin/bitcoin#35087: tor: limit torcontrol line size that is processed to prevent OOM
9fe5896a44 tor: torcontrol disconnect on too many lines to avoid OOM (David Gumberg)
8b68287bf9 test: Make torcontrol max line length test stricter and test boundaries. (David Gumberg)
ab5889796f refactor: torcontrol add connection checks to restart_with_mock (David Gumberg)

Pull request description:

  LLM disclosure: Found with the help of Claude Opus 4.6, fix, test, description, and commit messages written by me.

  ------

  This fixes a low-severity issue where a misbehaving Tor control daemon can cause
  bitcoind to OOM by sending continuation lines without sending `250 OK` or
  similar.

  This issue is not that serious because if your tor control daemon is malicious you are already in all kinds of trouble, but as a matter of robustness this should be fixed.

  The fix is to prevent the `TorControlConnection::m_message` buffer from growing
  without bound by by limiting the number of lines handled by `TorControlConnection::ProcessBuffer()`
  to `MAX_LINE_COUNT = 1000`. Now the most memory that can be occupied by
  `m_message` is on the order of `MAX_LINE_LENGTH * MAX_LINE_COUNT= 100MB`

  Although this is not compliant with the Tor control protocol in general,
  where commands like `GETINFO ns/all` will likely return thousands of
  lines, it is more than sufficient for handling the replies from the
  commands that are used by a node:

  <details>

  <summary>

  #### Tor control commands used by Bitcoin Core

  </summary>

  `AUTHENTICATE`: 1 line:
      The server responds with 250 OK on success or 515 Bad
      authentication if the authentication cookie is incorrect. Tor closes
      the connection on an authentication failure.

  https://spec.torproject.org/control-spec/commands.html#authenticate

  `GETINFO net/listener/socks`: 2 lines
      A quoted, space-separated list of the locations where Tor is
      listening...

  https://spec.torproject.org/control-spec/commands.html#getinfo

  `AUTHCHALLENGE SAFECOOKIE`: 1 line
      If the server accepts the command, the server reply format is:

      ```
      "250 AUTHCHALLENGE" SP "SERVERHASH=" ServerHash SP "SERVERNONCE="
      ServerNonce CRLF
      ```

  https://spec.torproject.org/control-spec/commands.html#authenticate

  `PROTOCOLINFO`: 4-5 lines

      The server reply format is:

      ```
      250-PROTOCOLINFO" SP PIVERSION CRLF \*InfoLine "250 OK" CRLF
      InfoLine = AuthLine / VersionLine / OtherLine
      ```

  (https://spec.torproject.org/control-spec/commands.html#protocolinfo)

  `ADD_ONION`: 2-3 lines for Bitcoin Core's tor control client.

      The server reply format is:

      ```
      "250-ServiceID=" ServiceID CRLF
      ["250-PrivateKey=" KeyType ":" KeyBlob CRLF]
      *("250-ClientAuth=" ClientName ":" ClientBlob CRLF)
      "250 OK" CRLF
      ```

      ...

      The server response will only include a private key if the server
      was requested to generate a new keypair

      ...

      If client authorization is enabled using the “BasicAuth” flag (which
      is v2 only), the service will not be accessible to clients without
      valid authorization data (configured with the “HidServAuth” option).
      The list of authorized clients is specified with one or more
      “ClientAuth” parameters. If “ClientBlob” is not specified for a
      client, a new credential will be randomly generated and returned."

  https://spec.torproject.org/control-spec/commands.html#add_onion

  We don't set the `BasicAuth` flag, so the response will not include any
  `ClientAuthLines`.

  </details>

  ## Reproduce

  To reproduce this issue, the following script or similar can be used as the
  misbehaving Tor control daemon:

  ```python
  #!/usr/bin/env python3
  """
  A fake Tor control service that never finishes its reply. Sends unlimited
  continuation lines ("250-...") without ever sending the final "250 ...".
  Each line accumulates in m_message.lines with no cap. Bitcoind OOMs.
  """

  import socket
  import time

  PORT = 19191

  server = socket.create_server(("127.0.0.1", PORT))
  conn, _ = server.accept()
  conn.recv(4096)  # Receive PROTOCOLINFO

  time_start = time.time()

  try:
      while True:
          conn.sendall(b"250-Ceaseless\r\n" * 10000)
  except (BrokenPipeError, ConnectionResetError):
      elapsed = time.time() - time_start
      print(f"Node disconnected after {elapsed:.2f}s")
  ```

  **🟡¡This will OOM, run in a container, VM, or some sandbox with memory limits!🟡**
  Start a node with `-torcontrol=127.0.0.1=19191`.

  E.g. with systemd:

  ```bash
  systemd-run --user --scope -p MemoryMax=2G -p MemorySwapMax=0 bitcoind -regtest -torcontrol=127.0.0.1:19191
  ```

ACKs for top commit:
  fjahr:
    ACK 9fe5896a44
  danielabrozzoni:
    Code review ACK 9fe5896a44
  janb84:
    ACK. 9fe5896a44
  sedited:
    ACK 9fe5896a44

Tree-SHA512: ccbeba40c096e1fa3911c75c49e3a5c403712f646d77329de48017a19d1f0caa2ee4cc148b6c6473f68e55d7da04f17eb67748b5bf4dede3579b944ee5370cf5
2026-04-21 16:17:21 +02:00
merge-script
e32bc7f817 Merge bitcoin/bitcoin#35025: refactor: use SpanReader in deserialization benchmarks
13c8df4d5a refactor: replace `DataStream` with `SpanReader` in block deserialization tests (Lőrinc)
2529f25555 refactor: use `SpanReader` in `PrevectorDeserialize` (Lőrinc)
b8eb6c2081 refactor: use `SpanReader` in `TestBlockAndIndex` (Lőrinc)
61d678a6e3 refactor: use `DataStream::clear` in `::read` and `::ignore` (Lőrinc)

Pull request description:

  ### Problem

  Block deserialization benches still read immutable fixture bytes through `DataStream`, which keeps around mutable stream semantics and old compaction-oriented setup that these call sites do not need anymore.

  ### Fix
  We first remove the stale `Rewind()` parameter and failure path, which reduces rewinding to a simple reset of the read position that `clear()` can reuse.

  We then route fully consumed `read()`  and `ignore()` paths through `clear()`, remove the leftover compaction references and dummy-byte workaround, and finally switch the block deserialization benchmark readers to `SpanReader`.

  `DeserializeBlockTest` can then deserialize directly from the fixture bytes without an untimed setup phase, while `CheckBlockTest` still keeps setup only to rebuild a fresh `CBlock` before  the timed `CheckBlock()` call.

  ### Context
  This follows the same direction as #34483 and is a follow-up to https://github.com/bitcoin/bitcoin/pull/34208.
  The modified benchmarks retain their previous timing.

  ### Benchmarks

  The affected benchmarks speeds don't seem to be affected by the changes.

  <details><summary>Before & After</summary>

  > Before:

  ```bash

  |               ns/op |                op/s |    err% |     total | benchmark
  |--------------------:|--------------------:|--------:|----------:|:----------
  |       37,591,891.96 |               26.60 |    1.0% |     11.07 | `BlockToJsonVerboseWrite`
  |          155,664.09 |            6,424.09 |    0.1% |     10.99 | `BlockToJsonVerbosity1`
  |       28,620,345.39 |               34.94 |    0.1% |     10.99 | `BlockToJsonVerbosity2`
  |       28,637,604.74 |               34.92 |    0.1% |     11.01 | `BlockToJsonVerbosity3`

  |            ns/block |             block/s |    err% |     total | benchmark
  |--------------------:|--------------------:|--------:|----------:|:----------
  |          530,167.00 |            1,886.20 |    4.7% |      0.01 | `CheckBlockTest`
  |        1,439,417.00 |              694.73 |    0.7% |      0.02 | `DeserializeBlockTest`

  |               ns/op |                op/s |    err% |     total | benchmark
  |--------------------:|--------------------:|--------:|----------:|:----------
  |              269.95 |        3,704,375.43 |    0.4% |     11.01 | `PrevectorDeserializeNontrivial`
  |               14.90 |       67,114,436.52 |    0.0% |     10.88 | `PrevectorDeserializeTrivial`
  ```

  > After:

  ```bash
  |               ns/op |                op/s |    err% |     total | benchmark
  |--------------------:|--------------------:|--------:|----------:|:----------
  |       37,114,824.07 |               26.94 |    1.8% |     10.89 | `BlockToJsonVerboseWrite`
  |          154,881.99 |            6,456.53 |    0.2% |     10.99 | `BlockToJsonVerbosity1`
  |       28,546,697.37 |               35.03 |    0.2% |     10.98 | `BlockToJsonVerbosity2`
  |       28,547,328.27 |               35.03 |    0.3% |     11.02 | `BlockToJsonVerbosity3`

  |            ns/block |             block/s |    err% |     total | benchmark
  |--------------------:|--------------------:|--------:|----------:|:----------
  |          522,750.00 |            1,912.96 |    4.7% |      0.01 | `CheckBlockTest`
  |        1,404,510.54 |              711.99 |    0.1% |     11.00 | `DeserializeBlockTest`

  |               ns/op |                op/s |    err% |     total | benchmark
  |--------------------:|--------------------:|--------:|----------:|:----------
  |              273.52 |        3,655,991.66 |    0.4% |     11.00 | `PrevectorDeserializeNontrivial`
  |               14.31 |       69,863,193.52 |    1.4% |     11.03 | `PrevectorDeserializeTrivial`
  ```

  </details>

ACKs for top commit:
  maflcko:
    review ACK 13c8df4d5a 🐠
  sedited:
    Re-ACK 13c8df4d5a

Tree-SHA512: b469874908c694b6b7f45e686519bdce0c0f4da2ca56b3f7f9897c7f27bb19a787f9821466995f15414343d508f15616b24b7fd8f0fa389ade8698c8f190b669
2026-04-21 13:51:39 +02:00
Lőrinc
13c8df4d5a refactor: replace DataStream with SpanReader in block deserialization tests
These benchmark inputs are immutable fixture bytes, so `DataStream` adds an unnecessary owned buffer and the setup needed to recreate or preserve its state.

Use `SpanReader` for block deserialization in `checkblock` instead.
This keeps `DeserializeBlockTest` focused on deserialization work, while `CheckBlockTest` still uses untimed setup only to rebuild a fresh uncached `CBlock` for the timed `CheckBlock()` call.

Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>
2026-04-21 12:27:20 +02:00
Lőrinc
2529f25555 refactor: use SpanReader in PrevectorDeserialize
`PrevectorDeserialize` only needs a reusable read-only view over fixed serialized bytes.
Keeping a mutable `DataStream` around just to call `Rewind()` is unnecessary.

Rebuild a fresh `SpanReader` for each benchmark run and remove `DataStream::Rewind()`, whose remaining use was this benchmark-only reset path.
The benchmark can now serialize exactly the 1000 entries it deserializes, so drop the stale extra element that used to avoid full consumption.

Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>
2026-04-21 12:27:20 +02:00
Lőrinc
b8eb6c2081 refactor: use SpanReader in TestBlockAndIndex
`TestBlockAndIndex` still deserialized its fixed block fixture through `DataStream` and appended a dummy byte to avoid compaction after full consumption.

Use `SpanReader` for that fixture instead.
This removes the leftover dummy-byte workaround and reads the immutable fixture through a read-only view.
2026-04-21 12:25:44 +02:00
Lőrinc
61d678a6e3 refactor: use DataStream::clear in ::read and ::ignore
When `DataStream` is fully consumed, both `read()` and `ignore()` reset it to an empty state by clearing the backing buffer and resetting the read position.

Call `clear()` in both places instead of open-coding the same state transition.
This keeps the behavior unchanged while documenting the fully-consumed reset in one place.

Remove the unused `Compact()` method as well - it has been unused for a long time and can be added back if it is ever needed.
2026-04-21 12:25:44 +02:00
merge-script
d3a40dd9de Merge bitcoin/bitcoin#35127: fuzz: remove redundant CScript method calls from script harness
c9d8582235 fuzz: remove redundant CScript method calls from script harness (Bruno Garcia)

Pull request description:

  The script harness was calling `GetSigOpCount`, `HasValidOps`, `IsPayToAnchor`, `IsPayToScriptHash`, `IsPayToWitnessScriptHash`, and `IsPushOnly` on the fuzzed CScript. All of these are already covered by the `script_ops` harness, which is the dedicated harness for CScript member methods. Also, add the missing `IsPayToAnchor` call to `script_ops` so the move preserves coverage.

ACKs for top commit:
  maflcko:
    lgtm ACK c9d8582235

Tree-SHA512: f69c9f217b5422e24714f985a8c0f7fcfb2c1b1e9117a0e54e7d31139bedfec9279a756ceb9b8860f7574b7cf59fb17c1063596176de8de4800824dc7866f33c
2026-04-21 10:25:11 +01:00
Bruno Garcia
c9d8582235 fuzz: remove redundant CScript method calls from script harness
The script harness was calling GetSigOpCount, HasValidOps,
IsPayToAnchor, IsPayToScriptHash, IsPayToWitnessScriptHash, and
IsPushOnly on the fuzzed CScript. All of these are already covered
by the script_ops harness, which is the dedicated harness for
CScript member methods.

Also add the missing IsPayToAnchor call to script_ops so the move
preserves coverage.
2026-04-20 21:18:03 -03:00
Ava Chow
89e7c4274c Merge bitcoin/bitcoin#31449: coins,refactor: Reduce getblockstats RPC UTXO overhead estimation
5f36e0ff1e rpc: fix getblockstats UTXO overhead accounting (Lőrinc)
76190489e6 coins: pack `Coin` height/coinbase consistently (Lőrinc)
1f309d1aa2 coins: make `Coin::fCoinBase` a bool (Lőrinc)

Pull request description:

  The [`getblockstats` RPC](https://github.com/bitcoin/bitcoin/pull/10757) currently overestimates UTXO overhead by treating the `fCoinBase` bitfield as an additional `bool` in `PER_UTXO_OVERHEAD`.
  However, `fCoinBase` and `nHeight` are stored as bitfields and effectively packed into a single 32-bit value; counting an extra bool in the overhead calculation is unnecessary.

  This PR introduces the following changes across three commits:
  * Store `fCoinBase` as a `bool` bitfield to reduce implicit conversions at call sites.
  * Use a consistent height/coinbase packing style across `Coin` serialization, undo serialization, and coinstats hashing (casting `nHeight` to `uint32_t` before shifting to avoid signed-promotion UB).
  * Adjust UTXO overhead estimation to match the actual `Coin` layout and update the related tests accordingly.

ACKs for top commit:
  achow101:
    ACK 5f36e0ff1e
  sedited:
    ACK 5f36e0ff1e
  vasild:
    ACK 5f36e0ff1e
  optout21:
    crACK 5f36e0ff1e

Tree-SHA512: f4a44debed358e9e130da9d6fae5f89289daa34f0bdb7155edc3e9b691c219451f4c80b1e16aca5b011f0fa2fa975484ef1af4ca4563b7c6ba4ca9dd133f30be
2026-04-20 15:52:45 -07:00
Ava Chow
6b3dd6314f Merge bitcoin/bitcoin#34863: test: Clean shutdown in Socks5Server
6ac49373aa test: Add clean shutdown to Socks5Server (optout)

Pull request description:

  Add clean shutdown to `Socks5Server` test utility, fix a sporadic CI failure.

  Closes #34849.

  The `Socks5Server` utility handles multiple incoming connections, which are handled in separate background threads. Its `stop()` method unblocks and waits for the main background thread cleanly, but it doesn't attempt to wait for the completion of handler threads. There is no guarantee that the handler threads are finished after `stop()` returns, which can lead to IO errors.

  In the reported sporadic test failures, the test in `p2p_private_broadcast.py` uses the Socks5 server, and makes a node connect to/through it. Then it stops the Socks5 server, and then it stops the node. However, if a connection handler is still active, that can lead to errors, as the socket is closed.

  The change attempts to fix this by storing all handler threads and connections, and attempting to shut them down before `stop()` returns.

  Notes:

  - ~~I was not able to reliably reproduce the failure locally.~~
    Update: I could reproduce the failure, see https://github.com/bitcoin/bitcoin/issues/34849#issuecomment-4126331780 .

  Running the relevant test:
  ```sh
  build/test/functional/test_runner.py p2p_private_broadcast.py
  ```

ACKs for top commit:
  andrewtoth:
    re-ACK 6ac49373aa
  achow101:
    ACK 6ac49373aa
  vasild:
    ACK 6ac49373aa
  w0xlt:
    ACK 6ac49373aa

Tree-SHA512: c63a62a516925252c450c9b7931539aedac2e44566bd4fe217aa54e6ca1438c8f50a100c714166b7cc67786b00f42c1a36e4916d63311842a77293cd2e102356
2026-04-20 14:31:03 -07:00
merge-script
64a88c8c1e Merge bitcoin/bitcoin#35096: kernel: align height parameters to int32_t in btck API
07b9b13b45 doc: add integer type conventions in btck api remarks (Alexander Wiederin)
ba6287a449 kernel: align height parameters to int32_t in btck API (Alexander Wiederin)

Pull request description:

  Follow-up to https://github.com/bitcoin/bitcoin/pull/34885#discussion_r3093370576

  ### Summary
  Align height-related parameters and return values in the kernel API to use `int32_t`.

  ### Motivation

  The convention in the API is to use fixed-width types like `int32_t` for data values (e.g. heights), and plain `int`/`unsigned int` for boolean-like values and flags. Two functions were not following this:

  - `btck_chain_get_height`: header declared `int32_t` but implementation used `int`
  - `btck_chain_get_by_height`: both header and implementation used plain `int`

  ### Changes

  - `btck_chain_get_height`: align `.cpp` to match header (`int` -> `int32_t`)
  - `btck_chain_get_by_height`: update both header and `.cpp` (`int` -> `int32_t`)
  - `CountEntries` in `bitcoinkernel_wrapper.h`: align return type to `int32_t`
  - `GetByHeight` in `bitcoinkernel_wrapper.h`: align parameter type to `int32_t`
  - Document integer type conventions in the `@page remarks` section of `bitcoinkernel.h`

  *Note: This is technically a breaking change for C consumers who have function pointer declarations matching the old signature. The Rust, Go, Java and Python bindings should not be affected.*

ACKs for top commit:
  musaHaruna:
    Code review ACK [07b9b13](07b9b13b45)
  sedited:
    ACK 07b9b13b45
  stringintech:
    ACK 07b9b13

Tree-SHA512: 1c6c5c3113c82f7c5f07871c1aa996b71191d0b190d000d48774a866fcc08514cdabcc13a9de2fed8b5d824da050258db73d73e6aa0b80d828af1533128fe1cd
2026-04-20 15:51:56 +01:00
merge-script
0c0f75eaaf Merge bitcoin/bitcoin#35091: doc: archive release notes for v31.0
4d040b7d62 doc: archive release notes for v31.0 (fanquake)

Pull request description:

ACKs for top commit:
  janb84:
    ACK 4d040b7d62

Tree-SHA512: 1a210d8a213c48f2c46c5dde4348a92cea6bcf259f120a084e13aab6b910c2bb249d87557f3752611731f272ec8565aa404213af0ec8cc4538e218e20a6b487e
2026-04-20 14:15:48 +01:00
merge-script
5c50a03309 Merge bitcoin/bitcoin#35006: cli, rpc: add -rpcid option for custom request IDs
c54f37c1ba cli, rpc: add -rpcid option for custom request IDs (Torkel Rogstad)

Pull request description:

  Add a `-rpcid` CLI argument to `bitcoin-cli` that allows setting a custom string as the JSON-RPC request ID instead of the hardcoded default of 1. This enables correlating requests and responses when debugging or when multiple clients are making concurrent calls.

  On the server side, include the request ID in the RPC debug log line.

  Tests are added in `test/functional/interface_bitcoin_cli.py` for this.

ACKs for top commit:
  maflcko:
    lgtm ACK c54f37c1ba
  stickies-v:
    ACK c54f37c1ba
  sedited:
    ACK c54f37c1ba

Tree-SHA512: b693a50a2be5dc7797e5b61bddc4c10237888b52065d1b68029d7211542e0dd44f2b3dfb9b3bd7c5e4d9026766817de66a7ef4f29a8d97a268554ba775063e10
2026-04-20 14:32:43 +02:00
merge-script
b6d1b65062 Merge bitcoin/bitcoin#34908: rpc, refactor: gettxoutsetinfo race condition fix follow-ups
3e5dc61035 rpc, refactor: gettxoutsetinfo race condition fix follow-ups (rkrux)

Pull request description:

  This patch addresses my own review comments from the review of #34451. If these are found helpful, it makes sense to do them now after the previous PR was merged and backported.

  Pasting the comments below that also explains the changes:

  - Move the pindex declaration below now that it is not used earlier.
  - stats was being generated partially in both these ComputeUTXOStats functions, which reads oddly to me. Now that the pcursor is also moved and passed to this function, which reads oddly as well, I believe we can refactor this function to completely build the stats inside this function. A side benefit is that by removing the stats and pcursor arguments, the function signature becomes quite similar to its namesake, which in turn becomes a straightforward wrapper of this function.

ACKs for top commit:
  w0xlt:
    ACK 3e5dc61035
  sedited:
    ACK 3e5dc61035

Tree-SHA512: b8e4a4ebfe4935aa97920cb7068445ea93e571f80e679b8791343ac8750b48484d4288e083e07bf433b397cb6071171a2b77d34758a4627056b34cc63d06f0f4
2026-04-20 13:34:54 +02:00
merge-script
ad0545ba96 Merge bitcoin/bitcoin#35024: ci: Mitigate network issues in native Windows job
09c0e37789 ci: Rename vcpkg binary cache entity to force rebuild (Hennadii Stepanov)
dc93091083 ci: Cache `vcpkg/downloads` folder in native Windows CI job (Hennadii Stepanov)
88bbf2ad33 ci, refactor: Reuse primary key in `actions/cache/save` (Hennadii Stepanov)

Pull request description:

  This PR mitigates network issues when vcpkg downloads source tarballs by caching the entire `vcpkg/downloads` directory.

  Closes https://github.com/bitcoin/bitcoin/issues/34996.

ACKs for top commit:
  maflcko:
    review ACK 09c0e37789 📢
  sedited:
    utACK 09c0e37789

Tree-SHA512: 638796e1dc23e2f184852365566dc3feab7023948be506c1cc170d835633cbb0cd94c7c90da2705ab0f2cb2402cdd6acada14f33bae373f459faa4e99892ac5d
2026-04-19 12:40:55 +02:00
merge-script
a51ec89e0c Merge bitcoin/bitcoin#35099: ci: drop -lstdc++ from msan fuzz job
b02d6b0567 ci: drop -lstdc++ usage in msan fuzz job (fanquake)
655a39ee14 ci: use llvm 22.1.3 (fanquake)

Pull request description:

  Upstream seems to have solved their issues.
  Tested locally on aarch64 & x86_64.

ACKs for top commit:
  maflcko:
    lgtm ACK b02d6b0567
  sedited:
    ACK b02d6b0567

Tree-SHA512: 378a78af65730431ba28424b5c9e8b0b95ec7dbf9a68ced78bcfc39108d75bb9e84121f92d315a6d582c865cf6fb080124fa5eb4c0d16c9b95661ddb401fbcbc
2026-04-19 12:16:42 +02:00
merge-script
963ea38c0c Merge bitcoin/bitcoin#35038: bench: add script verification benchmark for P2TR script-path spends
fbffe8a64a bench: improve `VerifyNestedIfScript` benchmark precision (make stack clearing untimed) (David Gumberg)
616ee6fe74 bench: add script verification benchmark for P2TR script-path spends (Sebastian Falbesoner)

Pull request description:

  Similarly as #34472 already did for key-path spends, this PR adds a benchmark for P2TR script-path spends. So far we don't have a benchmark on master yet that exercises the verification of taproot commitments ([`VerifyTaprootCommitment`](141fbe4d53/src/script/interpreter.cpp (L1903))).

  Note that the tapscript leaf intentionally includes a single OP_CHECKSIG as it likely reflects the real world best. Spending tapscript leafs without any signature checks don't make much sense (they could be trivially tampered with and thus stolen by miners), and doing more than one signature check seems the exception rather than the rule.

  The primary motivation for this PR is to evaluate how potential secp256k1 changes in pubkey tweaking (e.g. [#1843](https://github.com/bitcoin-core/secp256k1/pull/1843)) may impact script verification performance.

ACKs for top commit:
  davidgumberg:
    reACK fbffe8a
  l0rinc:
    ACK fbffe8a64a
  sedited:
    ACK fbffe8a64a

Tree-SHA512: 6fa1f2c336d6332b4f2d22173279ee29ad3ec5e5431109913a6978fef32e22a34d3247729ac9092bfdbbcd8f9dfcad8da50bc4ede2cb7efc1f93d6a744ddf41b
2026-04-19 12:01:33 +02:00
merge-script
0bdf21022c Merge bitcoin/bitcoin#35089: test: Allow to set height in create_block
fa16bc53d7 test: Require named arg for create_block ntime arg (MarcoFalke)
fab352053d test: Remove unused create_coinbase imports (MarcoFalke)
fad6deb3cb scripted-diff: Use new create_block height option (MarcoFalke)
fa5eb74b96 test: Allow to set height in create_block (MarcoFalke)

Pull request description:

  The `create_block` helper is often called with `create_coinbase`: `create_block(prev_hash, create_coinbase(new_height))`

  This is fine, but a bit verbose and tedious to type each time. Also, it requires an additional import.

  Improve this by allowing to set `height` in `create_block` directly, similar to other options, such as `ntime`, or `hashprev`.

ACKs for top commit:
  l0rinc:
    reACK fa16bc53d7
  theStack:
    re-ACK fa16bc53d7

Tree-SHA512: 41ca7327aac714b446d53b1a29f83e792f7fc13d567cd0f063f743d50b193fa0c71cc651454ae1f3c960b0b82cc8658932ea08b3be8632f69a18ccd09a052c17
2026-04-19 11:26:00 +02:00
merge-script
ac9ce25b5f Merge bitcoin/bitcoin#34425: test: Fix all races after a socket is closed gracefully
fae807ed25 test: Remove unused, confusing and brittle connect_nodes.wait_for_connect (MarcoFalke)
fab2772647 test: Fix all races after a socket is closed gracefully (MarcoFalke)
fa21edddb2 test: Stricter checks in rpc_setban.py (MarcoFalke)
faa404e119 test: Add is_connected_to helper (MarcoFalke)

Pull request description:

  Currently, functional tests may intermittently fail, due to a lack of synchronization after a node connection socket was closed gracefully: If node A is connected to node B, and node B closes the connection, node A *must* wait for the connection to be closed before continuing the test. Otherwise, subsequent re-connections may not work while a stale connection is still alive.

  This can be reproduced locally via something like:

  ```diff
  diff --git a/src/net.cpp b/src/net.cpp
  index 6b79e913e8..32bd061500 100644
  --- a/src/net.cpp
  +++ b/src/net.cpp
  @@ -2200,2 +2200,3 @@ void CConnman::SocketHandlerConnected(const std::vector<CNode*>& nodes,
                   }
  +            UninterruptibleSleep(599ms);
                   pnode->CloseSocketDisconnect();
  ```

  With this diff, the tests should fail on master, and pass after this fix.

  The fix is placed inside the `connect_nodes` helper.

ACKs for top commit:
  rkrux:
    ACK fae807ed25
  w0xlt:
    ACK fae807ed25
  davidgumberg:
    (re-ish) crACK fae807ed25
  sedited:
    ACK fae807ed25

Tree-SHA512: 053825bbd319d7c49e08810bbabbf9c3a43d89897d697c0ca9232fd8a88ae475b4f9fbd79dff549b4e0a8941cf926ca4567e7fd43dc1749bf023d8ee7dd49608
2026-04-19 11:06:17 +02:00
merge-script
2f9aa400d9 Merge bitcoin/bitcoin#33032: wallet, test: Replace MockableDatabase with in-memory SQLiteDatabase
037ea2c714 walletdb: Remove m_mock from SQLiteDatabase (Ava Chow)
59484e2fdb wallet: Make Mockable{Database,Batch} subclasses of SQLite classes (Ava Chow)
b69f989dc5 wallet, bench: Use TestingSetup in CoinSelection benchmark (Ava Chow)
e7d67c9fd9 test: Make duplicating MockableDatabases use cursor and batch (Ava Chow)
964eafb71c bench, wallet: Make WalletMigration's setup WalletBatch scoped (Ava Chow)

Pull request description:

  `MockableDatabase` was introduced for the tests to avoid tying non-database tests to a particular database type. However, since the only database type now is sqlite, and because the mockable behavior is no longer used by the tests, we can replace usage of the `MockabeDatabase` with a SQLite database that lives only in memory.

  This is particularly useful for future work that has the wallet make use of SQLite's capabilities more, which are less conducive to having a separate mock database implementation.

ACKs for top commit:
  brunoerg:
    code review ACK 037ea2c714
  sedited:
    Re-ACK 037ea2c714
  furszy:
    Code review ACK 037ea2c714

Tree-SHA512: 0a99c27ef4e590966b3af929bf3acf99666861905aabf150fe5660ea07c881a49935a4e7dcd676dcd5e70616898d89d872b6e156ae9c600de1361c1b2469b64d
2026-04-19 10:54:39 +02:00
merge-script
378e17f703 Merge bitcoin/bitcoin#33477: Rollback for dumptxoutset without invalidating blocks
fc736013a5 rpc: Add in_memory option to dumptxoutset with rollback (Fabian Jahr)
d0fd718948 test: Extend named pipe sqlite tool test to use rollback (Fabian Jahr)
ab9463efac test: Add dumptxoutset fork test (Fabian Jahr)
49d5e835a8 rpc: Don't invalidate blocks in dumptxoutset (Fabian Jahr)
fe58eb9850 blockstorage: Add DeletePruneLock (Fabian Jahr)

Pull request description:

  This is an alternative approach to implement `dumptxoutset` with rollback that was discussed a few times. It does not rely on `invalidateblock` and `reconsiderblock` and instead creates a temporary copy of the coins DB, modifies this copy by rolling back as many blocks as necessary and then creating the dump from this temp copy DB. See also https://github.com/bitcoin/bitcoin/pull/29553#issuecomment-1978480989, https://github.com/bitcoin/bitcoin/issues/32817#issuecomment-3012406102 and #29565 discussions.

  The nice side-effects of this are that forks can not interfere with the rollback and network activity does not have to be suspended. But there are also some downsides when comparing to the current approach: this does require some additional disk space for the copied coins DB and performance is slower (master took 3m 17s vs 9m 16s in my last test with the code here, rolling back ~1500 blocks). However, there is also not much code being added here, network can stay active throughout and performance would stay constant with this approach while it would impact master if there were forks that needed to be invalidated as well (see #33444 for the alternative approach), so this could still be considered a good trade-off.

ACKs for top commit:
  stratospher:
    tested ACK fc73601. very nice!
  sedited:
    Re-ACK fc736013a5
  theStack:
    re-ACK fc736013a5

Tree-SHA512: d3d674f68184ac3ada87d969d0fca7bc38203ee939853864adcd235ee3a954914c7e351b817800b885a495606e323392c27d88ba8d8e018eaf8567c098eb0e9c
2026-04-19 10:34:36 +02:00
merge-script
654556e631 Merge bitcoin/bitcoin#35086: test: interface_http follow-ups
f49a2afd94 test: interface_http follow-ups (Matthew Zipkin)

Pull request description:

  This addresses post-merge and slightly-pre-merge comments from #34772 and closes #35082

  - Only one node needed for test
  - Use ascii encoding instead of utf-8
  - Make tests independent of each other
  - Expect HTTP error code 413 for too-large request
  - Clarify python client race condition in comment

ACKs for top commit:
  maflcko:
    lgtm ACK f49a2afd94
  hodlinator:
    re-ACK f49a2afd94

Tree-SHA512: 47014f7e81ba05b3ab83878b26185ae31d541d2d6ddf14c803bed8b9f39535998624d9df733cda8d30f7438564cf241b98f20643a9e0d8e0ef5f72b26ce1a8cd
2026-04-17 21:25:29 +01:00
David Gumberg
9fe5896a44 tor: torcontrol disconnect on too many lines to avoid OOM
This commit ensures the `TorControlConnection::m_message` buffer doesn't
grow unbounded and exhaust memory, by limiting the number of lines
handled by `TorControlConnection::ProcessBuffer()` to `MAX_LINE_COUNT =
1000`. Now the most memory that can be occupied by `m_message` is on the
order of `MAX_LINE_LENGTH * MAX_LINE_COUNT= 100MB`

Although this is not compliant with the tor control protocol in general,
where commands like `GETINFO ns/all` will likely return thousands of
lines, it is more than sufficient for handling the replies from the
commands that are used by a node:

`AUTHENTICATE`: 1 line:
    The server responds with 250 OK on success or 515 Bad
    authentication if the authentication cookie is incorrect. Tor closes
    the connection on an authentication failure.

https://spec.torproject.org/control-spec/commands.html#authenticate

`GETINFO net/listener/socks`: 2 lines
    A quoted, space-separated list of the locations where Tor is
    listening...

https://spec.torproject.org/control-spec/commands.html#getinfo

`AUTHCHALLENGE SAFECOOKIE`: 1 line
    If the server accepts the command, the server reply format is:

    ```
    "250 AUTHCHALLENGE" SP "SERVERHASH=" ServerHash SP "SERVERNONCE="
    ServerNonce CRLF
    ```

https://spec.torproject.org/control-spec/commands.html#authenticate

`PROTOCOLINFO`: 4-5 lines

    The server reply format is:

    ```
    250-PROTOCOLINFO" SP PIVERSION CRLF \*InfoLine "250 OK" CRLF
    InfoLine = AuthLine / VersionLine / OtherLine
    ```

(https://spec.torproject.org/control-spec/commands.html#protocolinfo)

`ADD_ONION`: 2-3 lines for Bitcoin Core's tor control client.

    The server reply format is:

    ```
    "250-ServiceID=" ServiceID CRLF
    ["250-PrivateKey=" KeyType ":" KeyBlob CRLF]
    *("250-ClientAuth=" ClientName ":" ClientBlob CRLF)
    "250 OK" CRLF
    ```

    ...

    The server response will only include a private key if the server
was requested to generate a new keypair

    ...

    If client authorization is enabled using the “BasicAuth” flag (which
    is v2 only), the service will not be accessible to clients without
    valid authorization data (configured with the “HidServAuth” option).
    The list of authorized clients is specified with one or more
    “ClientAuth” parameters. If “ClientBlob” is not specified for a
    client, a new credential will be randomly generated and returned."

https://spec.torproject.org/control-spec/commands.html#add_onion

We don't set the `BasicAuth` flag, so the response will not include any
`ClientAuthLines`.
2026-04-17 11:53:17 -07:00
David Gumberg
8b68287bf9 test: Make torcontrol max line length test stricter and test boundaries.
Adds a check that at the boundary of MAX_LINE_LENGTH, no disconnect
occurs.

Also makes the overlength test message exactly MAX_LINE_LENGTH + 1 to
test the boundary.

Drops the redundant node liveness check, which is covered by the later
check that the node reconnects.
2026-04-17 11:53:17 -07:00
Alexander Wiederin
07b9b13b45 doc: add integer type conventions in btck api remarks 2026-04-17 16:48:09 +02:00
Matthew Zipkin
f49a2afd94 test: interface_http follow-ups
- Only one node needed for test
- Use ascii encoding instead of utf-8
- Make tests independent of each other
- Expect HTTP error code 413 for too-large request
- Clarify python client race condition in comment
2026-04-17 10:45:03 -04:00
Alexander Wiederin
ba6287a449 kernel: align height parameters to int32_t in btck API
Aligns btck_chain_get_height and btck_chain_get_by_height to use int32_t
for height parameters and return values. Updates the C++ wrapper
accordingly.
2026-04-17 16:35:31 +02:00
fanquake
b02d6b0567 ci: drop -lstdc++ usage in msan fuzz job 2026-04-17 13:45:12 +01:00
fanquake
655a39ee14 ci: use llvm 22.1.3 2026-04-17 13:45:11 +01:00
merge-script
1fa34f90a2 Merge bitcoin/bitcoin#35095: doc: fix typos and minor formatting issues
bdc8e496da doc: fix typos and formatting in CONTRIBUTING, i2p, bitcoin-conf, files (Guillermo Fernandes)

Pull request description:

  Fix four small documentation issues found in actively maintained files:

  - `CONTRIBUTING.md`: "Valid areas as:" → "Valid areas are:" (grammar)
  - `doc/i2p.md`: remove double space after period
  - `doc/bitcoin-conf.md`: "some negating some lists" → "some negating lists" (duplicate word)
  - `doc/files.md`: missing space after comma in `**macOS**,the`

ACKs for top commit:
  maflcko:
    lgtm ACK bdc8e496da
  NellyNakhero:
    ACK bdc8e496da

Tree-SHA512: 15a5e284d517f7311a8c7c02a17292504a9eeafbaa81dc12a63a22fa1d49122e437e5647d9d0fbf397b5d150d0586632daccf0d2a7e7775a9bfd38083f0dfdcd
2026-04-17 10:05:35 +01:00
Guillermo Fernandes
bdc8e496da doc: fix typos and formatting in CONTRIBUTING, i2p, bitcoin-conf, files
- CONTRIBUTING.md: "Valid areas as" -> "Valid areas are"
- doc/i2p.md: remove double space after period
- doc/bitcoin-conf.md: "some negating some lists" -> "some negating lists"
- doc/files.md: missing space after comma in "macOS,the"
2026-04-16 23:18:20 -04:00
David Gumberg
ab5889796f refactor: torcontrol add connection checks to restart_with_mock 2026-04-16 18:11:44 -07:00
Hennadii Stepanov
e7d647388c Merge bitcoin/bitcoin#34923: depends: remove workaround for Make older than 4.2.90
f1e14dfbe9 depends: remove workaround for Make older than 4.2.90 (fanquake)

Pull request description:

  This was introduced for distros shipping older `make`, such as Ubuntu `20.04` (`4.2.1`). It's likely that any distros being used for Darwin and Windows cross compilation, are shipping a newer make at this point.

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

Tree-SHA512: bb5d785e4804f0b0d51c5abba31ee4537cf04247801edef51a5da728c7df7fff1189625d222f91b8f5896f9ec71dc8dbd11614a69e13e0dcad6017cab7dd5874
2026-04-16 17:19:16 +01:00
merge-script
c4361e53cd Merge bitcoin/bitcoin#34757: guix: re-enable riscv exported symbol checking
19e99be011 guix: remove riscv exclusion from symbol check (fanquake)
47b7a9f666 guix: binutils 2.46.0 (fanquake)

Pull request description:

  Switching to binutils `2.46.0` fixes the spurious exported symbols (2.45.1 was still broken).

  The relevant upstream change is https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=9e10fcf71c1101fb6422d0f52de5e615ed8df71d.

  Fixes #28095.

ACKs for top commit:
  hebasto:
    re-ACK 19e99be011, only rebased and properly adjusted since my recent [review](https://github.com/bitcoin/bitcoin/pull/34757#pullrequestreview-4015011610).

Tree-SHA512: 5673e8df8e2297e41c3f50fbe87ee506684a7dd7e8be27fc5613853ace9732d92616c10870614f6b196ca71a581470eb6f432cfd102e1fce58bbaf18c599342e
2026-04-16 13:46:04 +01:00
MarcoFalke
fa16bc53d7 test: Require named arg for create_block ntime arg
The named arg is useful, so that the two integral args (possibly
integral literals) `height` and `ntime` are not confused.
2026-04-16 14:08:56 +02:00
MarcoFalke
fab352053d test: Remove unused create_coinbase imports 2026-04-16 14:08:53 +02:00
MarcoFalke
fad6deb3cb scripted-diff: Use new create_block height option
-BEGIN VERIFY SCRIPT-

 # Replace single-arg create_coinbase calls ...
 # ... followed by ntime arg
 sed --in-place --regexp-extended 's/create_block\((.+), create_coinbase\(([^,]+)\), /create_block(\1, height=\2, ntime=/g' $( git grep -l 'create_block(' )
 # ... not followed by any other args
 sed --in-place --regexp-extended 's/create_block\((.+), create_coinbase\(([^,]+)\)\)/create_block(\1, height=\2)/g'        $( git grep -l 'create_block(' )

-END VERIFY SCRIPT-
2026-04-16 14:08:33 +02:00
MarcoFalke
fa5eb74b96 test: Allow to set height in create_block
Previously, it was only possible to set the height indirectly by calling
create_coinbase outside the create_block function. This is fine, but
verbose and not needed.

Just like hashprev can be set directly (instead of using the value from
tmpl), allow height to be set directly.

Also, use it in one place. The other places are done in a scripted-diff.

Also, add a unit test for the new feature.
2026-04-16 14:08:17 +02:00
Torkel Rogstad
c54f37c1ba cli, rpc: add -rpcid option for custom request IDs
Add a -rpcid CLI argument to bitcoin-cli that allows setting a custom
string as the JSON-RPC request ID instead of the hardcoded default of 1.
This enables correlating requests and responses when debugging or when
multiple clients are making concurrent calls.

On the server side, include the request ID in the RPC debug log line
when it differs from the default value of 1, so that custom IDs are
visible in the debug.log output.
2026-04-16 12:58:49 +02:00
fanquake
4d040b7d62 doc: archive release notes for v31.0 2026-04-16 09:22:29 +01:00
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
merge-script
53f4743c21 Merge bitcoin/bitcoin#35080: test: Add missing self.options.timeout_factor scale in tool_bitcoin_chainstate.py
fa02eb87df test: Add missing self.options.timeout_factor scale in tool_bitcoin_chainstate.py (MarcoFalke)

Pull request description:

  Without the factor, the test may fail when run cross-arch, possibly with sanitizers. E.g. in qemu-aarch64 in docker in a x86-VM.

ACKs for top commit:
  fanquake:
    ACK fa02eb87df

Tree-SHA512: 7dbf492de7478bcc95a62576499947fa83031c43496700657014aa9b29f6665c2a226b71287b71b8cd7a5240036c00f069f12ab231539e3387fe86ca298d6933
2026-04-15 15:13:41 +01:00
merge-script
edcf84c73a Merge bitcoin/bitcoin#35077: kernel: build: remove unused serfloat dependency
49895b9cbd kernel: build: remove unused serfloat dependency (Sebastian Falbesoner)

Pull request description:

  The serfloat module (more concretely, its two functions `{Encode,Decode}Double`) is only used for [fee estimation](7844a2f083/src/policy/fees/block_policy_estimator.cpp (L21)), which is not included in the bitcoinkernel library, so the linking dependency can be removed.

  (Not terribly important in practice, but: this reduces the static library size by ~1.5 KB (~2.7 KB unstripped) on my arm64 Linux machine.)

ACKs for top commit:
  davidgumberg:
    ACK 49895b9cbd
  stickies-v:
    ACK 49895b9cbd

Tree-SHA512: c3b4feec55cdc7476f54185db95c94e7365f5feadf09d3740d51dce32a1ceeef4d38ecf5c8cf7ca4ed326a12dab386bb104da978ff06bdf739889b2cfa81603d
2026-04-15 09:18:00 +01:00
MarcoFalke
fa02eb87df test: Add missing self.options.timeout_factor scale in tool_bitcoin_chainstate.py
Apply the timeout factor inside the add_block function.

Also, force named args for the two expected strings.

Also, add trailing comma for style.
2026-04-15 09:32:01 +02:00
Sebastian Falbesoner
49895b9cbd kernel: build: remove unused serfloat dependency
The serfloat module is only used for fee estimation, which is not
included in the bitcoinkernel library, so the dependency can be removed.
2026-04-14 23:57:37 +02:00