This replaces/includes #6625 (previously #6526), #6009, #6051 and #6591 (previously #6024).
EDIT (further explanation demanded):
Although the PRs linked from here can provide a better explanation of the motivation, it is not so convenient for reviewers since they have to go through them individually.
The first 4 commits are taken from #6625, which is a modification of #6526 that doesn’t break some other things. The modifications are explained in #6625. Although the #6526 has an extensive description, I will summarize its general purpose here.
The goal is to prepare the consensus code for an eventual block size hardfork and also for previous testing. It should simplify other PRs like #6382 (that introduces std::numeric_limits<uint64_t>::max()
testnet chains to test different block sizes), #6451 (BIP102) or any other block-size-related proposal.
The next commit is taken from #6009, which separates GetMedianTimePast() from CBlockIndex and moves it to consensus (it’s done in the same commit instead of the next one because it’s “cheaper diff-wise”). GetMedianTimePast() is needed for verifying block headers, but chain.o will not.
The next commit is the code movement. All consensus critical functions that are not separated already (like 4 of the 5 functions in pow.o [the other one can be separated out]) in build-separable files are moved. If you think any of the moved functions are not consensus critical or that there’s some missing functions, please, say so. One exception is main::ConnectBlock() which is consensus critical but contains other things that are not welcomed in libconsensus. A VerifyBlock library-safe function can be extracted from it later. #6051 was a similar movement.
The last commit is taken from #6591 (previously #6024). This one has 2 purposes:
- Remove chainparams.h and timedata.h dependencies (which are not library-friendly) from consensus.o
- It’s part of a bigger process (see #5970 ) to eventually be able to remove the pCurrentParams global (hidden behind
Params()
, but still a global). I hope I don’t need to explain here why removing globals is a desirable thing…