Commit Graph

1600 Commits

Author SHA1 Message Date
MarcoFalke
fab51e470e test: Move valgrind.supp to the other sanitizer_suppressions files 2026-02-27 12:27:49 +01:00
MarcoFalke
fa9cf81d39 test: Add missing resolve() to valgrind.supp file
Normally, when a symlinked test script is executed directly (e.g.,
`./bld-cmake/test/functional/wallet_disable.py`), Python's default
behavior is to resolve the symlink of the script itself, setting
`sys.path[0]` to the directory containing the physical source file.
Consequently, the test framework util.py is imported from the source
tree, and `Path(__file__).parents[3]` correctly resolves to the source
root.

However, `feature_framework_testshell.py` is unique because it manually
inserts `Path(__file__).parent` into `sys.path`. That refers to the
build tree and when importing the test framework util.py, the
`Path(__file__).parents[3]` will incorrectly point to the build
directory instead of the source root.

Use `.resolve()` to ensure the Valgrind suppressions file path is always
calculated relative to the physical source file, regardless of how the
framework was imported.
2026-02-27 12:27:42 +01:00
Ava Chow
b6b8f8ac55 Merge bitcoin/bitcoin#34562: ThreadPool follow-ups, proactive shutdown and HasReason dependency cleanup
408d5b12e8 test: include response body in non-JSON HTTP error msg (Matthew Zipkin)
9dc653b3b4 test: threadpool, add coverage for all Submit() errors (furszy)
ce2a984ee3 test: cleanup, use HasReason in threadpool_tests.cpp (l0rinc)
d9c6769d03 test: refactor, decouple HasReason from test framework machinery (furszy)
dbbb780af0 test: move and simplify BOOST_CHECK ostream helpers (Hodlinator)
3b7cbcafcb test: ensure Stop() thread helps drain the queue (seduless)
ca101a2315 test: coverage for queued tasks completion after interrupt (furszy)
bf2c607aaa threadpool: active-wait during shutdown (furszy)
e88d274430 test: add threadpool Start-Stop race coverage (furszy)
8cd4a4363f threadpool: guard against Start-Stop race (furszy)
9ff1e82e7d test: cleanup, block threads via semaphore instead of shared_future (l0rinc)

