partial PR15118 backport https://github.com/bitcoin/bitcoin/pull/15118/commits
This combines four refactor commits:
https://github.com/bitcoin/bitcoin/compare/9183d6ef6~1..e0380933e
...and a commit adding unit tests:
https://github.com/bitcoin/bitcoin/pull/15118/commits/4c01e4e159db82ce4b2acce75f709cac996367d7
These have been squashed due to intermediate commits not even building
properly. The tests have been modified to use CDiskBlockPos as the
rename is planned for a subsequent diff. Otherwise, it's the same.