forked from ethereum/py-evm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement main changes for the Merge / Paris hark fork
- Add ``Paris`` fork VM classes. - Supplant ``DIFFICULTY`` opcode at ``0x44`` with ``PREVRANDAO``. - Allow ``mix_hash`` to be retrieved from the execution context and add ``mixhash`` opcode logic function to be used in new ``PREVRANDAO`` opcode. - Some renaming of "Mining" nomenclature found within more general classes / methods - created an issue at ethereum#2079 to track more of these changes in a separate PR. - Minor cleanups along the way.
- Loading branch information
Showing
21 changed files
with
398 additions
and
34 deletions.
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
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 |
---|---|---|
|
@@ -37,3 +37,6 @@ | |
from .gray_glacier import ( # noqa: F401 | ||
GrayGlacierVM, | ||
) | ||
from .paris import ( # noqa: F401 | ||
ParisVM, | ||
) |
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,67 @@ | ||
from typing import ( | ||
Type, | ||
) | ||
|
||
from eth.abc import BlockAPI, BlockHeaderAPI | ||
from eth.constants import ( | ||
POST_MERGE_DIFFICULTY, | ||
POST_MERGE_NONCE, | ||
POST_MERGE_OMMERS_HASH, | ||
) | ||
from eth.rlp.blocks import BaseBlock | ||
from eth.vm.forks.gray_glacier import GrayGlacierVM | ||
from eth.vm.state import BaseState | ||
from eth_utils import ( | ||
ValidationError, | ||
) | ||
|
||
from .blocks import ParisBlock | ||
from .headers import ( | ||
configure_paris_header, | ||
create_paris_header_from_parent, | ||
) | ||
from .state import ParisState | ||
|
||
|
||
class ParisVM(GrayGlacierVM): | ||
# fork name | ||
fork = 'paris' | ||
|
||
# classes | ||
block_class: Type[BaseBlock] = ParisBlock | ||
_state_class: Type[BaseState] = ParisState | ||
|
||
# Methods | ||
create_header_from_parent = staticmethod( # type: ignore | ||
create_paris_header_from_parent(POST_MERGE_DIFFICULTY) | ||
) | ||
configure_header = configure_paris_header | ||
|
||
def _assign_block_rewards(self, block: BlockAPI) -> None: | ||
# No block reward or uncles / uncle rewards in PoS | ||
pass | ||
|
||
@classmethod | ||
def validate_header( | ||
cls, | ||
header: BlockHeaderAPI, | ||
parent_header: BlockHeaderAPI | ||
) -> None: | ||
super().validate_header(header, parent_header) | ||
|
||
difficulty, nonce, uncles_hash = ( | ||
header.difficulty, header.nonce, header.uncles_hash | ||
) | ||
|
||
if difficulty != POST_MERGE_DIFFICULTY: | ||
raise ValidationError( | ||
f"Difficulty must be {POST_MERGE_DIFFICULTY}, got {difficulty}." | ||
) | ||
if nonce != POST_MERGE_NONCE: | ||
raise ValidationError( | ||
f"Nonce must be {POST_MERGE_NONCE !r}, got {nonce !r}." | ||
) | ||
if uncles_hash != POST_MERGE_OMMERS_HASH: | ||
raise ValidationError( | ||
f"Uncles hash must be {POST_MERGE_OMMERS_HASH !r}, got {uncles_hash !r}." | ||
) |
Oops, something went wrong.