validation: Skip VerifyDB checks of level >=3 if dbcache is too small
Summary:
The previous behavior, skipping some L3 DisconnectBlock calls,
but still attempting to reconnect these blocks at L4, makes
ConnectBlock assert.
The variable skipped_l3_checks is introduced because even with an
insufficient cache for the L3 checks, the L1/L2 checks in the same
loop should still be completed.
This is a partial backport of core#27009
https://github.com/bitcoin/bitcoin/pull/27009/commits/61431e3a57b5613d8715c93c6eae0058e0217eaa
Fixes core#25563.
Test Plan:
src/bitcoind -dbcache=10
src/bitcoin-cli verifychain 4 10000
This produces the following output in the bitcoind terminal:
2023-12-06T12:57:54Z Verifying last 10000 blocks at level 4 2023-12-06T12:57:54Z [0%]...[10%]...[20%]...[30%]...[40%]...[50%]...Skipped verification of level >=3 (insufficient database cache size). Consider increasing -dbcache. 2023-12-06T12:57:57Z [DONE]. 2023-12-06T12:57:57Z No coin database inconsistencies in last 10000 blocks (9992 transactions)
Reviewers: #bitcoin_abc, Fabien
Reviewed By: #bitcoin_abc, Fabien
Differential Revision: https://reviews.bitcoinabc.org/D14921