Commit Graph

35769 Commits

Author SHA1 Message Date
Vasil Dimov
8d9ee8efe8
sync: remove DebugLock alias template
Use `UniqueLock` directly. Type deduction works just fine from the first
argument to the constructor of `UniqueLock`, so there is no need to
repeat

```cpp
UniqueLock<typename std::remove_reference<typename std::remove_pointer<decltype(cs)>::type>::type>
```

five times in the `LOCK` macros. Just `UniqueLock` suffices.
2022-10-10 09:20:58 +02:00
Vasil Dimov
4b2e16763f
sync: avoid confusing name overlap (Mutex)
Use `MutexType` instead of `Mutex` for the template parameter of
`UniqueLock` because there is already a class named `Mutex` and the
naming overlap is confusing. `MutexType` is used elsewhere in `sync.h`.
2022-10-10 09:20:45 +02:00
fanquake
4175c332b9
Merge bitcoin/bitcoin#26215: index: Improve BaseIndex::BlockUntilSyncedToCurrentChain reliability
8891949bdc index: Improve BaseIndex::BlockUntilSyncedToCurrentChain reliability (Ryan Ofsky)

Pull request description:

  Since commit f08c9fb0c6 from PR https://github.com/bitcoin/bitcoin/pull/21726, index  `BlockUntilSyncedToCurrentChain` behavior has been less reliable, and there has also been a race condition in the `coinstatsindex_initial_sync` unit test.

  It seems better for `BlockUntilSyncedToCurrentChain` to actually wait for the last connected block to be fully processed, than to be able to return before prune locks are set, so this switches the order of `m_best_block_index = block;` and `UpdatePruneLock` statements in `SetBestBlockIndex` to make it more reliable.

  Also since commit f08c9fb0c6, there has been a race condition in the `coinstatsindex_initial_sync` test. Before that commit, the atomic index best block pointer `m_best_block_index` was updated as the last step of `BaseIndex::BlockConnected`, so `BlockUntilSyncedToCurrentChain` could safely be used in tests to wait for the last `BlockConnected` notification to be finished before stopping and destroying the index.  But after that commit, calling `BlockUntilSyncedToCurrentChain` is no longer sufficient, and there is a race between the test shutdown code which destroys the index object and the new code introduced in that commit calling `AllowPrune()` and `GetName()` on the index object. Reproducibility instructions for this are in https://github.com/bitcoin/bitcoin/issues/25365#issuecomment-1259744133

  This commit fixes the `coinstatsindex_initial_sync` race condition, even though it will require an additional change to silence TSAN false positives, https://github.com/bitcoin/bitcoin/pull/26188, after it is fixed. So this partially addresses but does not resolve the bug reporting TSAN errors https://github.com/bitcoin/bitcoin/issues/25365.

  There is no known race condition outside of test code currently, because the bitcoind `Shutdown` function calls `FlushBackgroundCallbacks` not `BlockUntilSyncedToCurrentChain` to safely shut down.

  Co-authored-by: vasild
  Co-authored-by: MarcoFalke

ACKs for top commit:
  mzumsande:
    re-ACK 8891949bdc

Tree-SHA512: 52e29e3772a0c92873c54e5ffb31dd66a909b68a2031b7585713cd1d976811289c98bd9bb41679a8689062f03be4f97bb8368696e789caa4607c2fd8b1fe289b
2022-10-10 14:23:00 +08:00
fanquake
cf3db7c256
Merge bitcoin/bitcoin#26258: refactor: Remove unused CDataStream::rdbuf method
fabbbe32ee Remove unused CDataStream::rdbuf method (MacroFake)

Pull request description:

  It is unused and seems unlikely to be ever used.

ACKs for top commit:
  theStack:
    Code-review ACK fabbbe32ee
  aureleoules:
    ACK fabbbe32ee

