mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-27 06:47:13 +00:00
audit & update spec references for some slashing and rewards and penalty functions; check and update all remaining v0.11.0 spec references to v0.11.3 [skip ci]
This commit is contained in:
parent
0df191b559
commit
b9817867f5
@ -154,7 +154,7 @@ func initiate_validator_exit*(state: var BeaconState,
|
||||
validator.withdrawable_epoch =
|
||||
validator.exit_epoch + MIN_VALIDATOR_WITHDRAWABILITY_DELAY
|
||||
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#slash_validator
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/specs/phase0/beacon-chain.md#slash_validator
|
||||
proc slash_validator*(state: var BeaconState, slashed_index: ValidatorIndex,
|
||||
stateCache: var StateCache) =
|
||||
# Slash the validator with index ``index``.
|
||||
@ -180,6 +180,7 @@ proc slash_validator*(state: var BeaconState, slashed_index: ValidatorIndex,
|
||||
validator.effective_balance div MIN_SLASHING_PENALTY_QUOTIENT)
|
||||
|
||||
# The rest doesn't make sense without there being any proposer index, so skip
|
||||
# Apply proposer and whistleblower rewards
|
||||
let proposer_index = get_beacon_proposer_index(state, stateCache)
|
||||
if proposer_index.isNone:
|
||||
debug "No beacon proposer index and probably no active validators"
|
||||
@ -447,7 +448,7 @@ func get_attesting_indices*(state: BeaconState,
|
||||
if bits[i]:
|
||||
result.incl index
|
||||
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#get_indexed_attestation
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/specs/phase0/beacon-chain.md#get_indexed_attestation
|
||||
func get_indexed_attestation*(state: BeaconState, attestation: Attestation,
|
||||
stateCache: var StateCache): IndexedAttestation =
|
||||
# Return the indexed attestation corresponding to ``attestation``.
|
||||
|
@ -169,13 +169,13 @@ const
|
||||
SECONDS_PER_ETH1_BLOCK* = 14 # estimate from Eth1 mainnet)
|
||||
|
||||
# Phase 1: Upgrade from Phase 0
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.0/configs/mainnet.yaml#L161
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/mainnet.yaml#L161
|
||||
PHASE_1_FORK_VERSION* = 1
|
||||
INITIAL_ACTIVE_SHARDS* = 64
|
||||
|
||||
# Phase 1: General
|
||||
# ---------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.0/configs/mainnet.yaml#L169
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/mainnet.yaml#L166
|
||||
MAX_SHARDS* = 1024
|
||||
ONLINE_PERIOD* = 8 # epochs (~51 min)
|
||||
LIGHT_CLIENT_COMMITTEE_SIZE* = 128
|
||||
@ -191,22 +191,21 @@ const
|
||||
|
||||
# Phase 1: Custody game
|
||||
# ---------------------------------------------------------------
|
||||
|
||||
# Time parameters
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.0/configs/mainnet.yaml#L202
|
||||
RANDAO_PENALTY_EPOCHS* = 2 # epchs (12.8 minutes)
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/mainnet.yaml#L199
|
||||
RANDAO_PENALTY_EPOCHS* = 2 # epochs (12.8 minutes)
|
||||
EARLY_DERIVED_SECRET_PENALTY_MAX_FUTURE_EPOCHS* = 16384 # epochs (~73 days)
|
||||
EPOCHS_PER_CUSTODY_PERIOD* = 2048 # epochs (~9 days)
|
||||
CUSTODY_PERIOD_TO_RANDAO_PADDING* = 2048 # epochs (~9 days)
|
||||
MAX_REVEAL_LATENESS_DECREMENT* = 128 # epochs (~14 hours)
|
||||
|
||||
# Max operations
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.0/configs/mainnet.yaml#L214
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/mainnet.yaml#L211
|
||||
MAX_CUSTODY_KEY_REVEALS* = 256
|
||||
MAX_EARLY_DERIVED_SECRET_REVEALS* = 1
|
||||
MAX_CUSTODY_SLASHINGS* = 1
|
||||
|
||||
# Reward and penalty quotients
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.0/configs/mainnet.yaml#L220
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/mainnet.yaml#L217
|
||||
EARLY_DERIVED_SECRET_REVEAL_SLOT_REWARD_MULTIPLE* = 2
|
||||
MINOR_REWARD_QUOTIENT* = 256
|
||||
|
@ -148,13 +148,13 @@ const
|
||||
|
||||
# Phase 1: Upgrade from Phase 0
|
||||
# ---------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.0/configs/minimal.yaml#L161
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/minimal.yaml#L161
|
||||
PHASE_1_FORK_VERSION* = 16777217
|
||||
INITIAL_ACTIVE_SHARDS* = 4
|
||||
|
||||
# Phase 1: General
|
||||
# ---------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.0/configs/minimal.yaml#L171
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/minimal.yaml#L169
|
||||
MAX_SHARDS* = 8
|
||||
ONLINE_PERIOD* = 8 # epochs ~ 51 minutes
|
||||
LIGHT_CLIENT_COMMITTEE_SIZE* = 128
|
||||
@ -170,25 +170,21 @@ const
|
||||
|
||||
# Phase 1 - Custody game
|
||||
# ---------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/configs/minimal.yaml#L201
|
||||
# TODO those are included in minimal.yaml but not mainnet.yaml
|
||||
# Why?
|
||||
# Time parameters
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/minimal.yaml#L202
|
||||
RANDAO_PENALTY_EPOCHS* = 2
|
||||
EARLY_DERIVED_SECRET_PENALTY_MAX_FUTURE_EPOCHS* = 4096 # epochs
|
||||
EPOCHS_PER_CUSTODY_PERIOD* = 2048
|
||||
|
||||
# Time parameters
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.0/configs/minimal.yaml#L204
|
||||
CUSTODY_PERIOD_TO_RANDAO_PADDING* = 2048
|
||||
MAX_REVEAL_LATENESS_DECREMENT* = 128
|
||||
|
||||
# Max operations
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.0/configs/minimal.yaml#L216
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/minimal.yaml#L214
|
||||
MAX_CUSTODY_KEY_REVEALS* = 256
|
||||
MAX_EARLY_DERIVED_SECRET_REVEALS* = 1
|
||||
MAX_CUSTODY_SLASHINGS* = 1
|
||||
|
||||
# Reward and penalty quotients
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.0/configs/minimal.yaml#L222
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/configs/minimal.yaml#L220
|
||||
EARLY_DERIVED_SECRET_REVEAL_SLOT_REWARD_MULTIPLE* = 2
|
||||
MINOR_REWARD_QUOTIENT* = 256
|
||||
|
@ -347,7 +347,7 @@ func get_attestation_deltas(state: BeaconState, stateCache: var StateCache):
|
||||
|
||||
(rewards, penalties)
|
||||
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#rewards-and-penalties-1
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/specs/phase0/beacon-chain.md#rewards-and-penalties-1
|
||||
func process_rewards_and_penalties(
|
||||
state: var BeaconState, cache: var StateCache) {.nbench.}=
|
||||
if get_current_epoch(state) == GENESIS_EPOCH:
|
||||
|
@ -24,17 +24,18 @@ func shortLog*(x: Checkpoint): string =
|
||||
# Helpers used in epoch transition and trace-level block transition
|
||||
# --------------------------------------------------------
|
||||
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#helper-functions-1
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/specs/phase0/beacon-chain.md#helper-functions-1
|
||||
func get_attesting_indices*(
|
||||
state: BeaconState, attestations: openarray[PendingAttestation],
|
||||
stateCache: var StateCache): HashSet[ValidatorIndex] =
|
||||
# This is part of get_unslashed_attesting_indices(...) in spec.
|
||||
# Exported bceause of external trace-level chronicles logging.
|
||||
result = initHashSet[ValidatorIndex]()
|
||||
for a in attestations:
|
||||
result = result.union(get_attesting_indices(
|
||||
state, a.data, a.aggregation_bits, stateCache))
|
||||
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#helper-functions-1
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/specs/phase0/beacon-chain.md#helper-functions-1
|
||||
func get_unslashed_attesting_indices*(
|
||||
state: BeaconState, attestations: openarray[PendingAttestation],
|
||||
stateCache: var StateCache): HashSet[ValidatorIndex] =
|
||||
|
@ -84,7 +84,7 @@ proc verify_block_signature*(
|
||||
|
||||
true
|
||||
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#beacon-chain-state-transition-function
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.3/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
|
||||
proc verifyStateRoot(state: BeaconState, blck: BeaconBlock): bool =
|
||||
# This is inlined in state_transition(...) in spec.
|
||||
let state_root = hash_tree_root(state)
|
||||
|
Loading…
x
Reference in New Issue
Block a user