This is a backport of [[https://github.com/bitcoin/bitcoin/pull/21727 | core#21727]] [3&4/4]
https://github.com/bitcoin/bitcoin/pull/21727/commits/fa7e64d58615fffea91cd64dc4a2790221ceff0a
https://github.com/bitcoin/bitcoin/pull/21727/commits/fadafab83379ff10d86ada179c6f9641d19464fe
Depends on D12033
Note: in a previous attempt of refactoring validation code, we started moving stuff to a new `blockdb.{h|cpp}` module. This module did not have a dependency on validation.h, but blockstorage.h does have a circular dependency with validation. In order to avoid added a new temporary circular dependency `validation -> blockdb -> blockstorage -> validation`, I decided to squash the two commits. The first commit is hopefully simple enough that this should not make reviewing too difficult.