Skip to content

Commit aac86ec

Browse files
authored
Merge pull request #1969 from carver/berlin-stub
Implement Berlin fork stub
2 parents 5e949a4 + 9ea1269 commit aac86ec

File tree

7 files changed

+156
-0
lines changed

7 files changed

+156
-0
lines changed

eth/vm/forks/berlin/__init__.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from typing import (
2+
Type,
3+
)
4+
5+
from eth.rlp.blocks import BaseBlock
6+
from eth.vm.forks import (
7+
MuirGlacierVM,
8+
)
9+
from eth.vm.state import BaseState
10+
11+
from .blocks import BerlinBlock
12+
from .headers import (
13+
compute_berlin_difficulty,
14+
configure_berlin_header,
15+
create_berlin_header_from_parent,
16+
)
17+
from .state import BerlinState
18+
19+
20+
class BerlinVM(MuirGlacierVM):
21+
# fork name
22+
fork = 'berlin'
23+
24+
# classes
25+
block_class: Type[BaseBlock] = BerlinBlock
26+
_state_class: Type[BaseState] = BerlinState
27+
28+
# Methods
29+
create_header_from_parent = staticmethod(create_berlin_header_from_parent) # type: ignore
30+
compute_difficulty = staticmethod(compute_berlin_difficulty) # type: ignore
31+
configure_header = configure_berlin_header

eth/vm/forks/berlin/blocks.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from rlp.sedes import (
2+
CountableList,
3+
)
4+
from eth.rlp.headers import (
5+
BlockHeader,
6+
)
7+
from eth.vm.forks.muir_glacier.blocks import (
8+
MuirGlacierBlock,
9+
)
10+
11+
from .transactions import (
12+
BerlinTransaction,
13+
)
14+
15+
16+
class BerlinBlock(MuirGlacierBlock):
17+
transaction_class = BerlinTransaction
18+
fields = [
19+
('header', BlockHeader),
20+
('transactions', CountableList(transaction_class)),
21+
('uncles', CountableList(BlockHeader))
22+
]

eth/vm/forks/berlin/computation.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from eth.vm.forks.muir_glacier.computation import (
2+
MUIR_GLACIER_PRECOMPILES
3+
)
4+
from eth.vm.forks.muir_glacier.computation import (
5+
MuirGlacierComputation,
6+
)
7+
8+
from .opcodes import BERLIN_OPCODES
9+
10+
BERLIN_PRECOMPILES = MUIR_GLACIER_PRECOMPILES
11+
12+
13+
class BerlinComputation(MuirGlacierComputation):
14+
"""
15+
A class for all execution computations in the ``Berlin`` fork.
16+
Inherits from :class:`~eth.vm.forks.muir_glacier.MuirGlacierComputation`
17+
"""
18+
# Override
19+
opcodes = BERLIN_OPCODES
20+
_precompiles = BERLIN_PRECOMPILES

eth/vm/forks/berlin/headers.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from eth.vm.forks.muir_glacier.headers import (
2+
configure_header,
3+
create_header_from_parent,
4+
compute_muir_glacier_difficulty,
5+
)
6+
7+
8+
compute_berlin_difficulty = compute_muir_glacier_difficulty
9+
10+
create_berlin_header_from_parent = create_header_from_parent(
11+
compute_berlin_difficulty
12+
)
13+
configure_berlin_header = configure_header(compute_berlin_difficulty)

eth/vm/forks/berlin/opcodes.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import copy
2+
from typing import Dict
3+
4+
from eth_utils.toolz import merge
5+
6+
from eth.vm.forks.muir_glacier.opcodes import (
7+
MUIR_GLACIER_OPCODES,
8+
)
9+
from eth.vm.opcode import Opcode
10+
11+
12+
UPDATED_OPCODES: Dict[int, Opcode] = {
13+
# New opcodes
14+
}
15+
16+
BERLIN_OPCODES = merge(
17+
copy.deepcopy(MUIR_GLACIER_OPCODES),
18+
UPDATED_OPCODES,
19+
)

eth/vm/forks/berlin/state.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from eth.vm.forks.muir_glacier.state import (
2+
MuirGlacierState
3+
)
4+
5+
from .computation import BerlinComputation
6+
7+
8+
class BerlinState(MuirGlacierState):
9+
computation_class = BerlinComputation

eth/vm/forks/berlin/transactions.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from eth_keys.datatypes import PrivateKey
2+
from eth_typing import Address
3+
4+
from eth.vm.forks.muir_glacier.transactions import (
5+
MuirGlacierTransaction,
6+
MuirGlacierUnsignedTransaction,
7+
)
8+
9+
from eth._utils.transactions import (
10+
create_transaction_signature,
11+
)
12+
13+
14+
class BerlinTransaction(MuirGlacierTransaction):
15+
@classmethod
16+
def create_unsigned_transaction(cls,
17+
*,
18+
nonce: int,
19+
gas_price: int,
20+
gas: int,
21+
to: Address,
22+
value: int,
23+
data: bytes) -> 'BerlinUnsignedTransaction':
24+
return BerlinUnsignedTransaction(nonce, gas_price, gas, to, value, data)
25+
26+
27+
class BerlinUnsignedTransaction(MuirGlacierUnsignedTransaction):
28+
def as_signed_transaction(self,
29+
private_key: PrivateKey,
30+
chain_id: int = None) -> BerlinTransaction:
31+
v, r, s = create_transaction_signature(self, private_key, chain_id=chain_id)
32+
return BerlinTransaction(
33+
nonce=self.nonce,
34+
gas_price=self.gas_price,
35+
gas=self.gas,
36+
to=self.to,
37+
value=self.value,
38+
data=self.data,
39+
v=v,
40+
r=r,
41+
s=s,
42+
)

0 commit comments

Comments
 (0)