Default fork choice value and intermediates for block import parameters#4652
Default fork choice value and intermediates for block import parameters#4652
Conversation
|
|
||
| let intermediate = PowIntermediate::<B, Algorithm::Difficulty> { | ||
| hash: hash, | ||
| difficulty: None, |
There was a problem hiding this comment.
should we not verify the difficulty here in the Verifier, as that's the parallelizable operation?
There was a problem hiding this comment.
Difficulty may not be parallelizable operation. The mining algorithm is always fixed (or can only be chosen from a set of validated ones), but for difficulty adjustment algorithms, they can be defined in runtime. In those cases, block importer will have to do a runtime call on the parent block to fetch the difficulty. Because parent block may not be available in Verifier, we can only set it to None here, meaning we do not yet know the value.
However, in mining routine, the value of difficulty is indeed available because we mine on local best block. In that case, difficulty is set to Some so we can avoid double calculation.
|
LGTM except for question above |
Co-Authored-By: Robert Habermeier <rphmeier@gmail.com>
Co-Authored-By: Robert Habermeier <rphmeier@gmail.com>
andresilva
left a comment
There was a problem hiding this comment.
Changes LGTM. When we want to parallelize the Verifier we might need to make the pipeline more fine-grained though (depending on consensus algorithm). For epoch based consensus protocols we'll only be able to parallelize verification of blocks within the same epoch.
|
For babe we might also be able to use |
Addresses some of #3623.
This PR tries to improve several issues in the consensus engines:
BlockImportwith aVerifier, consensus will silently fail.Verifierdoes not assume parents, it is not always possible for it to return the correct fork choice rule, but currently it is forced to do so.Verifierto all subsequentBlockImports is not obvious.In this PR:
ForkChoiceStrategyto beOption. IfNone, it indicates that theBlockImportorVerifiercannot currently make a decision on the fork choice rule. SubsequentBlockImportshould properly modify the value. If the value is passed all the way down to the bottomBlockImport, then the block will not be imported.intermediatesinBlockImportParams. This indicates values that should be processed by subsequentBlockImports. If a value inintermediatesis not processed, the block import fails. As an example usage of this, in PoW engine,Verifierusesintermediatesto pass the calculated difficulty (if available) and the full block hash down toBlockImport, who will then use them to calculate the block auxiliary.BlockImportandVerifier.