Update
I think this is now in a state for code review Summary of discussion of overall design as well as some concept acks: https://bitcoincore.org/en/meetings/2018/05/03/
Description
This is still in progress and not fully completed yet, but wanted to put it out for review in terms of overall design/architecture
The high level goal here (in this, and if accepted, subsequent PRs) is to allow for net and validation to live on separate threads and communicate mostly via message passing - both for the efficiency benefits that further parallelism in the net layer might provide, but also perhaps moreso as a step towards the goal of reducing the amount of shared state and forcing a cleaner separation between the net and validation layers in the core node.
To keep this PR as self contained as possible - this set of commits does the following:
- defines
ProducerConsumerQueue() / ConsumerThread()
: infrastructure to facilitate async communication between the net and validation layers - defines ValidationLayer(): an interface where requests for (just
CBlock
for now) validation can be submitted and processed asynchronously - replaces synchronous calls of
ProcessNewBlock()
in net_processing with the new async interfaceValidationLayer::SubmitForValidation(CBlock) -> std::future<BlockValidationResult>
Because the P2P layer assumes that for a given node every message is fully processed before any subsequent messages are processed, when an asynchronous validation request is submitted for a block coming from a node - that node is “frozen” until that request has been fully validated. In the meantime - the net layer may continue servicing other nodes that do not have pending asynchronous validation requests.
The ProducerConsumerQueue() was left sufficiently generic so that it may be interposed in other places where separation of components via asynchronous message passing might make sense from a design perspective.