bitcoin/src/bench
Ryan Ofsky 2f53f2273d
Merge bitcoin/bitcoin#29975: blockstorage: Separate reindexing from saving new blocks
e41667b720 blockstorage: Don't move cursor backwards in UpdateBlockInfo (Ryan Ofsky)
17103637c6 blockstorage: Rename FindBlockPos and have it return a FlatFilePos (Martin Zumsande)
d9e477c4dc validation, blockstorage: Separate code paths for reindex and saving new blocks (Martin Zumsande)
064859bbad blockstorage: split up FindBlockPos function (Martin Zumsande)
fdae638e83 doc: Improve doc for functions involved in saving blocks to disk (Martin Zumsande)
0d114e3cb2 blockstorage: Add Assume for fKnown / snapshot chainstate (Martin Zumsande)

Pull request description:

  `SaveBlockToDisk` / `FindBlockPos` are used for two purposes, depending on whether they are called during reindexing (`dbp` set,  `fKnown = true`) or in the "normal" case when adding new blocks (`dbp == nullptr`,  `fKnown = false`).
  The actual tasks are quite different
  - In normal mode, preparations for saving a new block are made, which is then saved: find the correct position on disk (maybe skipping to a new blk file), check for available disk space, update the blockfile info db, save the block.
  - during reindex, most of this is not necessary (the block is already on disk after all), only the blockfile info needs to rebuilt because reindex wiped the leveldb it's saved in.

  Using one function with many conditional statements for this leads to code that is hard to read / understand and bug-prone:
  - many code paths in `FindBlockPos` are conditional on `fKnown` or `!fKnown`
  - It's not really clear what actually needs to be done during reindex (we don't need to "save a block to disk" or "find a block pos" as the function names suggest)
  - logic that should be applied to only one of the two modes is sometimes applied to both (see first commit, or #27039)

  #24858 and #27039 were recent bugs directly related to the differences between reindexing and normal mode, and in both cases the simple fix took a long time to be reviewed and merged.

  This PR proposes to clean this code up by splitting out the reindex logic into a separate function (`UpdateBlockInfo`) which will be called directly from validation. As a result, `SaveBlockToDisk` and `FindBlockPos` only need to cover the non-reindex logic.

ACKs for top commit:
  paplorinc:
    ACK e41667b720
  TheCharlatan:
    Re-ACK e41667b720
  ryanofsky:
    Code review ACK e41667b720. Just improvements to comments since last review.

Tree-SHA512: a14ff9a0facf6b1e3c1cd724a2d19a79a25d4b48de64398fdd172671532a472bc10a20cbb64ac3a3e55814dcc877d0597a3e1699cabc4f9d9a86b439b6eaba20
2024-05-16 11:16:08 -04:00
..
data Add deserialize + CheckBlock benchmarks, and a full block hex 2016-11-09 11:27:59 -08:00
.gitignore Ignore bench_bitcoin binary. 2015-10-06 17:46:12 +02:00
addrman.cpp p2p, refactor: return `std::optional<CNetAddr>` in `LookupHost` 2023-05-26 13:41:07 -03:00
base58.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
bech32.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
bench.cpp test: test_bitcoin: allow -testdatadir=<datadir> 2024-03-07 10:11:45 -07:00
bench.h Extract util::Xor, Add key_offset option, Add bench 2023-07-12 09:59:55 +02:00
bench_bitcoin.cpp move-only: Extract common/args and common/config.cpp from util/system 2023-04-19 10:48:30 +02:00
bip324_ecdh.cpp test: Use ECC_Context helper in bench and fuzz tests 2024-05-09 15:56:04 +02:00
block_assemble.cpp tidy: modernize-use-emplace 2023-10-12 11:27:19 +02:00
ccoins_caching.cpp test: Use ECC_Context helper in bench and fuzz tests 2024-05-09 15:56:04 +02:00
chacha20.cpp crypto: refactor ChaCha20 classes to use Span<std::byte> interface 2023-08-17 15:26:34 -04:00
checkblock.cpp Convert some CDataStream to DataStream 2023-11-16 11:14:13 +10:00
checkqueue.cpp test: Use ECC_Context helper in bench and fuzz tests 2024-05-09 15:56:04 +02:00
coin_selection.cpp Amend bumpfee for inputs with overlapping ancestry 2023-09-13 15:46:59 -04:00
crypto_hash.cpp bench: Add SHA256 implementation specific benchmarks 2023-09-20 21:12:00 +01:00
data.cpp scripted-diff: Bump copyright headers 2021-12-30 19:36:57 +02:00
data.h bench: Move generated data to a dedicated translation unit 2019-07-02 18:11:15 +01:00
descriptors.cpp test: Use ECC_Context helper in bench and fuzz tests 2024-05-09 15:56:04 +02:00
disconnected_transactions.cpp Use Txid in COutpoint 2023-11-21 13:15:44 +00:00
duplicate_inputs.cpp Use Txid in COutpoint 2023-11-21 13:15:44 +00:00
ellswift.cpp test: Use ECC_Context helper in bench and fuzz tests 2024-05-09 15:56:04 +02:00
examples.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
gcs_filter.cpp Fix clang-tidy readability-const-return-type violations 2023-02-01 11:33:35 +01:00
hashpadding.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
index_blockfilter.cpp bench: basic block filter index initial sync 2024-03-12 09:30:42 -03:00
load_external.cpp refactor: switch from CAutoFile to AutoFile 2023-11-18 03:01:41 +10:00
lockedpool.cpp clang-tidy: Add `performance-inefficient-vector-operation` check 2023-03-26 20:17:55 +01:00
logging.cpp refactor: Replace string chain name constants with ChainTypes 2023-05-09 15:49:14 +02:00
mempool_eviction.cpp mempool_entry: add mempool entry sequence number 2023-08-03 13:42:45 +10:00
mempool_stress.cpp Use Txid in COutpoint 2023-11-21 13:15:44 +00:00
merkle_root.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
nanobench.cpp Replace current benchmarking framework with nanobench 2020-06-13 12:24:18 +02:00
nanobench.h bench: Update nanobench to 4.3.11 2023-11-14 20:22:12 +01:00
parse_hex.cpp Add benchmark for TryParseHex 2024-02-28 17:23:54 +00:00
peer_eviction.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
poly1305.cpp Switch all callers from poly1305_auth to Poly1305 class 2023-07-12 22:43:55 -04:00
pool.cpp pool: make sure PoolAllocator uses the correct alignment 2023-11-19 18:43:29 +01:00
prevector.cpp bench: Add benchmark for prevector usage in std::vector 2023-03-26 15:49:41 +02:00
readblock.cpp validation, blockstorage: Separate code paths for reindex and saving new blocks 2024-05-14 14:54:27 -04:00
rollingbloom.cpp scripted-diff: Bump copyright headers 2022-12-24 23:49:50 +00:00
rpc_blockchain.cpp refactor: rpc: Pass CBlockIndex by reference instead of pointer 2023-12-07 12:05:21 +01:00
rpc_mempool.cpp mempool_entry: add mempool entry sequence number 2023-08-03 13:42:45 +10:00
streams_findbyte.cpp refactor: switch from CAutoFile to AutoFile 2023-11-18 03:01:41 +10:00
strencodings.cpp bench: explicitly make all current benchmarks "high" priority 2022-10-20 10:21:04 -03:00
util_time.cpp refactor: Remove unused GetTimeMillis 2023-05-08 12:40:48 +02:00
verify_script.cpp test: Use ECC_Context helper in bench and fuzz tests 2024-05-09 15:56:04 +02:00
wallet_balance.cpp refactor: De-globalize g_signals 2024-02-15 14:37:01 +01:00
wallet_create.cpp Merge bitcoin/bitcoin#29494: build: Assume HAVE_CONFIG_H, Add IWYU pragma keep to bitcoin-config.h includes 2024-05-07 14:14:03 -04:00
wallet_create_tx.cpp test: wallet, fix change position out of range error 2023-12-12 15:20:38 -03:00
wallet_ismine.cpp scripted-diff: Add IWYU pragma keep to bitcoin-config.h includes 2024-05-01 08:33:04 +02:00
wallet_loading.cpp scripted-diff: Add IWYU pragma keep to bitcoin-config.h includes 2024-05-01 08:33:04 +02:00
xor.cpp Extract util::Xor, Add key_offset option, Add bench 2023-07-12 09:59:55 +02:00