Skip to content

Commit

Permalink
Fix tests from 7251 and merge of other EIPs into Electra
Browse files Browse the repository at this point in the history
  • Loading branch information
ralexstokes committed Apr 16, 2024
1 parent 034909d commit c0fa05d
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 243 deletions.
6 changes: 1 addition & 5 deletions specs/electra/beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -588,11 +588,7 @@ def initiate_validator_exit(state: BeaconState, index: ValidatorIndex) -> None:
def switch_to_compounding_validator(state: BeaconState, index: ValidatorIndex) -> None:
validator = state.validators[index]
if has_eth1_withdrawal_credential(validator):
validator.withdrawal_credentials = (
COMPOUNDING_WITHDRAWAL_PREFIX
+ b'\x00' * 11
+ validator.withdrawal_credentials[20:]
)
validator.withdrawal_credentials = COMPOUNDING_WITHDRAWAL_PREFIX + validator.withdrawal_credentials[1:]
queue_excess_active_balance(state, index)
```

Expand Down
10 changes: 8 additions & 2 deletions specs/electra/fork.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,14 @@ def upgrade_to_electra(pre: deneb.BeaconState) -> BeaconState:
blob_gas_used=pre.latest_execution_payload_header.blob_gas_used,
excess_blob_gas=pre.latest_execution_payload_header.excess_blob_gas,
deposit_receipts_root=Root(), # [New in Electra:EIP6110]
exits_root=Root(), # [New in Electra:EIP7002],
withdrawal_requests_root=Root(), # [New in Electra:EIP7002],
)

exit_epochs = [v.exit_epoch for v in pre.validators if v.exit_epoch != FAR_FUTURE_EPOCH]
if not exit_epochs:
exit_epochs = [get_current_epoch(pre)]
earliest_exit_epoch = max(exit_epochs) + 1

post = BeaconState(
# Versioning
genesis_time=pre.genesis_time,
Expand Down Expand Up @@ -144,7 +150,7 @@ def upgrade_to_electra(pre: deneb.BeaconState) -> BeaconState:
# [New in Electra:EIP7251]
deposit_balance_to_consume=0,
exit_balance_to_consume=get_activation_exit_churn_limit(pre),
earliest_exit_epoch=max([v.exit_epoch for v in pre.validators if v.exit_epoch != FAR_FUTURE_EPOCH]) + 1,
earliest_exit_epoch=earliest_exit_epoch,
consolidation_balance_to_consume=get_consolidation_churn_limit(pre),
earliest_consolidation_epoch=compute_activation_exit_epoch(get_current_epoch(pre)),
pending_balance_deposits=[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_new_deposit_min(spec, state):
def test_new_deposit_between_min_and_max(spec, state):
# fresh deposit = next validator index = validator appended to registry
validator_index = len(state.validators)
amount = spec.MAX_EFFECTIVE_BALANCE_electra // 2
amount = spec.MAX_EFFECTIVE_BALANCE_ELECTRA // 2
deposit = prepare_state_and_deposit(spec, state, validator_index, amount, signed=True)
yield from run_deposit_processing(spec, state, deposit, validator_index)

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

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

Expand All @@ -71,16 +71,16 @@ def test_new_deposit_over_max(spec, state):
# @spec_state_test
# def test_top_up__max_effective_balance(spec, state):
# validator_index = 0
# amount = spec.MAX_EFFECTIVE_BALANCE_electra // 4
# amount = spec.MAX_EFFECTIVE_BALANCE_ELECTRA // 4
# deposit = prepare_state_and_deposit(spec, state, validator_index, amount, signed=True)

# state.balances[validator_index] = spec.MAX_EFFECTIVE_BALANCE_electra
# state.validators[validator_index].effective_balance = spec.MAX_EFFECTIVE_BALANCE_electra
# state.balances[validator_index] = spec.MAX_EFFECTIVE_BALANCE_ELECTRA
# state.validators[validator_index].effective_balance = spec.MAX_EFFECTIVE_BALANCE_ELECTRA

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

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

@with_electra_and_later
@spec_state_test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ def test_top_up__max_effective_balance(spec, state):

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

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


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

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

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

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

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

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

Expand Down Expand Up @@ -273,10 +276,18 @@ def test_success_top_up_to_withdrawn_validator(spec, state):

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

assert state.balances[validator_index] == amount
deposits_len = len(state.pending_balance_deposits)
assert state.pending_balance_deposits[deposits_len - 1].amount == amount
assert state.validators[validator_index].effective_balance == 0

validator = state.validators[validator_index]
balance = state.balances[validator_index]

pending_balance_deposits_len = len(state.pending_balance_deposits)
pending_balance_deposit = state.pending_balance_deposits[pending_balance_deposits_len - 1]
current_epoch = spec.get_current_epoch(state)
assert spec.is_fully_withdrawable_validator(validator, balance, current_epoch)
has_execution_withdrawal = spec.has_execution_withdrawal_credential(validator)
is_withdrawable = validator.withdrawable_epoch <= current_epoch
has_non_zero_balance = pending_balance_deposit.amount > 0
# NOTE: directly compute `is_fully_withdrawable_validator` conditions here
# to work around how the epoch processing changed balance updates
assert has_execution_withdrawal and is_withdrawable and has_non_zero_balance

This file was deleted.

Loading

0 comments on commit c0fa05d

Please sign in to comment.