Skip to content

Commit c0fa05d

Browse files
committed
Fix tests from 7251 and merge of other EIPs into Electra
1 parent 034909d commit c0fa05d

File tree

11 files changed

+155
-243
lines changed

11 files changed

+155
-243
lines changed

specs/electra/beacon-chain.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -588,11 +588,7 @@ def initiate_validator_exit(state: BeaconState, index: ValidatorIndex) -> None:
588588
def switch_to_compounding_validator(state: BeaconState, index: ValidatorIndex) -> None:
589589
validator = state.validators[index]
590590
if has_eth1_withdrawal_credential(validator):
591-
validator.withdrawal_credentials = (
592-
COMPOUNDING_WITHDRAWAL_PREFIX
593-
+ b'\x00' * 11
594-
+ validator.withdrawal_credentials[20:]
595-
)
591+
validator.withdrawal_credentials = COMPOUNDING_WITHDRAWAL_PREFIX + validator.withdrawal_credentials[1:]
596592
queue_excess_active_balance(state, index)
597593
```
598594

specs/electra/fork.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,14 @@ def upgrade_to_electra(pre: deneb.BeaconState) -> BeaconState:
9191
blob_gas_used=pre.latest_execution_payload_header.blob_gas_used,
9292
excess_blob_gas=pre.latest_execution_payload_header.excess_blob_gas,
9393
deposit_receipts_root=Root(), # [New in Electra:EIP6110]
94-
exits_root=Root(), # [New in Electra:EIP7002],
94+
withdrawal_requests_root=Root(), # [New in Electra:EIP7002],
9595
)
96+
97+
exit_epochs = [v.exit_epoch for v in pre.validators if v.exit_epoch != FAR_FUTURE_EPOCH]
98+
if not exit_epochs:
99+
exit_epochs = [get_current_epoch(pre)]
100+
earliest_exit_epoch = max(exit_epochs) + 1
101+
96102
post = BeaconState(
97103
# Versioning
98104
genesis_time=pre.genesis_time,
@@ -144,7 +150,7 @@ def upgrade_to_electra(pre: deneb.BeaconState) -> BeaconState:
144150
# [New in Electra:EIP7251]
145151
deposit_balance_to_consume=0,
146152
exit_balance_to_consume=get_activation_exit_churn_limit(pre),
147-
earliest_exit_epoch=max([v.exit_epoch for v in pre.validators if v.exit_epoch != FAR_FUTURE_EPOCH]) + 1,
153+
earliest_exit_epoch=earliest_exit_epoch,
148154
consolidation_balance_to_consume=get_consolidation_churn_limit(pre),
149155
earliest_consolidation_epoch=compute_activation_exit_epoch(get_current_epoch(pre)),
150156
pending_balance_deposits=[],

tests/core/pyspec/eth2spec/test/electra/block_processing/test_process_deposit.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_new_deposit_min(spec, state):
4141
def test_new_deposit_between_min_and_max(spec, state):
4242
# fresh deposit = next validator index = validator appended to registry
4343
validator_index = len(state.validators)
44-
amount = spec.MAX_EFFECTIVE_BALANCE_electra // 2
44+
amount = spec.MAX_EFFECTIVE_BALANCE_ELECTRA // 2
4545
deposit = prepare_state_and_deposit(spec, state, validator_index, amount, signed=True)
4646
yield from run_deposit_processing(spec, state, deposit, validator_index)
4747

@@ -52,7 +52,7 @@ def test_new_deposit_max(spec, state):
5252
# fresh deposit = next validator index = validator appended to registry
5353
validator_index = len(state.validators)
5454
# effective balance will be exactly the same as balance.
55-
amount = spec.MAX_EFFECTIVE_BALANCE_electra
55+
amount = spec.MAX_EFFECTIVE_BALANCE_ELECTRA
5656
deposit = prepare_state_and_deposit(spec, state, validator_index, amount, signed=True)
5757
yield from run_deposit_processing(spec, state, deposit, validator_index)
5858

@@ -62,7 +62,7 @@ def test_new_deposit_max(spec, state):
6262
def test_new_deposit_over_max(spec, state):
6363
# fresh deposit = next validator index = validator appended to registry
6464
validator_index = len(state.validators)
65-
amount = spec.MAX_EFFECTIVE_BALANCE_electra + 1
65+
amount = spec.MAX_EFFECTIVE_BALANCE_ELECTRA + 1
6666
deposit = prepare_state_and_deposit(spec, state, validator_index, amount, signed=True)
6767
yield from run_deposit_processing(spec, state, deposit, validator_index)
6868

@@ -71,16 +71,16 @@ def test_new_deposit_over_max(spec, state):
7171
# @spec_state_test
7272
# def test_top_up__max_effective_balance(spec, state):
7373
# validator_index = 0
74-
# amount = spec.MAX_EFFECTIVE_BALANCE_electra // 4
74+
# amount = spec.MAX_EFFECTIVE_BALANCE_ELECTRA // 4
7575
# deposit = prepare_state_and_deposit(spec, state, validator_index, amount, signed=True)
7676

77-
# state.balances[validator_index] = spec.MAX_EFFECTIVE_BALANCE_electra
78-
# state.validators[validator_index].effective_balance = spec.MAX_EFFECTIVE_BALANCE_electra
77+
# state.balances[validator_index] = spec.MAX_EFFECTIVE_BALANCE_ELECTRA
78+
# state.validators[validator_index].effective_balance = spec.MAX_EFFECTIVE_BALANCE_ELECTRA
7979

8080
# yield from run_deposit_processing(spec, state, deposit, validator_index)
8181

82-
# assert state.balances[validator_index] == spec.MAX_EFFECTIVE_BALANCE_electra + amount
83-
# assert state.validators[validator_index].effective_balance == spec.MAX_EFFECTIVE_BALANCE_electra
82+
# assert state.balances[validator_index] == spec.MAX_EFFECTIVE_BALANCE_ELECTRA + amount
83+
# assert state.validators[validator_index].effective_balance == spec.MAX_EFFECTIVE_BALANCE_ELECTRA
8484

8585
@with_electra_and_later
8686
@spec_state_test

tests/core/pyspec/eth2spec/test/electra/block_processing/test_process_deposit_receipt.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ def test_top_up__max_effective_balance(spec, state):
122122

123123
yield from run_deposit_receipt_processing(spec, state, deposit_receipt, validator_index)
124124

125-
assert state.balances[validator_index] == spec.MAX_EFFECTIVE_BALANCE + amount
125+
deposits_len = len(state.pending_balance_deposits)
126+
assert state.pending_balance_deposits[deposits_len - 1].amount == amount
126127
assert state.validators[validator_index].effective_balance == spec.MAX_EFFECTIVE_BALANCE
127128

128129

@@ -140,7 +141,8 @@ def test_top_up__less_effective_balance(spec, state):
140141

141142
yield from run_deposit_receipt_processing(spec, state, deposit_receipt, validator_index)
142143

143-
assert state.balances[validator_index] == initial_balance + amount
144+
deposits_len = len(state.pending_balance_deposits)
145+
assert state.pending_balance_deposits[deposits_len - 1].amount == amount
144146
# unchanged effective balance
145147
assert state.validators[validator_index].effective_balance == initial_effective_balance
146148

@@ -159,7 +161,8 @@ def test_top_up__zero_balance(spec, state):
159161

160162
yield from run_deposit_receipt_processing(spec, state, deposit_receipt, validator_index)
161163

162-
assert state.balances[validator_index] == initial_balance + amount
164+
deposits_len = len(state.pending_balance_deposits)
165+
assert state.pending_balance_deposits[deposits_len - 1].amount == amount
163166
# unchanged effective balance
164167
assert state.validators[validator_index].effective_balance == initial_effective_balance
165168

@@ -273,10 +276,18 @@ def test_success_top_up_to_withdrawn_validator(spec, state):
273276

274277
yield from run_deposit_receipt_processing(spec, state, deposit_receipt, validator_index)
275278

276-
assert state.balances[validator_index] == amount
279+
deposits_len = len(state.pending_balance_deposits)
280+
assert state.pending_balance_deposits[deposits_len - 1].amount == amount
277281
assert state.validators[validator_index].effective_balance == 0
278282

279283
validator = state.validators[validator_index]
280-
balance = state.balances[validator_index]
284+
285+
pending_balance_deposits_len = len(state.pending_balance_deposits)
286+
pending_balance_deposit = state.pending_balance_deposits[pending_balance_deposits_len - 1]
281287
current_epoch = spec.get_current_epoch(state)
282-
assert spec.is_fully_withdrawable_validator(validator, balance, current_epoch)
288+
has_execution_withdrawal = spec.has_execution_withdrawal_credential(validator)
289+
is_withdrawable = validator.withdrawable_epoch <= current_epoch
290+
has_non_zero_balance = pending_balance_deposit.amount > 0
291+
# NOTE: directly compute `is_fully_withdrawable_validator` conditions here
292+
# to work around how the epoch processing changed balance updates
293+
assert has_execution_withdrawal and is_withdrawable and has_non_zero_balance

tests/core/pyspec/eth2spec/test/electra/block_processing/test_process_execution_layer_exit.py

Lines changed: 0 additions & 107 deletions
This file was deleted.

0 commit comments

Comments
 (0)