diff --git a/pysetup/spec_builders/electra.py b/pysetup/spec_builders/electra.py index 6746d9aada..43362e4102 100644 --- a/pysetup/spec_builders/electra.py +++ b/pysetup/spec_builders/electra.py @@ -30,7 +30,8 @@ class NoopExecutionEngine(ExecutionEngine): def notify_new_payload(self: ExecutionEngine, execution_payload: ExecutionPayload, parent_beacon_block_root: Root, - execution_requests_list: Sequence[bytes]) -> bool: + execution_requests_list: Sequence[bytes], + target_blobs_per_block: uint64) -> bool: return True def notify_forkchoice_updated(self: ExecutionEngine, @@ -46,7 +47,9 @@ def get_payload(self: ExecutionEngine, payload_id: PayloadId) -> GetPayloadRespo def is_valid_block_hash(self: ExecutionEngine, execution_payload: ExecutionPayload, - parent_beacon_block_root: Root) -> bool: + parent_beacon_block_root: Root, + execution_requests_list: Sequence[bytes], + target_blobs_per_block: uint64) -> bool: return True def is_valid_versioned_hashes(self: ExecutionEngine, new_payload_request: NewPayloadRequest) -> bool: diff --git a/specs/_features/eip7594/beacon-chain.md b/specs/_features/eip7594/beacon-chain.md index 7ba88aa882..ffee297942 100644 --- a/specs/_features/eip7594/beacon-chain.md +++ b/specs/_features/eip7594/beacon-chain.md @@ -53,6 +53,7 @@ def process_execution_payload(state: BeaconState, body: BeaconBlockBody, executi versioned_hashes=versioned_hashes, parent_beacon_block_root=state.latest_block_header.parent_root, execution_requests=body.execution_requests, + target_blobs_per_block=MAX_BLOBS_PER_BLOCK // 2, ) ) # Cache execution payload header diff --git a/specs/_features/eip7732/beacon-chain.md b/specs/_features/eip7732/beacon-chain.md index 2303e33d40..df25fb43ac 100644 --- a/specs/_features/eip7732/beacon-chain.md +++ b/specs/_features/eip7732/beacon-chain.md @@ -705,6 +705,7 @@ def process_execution_payload(state: BeaconState, versioned_hashes=versioned_hashes, parent_beacon_block_root=state.latest_block_header.parent_root, execution_requests=requests, + target_blobs_per_block=MAX_BLOBS_PER_BLOCK // 2, ) ) diff --git a/specs/electra/beacon-chain.md b/specs/electra/beacon-chain.md index f14239c3f9..d61228bd31 100644 --- a/specs/electra/beacon-chain.md +++ b/specs/electra/beacon-chain.md @@ -79,6 +79,7 @@ - [Request data](#request-data) - [Modified `NewPayloadRequest`](#modified-newpayloadrequest) - [Engine APIs](#engine-apis) + - [Modified `is_valid_block_hash`](#modified-is_valid_block_hash) - [Modified `notify_new_payload`](#modified-notify_new_payload) - [Modified `verify_and_notify_new_payload`](#modified-verify_and_notify_new_payload) - [Block processing](#block-processing) @@ -1003,21 +1004,41 @@ class NewPayloadRequest(object): versioned_hashes: Sequence[VersionedHash] parent_beacon_block_root: Root execution_requests: ExecutionRequests # [New in Electra] + target_blobs_per_block: uint64 # [New in Electra:EIP7742] ``` #### Engine APIs +##### Modified `is_valid_block_hash` + +*Note*: The function `is_valid_block_hash` is modified to include the additional +`execution_requests_list` and `target_blobs_per_block` parameters in Electra. + +```python +def is_valid_block_hash(self: ExecutionEngine, + execution_payload: ExecutionPayload, + parent_beacon_block_root: Root, + execution_requests_list: Sequence[bytes], + target_blobs_per_block: uint64) -> bool: + """ + Return ``True`` if and only if ``execution_payload.block_hash`` is computed correctly. + """ + ... +``` + ##### Modified `notify_new_payload` -*Note*: The function `notify_new_payload` is modified to include the additional `execution_requests` parameter in Electra. +*Note*: The function `notify_new_payload` is modified to include the additional +`execution_requests_list` and `target_blobs_per_block` parameters in Electra. ```python def notify_new_payload(self: ExecutionEngine, execution_payload: ExecutionPayload, parent_beacon_block_root: Root, - execution_requests_list: Sequence[bytes]) -> bool: + execution_requests_list: Sequence[bytes], + target_blobs_per_block: uint64) -> bool: """ - Return ``True`` if and only if ``execution_payload`` and ``execution_requests`` + Return ``True`` if and only if ``execution_payload`` and ``execution_requests_list`` are valid with respect to ``self.execution_state``. """ ... @@ -1025,8 +1046,9 @@ def notify_new_payload(self: ExecutionEngine, ##### Modified `verify_and_notify_new_payload` -*Note*: The function `verify_and_notify_new_payload` is modified to pass the additional parameter `execution_requests` -when calling `notify_new_payload` in Electra. +*Note*: The function `verify_and_notify_new_payload` is modified to pass the additional parameters +`execution_requests_list` and `target_blobs_per_block` when calling `is_valid_block_hash` and +`notify_new_payload` in Electra. ```python def verify_and_notify_new_payload(self: ExecutionEngine, @@ -1037,11 +1059,17 @@ def verify_and_notify_new_payload(self: ExecutionEngine, execution_payload = new_payload_request.execution_payload parent_beacon_block_root = new_payload_request.parent_beacon_block_root execution_requests_list = get_execution_requests_list(new_payload_request.execution_requests) # [New in Electra] + target_blobs_per_block = new_payload_request.target_blobs_per_block # [New in Electra:EIP7742] if b'' in execution_payload.transactions: return False - if not self.is_valid_block_hash(execution_payload, parent_beacon_block_root): + # [Modified in Electra] + if not self.is_valid_block_hash( + execution_payload, + parent_beacon_block_root, + execution_requests_list, + target_blobs_per_block): return False if not self.is_valid_versioned_hashes(new_payload_request): @@ -1051,7 +1079,8 @@ def verify_and_notify_new_payload(self: ExecutionEngine, if not self.notify_new_payload( execution_payload, parent_beacon_block_root, - execution_requests_list): + execution_requests_list, + target_blobs_per_block): return False return True @@ -1213,6 +1242,7 @@ def process_execution_payload(state: BeaconState, body: BeaconBlockBody, executi versioned_hashes=versioned_hashes, parent_beacon_block_root=state.latest_block_header.parent_root, execution_requests=body.execution_requests, # [New in Electra] + target_blobs_per_block=MAX_BLOBS_PER_BLOCK // 2, # [New in Electra:EIP7742] ) ) # Cache execution payload header diff --git a/specs/electra/fork-choice.md b/specs/electra/fork-choice.md new file mode 100644 index 0000000000..8530239325 --- /dev/null +++ b/specs/electra/fork-choice.md @@ -0,0 +1,38 @@ +# Electra -- Fork Choice + +## Table of contents + + + + +- [Introduction](#introduction) +- [Containers](#containers) +- [Helpers](#helpers) + - [Extended `PayloadAttributes`](#extended-payloadattributes) + + + + +## Introduction + +This is the modification of the fork choice accompanying the Electra upgrade. + +## Containers + +## Helpers + +### Extended `PayloadAttributes` + +*Note*: `PayloadAttributes` is extended with the target/maximum number of blobs per block. + +```python +@dataclass +class PayloadAttributes(object): + timestamp: uint64 + prev_randao: Bytes32 + suggested_fee_recipient: ExecutionAddress + withdrawals: Sequence[Withdrawal] + parent_beacon_block_root: Root + target_blobs_per_block: uint64 # [New in Electra:EIP7742] + max_blobs_per_block: uint64 # [New in Electra:EIP7742] +``` diff --git a/specs/electra/validator.md b/specs/electra/validator.md index 2e980d5345..77476cf394 100644 --- a/specs/electra/validator.md +++ b/specs/electra/validator.md @@ -176,6 +176,8 @@ def prepare_execution_payload(state: BeaconState, suggested_fee_recipient=suggested_fee_recipient, withdrawals=withdrawals, parent_beacon_block_root=hash_tree_root(state.latest_block_header), + target_blobs_per_block=MAX_BLOBS_PER_BLOCK // 2, # [New in Electra:EIP7742] + max_blobs_per_block=MAX_BLOBS_PER_BLOCK, # [New in Electra:EIP7742] ) return execution_engine.notify_forkchoice_updated( head_block_hash=parent_hash,