44741 Commits

Author SHA1 Message Date
Hennadii Stepanov
fa2c548429
Merge bitcoin/bitcoin#32417: doc: Explain that .gitignore is not for IDE-specific excludes
fada115cbeaa8c0ca3d19178499079b66ee5f499 doc: Explain that .gitignore is not for IDE-specific excludes (MarcoFalke)

Pull request description:

  This comes up frequently, so document it.

  Examples:

  * https://github.com/bitcoin/bitcoin/pull/27275
  * https://github.com/bitcoin/bitcoin/pull/21894
  * https://github.com/bitcoin/bitcoin/pull/32392
  * https://github.com/bitcoin/bitcoin/pull/17868

  ...

ACKs for top commit:
  l0rinc:
    ACK fada115cbeaa8c0ca3d19178499079b66ee5f499
  hebasto:
    ACK fada115cbeaa8c0ca3d19178499079b66ee5f499.
  janb84:
    ACK [fada115](fada115cbe)

Tree-SHA512: 6fd1e48de54b40118a49ef61ad157fea278bba568286a022559a4815e53f26650db98a779a1ea2b3085237ded5cbee20d4c2dd1ef51e6a2d3d6085d7063f5309
2025-05-05 07:40:08 +01:00
MarcoFalke
fada115cbe
doc: Explain that .gitignore is not for IDE-specific excludes 2025-05-04 19:45:11 +02:00
Sebastian Falbesoner
b5f580c580 scripted-diff: adapt script error constant names in feature_taproot.py
In order to remove potential confusion, this commit adapts all script
error constant names in the functional tests (currently only in
feature_taproot.py) to the ones used in our C++ codebase. This also
makes checking whether we have test coverage for a certain script error
easier.

-BEGIN VERIFY SCRIPT-

ren() { sed -i "s|$1|$2|g" $( git grep -l "$1" -- "./test" ) ; }

ren ERR_SIG_SIZE          ERR_SCHNORR_SIG_SIZE
ren ERR_SIG_HASHTYPE      ERR_SCHNORR_SIG_HASHTYPE
ren ERR_SIG_SCHNORR       ERR_SCHNORR_SIG
ren ERR_CONTROLBLOCK_SIZE ERR_TAPROOT_WRONG_CONTROL_SIZE
ren ERR_PUSH_LIMIT        ERR_PUSH_SIZE
ren ERR_MINIMALIF         ERR_TAPSCRIPT_MINIMALIF
ren ERR_UNKNOWN_PUBKEY    ERR_PUBKEYTYPE
ren ERR_STACK_EMPTY       ERR_INVALID_STACK_OPERATION
ren ERR_SIGOPS_RATIO      ERR_TAPSCRIPT_VALIDATION_WEIGHT
ren ERR_UNDECODABLE       ERR_BAD_OPCODE
ren ERR_NO_SUCCESS        ERR_EVAL_FALSE
ren ERR_EMPTY_WITNESS     ERR_WITNESS_PROGRAM_WITNESS_EMPTY

-END VERIFY SCRIPT-
2025-05-03 20:32:13 +02:00
Ava Chow
eba5f9c4b6
Merge bitcoin/bitcoin#32403: test: remove Boost SIGCHLD workaround.
3add6ab9adcd722d57c6d488581358ae9b377f1a test: remove Boost SIGCHLD workaround. (fanquake)

Pull request description:

  The related code was removed from Boost in 2e3bd1025d.

ACKs for top commit:
  achow101:
    ACK 3add6ab9adcd722d57c6d488581358ae9b377f1a
  laanwj:
    ACK 3add6ab9adcd722d57c6d488581358ae9b377f1a
  hebasto:
    ACK 3add6ab9adcd722d57c6d488581358ae9b377f1a, I have reviewed the code and it looks OK.
  mabu44:
    ACK 3add6ab9adcd722d57c6d488581358ae9b377f1a

Tree-SHA512: a0db2bb4e6a476c920a97183bd807e800d935114ff28f8802373a08b5330df42a9be953e7ea6e3c09f2ed45175f60c26c33bb4e25010269e6e491f12867ba008
2025-05-02 14:10:23 -07:00
fanquake
e1f543823b
build: replace header checks with __has_include
See https://en.cppreference.com/w/cpp/preprocessor/include.
2025-05-02 16:41:04 +01:00
fanquake
3add6ab9ad
test: remove Boost SIGCHLD workaround.
The related code was removed from Boost in
2e3bd1025d.
2025-05-02 10:59:46 +01:00
Tomás Andróil
cd95c9d6a7
subprocess: check and handle fcntl(F_GETFD) failure
Add missing error check for fcntl(fd, F_GETFD, 0) in set_clo_on_exec.
Raise OSError on failure to align with existing FD_SETFD behavior.
This improves robustness in subprocess setup and error visibility.

Github-Pull: arun11299/cpp-subprocess#117
Rebased-From: 9974ff69cdd5fc1a2722cb63f006df9308628b35
2025-05-01 22:16:11 +01:00
Haowen Liu
b7288decdf
subprocess: Proper implementation of wait() on Windows
This commit makes sure:
1. WaitForSingleObject returns with expected
code before proceeding.
2. Process handle is properly closed.

Github-Pull: arun11299/cpp-subprocess#116
Rebased-From: 625a8775791e62736f20f3fa3e6cc4f1b24aa89a
2025-05-01 22:15:57 +01:00
Hennadii Stepanov
7423214d8d
subprocess: Do not escape double quotes for command line arguments on Windows
* refactor: Guard `util::quote_argument()` with `#ifdef __USING_WINDOWS__`

The `util::quote_argument()` function is specific to Windows and is used
in code already guarded by `#ifdef __USING_WINDOWS__`.

* Do not escape double quotes for command line arguments on Windows

