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

Moving requests out of execution_payload into beacon_block.body #3875

Merged
merged 25 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
355a9a3
Introducing ExecutionPayloadEnvelope
lucassaldanha Aug 9, 2024
ed9b061
Comments
lucassaldanha Aug 9, 2024
f26c9be
Removing EL requests from ExecutionPayload
lucassaldanha Aug 11, 2024
f9ac902
Updated light-client block -> header function
lucassaldanha Aug 11, 2024
e26a3e0
New execution payload global index
lucassaldanha Aug 11, 2024
9a2e088
requests_root
lucassaldanha Aug 12, 2024
858402f
Updated with requests on block body
lucassaldanha Aug 13, 2024
794b942
Undo execution_payload gsync change
lucassaldanha Aug 13, 2024
5c88de8
Remove requests in execution_payload from full-node lightclient spec
lucassaldanha Aug 13, 2024
6669675
Test updates
lucassaldanha Aug 13, 2024
4185c00
Fork fix and tests
lucassaldanha Aug 13, 2024
fa78e0d
PR comments
lucassaldanha Aug 13, 2024
e3ec53f
Fix lint
lucassaldanha Aug 13, 2024
3527a9b
Cleaning unchanged ExecutionPayload
lucassaldanha Aug 14, 2024
b84316d
PR Comments
lucassaldanha Aug 16, 2024
98dd188
Rename requests to execution_requests
lucassaldanha Aug 16, 2024
dc1892e
Updated NewPayloadRequest
lucassaldanha Aug 22, 2024
b8ca7cc
PR comments
lucassaldanha Aug 22, 2024
e445cdf
Merge branch 'dev' into 3865
lucassaldanha Sep 1, 2024
38baa57
Rename ExecutionLayerRequests to ExecutionRequests
lucassaldanha Sep 1, 2024
31225f1
Temp fix for linter on eip-7732 beacon chain spec
lucassaldanha Sep 2, 2024
abf382a
Fix 7732
potuz Sep 4, 2024
beff03d
Updated verify_and_notify_new_payload and notify_new_payload
lucassaldanha Sep 5, 2024
c8dd790
Fix linter
lucassaldanha Sep 5, 2024
622ccd1
Updated ElectraSpecBuilder (NoopExecutionEngine#notify_new_payload)
lucassaldanha Sep 5, 2024
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
158 changes: 40 additions & 118 deletions specs/electra/beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
- [`WithdrawalRequest`](#withdrawalrequest)
- [`ConsolidationRequest`](#consolidationrequest)
- [`PendingConsolidation`](#pendingconsolidation)
- [`ValidatorRequests`](#validatorrequests)
- [Modified Containers](#modified-containers)
- [`AttesterSlashing`](#attesterslashing)
- [`BeaconBlockBody`](#beaconblockbody)
- [Extended Containers](#extended-containers)
- [`Attestation`](#attestation)
- [`IndexedAttestation`](#indexedattestation)
- [`BeaconBlockBody`](#beaconblockbody)
- [`ExecutionPayload`](#executionpayload)
- [`ExecutionPayloadHeader`](#executionpayloadheader)
- [`BeaconState`](#beaconstate)
- [Helper functions](#helper-functions)
- [Predicates](#predicates)
Expand Down Expand Up @@ -78,8 +78,6 @@
- [Withdrawals](#withdrawals)
- [Modified `get_expected_withdrawals`](#modified-get_expected_withdrawals)
- [Modified `process_withdrawals`](#modified-process_withdrawals)
- [Execution payload](#execution-payload)
- [Modified `process_execution_payload`](#modified-process_execution_payload)
- [Operations](#operations)
- [Modified `process_operations`](#modified-process_operations)
- [Attestations](#attestations)
Expand Down Expand Up @@ -258,6 +256,15 @@ class PendingConsolidation(Container):
target_index: ValidatorIndex
```

#### `ValidatorRequests`

```python
class ValidatorRequests(Container):
lucassaldanha marked this conversation as resolved.
Show resolved Hide resolved
deposit_requests: List[DepositRequest, MAX_DEPOSIT_REQUESTS_PER_PAYLOAD] # [New in Electra:EIP6110]
lucassaldanha marked this conversation as resolved.
Show resolved Hide resolved
withdrawal_requests: List[WithdrawalRequest, MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD] # [New in Electra:EIP7002:EIP7251]
lucassaldanha marked this conversation as resolved.
Show resolved Hide resolved
consolidation_requests: List[ConsolidationRequest, MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD] # [New in Electra:EIP7251]
```

### Modified Containers

#### `AttesterSlashing`
Expand All @@ -268,6 +275,27 @@ class AttesterSlashing(Container):
attestation_2: IndexedAttestation # [Modified in Electra:EIP7549]
```

#### `BeaconBlockBody`

```python
class BeaconBlockBody(Container):
randao_reveal: BLSSignature
eth1_data: Eth1Data # Eth1 data vote
graffiti: Bytes32 # Arbitrary data
# Operations
proposer_slashings: List[ProposerSlashing, MAX_PROPOSER_SLASHINGS]
attester_slashings: List[AttesterSlashing, MAX_ATTESTER_SLASHINGS_ELECTRA] # [Modified in Electra:EIP7549]
attestations: List[Attestation, MAX_ATTESTATIONS_ELECTRA] # [Modified in Electra:EIP7549]
deposits: List[Deposit, MAX_DEPOSITS]
voluntary_exits: List[SignedVoluntaryExit, MAX_VOLUNTARY_EXITS]
sync_aggregate: SyncAggregate
# Execution
execution_payload: ExecutionPayload
bls_to_execution_changes: List[SignedBLSToExecutionChange, MAX_BLS_TO_EXECUTION_CHANGES]
blob_kzg_commitments: List[KZGCommitment, MAX_BLOB_COMMITMENTS_PER_BLOCK]
requests: ValidatorRequests # [New in Electra:EIP????]
lucassaldanha marked this conversation as resolved.
Show resolved Hide resolved
```

### Extended Containers

#### `Attestation`
Expand All @@ -290,26 +318,6 @@ class IndexedAttestation(Container):
signature: BLSSignature
```

#### `BeaconBlockBody`

```python
class BeaconBlockBody(Container):
randao_reveal: BLSSignature
eth1_data: Eth1Data # Eth1 data vote
graffiti: Bytes32 # Arbitrary data
# Operations
proposer_slashings: List[ProposerSlashing, MAX_PROPOSER_SLASHINGS]
attester_slashings: List[AttesterSlashing, MAX_ATTESTER_SLASHINGS_ELECTRA] # [Modified in Electra:EIP7549]
attestations: List[Attestation, MAX_ATTESTATIONS_ELECTRA] # [Modified in Electra:EIP7549]
deposits: List[Deposit, MAX_DEPOSITS]
voluntary_exits: List[SignedVoluntaryExit, MAX_VOLUNTARY_EXITS]
sync_aggregate: SyncAggregate
# Execution
execution_payload: ExecutionPayload # [Modified in Electra:EIP6110:EIP7002]
bls_to_execution_changes: List[SignedBLSToExecutionChange, MAX_BLS_TO_EXECUTION_CHANGES]
blob_kzg_commitments: List[KZGCommitment, MAX_BLOB_COMMITMENTS_PER_BLOCK]
```

#### `ExecutionPayload`
lucassaldanha marked this conversation as resolved.
Show resolved Hide resolved

```python
Expand All @@ -333,39 +341,6 @@ class ExecutionPayload(Container):
withdrawals: List[Withdrawal, MAX_WITHDRAWALS_PER_PAYLOAD]
blob_gas_used: uint64
excess_blob_gas: uint64
deposit_requests: List[DepositRequest, MAX_DEPOSIT_REQUESTS_PER_PAYLOAD] # [New in Electra:EIP6110]
# [New in Electra:EIP7002:EIP7251]
withdrawal_requests: List[WithdrawalRequest, MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD]
# [New in Electra:EIP7251]
consolidation_requests: List[ConsolidationRequest, MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD]
```

#### `ExecutionPayloadHeader`

```python
class ExecutionPayloadHeader(Container):
# Execution block header fields
parent_hash: Hash32
fee_recipient: ExecutionAddress
state_root: Bytes32
receipts_root: Bytes32
logs_bloom: ByteVector[BYTES_PER_LOGS_BLOOM]
prev_randao: Bytes32
block_number: uint64
gas_limit: uint64
gas_used: uint64
timestamp: uint64
extra_data: ByteList[MAX_EXTRA_DATA_BYTES]
base_fee_per_gas: uint256
# Extra payload fields
block_hash: Hash32
transactions_root: Root
withdrawals_root: Root
blob_gas_used: uint64
excess_blob_gas: uint64
deposit_requests_root: Root # [New in Electra:EIP6110]
withdrawal_requests_root: Root # [New in Electra:EIP7002:EIP7251]
consolidation_requests_root: Root # [New in Electra:EIP7251]
```

#### `BeaconState`
Expand Down Expand Up @@ -875,7 +850,7 @@ def process_pending_balance_deposits(state: BeaconState) -> None:
if processed_amount + deposit.amount > available_for_processing:
break
# Deposit fits in the churn, process it. Increase balance and consume churn.
else:
else:
increase_balance(state, deposit.index, deposit.amount)
processed_amount += deposit.amount
# Regardless of how the deposit was handled, we move on in the queue.
Expand Down Expand Up @@ -946,8 +921,8 @@ def process_effective_balance_updates(state: BeaconState) -> None:
```python
def process_block(state: BeaconState, block: BeaconBlock) -> None:
process_block_header(state, block)
process_withdrawals(state, block.body.execution_payload) # [Modified in Electra:EIP7251]
process_execution_payload(state, block.body, EXECUTION_ENGINE) # [Modified in Electra:EIP6110]
process_withdrawals(state, block.body.execution_payload) # [Modified in Electra:EIP7251:EIP????]
lucassaldanha marked this conversation as resolved.
Show resolved Hide resolved
process_execution_payload(state, block.body, EXECUTION_ENGINE) # [Modified in Electra:EIP6110:EIP????]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
process_execution_payload(state, block.body, EXECUTION_ENGINE) # [Modified in Electra:EIP6110:EIP????]
process_execution_payload(state, block.body, EXECUTION_ENGINE)

process_randao(state, block.body)
process_eth1_data(state, block.body)
process_operations(state, block.body) # [Modified in Electra:EIP6110:EIP7002:EIP7549:EIP7251]
Expand Down Expand Up @@ -1047,59 +1022,6 @@ def process_withdrawals(state: BeaconState, payload: ExecutionPayload) -> None:
next_validator_index = ValidatorIndex(next_index % len(state.validators))
state.next_withdrawal_validator_index = next_validator_index
```

#### Execution payload

##### Modified `process_execution_payload`

*Note*: The function `process_execution_payload` is modified to use the new `ExecutionPayloadHeader` type.

```python
def process_execution_payload(state: BeaconState, body: BeaconBlockBody, execution_engine: ExecutionEngine) -> None:
payload = body.execution_payload

# Verify consistency of the parent hash with respect to the previous execution payload header
assert payload.parent_hash == state.latest_execution_payload_header.block_hash
# Verify prev_randao
assert payload.prev_randao == get_randao_mix(state, get_current_epoch(state))
# Verify timestamp
assert payload.timestamp == compute_timestamp_at_slot(state, state.slot)
# Verify commitments are under limit
assert len(body.blob_kzg_commitments) <= MAX_BLOBS_PER_BLOCK
# Verify the execution payload is valid
versioned_hashes = [kzg_commitment_to_versioned_hash(commitment) for commitment in body.blob_kzg_commitments]
assert execution_engine.verify_and_notify_new_payload(
NewPayloadRequest(
execution_payload=payload,
ralexstokes marked this conversation as resolved.
Show resolved Hide resolved
versioned_hashes=versioned_hashes,
parent_beacon_block_root=state.latest_block_header.parent_root,
)
)
# Cache execution payload header
state.latest_execution_payload_header = ExecutionPayloadHeader(
parent_hash=payload.parent_hash,
fee_recipient=payload.fee_recipient,
state_root=payload.state_root,
receipts_root=payload.receipts_root,
logs_bloom=payload.logs_bloom,
prev_randao=payload.prev_randao,
block_number=payload.block_number,
gas_limit=payload.gas_limit,
gas_used=payload.gas_used,
timestamp=payload.timestamp,
extra_data=payload.extra_data,
base_fee_per_gas=payload.base_fee_per_gas,
block_hash=payload.block_hash,
transactions_root=hash_tree_root(payload.transactions),
withdrawals_root=hash_tree_root(payload.withdrawals),
blob_gas_used=payload.blob_gas_used,
excess_blob_gas=payload.excess_blob_gas,
deposit_requests_root=hash_tree_root(payload.deposit_requests), # [New in Electra:EIP6110]
withdrawal_requests_root=hash_tree_root(payload.withdrawal_requests), # [New in Electra:EIP7002:EIP7251]
consolidation_requests_root=hash_tree_root(payload.consolidation_requests), # [New in Electra:EIP7251]
)
```

#### Operations

##### Modified `process_operations`
Expand All @@ -1126,11 +1048,11 @@ def process_operations(state: BeaconState, body: BeaconBlockBody) -> None:
for_ops(body.deposits, process_deposit) # [Modified in Electra:EIP7251]
for_ops(body.voluntary_exits, process_voluntary_exit) # [Modified in Electra:EIP7251]
for_ops(body.bls_to_execution_changes, process_bls_to_execution_change)
for_ops(body.execution_payload.deposit_requests, process_deposit_request) # [New in Electra:EIP6110]
# [New in Electra:EIP7002:EIP7251]
for_ops(body.execution_payload.withdrawal_requests, process_withdrawal_request)
# [New in Electra:EIP7251]
for_ops(body.execution_payload.consolidation_requests, process_consolidation_request)
for_ops(body.requests.deposit_requests, process_deposit_request) # [New in Electra:EIP6110:EIP????]
lucassaldanha marked this conversation as resolved.
Show resolved Hide resolved
# [New in Electra:EIP7002:EIP7251:EIP????]
lucassaldanha marked this conversation as resolved.
Show resolved Hide resolved
for_ops(body.requests.withdrawal_requests, process_withdrawal_request)
# [New in Electra:EIP7251:EIP????]
lucassaldanha marked this conversation as resolved.
Show resolved Hide resolved
for_ops(body.requests.consolidation_requests, process_consolidation_request)
```

##### Attestations
Expand Down
6 changes: 0 additions & 6 deletions specs/electra/light-client/full-node.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ def block_to_light_client_header(block: SignedBeaconBlock) -> LightClientHeader:
execution_header.blob_gas_used = payload.blob_gas_used
execution_header.excess_blob_gas = payload.excess_blob_gas

# [New in Electra:EIP6110:EIP7002:EIP7251]
if epoch >= ELECTRA_FORK_EPOCH:
execution_header.deposit_requests_root = hash_tree_root(payload.deposit_requests)
execution_header.withdrawal_requests_root = hash_tree_root(payload.withdrawal_requests)
execution_header.consolidation_requests_root = hash_tree_root(payload.consolidation_requests)

execution_branch = ExecutionBranch(
compute_merkle_proof(block.message.body, EXECUTION_PAYLOAD_GINDEX))
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_basic_el_withdrawal_request(spec, state):
validator_pubkey=validator_pubkey,
)
block = build_empty_block_for_next_slot(spec, state)
block.body.execution_payload.withdrawal_requests = [withdrawal_request]
block.body.requests.withdrawal_requests = [withdrawal_request]
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload, state)
signed_block = state_transition_and_sign_block(spec, state, block)

Expand Down Expand Up @@ -77,7 +77,7 @@ def test_basic_btec_and_el_withdrawal_request_in_same_block(spec, state):
source_address=address,
validator_pubkey=validator_pubkey,
)
block.body.execution_payload.withdrawal_requests = [withdrawal_request]
block.body.requests.withdrawal_requests = [withdrawal_request]

block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload, state)
signed_block = state_transition_and_sign_block(spec, state, block)
Expand Down Expand Up @@ -130,7 +130,7 @@ def test_basic_btec_before_el_withdrawal_request(spec, state):
validator_pubkey=validator_pubkey,
)
block_2 = build_empty_block_for_next_slot(spec, state)
block_2.body.execution_payload.withdrawal_requests = [withdrawal_request]
block_2.body.requests.withdrawal_requests = [withdrawal_request]
block_2.body.execution_payload.block_hash = compute_el_block_hash(spec, block_2.body.execution_payload, state)
signed_block_2 = state_transition_and_sign_block(spec, state, block_2)

Expand Down Expand Up @@ -163,7 +163,7 @@ def test_cl_exit_and_el_withdrawal_request_in_same_block(spec, state):
)
block = build_empty_block_for_next_slot(spec, state)
block.body.voluntary_exits = signed_voluntary_exits
block.body.execution_payload.withdrawal_requests = [withdrawal_request]
block.body.requests.withdrawal_requests = [withdrawal_request]
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload, state)
signed_block = state_transition_and_sign_block(spec, state, block)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def run_deposit_transition_block(spec, state, block, top_up_keys=[], valid=True)
# Check that deposits are applied
if valid:
expected_pubkeys = [d.data.pubkey for d in block.body.deposits]
deposit_requests = block.body.execution_payload.deposit_requests
deposit_requests = block.body.requests.deposit_requests
expected_pubkeys = expected_pubkeys + [d.pubkey for d in deposit_requests if (d.pubkey not in top_up_keys)]
actual_pubkeys = [v.pubkey for v in state.validators[len(state.validators) - len(expected_pubkeys):]]

Expand Down Expand Up @@ -102,7 +102,7 @@ def prepare_state_and_block(spec,

# Assign deposits and deposit requests
block.body.deposits = deposits
block.body.execution_payload.deposit_requests = deposit_requests
block.body.requests.deposit_requests = deposit_requests
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload, state)

return state, block
Expand All @@ -120,7 +120,7 @@ def test_deposit_transition__start_index_is_set(spec, state):
yield from run_deposit_transition_block(spec, state, block)

# deposit_requests_start_index must be set to the index of the first request
assert state.deposit_requests_start_index == block.body.execution_payload.deposit_requests[0].index
assert state.deposit_requests_start_index == block.body.requests.deposit_requests[0].index


@with_phases([ELECTRA])
Expand Down Expand Up @@ -219,7 +219,7 @@ def test_deposit_transition__deposit_and_top_up_same_block(spec, state):

# Artificially assign deposit's pubkey to a deposit request of the same block
top_up_keys = [block.body.deposits[0].data.pubkey]
block.body.execution_payload.deposit_requests[0].pubkey = top_up_keys[0]
block.body.requests.deposit_requests[0].pubkey = top_up_keys[0]
block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload, state)

pre_pending_deposits = len(state.pending_balance_deposits)
Expand All @@ -229,5 +229,5 @@ def test_deposit_transition__deposit_and_top_up_same_block(spec, state):
# Check the top up
assert len(state.pending_balance_deposits) == pre_pending_deposits + 2
assert state.pending_balance_deposits[pre_pending_deposits].amount == block.body.deposits[0].data.amount
amount_from_deposit = block.body.execution_payload.deposit_requests[0].amount
amount_from_deposit = block.body.requests.deposit_requests[0].amount
assert state.pending_balance_deposits[pre_pending_deposits + 1].amount == amount_from_deposit
7 changes: 6 additions & 1 deletion tests/core/pyspec/eth2spec/test/helpers/block.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from eth2spec.test.helpers.execution_payload import build_empty_execution_payload
from eth2spec.test.helpers.execution_payload import build_empty_signed_execution_payload_header
from eth2spec.test.helpers.forks import is_post_whisk, is_post_altair, is_post_bellatrix, is_post_eip7732
from eth2spec.test.helpers.forks import is_post_whisk, is_post_altair, is_post_bellatrix, is_post_eip7732, is_post_electra
from eth2spec.test.helpers.keys import privkeys, whisk_ks_initial, whisk_ks_final
from eth2spec.utils import bls
from eth2spec.utils.bls import only_with_bls
Expand Down Expand Up @@ -126,6 +126,11 @@ def build_empty_block(spec, state, slot=None, proposer_index=None):
if is_post_bellatrix(spec):
empty_block.body.execution_payload = build_empty_execution_payload(spec, state)

if is_post_electra(spec):
empty_block.body.requests.deposit_requests = []
mkalinin marked this conversation as resolved.
Show resolved Hide resolved
empty_block.body.requests.withdrawal_requests = []
empty_block.body.requests.consolidation_requests = []

if is_post_whisk(spec):
# Whisk opening proof
#######
Expand Down
Loading