Update `ExecutionLayerExit` fields: replace `validator_index` with `validator_pubkey`
This commit is contained in:
parent
6e08327d1f
commit
a11cc094ee
|
@ -53,7 +53,7 @@ This mechanism relies on the changes proposed by [EIP-7002](http://eips.ethereum
|
||||||
```python
|
```python
|
||||||
class ExecutionLayerExit(Container):
|
class ExecutionLayerExit(Container):
|
||||||
source_address: ExecutionAddress
|
source_address: ExecutionAddress
|
||||||
validator_index: ValidatorIndex
|
validator_pubkey: BLSPubkey
|
||||||
```
|
```
|
||||||
|
|
||||||
### Extended Containers
|
### Extended Containers
|
||||||
|
@ -238,7 +238,9 @@ def process_operations(state: BeaconState, body: BeaconBlockBody) -> None:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def process_execution_layer_exit(state: BeaconState, execution_layer_exit: ExecutionLayerExit) -> None:
|
def process_execution_layer_exit(state: BeaconState, execution_layer_exit: ExecutionLayerExit) -> None:
|
||||||
validator = state.validators[execution_layer_exit.validator_index]
|
validator_pubkeys = [v.pubkey for v in state.validators]
|
||||||
|
validator_index = ValidatorIndex(validator_pubkeys.index(execution_layer_exit.validator_pubkey))
|
||||||
|
validator = state.validators[validator_index]
|
||||||
|
|
||||||
# Verify withdrawal credentials
|
# Verify withdrawal credentials
|
||||||
is_correct_source_address = (
|
is_correct_source_address = (
|
||||||
|
@ -258,7 +260,7 @@ def process_execution_layer_exit(state: BeaconState, execution_layer_exit: Execu
|
||||||
return
|
return
|
||||||
|
|
||||||
# Initiate exit
|
# Initiate exit
|
||||||
initiate_validator_exit(state, execution_layer_exit.validator_index)
|
initiate_validator_exit(state, validator_index)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|
|
@ -11,11 +11,12 @@ def test_basic_exit(spec, state):
|
||||||
|
|
||||||
current_epoch = spec.get_current_epoch(state)
|
current_epoch = spec.get_current_epoch(state)
|
||||||
validator_index = spec.get_active_validator_indices(state, current_epoch)[0]
|
validator_index = spec.get_active_validator_indices(state, current_epoch)[0]
|
||||||
|
validator_pubkey = state.validators[validator_index].pubkey
|
||||||
address = b'\x22' * 20
|
address = b'\x22' * 20
|
||||||
set_eth1_withdrawal_credential_with_balance(spec, state, validator_index, address=address)
|
set_eth1_withdrawal_credential_with_balance(spec, state, validator_index, address=address)
|
||||||
execution_layer_exit = spec.ExecutionLayerExit(
|
execution_layer_exit = spec.ExecutionLayerExit(
|
||||||
source_address=address,
|
source_address=address,
|
||||||
validator_index=validator_index,
|
validator_pubkey=validator_pubkey,
|
||||||
)
|
)
|
||||||
|
|
||||||
yield from run_execution_layer_exit_processing(spec, state, execution_layer_exit)
|
yield from run_execution_layer_exit_processing(spec, state, execution_layer_exit)
|
||||||
|
@ -29,12 +30,13 @@ def test_incorrect_source_address(spec, state):
|
||||||
|
|
||||||
current_epoch = spec.get_current_epoch(state)
|
current_epoch = spec.get_current_epoch(state)
|
||||||
validator_index = spec.get_active_validator_indices(state, current_epoch)[0]
|
validator_index = spec.get_active_validator_indices(state, current_epoch)[0]
|
||||||
|
validator_pubkey = state.validators[validator_index].pubkey
|
||||||
address = b'\x22' * 20
|
address = b'\x22' * 20
|
||||||
incorrect_address = b'\x33' * 20
|
incorrect_address = b'\x33' * 20
|
||||||
set_eth1_withdrawal_credential_with_balance(spec, state, validator_index, address=address)
|
set_eth1_withdrawal_credential_with_balance(spec, state, validator_index, address=address)
|
||||||
execution_layer_exit = spec.ExecutionLayerExit(
|
execution_layer_exit = spec.ExecutionLayerExit(
|
||||||
source_address=incorrect_address,
|
source_address=incorrect_address,
|
||||||
validator_index=validator_index,
|
validator_pubkey=validator_pubkey,
|
||||||
)
|
)
|
||||||
|
|
||||||
yield from run_execution_layer_exit_processing(spec, state, execution_layer_exit, success=False)
|
yield from run_execution_layer_exit_processing(spec, state, execution_layer_exit, success=False)
|
||||||
|
|
|
@ -24,11 +24,12 @@ def test_basic_exit(spec, state):
|
||||||
|
|
||||||
current_epoch = spec.get_current_epoch(state)
|
current_epoch = spec.get_current_epoch(state)
|
||||||
validator_index = spec.get_active_validator_indices(state, current_epoch)[0]
|
validator_index = spec.get_active_validator_indices(state, current_epoch)[0]
|
||||||
|
validator_pubkey = state.validators[validator_index].pubkey
|
||||||
address = b'\x22' * 20
|
address = b'\x22' * 20
|
||||||
set_eth1_withdrawal_credential_with_balance(spec, state, validator_index, address=address)
|
set_eth1_withdrawal_credential_with_balance(spec, state, validator_index, address=address)
|
||||||
execution_layer_exit = spec.ExecutionLayerExit(
|
execution_layer_exit = spec.ExecutionLayerExit(
|
||||||
source_address=address,
|
source_address=address,
|
||||||
validator_index=validator_index,
|
validator_pubkey=validator_pubkey,
|
||||||
)
|
)
|
||||||
|
|
||||||
yield 'pre', state
|
yield 'pre', state
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from eth2spec.test.context import expect_assertion_error
|
from eth2spec.test.context import expect_assertion_error
|
||||||
|
from eth2spec.test.helpers.state import get_validator_index_by_pubkey
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -14,7 +15,7 @@ def run_execution_layer_exit_processing(spec, state, execution_layer_exit, valid
|
||||||
- post-state ('post').
|
- post-state ('post').
|
||||||
If ``valid == False``, run expecting ``AssertionError``
|
If ``valid == False``, run expecting ``AssertionError``
|
||||||
"""
|
"""
|
||||||
validator_index = execution_layer_exit.validator_index
|
validator_index = get_validator_index_by_pubkey(state, execution_layer_exit.validator_pubkey)
|
||||||
|
|
||||||
yield 'pre', state
|
yield 'pre', state
|
||||||
yield 'execution_layer_exit', execution_layer_exit
|
yield 'execution_layer_exit', execution_layer_exit
|
||||||
|
|
|
@ -141,8 +141,8 @@ def get_exit_rlp(exit):
|
||||||
exit_rlp = [
|
exit_rlp = [
|
||||||
# source_address
|
# source_address
|
||||||
(Binary(20, 20), exit.source_address),
|
(Binary(20, 20), exit.source_address),
|
||||||
# validator_index
|
# validator_pubkey
|
||||||
(big_endian_int, exit.validator_index),
|
(Binary(48, 48), exit.validator_pubkey),
|
||||||
]
|
]
|
||||||
|
|
||||||
sedes = List([schema for schema, _ in exit_rlp])
|
sedes = List([schema for schema, _ in exit_rlp])
|
||||||
|
|
|
@ -166,3 +166,8 @@ def has_active_balance_differential(spec, state):
|
||||||
active_balance = spec.get_total_active_balance(state)
|
active_balance = spec.get_total_active_balance(state)
|
||||||
total_balance = spec.get_total_balance(state, set(range(len(state.validators))))
|
total_balance = spec.get_total_balance(state, set(range(len(state.validators))))
|
||||||
return active_balance // spec.EFFECTIVE_BALANCE_INCREMENT != total_balance // spec.EFFECTIVE_BALANCE_INCREMENT
|
return active_balance // spec.EFFECTIVE_BALANCE_INCREMENT != total_balance // spec.EFFECTIVE_BALANCE_INCREMENT
|
||||||
|
|
||||||
|
|
||||||
|
def get_validator_index_by_pubkey(state, pubkey):
|
||||||
|
index = next((i for i, validator in enumerate(state.validators) if validator.pubkey == pubkey), None)
|
||||||
|
return index
|
||||||
|
|
Loading…
Reference in New Issue