This change fixes the handling of double quotes and aligns the behavior
with Python's `Popen` class. For example:
```
>py -3
>>> import subprocess
>>> p = subprocess.Popen("cmd.exe /c dir \"C:\\Program Files\"", stdout=subprocess.PIPE, text=True)
>>> print(f"Captured stdout:\n{stdout}")
```

Currently, the same command line processed by the `quote_argument()`
function looks like `cmd.exe /c dir "\"C:\Program" "Files\""`, which is
broken.

With this change, it looks correct: `cmd.exe /c dir "C:\Program Files"`.

Github-Pull: arun11299/cpp-subprocess#113
Rebased-From: ed313971c04ac10dc006104aba07d016ffc6542a
2025-05-01 22:15:19 +01:00
Shunsuke Shimizu
bb9ffea53f
subprocess: Explicitly define move constructor of Streams class
This suppresses the following warning caused by clang-20.

```
error: definition of implicit copy constructor for 'Streams' is deprecated because it has a user-declared copy assignment operator [-Werror,-Wdeprecated-copy]
```

Copy constructor or move constructor is called when std::vector re-allocates
memory. In this case, move constructor should be called, because copying
Streams instances breaks file-descriptor management.

Communication class is modified as well, since it's instance is a member of
Streams class.

Github-Pull: arun11299/cpp-subprocess#107
Rebased-From: 38d98d9d20be50c7187b98ac9bc9a6e66920f6ef
2025-05-01 22:14:29 +01:00
Hennadii Stepanov
174bd43f2e
subprocess: Avoid leaking POSIX name aliases beyond subprocess.h
The commit a32c0f3df4b6bcd1d2e93f19e8f380bb890cd507 introduced code to
silence MSVC's "warning C4996: The POSIX name for this item is
deprecated."

However, it exhibits several issues:
1. The aliases may leak into code outside the `subprocess.hpp` header.
2. They are unnecessarily applied when using the MinGW-w64 toolchain.
3. The fix is incomplete: downstream projects still see C4996 warnings.
4. The implementation lacks documentation.

This change addresses all of the above shortcomings.

Github-Pull: arun11299/cpp-subprocess#112
Rebased-From: 778543b2f2ca7f5d1c4f0241b635bbb265d750dd

Co-authored-by: Luke Dashjr <luke-jr+git@utopios.org>
2025-05-01 22:10:35 +01:00
Hennadii Stepanov
7997b7656f
subprocess: Fix cross-compiling with mingw toolchain
Github-Pull: arun11299/cpp-subprocess#99
Rebased-From: 34033d03deacfdba892a708b7d8092b4d9e5e889
2025-05-01 22:07:39 +01:00
Haowen Liu
647630462f
subprocess: Get Windows return code in wait()
Currently, wait() returns 0 on windows regardless
of the actual return code of processes.

Github-Pull: arun11299/cpp-subprocess#109
Rebased-From: 04b015a8e52ead4d8bb5f0eb486419c77e418a17
2025-05-01 22:07:21 +01:00
Haowen Liu
d3f511b458
subprocess: Fix string_arg when used with rref
When passing in a rvalue reference, compiler
considers it ambiguous between std::string and
std::string&&. Making one of them take a lvalue
reference makes compilers correctly pick the right
one depending on whether the passed in value binds
to a rvalue or lvalue reference.

Github-Pull: arun11299/cpp-subprocess#110
Rebased-From: 2d8a8eebb03e509840e2c3c755d1abf32d930f33
2025-05-01 22:06:28 +01:00
Haoran Peng
2fd3f2fec6
subprocess: Fix memory leaks
I encountered this issue while running my code with Valgrind today.
Below is part of the Valgrind error message:

```
==1578139== 472 bytes in 1 blocks are still reachable in loss record 1 of 1
==1578139==    at 0x4848899: malloc (...)
==1578139==    by 0x4B3AF62: fdopen@@GLIBC_2.2.5 (...)
==1578139==    by 0x118B09: subprocess::Popen::execute_process() (...)
```

I noticed that a similar fix had been proposed by another contributor
previously. I did not mean to scoop their work, but merely hoping to fix
it sooner so other people don't get confused by it just as I did today.

Github-Pull: arun11299/cpp-subprocess#106
Rebased-From: 3afe581c1f22f106d59cf54b9b65251e6c554671
2025-05-01 22:04:59 +01:00
Ava Chow
5b8046a6e8
Merge bitcoin/bitcoin#30611: validation: write chainstate to disk every hour
e976bd3045010ee217aa0f2dca4c962aabb789d5 validation: add randomness to periodic write interval (Andrew Toth)
2e2f41068128c38120a5b44d24ee30f71970455a refactor: replace m_last_write with m_next_write (Andrew Toth)
b557fa7a175f139614932fbb3a4ad0af8271c73c refactor: rename fDoFullFlush to should_write (Andrew Toth)
d73bd9fbe483ad1397f62dc1d580314202351ace validation: write chainstate to disk every hour (Andrew Toth)
0ad7d7abdbcffc11a46413545a214a716f56dc95 test: chainstate write test for periodic chainstate flush (Andrew Toth)

