Commit graph

41732 commits

Author SHA1 Message Date
Ava Chow
7461d0c006 wallet: Move LegacySPKM data storage and handling to LegacyDataSPKM
In order to load the necessary data for migrating a legacy wallet
without the full LegacyScriptPubKeyMan, move the data storage and
loading components to LegacyDataSPKM. LegacyScriptPubKeyMan now
subclasses that.
2024-07-01 14:24:35 -04:00
Pieter Wuille
ce8094246e random: replace construct/assign with explicit Reseed() 2024-07-01 12:39:57 -04:00
Pieter Wuille
2ae392d561 random: use LogError for init failure 2024-07-01 12:39:57 -04:00
Pieter Wuille
97e16f5704 tests: make fuzz tests (mostly) deterministic with fixed seed 2024-07-01 12:39:57 -04:00
Pieter Wuille
2c91330dd6 random: cleanup order, comments, static 2024-07-01 12:39:57 -04:00
Pieter Wuille
8e31cf9c9b net, net_processing: use existing RNG objects more
PeerManagerImpl, as well as several net functions, already have existing
FastRandomContext objects. Reuse them instead of constructing new ones.
2024-07-01 12:39:57 -04:00
Pieter Wuille
d5fcbe966b random: improve precision of MakeExponentiallyDistributed 2024-07-01 12:39:57 -04:00
Pieter Wuille
cfb0dfe2cf random: convert GetExponentialRand into rand_exp_duration 2024-07-01 12:39:57 -04:00
Pieter Wuille
4eaa239dc3 random: convert GetRand{Micros,Millis} into randrange
There are only a few call sites of these throughout the codebase, so
move the functionality into FastRandomContext, and rewrite all call sites.

This requires the callers to explicit construct FastRandomContext objects,
which do add to the verbosity, but also make potentially apparent locations
where the code can be improved by reusing a FastRandomContext object (see
further commit).
2024-07-01 12:39:57 -04:00
Pieter Wuille
82de1b80d9 net: use GetRandMicros for cache expiration
This matches the data type of m_cache_entry_expiration.
2024-07-01 12:39:57 -04:00
Pieter Wuille
ddc184d999 random: get rid of GetRand by inlining 2024-07-01 12:39:53 -04:00
ishaanam
7d55796c53 wallet: update mempool conflicts tests + docs 2024-07-01 12:27:43 -04:00
merge-script
fe70be5377
Merge bitcoin/bitcoin#30369: ci: Clear unused /msan/llvm-project
fa6beb8cfc ci: Clear unused /msan/llvm-project (MarcoFalke)

Pull request description:

  Could help to fix the `no space left on device` that are sometimes seen.

ACKs for top commit:
  theuni:
    utACK fa6beb8cfc

Tree-SHA512: 0bedf4b26eed842c7bfa2caeac4df578cdbb00a658e8d0037b8b7b90150d8a9d1b8140437d1cf40b50d82a9085ea50cf9a010764c4439b2a03a457d399191319
2024-07-01 17:20:17 +01:00
MarcoFalke
fa360b047f
util: Use SteadyClock in RandAddSeedPerfmon 2024-07-01 17:40:35 +02:00
Pieter Wuille
e2d1f84858 random: make GetRand() support entire range (incl. max)
The existing code uses GetRand(nMax), with a default value for nMax, where nMax is the
range of values (not the maximum!) that the output is allowed to take. This will always
miss the last possible value (e.g. GetRand<uint32_t>() will never return 0xffffffff).

Fix this, by moving the functionality largely in RandomMixin, and also adding a
separate RandomMixin::rand function, which returns a value in the entire (non-negative)
range of an integer.
2024-07-01 10:26:46 -04:00
Pieter Wuille
810cdf6b4e tests: overhaul deterministic test randomness
The existing code provides two randomness mechanisms for test purposes:
- g_insecure_rand_ctx (with its wrappers InsecureRand*), which during tests is
  initialized using either zeros (SeedRand::ZEROS), or using environment-provided
  randomness (SeedRand::SEED).
