* instantsend: Avoid writing IS locks for unknown txes
* instantsend: Allow a competing tx into mempool if there is an islock waiting for it
* use try_emplace
* Hold cs_main while calling ResetBlockFailureFlags
* fix: replace seemingly buggy loop with std::adjacent_find
* Remove redundant variable declaration
* use std::fill instead of a loop
* remove a few raw for loops
* use unique_ptr instead of shared
Signed-off-by: pasta <pasta@dashboost.org>
* unique_ptr over shared_ptr
Signed-off-by: pasta <pasta@dashboost.org>
* remove unneeded ptr
Signed-off-by: pasta <pasta@dashboost.org>
* Adjust IsTxSafeForMining checks
Signed-off-by: pasta <pasta@dashboost.org>
* use const ref
Signed-off-by: pasta <pasta@dashboost.org>
* add a todo
Signed-off-by: pasta <pasta@dashboost.org>
* use optional instead of magic max value
fixes a hypothetical bug where myIdx is not "initialized" (ie max), and we sleep forever
Signed-off-by: pasta <pasta@dashboost.org>
* simplify relay check
Signed-off-by: pasta <pasta@dashboost.org>
* use count_if instead of a loop
Signed-off-by: pasta <pasta@dashboost.org>
* add a few vector reserves
Signed-off-by: pasta <pasta@dashboost.org>
* Handle attempts to read non-existent records from isdb properly
* Do not reject blocks that conflict with islocks while still syncing
Otherwise you can stuck with no new blocks/headers which means you won't be able to verify new chainlocks that might override stored islocks
* Handle duplicates/conflicting islocks better
* More constness
519b0bc5dc5155b6f7e2362c2105552bb7618ad0 Make last disconnected block BLOCK_FAILED_VALID, even when aborted (Pieter Wuille)
8d220417cd7bc34464e28a4861a885193ec091c2 Optimization: don't add txn back to mempool after 10 invalidates (Pieter Wuille)
9ce9c37004440d6a329874dbf66b51666d497dcb Prevent callback overruns in InvalidateBlock and RewindBlockIndex (Pieter Wuille)
9bb32eb571a846b66ed3bac493f55cee11a3a1b9 Release cs_main during InvalidateBlock iterations (Pieter Wuille)
9b1ff5c742dec0a6e0d6aab29b0bb771ad6d8135 Call InvalidateBlock without cs_main held (Pieter Wuille)
241b2c74ac8c4c3000e778554da1271e3f293e5d Make RewindBlockIndex interruptible (Pieter Wuille)
880ce7d46b51835c00d77a366ec28f54a05239df Call RewindBlockIndex without cs_main held (Pieter Wuille)
436f7d735f1c37e77d42ff59d4cbb1bd76d5fcfb Release cs_main during RewindBlockIndex operation (Pieter Wuille)
1d342875c21b5d0a17cf4d176063bb14b35b657e Merge the disconnection and erasing loops in RewindBlockIndex (Pieter Wuille)
32b2696ab4b079db736074b57bbc24deaee0b3d9 Move erasure of non-active blocks to a separate loop in RewindBlockIndex (Pieter Wuille)
9d6dcc52c6cb0cdcda220fddccaabb0ffd40068d Abstract EraseBlockData out of RewindBlockIndex (Pieter Wuille)
Pull request description:
This PR makes a number of improvements to the InvalidateBlock (`invalidateblock` RPC) and RewindBlockIndex functions, primarily around breaking up their long-term cs_main holding. In addition:
* They're made safely interruptible (`bitcoind` can be shutdown, and no progress in either will be lost, though if incomplete, `invalidateblock` won't continue after restart and will need to be called again)
* The validation queue is prevented from overflowing (meaning `invalidateblock` on a very old block will not drive bitcoind OOM) (see #14289).
* `invalidateblock` won't bother to move transactions back into the mempool after 10 blocks (optimization).
This is not an optimal solution, as we're relying on the scheduler call sites to make sure the scheduler doesn't overflow. Ideally, the scheduler would guarantee this directly, but that needs a few further changes (moving the signal emissions out of cs_main) to prevent deadlocks.
I have manually tested the `invalidateblock` changes (including interrupting, and running with -checkblockindex and -checkmempool), but haven't tried the rewinding (which is probably becoming increasingly unnecessary, as very few pre-0.13.1 nodes remain that would care to upgrade).
Tree-SHA512: 692e42758bd3d3efc2eb701984a8cb5db25fbeee32e7575df0183a00d0c2c30fdf72ce64c7625c32ad8c8bdc56313da72a7471658faeb0d39eefe39c4b8b8474
* replace raw owning ptr with unique ptr
Signed-off-by: pasta <pasta@dashboost.org>
* Add GUARDED_BY annotation to llmq_versionbitscache
Signed-off-by: pasta <pasta@dashboost.org>
* limit scope of locking cs_llmq_vbc
Signed-off-by: pasta <pasta@dashboost.org>
* use llmq_versionbitscache instead of versionbitscache in UpdatedBlockTip to avoid cs_main locking
Signed-off-by: pasta <pasta@dashboost.org>
* drop unneeded cs_main ::mempool.cs
* lock cs_main and mempool.cs in Db::Upgrade
* include adjustments
* fix macOs build failure
Signed-off-by: pasta <pasta@dashboost.org>
* expcitly include array in spork.h
* sort includes in most files
* merge bitcoin#15855: Add missing LockAnnotation for cs_main
* mutex: update cs_main locks, assertions and annotations
This commit is a squash between 8c98823 and 90d0535
bf2e01097 uint256: Remove unnecessary crypto/common.h use (Karl-Johan Alm)
Pull request description:
This is an alternative to #13242 which keeps the `ReadLE64` part, but moves the `crypto/common.h` dependency into `crypto/common.h` as a function outside of `uint256`.
**Reason:** this change will remove dependencies for `uint256` to `crypto/common.h`, `compat/endian.h`, and `compat/byteswap.h`.
This PR removes the need to update tests to be endian-aware/-independent, but keeps the (arguably dubious) `ReadLE64` part (which was only introduced to fix the tests, not for any functionality).
Tree-SHA512: 78b35123cdb185b3b3ec59aba5ca8a5db72624d147f2d6a5484ffa5ce626a72f782a01dc6893fc8f5619b03e2eae7b5a03b0df5d43460f3bda428e719e188aec
* refactor: introduce PendingSignatureData
* refactor: explicitly capture in lambdas
* refactor: use structured bindings
* refactor: use more const
* refactor: remove unused include header
* refactor: use if-init
* refactor: add nodiscard
* refactor: initialize llmqType
* refactor: add override
* refactor: remove redundant specifiers
* refactor: prevent shadowing
* refactor: use try_emplace where possible
* refactor: use more accurate name
string_view is needed for compile time interpretation (constexpr) of the LLMQParams
constexpr is good to add such that we aren't initializing in static scope, but instead at compile time
Sadly using string_view will require that we construct a std::string when passing into univalue, however, this isn't in a performance important section (rpc) and as such another allocation is an okay trade off for the benefits of constexpr
Also, now we aren't having extern variables, which should make the linker mildly happier
Signed-off-by: pasta <pasta@dashboost.org>
When receiving an islock, propagate it as islock.
When creating/receiving and isdlock, propagate it as isdlock to peers which support it and as islock to peers which don't.
Functional tests to cover both islock and isdlock scenarios.
* bls: use constexpr int instead of #define
* lint: bump c++ version to 17
* test: use BOOST_CHECK_EQUAL instead of BOOST_ASSERT, call boost assert in another location
* coinjoin: fix typo
* drop redundant LLMQType cast
* use numeric_limits instead of magic value
* net_processing.cpp whitespace fixes
* Add some const
* use std::all_of instead of raw for loop
* Introduce UNINITIALIZED_SESSION_ID and use it instead of a magic number
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
* Don't lock instantsend cs where not needed (db interactions)
* Introduce cs_db to CInstantSendDb
All private members are GUARDED_BY or EXCLUSIVE_LOCKS_REQUIRED w/ cs_db
All public functions lock cs_db immediately
* adjust cs usage a bit more in CInstantSendManager
* Use WITH_LOCK in a few spots
* Make AddNonLockedTx lock internally instead of externally
* instantsend adjust formatting
* instantsend move IsInstantSendEnabled enabled check up
This backport does not include changes that depend on bitcoin pr 18037
70a6b529f306ff72ea1badf25e970a92b2b17ab3 lint-cppcheck: Remove -DHAVE_WORKING_BOOST_SLEEP_FOR (Anthony Towns)
294937b39de5924e772f8ed90d35c53290c8acab scheduler_tests: re-enable mockforward test (Anthony Towns)
cea19f685915be8affb2203184a549576194413f Drop unused reverselock.h (Anthony Towns)
d0ebd93270758ea97ea956b8821e17a2d001ea94 scheduler: switch from boost to std (Anthony Towns)
b9c426012770d166e6ebfab27689be44e6e89aa5 sync.h: add REVERSE_LOCK (Anthony Towns)
306f71b4eb4a0fd8e64f47dc008bc235b80b13d9 scheduler: don't rely on boost interrupt on shutdown (Anthony Towns)
Pull request description:
Replacing boost functionality with C++11 stuff.
Motivated by #18227, but should stand alone. Changing from `boost::condition_var` to `std::condition_var` means `threadGroup.interrupt_all` isn't enough to interrupt `serviceQueue` anymore, so that means calling `stop()` before `join_all()` is needed. And the existing reverselock.h code doesn't work with sync.h's DebugLock code (because the reversed lock won't be removed from `g_lockstack` which then leads to incorrect potential deadlock warnings), so I've replaced that with a dedicated class and macro that's aware of our debug lock behaviour.
Fixes#16027, Fixes#14200, Fixes#18227
ACKs for top commit:
laanwj:
ACK 70a6b529f306ff72ea1badf25e970a92b2b17ab3
Tree-SHA512: d1da13adeabcf9186d114e2dad9a4fdbe2e440f7afbccde0c13dfbaf464efcd850b69d3371c5bf8b179d7ceb9d81f4af3cc22960b90834e41eaaf6d52ef7d331
# Conflicts:
# src/reverselock.h
# src/rpc/misc.cpp
# src/scheduler.cpp
# src/scheduler.h
# src/sync.cpp
# src/sync.h
# src/test/reverselock_tests.cpp
# src/test/scheduler_tests.cpp
# src/test/test_dash.cpp
# test/lint/extended-lint-cppcheck.sh
* Avoid locking cs_main before logging, instead log, then lock where possible
* use WITH_LOCK in a number of locations as a replacement of simple scopes
* add EXCLUSIVE_LOCKS_REQUIRED
* minimize locked scope in rpc
* fix macOS build error
Signed-off-by: pasta <pasta@dashboost.org>
* add missing EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Signed-off-by: pasta <pasta@dashboost.org>
* revert an rpc scope reduction
* revert an rpc scope reduction
77777c5624 log: Construct global logger on first use (MarcoFalke)
Pull request description:
The (de)initialization order is not well defined in C++, so generally it is not safe to use globals as the (de/con)structor of one global could use the (de/con)structor of another global before/after it has been (con/de)structed.
Specifically this fixes:
* `g_logger` might not be initialized on the first use, so do that. (Fixes#15111)
Tree-SHA512: eb9c22f4baf31ebc5b0b9ee6a51d1354bae1f0df186cc0ce818b4483c7b5a7f90268d2b549ee96b4c57f8ef36ab239dc6497f74f3e2ef166038f7437c368297d
* refactor: Add `const` qualifier to various llmq related functions
* refactor: Add thread safety annotations to various llmq related functions
And around them where it's required
Fixes
```
POTENTIAL DEADLOCK DETECTED
Previous lock order was:
(1) cs llmq/quorums_instantsend.cpp:1071 (in thread )
(2) cs_main llmq/quorums_instantsend.cpp:1405 (in thread )
Current lock order is:
(2) cs_main net_processing.cpp:2535 (in thread )
(1) cs llmq/quorums_instantsend.cpp:1559 (in thread )
```
* Merge #13743: refactor: Replace boost::bind with std::bind
cb53b825c2 scripted-diff: Replace boost::bind with std::bind (Chun Kuan Lee)
2196c51821 refactor: Use boost::scoped_connection in signal/slot, also prefer range-based loop instead of std::transform (Chun Kuan Lee)
Pull request description:
Replace boost::bind with std::bind
- In `src/rpc/server.cpp`, replace `std::transform` with simple loop.
- In `src/validation.cpp`, store the `boost::signals2::connection` object and use it to disconnect.
- In `src/validationinterface.cpp`, use 2 map to store the `boost::signals2::scoped_connection` object.
Tree-SHA512: 6653cbe00036fecfc495340618efcba6d7be0227c752b37b81a27184433330f817e8de9257774e9b35828026cb55f11ee7f17d6c388aebe22c4a3df13b5092f0
* Replace boost::bind with std::bind and remove Boost.Bind includes
Co-authored-by: MarcoFalke <falke.marco@gmail.com>
* llmq: Split "isdb" out of "llmq" db
We write and erase islocks a lot. It probably makes sense to have a standalone db with a larger cache for this.
* llmq: Split "recsigdb" out of "llmq" db
* llmq: Migrate recovered sigs
* llmq: Split "dkgdb" out of "llmq" db
* llmq: Migrate DKG db
* llmq: Wipe llmq