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

feature: Pass Correct Fork Name to T8N on Transition Forks #222

Merged
merged 7 commits into from
Jul 25, 2023
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
28 changes: 19 additions & 9 deletions src/ethereum_test_forks/base_fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,58 +30,66 @@ class BaseFork(ABC, metaclass=BaseForkMeta):
Must contain all the methods used by every fork.
"""

@classmethod
@abstractmethod
def fork(cls, block_number: int = 0, timestamp: int = 0) -> str:
"""
Returns fork name as it's meant to be passed to the transition tool for execution.
"""
pass

# Header information abstract methods
@classmethod
@abstractmethod
def header_base_fee_required(cls, block_number: int, timestamp: int) -> bool:
def header_base_fee_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
"""
Returns true if the header must contain base fee
"""
pass

@classmethod
@abstractmethod
def header_prev_randao_required(cls, block_number: int, timestamp: int) -> bool:
def header_prev_randao_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
"""
Returns true if the header must contain Prev Randao value
"""
pass

@classmethod
@abstractmethod
def header_zero_difficulty_required(cls, block_number: int, timestamp: int) -> bool:
def header_zero_difficulty_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
"""
Returns true if the header must have difficulty zero
"""
pass

@classmethod
@abstractmethod
def header_withdrawals_required(cls, block_number: int, timestamp: int) -> bool:
def header_withdrawals_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
"""
Returns true if the header must contain withdrawals
"""
pass

@classmethod
@abstractmethod
def header_excess_data_gas_required(cls, block_number: int, timestamp: int) -> bool:
def header_excess_data_gas_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
"""
Returns true if the header must contain excess data gas
"""
pass

@classmethod
@abstractmethod
def header_data_gas_used_required(cls, block_number: int, timestamp: int) -> bool:
def header_data_gas_used_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
"""
Returns true if the header must contain data gas used
"""
pass

@classmethod
@abstractmethod
def get_reward(cls, block_number: int, timestamp: int) -> int:
def get_reward(cls, block_number: int = 0, timestamp: int = 0) -> int:
"""
Returns the expected reward amount in wei of a given fork
"""
Expand All @@ -90,7 +98,9 @@ def get_reward(cls, block_number: int, timestamp: int) -> int:
# Engine API information abstract methods
@classmethod
@abstractmethod
def engine_new_payload_version(cls, block_number: int, timestamp: int) -> Optional[int]:
def engine_new_payload_version(
cls, block_number: int = 0, timestamp: int = 0
) -> Optional[int]:
"""
Returns `None` if this fork's payloads cannot be sent over the engine API,
or the payload version if it can.
Expand All @@ -99,7 +109,7 @@ def engine_new_payload_version(cls, block_number: int, timestamp: int) -> Option

@classmethod
@abstractmethod
def engine_new_payload_blob_hashes(cls, block_number: int, timestamp: int) -> bool:
def engine_new_payload_blob_hashes(cls, block_number: int = 0, timestamp: int = 0) -> bool:
"""
Returns true if the engine api version requires new payload calls to include blob hashes.
"""
Expand Down
59 changes: 37 additions & 22 deletions src/ethereum_test_forks/forks/forks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,63 +13,72 @@ class Frontier(BaseFork):
"""

@classmethod
def header_base_fee_required(cls, block_number: int, timestamp: int) -> bool:
def fork(cls, block_number: int = 0, timestamp: int = 0) -> str:
"""
Returns fork name as it's meant to be passed to the transition tool for execution.
"""
return cls.name()

@classmethod
def header_base_fee_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
"""
At genesis, header must not contain base fee
"""
return False

@classmethod
def header_prev_randao_required(cls, block_number: int, timestamp: int) -> bool:
def header_prev_randao_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
"""
At genesis, header must not contain Prev Randao value
"""
return False

@classmethod
def header_zero_difficulty_required(cls, block_number: int, timestamp: int) -> bool:
def header_zero_difficulty_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
"""
At genesis, header must not have difficulty zero
"""
return False

@classmethod
def header_withdrawals_required(cls, block_number: int, timestamp: int) -> bool:
def header_withdrawals_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
"""
At genesis, header must not contain withdrawals
"""
return False

@classmethod
def header_excess_data_gas_required(cls, block_number: int, timestamp: int) -> bool:
def header_excess_data_gas_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
"""
At genesis, header must not contain excess data gas
"""
return False

@classmethod
def header_data_gas_used_required(cls, block_number: int, timestamp: int) -> bool:
def header_data_gas_used_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
"""
At genesis, header must not contain data gas used
"""
return False

@classmethod
def engine_new_payload_version(cls, block_number: int, timestamp: int) -> Optional[int]:
def engine_new_payload_version(
cls, block_number: int = 0, timestamp: int = 0
) -> Optional[int]:
"""
At genesis, payloads cannot be sent through the engine API
"""
return None

@classmethod
def engine_new_payload_blob_hashes(cls, block_number: int, timestamp: int) -> bool:
def engine_new_payload_blob_hashes(cls, block_number: int = 0, timestamp: int = 0) -> bool:
"""
At genesis, payloads do not have blob hashes.
"""
return False

@classmethod
def get_reward(cls, block_number: int, timestamp: int) -> int:
def get_reward(cls, block_number: int = 0, timestamp: int = 0) -> int:
"""
At Genesis the expected reward amount in wei is
5_000_000_000_000_000_000
Expand All @@ -91,7 +100,7 @@ class Byzantium(Homestead):
"""

@classmethod
def get_reward(cls, block_number: int, timestamp: int) -> int:
def get_reward(cls, block_number: int = 0, timestamp: int = 0) -> int:
"""
At Byzantium, the block reward is reduced to
3_000_000_000_000_000_000 wei
Expand All @@ -105,7 +114,7 @@ class Constantinople(Byzantium):
"""

@classmethod
def get_reward(cls, block_number: int, timestamp: int) -> int:
def get_reward(cls, block_number: int = 0, timestamp: int = 0) -> int:
"""
At Constantinople, the block reward is reduced to
2_000_000_000_000_000_000 wei
Expand Down Expand Up @@ -152,7 +161,7 @@ class London(Berlin):
"""

@classmethod
def header_base_fee_required(cls, block_number: int, timestamp: int) -> bool:
def header_base_fee_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
"""
Base Fee is required starting from London.
"""
Expand Down Expand Up @@ -182,28 +191,30 @@ class Merge(London):
"""

