mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-01-12 11:44:41 +00:00
validator init adjustments
This commit is contained in:
parent
4c9e5b8950
commit
03e956f9c9
@ -320,11 +320,11 @@ def get_randao_epoch_for_custody_period(period: uint64, validator_index: Validat
|
|||||||
### `get_custody_period_for_validator`
|
### `get_custody_period_for_validator`
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def get_custody_period_for_validator(state: BeaconState, validator_index: ValidatorIndex, epoch: Epoch=None) -> int:
|
def get_custody_period_for_validator(validator_index: ValidatorIndex, epoch: Epoch=None) -> int:
|
||||||
'''
|
'''
|
||||||
Return the reveal period for a given validator.
|
Return the reveal period for a given validator.
|
||||||
'''
|
'''
|
||||||
epoch = get_current_epoch(state) if epoch is None else epoch
|
epoch = if epoch is None else epoch
|
||||||
return (epoch + validator_index % EPOCHS_PER_CUSTODY_PERIOD) // EPOCHS_PER_CUSTODY_PERIOD
|
return (epoch + validator_index % EPOCHS_PER_CUSTODY_PERIOD) // EPOCHS_PER_CUSTODY_PERIOD
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -367,7 +367,7 @@ def process_custody_key_reveal(state: BeaconState, reveal: CustodyKeyReveal) ->
|
|||||||
revealer = state.validators[reveal.revealer_index]
|
revealer = state.validators[reveal.revealer_index]
|
||||||
epoch_to_sign = get_randao_epoch_for_custody_period(revealer.next_custody_secret_to_reveal, reveal.revealer_index)
|
epoch_to_sign = get_randao_epoch_for_custody_period(revealer.next_custody_secret_to_reveal, reveal.revealer_index)
|
||||||
|
|
||||||
assert revealer.next_custody_secret_to_reveal < get_custody_period_for_validator(state, reveal.revealer_index)
|
assert revealer.next_custody_secret_to_reveal < get_custody_period_for_validator(reveal.revealer_index, get_current_epoch(state))
|
||||||
|
|
||||||
# Revealed validator is active or exited, but not withdrawn
|
# Revealed validator is active or exited, but not withdrawn
|
||||||
assert is_slashable_validator(revealer, get_current_epoch(state))
|
assert is_slashable_validator(revealer, get_current_epoch(state))
|
||||||
@ -566,7 +566,7 @@ def process_bit_challenge(state: BeaconState, challenge: CustodyBitChallenge) ->
|
|||||||
# Verify attestation is eligible for challenging
|
# Verify attestation is eligible for challenging
|
||||||
responder = state.validators[challenge.responder_index]
|
responder = state.validators[challenge.responder_index]
|
||||||
assert get_current_epoch(state) <= get_randao_epoch_for_custody_period(
|
assert get_current_epoch(state) <= get_randao_epoch_for_custody_period(
|
||||||
get_custody_period_for_validator(state, challenge.responder_index, epoch),
|
get_custody_period_for_validator(challenge.responder_index, epoch),
|
||||||
challenge.responder_index
|
challenge.responder_index
|
||||||
) + 2 * EPOCHS_PER_CUSTODY_PERIOD + responder.max_reveal_lateness
|
) + 2 * EPOCHS_PER_CUSTODY_PERIOD + responder.max_reveal_lateness
|
||||||
|
|
||||||
@ -578,7 +578,7 @@ def process_bit_challenge(state: BeaconState, challenge: CustodyBitChallenge) ->
|
|||||||
assert record.challenger_index != challenge.challenger_index
|
assert record.challenger_index != challenge.challenger_index
|
||||||
# Verify the responder custody key
|
# Verify the responder custody key
|
||||||
epoch_to_sign = get_randao_epoch_for_custody_period(
|
epoch_to_sign = get_randao_epoch_for_custody_period(
|
||||||
get_custody_period_for_validator(state, challenge.responder_index, epoch),
|
get_custody_period_for_validator(challenge.responder_index, epoch),
|
||||||
challenge.responder_index,
|
challenge.responder_index,
|
||||||
)
|
)
|
||||||
domain = get_domain(state, DOMAIN_RANDAO, epoch_to_sign)
|
domain = get_domain(state, DOMAIN_RANDAO, epoch_to_sign)
|
||||||
|
@ -35,13 +35,14 @@ After `process_slots` of Phase 0 finishes, but before the first Phase 1 block is
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
def upgrade_to_phase1(pre: phase0.BeaconState) -> BeaconState:
|
def upgrade_to_phase1(pre: phase0.BeaconState) -> BeaconState:
|
||||||
|
epoch = get_current_epoch(pre)
|
||||||
post = BeaconState(
|
post = BeaconState(
|
||||||
genesis_time=pre.genesis_time,
|
genesis_time=pre.genesis_time,
|
||||||
slot=pre.slot,
|
slot=pre.slot,
|
||||||
fork=Fork(
|
fork=Fork(
|
||||||
previous_version=pre.current_version,
|
previous_version=pre.current_version,
|
||||||
current_version=PHASE_1_FORK_VERSION,
|
current_version=PHASE_1_FORK_VERSION,
|
||||||
epoch=get_current_epoch(pre),
|
epoch=epoch,
|
||||||
),
|
),
|
||||||
# History
|
# History
|
||||||
latest_block_header=pre.latest_block_header,
|
latest_block_header=pre.latest_block_header,
|
||||||
@ -58,14 +59,14 @@ def upgrade_to_phase1(pre: phase0.BeaconState) -> BeaconState:
|
|||||||
pubkey=phase0_validator.pubkey,
|
pubkey=phase0_validator.pubkey,
|
||||||
withdrawal_credentials=phase0_validator.withdrawal_credentials,
|
withdrawal_credentials=phase0_validator.withdrawal_credentials,
|
||||||
effective_balance=phase0_validator.effective_balance,
|
effective_balance=phase0_validator.effective_balance,
|
||||||
slashed=phase0.slashed,
|
slashed=phase0_validator.slashed,
|
||||||
activation_eligibility_epoch=phase0_validator.activation_eligibility_epoch,
|
activation_eligibility_epoch=phase0_validator.activation_eligibility_epoch,
|
||||||
activation_epoch=phase0_validator.activation_eligibility_epoch,
|
activation_epoch=phase0_validator.activation_eligibility_epoch,
|
||||||
exit_epoch=phase0_validator.exit_epoch,
|
exit_epoch=phase0_validator.exit_epoch,
|
||||||
withdrawable_epoch=phase0_validator.withdrawable_epoch,
|
withdrawable_epoch=phase0_validator.withdrawable_epoch,
|
||||||
next_custody_secret_to_reveal=,
|
next_custody_secret_to_reveal=get_custody_period_for_validator(validator_index, epoch),
|
||||||
max_reveal_lateness=,
|
max_reveal_lateness=0, # TODO custody refactor. Outdated?
|
||||||
) for phase0_validator in pre.validators
|
) for validator_index, phase0_validator in enumerate(pre.validators)
|
||||||
),
|
),
|
||||||
balances=pre.balances,
|
balances=pre.balances,
|
||||||
# Randomness
|
# Randomness
|
||||||
|
Loading…
x
Reference in New Issue
Block a user