- g_mock_deterministic_tests, which controls some (but not all) of the normal
  randomness output if set, but then makes it extremely predictable (identical
  output repeatedly).

Replace this with a single mechanism, which retains the SeedRand modes to control
all randomness. There is a new internal deterministic PRNG inside the random
module, which is used in GetRandBytes() when in test mode, and which is also used
to initialize g_insecure_rand_ctx. This means that during tests, all random numbers
are made deterministic. There is one exception, GetStrongRandBytes(), which even
in test mode still uses the normal PRNG state.

This probably opens the door to removing a lot of the ad-hoc "deterministic" mode
functions littered through the codebase (by simply running relevant tests in
SeedRand::ZEROS mode), but this isn't done yet.
2024-07-01 10:26:46 -04:00
Pieter Wuille
6cfdc5b104 random: convert XoRoShiRo128PlusPlus into full RNG
Convert XoRoShiRo128PlusPlus into a full RandomMixin-based RNG class,
providing all utility functionality that FastRandomContext has. In doing so,
it is renamed to InsecureRandomContext, highlighting its non-cryptographic
nature.

To do this, a fillrand fallback is added to RandomMixin (where it is used by
InsecureRandomContext), but FastRandomContext still uses its own fillrand.
2024-07-01 10:26:46 -04:00
Pieter Wuille
8cc2f45065 random: move XoRoShiRo128PlusPlus into random module
This is preparation for making it more generally accessible.
2024-07-01 10:26:46 -04:00
Pieter Wuille
8f5ac0d0b6 xoroshiro128plusplus: drop comment about nonexisting copy() 2024-07-01 10:26:46 -04:00
Pieter Wuille
8924f5120f random: modernize XoRoShiRo128PlusPlus a bit
Make use of C++20 functions in XoRoShiRo128PlusPlus.
2024-07-01 10:26:46 -04:00
Pieter Wuille
ddb7d26cfd random: add RandomMixin::randbits with compile-known bits
In many cases, it is known at compile time how many bits are requested from
randbits. Provide a variant of randbits that accepts this number as a template,
to make sure the compiler can make use of this knowledge. This is used immediately
in rand32() and randbool(), and a few further call sites.
2024-07-01 10:26:46 -04:00
Pieter Wuille
21ce9d8658 random: Improve RandomMixin::randbits
The previous randbits code would, when requesting more randomness than available
in its random bits buffer, discard the remaining entropy and generate new.

Benchmarks show that it's usually better to first consume the existing randomness
and only then generate new ones. This adds some complexity to randbits, but it
doesn't weigh up against the reduced need to generate more randomness.
2024-07-01 10:26:46 -04:00
Pieter Wuille
9b14d3d2da random: refactor: move rand* utilities to RandomMixin
Rather than make all the useful types of randomness be exclusive to
FastRandomContext, move it to a separate RandomMixin class where it can be reused by
other RNGs.

A Curiously Recurring Template Pattern (CRTP) is used for this, to provide the ability
for individual RNG classes to override one or more randomness functions, without
needing the runtime-cost of virtual classes.

Specifically, RNGs are expected to only provide fillrand and rand64, while all others
are derived from those:
- randbits
- randrange
- randbytes
- rand32
- rand256
- randbool
- rand_uniform_delay
- rand_uniform_duration
- min(), max(), operator()(), to comply with C++ URBG concept.
2024-07-01 10:26:46 -04:00
Pieter Wuille
40dd86fc3b random: use BasicByte concept in randbytes 2024-07-01 10:26:46 -04:00
Pieter Wuille
27cefc7fd6 random: add a few noexcepts to FastRandomContext 2024-07-01 10:26:46 -04:00
Pieter Wuille
b3b382dde2 random: move rand256() and randbytes() to .h file 2024-07-01 10:26:46 -04:00
Pieter Wuille
493a2e024e random: write rand256() in function of fillrand() 2024-07-01 10:26:46 -04:00
MarcoFalke
fa6beb8cfc
ci: Clear unused /msan/llvm-project 2024-07-01 15:51:51 +02:00
glozow
0bd2bd1efb
Merge bitcoin/bitcoin#30237: test: Add Compact Block Encoding test ReceiveWithExtraTransactions covering non-empty extra_txn
55eea003af test: Make blockencodings_tests deterministic (AngusP)
4c99301220 test: Add ReceiveWithExtraTransactions Compact Block receive test. (AngusP)
4621e7cc8f test: refactor: Rename extra_txn to const empty_extra_txn as it is empty in all test cases (AngusP)

