Commit Graph

45555 Commits

Author SHA1 Message Date
Vasil Dimov
4bb5dd78ea util: check that a file has been closed before ~AutoFile() is called
If an `AutoFile` has been written to, then expect callers to have closed
it explicitly via the `AutoFile::fclose()` method. This is because if
the destructor calls `std::fclose()` and encounters an error, then it
is too late to indicate this to the caller in a meaningful way.
2025-06-16 15:33:19 +02:00
Vasil Dimov
8bb34f07df Explicitly close all AutoFiles that have been written
There is no way to report a close error from `AutoFile` destructor.
Such an error could be serious if the file has been written to because
it may mean the file is now corrupted (same as if write fails).

So, change all users of `AutoFile` that use it to write data to
explicitly close the file and handle a possible error.
2025-06-16 15:33:15 +02:00
Hodlinator
a69c4098b2 rpc: take ownership of the file by WriteUTXOSnapshot()
Have `WriteUTXOSnapshot()` take rvalue reference to make it obvious that
it takes ownership of the file.
2025-06-16 15:20:47 +02:00
fanquake
c7eaac326a depends: capnp 1.2.0 2025-06-16 10:55:14 +01:00
stratospher
afaaba69ed test: refactor out same-txid-diff-wtxid tx to reuse in other tests
useful to easily create transactions with same txid, different
wtxid and valid witness for testing scenarios in other places
(ex: private broadcast connections)
2025-06-16 14:48:17 +05:30
merge-script
084eee0291 Merge bitcoin/bitcoin#32743: refactor: use std::vector<std::byte> for BlockManager::ReadRawBlock()
6ecb9fc65f chore: use `std::vector<std::byte>` for `BlockManager::ReadRawBlock()` (Roman Zeyde)

