VerifyHeader basically calls CheckBlockHeader and ContextualCheckBlockHeader for a given CBlockHeader (and all the required parameters).
Since ContextualCheckBlockHeader previously depends on CBlockIndex, some kind of C-compatible API for it must be exposed if we want a complete libconsensus to remain storage agnostic. Alternative implementations of BlockIndexInterface are more than welcomed. If there’s parts of this PR that you think would be acceptable separately, please, say so. If you come up with alternative preparations for making this PR (or an alternative) smaller, that’s welcomed too. And nits, if I haven’t said so before, are always welcomed.
We could also expose CheckBlockHeader independently. An SPV wallet using libconsensus for verifyscript already would bea easily able to also easily check CheckTransaction (which @NicolasDorier is working on) and CheckBlockHeader without any context. If we do so, we could easily move the time checks from ContextualCheckBlockHeader to CheckBlockHeader if we accept the current time of the node as a “non-contextual” parameter for CheckBlockHeader. Obviously time is context, but being pragmatic, these checks are to easy not to expose in CheckBlockHeader and everybody can be expected to have a clock they can trust (the error margins in your clock seem quite safe to me and, maybe more importante, VerifyHeader is going to use the caller’s clock anyway).
Please feel free to ask for squashes as well.
Replaces #5995
Depdendencies:
- Consensus: MOVEONLY: Move functions for header verification #8337
- finish implementing bitcoinconsensus_create_consensus_parameters (and remove whatever is not needed anymore from the base_blob<> preparations).
Death TODOs:
- Hide uint256 and DifficultyAdjustmentInterval() in Consensus::Params: the create interface should be enough.
- [ ] The interface for CBlockIndex (
const BlockIndexInterface* iBlockIndex
) could be hidden in libconsensus using the same create/destroy blockindexInterfaceTrick, even if some of the parameters are going to be function pointers. Or we could offer both and see what happens…discussion welcomed here, but allowing BlockIndexInterface* to be passed as void* it’s in the todo list whether for necessary or just to see how it looks like. If we ever need a DifficultyAdjustmentInterval-like method internally, void* will be transparent. It’s simply the same argument and we should do the same.- [ ] new warnings