mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-02-04 10:43:40 +00:00
add some helper functions from new spec; fix some comments; more plumbing; start removing some of the status-code refs in favor of the new status bitfield
This commit is contained in:
parent
bc65693eae
commit
2ff973e46f
@ -106,11 +106,8 @@ func activate_validator(state: var BeaconState,
|
|||||||
## 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]
|
||||||
|
|
||||||
if validator.status != PENDING_ACTIVATION:
|
|
||||||
return
|
|
||||||
|
|
||||||
validator.status = ACTIVE
|
validator.status = ACTIVE
|
||||||
validator.latest_status_change_slot = state.slot
|
validator.activation_slot = if genesis: GENESIS_SLOT else: state.slot + ENTRY_EXIT_DELAY
|
||||||
state.validator_registry_delta_chain_tip =
|
state.validator_registry_delta_chain_tip =
|
||||||
get_new_validator_registry_delta_chain_tip(
|
get_new_validator_registry_delta_chain_tip(
|
||||||
state.validator_registry_delta_chain_tip,
|
state.validator_registry_delta_chain_tip,
|
||||||
@ -349,7 +346,8 @@ func update_validator_registry*(state: var BeaconState) =
|
|||||||
# Exit validators within the allowable balance churn
|
# Exit validators within the allowable balance churn
|
||||||
balance_churn = 0
|
balance_churn = 0
|
||||||
for index, validator in state.validator_registry:
|
for index, validator in state.validator_registry:
|
||||||
if validator.status == ACTIVE_PENDING_EXIT:
|
if (validator.exit_slot > state.slot + ENTRY_EXIT_DELAY) and
|
||||||
|
((validator.status_flags and INITIATED_EXIT) == INITIATED_EXIT):
|
||||||
# Check the balance churn would be within the allowance
|
# Check the balance churn would be within the allowance
|
||||||
balance_churn += get_effective_balance(state, index.Uint24)
|
balance_churn += get_effective_balance(state, index.Uint24)
|
||||||
if balance_churn > max_balance_churn:
|
if balance_churn > max_balance_churn:
|
||||||
|
@ -132,6 +132,9 @@ const
|
|||||||
COLLECTIVE_PENALTY_CALCULATION_PERIOD* = 2'u64^20 ##\
|
COLLECTIVE_PENALTY_CALCULATION_PERIOD* = 2'u64^20 ##\
|
||||||
## slots (~73 days)
|
## slots (~73 days)
|
||||||
|
|
||||||
|
ENTRY_EXIT_DELAY* = 256 ##\
|
||||||
|
## slots (~25.6 minutes)
|
||||||
|
|
||||||
ZERO_BALANCE_VALIDATOR_TTL* = 2'u64^22 ##\
|
ZERO_BALANCE_VALIDATOR_TTL* = 2'u64^22 ##\
|
||||||
## slots (~291 days)
|
## slots (~291 days)
|
||||||
|
|
||||||
|
@ -113,6 +113,18 @@ func processDepositRoot(state: var BeaconState, blck: BeaconBlock) =
|
|||||||
vote_count: 1
|
vote_count: 1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func penalizeValidator(state: var BeaconState, index: Uint24) =
|
||||||
|
exit_validator(state, index, EXITED_WITH_PENALTY)
|
||||||
|
var validator = state.validator_registry[index]
|
||||||
|
#state.latest_penalized_exit_balances[(state.slot div EPOCH_LENGTH) mod LATEST_PENALIZED_EXIT_LENGTH] += get_effective_balance(state, index.Uint24)
|
||||||
|
|
||||||
|
let
|
||||||
|
whistleblower_index = get_beacon_proposer_index(state, state.slot)
|
||||||
|
whistleblower_reward = get_effective_balance(state, index) div WHISTLEBLOWER_REWARD_QUOTIENT
|
||||||
|
state.validator_balances[whistleblower_index] += whistleblower_reward
|
||||||
|
state.validator_balances[index] -= whistleblower_reward
|
||||||
|
validator.penalized_slot = state.slot
|
||||||
|
|
||||||
proc processProposerSlashings(
|
proc processProposerSlashings(
|
||||||
state: var BeaconState, blck: BeaconBlock, flags: UpdateFlags): bool =
|
state: var BeaconState, blck: BeaconBlock, flags: UpdateFlags): bool =
|
||||||
## https://github.com/ethereum/eth2.0-specs/blob/master/specs/core/0_beacon-chain.md#proposer-slashings-1
|
## https://github.com/ethereum/eth2.0-specs/blob/master/specs/core/0_beacon-chain.md#proposer-slashings-1
|
||||||
@ -159,12 +171,11 @@ proc processProposerSlashings(
|
|||||||
warn("PropSlash: block root mismatch")
|
warn("PropSlash: block root mismatch")
|
||||||
return false
|
return false
|
||||||
|
|
||||||
if not (proposer.status != EXITED_WITH_PENALTY):
|
if not (proposer.penalized_slot > state.slot):
|
||||||
warn("PropSlash: wrong status")
|
warn("PropSlash: penalized slot")
|
||||||
return false
|
return false
|
||||||
|
|
||||||
exit_validator(
|
penalizeValidator(state, proposer_slashing.proposer_index)
|
||||||
state, proposer_slashing.proposer_index, EXITED_WITH_PENALTY)
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
@ -285,20 +296,16 @@ proc processExits(
|
|||||||
warn("Exit: invalid signature")
|
warn("Exit: invalid signature")
|
||||||
return false
|
return false
|
||||||
|
|
||||||
if not (validator.status == ACTIVE):
|
if not (validator.exit_slot > state.slot + ENTRY_EXIT_DELAY):
|
||||||
warn("Exit: validator not active")
|
warn("Exit: exit/entry too close")
|
||||||
return false
|
return false
|
||||||
|
|
||||||
if not (state.slot >= exit.slot):
|
if not (state.slot >= exit.slot):
|
||||||
warn("Exit: bad slot")
|
warn("Exit: bad slot")
|
||||||
return false
|
return false
|
||||||
|
|
||||||
if not (state.slot >=
|
|
||||||
validator.latest_status_change_slot +
|
|
||||||
SHARD_PERSISTENT_COMMITTEE_CHANGE_PERIOD):
|
|
||||||
warn("Exit: not within committee change period")
|
|
||||||
|
|
||||||
exit_validator(state, exit.validator_index, ACTIVE_PENDING_EXIT)
|
exit_validator(state, exit.validator_index, ACTIVE_PENDING_EXIT)
|
||||||
|
initiate_validator_exit(state, exit.validator_index)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
@ -567,7 +574,7 @@ func processEpoch(state: var BeaconState) =
|
|||||||
func total_balance_sac(shard_committee: ShardCommittee): uint64 =
|
func total_balance_sac(shard_committee: ShardCommittee): uint64 =
|
||||||
sum_effective_balances(statePtr[], shard_committee.committee)
|
sum_effective_balances(statePtr[], shard_committee.committee)
|
||||||
|
|
||||||
block: # Receipt roots
|
block: # Deposit roots
|
||||||
if state.slot mod POW_RECEIPT_ROOT_VOTING_PERIOD == 0:
|
if state.slot mod POW_RECEIPT_ROOT_VOTING_PERIOD == 0:
|
||||||
for x in state.deposit_roots:
|
for x in state.deposit_roots:
|
||||||
if x.vote_count * 2 >= POW_RECEIPT_ROOT_VOTING_PERIOD:
|
if x.vote_count * 2 >= POW_RECEIPT_ROOT_VOTING_PERIOD:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user