diff --git a/eth/chains/mainnet/__init__.py b/eth/chains/mainnet/__init__.py index e303740923..cf77195b47 100644 --- a/eth/chains/mainnet/__init__.py +++ b/eth/chains/mainnet/__init__.py @@ -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""" @@ -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):