Pull request description:

  This test uses the `extra_txn` (`vExtraTxnForCompact`) vector of optional orphan/conflicted/etc. transactions to provide transactions to a PartiallyDownloadedBlock that are not otherwise present in the mempool, and check that they are used.

  This also covers a former nullptr deref bug that was fixed in #29752 (bf031a517c) where the `extra_txn` vec/circular-buffer was null-initialized and not yet filled when dereferenced in `PartiallyDownloadedBlock::InitData`.

ACKs for top commit:
  marcofleon:
    Code review ACK 55eea003af. I ran the `blockencodings` unit test and no issues with the new test case.
  dergoegge:
    Code review ACK 55eea003af
  glozow:
    ACK 55eea003af

Tree-SHA512: d7909c212bb069e1f6184b26390a5000dcc5f2b18e49b86cceccb9f1ec4f874dd43bc9bc92abd4207c71dd78112ba58400042c230c42e93afe55ba51b943262c
2024-07-01 14:11:52 +01:00
merge-script
4c573e5718
Merge bitcoin/bitcoin#30306: fuzz: Improve stability for txorphan and mini_miner harnesses
e009bf681c Don't use iterator addresses in IteratorComparator (dergoegge)

Pull request description:

  See #29018.

  Stability for `txorphan` is now >90%. `mini_miner` needs further investigation, stability still low (although slightly improved by this PR) at ~62%.

ACKs for top commit:
  marcofleon:
    Tested ACK e009bf681c. Using afl++, stability for `txorphan` went from 82% to ~94% and for `mini_miner` it went from 84% to 97%. I ran them both using the corpora in qa-assets.
  glozow:
    utACK e009bf681c

Tree-SHA512: 6d0a20fd7ceedca8e702d8adde5fca500d8b0187147aee8d43b4e9eb5176dcacf60180f42a7158f037d18dbb27e479b6c069a0f3c912226505cbff5aa073a415
2024-07-01 12:11:27 +01:00
merge-script
c3b446a494
Merge bitcoin/bitcoin#30273: fuzz: FuzzedSock::Recv() don't lose bytes from MSG_PEEK read
4d81b4de33 fuzz: FuzzedSock::Recv() don't lose bytes from MSG_PEEK read (Vasil Dimov)
b51d75ea97 fuzz: simplify FuzzedSock::m_peek_data (Vasil Dimov)

Pull request description:

  Problem:

  If `FuzzedSock::Recv(N, MSG_PEEK)` is called then `N` bytes would be
  retrieved from the fuzz provider, saved in `m_peek_data` and returned
  to the caller (ok).

  If after this `FuzzedSock::Recv(M, 0)` is called where `M < N`
  then the first `M` bytes from `m_peek_data` would be returned
  to the caller (ok), but the remaining `N - M` bytes in `m_peek_data`
  would be discarded/lost (not ok). They must be returned by a subsequent
  `Recv()`.

  To resolve this, only remove the head `N` bytes from `m_peek_data`.

  ---

  This is a followup to https://github.com/bitcoin/bitcoin/pull/30211, more specifically:

  https://github.com/bitcoin/bitcoin/pull/30211#discussion_r1633199919
  https://github.com/bitcoin/bitcoin/pull/30211#discussion_r1633216366

ACKs for top commit:
  marcofleon:
    ACK 4d81b4de33. Tested this with the I2P fuzz target and there's no loss in coverage. I think overall this is an improvement in the robustness of `Recv` in `FuzzedSock`.
  dergoegge:
    Code review ACK 4d81b4de33
  brunoerg:
    utACK 4d81b4de33

