Silently skip deposits with invalid proof in process_deposit

This commit is contained in:
Anton Nashatyrev 2019-02-08 18:04:32 +03:00
parent cd0f98b85f
commit f9eaab1d04
1 changed files with 25 additions and 24 deletions

View File

@ -1252,36 +1252,37 @@ def process_deposit(state: BeaconState,
Note that this function mutates ``state``. Note that this function mutates ``state``.
""" """
# Validate the given `proof_of_possession` # Validate the given `proof_of_possession`
assert validate_proof_of_possession( valid_proof = validate_proof_of_possession(
state, state,
pubkey, pubkey,
proof_of_possession, proof_of_possession,
withdrawal_credentials, withdrawal_credentials,
) )
validator_pubkeys = [v.pubkey for v in state.validator_registry] if valid_proof:
validator_pubkeys = [v.pubkey for v in state.validator_registry]
if pubkey not in validator_pubkeys:
# Add new validator if pubkey not in validator_pubkeys:
validator = Validator( # Add new validator
pubkey=pubkey, validator = Validator(
withdrawal_credentials=withdrawal_credentials, pubkey=pubkey,
activation_epoch=FAR_FUTURE_EPOCH, withdrawal_credentials=withdrawal_credentials,
exit_epoch=FAR_FUTURE_EPOCH, activation_epoch=FAR_FUTURE_EPOCH,
withdrawal_epoch=FAR_FUTURE_EPOCH, exit_epoch=FAR_FUTURE_EPOCH,
penalized_epoch=FAR_FUTURE_EPOCH, withdrawal_epoch=FAR_FUTURE_EPOCH,
status_flags=0, penalized_epoch=FAR_FUTURE_EPOCH,
) status_flags=0,
)
# Note: In phase 2 registry indices that have been withdrawn for a long time will be recycled.
state.validator_registry.append(validator) # Note: In phase 2 registry indices that have been withdrawn for a long time will be recycled.
state.validator_balances.append(amount) state.validator_registry.append(validator)
else: state.validator_balances.append(amount)
# Increase balance by deposit amount else:
index = validator_pubkeys.index(pubkey) # Increase balance by deposit amount
assert state.validator_registry[index].withdrawal_credentials == withdrawal_credentials index = validator_pubkeys.index(pubkey)
assert state.validator_registry[index].withdrawal_credentials == withdrawal_credentials
state.validator_balances[index] += amount
state.validator_balances[index] += amount
``` ```
### Routines for updating validator status ### Routines for updating validator status