Tree-SHA512: 5804642658f96a0fb51482ebf3a062bb0f997c1e0527455afa4aceeeb6c1ad139a98b14a7c8a0909daba733a83bdc24fcadad45060ead4be6eb3dc3e66c129e2
2022-10-10 14:14:15 +08:00
glozow
d33c5894e9
Merge bitcoin/bitcoin#26103: refactor: mempool: use CTxMemPool::Limits
33b12e5df6 docs: improve docs where MemPoolLimits is used (stickies-v)
6945853c0b test: use NoLimits() in MempoolIndexingTest (stickies-v)
3a86f24a4c refactor: mempool: use CTxMempool::Limits (stickies-v)
b85af25f87 refactor: mempool: add MemPoolLimits::NoLimits() (stickies-v)

Pull request description:

  Mempool currently considers 4 limits regarding ancestor and descendant count and size, which get passed around between functions quite a bit. This PR uses `CTxMemPool::Limits` introduced in https://github.com/bitcoin/bitcoin/pull/25290 to simplify those signatures and callsites.

  The purpose of this PR is to improve readability and maintenance, without behaviour change.

  As noted in the first commit "refactor: mempool: change MemPoolLimits members to uint", we currently have an underflow issue where a user could pass a negative `-limitancestorsize`, which is eventually cast to an unsigned integer. This behaviour already exists. Because it's orthogonal and to minimize scope, I think this should be fixed in a separate PR.

ACKs for top commit:
  hebasto:
    ACK 33b12e5df6, I have reviewed the code and it looks OK, I agree it can be merged.
  glozow:
    reACK 33b12e5df6

Tree-SHA512: 591c6dcee1894f1c3ca28b34a680eeadcf0d40cda92451b4a422c03087b27d682b5e30ba4367abd75a99b5ccb115b7884b0026958d3c7dddab030549db5a4056
2022-10-09 10:28:32 -04:00
Dimitris Tsapakidis
adb1714426 Fix comment typos in scriptpubkeyman.cpp, wallet.cpp, wallet.h
Fix comment typos:
sigature -> signature
ponter -> pointer
it's key -> its key
2022-10-09 17:19:59 +03:00
glozow
ec8016eba7
Merge bitcoin/bitcoin#26281: docs: fix m_children to be a member of CTxMemPoolEntry
01bf4af4f2 docs: fix m_children to be a member of CTxMemPoolEntry (stickies-v)

Pull request description:

  Small documentation fix to reflect that `m_children` [is a member](73b61717a9/src/txmempool.h (L99)) of `CTxMemPoolEntry`, not `CTxMemPool`

ACKs for top commit:
  hebasto:
    ACK 01bf4af4f2, wrong wording was introduced in bitcoin/bitcoin#19478.
  glozow:
    ACK 01bf4af4f2

Tree-SHA512: b66c43b92fda44682b1f67c43073ca9e133a6dc03cd28253e571e67170531138c20b22ffdb08f312fb2d47a1f869b876611646b54325c8b614d12049befad578
2022-10-09 10:17:02 -04:00
James O'Beirne
1c36bafc5f
wallet: have prune error take precedence over assumedvalid
From Russ Yanofsky:

"Agree with all of Marco's points here and think this should be updated

If havePrune and hasAssumedValidChain are both true, better to show
havePrune error message.  Assumed-valid error message is vague and not
very actionable.  Would suggest "Error loading wallet. Wallet requires
blocks to be downloaded, and software does not currently support loading
wallets while blocks are being downloaded out of order though assumeutxo
snapshots. Wallet should be able to load successfully after node sync
reaches height {block_height}"

Co-authored-by: MacroFake <MarcoFalke@gmail.com>
Co-authored-by: Russ Yanofsky <russ@yanofsky.org>
2022-10-07 15:19:31 -04:00
stickies-v
01bf4af4f2
docs: fix m_children to be a member of CTxMemPoolEntry 2022-10-07 15:06:45 +01:00
MacroFake
fa08663344
rpc: Return coinbase flag in scantxoutset 2022-10-07 15:04:28 +02:00
MacroFake
fa8a305ddd
test: Remove confusing DUMMY_P2WPKH_SCRIPT 2022-10-07 13:11:05 +02:00
josibake
deba6fe315
test: update feature_config_args.py
add two new test cases for conf and reindex
2022-10-06 18:20:30 -04:00
josibake
2e3826cbcd
util: warn if reindex is used in conf
using reindex in a conf file can lead to the node reindexing on every restart.
we still allow it but throw a warning.
2022-10-06 18:20:30 -04:00
josibake
5e744f4238
util: disallow setting conf in bitcoin.conf
Help from `bitcoind -h` states that conf can only be used from the commandline.
However, if conf is set in a bitcoin.conf file, it is ignored but there is no error.

