Skip to content

Commit 31349a2

Browse files
fix ethspecify
1 parent fb81493 commit 31349a2

File tree

2 files changed

+117
-77
lines changed

2 files changed

+117
-77
lines changed

specrefs/dataclasses.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,46 @@
3737
blobs: List[Blob, MAX_BLOB_COMMITMENTS_PER_BLOCK]
3838
</spec>
3939
40+
- name: ExpectedWithdrawals#capella
41+
sources:
42+
- file: ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/withdrawals/WithdrawalsHelpers.java
43+
search: record ExpectedWithdrawals(
44+
spec: |
45+
<spec dataclass="ExpectedWithdrawals" fork="capella" hash="73becb4c">
46+
class ExpectedWithdrawals(object):
47+
withdrawals: Sequence[Withdrawal]
48+
processed_sweep_withdrawals_count: uint64
49+
</spec>
50+
51+
- name: ExpectedWithdrawals#electra
52+
sources:
53+
- file: ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/withdrawals/WithdrawalsHelpers.java
54+
search: record ExpectedWithdrawals(
55+
spec: |
56+
<spec dataclass="ExpectedWithdrawals" fork="electra" hash="a3827f01">
57+
class ExpectedWithdrawals(object):
58+
withdrawals: Sequence[Withdrawal]
59+
# [New in Electra:EIP7251]
60+
processed_partial_withdrawals_count: uint64
61+
processed_sweep_withdrawals_count: uint64
62+
</spec>
63+
64+
- name: ExpectedWithdrawals#gloas
65+
sources:
66+
- file: ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/withdrawals/WithdrawalsHelpers.java
67+
search: record ExpectedWithdrawals(
68+
spec: |
69+
<spec dataclass="ExpectedWithdrawals" fork="gloas" hash="b32cc9c9">
70+
class ExpectedWithdrawals(object):
71+
withdrawals: Sequence[Withdrawal]
72+
# [New in Gloas:EIP7732]
73+
processed_builder_withdrawals_count: uint64
74+
processed_partial_withdrawals_count: uint64
75+
# [New in Gloas:EIP7732]
76+
processed_builders_sweep_count: uint64
77+
processed_sweep_withdrawals_count: uint64
78+
</spec>
79+
4080
- name: GetPayloadResponse#bellatrix
4181
sources:
4282
- file: ethereum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/execution/GetPayloadResponse.java

specrefs/functions.yml

Lines changed: 77 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -3711,8 +3711,8 @@
37113711
- file: ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/capella/withdrawals/WithdrawalsHelpersCapella.java
37123712
search: public ExpectedWithdrawals getExpectedWithdrawals(
37133713
spec: |
3714-
<spec fn="get_expected_withdrawals" fork="capella" hash="d6a98c14">
3715-
def get_expected_withdrawals(state: BeaconState) -> Tuple[Sequence[Withdrawal], uint64]:
3714+
<spec fn="get_expected_withdrawals" fork="capella" hash="12088347">
3715+
def get_expected_withdrawals(state: BeaconState) -> ExpectedWithdrawals:
37163716
withdrawal_index = state.next_withdrawal_index
37173717
withdrawals: List[Withdrawal] = []
37183718

@@ -3722,16 +3722,19 @@
37223722
)
37233723
withdrawals.extend(validators_sweep_withdrawals)
37243724

3725-
return withdrawals, processed_validators_sweep_count
3725+
return ExpectedWithdrawals(
3726+
withdrawals,
3727+
processed_validators_sweep_count,
3728+
)
37263729
</spec>
37273730

37283731
- name: get_expected_withdrawals#electra
37293732
sources:
37303733
- file: ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/capella/withdrawals/WithdrawalsHelpersCapella.java
37313734
search: public ExpectedWithdrawals getExpectedWithdrawals(
37323735
spec: |
3733-
<spec fn="get_expected_withdrawals" fork="electra" hash="cfce862b">
3734-
def get_expected_withdrawals(state: BeaconState) -> Tuple[Sequence[Withdrawal], uint64, uint64]:
3736+
<spec fn="get_expected_withdrawals" fork="electra" hash="254541e3">
3737+
def get_expected_withdrawals(state: BeaconState) -> ExpectedWithdrawals:
37353738
withdrawal_index = state.next_withdrawal_index
37363739
withdrawals: List[Withdrawal] = []
37373740

@@ -3748,17 +3751,19 @@
37483751
)
37493752
withdrawals.extend(validators_sweep_withdrawals)
37503753

3751-
# [Modified in Electra:EIP7251]
3752-
return withdrawals, processed_partial_withdrawals_count, processed_validators_sweep_count
3754+
return ExpectedWithdrawals(
3755+
withdrawals,
3756+
# [New in Electra:EIP7251]
3757+
processed_partial_withdrawals_count,
3758+
processed_validators_sweep_count,
3759+
)
37533760
</spec>
37543761

37553762
- name: get_expected_withdrawals#gloas
37563763
sources: []
37573764
spec: |
3758-
<spec fn="get_expected_withdrawals" fork="gloas" hash="950fb815">
3759-
def get_expected_withdrawals(
3760-
state: BeaconState,
3761-
) -> Tuple[Sequence[Withdrawal], uint64, uint64, uint64, uint64]:
3765+
<spec fn="get_expected_withdrawals" fork="gloas" hash="8d0675cb">
3766+
def get_expected_withdrawals(state: BeaconState) -> ExpectedWithdrawals:
37623767
withdrawal_index = state.next_withdrawal_index
37633768
withdrawals: List[Withdrawal] = []
37643769

@@ -3788,11 +3793,12 @@
37883793
)
37893794
withdrawals.extend(validators_sweep_withdrawals)
37903795

3791-
# [Modified in Gloas:EIP7732]
3792-
return (
3796+
return ExpectedWithdrawals(
37933797
withdrawals,
3798+
# [New in Gloas:EIP7732]
37943799
processed_builder_withdrawals_count,
37953800
processed_partial_withdrawals_count,
3801+
# [New in Gloas:EIP7732]
37963802
processed_builders_sweep_count,
37973803
processed_validators_sweep_count,
37983804
)
@@ -7314,10 +7320,10 @@
73147320
- name: prepare_execution_payload#capella
73157321
sources: []
73167322
spec: |
7317-
<spec fn="prepare_execution_payload" fork="capella" style="diff" hash="c258893e">
7323+
<spec fn="prepare_execution_payload" fork="capella" style="diff" hash="998e8b92">
73187324
--- bellatrix
73197325
+++ capella
7320-
@@ -4,28 +4,16 @@
7326+
@@ -4,28 +4,14 @@
73217327
finalized_block_hash: Hash32,
73227328
suggested_fee_recipient: ExecutionAddress,
73237329
execution_engine: ExecutionEngine,
@@ -7331,21 +7337,20 @@
73317337
- )
73327338
- if is_terminal_block_hash_set and not is_activation_epoch_reached:
73337339
- return None
7334-
+ parent_hash = state.latest_execution_payload_header.block_hash
7335-
7340+
-
73367341
- terminal_pow_block = get_terminal_pow_block(pow_chain)
73377342
- if terminal_pow_block is None:
73387343
- return None
73397344
- parent_hash = terminal_pow_block.block_hash
73407345
- else:
73417346
- parent_hash = state.latest_execution_payload_header.block_hash
7342-
+ withdrawals, _ = get_expected_withdrawals(state)
7347+
+ parent_hash = state.latest_execution_payload_header.block_hash
73437348

73447349
payload_attributes = PayloadAttributes(
73457350
timestamp=compute_time_at_slot(state, state.slot),
73467351
prev_randao=get_randao_mix(state, get_current_epoch(state)),
73477352
suggested_fee_recipient=suggested_fee_recipient,
7348-
+ withdrawals=withdrawals,
7353+
+ withdrawals=get_expected_withdrawals(state).withdrawals,
73497354
)
73507355
return execution_engine.notify_forkchoice_updated(
73517356
head_block_hash=parent_hash,
@@ -7354,13 +7359,13 @@
73547359
- name: prepare_execution_payload#deneb
73557360
sources: []
73567361
spec: |
7357-
<spec fn="prepare_execution_payload" fork="deneb" style="diff" hash="59f61f3a">
7362+
<spec fn="prepare_execution_payload" fork="deneb" style="diff" hash="c617aa1b">
73587363
--- capella
73597364
+++ deneb
7360-
@@ -14,6 +14,7 @@
7365+
@@ -12,6 +12,7 @@
73617366
prev_randao=get_randao_mix(state, get_current_epoch(state)),
73627367
suggested_fee_recipient=suggested_fee_recipient,
7363-
withdrawals=withdrawals,
7368+
withdrawals=get_expected_withdrawals(state).withdrawals,
73647369
+ parent_beacon_block_root=hash_tree_root(state.latest_block_header),
73657370
)
73667371
return execution_engine.notify_forkchoice_updated(
@@ -7370,43 +7375,40 @@
73707375
- name: prepare_execution_payload#electra
73717376
sources: []
73727377
spec: |
7373-
<spec fn="prepare_execution_payload" fork="electra" style="diff" hash="5414b883">
7374-
--- deneb
7378+
<spec fn="prepare_execution_payload" fork="electra" style="diff" hash="c617aa1b">
7379+
--- capella
73757380
+++ electra
7376-
@@ -7,7 +7,7 @@
7377-
) -> Optional[PayloadId]:
7378-
parent_hash = state.latest_execution_payload_header.block_hash
7379-
7380-
- withdrawals, _ = get_expected_withdrawals(state)
7381-
+ withdrawals, _, _ = get_expected_withdrawals(state)
7382-
7383-
payload_attributes = PayloadAttributes(
7384-
timestamp=compute_time_at_slot(state, state.slot),
7381+
@@ -12,6 +12,7 @@
7382+
prev_randao=get_randao_mix(state, get_current_epoch(state)),
7383+
suggested_fee_recipient=suggested_fee_recipient,
7384+
withdrawals=get_expected_withdrawals(state).withdrawals,
7385+
+ parent_beacon_block_root=hash_tree_root(state.latest_block_header),
7386+
)
7387+
return execution_engine.notify_forkchoice_updated(
7388+
head_block_hash=parent_hash,
73857389
</spec>
73867390

73877391
- name: prepare_execution_payload#gloas
73887392
sources: []
73897393
spec: |
7390-
<spec fn="prepare_execution_payload" fork="gloas" hash="8fdad5cf">
7394+
<spec fn="prepare_execution_payload" fork="gloas" hash="c617aa1b">
73917395
def prepare_execution_payload(
73927396
state: BeaconState,
73937397
safe_block_hash: Hash32,
73947398
finalized_block_hash: Hash32,
73957399
suggested_fee_recipient: ExecutionAddress,
73967400
execution_engine: ExecutionEngine,
73977401
) -> Optional[PayloadId]:
7398-
# Verify consistency of the parent hash with respect to the previous execution payload bid
7399-
parent_hash = state.latest_execution_payload_bid.block_hash
7402+
# Verify consistency of the parent hash with respect to the previous execution payload header
7403+
parent_hash = state.latest_execution_payload_header.block_hash
74007404

7401-
# [Modified in Gloas:EIP7732]
74027405
# Set the forkchoice head and initiate the payload build process
7403-
withdrawals, _, _, _, _ = get_expected_withdrawals(state)
7404-
74057406
payload_attributes = PayloadAttributes(
74067407
timestamp=compute_time_at_slot(state, state.slot),
74077408
prev_randao=get_randao_mix(state, get_current_epoch(state)),
74087409
suggested_fee_recipient=suggested_fee_recipient,
7409-
withdrawals=withdrawals,
7410+
withdrawals=get_expected_withdrawals(state).withdrawals,
7411+
# [New in Deneb:EIP4788]
74107412
parent_beacon_block_root=hash_tree_root(state.latest_block_header),
74117413
)
74127414
return execution_engine.notify_forkchoice_updated(
@@ -9912,50 +9914,47 @@
99129914
- file: ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/capella/block/BlockProcessorCapella.java
99139915
search: public void processWithdrawals(
99149916
spec: |
9915-
<spec fn="process_withdrawals" fork="capella" hash="901f9fc4">
9917+
<spec fn="process_withdrawals" fork="capella" hash="47327ef6">
99169918
def process_withdrawals(state: BeaconState, payload: ExecutionPayload) -> None:
99179919
# Get expected withdrawals
9918-
withdrawals, processed_validators_sweep_count = get_expected_withdrawals(state)
9919-
assert payload.withdrawals == withdrawals
9920+
expected = get_expected_withdrawals(state)
9921+
assert payload.withdrawals == expected.withdrawals
99209922

99219923
# Apply expected withdrawals
9922-
apply_withdrawals(state, withdrawals)
9924+
apply_withdrawals(state, expected.withdrawals)
99239925

99249926
# Update withdrawals fields in the state
9925-
update_next_withdrawal_index(state, withdrawals)
9926-
update_next_withdrawal_validator_index(state, processed_validators_sweep_count)
9927+
update_next_withdrawal_index(state, expected.withdrawals)
9928+
update_next_withdrawal_validator_index(state, expected.withdrawals)
99279929
</spec>
99289930

99299931
- name: process_withdrawals#electra
99309932
sources:
99319933
- file: ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/capella/block/BlockProcessorCapella.java
99329934
search: public void processWithdrawals(
99339935
spec: |
9934-
<spec fn="process_withdrawals" fork="electra" hash="67870972">
9936+
<spec fn="process_withdrawals" fork="electra" hash="24a50daa">
99359937
def process_withdrawals(state: BeaconState, payload: ExecutionPayload) -> None:
9936-
# [Modified in Electra:EIP7251]
99379938
# Get expected withdrawals
9938-
withdrawals, processed_partial_withdrawals_count, processed_validators_sweep_count = (
9939-
get_expected_withdrawals(state)
9940-
)
9941-
assert payload.withdrawals == withdrawals
9939+
expected = get_expected_withdrawals(state)
9940+
assert payload.withdrawals == expected.withdrawals
99429941

99439942
# Apply expected withdrawals
9944-
apply_withdrawals(state, withdrawals)
9943+
apply_withdrawals(state, expected.withdrawals)
99459944

99469945
# Update withdrawals fields in the state
9947-
update_next_withdrawal_index(state, withdrawals)
9946+
update_next_withdrawal_index(state, expected.withdrawals)
99489947
# [New in Electra:EIP7251]
9949-
update_pending_partial_withdrawals(state, processed_partial_withdrawals_count)
9950-
update_next_withdrawal_validator_index(state, processed_validators_sweep_count)
9948+
update_pending_partial_withdrawals(state, expected.processed_partial_withdrawals_count)
9949+
update_next_withdrawal_validator_index(state, expected.withdrawals)
99519950
</spec>
99529951

99539952
- name: process_withdrawals#gloas
99549953
sources:
99559954
- file: ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/gloas/withdrawals/WithdrawalsHelpersGloas.java
99569955
search: public void processWithdrawals(
99579956
spec: |
9958-
<spec fn="process_withdrawals" fork="gloas" hash="3caee596">
9957+
<spec fn="process_withdrawals" fork="gloas" hash="16d9ad2a">
99599958
def process_withdrawals(
99609959
state: BeaconState,
99619960
# [Modified in Gloas:EIP7732]
@@ -9966,29 +9965,22 @@
99669965
if not is_parent_block_full(state):
99679966
return
99689967

9969-
# [Modified in Gloas:EIP7732]
99709968
# Get expected withdrawals
9971-
(
9972-
withdrawals,
9973-
processed_builder_withdrawals_count,
9974-
processed_partial_withdrawals_count,
9975-
processed_builders_sweep_count,
9976-
processed_validators_sweep_count,
9977-
) = get_expected_withdrawals(state)
9969+
expected = get_expected_withdrawals(state)
99789970

99799971
# Apply expected withdrawals
9980-
apply_withdrawals(state, withdrawals)
9972+
apply_withdrawals(state, expected.withdrawals)
99819973

99829974
# Update withdrawals fields in the state
9983-
update_next_withdrawal_index(state, withdrawals)
9975+
update_next_withdrawal_index(state, expected.withdrawals)
99849976
# [New in Gloas:EIP7732]
9985-
update_payload_expected_withdrawals(state, withdrawals)
9977+
update_payload_expected_withdrawals(state, expected.withdrawals)
99869978
# [New in Gloas:EIP7732]
9987-
update_builder_pending_withdrawals(state, processed_builder_withdrawals_count)
9988-
update_pending_partial_withdrawals(state, processed_partial_withdrawals_count)
9979+
update_builder_pending_withdrawals(state, expected.processed_builder_withdrawals_count)
9980+
update_pending_partial_withdrawals(state, expected.processed_partial_withdrawals_count)
99899981
# [New in Gloas:EIP7732]
9990-
update_next_withdrawal_builder_index(state, processed_builders_sweep_count)
9991-
update_next_withdrawal_validator_index(state, processed_validators_sweep_count)
9982+
update_next_withdrawal_builder_index(state, expected.processed_builders_sweep_count)
9983+
update_next_withdrawal_validator_index(state, expected.withdrawals)
99929984
</spec>
99939985

99949986
- name: queue_excess_active_balance#electra
@@ -10690,14 +10682,22 @@
1069010682
- file: ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/capella/withdrawals/WithdrawalsHelpersCapella.java
1069110683
search: protected void updateNextWithdrawalValidatorIndex(
1069210684
spec: |
10693-
<spec fn="update_next_withdrawal_validator_index" fork="capella" hash="98095ea6">
10685+
<spec fn="update_next_withdrawal_validator_index" fork="capella" hash="4a3ee635">
1069410686
def update_next_withdrawal_validator_index(
10695-
state: BeaconState, processed_validators_sweep_count: uint64
10687+
state: BeaconState, withdrawals: Sequence[Withdrawal]
1069610688
) -> None:
1069710689
# Update the next validator index to start the next withdrawal sweep
10698-
next_index = state.next_withdrawal_validator_index + processed_validators_sweep_count
10699-
next_validator_index = ValidatorIndex(next_index % len(state.validators))
10700-
state.next_withdrawal_validator_index = next_validator_index
10690+
if len(withdrawals) == MAX_WITHDRAWALS_PER_PAYLOAD:
10691+
# Next sweep starts after the latest withdrawal's validator index
10692+
next_validator_index = ValidatorIndex(
10693+
(withdrawals[-1].validator_index + 1) % len(state.validators)
10694+
)
10695+
state.next_withdrawal_validator_index = next_validator_index
10696+
else:
10697+
# Advance sweep by the max length of the sweep if there was not a full set of withdrawals
10698+
next_index = state.next_withdrawal_validator_index + MAX_VALIDATORS_PER_WITHDRAWALS_SWEEP
10699+
next_validator_index = ValidatorIndex(next_index % len(state.validators))
10700+
state.next_withdrawal_validator_index = next_validator_index
1070110701
</spec>
1070210702

1070310703
- name: update_payload_expected_withdrawals#gloas

0 commit comments

Comments
 (0)