@classmethod
def header_prev_randao_required(cls, block_number: int, timestamp: int) -> bool:
def header_prev_randao_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
"""
Prev Randao is required starting from Merge.
"""
return True

@classmethod
def header_zero_difficulty_required(cls, block_number: int, timestamp: int) -> bool:
def header_zero_difficulty_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
"""
Zero difficulty is required starting from Merge.
"""
return True

@classmethod
def get_reward(cls, block_number: int, timestamp: int) -> int:
def get_reward(cls, block_number: int = 0, timestamp: int = 0) -> int:
"""
Merge updates the reward to 0.
"""
return 0

@classmethod
def engine_new_payload_version(cls, block_number: int, timestamp: int) -> Optional[int]:
def engine_new_payload_version(
cls, block_number: int = 0, timestamp: int = 0
) -> Optional[int]:
"""
Starting at the merge, payloads can be sent through the engine API
"""
Expand All @@ -216,14 +227,16 @@ class Shanghai(Merge):
"""

@classmethod
def header_withdrawals_required(cls, block_number: int, timestamp: int) -> bool:
def header_withdrawals_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
"""
Withdrawals are required starting from Shanghai.
"""
return True

@classmethod
def engine_new_payload_version(cls, block_number: int, timestamp: int) -> Optional[int]:
def engine_new_payload_version(
cls, block_number: int = 0, timestamp: int = 0
) -> Optional[int]:
"""
Starting at Shanghai, new payload calls must use version 2
"""
Expand All @@ -244,28 +257,30 @@ def is_deployed(cls):
return False

@classmethod
def header_excess_data_gas_required(cls, block_number: int, timestamp: int) -> bool:
def header_excess_data_gas_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
"""
Excess data gas is required starting from Cancun.
"""
return True

@classmethod
def header_data_gas_used_required(cls, block_number: int, timestamp: int) -> bool:
def header_data_gas_used_required(cls, block_number: int = 0, timestamp: int = 0) -> bool:
"""
Data gas used is required starting from Cancun.
"""
return True

@classmethod
def engine_new_payload_version(cls, block_number: int, timestamp: int) -> Optional[int]:
def engine_new_payload_version(
cls, block_number: int = 0, timestamp: int = 0
) -> Optional[int]:
"""
Starting at Cancun, new payload calls must use version 3
"""
return 3

@classmethod
def engine_new_payload_blob_hashes(cls, block_number: int, timestamp: int) -> bool:
def engine_new_payload_blob_hashes(cls, block_number: int = 0, timestamp: int = 0) -> bool:
"""
Starting at Cancun, payloads must have blob hashes.
"""
Expand Down
54 changes: 8 additions & 46 deletions src/ethereum_test_forks/forks/transition.py
Original file line number Diff line number Diff line change
@@ -1,71 +1,33 @@
"""
List of all transition fork definitions.
"""
from typing import Optional

from ..transition_base_fork import transition_fork
from .forks import Berlin, Cancun, London, Merge, Shanghai


# Transition Forks
@transition_fork(to_fork=London)
@transition_fork(to_fork=London, at_block=5)
class BerlinToLondonAt5(Berlin):
"""
Berlin to London transition at Block 5 fork
Berlin to London transition at Block 5
"""

@classmethod
def header_base_fee_required(cls, block_number: int, _: int) -> bool:
"""
Base Fee is required starting from London.
"""
return block_number >= 5
pass


@transition_fork(to_fork=Shanghai)
@transition_fork(to_fork=Shanghai, at_timestamp=15_000)
class MergeToShanghaiAtTime15k(Merge):
"""
Merge to Shanghai transition at Timestamp 15k fork
Merge to Shanghai transition at Timestamp 15k
"""

@classmethod
def header_withdrawals_required(cls, _: int, timestamp: int) -> bool:
"""
Withdrawals are required starting from Shanghai.
"""
return timestamp >= 15_000

@classmethod
def engine_new_payload_version(cls, block_number: int, timestamp: int) -> Optional[int]:
"""
Starting at Shanghai, new payload calls must use version 2
"""
return 2 if timestamp >= 15_000 else 1
pass


@transition_fork(to_fork=Cancun)
@transition_fork(to_fork=Cancun, at_timestamp=15_000)
class ShanghaiToCancunAtTime15k(Shanghai):
"""
Shanghai to Cancun transition at Timestamp 15k
"""

@classmethod
def header_excess_data_gas_required(cls, _: int, timestamp: int) -> bool:
"""
Excess data gas is required if transitioning to Cancun.
"""
return timestamp >= 15_000

@classmethod
def engine_new_payload_version(cls, block_number: int, timestamp: int) -> Optional[int]:
"""
Starting at Cancun, new payload calls must use version 3
"""
return 3 if timestamp >= 15_000 else 2

@classmethod
def engine_new_payload_blob_hashes(cls, block_number: int, timestamp: int) -> bool:
"""
Starting at Cancun, payloads must have blob hashes.
"""
return timestamp >= 15_000
pass
Loading
Loading