Show an error to user if conf is set in a .conf file and prompt them to use
`includeconf` if they wish to specify additional config files.

Adds `IsConfSupported` function to allow for easily adding conf options
to disallow or throw warnings for.
2022-10-06 18:20:14 -04:00
Andrew Chow
9e386afb67 tests: Test that PSBT_OUT_TAP_TREE is included correctly 2022-10-06 15:32:51 -04:00
Andrew Chow
30ff25cf37 psbt: Only include m_tap_tree if it has scripts 2022-10-06 15:32:51 -04:00
Andrew Chow
0577d423ad psbt: Change m_tap_tree to store just the tuples
Instead of having an entire TaprootBuilder which may or may not be
complete, and could potentially have future changes that interact oddly
with taproot tree tuples, have m_tap_tree be just the tuples.

When needed in other a TaprootBuilder for actual use, the tuples will be
added to a a TaprootBuilder that, in the future, can take in whatever
other data is needed as well.
2022-10-06 15:32:51 -04:00
Andrew Chow
22c051ca70 tests: Test that PSBT_OUT_TAP_TREE is combined correctly 2022-10-06 15:32:45 -04:00
Andrew Chow
7df6e1bb77 psbt: Fix merging of m_tap_tree
Merging should be checking that the current PSBTOutput doesn't have a
taptree and the other one's is copied over. The original merging had
this inverted and would remove m_tap_tree if the other did not have it.
2022-10-06 15:19:30 -04:00
MacroFake
73b61717a9
Merge bitcoin/bitcoin#26272: test: Prevent UB in minisketch_tests.cpp
97007e2b9b test: Prevent UB in `minisketch_tests.cpp` (Hennadii Stepanov)

