Add function to validate difficulty changes
The rule against difficulty adjustments changing by more than a factor of 4 can
be helpful for anti-DoS measures in contexts where we lack a full headers
chain, so expose this functionality separately and in the narrow case where we
only know the height, new value, and old value.
https://github.com/bitcoin/bitcoin/pull/25717/commits/84852bb6bb3579e475ce78fe729fd125ddbc715f
TODO: add similar rules for the various newerDAA algorithms
Add bitdeque, an std::deque<bool> analogue that does bit packing.
https://github.com/bitcoin/bitcoin/pull/25717/commits/84852bb6bb3579e475ce78fe729fd125ddbc715f
Add functions to construct locators without CChain
This introduces an insignificant performance penalty, as it means locator
construction needs to use the skiplist-based CBlockIndex::GetAncestor()
function instead of the lookup-based CChain, but avoids the need for
callers to have access to a relevant CChain object.
https://github.com/bitcoin/bitcoin/pull/25717/commits/ed470940cddbeb40425960d51cefeec4948febe4
Utilize anti-DoS headers download strategy
Avoid permanently storing headers from a peer, unless the headers are part of a
chain with sufficiently high work. This prevents memory attacks using low-work
headers.
Designed and co-authored with Pieter Wuille.
https://github.com/bitcoin/bitcoin/pull/25717/commits/551a8d957c4c44afbd0d608fcdf7c6a4352babce
https://github.com/bitcoin/bitcoin/pull/25960/commits/132ed7eaaa4a47ab94db72ebfab0ef0e03caa488 (use NET logging category)
https://github.com/bitcoin/bitcoin/pull/26172/commits/bdcafb913398f0cdaff9c880618f9ebfc85c7693 (bugfix)
Notes:
- SaltedBlockHashHasher was added because it didn't seem right to use SaltedTxidHasher. In practice, they all do the same as the generic SaltedUInt256Hasher.
- I made the "Initial headers sync aborted..." log messages unconditional instead of logging into the NET category. They should not be printed very often, and it is valuable information for debugging from logs shared by users. Without this, we would have to guess the problematic block height from the headersync percentage (logged only once every 2000 blocks).
Require callers of AcceptBlockHeader() to perform anti-dos checks
In order to prevent memory DoS, we must ensure that we don't accept a new
header into memory until we've performed anti-DoS checks, such as verifying
that the header is part of a sufficiently high work chain. This commit adds a
new argument to AcceptBlockHeader() so that we can ensure that all call-sites
which might cause a new header to be accepted into memory have to grapple with
the question of whether the header is safe to accept, or needs further
validation.
This patch also fixes two places where low-difficulty-headers could have been
processed without such validation (processing an unrequested block from the
network, and processing a compact block).
Credit to Niklas Gögge for noticing this issue, and thanks to Sjors Provoost
for test code.
https://github.com/bitcoin/bitcoin/pull/25717/commits/ed6cddd98e32263fc116a4380af6d66da20da990
Reduce spurious messages during headers sync
Delay sending SENDHEADERS (BIP 130) message until we know our peer's best
header's chain has more than nMinimumChainWork. This reduces inadvertent
headers messages received during initial headers sync due to block
announcements, which throw off our sync algorithm.
https://github.com/bitcoin/bitcoin/pull/25717/commits/83c6a0c5249c4ecbd11f7828c84a50fb473faba3
Add unit test for HeadersSyncState
https://github.com/bitcoin/bitcoin/pull/25717/commits/0b6aa826b53470c9cc8ef4a153fa710dce80882f
Test headers sync using minchainwork threshold
https://github.com/bitcoin/bitcoin/pull/25717/commits/150a5486db50ff77c91765392149000029c8a309
Expose HeadersSyncState::m_current_height in getpeerinfo()
https://github.com/bitcoin/bitcoin/pull/25717/commits/03712dddfbb9fe0dc7a2ead53c65106189f5c803
Track headers presync progress and log it
https://github.com/bitcoin/bitcoin/pull/25717/commits/355547334f7d08640ee1fa291227356d61145d1a
Test large reorgs with headerssync logic
https://github.com/bitcoin/bitcoin/pull/25717/commits/376086fc5a187f5b2ab3a0d1202ed4e6c22bdb50
Make validation interface capable of signalling header presync
This makes a number of changes:
- Get rid of the verification_progress argument in the node interface NotifyHeaderTip (it was always 0.0).
- Instead of passing a CBlockIndex* in the UI interface's NotifyHeaderTip, send separate height, timestamp fields. This is becuase in headers presync, no actual CBlockIndex object is available.
- Add a bool presync argument to both of the above, to identify signals pertaining to the first headers sync phase.
https://github.com/bitcoin/bitcoin/pull/25717/commits/376086fc5a187f5b2ab3a0d1202ed4e6c22bdb50
TODO: backport core-gui#581 and fix clientmodel.cpp
Emit NotifyHeaderTip signals for pre-synchronization progress
https://github.com/bitcoin/bitcoin/pull/25717/commits/738421c50f2dbd7395b50a5dbdf6168b07435e62