Only sleep during prepare if node is validating #1857
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This change mitigates the problem of low gas estimates #1856, by ensuring that non validating nodes do not wait till the next block is due when engine.Prepare is called. This results in non validating nodes having an up to date pending block( I.E a pending block with a number 1 greater than the last inserted block). For some reason validating nodes produce the correct gas estimate even when they have an old pending block (I.E a pending block with the same number as the last inserted block).
Tested
I have tested this locally using mycelo to start a network with 1 validator and then starting up a full node that connects to that network. Without the fix the tests here repeatedly show a low gas estimate for the first few gas estimation calls made against the pending block. With the fix I have not been able to elicit an incorrect gas estimate (although it is definitely possible because block insertion and pending block creation are not part of a single atomic operation). Prior to the fix I observed from the logs that gas estimates using the latest and pending block would execute against a block with the same number, after the fix I observed from the logs that gas estimates with the pending block executed against a block with number one greater than gas estimates with the latest block.
Related issues
-Mitigates #1856