Pull request description:

  A few follow-ups to #33689, includes:

  1) `ThreadPool` active-wait during shutdown:
  Instead of just waiting for workers to finish processing tasks, `Stop()` now helps them actively.
  This speeds up the JSON-RPC and REST server shutdown, resulting in a faster node shutdown when many requests remain unhandled. This wasn't included in the original PR due to the behavior change this introduces.

  2) Decouple `HasReason` from the unit test framework machinery
  This avoids providing the entire unit test framework dependency to low-level tests that only require access to the `HasReason` utility class. Examples are: `reverselock_tests.cpp`, `sync_tests.cpp`, `util_check_tests.cpp`, `util_string_tests.cpp`, `script_parse_tests.cpp` and `threadpool_tests.cpp`. These tests no longer gain access to unnecessary components like the chainstate, node context, caches, etc. It includes l0rinc's `threadpool_tests.cpp` `HasReason` changes.

  3) Include response body in non-JSON HTTP error messages
  Straight from pinheadmz [comment](https://github.com/bitcoin/bitcoin/pull/33689#discussion_r2783817192), it makes debugging CI issues easier.

ACKs for top commit:
  maflcko:
    review ACK 408d5b12e8 🕗
  achow101:
    ACK 408d5b12e8
  hodlinator:
    re-ACK 408d5b12e8

Tree-SHA512: 57aa0ef96886f32bf95a0bd7f87c878d31c9df9e34cb96de615eee703ce0824b5cfdf8f5c9cd19a3594559994295b5810c38c94f5efd6291cbbd83a95473357a
2026-02-26 12:44:11 -08:00
Matthew Zipkin
408d5b12e8 test: include response body in non-JSON HTTP error msg
Useful for debugging issues.

Co-authored-by: Matias Furszyfer <matiasfurszyfer@protonmail.com>
2026-02-26 11:28:55 -03:00
Ryan Ofsky
403523127b Merge bitcoin/bitcoin#34608: test: Fix broken --valgrind handling after bitcoin wrapper
fa5d478853 test: valgrind --trace-children=yes for bitcoin wrapper (MarcoFalke)
fa29fb72cb test: Remove redundant warning about missing binaries (MarcoFalke)
fa03fbf7e3 test: Fix broken --valgrind handling after bitcoin wrapper (MarcoFalke)

Pull request description:

  Currently, tool_bitcoin.py is failing under `--valgrind`:

  ```sh
  $ ./bld-cmake/test/functional/tool_bitcoin.py --valgrind
  TestFramework (ERROR): Unexpected exception
  Traceback (most recent call last):
    File "./test/functional/test_framework/test_framework.py", line 138, in main
      self.setup()
      ~~~~~~~~~~^^
    File "./test/functional/test_framework/test_framework.py", line 269, in setup
      self.setup_network()
      ~~~~~~~~~~~~~~~~~~^^
    File "./test/functional/tool_bitcoin.py", line 38, in setup_network
      assert all(node.args[:len(node_argv)] == node_argv for node in self.nodes)
             ~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  AssertionError
  ```

  Fix this issue by running `bitcoin` under valgrind.

ACKs for top commit:
  achow101:
    ACK fa5d478853
  ryanofsky:
    Code review ACK fa5d478853 just squashing commits since last review (Thanks!)

Tree-SHA512: 503685ac69e1ca3046958655bed4fe6d0aee1525c5ea58ebf098efd0332c0e16f138540baffaf9af1263a8c42ac6b150ed8bca5a5371a3c49802e21957ec6632
2026-02-25 05:03:05 -05:00
MarcoFalke
fa5d478853 test: valgrind --trace-children=yes for bitcoin wrapper 2026-02-24 13:16:08 +01:00
MarcoFalke
fa29fb72cb test: Remove redundant warning about missing binaries
The error was added in commit 1ea7e45a1f,
because there was an additional confusing `AssertionError: [node 0]
Error: no RPC connection` instead of just a single `FileNotFoundError:
[Errno 2] No such file or directory`.

This is no longer needed on current master.

Also, the test is incomplete, because it was just checking bitcoind and
bitcoin-cli, not any other missing binaries.

Also, after the previous commit, it would not work in combination with
--valgrind.

Instead of trying to make it complete, and work in all combinations,
just remove it, because the already existing error will be clear in any
case.

This can be tested via:

```sh
 ./test/get_previous_releases.py

 mv releases releases_backup
 # Confirm the test is skipped due to missing releases
 ./bld-cmake/test/functional/wallet_migration.py
 # Confirm the test fails due to missing releases
 ./bld-cmake/test/functional/wallet_migration.py --previous-releases
 mv releases_backup releases

 mv ./releases/v28.2 ./releases/v28.2_backup
 # Confirm the test fails with a single FileNotFoundError
 ./bld-cmake/test/functional/wallet_migration.py
 mv ./releases/v28.2_backup ./releases/v28.2
 # Confirm the test runs and passes
 ./bld-cmake/test/functional/wallet_migration.py

 rm ./bld-cmake/bin/bitcoind
 # Confirm the test fails with a single "No such file or directory",
 # testing with and without --valgrind
 ./bld-cmake/test/functional/wallet_migration.py
 ./bld-cmake/test/functional/wallet_migration.py --valgrind
```
2026-02-24 13:15:58 +01:00
MarcoFalke
fa03fbf7e3 test: Fix broken --valgrind handling after bitcoin wrapper
Prior to this commit, tool_bitcoin.py was failing:

```sh
$ ./bld-cmake/test/functional/tool_bitcoin.py --valgrind
TestFramework (ERROR): Unexpected exception
Traceback (most recent call last):
  File "./test/functional/test_framework/test_framework.py", line 138, in main
    self.setup()
    ~~~~~~~~~~^^
  File "./test/functional/test_framework/test_framework.py", line 269, in setup
    self.setup_network()
    ~~~~~~~~~~~~~~~~~~^^
  File "./test/functional/tool_bitcoin.py", line 38, in setup_network
    assert all(node.args[:len(node_argv)] == node_argv for node in self.nodes)
           ~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
```

This commit fixes this issue by running `bitcoin` under valgrind. Also,
it comes with other improvements:

* Drop the outdated valgrind 3.14 requirement, because there is no
  distro that ships a version that old anymore.
* Drop the VALGRIND_SUPPRESSIONS_FILE env var handling, because it was
  presumably never used since it was introduced. Also, the use-case
  seems limited.

Review note:

The set_cmd_args was ignoring the --valgrind test option.

In theory, this could be fixed by refactoring Binaries::node_argv() to
be used here. However, for now, just re-implement the node_argv logic in
set_cmd_args to prepend the valgrind cmd.
2026-02-24 13:15:57 +01:00
merge-script
cb3473a680 Merge bitcoin/bitcoin#34568: mining: Break compatibility with existing IPC mining clients
f700609e8a doc: Release notes for mining IPC interface bump (Ryan Ofsky)
9453c15361 ipc mining: break compatibility with existing clients (version bump) (Sjors Provoost)
70de5cc2d2 ipc mining: pass missing context to BlockTemplate methods (incompatible schema change) (Sjors Provoost)
2278f017af ipc mining: remove deprecated methods (incompatible schema change) (Ryan Ofsky)
c6638fa7c5 ipc mining: provide default option values (incompatible schema change) (Ryan Ofsky)
a4603ac774 ipc mining: declare constants for default field values (Ryan Ofsky)
ff995b50cf ipc test: add workaround to block_reserved_weight exception test (Ryan Ofsky)
b970cdf20f test framework: expand expected_stderr, expected_ret_code options (Ryan Ofsky)
df53a3e5ec rpc refactor: stop using deprecated getCoinbaseCommitment method (Ryan Ofsky)

Pull request description:

  This PR increments the field number of the `Init.makeMining` method and makes the old `makeMining` method return an error, so IPC mining clients not using the latest schema file will get an error and not be able to access the Mining interface.

  Normally, there shouldn't be a need to break compatibility this way, but the mining interface has evolved a lot since it was first introduced, with old clients using the original methods less stable and performant than newer clients. So now is a good time to introduce a cutoff, drop deprecated methods, and stop supporting old clients which can't function as well.

  Bumping the field number is also an opportunity to make other improvements that would be awkward to implement compatibly:
  - Making Cap'n Proto default parameter and field values match default values of corresponding C++ methods and structs.
  - Adding missing Context parameters to Mining.createNewBlock and checkBlock methods so these methods will be executed on separate execution threads and not block the Cap'n Proto event loop thread.

  More details about these changes are in the commit messages.

ACKs for top commit:
  Sjors:
    ACK f700609e8a
  enirox001:
    ACK f700609e8a
  ismaelsadeeq:
    ACK f700609e8a
  sedited:
    ACK f700609e8a

Tree-SHA512: 0901886af00214c138643b33cec21647de5671dfff2021afe06d78dfd970664a844cde9a1e28f685bb27edccaf6e0c3f2d1e6bb4164bde6b84f42955946e366d
2026-02-20 11:06:06 +01:00
Ava Chow
4933d1fbba Merge bitcoin/bitcoin#28792: build: Embedded ASMap [3/3]: Build binary dump header file
24699fec84 doc: Add initial asmap data documentation (Fabian Jahr)
bab085d282 ci: Use without embedded asmap build option in one ci job (Fabian Jahr)
e53934422a doc: Expand documentation on asmap feature and tooling (Fabian Jahr)
6244212a55 init, net: Implement usage of binary-embedded asmap data (Fabian Jahr)
6202b50fb9 build: Generate ip_asn.dat.h during build process (Fabian Jahr)
634cd60dc8 build: Add embedded asmap data (Fabian Jahr)

Pull request description:

  This is the final in a series of PRs that implement the necessary changes for embedding of asmap data into the binary. This last part add the initial asmap data, implements the build changes and adds further documentation.

  Currently an asmap file needs to be acquired by there user from some location or the user needs to generate one themselves. Then they need to move the file to the right place in datadir or pass the path to the file as `-asmap=PATH` in order to use the asmap feature. The change here allows for builds to embed asmap data into the bitcoind binary which makes it possible to use the feature without handling of the asmap file by the user. If the user starts bitcoind with `-asmap` the embedded data will be used for bucketing of nodes.

  The data lives in the repository at `src/node/data/ip_asn.dat` and can be replaced with a new version at any time. The idea is that the data should be updated with every release. By default the data at that location is embedded into the binary but there is also a build option to prevent this (`-DWITH_EMBEDDED_ASMAP=OFF`). In this case the original behavior of the `-asmap` option is maintained.

ACKs for top commit:
  achow101:
    ACK 24699fec84
  sipa:
    ACK 24699fec84
  hodlinator:
    ACK 24699fec84

Tree-SHA512: c2e33dbeea387efdfd3d415432bf8fa64de80f272c1207015ea53b85bb77f5c29f1dae5644513a23c844a98fb0a4bb257bf765f38b15bfc4c41984f0315b4c6a
2026-02-18 16:43:34 -08:00
merge-script
9e4567b17a Merge bitcoin/bitcoin#34581: test: Set assert_debug_log timeout to 0
fa4cb96bde test: Set assert_debug_log timeout to 0 (MarcoFalke)

Pull request description:

  The `assert_debug_log` helper is meant to be a context manager. However, it has a  default timeout of 2 seconds, and can act as a silent polling/wait/sync function. This is confusing and brittle, and leads to intermittent bugs such as https://github.com/bitcoin/bitcoin/pull/34571.

  Fix all issues, by setting the default timeout to zero. Then adjust all call sites to either use this correctly like a context manager, or adjust them explicitly to specify a timeout, to document that this is a polling sync function.

ACKs for top commit:
  hodlinator:
    re-ACK fa4cb96bde
  brunoerg:
    ACK fa4cb96bde

Tree-SHA512: 111a45c84327c3afea98fd9f8de13dd7d11969b2309471b4ad21694b290a3734f6e1eda75a41b39613b0995c5b7075298085cea2ca06aa07d4385eb8d72fe95b
2026-02-18 17:03:32 +00:00
MarcoFalke
fa4cb96bde test: Set assert_debug_log timeout to 0 2026-02-17 16:10:47 +01:00
MarcoFalke
211111b804 test: Avoid empty errmsg in JSONRPCException
It is unclear why the fallback should be an empty message, when it is
better to include all rpc_error details that are available.

Also, include the http status.

This allows to revert commit 6354b4fd7f,
because it is no longer needed.
2026-02-13 18:55:53 +01:00
Sjors Provoost
70de5cc2d2 ipc mining: pass missing context to BlockTemplate methods (incompatible schema change)
Adding a context parameter ensures that these methods are run in
their own thread and don't block other calls. They were missing
for:

- createNewBlock()
- checkBlock()

The missing parameters were first pointed out by plebhash in
https://github.com/bitcoin/bitcoin/issues/33575#issuecomment-3383290115 and
adding them should prevent possible performance problems and lockups,
especially with #34184 which can make the createNewBlock method block for a
long time before returning. It would be straightforward to make this change in
a backward compatible way
(https://github.com/bitcoin/bitcoin/pull/34184#discussion_r2770232149) but nice
to not need to go through the trouble.

Warning: This is an intermediate, review-only commit. Binaries built from it
should not be distributed or used to connect to other clients or servers. It
makes incompatible changes to the `mining.capnp` schema without updating the
`Init.makeMining` version, causing binaries to advertise support for a schema
they do not actually implement. Mixed versions may therefore exchange garbage
requests/responses instead of producing clear errors. The final commit in this
series bumps the mining interface number to ensure mismatches are detected.

git-bisect-skip: yes

Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
2026-02-12 03:34:08 +01:00
Ryan Ofsky
2278f017af ipc mining: remove deprecated methods (incompatible schema change)
This change removes deprecated methods from the ipc mining interface.

Warning: This is an intermediate, review-only commit. Binaries built from it
should not be distributed or used to connect to other clients or servers. It
makes incompatible changes to the `mining.capnp` schema without updating the
`Init.makeMining` version, causing binaries to advertise support for a schema
they do not actually implement. Mixed versions may therefore exchange garbage
requests/responses instead of producing clear errors. The final commit in this
series bumps the mining interface number to ensure mismatches are detected.

git-bisect-skip: yes
2026-02-11 21:34:08 -05:00
Ryan Ofsky
b970cdf20f test framework: expand expected_stderr, expected_ret_code options
Allow `expected_stderr` option passed to `wait_until_stopped` and
`is_node_stopped` helper functions to be a regex pattern instead of just a
fixed string.

Allow `expected_ret_code` be list of possible exit codes instead of a single
error code to handle the case where exit codes vary depending on OS and libc.
2026-02-11 21:34:08 -05:00
Ryan Ofsky
0b4cd08fcd Merge bitcoin/bitcoin#33965: mining: fix -blockreservedweight shadows IPC option
b623fab1ba mining: enforce minimum reserved weight for IPC (Sjors Provoost)
d3e49528d4 mining: fix -blockreservedweight shadows IPC option (Sjors Provoost)
418b7995dd test: have mining template helpers return None (Sjors Provoost)

Pull request description:

  Also enforce `MINIMUM_BLOCK_RESERVED_WEIGHT` for IPC clients.

  The `-blockreservedweight` startup option should only affect RPC code, because IPC clients (currently) do not have a way to signal their intent to use the node default (the `BlockCreateOptions` struct defaults merely document a recommendation for client software).

  Before this PR however, if the user set `-blockreservedweight` then `ApplyArgsManOptions` would cause the `block_reserved_weight` option passed by IPC clients to be ignored. _Users who don't set this value were not affected._

  Fix this by making BlockCreateOptions::block_reserved_weight an std::optional.

  Internal interface users, such as the RPC call sites, don't set a value so -blockreservedweight is used. Whereas IPC clients do set a value which is no longer ignored.

  Test coverage is added, with a preliminary commit that refactors the `create_block_template` and `wait_next_template` helpers.

  `mining_basic.py` already ensured `-blockreservedweight` is enforced by mining RPC methods. The second commit adds coverage for Mining interface IPC clients. It also verifies that `-blockreservedweight` has no effect on them.

  The third commit enforces `MINIMUM_BLOCK_RESERVED_WEIGHT` for IPC clients. Previously lower values were quietly clamped.

  ---

  Merge order preference: #34452 should ideally go first.

ACKs for top commit:
  sedited:
    Re-ACK b623fab1ba
  ryanofsky:
    Code review ACK b623fab1ba. Was rebased and test split up and comment updated since last review.
  ismaelsadeeq:
    ACK b623fab1ba

Tree-SHA512: 9e651a520d8e4aeadb330da86788744b6ecad8060fa21d50dc8e6012a60083e7b262aaa08a64676b9ef18ba65b651bc1272d8383d184030342e4c0f2c6a9866d
2026-02-11 21:22:28 -05:00
merge-script
4a05825a3f Merge bitcoin/bitcoin#33689: http: replace WorkQueue and single threads handling for ThreadPool
38fd85c676 http: replace WorkQueue and threads handling for ThreadPool (furszy)
c323f882ed fuzz: add test case for threadpool (TheCharlatan)
c528dd5f8c util: introduce general purpose thread pool (furszy)
6354b4fd7f tests: log node JSON-RPC errors during test setup (furszy)
45930a7941 http-server: guard against crashes from unhandled exceptions (furszy)

Pull request description:

  This has been a recent discovery; the general thread pool class created for #26966, cleanly
  integrates into the HTTP server. It simplifies init, shutdown and requests execution logic.
  Replacing code that was never unit tested for code that is properly unit and fuzz tested.
  Although our functional test framework extensively uses this RPC interface (that’s how
  we’ve been ensuring its correct behavior so far - which is not the best).

  This clearly separates the responsibilities:
  The HTTP server now focuses solely on receiving and dispatching requests, while ThreadPool handles
  concurrency, queuing, and execution.

  This will also allows us to experiment with further performance improvements at the task queuing and
  execution level, such as a lock-free structure or task prioritization or any other implementation detail
  like coroutines in the future, without having to deal with HTTP code that lives on a different layer.

  Note:
  The rationale behind introducing the ThreadPool first is to be able to easily cherry-pick it across different
  working paths. Some of the ones that are benefited from it are #26966 for the parallelization of the indexes
  initial sync, #31132 for the parallelization of the inputs fetching procedure, #32061 for the libevent replacement,
  the kernel API #30595 (https://github.com/bitcoin/bitcoin/pull/30595#discussion_r2413702370) to avoid blocking validation among others use cases not publicly available.

  Note 2:
  I could have created a wrapper around the existing code and replaced the `WorkQueue` in a subsequent
  commit, but it didn’t seem worth the extra commits and review effort. The `ThreadPool` implements
  essentially the same functionality in a more modern and cleaner way.

ACKs for top commit:
  Eunovo:
    ReACK 38fd85c676
  sedited:
    Re-ACK 38fd85c676
  pinheadmz:
    ACK 38fd85c676

Tree-SHA512: a0330e54ed504330ca874c42d4e318a909f548b2fb9ac46db8badf5935b9eec47dc4ed503d1b6f98574418e3473420ea45f60498be05545c4325cfa89dcca689
2026-02-11 18:04:17 +01:00
Sjors Provoost
418b7995dd test: have mining template helpers return None
Refactor the mining_create_block_template and mining_wait_next_template
helpers in ipc_util.py to return None if they time out or fail. It makes
the test easier to read and provides a more clear error message in case
of a regression.

There were a few spots that didn't use mining_wait_next_template yet,
which now do.
2026-02-07 13:13:31 +01:00
Sjors Provoost
01a1ae889e test: move IPC helpers to ipc_util.py
Move IPC helpers into ipc_util.py and update interface_ipc.py
to use them.

Rename some helpers for clarity:
- parse_and_deserialize_block -> mining_get_block
- parse_and_deserialize_coinbase_tx -> mining_get_coinbase_tx
- get_coinbase_raw_tx -> mining_get_coinbase_raw_tx
- wait_next_template -> mining_wait_next_template
2026-02-06 15:44:06 +01:00
Fabian Jahr
6202b50fb9 build: Generate ip_asn.dat.h during build process
This can be disabled with -DWITH_EMBEDDED_ASMAP=OFF.
2026-02-03 18:03:37 +01:00
Ava Chow
47c9297172 Merge bitcoin/bitcoin#32420: mining, ipc: omit dummy extraNonce from coinbase
d511adb664 [miner] omit dummy extraNonce via IPC (Sjors Provoost)
bf3b5d6d06 test: clarify getCoinbaseRawTx() comparison (Sjors Provoost)
78df9003d6 [doc] Update comments on dummy extraNonces in tests (Anthony Towns)

Pull request description:

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

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

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

Tree-SHA512: d41fa813eb6b5626f4f475d8abc506b29090f4a2d218f2d6824db58b5ebe2ed7c584a903b44de18ccec142bb79c257b0aba6d6da073f56175aec88df96aaaaba
2026-02-02 15:21:16 -08:00
Hennadii Stepanov
f7e0c3d3d3 Merge bitcoin/bitcoin#34346: test: use IP_PORTRANGE_HIGH on FreeBSD for dynamic port allocation
2845f10a2b test: extend FreeBSD ephemeral port range fix to P2P listeners (node)
34bed0ed8c test: use IP_PORTRANGE_HIGH on FreeBSD for dynamic port allocation (woltx)

Pull request description:

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

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

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

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

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

  Fixes #34331

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

Tree-SHA512: ce501ce3e8a4023e07bad572df2b85d6829becf133813e4529aebba83e4eba59fa8b48e9d2197ebbb226adaf3054fad720775a787244d6b38c0078ee086102f4
2026-01-29 11:33:35 +00:00
furszy
6354b4fd7f tests: log node JSON-RPC errors during test setup
Currently, if the node replies to any command with an error during
the test framework's setup(), we log the generic and not really useful
"Unexpected exception" from the BaseException catch, with no further
information.
This isn't helpful for diagnosing the issue. Fix it by explicitly handling
JSONRPCException and logging the response error message and http status
code.
2026-01-28 19:03:33 -05:00
Anthony Towns
78df9003d6 [doc] Update comments on dummy extraNonces in tests 2026-01-27 14:41:00 +01:00
merge-script
8593d96519 Merge bitcoin/bitcoin#33067: test: refactor ValidWitnessMalleatedTx class to helper function
3f5211cba8 test: remove child_one/child_two (w)txid variables (naiyoma)
7cfe790820 test: replace ValidWitnessMalleatedTx class with function (naiyoma)
81675a781f test: use pre-generated chain (naiyoma)

Pull request description:

  This PR refactors ` ValidWitnessMalleatedTx` class into a `build_malleated_tx_package` function. As a result, two tests are updated:  `mempool_accept_wtxid` and `p2p_p2p_private_broadcast`. Also included are a  few small refactors in mempool_accept_wtxid , (switching to MiniWallet, using a pre-mined chain, using txid directly.)

  Together, these changes reduce complexity and improve test runtime.

ACKs for top commit:
  stratospher:
    reACK 3f5211c.
  cedwies:
    reACK 3f5211c
  maflcko:
    review ACK 3f5211cba8 👥
  rkrux:
    ACK 3f5211cba8

Tree-SHA512: 1fd02be3432fef6b68e54fbe8b15ed56d2699580bb13d0777b21f9cbe4c6d33bbb710541e3ca2fc93eab771d17bf1c427e4b08fa216d561bdb320cc6b36ac8fc
2026-01-27 10:10:41 +00:00
merge-script
5715748333 Merge bitcoin/bitcoin#34366: test: switch order of error code and message check
0aba464ce7 test: switch order of error code and message check (rkrux)

Pull request description:

  I feel it'd be easier to debug intermittent test failures if the error message is present in the logs instead of error code. So, switching order of error code and message in the `try_rpc` function to aid error debugging.

  Should help in debugging #34354 IMO. It's an intermittent failure on Windows that I can't reproduce and it's more difficult to figure out what could have gone wrong only by seeing the error code like below in the CI logs. Given that the functional tests pass, I don't see a harm in checking for error message first and throwing it in case of a mismatch.

  ```python
  AssertionError: Unexpected JSONRPC error code -1
  ```

  <!--
  *** Please remove the following help text before submitting: ***

  Pull requests without a rationale and clear improvement may be closed
  immediately.

  GUI-related pull requests should be opened against
  https://github.com/bitcoin-core/gui
  first. See CONTRIBUTING.md
  -->

  <!--
  Please provide clear motivation for your patch and explain how it improves
  Bitcoin Core user experience or Bitcoin Core developer experience
  significantly:

  * Any test improvements or new tests that improve coverage are always welcome.
  * All other changes should have accompanying unit tests (see `src/test/`) or
    functional tests (see `test/`). Contributors should note which tests cover
    modified code. If no tests exist for a region of modified code, new tests
    should accompany the change.
  * Bug fixes are most welcome when they come with steps to reproduce or an
    explanation of the potential issue as well as reasoning for the way the bug
    was fixed.
  * Features are welcome, but might be rejected due to design or scope issues.
    If a feature is based on a lot of dependencies, contributors should first
    consider building the system outside of Bitcoin Core, if possible.
  * Refactoring changes are only accepted if they are required for a feature or
    bug fix or otherwise improve developer experience significantly. For example,
    most "code style" refactoring changes require a thorough explanation why they
    are useful, what downsides they have and why they *significantly* improve
    developer experience or avoid serious programming bugs. Note that code style
    is often a subjective matter. Unless they are explicitly mentioned to be
    preferred in the [developer notes](/doc/developer-notes.md), stylistic code
    changes are usually rejected.
  -->

  <!--
  Bitcoin Core has a thorough review process and even the most trivial change
  needs to pass a lot of eyes and requires non-zero or even substantial time
  effort to review. There is a huge lack of active reviewers on the project, so
  patches often sit for a long time.
  -->

ACKs for top commit:
  maflcko:
    lgtm ACK 0aba464ce7
  polespinasa:
    lgtm ACK 0aba464ce7
  fjahr:
    utACK 0aba464ce7
  brunoerg:
    code review ACK 0aba464ce7
  sedited:
    ACK 0aba464ce7

Tree-SHA512: b09ba4b5d13a2c93a4a28a5c1b06af44a91295974236bb8326b74a988878c431e9ce0e19ec14bb98ac2b002da877abaa7da6a9851424453bcb494c0317b57227
2026-01-21 23:09:30 +01:00
merge-script
2a1234001c Merge bitcoin/bitcoin#34269: wallet: disallow creating new or restoring to an unnamed (default) wallet
75b704df9d wallettool: Disallow creating new unnamed wallets (Ava Chow)
5875a9c502 wallet: disallow unnamed wallets in createwallet and restorewallet (Ava Chow)
d30ad4a912 wallet, rpc: Use HandleWalletError in createwallet (Ava Chow)

Pull request description:

  We've been moving in the direction that all wallets must have a name. Therefore, we shouldn't allow creating new unnamed wallets. `createwallet`, `restorewallet`, and the wallet tool's `create` and `createfromdump` all now require the user to provide a non-empty wallet name when creating/restoring a wallet.

  The GUI is already enforcing this, but we were not enforcing it for RPCs or in the underlying `CreateWallet` and `RestoreWallet` functions.

  Wallet migration does still need to be able to restore unnamed wallets, so there is a new argument to `RestoreWallet` to explicitly allow that behavior for migration only.

ACKs for top commit:
  rkrux:
    lgtm ACK 75b704df9d
  polespinasa:
    re ACK 75b704df9d

Tree-SHA512: 8bde76d0b091e9276788c69412934af3426da2a7a69a00f94072d36c1a075cd41744ecdd5fef2b72870c1351b76aae061f124f716bb23f4839be20c464fc5ebd
2026-01-21 22:56:59 +01:00
node
2845f10a2b test: extend FreeBSD ephemeral port range fix to P2P listeners
The previous commit added set_ephemeral_port_range() to
avoid port conflicts on FreeBSD by requesting ports from the high
ephemeral range (49152-65535) instead of the default range
which overlaps with the test framework's static port range.

That fix was applied to the SOCKS5 server but not to P2P listeners
created via NetworkThread.create_listen_server(). This commit extends
the fix to cover P2P listeners as well.

When port=0 is requested (dynamic allocation), we now:
1. Manually create a socket with the appropriate address family
2. Call set_ephemeral_port_range() to configure the port range
3. Bind and listen on the socket
4. Pass the pre-configured socket to asyncio's create_server()

This ensures that dynamically allocated ports for P2P listeners also
come from the high range on FreeBSD, avoiding conflicts with the test
framework's static port assignments.

Co-Authored-By: Vasil Dimov <vd@FreeBSD.org>
2026-01-21 11:33:24 -08:00
MarcoFalke
fab055c907 test: Scale NetworkThread close timeout with timeout_factor 2026-01-21 16:18:07 +01:00
rkrux
0aba464ce7 test: switch order of error code and message check
I feel it'd be easier to debug intermittent test failures if the
error message is present in the logs instead of error code. So,
switching order of error code and message in the `try_rpc` function
to aid error debugging.
2026-01-21 17:23:30 +05:30
naiyoma
7cfe790820 test: replace ValidWitnessMalleatedTx class with function
Simplify the witness malleation test helper by converting the
ValidWitnessMalleatedTx class to a standalone function
build_malleated_tx_package() and updating call sites.

Co-authored-by: rkrux <rkrux.connect@gmail.com>
2026-01-21 14:07:59 +03:00
woltx
34bed0ed8c test: use IP_PORTRANGE_HIGH on FreeBSD for dynamic port allocation
On FreeBSD, the default ephemeral port range (10000-65535) overlaps
with the test framework's static port range (11000-26000), causing
intermittent "address already in use" failures when tests use dynamic
port allocation (port=0).

Add a helper function that sets the IP_PORTRANGE/IPV6_PORTRANGE socket
option to IP_PORTRANGE_HIGH before binding, which requests ports from
the high range (49152-65535) instead. This range does not overlap with
the test framework's static ports.

Constants from FreeBSD's netinet/in.h and netinet6/in6.h:
- IP_PORTRANGE = 19 (for IPv4 sockets)
- IPV6_PORTRANGE = 14 (for IPv6 sockets)
- IP_PORTRANGE_HIGH = 1

Fixes: bitcoin/bitcoin#34331

Co-Authored-By: Vasil Dimov <vd@FreeBSD.org>
Co-Authored-By: MarcoFalke <*~=\`'#}+{/-|&$^_@721217.xyz>
2026-01-20 12:08:05 -08:00
Ava Chow
5875a9c502 wallet: disallow unnamed wallets in createwallet and restorewallet
Migration still needs to be able to restore unnamed wallets, so
allow_unnamed is added to RestoreWallet to explicitly allow that
behavior for migration only.
2026-01-19 10:55:55 -08:00
Ava Chow
ae3b5a99f8 Merge bitcoin/bitcoin#34186: test: use dynamic port allocation in proxy tests
ce63d37ebe test: use dynamic port allocation to avoid test conflicts (woltx)

Pull request description:

  Use `port=0` for dynamic port allocation in test framework components to avoid intermittent "address already in use" errors when running tests concurrently or when ports are stuck in TIME_WAIT state. Example: https://github.com/bitcoin/bitcoin/pull/29415#discussion_r2634509304

  Changes:

    - Update `socks5.py` and `p2p.py` to support dynamic port allocation
    - Convert `feature_proxy.py` and `feature_anchors.py` to use `port=0`

ACKs for top commit:
  achow101:
    ACK ce63d37ebe
  vasild:
    ACK ce63d37ebe
  mzumsande:
    re-ACK ce63d37ebe

Tree-SHA512: 4efcedca3bde209fbd1bdc2a4ae04b7d53515587d86e421ce61064f78c675c71b45d9782b514c5e7cfc0e92842c947d49f7a3fddb03fe619fcdec9b565f0ecbd
2026-01-14 14:40:10 -08:00
Ryan Ofsky
62557c9529 Merge bitcoin/bitcoin#33819: mining: getCoinbase() returns struct instead of raw tx
48f57bb35b mining: add new getCoinbaseTx() returning a struct (Sjors Provoost)
d59b4cdb57 mining: rename getCoinbaseTx() to ..RawTx() (Sjors Provoost)

Pull request description:

  The first commit renames `getCoinbaseTx()` to `getCoinbaseRawTx()` to reflect that it returns a serialised transaction. This does not impact IPC clients, because they do not use the function name.

  The second commit then introduces a replacement `getCoinbase()` that provides a struct with everything clients need to construct a coinbase. This avoids clients having to parse and manipulate our dummy transaction.

  Deprecate but don't remove `getCoinbaseRawTx()`, `getCoinbaseCommitment()` and `getWitnessCommitmentIndex()`.

  After this change we can drop these deprecated methods, which in turn would allow us to clear the dummy transaction from the `getBlock()` result. But that is left for a followup to keep this PR focussed. See https://github.com/Sjors/bitcoin/pull/106 for an approach.

  Expand the `interface_ipc.py` functional test to document its usage.

  Can be tested using:
  - https://github.com/stratum-mining/sv2-tp/pull/59

ACKs for top commit:
  ryanofsky:
    Code review ACK 48f57bb35b. Just rebased and addressed comments and dropped coinbase tx "template" suffix, which is a nice change
  ismaelsadeeq:
    code review ACK 48f57bb35b
  vasild:
    ACK 48f57bb35b

Tree-SHA512: c4f1d752777fb3086a1a0b7b8b06e4205dbe2f3adb41f218855ad1dee952adccc263cf82acd3bf9300cc83c2c64cebd2b27f66a69beee32d325b9a85e3643b0d
2026-01-13 08:01:57 -05:00
woltx
ce63d37ebe test: use dynamic port allocation to avoid test conflicts
Use port=0 for dynamic port allocation in test framework components
to avoid "address already in use" errors from concurrent tests or
ports stuck in TIME_WAIT state from previous test runs.

Changes:
- socks5.py: Update conf.addr after bind() to reflect actual port
- p2p.py: Retrieve actual port after create_server() when port=0
- feature_proxy.py: Use port=0 for all SOCKS5 proxy servers
- feature_anchors.py: Use port=0 for onion proxy server
2026-01-09 18:43:44 -08:00
Ava Chow
0ad4376a49 Merge bitcoin/bitcoin#33142: test: Run bench sanity checks in parallel with functional tests
fa65bc0e79 test: Run bench sanity checks in parallel with functional tests (MarcoFalke)
fa9fdbce79 test: Pass bench exe into test framework utils (MarcoFalke)

Pull request description:

  The ctest target `bench_sanity_check` has many issues:

  * With sanitizers enabled, it is one of the slowest targets, often taking several minutes. See https://github.com/bitcoin/bitcoin/issues/32770#issuecomment-2984264066.
  * There is no insight from ctest into how long each individual sanity check takes.
  * On a timeout, or OOM issue, there is no insight into which sub-bench failed. The failure will generally just look like `75/153 Test   #9: bench_sanity_check ...................***Failed  770.84 sec    out of memory`
  * Places that can't use ctest (like the Windows-cross CI task) have to explicitly run it, or risk forgetting to run it.
  * All benchmarks are run sequentially, when they could run in parallel instead.

  Both issues can lead to CI timeouts and leave CPU unused during testing.

  Fix all issues by running it as part of the functional tests instead. This is similar to the rpcauth tests (https://github.com/bitcoin/bitcoin/pull/32881) and util tests [bitcoin-tx, and bitcoin-util] (https://github.com/bitcoin/bitcoin/pull/32697).

ACKs for top commit:
  achow101:
    ACK fa65bc0e79
  l0rinc:
    Tested ACK fa65bc0e79
  janb84:
    tACK fa65bc0e79
  willcl-ark:
    ACK fa65bc0e79

Tree-SHA512: d27e363b7896a7543a4ee8df41a56e58b74f07d4f296e2e5ee293fc91817d0be310e26905755fb94d44417d94fa29ad4cc5d4aa19e78d25d41bc2d9e0948c034
2026-01-05 15:47:49 -08:00
Sjors Provoost
48f57bb35b mining: add new getCoinbaseTx() returning a struct
Introduce a new method intended to replace getCoinbaseRawTx(), which
provides a struct with everything clients need to construct a coinbase.
This is safer than providing a raw dummy coinbase that clients then have
to manipulate.

The CoinbaseTx data is populated during the dummy transaction generation
and stored in struct CBlockTemplate.

Expand the interface_ipc.py functional test to document its usage
and ensure equivalence.
2026-01-05 09:51:57 +07:00
merge-script
bd4f4782f2 Merge bitcoin/bitcoin#34154: test: Enable ruff E713 lint
fab300b378 test: Enable ruff E713 lint (MarcoFalke)

Pull request description:

  Membership tests of the form `not item in stuff` may be confusing, because they could be read as `(not item) in stuff`, which is different.

  So enable the ruff E713 lint, which should also help to avoid having to go through review cycles for this.

ACKs for top commit:
  bensig:
    ACK fab300b378
  l0rinc:
    ACK fab300b378
  rkrux:
    lgtm crACK fab300b378

Tree-SHA512: c3eaf0fbe0dd22d8e04b896e98adaf28162fb748e6f7f5ebfd73b2020da66046bf8f0c1a27db5da05250366b98ded8c4a55d53edd8fa050e80521aee42ba3c5a
2026-01-04 16:22:38 +00:00
Ava Chow
2628de7479 Merge bitcoin/bitcoin#33135: wallet: warn against accidental unsafe older() import
76c092ff80 wallet: warn against accidental unsafe older() import (Sjors Provoost)
592157b759 test: move SEQUENCE_LOCKTIME flags to script (Sjors Provoost)

Pull request description:

  [BIP 379](https://github.com/bitcoin/bips/blob/master/bip-0379.md) ([Miniscript](https://bitcoin.sipa.be/miniscript/)) allows relative height and time locks that have no consensus meaning in [BIP 68](https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki) (relative timelocks) / [BIP 112](https://github.com/bitcoin/bips/blob/master/bip-0112.mediawiki) (`CHECKSEQUENCEVERIFY`). This is (ab)used by some protocols, e.g. [by Lightning to encode extra data](https://delvingbitcoin.org/t/exploring-extended-relative-timelocks/1818/23), but is unsafe when used unintentionally: `older(65536)` is equivalent to `older(1)`.

  This PR emits a warning when `importdescriptors` contains such a descriptor.

  The first commit makes `SEQUENCE_LOCKTIME` flags reusable by other tests.

  The main commit adds the `ForEachNode` helper to `miniscript.h` which is then used in the `MiniscriptDescriptor` constructor to check for `Fragment::OLDER` with unsafe values. These are stored in `m_warnings`, which the RPC code then collects via `Warnings()`.

  It adds both a unit and functional test.

  ---

  A previous version of this PR prevented the import, unless the user opted in with an `unsafe` flag. It also used string parsing in the RPC code.

  ---

  Based on:
  - [x] https://github.com/bitcoin/bitcoin/pull/33914

ACKs for top commit:
  pythcoiner:
    reACK 76c092ff80
  achow101:
    ACK 76c092ff80
  rkrux:
    lgtm re-ACK 76c092ff80
  brunoerg:
    reACK 76c092ff80

Tree-SHA512: 8e944e499bd4a43cc27eeb889f262b499b9b07aa07610f4a415ccb4e34a9110f9946646f446a54ac5bf17494d8d96a89e4a1fa278385db9b950468f27283e17a
2026-01-02 16:15:50 -08:00
MarcoFalke
fa9fdbce79 test: Pass bench exe into test framework utils
This teaches the test framework about the bench executable, which is
required for the next commit.
2026-01-01 20:38:59 +01:00
MarcoFalke
fab300b378 test: Enable ruff E713 lint 2025-12-26 08:19:34 +01:00
merge-script
1f151e73c0 Merge bitcoin/bitcoin#32929: qa: Clarify assert_start_raises_init_error output
356883f0e4 qa-tests: Log expected output in debug (Hodlinator)
7427a03b5a qa-tests: Add test for timeouts due to missing init errors (Hodlinator)
d7f703c1f1 refactor(qa-tests): Extract InternalDurationTestMixin for use in next commit (Hodlinator)
69bcfcad8c fix(qa-tests): Bring back decoding of exception field (Hodlinator)
fb43b2f8cc qa: Improve assert_start_raises_init_error output (Hodlinator)

Pull request description:

  Raising a new exception from within a Python `except`-block, as `assert_start_raises_init_error()` does, causes the interpreter to generate extra error output which is unnecessary in this case.

  <details><summary>Example output before & after this PR</summary>

  Before:
  ```
  2025-07-08T20:05:48.407001Z TestFramework (ERROR): Assertion failed
  Traceback (most recent call last):
    File "/home/hodlinator/bitcoin/test/functional/test_framework/test_node.py", line 686, in assert_start_raises_init_error
      ret = self.process.wait(timeout=self.rpc_timeout)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/nix/store/fqm9bqqlmaqqr02qbalm1bazp810qfiw-python3-3.12.9/lib/python3.12/subprocess.py", line 1266, in wait
      return self._wait(timeout=timeout)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/nix/store/fqm9bqqlmaqqr02qbalm1bazp810qfiw-python3-3.12.9/lib/python3.12/subprocess.py", line 2053, in _wait
      raise TimeoutExpired(self.args, timeout)
  subprocess.TimeoutExpired: Command '['/home/hodlinator/bitcoin/build/bin/bitcoind', '-datadir=/tmp/bitcoin_func_test_v96lkcq8/eb2665c7/node0', '-logtimemicros', '-debug', '-debugexclude=libevent', '-debugexclude=leveldb', '-debugexclude=rand', '-uacomment=testnode0', '-disablewallet', '-logthreadnames', '-logsourcelocations', '-loglevel=trace', '-v2transport=0']' timed out after 3 seconds

  During handling of the above exception, another exception occurred:

  Traceback (most recent call last):
    File "/home/hodlinator/bitcoin/test/functional/test_framework/test_framework.py", line 186, in main
      self.setup()
    File "/home/hodlinator/bitcoin/test/functional/test_framework/test_framework.py", line 358, in setup
      self.setup_network()
    File "/home/hodlinator/bitcoin/build/test/functional/feature_framework_startup_failures.py", line 151, in setup_network
      self.nodes[0].assert_start_raises_init_error()
    File "/home/hodlinator/bitcoin/test/functional/test_framework/test_node.py", line 716, in assert_start_raises_init_error
      self._raise_assertion_error(assert_msg)
    File "/home/hodlinator/bitcoin/test/functional/test_framework/test_node.py", line 196, in _raise_assertion_error
      raise AssertionError(self._node_msg(msg))
  AssertionError: [node 0] bitcoind should have exited within 3s with an error
  ```
  After:
  ```
  2025-07-08T20:09:15.330589Z TestFramework (ERROR): Assertion failed
  Traceback (most recent call last):
    File "/home/hodlinator/bitcoin/test/functional/test_framework/test_framework.py", line 186, in main
      self.setup()
    File "/home/hodlinator/bitcoin/test/functional/test_framework/test_framework.py", line 358, in setup
      self.setup_network()
    File "/home/hodlinator/bitcoin/build/test/functional/feature_framework_startup_failures.py", line 151, in setup_network
      self.nodes[0].assert_start_raises_init_error()
    File "/home/hodlinator/bitcoin/test/functional/test_framework/test_node.py", line 720, in assert_start_raises_init_error
      self._raise_assertion_error(assert_msg)
    File "/home/hodlinator/bitcoin/test/functional/test_framework/test_node.py", line 196, in _raise_assertion_error
      raise AssertionError(self._node_msg(msg))
  AssertionError: [node 0] bitcoind should have exited within 3s with an error (cmd: ['/home/hodlinator/bitcoin/build/bin/bitcoind', '-datadir=/tmp/bitcoin_func_test_v96lkcq8/eb2665c7/node0', '-logtimemicros', '-debug', '-debugexclude=libevent', '-debugexclude=leveldb', '-debugexclude=rand', '-uacomment=testnode0', '-disablewallet', '-logthreadnames', '-logsourcelocations', '-loglevel=trace', '-v2transport=0'])
  ```

  </details>

  ---

  Can be tested on this PR by:
  1. Execute test containing new test case:
      ```shell
      build/test/functional/feature_framework_startup_failures.py -ldebug > after.log
      ```
  2. Drop first commit which contains the fix.
  3. Re-run test:
      ```shell
      build/test/functional/feature_framework_startup_failures.py -ldebug > before.log
      ```
  4. Diff logs, focusing on `TestInitErrorTimeout OUTPUT` sections.

  ---

  Found while testing #32835 using the suggested method (https://github.com/bitcoin/bitcoin/pull/32835#issue-3188748624) which triggered expected timeouts, but with the extra error noise.

ACKs for top commit:
  l0rinc:
    ACK 356883f0e4
  ryanofsky:
    Code review ACK 356883f0e4. Thanks for the updates! Just rearranged commits and made minor changes in "missing init errors" test since last review
  furszy:
    Code ACK 356883f0e4

Tree-SHA512: 01f2f1f6a5e79cf83a39a143cfb8b2bb8360e0402e91a97a7df8254309fd4436a55468d11825093c052010bfce57f3461d912a578cd2594114aba435ab48b999
2025-12-22 07:09:58 -08:00
merge-script
7f295e1d9b Merge bitcoin/bitcoin#34084: scripted-diff: [doc] Unify stale copyright headers
fa4cb13b52 test: [doc] Manually unify stale headers (MarcoFalke)
fa5f297748 scripted-diff: [doc] Unify stale copyright headers (MarcoFalke)

Pull request description:

  Historically, the upper year range in file headers was bumped manually
  or with a script.

  This has many issues:

  * The script is causing churn. See for example commit 306ccd4, or
    drive-by first-time contributions bumping them one-by-one. (A few from
    this year: https://github.com/bitcoin/bitcoin/pull/32008,
    https://github.com/bitcoin/bitcoin/pull/31642,
    https://github.com/bitcoin/bitcoin/pull/32963, ...)
  * Some, or likely most, upper year values were wrong. Reasons for
    incorrect dates could be code moves, cherry-picks, or simply bugs in
    the script.
  * The upper range is not needed for anything.
  * Anyone who wants to find the initial file creation date, or file
    history, can use `git log` or `git blame` to get more accurate
    results.
  * Many places are already using the `-present` suffix, with the meaning
    that the upper range is omitted.

  To fix all issues, this bumps the upper range of the copyright headers
  to `-present`.

  Further notes:

  * Obviously, the yearly 4-line bump commit for the build system (c.f.
    b537a2c02a) is fine and will remain.
  * For new code, the date range can be fully omitted, as it is done
    already by some developers. Obviously, developers are free to pick
    whatever style they want. One can list the commits for each style.
  * For example, to list all commits that use `-present`:
    `git log --format='%an (%ae) [%h: %s]' -S 'present The Bitcoin'`.
  * Alternatively, to list all commits that use no range at all:
    `git log --format='%an (%ae) [%h: %s]' -S '(c) The Bitcoin'`.

  <!--
  * The lower range can be wrong as well, so it could be omitted as well,
    but this is left for a follow-up. A previous attempt was in
    https://github.com/bitcoin/bitcoin/pull/26817.

ACKs for top commit:
  l0rinc:
    ACK fa4cb13b52
  rkrux:
    re-ACK fa4cb13b52
  janb84:
    ACK fa4cb13b52

Tree-SHA512: e5132781bdc4417d1e2922809b27ef4cf0abb37ffb68c65aab8a5391d3c917b61a18928ec2ec2c75ef5184cb79a5b8c8290d63e949220dbeab3bd2c0dfbdc4c5
2025-12-19 16:56:02 +00:00
merge-script
3a2807ad95 Merge bitcoin/bitcoin#33875: qa: Account for unset errno in ConnectionResetError
76e0e6087d qa: Account for errno not always being set for ConnectionResetError (Hodlinator)

Pull request description:

  The lack of errno can cause unclear and long log output.

  Issue can be triggered by:

  ```diff
  --- a/src/httpserver.cpp
  +++ b/src/httpserver.cpp
  @@ -263,6 +263,7 @@ std::string RequestMethodString(HTTPRequest::RequestMethod m)
   /** HTTP request callback */
   static void http_request_cb(struct evhttp_request* req, void* arg)
   {
  +    throw std::runtime_error{"Hello"};
       evhttp_connection* conn{evhttp_request_get_connection(req)};
       // Track active requests
       {
  ```
  and running a functional test such as *test/functional/feature_abortnode.py*.

  `http.client.RemoteDisconnected` not specifying `errno` to `ConnectionResetError`-ctor: ce4b0ede16/Lib/http/client.py (L1556C9-L1556C29)

  <details><summary>Before/after log examples</summary>

  #### Log before
  ```
  2025-11-14T20:53:05.272804Z TestFramework (ERROR): Unexpected exception
  Traceback (most recent call last):
    File "/home/hodlinator/bc/3/test/functional/test_framework/test_framework.py", line 138, in main
      self.setup()
      ~~~~~~~~~~^^
    File "/home/hodlinator/bc/3/test/functional/test_framework/test_framework.py", line 268, in setup
      self.setup_network()
      ~~~~~~~~~~~~~~~~~~^^
    File "/home/hodlinator/bc/3/./build/test/functional/feature_abortnode.py", line 21, in setup_network
      self.setup_nodes()
      ~~~~~~~~~~~~~~~~^^
    File "/home/hodlinator/bc/3/test/functional/test_framework/test_framework.py", line 381, in setup_nodes
      self.start_nodes()
      ~~~~~~~~~~~~~~~~^^
    File "/home/hodlinator/bc/3/test/functional/test_framework/test_framework.py", line 527, in start_nodes
      node.wait_for_rpc_connection()
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
    File "/home/hodlinator/bc/3/test/functional/test_framework/test_node.py", line 326, in wait_for_rpc_connection
      rpc.getblockcount()
      ~~~~~~~~~~~~~~~~~^^
    File "/home/hodlinator/bc/3/test/functional/test_framework/coverage.py", line 50, in __call__
      return_val = self.auth_service_proxy_instance.__call__(*args, **kwargs)
    File "/home/hodlinator/bc/3/test/functional/test_framework/authproxy.py", line 137, in __call__
      response, status = self._request('POST', self.__url.path, postdata.encode('utf-8'))
                         ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/hodlinator/bc/3/test/functional/test_framework/authproxy.py", line 111, in _request
      return self._get_response()
             ~~~~~~~~~~~~~~~~~~^^
    File "/home/hodlinator/bc/3/test/functional/test_framework/authproxy.py", line 174, in _get_response
      http_response = self.__conn.getresponse()
    File "/nix/store/62fdlzq1x1ak2lsxp4ij7ip5k9nia3hc-python3-3.13.7/lib/python3.13/http/client.py", line 1430, in getresponse
      response.begin()
      ~~~~~~~~~~~~~~^^
    File "/nix/store/62fdlzq1x1ak2lsxp4ij7ip5k9nia3hc-python3-3.13.7/lib/python3.13/http/client.py", line 331, in begin
      version, status, reason = self._read_status()
                                ~~~~~~~~~~~~~~~~~^^
    File "/nix/store/62fdlzq1x1ak2lsxp4ij7ip5k9nia3hc-python3-3.13.7/lib/python3.13/http/client.py", line 300, in _read_status
      raise RemoteDisconnected("Remote end closed connection without"
                               " response")
  http.client.RemoteDisconnected: Remote end closed connection without response
  ```

  #### Log after

  ```
  2025-11-14T20:48:10.552126Z TestFramework (ERROR): Unexpected exception
  Traceback (most recent call last):
    File "/home/hodlinator/bc/3/test/functional/test_framework/test_framework.py", line 138, in main
      self.setup()
      ~~~~~~~~~~^^
    File "/home/hodlinator/bc/3/test/functional/test_framework/test_framework.py", line 268, in setup
      self.setup_network()
      ~~~~~~~~~~~~~~~~~~^^
    File "/home/hodlinator/bc/3/./build/test/functional/feature_abortnode.py", line 21, in setup_network
      self.setup_nodes()
      ~~~~~~~~~~~~~~~~^^
    File "/home/hodlinator/bc/3/test/functional/test_framework/test_framework.py", line 381, in setup_nodes
      self.start_nodes()
      ~~~~~~~~~~~~~~~~^^
    File "/home/hodlinator/bc/3/test/functional/test_framework/test_framework.py", line 527, in start_nodes
      node.wait_for_rpc_connection()
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
    File "/home/hodlinator/bc/3/test/functional/test_framework/test_node.py", line 316, in wait_for_rpc_connection
      raise FailedToStartError(self._node_msg(
          f'bitcoind exited with status {self.process.returncode} during initialization. {str_error}'))
  test_framework.test_node.FailedToStartError: [node 0] bitcoind exited with status -6 during initialization. terminate called after throwing an instance of 'std::runtime_error'
    what():  Hello
  ************************
  ```
  Note how even the C++ exception message is now included.

  </details>

ACKs for top commit:
  maflcko:
    review ACK 76e0e6087d 🌬
  furszy:
    Tested ACK 76e0e6087d
  l0rinc:
    untested code review ACK 76e0e6087d

Tree-SHA512: 55a83d664624932b919ab2a5b6369121db448d27628029f21c5df297892dd56d179d710ad744f6407b51aa576fb6905a38bbc29885c534ec20704c22717a0880
2025-12-18 11:46:13 +00:00
Hodlinator
fb43b2f8cc qa: Improve assert_start_raises_init_error output
Re-raising within the except-block would trigger excessive "During handling of the above exception, another exception occurred"-output.

Also changed comment - exceptions are raised in Python, not thrown.
2025-12-17 11:20:19 +01:00
MarcoFalke
fa5f297748 scripted-diff: [doc] Unify stale copyright headers
-BEGIN VERIFY SCRIPT-

 sed --in-place --regexp-extended \
   's;( 20[0-2][0-9])(-20[0-2][0-9])? The Bitcoin Core developers;\1-present The Bitcoin Core developers;g' \
   $( git grep -l 'The Bitcoin Core developers' -- ':(exclude)COPYING' ':(exclude)src/ipc/libmultiprocess' ':(exclude)src/minisketch' )

-END VERIFY SCRIPT-
2025-12-16 22:21:15 +01:00
merge-script
500862b2d4 Merge bitcoin/bitcoin#33423: qa: Improvements to debug_assert_log + busy_wait_for_debug_log
a1f7623020 qa: Only complain about expected messages that were not found (Hodlinator)
1e54125e2e refactor(qa): Avoid unnecessary string operations (Hodlinator)
a9021101dc qa: Replace always-escaped regexps with "X in Y" (Hodlinator)
5c16e4631c doc: Remove no longer correct comment (Hodlinator)

Pull request description:

  * Remove incorrect docstring in `busy_wait_for_debug_log()`.
  * Replace nerfed regex searches with `X in Y` expressions.
  * Only compute the log string to be printed on failure *when we actually fail* instead of every 0.05s.
  * As we find each needle (expected message) in the haystack (log output), stop searching for it. **If we fail and time out, we will only complain about the needles (expected messages) we didn't find. On master we also include found needles, which is less helpful.**

  Found while developing a new test case in https://github.com/bitcoin/bitcoin/pull/33336#discussion_r2351892330

ACKs for top commit:
  l0rinc:
    Code review ACK a1f7623020
  maflcko:
    review ACK a1f7623020 💨

Tree-SHA512: 191ea7647b0ea8b4220e37c62d176861c2fd0e3737aee3641b262915d9118f48953cf1204767c93a93a8fc78a44c2c29206fb390b44c59d99fc2aa7d12bf4889
2025-12-10 11:40:59 +00:00
merge-script
39ca015259 Merge bitcoin/bitcoin#33140: test: Avoid shutdown race in NetworkThread
fa6db79302 test: Avoid shutdown race in NetworkThread (MarcoFalke)

Pull request description:

  Locally, I am seeing rare intermittent exceptions in the network thread:

  ```
  stderr:
  Exception in thread NetworkThread:
  Traceback (most recent call last):
  File "/python3.10/threading.py", line 1016, in _bootstrap_inner
  self.run()
  File "./test/functional/test_framework/p2p.py", line 744, in run
  self.network_event_loop.run_forever()
  File "/python3.10/asyncio/base_events.py", line 603, in run_forever
  self._run_once()
  File "/python3.10/asyncio/base_events.py", line 1871, in _run_once
  event_list = self._selector.select(timeout)
  AttributeError: 'NoneType' object has no attribute 'select'
  ```

  I can reproduce this intermittently via `while ./bld-cmake/test/functional/test_runner.py $(for i in {1..400}; do echo -n "tool_rpcauth "; done)  -j 400 ; do true ; done`.

  I suspect this is a race where the shutdown starts the close of the network thread while it is starting.

  A different exception showing this race can be reproduced via:

  ```diff
  diff --git a/test/functional/test_framework/p2p.py b/test/functional/test_framework/p2p.py
  index 610aa4ccca..64561e157c 100755
  --- a/test/functional/test_framework/p2p.py
  +++ b/test/functional/test_framework/p2p.py
  @@ -741,6 +741,7 @@ class NetworkThread(threading.Thread):

       def run(self):
           """Start the network thread."""
  +        import time;time.sleep(.1)
           self.network_event_loop.run_forever()

       def close(self, *, timeout=10):
  ```

  It is trivial to reproduce via any test (e.g. `./bld-cmake/test/functional/tool_rpcauth.py`) and shows a similar traceback to the one above:

  ```
  Exception in thread NetworkThread:
  Traceback (most recent call last):
    File "/python3.10/threading.py", line 1016, in _bootstrap_inner
      self.run()
    File "./test/functional/test_framework/p2p.py", line 745, in run
      self.network_event_loop.run_forever()
    File "/python3.10/asyncio/base_events.py", line 591, in run_forever
      self._check_closed()
    File "/python3.10/asyncio/base_events.py", line 515, in _check_closed
      raise RuntimeError('Event loop is closed')
  RuntimeError: Event loop is closed
  ```

  So fix the second runtime error in hope of fixing the first one as well.

ACKs for top commit:
  brunoerg:
    code review ACK fa6db79302

Tree-SHA512: ca352ebf7929456ea2bbfcfe4f726adcbfcfb3dc0edeaddae7f6926f998888f0bd8b987ddef60308266eeab6bffa7ebdc32f5908db9de5404df95635dae4a8f6
2025-12-03 10:42:30 +00:00