Pull request description:

  Since #28233, periodically writing the chainstate to disk every 24 hours does not clear the dbcache. Since #28280, periodically writing the chainstate to disk is proportional only to the amount of dirty entries in the cache. Due to these changes, it is no longer beneficial to only write the chainstate to disk every 24 hours. The periodic flush interval was necessary because every write of the chainstate would clear the dbcache. Now, we can get rid of the periodic flush interval and simply write the chainstate along with blocks and block index at least every hour.

  Three benefits of doing this:
  1. For IBD or reindex-chainstate with a combination of large dbcache setting, slow CPU, slow internet speed/unreliable peers, it could be up to 24 hours until the chainstate is persisted to disk. A power outage or crash could potentially lose up to 24 hours of progress. If there is a very large amount of dirty cache entries, writing to disk when a flush finally does occur will take a very long time. Crashing during this window of writing can cause https://github.com/bitcoin/bitcoin/issues/11600. By syncing every hour in unison with the block index we avoid this problem. Only a maximum of one hour of progress can be lost, and the window for crashing during writing is much smaller. For IBD with lower dbcache settings, faster CPU, or better internet speed/reliable peers, chainstate writes are already triggered more often than every hour so this change will have no effect on IBD.
  2. Based on discussion in #28280, writing only once every 24 hours during long running operation of a node causes IO spikes. Writing smaller chainstate changes every hour like we do with blocks and block index will reduce IO spikes.
  3. Faster shutdown speeds. All dirty chainstate entries must be persisted to disk on shutdown. If we have a lot of dirty entries, such as when close to 24 hours or if we sync with a large dbcache, it can take a long time to shutdown. By keeping the chainstate clean we avoid this problem.

  Inspired by [this comment](https://github.com/bitcoin/bitcoin/pull/28280#issuecomment-2121088705).

  Resolves https://github.com/bitcoin/bitcoin/issues/11600

ACKs for top commit:
  achow101:
    ACK e976bd3045010ee217aa0f2dca4c962aabb789d5
  davidgumberg:
    utACK e976bd3045
  sipa:
    utACK e976bd3045010ee217aa0f2dca4c962aabb789d5
  l0rinc:
    ACK  e976bd3045010ee217aa0f2dca4c962aabb789d5

Tree-SHA512: 5bccd8f1dea47f9820a3fd32fe3bb6841c0167b3d6870cc8f3f7e2368f124af1a914bca6acb06889cd7183638a8dbdbace54d3237c3683f2b567eb7355e015ee
2025-05-01 12:11:55 -07:00
merge-script
fc6346dbc8
Merge bitcoin/bitcoin#32389: doc: Fix test_bitcoin path
6cbc28b8dd629062950f195facc009fd8ba86310 doc: Fix test_bitcoin path (monlovesmango)

Pull request description:

  This commit fixes a couple command paths for interacting with the test_bitcoin binary within the Unit Test documentation.

  If the commands are run as is a `command not found` error is returned.

  ```bash
  ❯ test_bitcoin --list_content
  bash: test_bitcoin: command not found
  ```

  ```bash
  ❯ test_bitcoin --help
  bash: test_bitcoin: command not found
  ```

ACKs for top commit:
  davidgumberg:
    ACK 6cbc28b8dd

Tree-SHA512: 0b10bc3aead360fa499beef7c9715f95a9acacdda44cbfac15566428594a7a8bdece24114a42618355959e20754bedc7a903bdddbf21b819c7b75375bdc80a93
2025-05-01 10:21:31 +01:00
monlovesmango
6cbc28b8dd doc: Fix test_bitcoin path
This commit fixes a couple command paths for interacting with the
test_bitcoin binary within the Unit Test documentation.
2025-05-01 03:05:57 +00:00
Murch
85368aafa0
test: Run simple tests at various feerates 2025-04-30 15:38:04 -07:00
Murch
d610951c15
test: Recreate BnB iteration exhaustion test 2025-04-30 15:38:02 -07:00
Murch
2a1b2754f1
test: Remove redundant repeated test
We do not need to repeat the same test multiple times because BnB is
deterministic and will therefore always have the same outcome.
Additionally, this test was redundant because it repeats the "Smallest
combination too big" test.
2025-04-30 15:38:01 -07:00
Murch
4781f5c8be
test: Recreate simple BnB failure tests 2025-04-30 15:37:59 -07:00
Murch
a94030ae98
test: Recreate BnB clone skipping test 2025-04-30 15:37:58 -07:00
Murch
7db6f012c0
test: Move BnB feerate sensitivity tests
Originally these tests verified that at a SelectCoins level that a
solution with fewer inputs gets preferred at high feerates, and a
solution with more inputs gets preferred at low feerates. This outcome
relies on the behavior of BnB, so we move these tests under the umbrella
of BnB tests.

Originally these tests relied on SFFO to work.
2025-04-30 15:37:55 -07:00
Murch
2bafc46261
test: Recreate simple BnB success tests
Recreates the tests in a new test suite coinselection_tests.cpp that is
based on UTXOs being created per their effective values rather than
nominal values and uses transactions with non-zero feerates.
2025-04-30 15:37:44 -07:00
Andrew Toth
e976bd3045
validation: add randomness to periodic write interval
Co-Authored-By: Pieter Wuille <pieter@wuille.net>
Co-Authored-By: l0rinc <pap.lorinc@gmail.com>
2025-04-30 18:35:03 -04:00
Andrew Toth
2e2f410681
refactor: replace m_last_write with m_next_write
Co-Authored-By: l0rinc <pap.lorinc@gmail.com>
2025-04-30 18:33:43 -04:00
Andrew Toth
b557fa7a17 refactor: rename fDoFullFlush to should_write 2025-04-30 18:32:51 -04:00
Andrew Toth
d73bd9fbe4
validation: write chainstate to disk every hour
Remove the 24 hour periodic flush interval and
write the chainstate along with blocks and block
index every hour
2025-04-30 18:32:41 -04:00
Ava Chow
68ac9f116c
Merge bitcoin/bitcoin#32383: util: Remove fsbridge::get_filesystem_error_message()
97eaadc3bf9f621ba397e29bb1c0cd99af55f2e3 util: Remove `fsbridge::get_filesystem_error_message()` (Hennadii Stepanov)

Pull request description:

  The `fsbridge::get_filesystem_error_message()` function exhibits several drawbacks:

  1. It was introduced in https://github.com/bitcoin/bitcoin/pull/14192 to account for platform-specific variations in
  `boost::filesystem::filesystem_error::what()`. Since [migrating](https://github.com/bitcoin/bitcoin/pull/20744) to `std::filesystem`, those discrepancies no longer exist.

  2. It fails to display UTF-8 paths correctly on Windows:
  ```
  > build\bin\Release\bitcoind.exe -datadir="C:\Users\hebasto\dd_₿_🏃" -regtest
  ...
  2025-04-30T00:17:48Z DeleteAuthCookie: Unable to remove random auth cookie file: remove: Access is denied.: "C:\Users\hebasto\dd_?_??\regtest\.cookie"
  ...
  ```

  3. It relies on `std::wstring_convert`, which was deprecated in C++17 and removed in C++26 (also see https://github.com/bitcoin/bitcoin/issues/32361).

  This PR removes the obsolete `fsbridge::get_filesystem_error_message()` function, thereby resolving all of the above issues.

ACKs for top commit:
  maflcko:
    lgtm re-ACK 97eaadc3bf9f621ba397e29bb1c0cd99af55f2e3
  davidgumberg:
    untested crACK 97eaadc3bf
  achow101:
    ACK 97eaadc3bf9f621ba397e29bb1c0cd99af55f2e3
  laanwj:
    Code review ACK 97eaadc3bf9f621ba397e29bb1c0cd99af55f2e3

Tree-SHA512: 3c7378a9b143ac2a71add967318a13c346ae3bccbec6e9879d7873083f3fa469b3eef529b2c9c142b2489ba9563e4e12f685745c09a8a219d58b384f7ecf1be1
2025-04-30 10:56:14 -07:00
MarcoFalke
fa4804009c
fuzz: Remove unused TimeoutExpired catch in fuzz runner
Can be reviewed with --ignore-all-space
2025-04-30 19:55:03 +02:00
Hennadii Stepanov
97eaadc3bf
util: Remove fsbridge::get_filesystem_error_message()
The `fsbridge::get_filesystem_error_message()` function exhibits several
drawbacks:

1. It was introduced in https://github.com/bitcoin/bitcoin/pull/14192 to
account for platform-specific variations in
`boost::filesystem::filesystem_error::what()`. Since migrating to
`std::filesystem`, those discrepancies no longer exist.

2. It fails to display UTF-8 paths correctly on Windows.

3. It relies on `std::wstring_convert`, which was deprecated in C++17
and removed in C++26.

This change removes the `fsbridge::get_filesystem_error_message()`
function, thereby resolving all of the above issues.

Additionally, filesystem error messages now use the "Warning" log level.
2025-04-30 10:41:34 +01:00
Ava Chow
14b8dfb2bd
Merge bitcoin/bitcoin#31398: wallet: refactor: various master key encryption cleanups
a8333fc9ff9adaa97a1f9024f5783cc071777150 scripted-diff: wallet: rename plain and encrypted master key variables (Sebastian Falbesoner)
5a92077fd5317f936da2fa0aa45e0173248f765b wallet: refactor: dedup master key decryption (Sebastian Falbesoner)
846545947cd3b993c40362b9d0afcd7b4f5f05bd wallet: refactor: dedup master key encryption / derivation rounds setting (Sebastian Falbesoner)
a6d9b415aa3afcfe463887d0fde00c3d2d32672a wallet: refactor: introduce `CMasterKey::DEFAULT_DERIVE_ITERATIONS` constant (Sebastian Falbesoner)
62c209f50d9c33fde5062ebca317b9a4233aff62 wallet: doc: remove mentions of unavailable scrypt derivation method (Sebastian Falbesoner)

Pull request description:

  This PR contains various cleanups around the wallet's master key encryption logic. The default/minimum key derivation rounds magic number of 25000 is hoisted into a constant (member of `CMasterKey`) and two new functions `EncryptMasterKey`/`DecryptMasterKey` are introduced in order to deduplicate code for the derivation round determination and master key en/decryption. Also, mentions of the never-implemented derivation method `scrypt` are removed from the wallet crypter header and both plain and encrypted master key instances are renamed to adapt to moderning coding style (hopefully improving readability).

ACKs for top commit:
  davidgumberg:
    ACK a8333fc9ff
  achow101:
    ACK a8333fc9ff9adaa97a1f9024f5783cc071777150

Tree-SHA512: 5a66d3b26f481347d0b5b4f742dd237803a35aad6e3480ed15fd38b7fa3700650bd5f67f4c30ed88f5fad45d6cd4c893fe4f1657e36e563b4294fd3596187724
2025-04-29 16:32:21 -07:00
Ava Chow
a60445cd04
Merge bitcoin/bitcoin#32355: Bugfix: Miner: Don't reuse block_reserved_weight for "block is full enough to give up" weight delta
524f981bb87319fdd6ff2ab4a932c4b4e31a7398 Bugfix: Miner: Don't reuse block_reserved_weight for "block is full enough to give up" weight delta (Luke Dashjr)

Pull request description:

  PR #30356 incorrectly changed a constant of `4000` to `m_options.coinbase_max_additional_weight` in the check for when to give up finding another transaction to fill the block:

  ```diff
               if (nConsecutiveFailed > MAX_CONSECUTIVE_FAILURES && nBlockWeight >
  -                    m_options.nBlockMaxWeight - 4000) {
  +                    m_options.nBlockMaxWeight - m_options.block_reserved_weight) {
                   // Give up if we're close to full and haven't succeeded in a while
                   break;
               }
  ```

  But this constant did not deal with the reserved weight at all. It was in fact simply checking if the block was close to full, and if so, giving up finding another transaction to pad it with after `MAX_CONSECUTIVE_FAILURES` failed attempts.

  It doesn't seem very logical to reuse the reserve weight for this purpose, and it would be overcomplicated to add yet another setting, so this PR changes it to a new constexpr.

ACKs for top commit:
  achow101:
    ACK 524f981bb87319fdd6ff2ab4a932c4b4e31a7398
  darosior:
    utACK 524f981bb87319fdd6ff2ab4a932c4b4e31a7398
  ismaelsadeeq:
    ACK 524f981bb87319fdd6ff2ab4a932c4b4e31a7398

Tree-SHA512: c066debc34a021380424bd21b40444071b736325e41779a41590c2c8a6822ceeaf910fe067817c1dba108210b24c574977b0350b29520502e7af79d3b405928b
2025-04-29 15:51:18 -07:00
Ava Chow
2d5b424414
Merge bitcoin/bitcoin#32351: test: avoid stack overflow in FindChallenges via manual iteration
7e8ef959d0637ca5543ed33d3919937e0d053e70 refactor: Fix Sonar rule `cpp:S4998` - avoid unique_ptr const& as parameter (Lőrinc)
e400ac53524d143467740e2f59698a7c94644c21 refactor: simplify repeated comparisons in `FindChallenges` (Lőrinc)
f670836112c01feb3cb71618192e9c0c2e55767f test: remove old recursive `FindChallenges_recursive` implementation (Lőrinc)
b80d0bdee4603aa8ab69587d0c311aad1a9b3c7a test: avoid stack overflow in `FindChallenges` via manual iteration (Lőrinc)

Pull request description:

  `FindChallenges` explores the `Miniscript` node tree by going deep into the first child's subtree, then the second, and so on - effectively performing a pre-order Traversal (Depth-First Search) recursively, using the call stack which can result in stack overflows on Windows debug builds.

  This change replaces the recursive implementation with an iterative version using an explicit stack. The new implementation also performs a pre-order depth-first traversal, though it processes children in right-to-left order (rather than left-to-right) due to the LIFO nature of the stack. Since both versions store results in a `std::set`, which automatically sorts and deduplicates elements, the exact traversal order doesn't affect the final result.

  It is an alternative to increasing the Windows stack size, as proposed in #32349, and addresses the issue raised in #32341 by avoiding deep recursion altogether.

  The change is done in two commits:
  * add a new iterative `FindChallenges` method and rename the old method to `*_recursive` (to simplify the next commit where we remove it), asserting that its result matches the original;
  * remove the original recursive implementation.

  This approach avoids ignoring the `misc-no-recursion` warning as well.

  I tried modifying the new method to store results in a vector instead, but it demonstrated that the deduplication provided by `std::set` was necessary. One example showing the need for deduplication:

  Recursive (using set):
  ```
    (6, 9070746)
    (6, 19532513)
    (6, 3343376967)
  ```
  Iterative (using vector attempt):
  ```
    (6, 19532513)
    (6, 9070746)
    (6, 3343376967)
    (6, 9070746)  // Duplicate entry
  ```

  The performance of the test is the same as before, with the recursive method.

  Fixes https://github.com/bitcoin/bitcoin/issues/32341

ACKs for top commit:
  achow101:
    ACK 7e8ef959d0637ca5543ed33d3919937e0d053e70
  sipa:
    utACK 7e8ef959d0637ca5543ed33d3919937e0d053e70
  hodlinator:
    re-ACK 7e8ef959d0637ca5543ed33d3919937e0d053e70

Tree-SHA512: 9e52eff82a7d76f5d37e3b74c508f08e5fced5386dad504bed111b27ed2b529008a6dd12a5116f009609a94c7ee7ebe3e80a759dda55dd1cb3ae52078f65ec71
2025-04-29 15:29:50 -07:00
Ava Chow
0ed5f37afe
Merge bitcoin/bitcoin#31014: net: Use GetAdaptersAddresses to get local addresses on Windows
b9d4d5f66a5a35c47e7abc9ec6ef5ab242b3f1e1 net: Use GetAdaptersAddresses to get local addresses on Windows (laanwj)

Pull request description:

  Instead of a `gethostname` hack, which is not guaranteed to return all addresses, use the official way of calling `GetAdaptersAddresses` to get local network addresses on Windows.

  Do the same checks as the UNIX path: interface is up, interface is not loopback.

  Suggested by Ava Chow.

  Addiional changes:

  - Cleanup: move out `FromSockAddr` in `netif.cpp` from MacOS and use it everywhere appropriate. This avoids code duplication.

ACKs for top commit:
  davidgumberg:
    utreACK b9d4d5f66a
  achow101:
    ACK b9d4d5f66a5a35c47e7abc9ec6ef5ab242b3f1e1

Tree-SHA512: e9f0a7ec0c46f21c0377d5174e054a6569f858630727f94dac00c0cb7c241c56892d0b902706d6dd53880cc3b5ae1f2dba9caa1fec40e64cd4cf0d34493a49c1
2025-04-29 15:13:39 -07:00
Ava Chow
7a4a2a38ea
Merge bitcoin/bitcoin#27826: validation: log which peer sent us a header
abe43dfadd6325f80975a76aea57a549c3162191 doc: release note for #27826 (Sjors Provoost)
f9fa28788e63e2bd059a21ec0e76ae6903b2a6be Use LogBlockHeader for compact blocks (Sjors Provoost)
bad7c914793134abe2f64d96c367d5e9b07e60fd Log which peer sent us a header (Sjors Provoost)
9d3e39c29c31775fd82af319d1d4dfbbd3e21bfa Log block header in net_processing (Sjors Provoost)

Pull request description:

  Fixes #27744

  Since #27278 we log received headers. For compact blocks we also log which peer sent it (e5ce8576349d404c466b2f4cab1ca7bf920904b2), but not for regular headers. That required an additional refactor, which this PR provides.

  Move the logging from validation to net_processing.

  This also reduces the number of log entries (under default configuration) per compact block header from 3 to 2: one for the header and one for the connected tip.

  The PR introduces a new helper method `LogBlockHeader`.

  When receiving a _compact block_ we call `LogBlockHeader` from the exact same place as where we previously logged. So that log message doesn't change. What does change is that we no longer _also_ log from `AcceptBlockHeader`.

  When receiving a regular header(s) message, _we only log the last one_. This is a change in behaviour because it was simpler to implement, but it's probably better anyway. It does mean that if a peer sends of a bunch of headers of which _any_ is invalid, we won't log it (here).

  Lastly I expanded the code comment explaining why we log this. It initially only covered selfish mining, but we also care about peers sending us headers but not following up (see e.g. #27626).

  Example log:

  ```
  2023-06-05T13:12:21Z Saw new header hash=000000000000000000045910263ef84b575ae3af151865238f1e5c619e69c330 height=792964 peer=0
  2023-06-05T13:12:23Z UpdateTip: new best=000000000000000000045910263ef84b575ae3af151865238f1e5c619e69c330 height=792964 version=0x20000000 log2_work=94.223098 tx=848176824 date='2023-06-05T13:11:49Z' progress=1.000000 cache=6.4MiB(54615txo)
  2023-06-05T13:14:05Z Saw new cmpctblock header hash=00000000000000000003c6fd4ef2e1246a3f9e1fffab7247344f94cadb9de979 height=792965 peer=0
  2023-06-05T13:14:05Z UpdateTip: new best=00000000000000000003c6fd4ef2e1246a3f9e1fffab7247344f94cadb9de979 height=792965 version=0x20000000 log2_work=94.223112 tx=848179461 date='2023-06-05T13:13:58Z' progress=1.000000 cache=7.2MiB(61275txo)
  2023-06-05T13:14:41Z Saw new header hash=000000000000000000048e6d69c8399992782d08cb57f5d6cbc81a9f996c3f43 height=792966 peer=8
  2023-06-05T13:14:42Z UpdateTip: new best=000000000000000000048e6d69c8399992782d08cb57f5d6cbc81a9f996c3f43 height=792966 version=0x2db3c000 log2_work=94.223126 tx=848182944 date='2023-06-05T13:14:35Z' progress=1.000000 cache=8.0MiB(69837txo)
  ```

ACKs for top commit:
  danielabrozzoni:
    tACK abe43dfadd6325f80975a76aea57a549c3162191
  achow101:
    ACK abe43dfadd6325f80975a76aea57a549c3162191
  vasild:
    ACK abe43dfadd6325f80975a76aea57a549c3162191

Tree-SHA512: 081e0de62cbd8a0b35cf54daaa09e3e6991d0cc9f706ef3eb50908752fe7815de69b367f7313381c90cd8d5de0ae5f532d1cd54948c5c1133b1832f266d9c232
2025-04-29 14:48:16 -07:00
Ava Chow
4694732bc4
Merge bitcoin/bitcoin#32338: net: remove unnecessary check from AlreadyConnectedToAddress()
f1b142856a4ecd0a0d90bc3d73ef5137997b14ff test: Same addr, diff port is already connected (David Gumberg)
94e85a82a753a0aa5ad688fc46330e83c9a697fe net: remove unnecessary check from AlreadyConnectedToAddress() (Vasil Dimov)

Pull request description:

  `CConnman::AlreadyConnectedToAddress()` searches the existent nodes by address or by address-and-port:

  ```cpp
  FindNode(static_cast<CNetAddr>(addr)) || FindNode(addr.ToStringAddrPort())
  ```

  but:

  * if there is a match by just the address, then the address-and-port search will not be evaluated and the whole condition will be `true`
  * if the there is no node with the same address, then the second search by address-and-port will not find a match either.

  The search by address-and-port is comparing against `CNode::m_addr_name` which could be a hostname, e.g. `"node.foobar.com:8333"`, but `addr.ToStringAddrPort()` is always going to be numeric.

  ---

  In other words: let `A` be "CNetAddr equals" and `B` be "addr:port string matches", then:

  * If `A` (is `true`), then `B` is irrelevant, so the condition `A || B` is equivalent to `A` is `true`.
  * Observation in this PR: if `!A` (`A` is `false`), then `!B` for sure, thus the condition `A || B` is equivalent to `A` is `false`.

  So, simplify `A || B` to `A`.

  https://en.wikipedia.org/wiki/Modus_tollens `!A => !B` is equivalent to `B => A`. So the added fuzz test asserts that if `B` is `true`, then `A` is `true`.

ACKs for top commit:
  davidgumberg:
    crACK f1b142856a4ecd0a0d90bc3d
  achow101:
    ACK f1b142856a4ecd0a0d90bc3d73ef5137997b14ff
  theuni:
    utACK f1b142856a4ecd0a0d90bc3d73ef5137997b14ff
  mzumsande:
    Code Review ACK f1b142856a4ecd0a0d90bc3d73ef5137997b14ff

Tree-SHA512: d744b60e9bace121faa3a746463f6b6e0e6ef08eac0e7879326cbd5f4721e47e6e10f6203dfd3870a2057c4ddd1860692c070ef048a76d773b84e6c2f840cc86
2025-04-29 14:31:59 -07:00
Ava Chow
7db096121d
Merge bitcoin/bitcoin#29039: versionbits refactoring
e3014017bacff42d8d69f3061ce1ee621aaa450a test: add IsActiveAfter tests for versionbits (Anthony Towns)
60950f77c35e54e2884cfc14ab67623f3e325099 versionbits: docstrings for BIP9Info (Anthony Towns)
7565563bc7a5bb98ebf03a7d6881912a74d3f302 tests: refactor versionbits fuzz test (Anthony Towns)
2e4e9b9608c722aaf767638e9dba498d8dc3e772 tests: refactor versionbits unit test (Anthony Towns)
525c00f91bb27d0f2a1b2e5532aebec7fac97d3a versionbits: Expose VersionBitsConditionChecker via impl header (Anthony Towns)
e74a7049b477d1853191ded75fdf25024a6e233f versionbits: Expose StateName function (Anthony Towns)
d00d1ed52c8ee95eeed665d68d6715a694bd4c1f versionbits: Split out internal details into impl header (Anthony Towns)
37b9b67a39554465104c9cf1a74690f40019dbad versionbits: Simplify VersionBitsCache API (Anthony Towns)
1198e7d2fd665bf2bc49fd26773d4fd5fbc2b716 versionbits: Move BIP9 status logic for getblocktemplate to versionbits (Anthony Towns)
b1e967c3ec92738affb22d3b58483ebcdd8dfea2 versionbits: Move getdeploymentinfo logic to versionbits (Anthony Towns)
3bd32c20550e69688a4ff02409fb34b9a637b9c4 versionbits: Move WarningBits logic from validation to versionbits (Anthony Towns)
5da119e5d0e61f0b583f0fe21b9a00ee815a3e46 versionbits: Change BIP9Stats to uint32_t types (Anthony Towns)
a679040ec19ef17f3f03988a52207f1c03af701e consensus/params: Move version bits period/threshold to bip9 param (Anthony Towns)
e9d617095d4ce9525a4337d33624cac9d6b4abe6 versionbits: Remove params from AbstractThresholdConditionChecker (Anthony Towns)
9bc41f1b48b2e0cc6abf9714e860a29989d7809c versionbits: Use std::array instead of C-style arrays (Anthony Towns)

Pull request description:

  Increases the encapsulation/modularity of the versionbits code, moving more of the logic into the versionbits module rather than having it scattered across validation and rpc code. Updates unit/fuzz tests to test the actual code used rather than just a close approximation of it.

ACKs for top commit:
  achow101:
    ACK e3014017bacff42d8d69f3061ce1ee621aaa450a
  TheCharlatan:
    Re-ACK e3014017bacff42d8d69f3061ce1ee621aaa450a
  darosior:
    ACK e3014017bacff42d8d69f3061ce1ee621aaa450a

Tree-SHA512: 2978db5038354b56fa1dd6aafd511099e9c16504d6a88daeac2ff2702c87bcf3e55a32e2f0a7697e3de76963b68b9d5ede7976ee007e45862fa306911194496d
2025-04-29 14:06:45 -07:00
Ava Chow
51d76634fb
Merge bitcoin/bitcoin#32365: descriptors: Reject + sign while parsing unsigned
fa655da159876861251d1149a5c31a830bd35596 test: [refactor] Use ToIntegral in CheckInferDescriptor (MarcoFalke)
fa55dd01df8384e0d57fbb442d170c8a60d0260b descriptors: Reject + sign when parsing multi threshold (MarcoFalke)
fa6f77ed3c152e0ff695c36b7a4ebb2c2efe916f descriptors: Reject + sign in ParseKeyPathNum (MarcoFalke)

Pull request description:

  As a follow-up to https://github.com/bitcoin/bitcoin/pull/30577, reject `+` for unsigned values in key-path parsing and multi threshold parsing as well.

  Both of those are using unsigned, and Bitcoin Core would never serialize a descriptor string with a stray `+`. Accepting stray `+` signs could lead to checksum mismatches, or other incompatibilities later on.

  Just like https://github.com/bitcoin/bitcoin/pull/30577, both changes are breaking changes on the RPC interface, but hopefully no one should be relying on this behavior in production. Similarly, both changes should be fine for the wallet, because it normalizes the strings on import, see https://github.com/bitcoin/bitcoin/pull/30577#pullrequestreview-2218436014.

ACKs for top commit:
  achow101:
    ACK fa655da159876861251d1149a5c31a830bd35596
  brunoerg:
    code review ACK fa655da159876861251d1149a5c31a830bd35596
  janb84:
    tACK [fa655da](fa655da159)

Tree-SHA512: d0c7262a167f7ba98b44ed8bf49ff4c15a1eb647cbac39a59b83c7cc379903c24dae3996e5f557497eb08e16d7121417916147058d97bdf168cd6eada57dceef
2025-04-29 10:25:21 -07:00
merge-script
c5e44a0435
Merge bitcoin/bitcoin#32369: test: Use the correct node for doubled keypath test
32d55e28af69ef09094ba921289bf4d1ad79905a test: Use the correct node for doubled keypath test (Ava Chow)

Pull request description:

  #29124 had a silent merge conflict with #32350 which resulted in it using the wrong node. Fix the test to use the correct v22 node.

ACKs for top commit:
  maflcko:
    lgtm ACK 32d55e28af69ef09094ba921289bf4d1ad79905a
  rkrux:
    ACK 32d55e28af69ef09094ba921289bf4d1ad79905a
  BrandonOdiwuor:
    Code Review ACK 32d55e28af69ef09094ba921289bf4d1ad79905a

Tree-SHA512: 1e0231985beb382b16e1d608c874750423d0502388db0c8ad450b22d17f9d96f5e16a6b44948ebda5efc750f62b60d0de8dd20131f449427426a36caf374af92
2025-04-29 09:59:42 +01:00
Ava Chow
32d55e28af test: Use the correct node for doubled keypath test 2025-04-28 14:44:17 -07:00
Ava Chow
65714c162c
Merge bitcoin/bitcoin#32327: test: Add missing check for empty stderr in util tester
fadf12a56c294696052c4cb6ee5284030ada7498 test: Add missing check for empty stderr in util tester (MarcoFalke)

Pull request description:

  Now that wine support was removed from the CI in 25b56fd9b469f8e5d36f0132c3b79a5214e3372a, it can probably be removed from the util tester as well.

  If someone really needs this, they can comment the new check out, or submit a patch to add an option/env var to silence the new check.

ACKs for top commit:
  achow101:
    ACK fadf12a56c294696052c4cb6ee5284030ada7498
  i-am-yuvi:
    tACK fadf12a56c294696052c4cb6ee5284030ada7498
  BrandonOdiwuor:
    Code Review ACK fadf12a56c294696052c4cb6ee5284030ada7498
  ismaelsadeeq:
    Tested ACK fadf12a56c294696052c4cb6ee5284030ada7498

Tree-SHA512: d9e4d7a7f724e114391070ea7f17b585a7e4c4f3221c3bf510eeb11df6ccd089b881ab5654adfef8d3a1f8fa7ec6bf5e3a3feeb0cdfe724a8f3e5a146c388e66
2025-04-28 14:43:32 -07:00
merge-script
a4eee6d50b
Merge bitcoin/bitcoin#29124: test: Test that migration automatically repairs corrupted metadata with doubled derivation path
c7e2b9e2644442b147880becb8a659f3d00092d9 tests: Test migration cleans up bad inactive chain derivation path (Ava Chow)

Pull request description:

  A bug in 0.21.x and 22.x resulted in some wallets having invalid derivation paths that are the concatenation of two derivation paths. These appear only when inactive hd chains are topped up.

  Since key metadata is a legacy wallet only record, migrating legacy wallets to descriptor wallets will fix this issue as all key metadata records are deleted. The derivation path information is derived on-the-fly from the descriptor that is produced for the inactive hd chain.

  Thus we only need a test to verify that the derivation paths are good, and that all key metadata records are deleted from the migrated wallet.

ACKs for top commit:
  murchandamus:
    re-ACK c7e2b9e2644442b147880becb8a659f3d00092d9 via range-diff:
  rkrux:
    re-ACK c7e2b9e2644442b147880becb8a659f3d00092d9
  furszy:
    utACK c7e2b9e2644442b147880becb8a659f3d00092d9

Tree-SHA512: 3117c4a43798972109fe2d3539341a8b69db70c6457fcabdd019e6044834dc4b17212abbc006d7b8008f560dce4b7856142b057981b9404f406d58fa0955cbd9
2025-04-28 17:13:42 -04:00
Ava Chow
af6cffa36d
Merge bitcoin/bitcoin#32350: test: Slim down previous releases bdb check
fa58f40b898ba6c57655bf38a241fb10107d4a3a test: Slim down previous releases bdb check (MarcoFalke)

Pull request description:

  The check iterates over several previous BDB-only releases to check that descriptor wallets are considered "corrupt" when loading. It is unclear why this needs to be done for more than one release.

  Avoid the confusion by removing the unused releases from the test and from the download script.

ACKs for top commit:
  achow101:
    ACK fa58f40b898ba6c57655bf38a241fb10107d4a3a
  rkrux:
    ACK fa58f40b898ba6c57655bf38a241fb10107d4a3a

Tree-SHA512: 8084392481bfe1fba9b80bb865ffbdfa454e9e6e14e02c39fa3f61c1a596b1def2c531c5da1c7566e5fddb77ac7e56f19feabaaf9b5af043fa6c230d9e2370b5
2025-04-28 12:56:22 -07:00
Ava Chow
33e6538b30
Merge bitcoin/bitcoin#32360: test: Force named args for RPCOverloadWrapper optional args
fa48be3ba443d2436f754265b86331f84b866130 test: Force named args for RPCOverloadWrapper optional args (MarcoFalke)
aaaa45399ca3f9a5ed19c176b25e3165e1e4e0d9 test: Remove unused createwallet_passthrough (MarcoFalke)
cccc1f4e91902f2e95481630fd534b8c72452b44 test: Remove unused RPCOverloadWrapper is_cli field (MarcoFalke)

Pull request description:

  This can avoid bugs and makes the test code easier to read, because the
  order of positional args does not have to be known or assumed.

  Also, contains two commits to remove dead code.

ACKs for top commit:
  achow101:
    ACK fa48be3ba443d2436f754265b86331f84b866130
  rkrux:
    tACK fa48be3ba443d2436f754265b86331f84b866130
  janb84:
    tACK [fa48be3](fa48be3ba4)

Tree-SHA512: d938fbc18be5035ad0d0e1ad2bf7297b2b66ede3bb2d3f10b8d27aa2a19d27a897b024a5f5a2a1cceca467837890729c26054928cb06acbe282b9e9eea94ae69
2025-04-28 12:41:00 -07:00
merge-script
3a29ba33dc
Merge bitcoin/bitcoin#32357: depends: Fix cross-compiling qt package from macOS to Windows
35e57fbe336cdcb348ff088fc04216f1f5cf2742 depends: Fix cross-compiling `qt` package from macOS to Windows (Hennadii Stepanov)

Pull request description:

  Native packages cannot be used during cross-compiling. However, Qt still unconditionally tries to find them, which causes issues in some cases, such as when [cross-compiling from macOS to Windows](https://github.com/bitcoin/bitcoin/issues/32346).

  This PR explicitly disables this unnecessary Qt behaviour.

  Fixes https://github.com/bitcoin/bitcoin/issues/32346.

  Here is a full workflow on my macOS Sequoia 15.4.1 (Intel):
  ```
  % brew install make cmake ninja mingw-w64 nsis
  % gmake -C depends -j 10 HOST=x86_64-w64-mingw32
  % cmake -B build --toolchain depends/x86_64-w64-mingw32/toolchain.cmake
  % cmake --build build -j 10 -t deploy
  ```

ACKs for top commit:
  shahsb:
    ACK 35e57fbe33
  fanquake:
    ACK 35e57fbe336cdcb348ff088fc04216f1f5cf2742

Tree-SHA512: 2822fb49bc84dd094dbd189d8a9ca0f023e1e48127db7beaefb9db92de53df63bb0f399c9c430c33941f9a9ee6976b9161d80467d889f7717385b9d1ea9fee43
2025-04-28 16:15:13 +01:00
MarcoFalke
fa655da159
test: [refactor] Use ToIntegral in CheckInferDescriptor 2025-04-28 17:05:43 +02:00
MarcoFalke
fa55dd01df
descriptors: Reject + sign when parsing multi threshold 2025-04-28 17:05:37 +02:00
MarcoFalke
fa6f77ed3c
descriptors: Reject + sign in ParseKeyPathNum 2025-04-28 17:05:36 +02:00