def process_deposit(*, state: BeaconState, pubkey: BLSPubkey, deposit: Gwei, proof_of_possession: BLSSignature, withdrawal_credentials: Hash32, randao_commitment: Hash32, custody_commitment: Hash32, zero_balance_validator_ttl: int) -> Tuple[BeaconState, ValidatorIndex]: """ Process a deposit from Ethereum 1.0. """ validate_proof_of_possession( state, pubkey, proof_of_possession, withdrawal_credentials, randao_commitment, custody_commitment, ) validator_pubkeys = tuple(v.pubkey for v in state.validator_registry) if pubkey not in validator_pubkeys: validator = ValidatorRecord.get_pending_validator( pubkey=pubkey, withdrawal_credentials=withdrawal_credentials, randao_commitment=randao_commitment, latest_status_change_slot=state.slot, custody_commitment=custody_commitment, ) state, index = add_pending_validator( state, validator, deposit, zero_balance_validator_ttl, ) else: # Top-up - increase balance by deposit index = ValidatorIndex(validator_pubkeys.index(pubkey)) validator = state.validator_registry[index] if validator.withdrawal_credentials != withdrawal_credentials: raise ValidationError( "`withdrawal_credentials` are incorrect:\n" "\texpected: %s, found: %s" % ( validator.withdrawal_credentials, validator.withdrawal_credentials, ) ) # Update validator's balance and state state = state.update_validator( validator_index=index, validator=validator, balance=state.validator_balances[index] + deposit, ) return state, index
def test_get_pending_validator(): pubkey = 123 withdrawal_credentials = b'\x11' * 32 randao_commitment = b'\x22' * 32 latest_status_change_slot = 10 validator = ValidatorRecord.get_pending_validator( pubkey=pubkey, withdrawal_credentials=withdrawal_credentials, randao_commitment=randao_commitment, latest_status_change_slot=latest_status_change_slot, ) assert validator.pubkey == pubkey assert validator.withdrawal_credentials == withdrawal_credentials assert validator.randao_commitment == randao_commitment assert validator.latest_status_change_slot == latest_status_change_slot assert validator.status == ValidatorStatusCode.PENDING_ACTIVATION assert validator.randao_layers == 0 assert validator.exit_count == 0