Skip to content

Commit c977794

Browse files
committed
Add Petersburg fork aka Constantinople that works
1 parent 100b8c7 commit c977794

File tree

17 files changed

+257
-18
lines changed

17 files changed

+257
-18
lines changed

docs/release_notes/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Release notes
22
=============
33

4+
Unreleased (latest source)
5+
--------------------------
6+
7+
- `#1719 <https://github.com/ethereum/py-evm/pull/1719>`_: Implement and activate Petersburg fork (aka Constantinople fixed)
8+
9+
410
0.2.0-alpha.40
511
--------------
612

eth/chains/mainnet/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from .constants import (
1414
MAINNET_CHAIN_ID,
1515
BYZANTIUM_MAINNET_BLOCK,
16-
CONSTANTINOPLE_MAINNET_BLOCK,
16+
PETERSBURG_MAINNET_BLOCK,
1717
TANGERINE_WHISTLE_MAINNET_BLOCK,
1818
HOMESTEAD_MAINNET_BLOCK,
1919
SPURIOUS_DRAGON_MAINNET_BLOCK,
@@ -29,9 +29,9 @@
2929
from eth.vm.base import BaseVM # noqa: F401
3030
from eth.vm.forks import (
3131
ByzantiumVM,
32-
ConstantinopleVM,
3332
FrontierVM,
3433
HomesteadVM,
34+
PetersburgVM,
3535
SpuriousDragonVM,
3636
TangerineWhistleVM,
3737
)
@@ -80,15 +80,15 @@ class MainnetHomesteadVM(MainnetDAOValidatorVM):
8080
TANGERINE_WHISTLE_MAINNET_BLOCK,
8181
SPURIOUS_DRAGON_MAINNET_BLOCK,
8282
BYZANTIUM_MAINNET_BLOCK,
83-
CONSTANTINOPLE_MAINNET_BLOCK,
83+
PETERSBURG_MAINNET_BLOCK,
8484
)
8585
MAINNET_VMS = (
8686
FrontierVM,
8787
MainnetHomesteadVM,
8888
TangerineWhistleVM,
8989
SpuriousDragonVM,
9090
ByzantiumVM,
91-
ConstantinopleVM,
91+
PetersburgVM,
9292
)
9393

9494
MAINNET_VM_CONFIGURATION = tuple(zip(MAINNET_FORK_BLOCKS, MAINNET_VMS))

eth/chains/mainnet/constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@
3939
BYZANTIUM_MAINNET_BLOCK = BlockNumber(4370000)
4040

4141
#
42-
# Constantinople Block
42+
# Petersburg Block
4343
#
44-
CONSTANTINOPLE_MAINNET_BLOCK = BlockNumber(9876543210)
44+
PETERSBURG_MAINNET_BLOCK = BlockNumber(7280000)

eth/chains/ropsten/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .constants import (
55
BYZANTIUM_ROPSTEN_BLOCK,
66
CONSTANTINOPLE_ROPSTEN_BLOCK,
7+
PETERSBURG_ROPSTEN_BLOCK,
78
ROPSTEN_CHAIN_ID,
89
SPURIOUS_DRAGON_ROPSTEN_BLOCK,
910
TANGERINE_WHISTLE_ROPSTEN_BLOCK,
@@ -16,6 +17,7 @@
1617
from eth.vm.forks import (
1718
ByzantiumVM,
1819
ConstantinopleVM,
20+
PetersburgVM,
1921
SpuriousDragonVM,
2022
TangerineWhistleVM,
2123
)
@@ -27,6 +29,7 @@
2729
(SPURIOUS_DRAGON_ROPSTEN_BLOCK, SpuriousDragonVM),
2830
(BYZANTIUM_ROPSTEN_BLOCK, ByzantiumVM),
2931
(CONSTANTINOPLE_ROPSTEN_BLOCK, ConstantinopleVM),
32+
(PETERSBURG_ROPSTEN_BLOCK, PetersburgVM),
3033
)
3134

3235

