-
Notifications
You must be signed in to change notification settings - Fork 650
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
85f5b09
commit b069648
Showing
7 changed files
with
155 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from typing import ( | ||
Type, | ||
) | ||
|
||
from eth.rlp.blocks import BaseBlock | ||
from eth.vm.forks.constantinople import ( | ||
ConstantinopleVM, | ||
) | ||
from eth.vm.state import BaseState | ||
|
||
from .blocks import BerlinBlock | ||
from .headers import ( | ||
compute_berlin_difficulty, | ||
configure_berlin_header, | ||
create_berlin_header_from_parent, | ||
) | ||
from .state import BerlinState | ||
|
||
|
||
class BerlinVM(ConstantinopleVM): | ||
# fork name | ||
fork = 'berlin' | ||
|
||
# classes | ||
block_class: Type[BaseBlock] = BerlinBlock | ||
_state_class: Type[BaseState] = BerlinState | ||
|
||
# Methods | ||
create_header_from_parent = staticmethod(create_berlin_header_from_parent) # type: ignore | ||
compute_difficulty = staticmethod(compute_berlin_difficulty) # type: ignore | ||
configure_header = configure_berlin_header |
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,22 @@ | ||
from rlp.sedes import ( | ||
CountableList, | ||
) | ||
from eth.rlp.headers import ( | ||
BlockHeader, | ||
) | ||
from eth.vm.forks.muir_glacier.blocks import ( | ||
MuirGlacierBlock, | ||
) | ||
|
||
from .transactions import ( | ||
BerlinTransaction, | ||
) | ||
|
||
|
||
class BerlinBlock(MuirGlacierBlock): | ||
transaction_class = BerlinTransaction | ||
fields = [ | ||
('header', BlockHeader), | ||
('transactions', CountableList(transaction_class)), | ||
('uncles', CountableList(BlockHeader)) | ||
] |
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,20 @@ | ||
from eth.vm.forks.muir_glacier.computation import ( | ||
MUIR_GLACIER_PRECOMPILES | ||
) | ||
from eth.vm.forks.muir_glacier.computation import ( | ||
MuirGlacierComputation, | ||
) | ||
|
||
from .opcodes import BERLIN_OPCODES | ||
|
||
BERLIN_PRECOMPILES = MUIR_GLACIER_PRECOMPILES | ||
|
||
|
||
class BerlinComputation(MuirGlacierComputation): | ||
""" | ||
A class for all execution computations in the ``Berlin`` fork. | ||
Inherits from :class:`~eth.vm.forks.muir_glacier.MuirGlacierComputation` | ||
""" | ||
# Override | ||
opcodes = BERLIN_OPCODES | ||
_precompiles = BERLIN_PRECOMPILES |
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,13 @@ | ||
from eth.vm.forks.muir_glacier.headers import ( | ||
configure_header, | ||
create_header_from_parent, | ||
compute_muir_glacier_difficulty, | ||
) | ||
|
||
|
||
compute_berlin_difficulty = compute_muir_glacier_difficulty | ||
|
||
create_berlin_header_from_parent = create_header_from_parent( | ||
compute_berlin_difficulty | ||
) | ||
configure_berlin_header = configure_header(compute_berlin_difficulty) |
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,18 @@ | ||
import copy | ||
|
||
from eth_utils.toolz import merge | ||
|
||
|
||
from eth.vm.forks.muir_glacier.opcodes import ( | ||
MUIR_GLACIER_OPCODES, | ||
) | ||
|
||
|
||
UPDATED_OPCODES = { | ||
# New opcodes | ||
} | ||
|
||
BERLIN_OPCODES = merge( | ||
copy.deepcopy(MUIR_GLACIER_OPCODES), | ||
UPDATED_OPCODES, | ||
) |
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 eth.vm.forks.muir_glacier.state import ( | ||
MuirGlacierState | ||
) | ||
|
||
from .computation import BerlinComputation | ||
|
||
|
||
class BerlinState(MuirGlacierState): | ||
computation_class = BerlinComputation |
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,42 @@ | ||
from eth_keys.datatypes import PrivateKey | ||
from eth_typing import Address | ||
|
||
from eth.vm.forks.muir_glacier.transactions import ( | ||
MuirGlacierTransaction, | ||
MuirGlacierUnsignedTransaction, | ||
) | ||
|
||
from eth._utils.transactions import ( | ||
create_transaction_signature, | ||
) | ||
|
||
|
||
class BerlinTransaction(MuirGlacierTransaction): | ||
@classmethod | ||
def create_unsigned_transaction(cls, | ||
*, | ||
nonce: int, | ||
gas_price: int, | ||
gas: int, | ||
to: Address, | ||
value: int, | ||
data: bytes) -> 'BerlinUnsignedTransaction': | ||
return BerlinUnsignedTransaction(nonce, gas_price, gas, to, value, data) | ||
|
||
|
||
class BerlinUnsignedTransaction(MuirGlacierUnsignedTransaction): | ||
def as_signed_transaction(self, | ||
private_key: PrivateKey, | ||
chain_id: int=None) -> BerlinTransaction: | ||
v, r, s = create_transaction_signature(self, private_key, chain_id=chain_id) | ||
return BerlinTransaction( | ||
nonce=self.nonce, | ||
gas_price=self.gas_price, | ||
gas=self.gas, | ||
to=self.to, | ||
value=self.value, | ||
data=self.data, | ||
v=v, | ||
r=r, | ||
s=s, | ||
) |