Use add_validator_to_registry in whisk (#3486)

This commit is contained in:
Lion - dapplion 2023-10-10 14:09:21 +02:00 committed by GitHub
parent b04430332e
commit 8acb254511
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 32 deletions

View File

@ -415,38 +415,21 @@ def get_initial_tracker(k: BLSFieldElement) -> WhiskTracker:
``` ```
```python ```python
def apply_deposit(state: BeaconState, def add_validator_to_registry(state: BeaconState,
pubkey: BLSPubkey, pubkey: BLSPubkey,
withdrawal_credentials: Bytes32, withdrawal_credentials: Bytes32,
amount: uint64, amount: uint64) -> None:
signature: BLSSignature) -> None: index = get_index_for_new_validator(state)
validator_pubkeys = [validator.pubkey for validator in state.validators] validator = get_validator_from_deposit(pubkey, withdrawal_credentials, amount)
if pubkey not in validator_pubkeys: set_or_append_list(state.validators, index, validator)
# Verify the deposit signature (proof of possession) which is not checked by the deposit contract set_or_append_list(state.balances, index, amount)
deposit_message = DepositMessage( set_or_append_list(state.previous_epoch_participation, index, ParticipationFlags(0b0000_0000))
pubkey=pubkey, set_or_append_list(state.current_epoch_participation, index, ParticipationFlags(0b0000_0000))
withdrawal_credentials=withdrawal_credentials, set_or_append_list(state.inactivity_scores, index, uint64(0))
amount=amount, # [New in Whisk]
) k = get_unique_whisk_k(state, ValidatorIndex(len(state.validators) - 1))
domain = compute_domain(DOMAIN_DEPOSIT) # Fork-agnostic domain since deposits are valid across forks state.whisk_trackers.append(get_initial_tracker(k))
signing_root = compute_signing_root(deposit_message, domain) state.whisk_k_commitments.append(get_k_commitment(k))
# Initialize validator if the deposit signature is valid
if bls.Verify(pubkey, signing_root, signature):
index = get_index_for_new_validator(state)
validator = get_validator_from_deposit(pubkey, withdrawal_credentials, amount)
set_or_append_list(state.validators, index, validator)
set_or_append_list(state.balances, index, amount)
set_or_append_list(state.previous_epoch_participation, index, ParticipationFlags(0b0000_0000))
set_or_append_list(state.current_epoch_participation, index, ParticipationFlags(0b0000_0000))
set_or_append_list(state.inactivity_scores, index, uint64(0))
# [New in Whisk]
k = get_unique_whisk_k(state, ValidatorIndex(len(state.validators) - 1))
state.whisk_trackers.append(get_initial_tracker(k))
state.whisk_k_commitments.append(get_k_commitment(k))
else:
# Increase balance by deposit amount
index = ValidatorIndex(validator_pubkeys.index(pubkey))
increase_balance(state, index, amount)
``` ```
### `get_beacon_proposer_index` ### `get_beacon_proposer_index`