bitcoin/src
fanquake e9035f867a
Merge bitcoin/bitcoin#25717: p2p: Implement anti-DoS headers sync
3add234546 ui: show header pre-synchronization progress (Pieter Wuille)
738421c50f Emit NotifyHeaderTip signals for pre-synchronization progress (Pieter Wuille)
376086fc5a Make validation interface capable of signalling header presync (Pieter Wuille)
93eae27031 Test large reorgs with headerssync logic (Suhas Daftuar)
355547334f Track headers presync progress and log it (Pieter Wuille)
03712dddfb Expose HeadersSyncState::m_current_height in getpeerinfo() (Suhas Daftuar)
150a5486db Test headers sync using minchainwork threshold (Suhas Daftuar)
0b6aa826b5 Add unit test for HeadersSyncState (Suhas Daftuar)
83c6a0c524 Reduce spurious messages during headers sync (Suhas Daftuar)
ed6cddd98e Require callers of AcceptBlockHeader() to perform anti-dos checks (Suhas Daftuar)
551a8d957c Utilize anti-DoS headers download strategy (Suhas Daftuar)
ed470940cd Add functions to construct locators without CChain (Pieter Wuille)
84852bb6bb Add bitdeque, an std::deque<bool> analogue that does bit packing. (Pieter Wuille)
1d4cfa4272 Add function to validate difficulty changes (Suhas Daftuar)

Pull request description:

  New nodes starting up for the first time lack protection against DoS from low-difficulty headers. While checkpoints serve as our protection against headers that fork from the main chain below the known checkpointed values, this protection only applies to nodes that have been able to download the honest chain to the checkpointed heights.

  We can protect all nodes from DoS from low-difficulty headers by adopting a different strategy: before we commit to storing a header in permanent storage, first verify that the header is part of a chain that has sufficiently high work (either `nMinimumChainWork`, or something comparable to our tip). This means that we will download headers from a given peer twice: once to verify the work on the chain, and a second time when permanently storing the headers.

  The p2p protocol doesn't provide an easy way for us to ensure that we receive the same headers during the second download of peer's headers chain. To ensure that a peer doesn't (say) give us the main chain in phase 1 to trick us into permanently storing an alternate, low-work chain in phase 2, we store commitments to the headers during our first download, which we validate in the second download.

  Some parameters must be chosen for commitment size/frequency in phase 1, and validation of commitments in phase 2. In this PR, those parameters are chosen to both (a) minimize the per-peer memory usage that an attacker could utilize, and (b) bound the expected amount of permanent memory that an attacker could get us to use to be well-below the memory growth that we'd get from the honest chain (where we expect 1 new block header every 10 minutes).

  After this PR, we should be able to remove checkpoints from our code, which is a nice philosophical change for us to make as well, as there has been confusion over the years about the role checkpoints play in Bitcoin's consensus algorithm.

  Thanks to Pieter Wuille for collaborating on this design.

ACKs for top commit:
  Sjors:
    re-tACK 3add234546
  mzumsande:
    re-ACK 3add234546
  sipa:
    re-ACK 3add234546
  glozow:
    ACK 3add234546