Tree-SHA512: 73b5cb396784652447874998850e45899e8cba49dcd2cc96b2d1f63be78e48201ab88a76cf1c3cb880abac57af07f2c65d673a1021ee1a577d0496c3a4b0c5dd
2024-07-01 11:58:58 +01:00
merge-script
2f813154ef
Merge bitcoin/bitcoin#30358: scripted-diff: Log parameter interaction not thrice
fa1bc7c88b scripted-diff: Log parameter interaction not thrice (MarcoFalke)
fafb7875e1 doc: Fix outdated dev comment about logging (MarcoFalke)

Pull request description:

  Seems a bit overkill to log the words "parameter interaction" thrice, when at least once is enough. So do that.

  Before:

  ```
  2024-06-28T15:30:57Z [init.cpp:745] [InitParameterInteraction] InitParameterInteraction: parameter interaction: -connect or -maxconnections=0 set -> setting -dnsseed=0
  ```

  After:

  ```
  2024-06-28T15:47:27Z [init.cpp:745] [InitParameterInteraction] parameter interaction: -connect or -maxconnections=0 set -> setting -dnsseed=0

ACKs for top commit:
  paplorinc:
    ACK fa1bc7c88b
  fjahr:
    utACK fa1bc7c88b
  TheCharlatan:
    Nice, ACK fa1bc7c88b
  hodlinator:
    utACK fa1bc7c88b

Tree-SHA512: 83cd92e20dffa38737d4fd31764481284383e12671d9e4b33cfa496743c95c10921a113b1da2caafeb44fca3759a28a8e230df5e30c29fb55d5854ff1531382c
2024-07-01 11:56:23 +01:00
merge-script
b3c22e0c72
Merge bitcoin/bitcoin#30362: test: p2p: check that connecting to ourself leads to disconnect
5d2fb14baf test: p2p: check that connecting to ourself leads to disconnect (Sebastian Falbesoner)

Pull request description:

  This small PR adds test coverage for the scenario of connecting to ourself, leading to an immediate disconnect:
  2f6dca4d1c/src/net_processing.cpp (L3729-L3735)

  This logic has been first introduced by Satoshi in October 2009, together with a couple of other changes and a version bump to "v0.1.6 BETA" (see commit cc0b4c3b62).

ACKs for top commit:
  kevkevinpal:
    tACK [5d2fb14](5d2fb14baf)
  maflcko:
    ACK 5d2fb14baf
  fjahr:
    tACK 5d2fb14baf
  tdb3:
    ACK 5d2fb14baf

Tree-SHA512: 30fb8c82cef94701affeca386ecd59daa32231635fa770fe225feb69fdab2ffedbfa157edd563f65099ec209f2dafffc1154f7f9292c2ea68bbd114750904875
2024-07-01 10:32:52 +01:00
Lőrinc
323ce30308 Moved the repeated -printpriority fetching out of AddToBlock
AddToBlock was called repeatedly from `addPackageTxs` where the constant value of `printpriority` is recalculated every time.
Since its behavior was changed in 400b151, I've named the variable accordingly.

This showed up during profiling of AssembleBlock, fetching it once in the constructor results in a measurable speed increase for many iterations.

> ./src/bench/bench_bitcoin --filter='AssembleBlock' --min-time=1000

before:
|               ns/op |                op/s |    err% |     total | benchmark
|--------------------:|--------------------:|--------:|----------:|:----------
|          155,558.97 |            6,428.43 |    0.1% |      1.10 | `AssembleBlock`

after:
|               ns/op |                op/s |    err% |     total | benchmark
|--------------------:|--------------------:|--------:|----------:|:----------
|          148,083.68 |            6,752.94 |    0.1% |      1.10 | `AssembleBlock`

Co-authored-by: furszy <mfurszy@protonmail.com>
2024-06-30 23:00:13 +02:00
kevkevinpal
8ec24bdad8
test: Added coverage to Block not found error using gettxoutsetinfo 2024-06-30 10:46:33 -04:00
Martin Zumsande
d35efe1efc p2p: Start downloading historical blocks from common ancestor
Otherwise, if the background tip is not an ancestor of the snapshot, blocks in between that ancestor up to the height of the background tip will never be requested.

Co-authored-by: Martin Zumsande <mzumsande@gmail.com>
Co-authored-by: Alfonso Roman Zubeldia <19962151+alfonsoromanz@users.noreply.github.com>
2024-06-29 14:07:34 +02:00
Sebastian Falbesoner
5d2fb14baf test: p2p: check that connecting to ourself leads to disconnect
The "connect to ourself" detection logic has been first introduced
by Satoshi in October 2009, together with a couple of other changes
and a version bump to "v0.1.6 BETA" (see commit
cc0b4c3b62).
2024-06-29 00:30:14 +02:00
MarcoFalke
fa1bc7c88b
scripted-diff: Log parameter interaction not thrice
-BEGIN VERIFY SCRIPT-
 sed -i 's/LogPrintf("%s: \(parameter interaction: .*\)", __func__/LogInfo("\1"/g' ./src/init.cpp
-END VERIFY SCRIPT-
2024-06-28 17:46:00 +02:00
MarcoFalke
fafb7875e1
doc: Fix outdated dev comment about logging 2024-06-28 17:37:58 +02:00
Anthony Towns
46819f5df6 wallet: use LogTrace for walletdb log messages at trace level 2024-06-28 17:41:52 +10:00
Ryan Ofsky
2f6dca4d1c
Merge bitcoin/bitcoin#30335: Mining interface followups, reduce cs_main locking, test rpc bug fix
a74b0f93ef Have testBlockValidity hold cs_main instead of caller (Sjors Provoost)
f6dc6db44d refactor: use CHECK_NONFATAL to avoid single-use symbol (Sjors Provoost)
5fb2b70489 Drop unneeded lock from createNewBlock (Sjors Provoost)
75ce7637ad refactor: testBlockValidity make out argument last (Sjors Provoost)
83a9bef0e2 Add missing include for mining interface (Sjors Provoost)

Pull request description:

  Followups from #30200

  Fixes:
  - `std::unique_ptr` needs `#include <memory>` (noticed while working on #30332, which has fewer includes than its parent PR that I originally tested with)
  - Drop lock from createNewBlock that was spuriously added
  - Have testBlockValidity hold cs_main instead of caller (also fixes a race condition in test-only code)

  Refactor:
  - Use CHECK_NONFATAL to avoid single-use symbol (refactor)
  - move output argument `state` to the end of `testBlockValidity`, see https://github.com/bitcoin/bitcoin/pull/30200#discussion_r1647987176

