-
Notifications
You must be signed in to change notification settings - Fork 659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor consensus engine handling as well as clique internals #1899
Merged
cburgdorf
merged 2 commits into
ethereum:master
from
cburgdorf:christoph/refactor/clique-validate-header2
Jan 8, 2020
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from .applier import ConsensusApplier # noqa: F401 | ||
from .clique.clique import ( # noqa: F401 | ||
CliqueApplier, | ||
CliqueConsensus, | ||
CliqueConsensusContext, | ||
) | ||
from .context import ConsensusContext # noqa: F401 | ||
from .noproof import NoProofConsensus # noqa: F401 | ||
from .pow import PowConsensus # noqa: F401 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from typing import ( | ||
Iterable, | ||
Type, | ||
) | ||
|
||
from eth_utils import ( | ||
to_tuple, | ||
) | ||
|
||
from eth.abc import ( | ||
ConsensusAPI, | ||
VirtualMachineModifierAPI, | ||
VMConfiguration, | ||
) | ||
from eth.typing import ( | ||
VMFork, | ||
) | ||
|
||
|
||
class ConsensusApplier(VirtualMachineModifierAPI): | ||
""" | ||
This class is used to apply simple types of consensus engines to a series of virtual machines. | ||
|
||
Note that this *must not* be used for Clique, which has its own modifier | ||
""" | ||
|
||
def __init__(self, consensus_class: Type[ConsensusAPI]) -> None: | ||
self._consensus_class = consensus_class | ||
|
||
@to_tuple | ||
def amend_vm_configuration(self, config: VMConfiguration) -> Iterable[VMFork]: | ||
""" | ||
Amend the given ``VMConfiguration`` to operate under the rules of the pre-defined consensus | ||
""" | ||
for pair in config: | ||
block_number, vm = pair | ||
yield block_number, vm.configure(consensus_class=self._consensus_class) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple random thoughts, as I won't be able to pick up the review again until later:
I was assuming we would formalize the idea that this context can't write to the database (Maybe this should be a read-only version that's supplied?) Or if we don't then maybe it fits as a kind of parallel to
ChainDB
, likeConsensusDB
."remains static" in the docs above didn't immediately mean to me what I think we want to say. Something like: this instance stays in memory across VM runs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But, we need to write to the database. E.g. Clique persists snapshots to the db.
py-evm/eth/consensus/clique/snapshot_manager.py
Line 248 in 7b94eb1
I'm not sure how that would work out. In the
ChainDB
case, we know the specific types that make a chain and that can be stored and retrieved. But for consensus, it seems pretty much up to the specific consensus algorithm which kind of things need persistence. Clique uses snapshots but it's hard to imagine all the different things other consensus schemes would require.👍 I'll update that.