9341b5333ablockstorage: make block read hash checks explicit (Lőrinc)2371b9f4eetest/bench: verify hash in `ComputeFilter` reads (Lőrinc)5d235d50d6net: assert block hash in `ProcessGetBlockData` and `ProcessMessage` (Lőrinc) Pull request description: A follow-up to https://github.com/bitcoin/bitcoin/pull/32487#discussion_r2094072165, after which validating the hash of a read block from disk doesn't incur the cost of calculating its hash anymore. ### Summary This PR adds explicit checks that the read block header's hash matches the one we were expecting. ### Context After the previous PR, validating a block's hash during read operations became essentially free. This PR leverages that by requiring callers to provide a block's expected hash (or `std::nullopt`), preventing silent failures caused by corrupted or mismatched data. Most `ReadBlock` usages were updated with expected hashes and now fail on mismatch. ### Changes * added hash assertions in `ProcessGetBlockData` and `ProcessMessage` to validate that the block read from disk matches the expected hash; * updated tests and benchmark to pass the correct block hash to `ReadBlock()`, ensuring the hash validation is tested - or none if we already expect PoW failure; * removed the default value for `expected_hash`, requiring an explicit hash for all block reads. ### Why is the hash still optional (but no longer has a default value) * for header-error tests, where the goal is to trigger failures early in the parsing process; * for out-of-order orphan blocks, where the child hash isn't available before the initial disk read. ACKs for top commit: maflcko: review ACK9341b5333a🕙 achow101: ACK9341b5333ahodlinator: ACK9341b5333ajanb84: re ACK9341b5333aTree-SHA512: cf1d4fff4c15e3f8898ec284929cb83d7e747125d4ee759e77d369f1716728e843ef98030be32c8d608956a96ae2fbefa0e801200c333b9eefd6c086ec032e1f
src/node/
The src/node/ directory contains code that needs to access node state
(state in CChain, CBlockIndex, CCoinsView, CTxMemPool, and similar
classes).
Code in src/node/ is meant to be segregated from code in
src/wallet/ and src/qt/, to ensure wallet and GUI
code changes don't interfere with node operation, to allow wallet and GUI code
to run in separate processes, and to perhaps eventually allow wallet and GUI
code to be maintained in separate source repositories.
As a rule of thumb, code in one of the src/node/,
src/wallet/, or src/qt/ directories should avoid
calling code in the other directories directly, and only invoke it indirectly
through the more limited src/interfaces/ classes.
This directory is at the moment
sparsely populated. Eventually more substantial files like
src/validation.cpp and
src/txmempool.cpp might be moved there.