ACKs for top commit:
  AngusP:
    Code Review ACK a74b0f93ef
  itornaza:
    Tested ACK a74b0f93ef
  ryanofsky:
    Code review ACK a74b0f93ef. Just new error string is added since last review, and a commit message was updated

Tree-SHA512: 805e133bb59303fcee107d6f02b3e2761396c290efb731a85e6a29ae56b4b1b9cd28ada9629e979704dcfd98cf35034e7e6b618e29923049eb1eca2f65630e41
2024-06-27 18:16:27 -04:00
Ryan Ofsky
d38dbaad98
Merge bitcoin/bitcoin#28167: init: Add option for rpccookie permissions (replace 26088)
73f0a6cbd0 doc: detail -rpccookieperms option (willcl-ark)
d2afa2690c test: add rpccookieperms test (willcl-ark)
f467aede78 init: add option for rpccookie permissions (willcl-ark)
7df03f1a92 util: add perm string helper functions (willcl-ark)

Pull request description:

  This PR picks up #26088 by aureleoules which adds a bitcoind launch option `-rpccookieperms` to set the file permissions of the cookie generated by bitcoin core.

  Example usage to make the generated cookie group-readable: `./src/bitcoind -rpccookieperms=group`.

  Accepted values for `-rpccookieperms` are `[owner|group|all]`. We let `fs::perms` handle platform-specific permissions changes.

