Merge pull request #334 from ethereum/hwwhww-patch-2

Bugfix around on startup functions
This commit is contained in:
Danny Ryan 2018-12-18 12:46:30 -06:00 committed by GitHub
commit 966f2bf384
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 41 additions and 24 deletions

View File

@ -981,7 +981,7 @@ def get_new_validator_registry_delta_chain_tip(current_validator_registry_delta_
""" """
return hash_tree_root( return hash_tree_root(
ValidatorRegistryDeltaBlock( ValidatorRegistryDeltaBlock(
validator_registry_delta_chain_tip=current_validator_registry_delta_chain_tip, latest_registry_delta_root=current_validator_registry_delta_chain_tip,
validator_index=validator_index, validator_index=validator_index,
pubkey=pubkey, pubkey=pubkey,
flag=flag, flag=flag,
@ -1110,8 +1110,8 @@ A valid block with slot `INITIAL_SLOT_NUMBER` (a "genesis block") has the follow
state_root=STARTUP_STATE_ROOT, state_root=STARTUP_STATE_ROOT,
randao_reveal=ZERO_HASH, randao_reveal=ZERO_HASH,
candidate_pow_receipt_root=ZERO_HASH, candidate_pow_receipt_root=ZERO_HASH,
proposer_signature=EMPTY_SIGNATURE, signature=EMPTY_SIGNATURE,
'body': BeaconBlockBody( body=BeaconBlockBody(
proposer_slashings=[], proposer_slashings=[],
casper_slashings=[], casper_slashings=[],
attestations=[], attestations=[],
@ -1180,10 +1180,10 @@ def get_initial_beacon_state(initial_validator_deposits: List[Deposit],
randao_commitment=deposit.deposit_data.deposit_input.randao_commitment randao_commitment=deposit.deposit_data.deposit_input.randao_commitment
) )
if get_effective_balance(state, validator_index) == MAX_DEPOSIT * GWEI_PER_ETH: if get_effective_balance(state, validator_index) == MAX_DEPOSIT * GWEI_PER_ETH:
update_validator_status(state, index, ACTIVE) update_validator_status(state, validator_index, ACTIVE)
# set initial committee shuffling # set initial committee shuffling
initial_shuffling = get_new_shuffling(ZERO_HASH, initial_validator_registry, 0) initial_shuffling = get_new_shuffling(ZERO_HASH, state.validator_registry, 0)
state.shard_committees_at_slots = initial_shuffling + initial_shuffling state.shard_committees_at_slots = initial_shuffling + initial_shuffling
# set initial persistent shuffling # set initial persistent shuffling
@ -1195,7 +1195,7 @@ def get_initial_beacon_state(initial_validator_deposits: List[Deposit],
### Routine for processing deposits ### Routine for processing deposits
First, a helper function: First, two helper functions:
```python ```python
def min_empty_validator_index(validators: List[ValidatorRecord], def min_empty_validator_index(validators: List[ValidatorRecord],
@ -1207,6 +1207,31 @@ def min_empty_validator_index(validators: List[ValidatorRecord],
return None return None
``` ```
```python
def validate_proof_of_possession(state: BeaconState,
pubkey: int,
proof_of_possession: bytes,
withdrawal_credentials: Hash32,
randao_commitment: Hash32) -> bool:
proof_of_possession_data = DepositInput(
pubkey=pubkey,
withdrawal_credentials=withdrawal_credentials,
randao_commitment=randao_commitment,
proof_of_possession=EMPTY_SIGNATURE,
)
return bls_verify(
pubkey=pubkey,
message=hash_tree_root(proof_of_possession_data),
signature=proof_of_possession,
domain=get_domain(
state.fork_data,
state.slot,
DOMAIN_DEPOSIT,
)
)
```
Now, to add a [validator](#dfn-validator) or top up an existing [validator](#dfn-validator)'s balance by some `deposit` amount: Now, to add a [validator](#dfn-validator) or top up an existing [validator](#dfn-validator)'s balance by some `deposit` amount:
```python ```python
@ -1220,23 +1245,15 @@ def process_deposit(state: BeaconState,
Process a deposit from Ethereum 1.0. Process a deposit from Ethereum 1.0.
Note that this function mutates ``state``. Note that this function mutates ``state``.
""" """
proof_of_possession_data = DepositInput( # Validate the given `proof_of_possession`
pubkey=pubkey, assert validate_proof_of_possession(
withdrawal_credentials=withdrawal_credentials, state,
randao_commitment=randao_commitment, pubkey,
proof_of_possession=EMPTY_SIGNATURE, proof_of_possession,
withdrawal_credentials,
randao_commitment,
) )
assert bls_verify(
pubkey=pubkey,
message=hash_tree_root(proof_of_possession_data),
signature=proof_of_possession,
domain=get_domain(
state.fork_data,
state.slot,
DOMAIN_DEPOSIT
)
)
validator_pubkeys = [v.pubkey for v in state.validator_registry] validator_pubkeys = [v.pubkey for v in state.validator_registry]
if pubkey not in validator_pubkeys: if pubkey not in validator_pubkeys:
@ -1305,7 +1322,7 @@ def activate_validator(state: BeaconState,
validator.status = ACTIVE validator.status = ACTIVE
validator.latest_status_change_slot = state.slot validator.latest_status_change_slot = state.slot
state.validator_registry_delta_chain_tip = get_new_validator_registry_delta_chain_tip( state.validator_registry_delta_chain_tip = get_new_validator_registry_delta_chain_tip(
validator_registry_delta_chain_tip=state.validator_registry_delta_chain_tip, current_validator_registry_delta_chain_tip=state.validator_registry_delta_chain_tip,
validator_index=index, validator_index=index,
pubkey=validator.pubkey, pubkey=validator.pubkey,
flag=ACTIVATION, flag=ACTIVATION,
@ -1353,14 +1370,14 @@ def exit_validator(state: BeaconState,
state.validator_balances[whistleblower_index] += whistleblower_reward state.validator_balances[whistleblower_index] += whistleblower_reward
state.validator_balances[index] -= whistleblower_reward state.validator_balances[index] -= whistleblower_reward
if prev_status == EXITED_WITHOUT_PENALTY if prev_status == EXITED_WITHOUT_PENALTY:
return return
# The following updates only occur if not previous exited # The following updates only occur if not previous exited
state.validator_registry_exit_count += 1 state.validator_registry_exit_count += 1
validator.exit_count = state.validator_registry_exit_count validator.exit_count = state.validator_registry_exit_count
state.validator_registry_delta_chain_tip = get_new_validator_registry_delta_chain_tip( state.validator_registry_delta_chain_tip = get_new_validator_registry_delta_chain_tip(
validator_registry_delta_chain_tip=state.validator_registry_delta_chain_tip, current_validator_registry_delta_chain_tip=state.validator_registry_delta_chain_tip,
validator_index=index, validator_index=index,
pubkey=validator.pubkey, pubkey=validator.pubkey,
flag=EXIT flag=EXIT