Commit Graph

41699 Commits

Author SHA1 Message Date
Vasil Dimov
9a7e5f4d68
net: don't extra bind for Tor if binds are restricted
If only `-bind=addr:port` is given (without `-bind=...=onion`) then we
would bind to `addr:port` _and_ to `127.0.0.1:8334` in addition which
may be unexpected, assuming the semantic of `-bind=addr:port` is
"bind _only_ to `addr:port`".

Change the above to not do the additional bind: if only
`-bind=addr:port` is given (without `-bind=...=onion`) then bind to
`addr:port` (only). If we are creating a Tor hidden service then use
`addr:port` as target (same behavior as before
https://github.com/bitcoin/bitcoin/pull/19991).

This allows disabling binding on the onion port.

Fixes https://github.com/bitcoin/bitcoin/issues/22726
2024-07-02 14:17:50 +02:00
glozow
926b8e39dc [doc] add release note for TRUC 2024-07-02 12:20:12 +01:00
glozow
19a9b90617 use version=3 instead of v3 in debug strings
Make it more clear to the user what we mean by v3.
2024-07-02 12:20:12 +01:00
glozow
881fac8e60 scripted-diff: change names from V3 to TRUC
-BEGIN VERIFY SCRIPT-
sed -i 's/SingleV3Checks/SingleTRUCChecks/g' $(git grep -l 'SingleV3Checks')
sed -i 's/PackageV3Checks/PackageTRUCChecks/g' $(git grep -l 'PackageV3Checks')
sed -i 's/PV3C/PTRUCC/g' src/policy/truc_policy.h
sed -i 's/V3_MAX_VSIZE/TRUC_MAX_VSIZE/g' $(git grep -l 'V3_MAX_VSIZE')
sed -i 's/V3_CHILD_MAX_VSIZE/TRUC_CHILD_MAX_VSIZE/g' $(git grep -l 'V3_CHILD_MAX_VSIZE')
sed -i 's/V3_DESCENDANT_LIMIT/TRUC_DESCENDANT_LIMIT/g' $(git grep -l 'V3_DESCENDANT_LIMIT')
sed -i 's/V3_ANCESTOR_LIMIT/TRUC_ANCESTOR_LIMIT/g' $(git grep -l 'V3_ANCESTOR_LIMIT')
sed -i 's/CheckMempoolV3Invariants/CheckMempoolTRUCInvariants/g' $(git grep -l 'CheckMempoolV3Invariants')
-END VERIFY SCRIPT-
2024-07-02 12:06:07 +01:00
glozow
a573dd2617 [doc] replace mentions of v3 with TRUC
Keep mentions of v3 in debug strings to help people who might not know
that TRUC is applied when version=3.
Also keep variable names in tests, as it is less verbose to keep v3 and v2.
2024-07-02 12:06:07 +01:00
glozow
089b5757df rename mempool_accept_v3.py to mempool_truc.py 2024-07-02 11:57:59 +01:00
glozow
d2c8d161b4
Merge bitcoin/bitcoin#30344: kernel: remove mempool_persist
f1478c0545 mempool: move LoadMempool/DumpMempool to node (Cory Fields)
6d242ff1e9 kernel: remove mempool_persist.cpp (Cory Fields)

Pull request description:

  DumpMempool/LoadMempool are not necessary for the kernel.

  Noticed while working on instantiated logging.

  I suppose these could have been left in on purpose, but I'm assuming it was probably just an oversight.

ACKs for top commit:
  TheCharlatan:
    Re-ACK f1478c0545
  glozow:
    ACK f1478c0545
  stickies-v:
    ACK f1478c0545

Tree-SHA512: 5825da0cf2e67470524eb6ebe397eb90755a368469a25f184df99ab935b3eb6d89eb802b41a6c3661e869bba3bbfa8ba9d95281bc75ebbf790ec5d9d1f79c66f
2024-07-02 10:25:25 +01:00
willcl-ark
39cea21ec5
wallet: fix FillPSBT errantly showing as complete
Fix cases of calls to `FillPSBT` returning `complete=true` when it's not
the case.

This can happen when some inputs have been signed but the transaction is
subsequently modified, e.g. in the context of PayJoins.

Also fixes a related bug where a finalized hex string is attempted to be
added during `walletprocesspsbt` but a CHECK_NONFATAL causes an abort.

Reported in #30077.
2024-07-02 09:58:39 +01:00
merge-script
04d63fb8c3
Merge bitcoin/bitcoin#30374: Revert "test: p2p: check that connecting to ourself leads to disconnect"
9ec2c53701 Revert "test: p2p: check that connecting to ourself leads to disconnect" (Sebastian Falbesoner)

Pull request description:

  As suggested in https://github.com/bitcoin/bitcoin/issues/30368#issuecomment-2200786670, this PR reverts the recently  added test  #30362 that causes frequent CI failures. A TODO is added in the functional test file to re-add it later when the race condition is fixed.

ACKs for top commit:
  mzumsande:
    utACK 9ec2c53701
  brunoerg:
    utACK 9ec2c53701
  tdb3:
    ACK 9ec2c53701

Tree-SHA512: df211ab194dc47f2ff8192f3827382974db922ed9fa54bc44fac75de4edfb3af43c1340cd5434b15b0b573f7b0ddd4451a0bbbbd7deaf7f4244e4865b9d5977e
2024-07-02 09:41:00 +01:00
Fabian Jahr
2342b46c45 test: Add coverage for getchaintxstats in assumeutxo context 2024-07-02 08:47:24 +02:00
MarcoFalke
faf2a6750b
rpc: Reorder getchaintxstats output 2024-07-02 08:46:06 +02:00
MarcoFalke
fa2dada0c9
rpc: Avoid getchaintxstats invalid results 2024-07-02 08:46:02 +02:00
Sebastian Falbesoner
9ec2c53701 Revert "test: p2p: check that connecting to ourself leads to disconnect"
This reverts commit 5d2fb14baf and
adds a TODO to add it later again once the race condition is fixed.
2024-07-01 20:53:16 +02:00
furszy
8ce3739edb test: verify wallet is still active post-migration failure
The migration process reloads the wallet after all failures.
This commit tests the behavior by trying to obtain a new address
after a decryption failure during migration.
2024-07-01 14:25:55 -04:00
Ava Chow
771bc60f13 wallet: Use LegacyDataSPKM when loading
In SetupLegacyScriptPubKeyMan, a base LegacyDataSPKM will be created if
the database has the format "bdb_ro" (i.e. the wallet was opened only
for migration purposes).

All of the loading functions are now called with a LegacyDataSPKM object
instead of LegacyScriptPubKeyMan.
2024-07-01 14:25:55 -04:00
Ava Chow
61d872f1b3 wallet: Move MigrateToDescriptor and DeleteRecords to LegacyDataSPKM 2024-07-01 14:25:54 -04:00
Ava Chow
b231f4d556 wallet: Move LegacyScriptPubKeyMan::IsMine to LegacyDataSPKM
IsMine is necessary for migration. It should be inlined with migration
when the legacy wallet is removed.
2024-07-01 14:24:35 -04:00
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