Skip to content

Commit

Permalink
Extract DAO check into static function
Browse files Browse the repository at this point in the history
  • Loading branch information
cburgdorf committed Jan 10, 2020
1 parent 25aa036 commit 8b87c90
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions eth/chains/mainnet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,27 @@
)


def validate_header_is_on_intended_dao_fork(support_dao_fork: bool,
dao_fork_at: BlockNumber,
header: BlockHeaderAPI) -> None:

# The special extra_data is set on the ten headers starting at the fork
extra_data_block_nums = range(dao_fork_at, dao_fork_at + 10)

if header.block_number in extra_data_block_nums:
if support_dao_fork and header.extra_data != DAO_FORK_MAINNET_EXTRA_DATA:
raise ValidationError(
f"Block {header!r} must have extra data "
f"{encode_hex(DAO_FORK_MAINNET_EXTRA_DATA)} not "
f"{encode_hex(header.extra_data)} when supporting DAO fork"
)
elif not support_dao_fork and header.extra_data == DAO_FORK_MAINNET_EXTRA_DATA:
raise ValidationError(
f"Block {header!r} must not have extra data "
f"{encode_hex(DAO_FORK_MAINNET_EXTRA_DATA)} when declining the DAO fork"
)


class MainnetDAOValidatorVM(HomesteadVM):
"""Only on mainnet, TheDAO fork is accompanied by special extra data. Validate those headers"""

Expand All @@ -53,23 +74,11 @@ def validate_header(self,
check_seal: bool=True) -> None:

super().validate_header(header, previous_header, check_seal)

# The special extra_data is set on the ten headers starting at the fork
dao_fork_at = self.get_dao_fork_block_number()
extra_data_block_nums = range(dao_fork_at, dao_fork_at + 10)

if header.block_number in extra_data_block_nums:
if self.support_dao_fork and header.extra_data != DAO_FORK_MAINNET_EXTRA_DATA:
raise ValidationError(
f"Block {header!r} must have extra data "
f"{encode_hex(DAO_FORK_MAINNET_EXTRA_DATA)} not "
f"{encode_hex(header.extra_data)} when supporting DAO fork"
)
elif not self.support_dao_fork and header.extra_data == DAO_FORK_MAINNET_EXTRA_DATA:
raise ValidationError(
f"Block {header!r} must not have extra data "
f"{encode_hex(DAO_FORK_MAINNET_EXTRA_DATA)} when declining the DAO fork"
)
validate_header_is_on_intended_dao_fork(
self.support_dao_fork,
self.get_dao_fork_block_number(),
header
)


class MainnetHomesteadVM(MainnetDAOValidatorVM):
Expand Down

0 comments on commit 8b87c90

Please sign in to comment.