mintlayer-core
mintlayer-core copied to clipboard
Blockprod pow/pos separation
BlockProduction::produce_block_with_custom_id now delegates to one of 3 separate functions, based on the passed input data and the required consensus - produce_block_pos/produce_block_pow/produce_block_ignore_consensus; each of the functions works with the specific type of consensus and doesn't have to match it anymore (in the current master we match the required consensus multiple times on different levels).
Some common code that is shared among the functions has been put to the Helper struct.
The produce_block_xxx functions are now implemented differently:
- Only the "pow" one spawns a new job on the thread pool (because only in this case the task is heavy and needs cancellation if the tip has changed).
- the "pos" one constructs the block only after it has found a free time slot (though currently I don't take any advantage of this).
Also, the internal loop that the original produce_block_with_custom_id used to have no longer exists because IMO it was redundant (iteration could only happen on a "recoverable" mempool error, i.e. the one that happens when the tip changes; in this case we may just exit and let the wallet call blockprod again).
This is still work-in-progress. There is still more cleanup to be done (e.g. I'd get rid of the last_used_block_timestamps in JobsContainer because it's PoS specific and IMO should be stored somewhere else). Also, we need to make use of the fact that in PoS the block can now be constructed after staking has suceeded.