Pull request description:

  Following [this comment](https://github.com/bitcoin/bitcoin/pull/32540#discussion_r2135820932), this PR changes `BlockManager::ReadRawBlock()` to accept a `std::vector<std::byte>` instead of `std::vector<uint8_t>`, in order to avoid casts during its invocations.

  It also adds a new `SpanReader` constructor to allow reading from a span of `std::byte`s (in addition to span of `uint8_t`).

ACKs for top commit:
  l0rinc:
    ACK 6ecb9fc65f
  maflcko:
    re-ACK 6ecb9fc65f
  TheCharlatan:
    Re-ACK 6ecb9fc65f

Tree-SHA512: b0976c34b8da4fa1e6d805a89de2883f48ba431a71069e8c1ae450f48e425cc41aff1a5d479a7d40312a972aaf1f92e9478a985a14a1357c6b3e564e988d03e5
2025-06-16 09:52:53 +01:00
Roman Zeyde
c48846ec41 doc: add release notes for #32540 2025-06-15 21:20:17 +03:00
Pieter Wuille
d7fca5c171 clusterlin: add big comment explaning the relation between tests 2025-06-14 18:35:33 -04:00
Pieter Wuille
b64e61d2de clusterlin: abstract try-permutations into ExhaustiveLinearize function
Rather than this exhaustive linearization check happening inline inside
clusterlin_simple_linearize, abstract it out into a Linearize()-like
function for clarity.

Note that this isn't exactly a refactor, because the old code would compare the
found linearization against all (valid) permutations, while the new code instead
first computes the best linearization from all valid permutations, and then
compares it with the found one.
2025-06-14 18:28:13 -04:00
Pieter Wuille
1fa55a64ed clusterlin tests: verify that chunks are minimal 2025-06-14 18:27:24 -04:00
Pieter Wuille
da23ecef29 clusterlin tests: support non-empty ReadTopologicalSubset()
In several call sites for ReadTopologicalSubset, a non-empty result is
expected, necessitating a special case at the call site for empty results.

Fix this by adding a bool non_empty argument, which does this special
casing (more efficiently) inside ReadTopologicalSubset itself.
2025-06-14 18:27:24 -04:00
Pieter Wuille
94f3e17c33 clusterlin tests: compare with fuzz-provided linearizations 2025-06-14 18:27:24 -04:00
Pieter Wuille
5f92ebee0d clusterlin tests: compare with fuzz-provided topological sets 2025-06-14 18:27:24 -04:00
Pieter Wuille
6e37824ac3 clusterlin tests: optimize clusterlin_simple_linearize
Whenever a non-topological permutation is encountered, fast forward to the
last permutation with the same non-topological prefix, skipping over
potentially many permutations that are non-topological for the same reason.

With that, increase the checking of all permutations to clusters of size 8
instead of 7.
2025-06-14 18:27:24 -04:00
Pieter Wuille
98c1c88b6f clusterlin tests: separate testing of SimpleLinearize and Linearize
The separates the existing fuzz test into:

* clusterlin_linearize: establishes the correctness of Linearize() using the
                        simpler SimpleLinearize() function.
* clusterlin_simple_linearize: establishes the correctness of SimpleLinearize() by
                        comparing with all valid linearizations computed by
                        std::next_permutation.

rather than combining the first two into a single fuzz test.
2025-06-14 18:27:24 -04:00
Pieter Wuille
10e90f7aef clusterlin tests: make SimpleCandidateFinder always find connected
Make a small change to guarantee that SimpleCandidateFinder only ever returns
connected solutions, even when non-optimal. Then test this property.
2025-06-14 18:27:24 -04:00
Pieter Wuille
a38c38951e clusterlin tests: separate testing of Search- and SimpleCandidateFinder
This separates the existing fuzz test into:

* clusterlin_search_finder: establishes SearchCandidateFinder's correctness using the
                            simpler SimpleCandidateFinder.
* clusterlin_simple_finder: establishes SimpleCandidateFinder's correctness using the
                            (even) simpler ExhaustiveCandidateFinder.

rather than trying to do both at once.
2025-06-14 18:27:24 -04:00
Pieter Wuille
77a432ee70 clusterlin tests: count SimpleCandidateFinder iterations better
Only count the number of actual new subsets added. If the queue contains
a work item that completely covers a component, no transaction can be added
to it without creating a disconnected component. In this case, also don't
count it as an iteration.

With this, the number of iterations performed by SimpleCandidateFinder is
bounded by the number of distinct connected topologically-valid subsets of
the cluster.
2025-06-14 18:27:24 -04:00
Sjors Provoost
a18e572328 test: more template verification tests 2025-06-14 14:36:02 +02:00
Sjors Provoost
10c908808f test: move gbt proposal mode tests to new file
Additionally this commit gives each test its
own function.

The assert_submitblock helper is absorbed into
assert_template.

Review hint:
git show --color-moved=dimmed-zebra
2025-06-14 14:32:45 +02:00
Sjors Provoost
94959b8dee Add checkBlock to Mining interface
Use it in miner_tests.

The getblocktemplate and generateblock RPC calls don't use this,
because it would make the code more verbose.
2025-06-14 14:32:45 +02:00
Sjors Provoost
6077157531 ipc: drop BlockValidationState special handling
The Mining interface avoids using BlockValidationState.
2025-06-14 14:32:45 +02:00
Sjors Provoost
74690f4ed8 validation: refactor TestBlockValidity
Comments are expanded.

Return BlockValidationState instead of passing a reference.
Lock Chainman mutex instead of cs_main.
Remove redundant chainparams and pindexPrev arguments.
Drop defaults for checking proof-of-work and merkle root.

The ContextualCheckBlockHeader check is moved to after CheckBlock,
which is more similar to normal validation where context-free checks
are done first.

Validation failure reasons are no longer printed through LogError(),
since it depends on the caller whether this implies an actual bug
in the node, or an externally sourced block that happens to be invalid.
When called from getblocktemplate, via BlockAssembler::CreateNewBlock(),
this method already throws an std::runtime_error if validation fails.

Additionally it moves the inconclusive-not-best-prevblk check from RPC
code to TestBlockValidity.

There is no behavior change when callling getblocktemplate with proposal.
Previously this would return a BIP22ValidationResult which can throw for
state.IsError(). But CheckBlock() and the functions it calls only use
state.IsValid().

The final assert is changed into Assume, with a LogError.

Co-authored-by: <Ryan Ofsky <ryan@ofsky.org>
2025-06-14 14:32:45 +02:00
Ava Chow
2def858473 Merge bitcoin/bitcoin#32481: wallet, refactor: Remove Legacy wallet unused warnings and errors
ce90f0c99f rpc, wallet, refactor: Remove non-descriptor errors (pablomartin4btc)
573bcd75d7 wallet, refactor: Remove unused SetupGeneration (pablomartin4btc)
5431f2dc21 wallet, refactor: Remove Legacy warnings and errors (pablomartin4btc)

Pull request description:

  Remove dead code due to legacy wallet support removal.

  These changes have no impact on functionality. They are transparent to the end user, as legacy wallets can't be created or loaded anymore, so these checks are no longer reached. The legacy-to-descriptor wallet migration flow is not affected either, as these removals are not part of its process.

ACKs for top commit:
  achow101:
    ACK ce90f0c99f
  rkrux:
    utACK ce90f0c99f

Tree-SHA512: 9229ad9dda9ff1dece73b5b15a20d69c6ab1ff2c75b2ec430ddbbaeb3467f6a850f53df527bcb4a8114ccbf1aa9c794462d71a8d516aed6f9a9da74edae16feb
2025-06-13 17:27:39 -07:00
merge-script
287cd04a32 Merge bitcoin/bitcoin#32594: wallet, rpc: Return normalized descriptor in parent_descs
0def84d407 test: Verify parent_desc in RPCs (Ava Chow)
2554cee988 test: Enable default wallet for wallet_descriptor.py (Ava Chow)
3fc9d9f241 wallet, rpc: Push the normalized parent descriptor (Ava Chow)

Pull request description:

  Instead of prividing the descriptor string as stored in the db, use the normalized descriptor as is done for getaddressinfo's parent_desc field.

  Split from #32489

ACKs for top commit:
  Sjors:
    re-utACK 0def84d407
  rkrux:
    ACK 0def84d407
  w0xlt:
    reACK 0def84d407

Tree-SHA512: 575c5b545d6f0aa7e135696b7a55c004e754fca4dd35dd9cf71b0b45b49a2e86e7b20570e768534d587005953bb893645379ec1ba4f98cfd26811f9c2f17de2d
2025-06-13 18:25:13 -04:00
merge-script
fd74d609be Merge bitcoin/bitcoin#32620: wallet: Fix wallet interface detection of encrypted wallets
130a922980 wallet, interfaces: Use BERKELEY_RO in isEncrypted (Ava Chow)

Pull request description:

  The GUI uses `WalletLoader::isEncrypted()` to detect whether a wallet file is encrypted so that it knows whether to prompt for a passphrase when migrating a legacy wallet. However, legacy wallets need to be opened with `options.require_format = BERKELEY_RO`. Since this wasn't being provided, following #28710, encrypted legacy wallets could not be migrated.

  This fixes the issue by detecting when a wallet file is for a legacy wallet, and re-attempting with `options.require_format = BERKELEY_RO` in that case.

  Depends on #32449 for `DatabaseStatus::FAILED_LEGACY_DISABLED`

ACKs for top commit:
  davidgumberg:
    Tested ACK 130a922980
  furszy:
    utACK 130a922980
  pablomartin4btc:
    tACK 130a922980
  w0xlt:
    Code review ACK 130a922980
  rkrux:
    utACK 130a922980

Tree-SHA512: aa70defc3b5f41635333a4d83c46ecdb5cd3cb129d590b4c0fe7a5f16e8aeaba1592f932ead242ed5f84524b146d87319154f4a1820bb34d9e80f63d24fc6b20
2025-06-13 18:17:24 -04:00
Roman Zeyde
6ecb9fc65f chore: use std::vector<std::byte> for BlockManager::ReadRawBlock() 2025-06-13 19:19:44 +03:00
merge-script
65b26507b8 Merge bitcoin/bitcoin#32746: test: remove unnecessary m_best_header setting hack in feature_assumeutxo.py
206bc05e62 test: remove unnecessary m_best_header setting hack in feature_assumeutxo.py (Sebastian Falbesoner)

Pull request description:

  The mentioned bug (issue #26245) has been fixed in PR #30666, so the workaround is not needed anymore.

ACKs for top commit:
  fjahr:
    ACK 206bc05e62
  janb84:
    ACK 206bc05e62
  mzumsande:
    utACK 206bc05e62

Tree-SHA512: 92ad6c09c80318a02e00d8c2a4ca1ec8a6caa6aa310916ff705871c91fe5c960c15ed394ead8ce9c7466b592dba176aa87a635b3228ddc93f57082124f04613f
2025-06-13 15:56:00 +01:00
merge-script
3e81684426 Merge bitcoin/bitcoin#32739: tsan: remove note about dropping Qt wildcards
5db0a4a2db tsan: remove note about dropping Qt wildcards (fanquake)

Pull request description:

  Doing so looks unmaintainable.

ACKs for top commit:
  maflcko:
    lgtm ACK 5db0a4a2db

Tree-SHA512: 619ce944e5fc49d7e4d0de91f02599e0f8fff9b2ecaa354276bf4bd335238df99c7666f865400d00b6d44674bcda19313b9a51a722cb304657f0da4290666e64
2025-06-13 14:01:40 +01:00
merge-script
b8eb17792e Merge bitcoin/bitcoin#32175: fuzz: doc: add info about afl-system-config for macOS
61ea5f348d fuzz: doc: add info about `afl-system-config` for macOS (brunoerg)

Pull request description:

  `afl-system-config` adjusts the shared memory segment size limits and configures kernel parameters for better fuzzing performance. Since macOS has more conservative values on shared memory, it's necessary to run `afl-system-config`, or manually adjust the values to fuzz with AFL++.

  e.g.:
  ```sh
  kern.sysv.shmmax: 524288000
  kern.sysv.shmmin: 1
  kern.sysv.shmseg: 48
  kern.sysv.shmall: 131072000
  ```

ACKs for top commit:
  janb84:
    reACK [61ea5f3](61ea5f348d)
  w0xlt:
    ACK 61ea5f348d
  Crypt-iQ:
    ACK 61ea5f3

Tree-SHA512: 8fd9fcb397a6b22e344ac37d3d18052ce8b6b32a5118ab3554c49116d7dd8769cdcbad41f0784d9ab525d4284a82e3d7a89b2c66966b725bf3781d9389d7454d
2025-06-13 14:00:00 +01:00
Sebastian Falbesoner
206bc05e62 test: remove unnecessary m_best_header setting hack in feature_assumeutxo.py
The mentioned bug has been fixed in PR #30666,
so the workaround is not needed anymore.
2025-06-13 14:42:13 +02:00
MarcoFalke
272cd09b79 log: Use warning level while scanning wallet dir 2025-06-13 13:55:54 +02:00
Hodlinator
1777644367 qa, wallet: Verify warning when failing to scan 2025-06-13 13:55:54 +02:00
Hodlinator
893e51ffeb wallet: Correct dir iteration error handling
Seems to have been broken since conversion from Boost in #20744. The std::filesystem iteration aborts upon failure while Boost might have allowed skipping over faulty entries.
2025-06-13 13:41:59 +02:00
merge-script
52e6e93c3f Merge bitcoin/bitcoin#32693: depends: fix cmake compatibility error for freetype
d7c37906e7 build: patch cmake min version on freetype (josibake)

Pull request description:

  ## Problem

  While doing a depends build with CMake 4.0.1, I got the following error:

  ```
  Extracting freetype...
  /root/bitcoin/depends/sources/freetype-2.11.0.tar.xz: OK
  Preprocessing freetype...
  Configuring freetype...
  CMake Error at CMakeLists.txt:100 (cmake_minimum_required):
    Compatibility with CMake < 3.5 has been removed from CMake.

    Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
    to tell CMake that the project requires at least <min> but has been updated
    to work with policies introduced by <max> or earlier.

    Or, add -DCMAKE_POLICY_VERSION_MINIMUM=3.5 to try configuring anyway.

  -- Configuring incomplete, errors occurred!
  make: *** [funcs.mk:343: /root/bitcoin/depends/x86_64-pc-linux-gnu/.freetype_stamp_configured] Error 1
  make: Leaving directory '/root/bitcoin/depends'
  ```

  .. which led me to https://cmake.org/cmake/help/latest/release/4.0.html#deprecated-and-removed-features, which states compatibility with CMake versions less than 3.5 has been removed in 4.0.

  ## Fix
  Based on the suggestion from the error message (and from reading the CMake docs), I added `-DCMAKE_POLICY_VERSION_MINIMUM=3.22`. I picked `3.22` (as opposed to 3.5) since that is the minimum version of CMake we specify in `doc/dependencies.md`. Would be nice if there was a way to pipe the min version in as a variable (since presumably we'd want to update this to be in lock step with the minimum CMake version of the whole project), but I couldn't think of a simple way to do this. Open to suggestions on a more robust way to do this if this is deemed too brittle.

ACKs for top commit:
  fanquake:
    ACK d7c37906e7
  hebasto:
    ACK d7c37906e7. Tested on Ubuntu 25.04 with both cmake 4.0.2 and the default cmake 3.31.6.

Tree-SHA512: fb664ec73bfffc504f1dcc9076072307f443d056d14325de41c4a29f3ee4077f1922e79b5895b49e7354f45ad6a35be4973c153c2baf3376df6c0d209efc9c54
2025-06-13 12:27:46 +01:00
MarcoFalke
fa2f1c55b7 move-only util data to test/functional/data/util 2025-06-13 13:07:12 +02:00
MarcoFalke
faa18bf287 test: Turn util/test_runner into functional test
The moved portion can be reviewed via:

--color-moved=dimmed-zebra  --color-moved-ws=ignore-all-space
2025-06-13 13:06:59 +02:00
MarcoFalke
fa955154c7 test: Add missing skip_if_no_bitcoin_tx 2025-06-13 13:03:48 +02:00
Lőrinc
9341b5333a blockstorage: make block read hash checks explicit
Dropped the default expected_hash parameter from `ReadBlock()`.

In `blockmanager_flush_block_file` tests, we pass {} since the tests would already fail at PoW validation for corrupted blocks.

In `ChainstateManager::LoadExternalBlockFile`, we pass {} when processing child blocks because their hashes aren't known beforehand.
2025-06-13 12:32:56 +02:00
Lőrinc
2371b9f4ee test/bench: verify hash in ComputeFilter reads
Switch to the index-aware `ReadBlock()` overload in `ComputeFilter` so that filter creation will abort if the stored block header hash doesn't match the expected one.

In the `readwriteblock` benchmark, pass the expected hash to `ReadBlock()` to match the new signature without affecting benchmark performance.
2025-06-13 12:32:22 +02:00
Lőrinc
5d235d50d6 net: assert block hash in ProcessGetBlockData and ProcessMessage
The non-recent-block code path in `ProcessGetBlockData` already has `inv.hash` available (equaling `pindex->GetBlockHash()`).
Pass it to `ReadBlock()` and assert that the on-disk header matches the requested hash.

The `GETBLOCKTXN` message handler in `ProcessMessage` receives `req.blockhash` from the peer (equaling `pindex->GetBlockHash()`).
Pass this hash to `ReadBlock()` for verification and assert that the index lookup matches.

Co-authored-by: TheCharlatan <seb.kung@gmail.com>
Co-authored-by: Hodlinator <172445034+hodlinator@users.noreply.github.com>
2025-06-13 12:32:07 +02:00
fanquake
5db0a4a2db tsan: remove note about dropping Qt wildcards
Doing so looks unmaintainable.
2025-06-13 09:45:47 +01:00
merge-script
d91c718a68 Merge bitcoin/bitcoin#32717: doc: Update Qt 6 packages on FreeBSD
1df96f5931 doc: Update Qt 6 packages on FreeBSD (Hennadii Stepanov)

Pull request description:

  See:
  - https://cgit.freebsd.org/ports/tree/devel/qt6-base
  - https://cgit.freebsd.org/ports/tree/devel/qt6-translations

ACKs for top commit:
  vasild:
    ACK 1df96f5931

Tree-SHA512: 3ba44c9cd948f193648e49461b787ae1e443c55900e274e026d2a1c7490935348d733d76a01701157423d7acea17439f8900907e65017a802c040af1f1e219d2
2025-06-13 09:37:40 +01:00
MarcoFalke
fac9db6eb0 test: Add missing tx util to Binaries 2025-06-13 09:48:38 +02:00
MarcoFalke
fa91835ec6 test: Use lowercase env var as attribute name
This is a refactor.
2025-06-13 09:48:32 +02:00
MarcoFalke
fac49094cd test: Remove duplicate ConfigParser
It is sufficient to parse once.
2025-06-13 09:48:28 +02:00
Sjors Provoost
9dfc61d95f test: detect no external signer connected 2025-06-13 09:40:23 +02:00
Sebastian Falbesoner
dd8447f70f test: fix catchup loop in outbound eviction functional test
The catchup loop in the outbound eviction functional test currently has
a small flaw, as the contained waiting for a `getheaders` message just
waits for any such message instead of one with the intended block hash.
The reason is that the `prev_prev_hash` variable is set incorrectly,
since the `tip_header` instance is not updated and its field `.hash` is
None. Fix that by updating `tip_header` and use the correct field -- we
want the tip header's previous hash (`.hashPrevBlock`).
2025-06-13 01:44:07 +02:00
Ava Chow
19765dca19 Merge bitcoin/bitcoin#32694: index: move disk read lookups to base class
029ba1a21d index: remove CBlockIndex access from CustomAppend() (furszy)
91b7ab6c69 refactor: index, simplify CopyHeightIndexToHashIndex to process single block (furszy)
6f1392cc42 indexes, refactor: Remove remaining CBlockIndex* uses in index Rewind methods (Ryan Ofsky)
0a248708dc indexes, refactor: Stop requiring CBlockIndex type to call IsBIP30Unspendable (Ryan Ofsky)
331a25cb16 test: indexes, avoid creating threads when sync runs synchronously (furszy)

Pull request description:

  Combining common refactors from #24230 and #26966, aiming to move both efforts forward while reducing their size and review burden.

  Broadly, #24230 focuses on enabling indexes to run in a separate process, and #26966 aims to parallelize the indexes initial synchronization process. A shared prerequisite for both is ensuring that only the base index class interacts with the node’s chain internals - child index classes should instead operate solely through chain events.

  This PR moves disk read lookups from child index classes to the base index class. It also includes a few documentation improvements and a test-only code cleanup.

ACKs for top commit:
  maflcko:
    review ACK 029ba1a21d 👡
  achow101:
    ACK 029ba1a21d
  TheCharlatan:
    Re-ACK 029ba1a21d
  davidgumberg:
    ACK 029ba1a21d
  mzumsande:
    Code Review ACK 029ba1a21d

Tree-SHA512: f073af407fc86f228cb47a32c7bcf2241551cc89ff32059317eb81d5b86fd5fda35f228d2567e0aedbc9fd6826291f5fee05619db35ba44108421ae04d11e6fb
2025-06-12 16:01:04 -07:00
Martin Zumsande
8cc3ac6c23 validation: Don't use IsValid() to filter for invalid blocks
IsValid() also returns false for blocks that have not been
validated yet up to the default validity level of BLOCK_VALID_TRANSACTIONS but
are not marked as invalid - e.g. if we only know the header.
Here, we specifically want to filter for invalid blocks.

Also removes the default arg from IsValid() which is now unused outside
of tests, to prevent this kind of misuse for the future.

Co-authored-by: TheCharlatan <seb.kung@gmail.com>
2025-06-12 14:40:59 -04:00