partial PR15118 backport https://github.com/bitcoin/bitcoin/pull/15118/commits
This combines four refactor commits:
...and a commit adding unit tests:
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.