Skip to content

Commit cf65c29

Browse files
authored
Use slot from header instead of bid (#5554)
On Discord, @potuz suggested we use the slot from `state.latest_block_header` instead of `state.latest_execution_payload_bid`. This is a bit simpler, as we do not need to cache the parent slot in `process_execution_payload_bid`.
1 parent cf58354 commit cf65c29

6 files changed

Lines changed: 18 additions & 23 deletions

File tree

specs/_features/eip8148/beacon-chain.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ def apply_parent_execution_payload(
498498
requests: ExecutionRequests,
499499
) -> None:
500500
parent_bid = state.latest_execution_payload_bid
501-
parent_slot = parent_bid.slot
501+
parent_slot = state.latest_block_header.slot
502502
parent_epoch = compute_epoch_at_slot(parent_slot)
503503

504504
assert len(requests.withdrawals) <= MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD

specs/gloas/beacon-chain.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,6 +1697,9 @@ def process_ptc_window(state: BeaconState) -> None:
16971697

16981698
```python
16991699
def process_block(state: BeaconState, block: BeaconBlock) -> None:
1700+
# [New in Gloas:EIP7732]
1701+
parent_slot = state.latest_block_header.slot
1702+
17001703
# [New in Gloas:EIP7732]
17011704
process_parent_execution_payload(state, block)
17021705
process_block_header(state, block)
@@ -1705,7 +1708,7 @@ def process_block(state: BeaconState, block: BeaconBlock) -> None:
17051708
# [Modified in Gloas:EIP7732]
17061709
# Removed `process_execution_payload`
17071710
# [New in Gloas:EIP7732]
1708-
parent_slot = process_execution_payload_bid(state, block.body.signed_execution_payload_bid)
1711+
process_execution_payload_bid(state, block.body.signed_execution_payload_bid)
17091712
process_randao(state, block.body)
17101713
process_eth1_data(state, block.body)
17111714
# [Modified in Gloas:EIP7732]
@@ -1728,7 +1731,7 @@ def apply_parent_execution_payload(
17281731
requests: ExecutionRequests,
17291732
) -> None:
17301733
parent_bid = state.latest_execution_payload_bid
1731-
parent_slot = parent_bid.slot
1734+
parent_slot = state.latest_block_header.slot
17321735
parent_epoch = compute_epoch_at_slot(parent_slot)
17331736

17341737
assert len(requests.withdrawals) <= MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD
@@ -2080,14 +2083,10 @@ def verify_execution_payload_bid_signature(
20802083

20812084
##### New `process_execution_payload_bid`
20822085

2083-
*Note*: This function returns the slot of the parent block, read from the bid in
2084-
the state before it is overwritten by the new bid. The slot is later given to
2085-
`process_attestation` to look up the payload availability of the attested block.
2086-
20872086
```python
20882087
def process_execution_payload_bid(
20892088
state: BeaconState, signed_bid: SignedExecutionPayloadBid
2090-
) -> Slot:
2089+
) -> None:
20912090
bid = signed_bid.message
20922091
builder_index = bid.builder_index
20932092
amount = bid.value
@@ -2135,13 +2134,8 @@ def process_execution_payload_bid(
21352134
pending_payment
21362135
)
21372136

2138-
# Cache the parent block's slot before overwriting the bid
2139-
parent_slot = state.latest_execution_payload_bid.slot
2140-
21412137
# Cache the signed execution payload bid
21422138
state.latest_execution_payload_bid = bid
2143-
2144-
return parent_slot
21452139
```
21462140

21472141
#### Operations

tests/core/pyspec/eth_consensus_specs/test/gloas/block_processing/test_process_attestation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ def test_old_attested_block_gets_head_flag(spec, state):
502502
state, attestation_slot
503503
)
504504
# The genesis payload was never revealed, which matches data.index == 0
505-
parent_slot = state.latest_execution_payload_bid.slot
505+
parent_slot = state.latest_block_header.slot
506506
assert parent_slot == 0
507507
assert not state.execution_payload_availability[parent_slot % spec.SLOTS_PER_HISTORICAL_ROOT]
508508

@@ -545,7 +545,7 @@ def test_builder_payment_weight_tracking_previous_epoch(spec, state):
545545
state,
546546
attestation.data,
547547
state.slot - attestation.data.slot,
548-
state.latest_execution_payload_bid.slot,
548+
state.latest_block_header.slot,
549549
)
550550
pre_prev_flags = state.previous_epoch_participation[attester]
551551
pre_curr_flags = state.current_epoch_participation[attester]

tests/core/pyspec/eth_consensus_specs/test/gloas/block_processing/test_process_parent_execution_payload.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ def _commit_full_parent_with_payment(spec, state, value, builder_index, fee_reci
5151
Commit a FULL parent with a builder payment at slot ``SLOTS_PER_EPOCH - 1``.
5252
Clear its availability bit.
5353
"""
54-
state.latest_execution_payload_bid.slot = spec.Slot(spec.SLOTS_PER_EPOCH - 1)
54+
parent_slot = spec.Slot(spec.SLOTS_PER_EPOCH - 1)
55+
state.latest_block_header.slot = parent_slot
56+
state.latest_execution_payload_bid.slot = parent_slot
5557
state.latest_execution_payload_bid.fee_recipient = fee_recipient
5658
_commit_parent_requests(
5759
spec, state, spec.ExecutionRequests(), value=value, builder_index=builder_index
@@ -94,7 +96,7 @@ def test_process_parent_execution_payload__empty_parent(spec, state):
9496
assert not is_parent_block_full
9597

9698
pre_latest_block_hash = state.latest_block_hash
97-
parent_slot = state.latest_execution_payload_bid.slot
99+
parent_slot = state.latest_block_header.slot
98100
pre_availability = state.execution_payload_availability[
99101
parent_slot % spec.SLOTS_PER_HISTORICAL_ROOT
100102
]

tests/core/pyspec/eth_consensus_specs/test/helpers/attestations.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818

1919

2020
def get_parent_slot(state):
21-
# Outside of block processing, the bid in the state is still the
22-
# parent block's bid, so its slot is the parent block's slot.
23-
return state.latest_execution_payload_bid.slot
21+
return state.latest_block_header.slot
2422

2523

2624
def process_attestation(spec, state, attestation):

tests/core/pyspec/eth_consensus_specs/test/phase0/sanity/test_blocks.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ def process_and_sign_block_without_header_validations(spec, state, block):
165165
WARNING UNSAFE: Only use when generating valid-looking invalid blocks for test vectors
166166
"""
167167

168+
# Cache the parent slot before overwriting the header, as `process_block` does
169+
parent_slot = state.latest_block_header.slot
170+
168171
# Perform single mutation in `process_block_header`
169172
state.latest_block_header = spec.BeaconBlockHeader(
170173
slot=block.slot,
@@ -186,9 +189,7 @@ def process_and_sign_block_without_header_validations(spec, state, block):
186189
spec.process_randao(state, block.body)
187190
spec.process_eth1_data(state, block.body)
188191
if is_post_gloas(spec):
189-
# The bid is not processed here, so the bid in the state is still
190-
# the parent block's bid and its slot is the parent block's slot.
191-
spec.process_operations(state, block.body, state.latest_execution_payload_bid.slot)
192+
spec.process_operations(state, block.body, parent_slot)
192193
else:
193194
spec.process_operations(state, block.body)
194195
if is_post_altair(spec):

0 commit comments

Comments
 (0)