mark several more functions and data structures as 0.9.3
This commit is contained in:
parent
1610981be6
commit
0328cd49bf
|
@ -1,5 +1,5 @@
|
||||||
# beacon_chain
|
# beacon_chain
|
||||||
# Copyright (c) 2018-2019 Status Research & Development GmbH
|
# Copyright (c) 2019 Status Research & Development GmbH
|
||||||
# Licensed and distributed under either of
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT).
|
# * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT).
|
||||||
# * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0).
|
# * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0).
|
||||||
|
@ -33,7 +33,7 @@ const
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/networking/p2p-interface.md#configuration
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/networking/p2p-interface.md#configuration
|
||||||
ATTESTATION_PROPAGATION_SLOT_RANGE = 32
|
ATTESTATION_PROPAGATION_SLOT_RANGE = 32
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/validator/0_beacon-chain-validator.md#aggregation-selection
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/validator/0_beacon-chain-validator.md#aggregation-selection
|
||||||
func get_slot_signature(state: BeaconState, slot: Slot, privkey: ValidatorPrivKey):
|
func get_slot_signature(state: BeaconState, slot: Slot, privkey: ValidatorPrivKey):
|
||||||
ValidatorSig =
|
ValidatorSig =
|
||||||
let domain =
|
let domain =
|
||||||
|
|
|
@ -11,7 +11,7 @@ import
|
||||||
../extras, ../ssz,
|
../extras, ../ssz,
|
||||||
./crypto, ./datatypes, ./digest, ./helpers, ./validator
|
./crypto, ./datatypes, ./digest, ./helpers, ./validator
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/core/0_beacon-chain.md#is_valid_merkle_branch
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#is_valid_merkle_branch
|
||||||
func is_valid_merkle_branch*(leaf: Eth2Digest, branch: openarray[Eth2Digest], depth: uint64, index: uint64, root: Eth2Digest): bool =
|
func is_valid_merkle_branch*(leaf: Eth2Digest, branch: openarray[Eth2Digest], depth: uint64, index: uint64, root: Eth2Digest): bool =
|
||||||
## Check if ``leaf`` at ``index`` verifies against the Merkle ``root`` and
|
## Check if ``leaf`` at ``index`` verifies against the Merkle ``root`` and
|
||||||
## ``branch``.
|
## ``branch``.
|
||||||
|
@ -116,7 +116,7 @@ func get_validator_churn_limit(state: BeaconState): uint64 =
|
||||||
max(MIN_PER_EPOCH_CHURN_LIMIT,
|
max(MIN_PER_EPOCH_CHURN_LIMIT,
|
||||||
len(active_validator_indices) div CHURN_LIMIT_QUOTIENT).uint64
|
len(active_validator_indices) div CHURN_LIMIT_QUOTIENT).uint64
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/core/0_beacon-chain.md#initiate_validator_exit
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#initiate_validator_exit
|
||||||
func initiate_validator_exit*(state: var BeaconState,
|
func initiate_validator_exit*(state: var BeaconState,
|
||||||
index: ValidatorIndex) =
|
index: ValidatorIndex) =
|
||||||
# Initiate the exit of the validator with index ``index``.
|
# Initiate the exit of the validator with index ``index``.
|
||||||
|
@ -274,7 +274,7 @@ func get_initial_beacon_block*(state: BeaconState): SignedBeaconBlock =
|
||||||
# parent_root, randao_reveal, eth1_data, signature, and body automatically
|
# parent_root, randao_reveal, eth1_data, signature, and body automatically
|
||||||
# initialized to default values.
|
# initialized to default values.
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/core/0_beacon-chain.md#get_block_root_at_slot
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#get_block_root_at_slot
|
||||||
func get_block_root_at_slot*(state: BeaconState,
|
func get_block_root_at_slot*(state: BeaconState,
|
||||||
slot: Slot): Eth2Digest =
|
slot: Slot): Eth2Digest =
|
||||||
# Return the block root at a recent ``slot``.
|
# Return the block root at a recent ``slot``.
|
||||||
|
|
|
@ -118,7 +118,7 @@ type
|
||||||
attestation_1*: IndexedAttestation
|
attestation_1*: IndexedAttestation
|
||||||
attestation_2*: IndexedAttestation
|
attestation_2*: IndexedAttestation
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/core/0_beacon-chain.md#indexedattestation
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#indexedattestation
|
||||||
IndexedAttestation* = object
|
IndexedAttestation* = object
|
||||||
# TODO ValidatorIndex, but that doesn't serialize properly
|
# TODO ValidatorIndex, but that doesn't serialize properly
|
||||||
attesting_indices*: List[uint64, MAX_VALIDATORS_PER_COMMITTEE]
|
attesting_indices*: List[uint64, MAX_VALIDATORS_PER_COMMITTEE]
|
||||||
|
@ -163,14 +163,14 @@ type
|
||||||
withdrawal_credentials*: Eth2Digest
|
withdrawal_credentials*: Eth2Digest
|
||||||
amount*: Gwei
|
amount*: Gwei
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/core/0_beacon-chain.md#depositdata
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#depositdata
|
||||||
DepositData* = object
|
DepositData* = object
|
||||||
pubkey*: ValidatorPubKey
|
pubkey*: ValidatorPubKey
|
||||||
withdrawal_credentials*: Eth2Digest
|
withdrawal_credentials*: Eth2Digest
|
||||||
amount*: uint64
|
amount*: uint64
|
||||||
signature*: ValidatorSig # signing over DepositMessage
|
signature*: ValidatorSig # signing over DepositMessage
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/core/0_beacon-chain.md#voluntaryexit
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#voluntaryexit
|
||||||
VoluntaryExit* = object
|
VoluntaryExit* = object
|
||||||
epoch*: Epoch ##\
|
epoch*: Epoch ##\
|
||||||
## Earliest epoch when voluntary exit can be processed
|
## Earliest epoch when voluntary exit can be processed
|
||||||
|
@ -215,7 +215,7 @@ type
|
||||||
deposits*: List[Deposit, MAX_DEPOSITS]
|
deposits*: List[Deposit, MAX_DEPOSITS]
|
||||||
voluntary_exits*: List[SignedVoluntaryExit, MAX_VOLUNTARY_EXITS]
|
voluntary_exits*: List[SignedVoluntaryExit, MAX_VOLUNTARY_EXITS]
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/core/0_beacon-chain.md#beaconstate
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#beaconstate
|
||||||
BeaconState* = object
|
BeaconState* = object
|
||||||
# Versioning
|
# Versioning
|
||||||
genesis_time*: uint64
|
genesis_time*: uint64
|
||||||
|
@ -242,7 +242,7 @@ type
|
||||||
validators*: seq[Validator]
|
validators*: seq[Validator]
|
||||||
balances*: seq[uint64]
|
balances*: seq[uint64]
|
||||||
|
|
||||||
# Shuffling
|
# Randomness
|
||||||
randao_mixes*: array[EPOCHS_PER_HISTORICAL_VECTOR, Eth2Digest]
|
randao_mixes*: array[EPOCHS_PER_HISTORICAL_VECTOR, Eth2Digest]
|
||||||
|
|
||||||
# Slashings
|
# Slashings
|
||||||
|
@ -299,7 +299,7 @@ type
|
||||||
|
|
||||||
proposer_index*: uint64
|
proposer_index*: uint64
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/core/0_beacon-chain.md#historicalbatch
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#historicalbatch
|
||||||
HistoricalBatch* = object
|
HistoricalBatch* = object
|
||||||
block_roots* : array[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest]
|
block_roots* : array[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest]
|
||||||
state_roots* : array[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest]
|
state_roots* : array[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest]
|
||||||
|
@ -335,7 +335,7 @@ type
|
||||||
message*: BeaconBlockHeader
|
message*: BeaconBlockHeader
|
||||||
signature*: ValidatorSig
|
signature*: ValidatorSig
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/validator/0_beacon-chain-validator.md#aggregateandproof
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/validator/0_beacon-chain-validator.md#aggregateandproof
|
||||||
AggregateAndProof* = object
|
AggregateAndProof* = object
|
||||||
aggregator_index*: uint64
|
aggregator_index*: uint64
|
||||||
aggregate*: Attestation
|
aggregate*: Attestation
|
||||||
|
|
|
@ -36,7 +36,7 @@ func compute_epoch_at_slot*(slot: Slot|uint64): Epoch =
|
||||||
template epoch*(slot: Slot): Epoch =
|
template epoch*(slot: Slot): Epoch =
|
||||||
compute_epoch_at_slot(slot)
|
compute_epoch_at_slot(slot)
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/core/0_beacon-chain.md#compute_start_slot_at_epoch
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#compute_start_slot_at_epoch
|
||||||
func compute_start_slot_at_epoch*(epoch: Epoch): Slot =
|
func compute_start_slot_at_epoch*(epoch: Epoch): Slot =
|
||||||
# Return the start slot of ``epoch``.
|
# Return the start slot of ``epoch``.
|
||||||
(epoch * SLOTS_PER_EPOCH).Slot
|
(epoch * SLOTS_PER_EPOCH).Slot
|
||||||
|
@ -54,7 +54,7 @@ func get_active_validator_indices*(state: BeaconState, epoch: Epoch):
|
||||||
if is_active_validator(val, epoch):
|
if is_active_validator(val, epoch):
|
||||||
result.add idx.ValidatorIndex
|
result.add idx.ValidatorIndex
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/core/0_beacon-chain.md#get_committee_count_at_slot
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#get_committee_count_at_slot
|
||||||
func get_committee_count_at_slot*(state: BeaconState, slot: Slot): uint64 =
|
func get_committee_count_at_slot*(state: BeaconState, slot: Slot): uint64 =
|
||||||
# Return the number of committees at ``slot``.
|
# Return the number of committees at ``slot``.
|
||||||
let epoch = compute_epoch_at_slot(slot)
|
let epoch = compute_epoch_at_slot(slot)
|
||||||
|
|
|
@ -45,7 +45,7 @@ const
|
||||||
MIN_GENESIS_ACTIVE_VALIDATOR_COUNT* {.intdefine.} = 16384
|
MIN_GENESIS_ACTIVE_VALIDATOR_COUNT* {.intdefine.} = 16384
|
||||||
|
|
||||||
# Constants (TODO: not actually configurable)
|
# Constants (TODO: not actually configurable)
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/core/0_beacon-chain.md#constants
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/configs/mainnet.yaml#L110
|
||||||
BASE_REWARDS_PER_EPOCH* = 4
|
BASE_REWARDS_PER_EPOCH* = 4
|
||||||
|
|
||||||
DEPOSIT_CONTRACT_TREE_DEPTH* = 32
|
DEPOSIT_CONTRACT_TREE_DEPTH* = 32
|
||||||
|
@ -153,7 +153,7 @@ const
|
||||||
|
|
||||||
# Fork choice
|
# Fork choice
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/core/0_fork-choice.md#configuration
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/configs/mainnet.yaml#L26
|
||||||
SAFE_SLOTS_TO_UPDATE_JUSTIFIED* = 8 # 96 seconds
|
SAFE_SLOTS_TO_UPDATE_JUSTIFIED* = 8 # 96 seconds
|
||||||
|
|
||||||
# Validators
|
# Validators
|
||||||
|
|
|
@ -146,7 +146,7 @@ const
|
||||||
|
|
||||||
# Phase 1 - Sharding
|
# Phase 1 - Sharding
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/core/1_shard-data-chains.md#time-parameters
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/configs/minimal.yaml#L153
|
||||||
# TODO those are included in minimal.yaml but not mainnet.yaml
|
# TODO those are included in minimal.yaml but not mainnet.yaml
|
||||||
# Why?
|
# Why?
|
||||||
SHARD_SLOTS_PER_BEACON_SLOT* = 2 # spec: SHARD_SLOTS_PER_EPOCH
|
SHARD_SLOTS_PER_BEACON_SLOT* = 2 # spec: SHARD_SLOTS_PER_EPOCH
|
||||||
|
|
|
@ -124,7 +124,7 @@ proc process_randao(
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/core/0_beacon-chain.md#eth1-data
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#eth1-data
|
||||||
func process_eth1_data(state: var BeaconState, body: BeaconBlockBody) =
|
func process_eth1_data(state: var BeaconState, body: BeaconBlockBody) =
|
||||||
state.eth1_data_votes.add body.eth1_data
|
state.eth1_data_votes.add body.eth1_data
|
||||||
if state.eth1_data_votes.count(body.eth1_data) * 2 >
|
if state.eth1_data_votes.count(body.eth1_data) * 2 >
|
||||||
|
|
|
@ -99,7 +99,7 @@ func get_attesting_balance(
|
||||||
get_total_balance(state, get_unslashed_attesting_indices(
|
get_total_balance(state, get_unslashed_attesting_indices(
|
||||||
state, attestations, stateCache))
|
state, attestations, stateCache))
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/core/0_beacon-chain.md#justification-and-finalization
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#justification-and-finalization
|
||||||
proc process_justification_and_finalization*(
|
proc process_justification_and_finalization*(
|
||||||
state: var BeaconState, stateCache: var StateCache) =
|
state: var BeaconState, stateCache: var StateCache) =
|
||||||
|
|
||||||
|
@ -348,7 +348,7 @@ func process_rewards_and_penalties(
|
||||||
increase_balance(state, i.ValidatorIndex, rewards[i])
|
increase_balance(state, i.ValidatorIndex, rewards[i])
|
||||||
decrease_balance(state, i.ValidatorIndex, penalties[i])
|
decrease_balance(state, i.ValidatorIndex, penalties[i])
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/core/0_beacon-chain.md#slashings
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#slashings
|
||||||
func process_slashings*(state: var BeaconState) =
|
func process_slashings*(state: var BeaconState) =
|
||||||
let
|
let
|
||||||
epoch = get_current_epoch(state)
|
epoch = get_current_epoch(state)
|
||||||
|
|
|
@ -32,7 +32,7 @@ func get_attesting_indices*(
|
||||||
result = result.union(get_attesting_indices(
|
result = result.union(get_attesting_indices(
|
||||||
state, a.data, a.aggregation_bits, stateCache))
|
state, a.data, a.aggregation_bits, stateCache))
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/core/0_beacon-chain.md#helper-functions-1
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#helper-functions-1
|
||||||
func get_unslashed_attesting_indices*(
|
func get_unslashed_attesting_indices*(
|
||||||
state: BeaconState, attestations: openarray[PendingAttestation],
|
state: BeaconState, attestations: openarray[PendingAttestation],
|
||||||
stateCache: var StateCache): HashSet[ValidatorIndex] =
|
stateCache: var StateCache): HashSet[ValidatorIndex] =
|
||||||
|
|
|
@ -87,7 +87,7 @@ func get_previous_epoch*(state: BeaconState): Epoch =
|
||||||
else:
|
else:
|
||||||
current_epoch - 1
|
current_epoch - 1
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/core/0_beacon-chain.md#compute_committee
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#compute_committee
|
||||||
func compute_committee(indices: seq[ValidatorIndex], seed: Eth2Digest,
|
func compute_committee(indices: seq[ValidatorIndex], seed: Eth2Digest,
|
||||||
index: uint64, count: uint64, stateCache: var StateCache): seq[ValidatorIndex] =
|
index: uint64, count: uint64, stateCache: var StateCache): seq[ValidatorIndex] =
|
||||||
## Return the committee corresponding to ``indices``, ``seed``, ``index``,
|
## Return the committee corresponding to ``indices``, ``seed``, ``index``,
|
||||||
|
|
Loading…
Reference in New Issue