eth/chains/ropsten/constants.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,9 @@
4040
# Constantinople
4141
#
4242
CONSTANTINOPLE_ROPSTEN_BLOCK = BlockNumber(4230000)
43+
44+
45+
#
46+
# Petersburg
47+
#
48+
PETERSBURG_ROPSTEN_BLOCK = BlockNumber(4939394)

eth/vm/forks/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@
1616
from .constantinople import ( # noqa: F401
1717
ConstantinopleVM,
1818
)
19+
from .petersburg import ( # noqa: F401
20+
PetersburgVM,
21+
)

eth/vm/forks/constantinople/computation.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
from eth_utils.toolz import (
2-
merge,
3-
)
4-
51
from eth.vm.forks.byzantium.computation import (
62
BYZANTIUM_PRECOMPILES
73
)
@@ -15,12 +11,7 @@
1511

1612
from .opcodes import CONSTANTINOPLE_OPCODES
1713

18-
CONSTANTINOPLE_PRECOMPILES = merge(
19-
BYZANTIUM_PRECOMPILES,
20-
{
21-
# TODO: add new precompiles
22-
},
23-
)
14+
CONSTANTINOPLE_PRECOMPILES = BYZANTIUM_PRECOMPILES
2415

2516

2617
class ConstantinopleComputation(ByzantiumComputation):

eth/vm/forks/petersburg/__init__.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from typing import ( # noqa: F401
2+
Type,
3+
)
4+
5+
from eth.rlp.blocks import BaseBlock # noqa: F401
6+
from eth.vm.forks.byzantium import (
7+
ByzantiumVM,
8+
get_uncle_reward,
9+
)
10+
from eth.vm.state import BaseState # noqa: F401
11+
12+
from .blocks import PetersburgBlock
13+
from .constants import EIP1234_BLOCK_REWARD
14+
from .headers import (
15+
compute_petersburg_difficulty,
16+
configure_petersburg_header,
17+
create_petersburg_header_from_parent,
18+
)
19+
from .state import PetersburgState
20+
21+
22+
class PetersburgVM(ByzantiumVM):
23+
# fork name
24+
fork = 'petersburg'
25+
26+
# classes
27+
block_class = PetersburgBlock # type: Type[BaseBlock]
28+
_state_class = PetersburgState # type: Type[BaseState]
29+
30+
# Methods
31+
create_header_from_parent = staticmethod(create_petersburg_header_from_parent) # type: ignore # noqa: E501
32+
compute_difficulty = staticmethod(compute_petersburg_difficulty) # type: ignore
33+
configure_header = configure_petersburg_header
34+
get_uncle_reward = staticmethod(get_uncle_reward(EIP1234_BLOCK_REWARD))
35+
36+
@staticmethod
37+
def get_block_reward() -> int:
38+
return EIP1234_BLOCK_REWARD

eth/vm/forks/petersburg/blocks.py

Lines changed: 22 additions & 0 deletions
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.byzantium.blocks import (
8+
ByzantiumBlock,
9+
)
10+
11+
from .transactions import (
12+
PetersburgTransaction,
13+
)
14+
15+
16+
class PetersburgBlock(ByzantiumBlock):
17+
transaction_class = PetersburgTransaction
18+
fields = [
19+
('header', BlockHeader),
20+
('transactions', CountableList(transaction_class)),
21+
('uncles', CountableList(BlockHeader))
22+
]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from eth.vm.forks.byzantium.computation import (
2+
BYZANTIUM_PRECOMPILES
3+
)
4+
from eth.vm.forks.byzantium.computation import (
5+
ByzantiumComputation
6+
)
7+
8+
from .opcodes import PETERSBURG_OPCODES
9+
10+
PETERSBURG_PRECOMPILES = BYZANTIUM_PRECOMPILES
11+
12+
13+
class PetersburgComputation(ByzantiumComputation):
14+
"""
15+
A class for all execution computations in the ``Petersburg`` fork.
16+
Inherits from :class:`~eth.vm.forks.byzantium.computation.ByzantiumComputation`
17+
"""
18+
# Override
19+
opcodes = PETERSBURG_OPCODES
20+
_precompiles = PETERSBURG_PRECOMPILES

0 commit comments

Comments
 (0)