Skip to content
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

Make the max bytes of extra_data configurable #1864

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions eth/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import (
Any,
Callable,
ClassVar,
ContextManager,
Dict,
Iterable,
Expand Down Expand Up @@ -1358,6 +1359,7 @@ def get_transaction_context(cls,
class VirtualMachineAPI(ConfigurableAPI):
fork: str # noqa: E701 # flake8 bug that's fixed in 3.6.0+
chaindb: ChainDatabaseAPI
extra_data_max_bytes: ClassVar[int]

@abstractmethod
def __init__(self, header: BlockHeaderAPI, chaindb: ChainDatabaseAPI) -> None:
Expand Down
11 changes: 9 additions & 2 deletions eth/vm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
from typing import (
Any,
ClassVar,
Iterable,
Iterator,
Optional,
Expand Down Expand Up @@ -90,6 +91,7 @@ class VM(Configurable, VirtualMachineAPI):
- ``_state_class``: The :class:`~eth.abc.StateAPI` class used by this VM for execution.
"""
block_class: Type[BlockAPI] = None
extra_data_max_bytes: ClassVar[int] = 32
fork: str = None # noqa: E701 # flake8 bug that's fixed in 3.6.0+
chaindb: ChainDatabaseAPI = None
_state_class: Type[StateAPI] = None
Expand Down Expand Up @@ -549,7 +551,11 @@ def validate_block(self, block: BlockAPI) -> None:
)

if block.is_genesis:
validate_length_lte(block.header.extra_data, 32, title="BlockHeader.extra_data")
validate_length_lte(
block.header.extra_data,
self.extra_data_max_bytes,
title="BlockHeader.extra_data"
)
else:
parent_header = get_parent_header(block.header, self.chaindb)
self.validate_header(block.header, parent_header)
Expand Down Expand Up @@ -593,7 +599,8 @@ def validate_header(cls,
# to validate genesis header, check if it equals canonical header at block number 0
raise ValidationError("Must have access to parent header to validate current header")
else:
validate_length_lte(header.extra_data, 32, title="BlockHeader.extra_data")
validate_length_lte(
header.extra_data, cls.extra_data_max_bytes, title="BlockHeader.extra_data")

validate_gas_limit(header.gas_limit, parent_header.gas_limit)

Expand Down
2 changes: 2 additions & 0 deletions newsfragments/1864.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Make the *max length validation* of the `extra_data` field configurable. The reason for that is that
different consensus engines such as Clique repurpose this field using different max length limits.