Tree-SHA512: e7789d65f62f72141b8899eb4a2fb3d0621278394d2d7adaa004675250118f89a4e4cb42777fe56649d744ec445ad95141e10f6def65f0a58b7b35b2e654a875
2022-08-30 15:37:59 +01:00
..
bench Merge bitcoin/bitcoin#25734: wallet, refactor: #24584 follow-ups 2022-08-16 20:00:19 -04:00
common
compat compat: document redefining ssize_t when using MSVC 2022-07-20 13:10:12 +01:00
config
consensus Require callers of AcceptBlockHeader() to perform anti-dos checks 2022-08-29 08:10:35 -04:00
crc32c Update crc32c subtree to latest upstream master 2022-08-13 13:55:38 +01:00
crypto Use HashWriter where possible 2022-07-20 15:34:36 +02:00
index Merge bitcoin/bitcoin#22485: doc: BaseIndex sync behavior with empty datadir 2022-07-21 19:54:18 +02:00
init Merge bitcoin/bitcoin#24675: util: Use ArgsManager::GetPathArg more widely 2022-08-04 16:58:01 +01:00
interfaces Make validation interface capable of signalling header presync 2022-08-29 08:10:35 -04:00
ipc
kernel Make adjusted time type safe 2022-08-05 14:59:15 +02:00
leveldb Update leveldb-subtree subtree to latest upstream 2022-07-29 14:43:11 +01:00
logging
minisketch Update minisketch subtree to latest master 2022-06-29 16:35:02 +01:00
node Make validation interface capable of signalling header presync 2022-08-29 08:10:35 -04:00
policy fixups for BIP125 doc cleanup 2022-08-22 14:59:58 +01:00
primitives Add time helpers 2022-08-05 14:45:02 +02:00
qt ui: show header pre-synchronization progress 2022-08-29 08:10:35 -04:00
rpc Expose HeadersSyncState::m_current_height in getpeerinfo() 2022-08-29 08:10:35 -04:00
script Make DUMMY_CHECKER availble outside of script/sign.cpp 2022-08-19 14:37:36 -04:00
secp256k1 Update secp256k1 subtree to latest upstream master 2022-06-11 14:55:18 +01:00
support build: globally define NOMINMAX 2022-06-20 12:22:05 +01:00
test Merge bitcoin/bitcoin#25717: p2p: Implement anti-DoS headers sync 2022-08-30 15:37:59 +01:00
univalue univalue: Remove unused and confusing set*() return value 2022-07-29 15:24:42 +02:00
util Merge bitcoin/bitcoin#25717: p2p: Implement anti-DoS headers sync 2022-08-30 15:37:59 +01:00
wallet Merge bitcoin/bitcoin#25922: wallet: trigger MaybeResendWalletTxs() every minute 2022-08-26 17:11:17 -04:00
zmq scripted-diff: remove duplicate categories from LogPrint output 2022-06-06 12:12:03 +02:00
.bear-tidy-config
.clang-format
.clang-tidy tidy: Enable two clang-tidy checks 2022-08-03 17:18:17 +02:00
addrdb.cpp
addrdb.h
addrman_impl.h addrman: Use system time instead of adjusted network time 2022-07-30 11:04:09 +02:00
addrman.cpp addrman: Use system time instead of adjusted network time 2022-07-30 11:04:09 +02:00
addrman.h addrman: Use system time instead of adjusted network time 2022-07-30 11:04:09 +02:00
arith_uint256.cpp
arith_uint256.h
attributes.h
banman.cpp scripted-diff: Avoid incompatibility with CMake AUTOUIC feature 2022-06-14 10:38:51 +02:00
banman.h
base58.cpp
base58.h
bech32.cpp
bech32.h
bitcoin-chainstate.cpp Require callers of AcceptBlockHeader() to perform anti-dos checks 2022-08-29 08:10:35 -04:00
bitcoin-cli-res.rc
bitcoin-cli.cpp Merge bitcoin/bitcoin#25707: refactor: Make const references to avoid unnecessarily copying objects and enable two clang-tidy checks 2022-08-19 17:11:06 +02:00
bitcoin-tx-res.rc
bitcoin-tx.cpp refactor: Make const refs vars where applicable 2022-07-27 13:27:57 +02:00
bitcoin-util-res.rc
bitcoin-util.cpp refactor: move compat.h into compat/ 2022-07-20 10:34:46 +01:00
bitcoin-wallet-res.rc
bitcoin-wallet.cpp refactor: move compat.h into compat/ 2022-07-20 10:34:46 +01:00
bitcoind-res.rc
bitcoind.cpp refactor: move compat.h into compat/ 2022-07-20 10:34:46 +01:00
blockencodings.cpp
blockencodings.h
blockfilter.cpp Use new Join() helper for ListBlockFilterTypes() 2022-08-24 10:15:32 +02:00
blockfilter.h
chain.cpp Add functions to construct locators without CChain 2022-08-23 16:05:00 -04:00
chain.h Add functions to construct locators without CChain 2022-08-23 16:05:00 -04:00
chainparams.cpp Use HashWriter where possible 2022-07-20 15:34:36 +02:00
chainparams.h
chainparamsbase.cpp
chainparamsbase.h
chainparamsseeds.h net: update hardcoded mainnet seeds for 24.x 2022-08-24 00:04:00 +02:00
checkqueue.h
clientversion.cpp
clientversion.h
coins.cpp Merge bitcoin/bitcoin#25707: refactor: Make const references to avoid unnecessarily copying objects and enable two clang-tidy checks 2022-08-19 17:11:06 +02:00
coins.h refactor: remove unused methods {CDBIterator,CCoinsViewDBCursor}::GetValueSize() 2022-06-21 16:19:10 +02:00
compressor.cpp
compressor.h
core_io.h
core_memusage.h
core_read.cpp refactor: Make const refs vars where applicable 2022-07-27 13:27:57 +02:00
core_write.cpp
cuckoocache.h validationcaches: Use size_t for sizes 2022-08-03 12:03:28 -04:00
dbwrapper.cpp Remove unused includes from dbwrapper.h 2022-07-19 14:32:53 +02:00
dbwrapper.h Remove unused includes from dbwrapper.h 2022-07-19 14:32:53 +02:00
deploymentinfo.cpp
deploymentinfo.h
deploymentstatus.cpp
deploymentstatus.h
dummywallet.cpp
external_signer.cpp refactor: Make const refs vars where applicable 2022-07-27 13:27:57 +02:00
external_signer.h
flatfile.cpp
flatfile.h
fs.cpp build: globally define NOMINMAX 2022-06-20 12:22:05 +01:00
fs.h fs: work around u8path deprecated-declaration warnings with libc++ 2022-08-19 08:58:56 +01:00
hash.cpp Use HashWriter where possible 2022-07-20 15:34:36 +02:00
hash.h Use HashWriter where possible 2022-07-20 15:34:36 +02:00
headerssync.cpp Utilize anti-DoS headers download strategy 2022-08-29 08:10:35 -04:00
headerssync.h Track headers presync progress and log it 2022-08-29 08:10:35 -04:00
httprpc.cpp
httprpc.h
httpserver.cpp refactor: move compat.h into compat/ 2022-07-20 10:34:46 +01:00
httpserver.h
i2p.cpp i2p: log "SAM session" instead of "session" 2022-08-16 13:02:21 +02:00
i2p.h i2p: add support for creating transient sessions 2022-08-11 17:51:18 +02:00
indirectmap.h
init.cpp Merge bitcoin/bitcoin#25775: docs: remove non-signaling mentions of BIP125 2022-08-22 10:35:26 +01:00
init.h Move init::SanityCheck to kernel::SanityCheck 2022-06-02 11:42:12 -04:00
key_io.cpp
key_io.h
key.cpp extended keys: fail to derive too large depth instead of wrapping around 2022-08-04 11:32:26 +02:00
key.h (pubk)key: mark Derive() as nodiscard 2022-08-04 11:32:25 +02:00
logging.cpp Utilize anti-DoS headers download strategy 2022-08-29 08:10:35 -04:00
logging.h Utilize anti-DoS headers download strategy 2022-08-29 08:10:35 -04:00
Makefile.am Utilize anti-DoS headers download strategy 2022-08-29 08:10:35 -04:00
Makefile.bench.include Merge bitcoin/bitcoin#25785: bench: Add a benchmark for descriptor expansion 2022-08-12 13:00:06 +02:00
Makefile.crc32c.include
Makefile.leveldb.include Use more specific path when including memenv.h header 2022-06-23 15:33:01 +02:00
Makefile.minisketch.include
Makefile.qt_locale.include
Makefile.qt.include qt, refactor: Add transactionoverviewwidget.cpp source file 2022-06-14 16:55:22 +02:00
Makefile.qttest.include
Makefile.test_fuzz.include test/fuzz: Invoke LoadMempool via CChainState 2022-07-15 12:26:00 -04:00
Makefile.test_util.include
Makefile.test.include Add unit test for HeadersSyncState 2022-08-29 08:10:35 -04:00
Makefile.univalue.include
mapport.cpp refactor: move compat.h into compat/ 2022-07-20 10:34:46 +01:00
mapport.h
memusage.h
merkleblock.cpp
merkleblock.h
net_permissions.cpp
net_permissions.h
net_processing.cpp Merge bitcoin/bitcoin#25717: p2p: Implement anti-DoS headers sync 2022-08-30 15:37:59 +01:00
net_processing.h Expose HeadersSyncState::m_current_height in getpeerinfo() 2022-08-29 08:10:35 -04:00
net_types.cpp
net_types.h
net.cpp net: mark CNode unique_ptr members as const 2022-08-29 22:50:54 +10:00
net.h net: note CNode members that are treated as const 2022-08-29 22:50:54 +10:00
netaddress.cpp
netaddress.h refactor: move compat.h into compat/ 2022-07-20 10:34:46 +01:00
netbase.cpp refactor: Make const refs vars where applicable 2022-07-27 13:27:57 +02:00
netbase.h refactor: move compat.h into compat/ 2022-07-20 10:34:46 +01:00
netgroup.cpp
netgroup.h
netmessagemaker.h
noui.cpp scripted-diff: Avoid incompatibility with CMake AUTOUIC feature 2022-06-14 10:38:51 +02:00
noui.h
outputtype.cpp Merge bitcoin/bitcoin#25734: wallet, refactor: #24584 follow-ups 2022-08-16 20:00:19 -04:00
outputtype.h wallet: remove UNKNOWN type from OUTPUT_TYPES array 2022-08-18 16:47:15 -03:00
pow.cpp Add function to validate difficulty changes 2022-08-23 11:34:10 -04:00
pow.h Add function to validate difficulty changes 2022-08-23 11:34:10 -04:00
prevector.h
protocol.cpp refactor: use strprintf for creating unknown-service-flag string 2022-08-20 15:11:28 +02:00
protocol.h refactor: Use type-safe std::chrono for addrman time 2022-07-26 11:06:10 +02:00
psbt.cpp psbt: Implement merge for Taproot fields 2022-06-27 16:47:48 -04:00
psbt.h psbt: Avoid unsigned int overflow in PSBT_IN_TAP_BIP32_DERIVATION 2022-08-10 11:58:17 -04:00
pubkey.cpp Merge bitcoin/bitcoin#25642: Don't wrap around when deriving an extended key at a too large depth 2022-08-10 14:25:43 -04:00
pubkey.h (pubk)key: mark Derive() as nodiscard 2022-08-04 11:32:25 +02:00
random.cpp refactor: move compat.h into compat/ 2022-07-20 10:34:46 +01:00
random.h refactor: Make FEELER_SLEEP_WINDOW type safe (std::chrono) 2022-07-13 15:21:12 +02:00
randomenv.cpp refactor: move compat.h into compat/ 2022-07-20 10:34:46 +01:00
randomenv.h
rest.cpp Fix logical race in rest_getutxos 2022-08-16 17:26:28 +02:00
rest.h
reverse_iterator.h
scheduler.cpp
scheduler.h
serialize.h Add ChronoFormatter to serialize 2022-07-26 11:05:04 +02:00
shutdown.cpp scripted-diff: Avoid incompatibility with CMake AUTOUIC feature 2022-06-14 10:38:51 +02:00
shutdown.h
signet.cpp
signet.h
span.h
streams.h streams: Add AutoFile without ser-type and ser-version 2022-06-29 10:31:53 +02:00
sync.cpp
sync.h
threadinterrupt.cpp Expose underlying clock in CThreadInterrupt 2022-07-13 15:20:49 +02:00
threadinterrupt.h Expose underlying clock in CThreadInterrupt 2022-07-13 15:20:49 +02:00
threadsafety.h
timedata.cpp Make adjusted time type safe 2022-08-05 14:59:15 +02:00
timedata.h Make adjusted time type safe 2022-08-05 14:59:15 +02:00
tinyformat.h
torcontrol.cpp refactor: move compat.h into compat/ 2022-07-20 10:34:46 +01:00
torcontrol.h
txdb.cpp CDiskBlockIndex: rename GetBlockHash() to ConstructBlockHash() 2022-07-22 12:45:07 +02:00
txdb.h Add missing includes 2022-07-19 14:12:33 +02:00
txmempool.cpp Remove ::g_max_datacarrier_bytes global 2022-08-02 15:29:16 +02:00
txmempool.h [doc] remove non-signaling mentions of BIP125 2022-08-04 16:56:33 +01:00
txorphanage.cpp refactor: log nEvicted message in LimitOrphans then return void 2022-07-28 14:39:45 +08:00
txorphanage.h refactor: log nEvicted message in LimitOrphans then return void 2022-07-28 14:39:45 +08:00
txrequest.cpp
txrequest.h
uint256.cpp
uint256.h
undo.h
validation.cpp Merge bitcoin/bitcoin#25717: p2p: Implement anti-DoS headers sync 2022-08-30 15:37:59 +01:00
validation.h Merge bitcoin/bitcoin#25717: p2p: Implement anti-DoS headers sync 2022-08-30 15:37:59 +01:00
validationinterface.cpp
validationinterface.h
version.h
versionbits.cpp
versionbits.h
walletinitinterface.h
warnings.cpp
warnings.h