stop routing through update_validator_status

This commit is contained in:
Dustin Brody 2019-01-16 04:20:44 -08:00
parent 5823091501
commit bc65693eae
2 changed files with 21 additions and 26 deletions

View File

@ -51,7 +51,7 @@ func process_deposit(state: var BeaconState,
proof_of_possession: ValidatorSig, proof_of_possession: ValidatorSig,
withdrawal_credentials: Eth2Digest, withdrawal_credentials: Eth2Digest,
randao_commitment: Eth2Digest, randao_commitment: Eth2Digest,
custody_commitment: Eth2Digest): Uint24 = custody_commitment: Eth2Digest) : Uint24 =
## Process a deposit from Ethereum 1.0. ## Process a deposit from Ethereum 1.0.
# TODO return error # TODO return error
@ -69,7 +69,6 @@ func process_deposit(state: var BeaconState,
randao_commitment: randao_commitment, randao_commitment: randao_commitment,
randao_layers: 0, randao_layers: 0,
status: PENDING_ACTIVATION, status: PENDING_ACTIVATION,
latest_status_change_slot: state.slot,
activation_slot: FAR_FUTURE_SLOT, activation_slot: FAR_FUTURE_SLOT,
exit_slot: FAR_FUTURE_SLOT, exit_slot: FAR_FUTURE_SLOT,
withdrawal_slot: FAR_FUTURE_SLOT, withdrawal_slot: FAR_FUTURE_SLOT,
@ -92,7 +91,7 @@ func process_deposit(state: var BeaconState,
state.validator_balances[index.get()] = deposit state.validator_balances[index.get()] = deposit
index.get().Uint24 index.get().Uint24
else: else:
# Increase balance by deposit # Increase balance by deposit amount
let index = validator_pubkeys.find(pubkey) let index = validator_pubkeys.find(pubkey)
let validator = addr state.validator_registry[index] let validator = addr state.validator_registry[index]
assert state.validator_registry[index].withdrawal_credentials == assert state.validator_registry[index].withdrawal_credentials ==
@ -102,7 +101,8 @@ func process_deposit(state: var BeaconState,
index.Uint24 index.Uint24
func activate_validator(state: var BeaconState, func activate_validator(state: var BeaconState,
index: Uint24) = index: Uint24,
genesis: bool) =
## Activate the validator with the given ``index``. ## Activate the validator with the given ``index``.
let validator = addr state.validator_registry[index] let validator = addr state.validator_registry[index]
@ -130,9 +130,9 @@ func initiate_validator_exit(state: var BeaconState,
validator.status = ACTIVE_PENDING_EXIT validator.status = ACTIVE_PENDING_EXIT
validator.latest_status_change_slot = state.slot validator.latest_status_change_slot = state.slot
func exit_validator(state: var BeaconState, func exit_validator*(state: var BeaconState,
index: Uint24, index: Uint24,
new_status: ValidatorStatusCodes) = new_status: ValidatorStatusCodes) =
## Exit the validator with the given ``index``. ## Exit the validator with the given ``index``.
let let
@ -181,18 +181,6 @@ func exit_validator(state: var BeaconState,
committee.delete(i) committee.delete(i)
break break
func update_validator_status*(state: var BeaconState,
index: Uint24,
new_status: ValidatorStatusCodes) =
## Update the validator status with the given ``index`` to ``new_status``.
## Handle other general accounting related to this status update.
if new_status == ACTIVE:
activate_validator(state, index)
if new_status == ACTIVE_PENDING_EXIT:
initiate_validator_exit(state, index)
if new_status in [EXITED_WITH_PENALTY, EXITED_WITHOUT_PENALTY]:
exit_validator(state, index, new_status)
func get_initial_beacon_state*( func get_initial_beacon_state*(
initial_validator_deposits: openArray[Deposit], initial_validator_deposits: openArray[Deposit],
genesis_time: uint64, genesis_time: uint64,
@ -257,8 +245,15 @@ func get_initial_beacon_state*(
deposit.deposit_data.deposit_input.randao_commitment, deposit.deposit_data.deposit_input.randao_commitment,
deposit.deposit_data.deposit_input.custody_commitment, deposit.deposit_data.deposit_input.custody_commitment,
) )
if state.validator_balances[validator_index] >= MAX_DEPOSIT: if state.validator_balances[validator_index] >= MAX_DEPOSIT:
update_validator_status(state, validator_index, ACTIVE) activate_validator(state, validator_index, true)
# Process initial activations
#for validator_index in 0 ..< state.validator_registry.len:
# let vi = validator_index.Uint24
# if get_effective_balance(state, vi) > MAX_DEPOSIT * GWEI_PER_ETH:
# activate_validator(state, vi, true)
# set initial committee shuffling # set initial committee shuffling
let let
@ -349,7 +344,7 @@ func update_validator_registry*(state: var BeaconState) =
break break
# Activate validator # Activate validator
update_validator_status(state, index.Uint24, ACTIVE) activate_validator(state, index.Uint24, false)
# Exit validators within the allowable balance churn # Exit validators within the allowable balance churn
balance_churn = 0 balance_churn = 0
@ -361,7 +356,7 @@ func update_validator_registry*(state: var BeaconState) =
break break
# Exit validator # Exit validator
update_validator_status(state, index.Uint24, EXITED_WITHOUT_PENALTY) exit_validator(state, index.Uint24, EXITED_WITHOUT_PENALTY)
# Calculate the total ETH that has been penalized in the last ~2-3 withdrawal periods # Calculate the total ETH that has been penalized in the last ~2-3 withdrawal periods
let let

View File

@ -163,7 +163,7 @@ proc processProposerSlashings(
warn("PropSlash: wrong status") warn("PropSlash: wrong status")
return false return false
update_validator_status( exit_validator(
state, proposer_slashing.proposer_index, EXITED_WITH_PENALTY) state, proposer_slashing.proposer_index, EXITED_WITH_PENALTY)
return true return true
@ -226,7 +226,7 @@ proc processCasperSlashings(state: var BeaconState, blck: BeaconBlock): bool =
for i in intersection: for i in intersection:
if state.validator_registry[i].status != EXITED_WITH_PENALTY: if state.validator_registry[i].status != EXITED_WITH_PENALTY:
update_validator_status(state, i, EXITED_WITH_PENALTY) exit_validator(state, i, EXITED_WITH_PENALTY)
return true return true
@ -298,7 +298,7 @@ proc processExits(
SHARD_PERSISTENT_COMMITTEE_CHANGE_PERIOD): SHARD_PERSISTENT_COMMITTEE_CHANGE_PERIOD):
warn("Exit: not within committee change period") warn("Exit: not within committee change period")
update_validator_status(state, exit.validator_index, ACTIVE_PENDING_EXIT) exit_validator(state, exit.validator_index, ACTIVE_PENDING_EXIT)
return true return true
@ -311,7 +311,7 @@ proc process_ejections(state: var BeaconState) =
for index, validator in state.validator_registry: for index, validator in state.validator_registry:
if is_active_validator(validator) and if is_active_validator(validator) and
state.validator_balances[index] < EJECTION_BALANCE: state.validator_balances[index] < EJECTION_BALANCE:
update_validator_status(state, index.Uint24, EXITED_WITHOUT_PENALTY) exit_validator(state, index.Uint24, EXITED_WITHOUT_PENALTY)
func processSlot(state: var BeaconState, previous_block_root: Eth2Digest) = func processSlot(state: var BeaconState, previous_block_root: Eth2Digest) =
## Time on the beacon chain moves in slots. Every time we make it to a new ## Time on the beacon chain moves in slots. Every time we make it to a new