Skip to content

Commit 093f5f3

Browse files
committed
EIP-7742: uncouple blob counts across CL and EL
1 parent 43d96cf commit 093f5f3

File tree

4 files changed

+134
-6
lines changed

4 files changed

+134
-6
lines changed

pysetup/spec_builders/electra.py

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,53 @@ class ElectraSpecBuilder(BaseSpecBuilder):
88

99
@classmethod
1010
def imports(cls, preset_name: str):
11-
return f'''
11+
return f"""
1212
from eth2spec.deneb import {preset_name} as deneb
13-
'''
13+
"""
1414

15-
## TODO: deal with changed gindices
15+
@classmethod
16+
def execution_engine_cls(cls) -> str:
17+
return """
18+
class NoopExecutionEngine(ExecutionEngine):
19+
20+
def notify_new_payload(self: ExecutionEngine,
21+
execution_payload: ExecutionPayload,
22+
parent_beacon_block_root: Root,
23+
target_blobs_per_block: uint64) -> bool:
24+
return True
25+
26+
def notify_forkchoice_updated(self: ExecutionEngine,
27+
head_block_hash: Hash32,
28+
safe_block_hash: Hash32,
29+
finalized_block_hash: Hash32,
30+
payload_attributes: Optional[PayloadAttributes]) -> Optional[PayloadId]:
31+
pass
32+
33+
def get_payload(self: ExecutionEngine, payload_id: PayloadId) -> GetPayloadResponse:
34+
# pylint: disable=unused-argument
35+
raise NotImplementedError("no default block production")
36+
37+
def is_valid_block_hash(self: ExecutionEngine,
38+
execution_payload: ExecutionPayload,
39+
parent_beacon_block_root: Root) -> bool:
40+
return True
41+
42+
def is_valid_versioned_hashes(self: ExecutionEngine, new_payload_request: NewPayloadRequest) -> bool:
43+
return True
44+
45+
def verify_and_notify_new_payload(self: ExecutionEngine,
46+
new_payload_request: NewPayloadRequest) -> bool:
47+
return True
48+
49+
50+
EXECUTION_ENGINE = NoopExecutionEngine()"""
51+
52+
## TODO: deal with changed gindices
1653

1754
@classmethod
1855
def hardcoded_ssz_dep_constants(cls) -> Dict[str, str]:
1956
return {
20-
'FINALIZED_ROOT_GINDEX': 'GeneralizedIndex(169)',
21-
'CURRENT_SYNC_COMMITTEE_GINDEX': 'GeneralizedIndex(86)',
22-
'NEXT_SYNC_COMMITTEE_GINDEX': 'GeneralizedIndex(87)',
57+
"FINALIZED_ROOT_GINDEX": "GeneralizedIndex(169)",
58+
"CURRENT_SYNC_COMMITTEE_GINDEX": "GeneralizedIndex(86)",
59+
"NEXT_SYNC_COMMITTEE_GINDEX": "GeneralizedIndex(87)",
2360
}

specs/electra/beacon-chain.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@
6767
- [New `compute_consolidation_epoch_and_update_churn`](#new-compute_consolidation_epoch_and_update_churn)
6868
- [Updated `slash_validator`](#updated-slash_validator)
6969
- [Beacon chain state transition function](#beacon-chain-state-transition-function)
70+
- [Execution engine](#execution-engine)
71+
- [Request data](#request-data)
72+
- [Engine APIs](#engine-apis)
73+
- [Modified `notify_new_payload`](#modified-notify_new_payload)
74+
- [Modified `verify_and_notify_new_payload`](#modified-verify_and_notify_new_payload)
7075
- [Epoch processing](#epoch-processing)
7176
- [Updated `process_epoch`](#updated-process_epoch)
7277
- [Updated `process_registry_updates`](#updated--process_registry_updates)
@@ -758,6 +763,54 @@ def slash_validator(state: BeaconState,
758763

759764
## Beacon chain state transition function
760765

766+
### Execution engine
767+
768+
#### Request data
769+
770+
#### Engine APIs
771+
772+
##### Modified `notify_new_payload`
773+
774+
*Note*: The function `notify_new_payload` is modified to include the target number of blobs
775+
allowed per block.
776+
777+
```python
778+
def notify_new_payload(self: ExecutionEngine,
779+
execution_payload: ExecutionPayload,
780+
parent_beacon_block_root: Root,
781+
target_blobs_per_block: uint64) -> bool:
782+
"""
783+
Return ``True`` if and only if ``execution_payload`` is valid with respect to ``self.execution_state``.
784+
"""
785+
...
786+
```
787+
788+
##### Modified `verify_and_notify_new_payload`
789+
790+
```python
791+
def verify_and_notify_new_payload(self: ExecutionEngine,
792+
new_payload_request: NewPayloadRequest) -> bool:
793+
"""
794+
Return ``True`` if and only if ``new_payload_request`` is valid with respect to ``self.execution_state``.
795+
"""
796+
execution_payload = new_payload_request.execution_payload
797+
parent_beacon_block_root = new_payload_request.parent_beacon_block_root
798+
799+
if not self.is_valid_block_hash(execution_payload, parent_beacon_block_root):
800+
return False
801+
802+
if not self.is_valid_versioned_hashes(new_payload_request):
803+
return False
804+
805+
# [Modified in Electra]
806+
if not self.notify_new_payload(execution_payload,
807+
parent_beacon_block_root,
808+
MAX_BLOBS_PER_BLOCK // 2):
809+
return False
810+
811+
return True
812+
```
813+
761814
### Epoch processing
762815

763816
#### Updated `process_epoch`

specs/electra/fork-choice.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Electra -- Fork Choice
2+
3+
## Table of contents
4+
<!-- TOC -->
5+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
6+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
7+
8+
- [Introduction](#introduction)
9+
- [Containers](#containers)
10+
- [Helpers](#helpers)
11+
- [Extended `PayloadAttributes`](#extended-payloadattributes)
12+
13+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
14+
<!-- /TOC -->
15+
16+
## Introduction
17+
18+
This is the modification of the fork choice accompanying the Electra upgrade.
19+
20+
## Containers
21+
22+
## Helpers
23+
24+
### Extended `PayloadAttributes`
25+
26+
`PayloadAttributes` is extended with the maximum number of blobs per block.
27+
28+
```python
29+
@dataclass
30+
class PayloadAttributes(object):
31+
timestamp: uint64
32+
prev_randao: Bytes32
33+
suggested_fee_recipient: ExecutionAddress
34+
withdrawals: Sequence[Withdrawal]
35+
parent_beacon_block_root: Root
36+
target_blobs_per_block: uint64 # [New in Electra]
37+
```

specs/electra/validator.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ def prepare_execution_payload(state: BeaconState,
139139
suggested_fee_recipient=suggested_fee_recipient,
140140
withdrawals=withdrawals,
141141
parent_beacon_block_root=hash_tree_root(state.latest_block_header),
142+
target_blobs_per_block=MAX_BLOBS_PER_BLOCK // 2, # [New in Electra]
142143
)
143144
return execution_engine.notify_forkchoice_updated(
144145
head_block_hash=parent_hash,

0 commit comments

Comments
 (0)