ACKs for top commit:
  achow101:
    ACK 73f0a6cbd0
  ryanofsky:
    Code review ACK 73f0a6cbd0. Main change since last review is no longer throwing a skip exception in the rpc test on windows, so other checks can run after it, and overall test result is passing, not skipped. Also were clarifying renames and documentation improvements.
  tdb3:
    cr ACK 73f0a6cbd0

Tree-SHA512: e800d59a44aca10e1c58ca69bf3fdde9f6ccf5eab4b7b962645af6d6bc0cfa3a357701e409c8c60d8d7744fcd33a91e77ada11790aa88cd7811ef60fab86ab11
2024-06-27 17:35:08 -04:00
Ava Chow
f0745d028e
Merge bitcoin/bitcoin#30050: refactor, wallet: get serialized size of CRecipients directly
a9c7300135 move-only: refactor CreateTransactionInternal (josibake)
adc6ab25bb wallet: use CRecipient instead of CTxOut (josibake)

Pull request description:

  Broken out from #28201

  ---

  In order to estimate fees properly, we need to know what the final serialized transaction size will be. This PR refactors `CreateTransactionInternal` to:

  * Get the serialized size directly from the `CRecipient`: this sets us up in a future PR to calculate the serialized size of silent payment `CTxDestinations` (see 797e21c8c1)
  * Use the new `GetSerializeSizeForRecipient` to move the serialize size calculation to *before* coin selection and the output creation to *after* coin selection: this also sets us up for silent payments sending in a future PR in that silent payments outputs cannot be created until after the inputs to the transaction have been selected

  Aside from the silent payments use case, I think this structure logically makes more sense. As a reminder, move-only commits are best reviewed with something like `git diff -w --color-moved=dimmed-zebra`

ACKs for top commit:
  S3RK:
    reACK a9c7300135
  achow101:
    ACK a9c7300135
  rkrux:
    tACK [a9c7300](a9c7300135)

Tree-SHA512: 412e1764b98f7428c8530c3a68f55e32063d6b66ab2ff613e1c7e12d49b049807cb60055cfe7f7e8ffe7ac7f0f9931427cbfd3efe7d4f97a5a0f6d1bf1aaac58
2024-06-27 13:59:46 -04:00
ismaelsadeeq
734076c6de [wallet, rpc]: add max_tx_weight to tx funding options
This allows a transaction's weight to be bound under a certain
weight if possible and desired. This can be beneficial for future
RBF attempts, or whenever a more restricted spend topology is
desired.

Co-authored-by: Greg Sanders <gsanders87@gmail.com>
2024-06-27 15:31:21 +01:00
willcl-ark
73f0a6cbd0
doc: detail -rpccookieperms option
Co-authored-by: tdb3 <106488469+tdb3@users.noreply.github.com>
2024-06-27 15:08:27 +01:00
willcl-ark
d2afa2690c
test: add rpccookieperms test
Tests various perms on non-Windows OSes
2024-06-27 15:08:23 +01:00
willcl-ark
f467aede78
init: add option for rpccookie permissions
Add a bitcoind launch option `-rpccookieperms` to configure the file
permissions of the cookie on Unix systems.
2024-06-27 15:08:19 +01:00
willcl-ark
7df03f1a92
util: add perm string helper functions
PermsToSymbolicString will convert from fs::perms to string type
'rwxrwxrwx'.

InterpretPermString will convert from a user-supplied "perm string" such
as 'owner', 'group' or 'all, into appropriate fs::perms.
2024-06-27 14:55:10 +01:00
ismaelsadeeq
b6fc5043c1 [wallet]: update the data type of change_output_size, change_spend_size and tx_noinputs_size to int
- This change ensures consistency in transaction size and weight calculation
  within the wallet and prevents conversion overflow when calculating
  `max_selection_weight`.
2024-06-27 12:37:33 +01:00
ismaelsadeeq
baab0d2d43 [doc]: update reason for deducting change output weight
`CoinGrinder` will also produce change output, listing all the
Coin selection algorithms that produces change output is not maintainable,
just infer that remaining algorithms all might produce change.
2024-06-27 12:37:33 +01:00