Pull request description:

  [`std::optional::operator*`](https://en.cppreference.com/w/cpp/utility/optional/operator*), which follows after the changed line, can cause UB.

  This PR addresses https://github.com/bitcoin/bitcoin/issues/26262#issuecomment-1268855418

ACKs for top commit:
  stickies-v:
    ACK 97007e2b9b

Tree-SHA512: a7dde8dac0cbdfa362fa1158b4564eccff9405852612227d581690c9a34084b3467ae6d4c0269262688d75339dcea90aaa38fccbba9be92d2643c2113860f3d6
2022-10-06 16:01:17 +02:00
Hennadii Stepanov
97007e2b9b
test: Prevent UB in minisketch_tests.cpp 2022-10-06 12:50:54 +01:00
glozow
292f652d53
Merge bitcoin/bitcoin#24364: refactor: remove duplicate code from BlockAssembler
0f40d65321 refactor: remove duplicate code from BlockAssembler (James O'Beirne)

Pull request description:

  Found while reminding myself how transactions are chosen for blocks. Take it or leave it!

ACKs for top commit:
  glozow:
    ACK 0f40d65321
  theStack:
    Concept and code-review ACK 0f40d65321

Tree-SHA512: 8a2694e670ce3fe897ab8f64f64c8df5f8487fc1264527a3abbcba0e5b921fb693416497ccd62508295bc33f202c65556b91b6af463acb91aab43138d2492c14
2022-10-06 12:50:33 +01:00
muxator
9153ff3e27 rpc: add non-regression test about deriveaddresses crash when index is 2147483647
This test would cause a crash in bitcoind (see #26274) if the fix given in the
previous commit was not applied.
2022-10-06 12:03:36 +02:00
muxator
addf9d6502 rpc: fix crash in deriveaddresses when derivation index is 2147483647
2147483647 is the maximum positive value of a signed int32, and - currently -
the maximum value that the deriveaddresses bitcoin RPC call accepts as
derivation index due to its input validation routines.

Before this change, when the derivation index (and thus range_end) reached
std::numeric_limits<int_32_t>::max(), the "i" variable in the for cycle (which
is declared as int, and as such 32 bits in size on most platforms) would be
incremented at the end of the first iteration and then warp back to
-2147483648. This caused SIGABRT in bitcoind and a core dump.

This change assigns "i" an explicit size of 64 bits on every platform,
sidestepping the problem.

Fixes #26274.
2022-10-06 22:17:49 +02:00
amadeuszpawlik
04526787b5 Validate port options
Check `port` options for invalid values (ports are parsed as uint16, so
in practice values >65535 are invalid; port 0 is undefined and therefore
considered invalid too). This allows for an early rejection of faulty
values and an supplying an informative message to the user.

Splits tests in `feature_proxy.py` to cover both invalid `hostname`
and `port` values.

Adds a release-note as previously valid `-port` and `-rpcport` values
can now result in errors.
2022-10-05 19:30:15 +02:00
amadeuszpawlik
f8387c4234 Validate port value in SplitHostPort
Forward the validation of the port from `ParseUInt16(...)`.
Consider port 0 as invalid.
Add suitable test for the `SplitHostPort` function.
Add doxygen description to the `SplitHostPort` function.
2022-10-05 19:24:04 +02:00
Ryan Ofsky
8891949bdc index: Improve BaseIndex::BlockUntilSyncedToCurrentChain reliability
Since commit f08c9fb0c6 from PR
https://github.com/bitcoin/bitcoin/pull/21726, index
`BlockUntilSyncedToCurrentChain` behavior has been less reliable, and there has
also been a race condition in the `coinstatsindex_initial_sync` unit test.

It seems better for `BlockUntilSyncedToCurrentChain` to actually wait for the
last connected block to be fully processed, than to be able to return before
prune locks are set, so this switches the order of `m_best_block_index =
block;` and `UpdatePruneLock` statements in `SetBestBlockIndex` to make it more
reliable.

Also since commit f08c9fb0c6, there has been a
race condition in the `coinstatsindex_initial_sync` test. Before that commit,
the atomic index best block pointer `m_best_block_index` was updated as the
last step of `BaseIndex::BlockConnected`, so `BlockUntilSyncedToCurrentChain`
could safely be used in tests to wait for the last `BlockConnected`
notification to be finished before stopping and destroying the index. But
after that commit, calling `BlockUntilSyncedToCurrentChain` is no longer
sufficient, and there is a race between the test shutdown code which destroys
the index object and the new code introduced in that commit calling
`AllowPrune()` and `GetName()` on the index object. Reproducibility
instructions for this are in
https://github.com/bitcoin/bitcoin/issues/25365#issuecomment-1259744133

This commit fixes the `coinstatsindex_initial_sync` race condition, even though
it will require an additional change to silence TSAN false positives,
https://github.com/bitcoin/bitcoin/pull/26188, after it is fixed. So this
partially addresses but does not resolve the bug reporting TSAN errors
https://github.com/bitcoin/bitcoin/issues/25365.

There is no known race condition outside of test code currently, because the
bitcoind `Shutdown` function calls `FlushBackgroundCallbacks` not
`BlockUntilSyncedToCurrentChain` to safely shut down.

Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
Co-authored-by: MacroFake <falke.marco@gmail.com>
2022-10-05 11:06:58 -04:00
MacroFake
5e82b9ba96
Merge bitcoin/bitcoin#26252: refactor: Make 64-bit shift explicit
5c5b85d0e7 refactor: Make 64-bit shift explicit (Hennadii Stepanov)

Pull request description:

  [`std::array::at()`](https://en.cppreference.com/w/cpp/container/array/at) expects an argument of the `size_t` type. This PR avoids implicit type conversion (for both 64-bit and 32-bit systems).

  Also it enables MSVC warning [C4334](https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4334) for all codebase.

ACKs for top commit:
  MarcoFalke:
    ACK 5c5b85d0e7 🚎
  jonatack:
    Code review ACK 5c5b85d0e7

Tree-SHA512: fda850a42068f2ada9f877fac9ff8af1e22b5dcb3e708f5b95c316e77c52c72d33cd9ec6507a7f5d1731d1afdf5af6dc65025d388cc480f82c46f4d88ef2d306
2022-10-05 15:46:23 +02:00
MacroFake
fabbbe32ee
Remove unused CDataStream::rdbuf method
It is unused and seems unlikely to be ever used.
2022-10-05 15:29:36 +02:00
Jon Atack
c2a21c0670 gui: use fallback value for Version and User Agent during peer connection
During connection setup for a peer, getpeerinfo returns "version": 0, "subver": ""
and the GUI Peers window displays 0 and an empty field, respectively.

Give these fields the same behavior as the other fields in the GUI Peers window:
display the fallback value in src/qt/forms/debugwindow.ui (i.e. "N/A") until a
valid result is available after the peer connection completes.
2022-10-05 15:19:01 +02:00
stickies-v
33b12e5df6
docs: improve docs where MemPoolLimits is used 2022-10-05 13:09:08 +01:00
stickies-v
6945853c0b
test: use NoLimits() in MempoolIndexingTest
The (100, 1000000, 1000, 1000000) limits are arbitrarily high and
don't restrict anything, they are just meant to calculate ancestors
properly. Using NoLimits() makes this intent more clear and simplifies
the code.
2022-10-05 13:07:11 +01:00
stickies-v
3a86f24a4c
refactor: mempool: use CTxMempool::Limits
Simplifies function signatures by removing repetition of all the
ancestor/descendant limits,  and increases readability by being
more verbose by naming the limits, while still reducing the LoC.
2022-10-05 13:07:11 +01:00
stickies-v
b85af25f87
refactor: mempool: add MemPoolLimits::NoLimits()
There are quite a few places in the codebase that require us to
construct a CTxMemPool without limits on ancestors and descendants.
This helper function allows us to get rid of all that duplication.
2022-10-05 13:07:11 +01:00
MacroFake
faa15527d7
test: Use dedicated mempool in TestBasicMining
No need for a shared mempool. Also remove unused chainparams parameter.

Can be reviewed with --ignore-all-space
2022-10-05 13:36:57 +02:00
MacroFake
fafab384a0
test: Use dedicated mempool in TestPackageSelection
No need for a shared mempool. Also remove unused chainparams parameter.
2022-10-05 13:36:56 +02:00
MacroFake
fa4055d79c
test: Use dedicated mempool in TestPrioritisedMining
No need for a shared mempool. Also remove unused chainparams parameter.
2022-10-05 13:35:18 +02:00
MacroFake
fa29218285
test: Pass mempool reference to AssemblerForTest 2022-10-05 13:34:36 +02:00
MacroFake
b2e6d37b51
Merge bitcoin/bitcoin#26256: ci: Remove clang-format from lint task
fa04376554 Remove clang-format from lint task (MacroFake)

Pull request description:

  clang-format could be used in scripted diffs, but remained largely unused.

  So remove the install bloat, as it is unlikely to be used in the future.

ACKs for top commit:
  fanquake:
    ACK fa04376554
  hebasto:
    ACK fa04376554

Tree-SHA512: e0a3ee47d2aa2565dd34676914c558c985eaeb522a05f10bcaac115871edcf0d7f101b517e4d452ca5223c40b18ad02883c31e2da3d1f4ff86464a9af0097b11
2022-10-05 11:52:46 +02:00
MacroFake
fa04376554
Remove clang-format from lint task
clang-format could be used in scripted diffs, but remained largely
unused.
2022-10-05 10:52:42 +02:00
MacroFake
d3cdd37d92
Merge bitcoin/bitcoin#26250: fuzz: add mempool_utils.cpp
8a6b6dfcd8 fuzz: pass max fee into ConsumeTxMemPoolEntry (fanquake)
eb15569280 fuzz: add util/mempool/h.cpp (fanquake)

Pull request description:

  Moving the heavy (Boost) mempool code out of fuzz/util.h. Means that (for ex) a crypto_common fuzz unit doesn't need to care about seeing endless Boost headers. This results in a ~10% speedup (for me) when compiling the fuzz tests. Your results may vary.

ACKs for top commit:
  MarcoFalke:
    review ACK 8a6b6dfcd8 🍮

Tree-SHA512: 27dc9d9581ac0b1b319cc0dc08fe5f8fbf9269386a5cb23f6fd5d8231bf015ed942ab4414d8001220541be0013756354578ddab1fec607c6fba04daf421bc870
2022-10-05 10:29:00 +02:00
Cory Fields
43b8777dc3 refactor: move run_command from util to common
Quoting ryanofsky: "util can be the library for things included in the kernel
which the kernel can depend on, and common can be the library for other code
that needs to be shared internally, but should not be part of the kernel or
shared externally."
2022-10-04 21:21:05 +00:00
Hennadii Stepanov
5c5b85d0e7
refactor: Make 64-bit shift explicit
Also this change enables MSVC warning C4334 for all codebase.

https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4334
2022-10-04 21:49:07 +01:00
fanquake
a23f8c8978
Merge bitcoin/bitcoin#26234: ci: Allow PIP_PACKAGES on centos
fa6054e952 ci: Allow PIP_PACKAGES on centos (MacroFake)
fac085a05c ci: Remove unused package (MacroFake)

Pull request description:

  This was added in 7fc5e865b9 but I can't see a reason why this should be forbidden.

  This is also needed for other changes (bumping the minimum python version).

ACKs for top commit:
  hebasto:
    re-ACK fa6054e952

Tree-SHA512: e8ead9ee00079024eb1e8c6e7b31c78cf2a3392159b444765c2ea9a58bed2a7550bf71083210692a45bb8ed7896cb882b72bf70baa13a2384864b2b510b73005
2022-10-04 21:39:29 +01:00
fanquake
b6565b65aa
Merge bitcoin/bitcoin#26243: test: Remove unused fCheckpointsEnabled from miner_tests
fa9436e908 test: Remove unused fCheckpointsEnabled from miner_tests (MacroFake)

Pull request description:

  The earliest checkpoint is at height 11111, so this can't possibly have any impact on this test.

ACKs for top commit:
  fanquake:
    ACK fa9436e908 - given the low number of blocks, having the additional check in `ContextualCheckBlockHeader()` enabled should be a no-op, so disabling and re-enabling is dead code.

Tree-SHA512: 7d1b952c297c915e9588761f82f5006cf5186b7ff30e8a1c702302e0b44afe536bde9eda8acf2995825ae01d2ad9d2393ae2feefb29f15676aaf71881941579b
2022-10-04 21:17:07 +01:00
fanquake
8a6b6dfcd8
fuzz: pass max fee into ConsumeTxMemPoolEntry 2022-10-04 21:12:50 +01:00
fanquake
eb15569280
fuzz: add util/mempool/h.cpp
Moving the mempool code (Boost) out of util.h, results in a ~10% speedup
(for me) when compiling the fuzz tests.
2022-10-04 21:12:50 +01:00
fanquake
d919e8d574
Merge bitcoin/bitcoin#26244: build, msvc: Enable C4834 warning
f3e40c481a build, msvc: Enable C4834 warning (Hennadii Stepanov)

Pull request description:

  Since bitcoin/bitcoin#26189 our codebase is  C4834 warning free.

  See https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/c4834.

ACKs for top commit:
  sipsorcery:
    tACK f3e40c481a.

Tree-SHA512: 2dd8fdb5d6c0d4eaf7ffec82039411963010ecea559adfe7e2b5587f467135bd665e0cef5c748e4d6d9ba3c2038d6a5c79980972884adbaaac3bda3b2fbbc408
2022-10-04 21:09:58 +01:00
James O'Beirne
626b7c8493 fuzz: add scanblocks as safe for fuzzing 2022-10-04 13:51:35 -04:00
Jonas Schnelli
94fe5453c7 test: rpc: add scanblocks functional test
Co-authored-by: James O'Beirne <james.obeirne@gmail.com>
2022-10-04 13:51:35 -04:00