-
Notifications
You must be signed in to change notification settings - Fork 692
Add mysterious Petersburg fork #1719
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
Merged
cburgdorf
merged 5 commits into
ethereum:master
from
cburgdorf:christoph/feat/petersburg-fork
Feb 21, 2019
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c977794
Add Petersburg fork aka Constantinople that works
cburgdorf b74d07f
Make test more DRY
cburgdorf 8aaf861
eth/vm/state: recurse collect_touched_accounts() always, unless compu…
veox 7c8dd1a
Activate tests for Petersburg fork
cburgdorf 92b6585
tests/blockchain: duplicate INCORRECT_UPSTREAM_TESTS for Constantinop…
veox 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,38 @@ | ||
from typing import ( # noqa: F401 | ||
Type, | ||
) | ||
|
||
from eth.rlp.blocks import BaseBlock # noqa: F401 | ||
from eth.vm.forks.byzantium import ( | ||
ByzantiumVM, | ||
get_uncle_reward, | ||
) | ||
from eth.vm.state import BaseState # noqa: F401 | ||
|
||
from .blocks import PetersburgBlock | ||
from .constants import EIP1234_BLOCK_REWARD | ||
from .headers import ( | ||
compute_petersburg_difficulty, | ||
configure_petersburg_header, | ||
create_petersburg_header_from_parent, | ||
) | ||
from .state import PetersburgState | ||
|
||
|
||
class PetersburgVM(ByzantiumVM): | ||
# fork name | ||
fork = 'petersburg' | ||
|
||
# classes | ||
block_class = PetersburgBlock # type: Type[BaseBlock] | ||
_state_class = PetersburgState # type: Type[BaseState] | ||
|
||
# Methods | ||
create_header_from_parent = staticmethod(create_petersburg_header_from_parent) # type: ignore # noqa: E501 | ||
compute_difficulty = staticmethod(compute_petersburg_difficulty) # type: ignore | ||
configure_header = configure_petersburg_header | ||
get_uncle_reward = staticmethod(get_uncle_reward(EIP1234_BLOCK_REWARD)) | ||
|
||
@staticmethod | ||
def get_block_reward() -> int: | ||
return EIP1234_BLOCK_REWARD |
This file contains hidden or 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.byzantium.blocks import ( | ||
ByzantiumBlock, | ||
) | ||
|
||
from .transactions import ( | ||
PetersburgTransaction, | ||
) | ||
|
||
|
||
class PetersburgBlock(ByzantiumBlock): | ||
transaction_class = PetersburgTransaction | ||
fields = [ | ||
('header', BlockHeader), | ||
('transactions', CountableList(transaction_class)), | ||
('uncles', CountableList(BlockHeader)) | ||
] |
This file contains hidden or 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.byzantium.computation import ( | ||
BYZANTIUM_PRECOMPILES | ||
) | ||
from eth.vm.forks.byzantium.computation import ( | ||
ByzantiumComputation | ||
) | ||
|
||
from .opcodes import PETERSBURG_OPCODES | ||
|
||
PETERSBURG_PRECOMPILES = BYZANTIUM_PRECOMPILES | ||
|
||
|
||
class PetersburgComputation(ByzantiumComputation): | ||
""" | ||
A class for all execution computations in the ``Petersburg`` fork. | ||
Inherits from :class:`~eth.vm.forks.byzantium.computation.ByzantiumComputation` | ||
""" | ||
# Override | ||
opcodes = PETERSBURG_OPCODES | ||
_precompiles = PETERSBURG_PRECOMPILES |
This file contains hidden or 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,6 @@ | ||
from eth_utils import denoms | ||
|
||
|
||
GAS_EXTCODEHASH_EIP1052 = 400 | ||
|
||
EIP1234_BLOCK_REWARD = 2 * denoms.ether |
This file contains hidden or 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.byzantium.headers import ( | ||
configure_header, | ||
create_header_from_parent, | ||
compute_difficulty, | ||
) | ||
|
||
|
||
compute_petersburg_difficulty = compute_difficulty(5000000) | ||
|
||
create_petersburg_header_from_parent = create_header_from_parent( | ||
compute_petersburg_difficulty | ||
) | ||
configure_petersburg_header = configure_header(compute_petersburg_difficulty) |
This file contains hidden or 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,60 @@ | ||
import copy | ||
from eth_utils.toolz import ( | ||
merge | ||
) | ||
|
||
from eth import ( | ||
constants | ||
) | ||
from eth.vm import ( | ||
mnemonics, | ||
opcode_values, | ||
) | ||
from eth.vm.forks.byzantium.opcodes import ( | ||
BYZANTIUM_OPCODES, | ||
) | ||
from eth.vm.forks.petersburg.constants import ( | ||
GAS_EXTCODEHASH_EIP1052 | ||
) | ||
from eth.vm.logic import ( | ||
arithmetic, | ||
context, | ||
system, | ||
) | ||
from eth.vm.opcode import ( | ||
as_opcode | ||
) | ||
|
||
|
||
UPDATED_OPCODES = { | ||
opcode_values.SHL: as_opcode( | ||
logic_fn=arithmetic.shl, | ||
mnemonic=mnemonics.SHL, | ||
gas_cost=constants.GAS_VERYLOW, | ||
), | ||
opcode_values.SHR: as_opcode( | ||
logic_fn=arithmetic.shr, | ||
mnemonic=mnemonics.SHR, | ||
gas_cost=constants.GAS_VERYLOW, | ||
), | ||
opcode_values.SAR: as_opcode( | ||
logic_fn=arithmetic.sar, | ||
mnemonic=mnemonics.SAR, | ||
gas_cost=constants.GAS_VERYLOW, | ||
), | ||
opcode_values.EXTCODEHASH: as_opcode( | ||
logic_fn=context.extcodehash, | ||
mnemonic=mnemonics.EXTCODEHASH, | ||
gas_cost=GAS_EXTCODEHASH_EIP1052, | ||
), | ||
opcode_values.CREATE2: system.Create2.configure( | ||
__name__='opcode:CREATE2', | ||
mnemonic=mnemonics.CREATE2, | ||
gas_cost=constants.GAS_CREATE, | ||
)(), | ||
} | ||
|
||
PETERSBURG_OPCODES = merge( | ||
copy.deepcopy(BYZANTIUM_OPCODES), | ||
UPDATED_OPCODES, | ||
) |
This file contains hidden or 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.byzantium.state import ( | ||
ByzantiumState | ||
) | ||
|
||
from .computation import PetersburgComputation | ||
|
||
|
||
class PetersburgState(ByzantiumState): | ||
computation_class = PetersburgComputation |
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.
Maybe
compute_difficulty(bomb_delay=5000000)
as a way to document what this magic number is.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.
For some reason, this fails the tests with:
Leaving it as is for now.