mark all compatible 0.9.3 functions and data structures as 0.9.4
This commit is contained in:
parent
b49a2f8c2c
commit
46de726e3d
|
@ -16,7 +16,7 @@ Nimbus beacon chain is a research implementation of the beacon chain component o
|
||||||
## Related
|
## Related
|
||||||
|
|
||||||
* [status-im/nimbus](https://github.com/status-im/nimbus/): Nimbus for Ethereum 1
|
* [status-im/nimbus](https://github.com/status-im/nimbus/): Nimbus for Ethereum 1
|
||||||
* [ethereum/eth2.0-specs](https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md): Serenity specification that this project implements
|
* [ethereum/eth2.0-specs](https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md): Serenity specification that this project implements
|
||||||
|
|
||||||
You can check where the beacon chain fits in the Ethereum ecosystem our Two-Point-Oh series: https://our.status.im/tag/two-point-oh/
|
You can check where the beacon chain fits in the Ethereum ecosystem our Two-Point-Oh series: https://our.status.im/tag/two-point-oh/
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
# The other part is arguably part of attestation pool -- the validation's
|
# The other part is arguably part of attestation pool -- the validation's
|
||||||
# something that should be happing on receipt, not aggregation per se. In
|
# something that should be happing on receipt, not aggregation per se. In
|
||||||
# that part, check that messages conform -- so, check for each type
|
# that part, check that messages conform -- so, check for each type
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/networking/p2p-interface.md#topics-and-messages
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/networking/p2p-interface.md#topics-and-messages
|
||||||
# specifies. So by the time this calls attestation pool, all validation's
|
# specifies. So by the time this calls attestation pool, all validation's
|
||||||
# already done.
|
# already done.
|
||||||
#
|
#
|
||||||
|
@ -30,17 +30,17 @@ import
|
||||||
# https://github.com/status-im/nim-beacon-chain/issues/122#issuecomment-562479965
|
# https://github.com/status-im/nim-beacon-chain/issues/122#issuecomment-562479965
|
||||||
|
|
||||||
const
|
const
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/networking/p2p-interface.md#configuration
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/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.3/specs/validator/0_beacon-chain-validator.md#aggregation-selection
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/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 =
|
||||||
get_domain(state, DOMAIN_BEACON_ATTESTER, compute_epoch_at_slot(slot))
|
get_domain(state, DOMAIN_BEACON_ATTESTER, compute_epoch_at_slot(slot))
|
||||||
bls_sign(privkey, hash_tree_root(slot).data, domain)
|
bls_sign(privkey, hash_tree_root(slot).data, domain)
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/validator/0_beacon-chain-validator.md#aggregation-selection
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/validator/0_beacon-chain-validator.md#aggregation-selection
|
||||||
func is_aggregator(state: BeaconState, slot: Slot, index: uint64,
|
func is_aggregator(state: BeaconState, slot: Slot, index: uint64,
|
||||||
slot_signature: ValidatorSig): bool =
|
slot_signature: ValidatorSig): bool =
|
||||||
# TODO index is a CommitteeIndex, aka uint64
|
# TODO index is a CommitteeIndex, aka uint64
|
||||||
|
@ -65,17 +65,17 @@ proc aggregate_attestations*(
|
||||||
doAssert slot + ATTESTATION_PROPAGATION_SLOT_RANGE >= state.slot
|
doAssert slot + ATTESTATION_PROPAGATION_SLOT_RANGE >= state.slot
|
||||||
doAssert state.slot >= slot
|
doAssert state.slot >= slot
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/validator/0_beacon-chain-validator.md#aggregation-selection
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/validator/0_beacon-chain-validator.md#aggregation-selection
|
||||||
if not is_aggregator(state, slot, index, slot_signature):
|
if not is_aggregator(state, slot, index, slot_signature):
|
||||||
return none(AggregateAndProof)
|
return none(AggregateAndProof)
|
||||||
|
|
||||||
let attestation_data =
|
let attestation_data =
|
||||||
makeAttestationData(state, slot, index, get_block_root_at_slot(state, slot))
|
makeAttestationData(state, slot, index, get_block_root_at_slot(state, slot))
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/validator/0_beacon-chain-validator.md#construct-aggregate
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/validator/0_beacon-chain-validator.md#construct-aggregate
|
||||||
for attestation in getAttestationsForBlock(pool, state, slot):
|
for attestation in getAttestationsForBlock(pool, state, slot):
|
||||||
if attestation.data == attestation_data:
|
if attestation.data == attestation_data:
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/validator/0_beacon-chain-validator.md#aggregateandproof
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/validator/0_beacon-chain-validator.md#aggregateandproof
|
||||||
return some(AggregateAndProof(
|
return some(AggregateAndProof(
|
||||||
aggregator_index: index,
|
aggregator_index: index,
|
||||||
aggregate: attestation,
|
aggregate: attestation,
|
||||||
|
|
|
@ -765,7 +765,7 @@ proc onSlotStart(node: BeaconNode, lastSlot, scheduledSlot: Slot) {.gcsafe, asyn
|
||||||
# with any clock discrepancies once only, at the start of slot timer
|
# with any clock discrepancies once only, at the start of slot timer
|
||||||
# processing..
|
# processing..
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/validator/0_beacon-chain-validator.md#attesting
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/validator/0_beacon-chain-validator.md#attesting
|
||||||
# A validator should create and broadcast the attestation to the
|
# A validator should create and broadcast the attestation to the
|
||||||
# associated attestation subnet one-third of the way through the slot
|
# associated attestation subnet one-third of the way through the slot
|
||||||
# during which the validator is assigned―that is, SECONDS_PER_SLOT / 3
|
# during which the validator is assigned―that is, SECONDS_PER_SLOT / 3
|
||||||
|
|
|
@ -39,7 +39,7 @@ const eth1BlockHash* = block:
|
||||||
for v in x.data.mitems: v = 0x42
|
for v in x.data.mitems: v = 0x42
|
||||||
x
|
x
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_deposit-contract.md#withdrawal-credentials
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_deposit-contract.md#withdrawal-credentials
|
||||||
func makeWithdrawalCredentials*(k: ValidatorPubKey): Eth2Digest =
|
func makeWithdrawalCredentials*(k: ValidatorPubKey): Eth2Digest =
|
||||||
var bytes = eth2hash(k.getBytes())
|
var bytes = eth2hash(k.getBytes())
|
||||||
bytes.data[0] = BLS_WITHDRAWAL_PREFIX.uint8
|
bytes.data[0] = BLS_WITHDRAWAL_PREFIX.uint8
|
||||||
|
|
|
@ -12,7 +12,7 @@ import
|
||||||
./crypto, ./datatypes, ./digest, ./helpers, ./validator,
|
./crypto, ./datatypes, ./digest, ./helpers, ./validator,
|
||||||
../../nbench/bench_lab
|
../../nbench/bench_lab
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#is_valid_merkle_branch
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/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 {.nbench.}=
|
func is_valid_merkle_branch*(leaf: Eth2Digest, branch: openarray[Eth2Digest], depth: uint64, index: uint64, root: Eth2Digest): bool {.nbench.}=
|
||||||
## Check if ``leaf`` at ``index`` verifies against the Merkle ``root`` and
|
## Check if ``leaf`` at ``index`` verifies against the Merkle ``root`` and
|
||||||
## ``branch``.
|
## ``branch``.
|
||||||
|
@ -30,13 +30,13 @@ func is_valid_merkle_branch*(leaf: Eth2Digest, branch: openarray[Eth2Digest], de
|
||||||
value = eth2hash(buf)
|
value = eth2hash(buf)
|
||||||
value == root
|
value == root
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#increase_balance
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#increase_balance
|
||||||
func increase_balance*(
|
func increase_balance*(
|
||||||
state: var BeaconState, index: ValidatorIndex, delta: Gwei) =
|
state: var BeaconState, index: ValidatorIndex, delta: Gwei) =
|
||||||
# Increase the validator balance at index ``index`` by ``delta``.
|
# Increase the validator balance at index ``index`` by ``delta``.
|
||||||
state.balances[index] += delta
|
state.balances[index] += delta
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#decrease_balance
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#decrease_balance
|
||||||
func decrease_balance*(
|
func decrease_balance*(
|
||||||
state: var BeaconState, index: ValidatorIndex, delta: Gwei) =
|
state: var BeaconState, index: ValidatorIndex, delta: Gwei) =
|
||||||
## Decrease the validator balance at index ``index`` by ``delta``, with
|
## Decrease the validator balance at index ``index`` by ``delta``, with
|
||||||
|
@ -103,13 +103,13 @@ func process_deposit*(
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#compute_activation_exit_epoch
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#compute_activation_exit_epoch
|
||||||
func compute_activation_exit_epoch(epoch: Epoch): Epoch =
|
func compute_activation_exit_epoch(epoch: Epoch): Epoch =
|
||||||
## Return the epoch during which validator activations and exits initiated in
|
## Return the epoch during which validator activations and exits initiated in
|
||||||
## ``epoch`` take effect.
|
## ``epoch`` take effect.
|
||||||
epoch + 1 + MAX_SEED_LOOKAHEAD
|
epoch + 1 + MAX_SEED_LOOKAHEAD
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#get_validator_churn_limit
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#get_validator_churn_limit
|
||||||
func get_validator_churn_limit(state: BeaconState): uint64 =
|
func get_validator_churn_limit(state: BeaconState): uint64 =
|
||||||
# Return the validator churn limit for the current epoch.
|
# Return the validator churn limit for the current epoch.
|
||||||
let active_validator_indices =
|
let active_validator_indices =
|
||||||
|
@ -117,7 +117,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.3/specs/core/0_beacon-chain.md#initiate_validator_exit
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/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``.
|
||||||
|
@ -190,7 +190,7 @@ proc slash_validator*(state: var BeaconState, slashed_index: ValidatorIndex,
|
||||||
increase_balance(
|
increase_balance(
|
||||||
state, whistleblower_index, whistleblowing_reward - proposer_reward)
|
state, whistleblower_index, whistleblowing_reward - proposer_reward)
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#genesis
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#genesis
|
||||||
func initialize_beacon_state_from_eth1*(
|
func initialize_beacon_state_from_eth1*(
|
||||||
eth1_block_hash: Eth2Digest,
|
eth1_block_hash: Eth2Digest,
|
||||||
eth1_timestamp: uint64,
|
eth1_timestamp: uint64,
|
||||||
|
@ -275,7 +275,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.3/specs/core/0_beacon-chain.md#get_block_root_at_slot
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/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``.
|
||||||
|
@ -284,12 +284,12 @@ func get_block_root_at_slot*(state: BeaconState,
|
||||||
doAssert slot < state.slot
|
doAssert slot < state.slot
|
||||||
state.block_roots[slot mod SLOTS_PER_HISTORICAL_ROOT]
|
state.block_roots[slot mod SLOTS_PER_HISTORICAL_ROOT]
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#get_block_root
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#get_block_root
|
||||||
func get_block_root*(state: BeaconState, epoch: Epoch): Eth2Digest =
|
func get_block_root*(state: BeaconState, epoch: Epoch): Eth2Digest =
|
||||||
# Return the block root at the start of a recent ``epoch``.
|
# Return the block root at the start of a recent ``epoch``.
|
||||||
get_block_root_at_slot(state, compute_start_slot_at_epoch(epoch))
|
get_block_root_at_slot(state, compute_start_slot_at_epoch(epoch))
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#get_total_balance
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#get_total_balance
|
||||||
func get_total_balance*(state: BeaconState, validators: auto): Gwei =
|
func get_total_balance*(state: BeaconState, validators: auto): Gwei =
|
||||||
## Return the combined effective balance of the ``indices``. (1 Gwei minimum
|
## Return the combined effective balance of the ``indices``. (1 Gwei minimum
|
||||||
## to avoid divisions by zero.)
|
## to avoid divisions by zero.)
|
||||||
|
@ -299,13 +299,13 @@ func get_total_balance*(state: BeaconState, validators: auto): Gwei =
|
||||||
|
|
||||||
# XXX: Move to state_transition_epoch.nim?
|
# XXX: Move to state_transition_epoch.nim?
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#is_eligible_for_activation_queue
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#is_eligible_for_activation_queue
|
||||||
func is_eligible_for_activation_queue(validator: Validator): bool =
|
func is_eligible_for_activation_queue(validator: Validator): bool =
|
||||||
# Check if ``validator`` is eligible to be placed into the activation queue.
|
# Check if ``validator`` is eligible to be placed into the activation queue.
|
||||||
validator.activation_eligibility_epoch == FAR_FUTURE_EPOCH and
|
validator.activation_eligibility_epoch == FAR_FUTURE_EPOCH and
|
||||||
validator.effective_balance == MAX_EFFECTIVE_BALANCE
|
validator.effective_balance == MAX_EFFECTIVE_BALANCE
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#is_eligible_for_activation
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#is_eligible_for_activation
|
||||||
func is_eligible_for_activation(state: BeaconState, validator: Validator):
|
func is_eligible_for_activation(state: BeaconState, validator: Validator):
|
||||||
bool =
|
bool =
|
||||||
# Check if ``validator`` is eligible for activation.
|
# Check if ``validator`` is eligible for activation.
|
||||||
|
@ -315,7 +315,7 @@ func is_eligible_for_activation(state: BeaconState, validator: Validator):
|
||||||
# Has not yet been activated
|
# Has not yet been activated
|
||||||
validator.activation_epoch == FAR_FUTURE_EPOCH
|
validator.activation_epoch == FAR_FUTURE_EPOCH
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#registry-updates
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#registry-updates
|
||||||
proc process_registry_updates*(state: var BeaconState) {.nbench.}=
|
proc process_registry_updates*(state: var BeaconState) {.nbench.}=
|
||||||
## Process activation eligibility and ejections
|
## Process activation eligibility and ejections
|
||||||
## Try to avoid caching here, since this could easily become undefined
|
## Try to avoid caching here, since this could easily become undefined
|
||||||
|
@ -367,7 +367,7 @@ proc process_registry_updates*(state: var BeaconState) {.nbench.}=
|
||||||
validator.activation_epoch =
|
validator.activation_epoch =
|
||||||
compute_activation_exit_epoch(get_current_epoch(state))
|
compute_activation_exit_epoch(get_current_epoch(state))
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#is_valid_indexed_attestation
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#is_valid_indexed_attestation
|
||||||
proc is_valid_indexed_attestation*(
|
proc is_valid_indexed_attestation*(
|
||||||
state: BeaconState, indexed_attestation: IndexedAttestation): bool =
|
state: BeaconState, indexed_attestation: IndexedAttestation): bool =
|
||||||
## Check if ``indexed_attestation`` has valid indices and signature.
|
## Check if ``indexed_attestation`` has valid indices and signature.
|
||||||
|
@ -400,7 +400,7 @@ proc is_valid_indexed_attestation*(
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#get_attesting_indices
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#get_attesting_indices
|
||||||
func get_attesting_indices*(state: BeaconState,
|
func get_attesting_indices*(state: BeaconState,
|
||||||
data: AttestationData,
|
data: AttestationData,
|
||||||
bits: CommitteeValidatorsBits,
|
bits: CommitteeValidatorsBits,
|
||||||
|
@ -413,7 +413,7 @@ func get_attesting_indices*(state: BeaconState,
|
||||||
if bits[i]:
|
if bits[i]:
|
||||||
result.incl index
|
result.incl index
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#get_indexed_attestation
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#get_indexed_attestation
|
||||||
func get_indexed_attestation(state: BeaconState, attestation: Attestation,
|
func get_indexed_attestation(state: BeaconState, attestation: Attestation,
|
||||||
stateCache: var StateCache): IndexedAttestation =
|
stateCache: var StateCache): IndexedAttestation =
|
||||||
# Return the indexed attestation corresponding to ``attestation``.
|
# Return the indexed attestation corresponding to ``attestation``.
|
||||||
|
|
|
@ -141,15 +141,15 @@ func combine*[T](x: var BlsValue[T], other: BlsValue[T]) =
|
||||||
doAssert x.kind == Real and other.kind == Real
|
doAssert x.kind == Real and other.kind == Real
|
||||||
x.blsValue.combine(other.blsValue)
|
x.blsValue.combine(other.blsValue)
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/bls_signature.md#bls_aggregate_pubkeys
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/bls_signature.md#bls_aggregate_pubkeys
|
||||||
func bls_aggregate_pubkeys*(keys: openArray[ValidatorPubKey]): ValidatorPubKey =
|
func bls_aggregate_pubkeys*(keys: openArray[ValidatorPubKey]): ValidatorPubKey =
|
||||||
keys.combine()
|
keys.combine()
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/bls_signature.md#bls_aggregate_signatures
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/bls_signature.md#bls_aggregate_signatures
|
||||||
func bls_aggregate_signatures*(keys: openArray[ValidatorSig]): ValidatorSig =
|
func bls_aggregate_signatures*(keys: openArray[ValidatorSig]): ValidatorSig =
|
||||||
keys.combine()
|
keys.combine()
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/bls_signature.md#bls_verify
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/bls_signature.md#bls_verify
|
||||||
func bls_verify*(
|
func bls_verify*(
|
||||||
pubkey: ValidatorPubKey, msg: openArray[byte], sig: ValidatorSig,
|
pubkey: ValidatorPubKey, msg: openArray[byte], sig: ValidatorSig,
|
||||||
domain: Domain): bool =
|
domain: Domain): bool =
|
||||||
|
|
|
@ -52,13 +52,13 @@ else:
|
||||||
{.fatal: "Preset \"" & const_preset ".nim\" is not supported.".}
|
{.fatal: "Preset \"" & const_preset ".nim\" is not supported.".}
|
||||||
|
|
||||||
const
|
const
|
||||||
SPEC_VERSION* = "0.9.3" ## \
|
SPEC_VERSION* = "0.9.4" ## \
|
||||||
## Spec version we're aiming to be compatible with, right now
|
## Spec version we're aiming to be compatible with, right now
|
||||||
## TODO: improve this scheme once we can negotiate versions in protocol
|
## TODO: improve this scheme once we can negotiate versions in protocol
|
||||||
|
|
||||||
# Initial values
|
# Initial values
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#initial-values
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#initial-values
|
||||||
GENESIS_EPOCH* = (GENESIS_SLOT.uint64 div SLOTS_PER_EPOCH).Epoch ##\
|
GENESIS_EPOCH* = (GENESIS_SLOT.uint64 div SLOTS_PER_EPOCH).Epoch ##\
|
||||||
## compute_epoch_at_slot(GENESIS_SLOT)
|
## compute_epoch_at_slot(GENESIS_SLOT)
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ type
|
||||||
|
|
||||||
# Domains
|
# Domains
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#domain-types
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#domain-types
|
||||||
DomainType* {.pure.} = enum
|
DomainType* {.pure.} = enum
|
||||||
DOMAIN_BEACON_PROPOSER = 0
|
DOMAIN_BEACON_PROPOSER = 0
|
||||||
DOMAIN_BEACON_ATTESTER = 1
|
DOMAIN_BEACON_ATTESTER = 1
|
||||||
|
@ -88,10 +88,10 @@ type
|
||||||
DOMAIN_DEPOSIT = 3
|
DOMAIN_DEPOSIT = 3
|
||||||
DOMAIN_VOLUNTARY_EXIT = 4
|
DOMAIN_VOLUNTARY_EXIT = 4
|
||||||
# Phase 1 - Custody game
|
# Phase 1 - Custody game
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/1_custody-game.md#signature-domain-types
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/1_custody-game.md#signature-domain-types
|
||||||
DOMAIN_CUSTODY_BIT_CHALLENGE = 6
|
DOMAIN_CUSTODY_BIT_CHALLENGE = 6
|
||||||
# Phase 1 - Sharding
|
# Phase 1 - Sharding
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/1_shard-data-chains.md#signature-domain-types
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/1_shard-data-chains.md#signature-domain-types
|
||||||
DOMAIN_SHARD_PROPOSER = 128
|
DOMAIN_SHARD_PROPOSER = 128
|
||||||
DOMAIN_SHARD_ATTESTER = 129
|
DOMAIN_SHARD_ATTESTER = 129
|
||||||
|
|
||||||
|
@ -107,18 +107,18 @@ type
|
||||||
|
|
||||||
BitList*[maxLen: static int] = distinct BitSeq
|
BitList*[maxLen: static int] = distinct BitSeq
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#proposerslashing
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#proposerslashing
|
||||||
ProposerSlashing* = object
|
ProposerSlashing* = object
|
||||||
proposer_index*: uint64
|
proposer_index*: uint64
|
||||||
signed_header_1*: SignedBeaconBlockHeader
|
signed_header_1*: SignedBeaconBlockHeader
|
||||||
signed_header_2*: SignedBeaconBlockHeader
|
signed_header_2*: SignedBeaconBlockHeader
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#attesterslashing
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#attesterslashing
|
||||||
AttesterSlashing* = object
|
AttesterSlashing* = object
|
||||||
attestation_1*: IndexedAttestation
|
attestation_1*: IndexedAttestation
|
||||||
attestation_2*: IndexedAttestation
|
attestation_2*: IndexedAttestation
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#indexedattestation
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/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]
|
||||||
|
@ -127,18 +127,18 @@ type
|
||||||
|
|
||||||
CommitteeValidatorsBits* = BitList[MAX_VALIDATORS_PER_COMMITTEE]
|
CommitteeValidatorsBits* = BitList[MAX_VALIDATORS_PER_COMMITTEE]
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#attestation
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#attestation
|
||||||
Attestation* = object
|
Attestation* = object
|
||||||
aggregation_bits*: CommitteeValidatorsBits
|
aggregation_bits*: CommitteeValidatorsBits
|
||||||
data*: AttestationData
|
data*: AttestationData
|
||||||
signature*: ValidatorSig
|
signature*: ValidatorSig
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#checkpoint
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#checkpoint
|
||||||
Checkpoint* = object
|
Checkpoint* = object
|
||||||
epoch*: Epoch
|
epoch*: Epoch
|
||||||
root*: Eth2Digest
|
root*: Eth2Digest
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#AttestationData
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#AttestationData
|
||||||
AttestationData* = object
|
AttestationData* = object
|
||||||
slot*: Slot
|
slot*: Slot
|
||||||
index*: uint64
|
index*: uint64
|
||||||
|
@ -150,34 +150,34 @@ type
|
||||||
source*: Checkpoint
|
source*: Checkpoint
|
||||||
target*: Checkpoint
|
target*: Checkpoint
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#deposit
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#deposit
|
||||||
Deposit* = object
|
Deposit* = object
|
||||||
proof*: array[DEPOSIT_CONTRACT_TREE_DEPTH + 1, Eth2Digest] ##\
|
proof*: array[DEPOSIT_CONTRACT_TREE_DEPTH + 1, Eth2Digest] ##\
|
||||||
## Merkle path to deposit data list root
|
## Merkle path to deposit data list root
|
||||||
|
|
||||||
data*: DepositData
|
data*: DepositData
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#depositdata
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#depositdata
|
||||||
DepositMessage* = object
|
DepositMessage* = object
|
||||||
pubkey*: ValidatorPubKey
|
pubkey*: ValidatorPubKey
|
||||||
withdrawal_credentials*: Eth2Digest
|
withdrawal_credentials*: Eth2Digest
|
||||||
amount*: Gwei
|
amount*: Gwei
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#depositdata
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/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.3/specs/core/0_beacon-chain.md#voluntaryexit
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/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
|
||||||
|
|
||||||
validator_index*: uint64
|
validator_index*: uint64
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#beaconblock
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#beaconblock
|
||||||
BeaconBlock* = object
|
BeaconBlock* = object
|
||||||
## For each slot, a proposer is chosen from the validator pool to propose
|
## For each slot, a proposer is chosen from the validator pool to propose
|
||||||
## a new block. Once the block as been proposed, it is transmitted to
|
## a new block. Once the block as been proposed, it is transmitted to
|
||||||
|
@ -195,14 +195,14 @@ type
|
||||||
|
|
||||||
body*: BeaconBlockBody
|
body*: BeaconBlockBody
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#beaconblockheader
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#beaconblockheader
|
||||||
BeaconBlockHeader* = object
|
BeaconBlockHeader* = object
|
||||||
slot*: Slot
|
slot*: Slot
|
||||||
parent_root*: Eth2Digest
|
parent_root*: Eth2Digest
|
||||||
state_root*: Eth2Digest
|
state_root*: Eth2Digest
|
||||||
body_root*: Eth2Digest
|
body_root*: Eth2Digest
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#beaconblockbody
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#beaconblockbody
|
||||||
BeaconBlockBody* = object
|
BeaconBlockBody* = object
|
||||||
randao_reveal*: ValidatorSig
|
randao_reveal*: ValidatorSig
|
||||||
eth1_data*: Eth1Data
|
eth1_data*: Eth1Data
|
||||||
|
@ -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.3/specs/core/0_beacon-chain.md#beaconstate
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#beaconstate
|
||||||
BeaconState* = object
|
BeaconState* = object
|
||||||
# Versioning
|
# Versioning
|
||||||
genesis_time*: uint64
|
genesis_time*: uint64
|
||||||
|
@ -267,7 +267,7 @@ type
|
||||||
current_justified_checkpoint*: Checkpoint
|
current_justified_checkpoint*: Checkpoint
|
||||||
finalized_checkpoint*: Checkpoint
|
finalized_checkpoint*: Checkpoint
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#validator
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#validator
|
||||||
Validator* = object
|
Validator* = object
|
||||||
pubkey*: ValidatorPubKey
|
pubkey*: ValidatorPubKey
|
||||||
|
|
||||||
|
@ -289,7 +289,7 @@ type
|
||||||
withdrawable_epoch*: Epoch ##\
|
withdrawable_epoch*: Epoch ##\
|
||||||
## When validator can withdraw or transfer funds
|
## When validator can withdraw or transfer funds
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#pendingattestation
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#pendingattestation
|
||||||
PendingAttestation* = object
|
PendingAttestation* = object
|
||||||
aggregation_bits*: CommitteeValidatorsBits
|
aggregation_bits*: CommitteeValidatorsBits
|
||||||
data*: AttestationData
|
data*: AttestationData
|
||||||
|
@ -299,12 +299,12 @@ type
|
||||||
|
|
||||||
proposer_index*: uint64
|
proposer_index*: uint64
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#historicalbatch
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/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]
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#fork
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#fork
|
||||||
Fork* = object
|
Fork* = object
|
||||||
# TODO: Spec introduced an alias for Version = array[4, byte]
|
# TODO: Spec introduced an alias for Version = array[4, byte]
|
||||||
# and a default parameter to compute_domain
|
# and a default parameter to compute_domain
|
||||||
|
@ -314,28 +314,28 @@ type
|
||||||
epoch*: Epoch ##\
|
epoch*: Epoch ##\
|
||||||
## Epoch of latest fork
|
## Epoch of latest fork
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#eth1data
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#eth1data
|
||||||
Eth1Data* = object
|
Eth1Data* = object
|
||||||
deposit_root*: Eth2Digest
|
deposit_root*: Eth2Digest
|
||||||
deposit_count*: uint64
|
deposit_count*: uint64
|
||||||
block_hash*: Eth2Digest
|
block_hash*: Eth2Digest
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#signedvoluntaryexit
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#signedvoluntaryexit
|
||||||
SignedVoluntaryExit* = object
|
SignedVoluntaryExit* = object
|
||||||
message*: VoluntaryExit
|
message*: VoluntaryExit
|
||||||
signature*: ValidatorSig
|
signature*: ValidatorSig
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#signedbeaconblock
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#signedbeaconblock
|
||||||
SignedBeaconBlock* = object
|
SignedBeaconBlock* = object
|
||||||
message*: BeaconBlock
|
message*: BeaconBlock
|
||||||
signature*: ValidatorSig
|
signature*: ValidatorSig
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#signedvoluntaryexit
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#signedvoluntaryexit
|
||||||
SignedBeaconBlockHeader* = object
|
SignedBeaconBlockHeader* = object
|
||||||
message*: BeaconBlockHeader
|
message*: BeaconBlockHeader
|
||||||
signature*: ValidatorSig
|
signature*: ValidatorSig
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/validator/0_beacon-chain-validator.md#aggregateandproof
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/validator/0_beacon-chain-validator.md#aggregateandproof
|
||||||
AggregateAndProof* = object
|
AggregateAndProof* = object
|
||||||
aggregator_index*: uint64
|
aggregator_index*: uint64
|
||||||
aggregate*: Attestation
|
aggregate*: Attestation
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
# Serenity hash function / digest
|
# Serenity hash function / digest
|
||||||
#
|
#
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#hash
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#hash
|
||||||
#
|
#
|
||||||
# In Phase 0 the beacon chain is deployed with SHA256 (SHA2-256).
|
# In Phase 0 the beacon chain is deployed with SHA256 (SHA2-256).
|
||||||
# Note that is is different from Keccak256 (often mistakenly called SHA3-256)
|
# Note that is is different from Keccak256 (often mistakenly called SHA3-256)
|
||||||
|
|
|
@ -15,7 +15,7 @@ import
|
||||||
# Internal
|
# Internal
|
||||||
./datatypes, ./digest
|
./datatypes, ./digest
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#integer_squareroot
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#integer_squareroot
|
||||||
func integer_squareroot*(n: SomeInteger): SomeInteger =
|
func integer_squareroot*(n: SomeInteger): SomeInteger =
|
||||||
# Return the largest integer ``x`` such that ``x**2 <= n``.
|
# Return the largest integer ``x`` such that ``x**2 <= n``.
|
||||||
doAssert n >= 0'u64
|
doAssert n >= 0'u64
|
||||||
|
@ -28,7 +28,7 @@ func integer_squareroot*(n: SomeInteger): SomeInteger =
|
||||||
y = (x + n div x) div 2
|
y = (x + n div x) div 2
|
||||||
x
|
x
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#compute_epoch_at_slot
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#compute_epoch_at_slot
|
||||||
func compute_epoch_at_slot*(slot: Slot|uint64): Epoch =
|
func compute_epoch_at_slot*(slot: Slot|uint64): Epoch =
|
||||||
# Return the epoch number at ``slot``.
|
# Return the epoch number at ``slot``.
|
||||||
(slot div SLOTS_PER_EPOCH).Epoch
|
(slot div SLOTS_PER_EPOCH).Epoch
|
||||||
|
@ -36,17 +36,17 @@ 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.3/specs/core/0_beacon-chain.md#compute_start_slot_at_epoch
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/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
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#is_active_validator
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#is_active_validator
|
||||||
func is_active_validator*(validator: Validator, epoch: Epoch): bool =
|
func is_active_validator*(validator: Validator, epoch: Epoch): bool =
|
||||||
### Check if ``validator`` is active
|
### Check if ``validator`` is active
|
||||||
validator.activation_epoch <= epoch and epoch < validator.exit_epoch
|
validator.activation_epoch <= epoch and epoch < validator.exit_epoch
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#get_active_validator_indices
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#get_active_validator_indices
|
||||||
func get_active_validator_indices*(state: BeaconState, epoch: Epoch):
|
func get_active_validator_indices*(state: BeaconState, epoch: Epoch):
|
||||||
seq[ValidatorIndex] =
|
seq[ValidatorIndex] =
|
||||||
# Return the sequence of active validator indices at ``epoch``.
|
# Return the sequence of active validator indices at ``epoch``.
|
||||||
|
@ -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.3/specs/core/0_beacon-chain.md#get_committee_count_at_slot
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/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)
|
||||||
|
@ -67,13 +67,13 @@ func get_committee_count_at_slot*(state: BeaconState, slot: Slot): uint64 =
|
||||||
# Otherwise, get_beacon_committee(...) cannot access some committees.
|
# Otherwise, get_beacon_committee(...) cannot access some committees.
|
||||||
doAssert (SLOTS_PER_EPOCH * MAX_COMMITTEES_PER_SLOT).uint64 >= result
|
doAssert (SLOTS_PER_EPOCH * MAX_COMMITTEES_PER_SLOT).uint64 >= result
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#get_current_epoch
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#get_current_epoch
|
||||||
func get_current_epoch*(state: BeaconState): Epoch =
|
func get_current_epoch*(state: BeaconState): Epoch =
|
||||||
# Return the current epoch.
|
# Return the current epoch.
|
||||||
doAssert state.slot >= GENESIS_SLOT, $state.slot
|
doAssert state.slot >= GENESIS_SLOT, $state.slot
|
||||||
compute_epoch_at_slot(state.slot)
|
compute_epoch_at_slot(state.slot)
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#get_randao_mix
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#get_randao_mix
|
||||||
func get_randao_mix*(state: BeaconState,
|
func get_randao_mix*(state: BeaconState,
|
||||||
epoch: Epoch): Eth2Digest =
|
epoch: Epoch): Eth2Digest =
|
||||||
## Returns the randao mix at a recent ``epoch``.
|
## Returns the randao mix at a recent ``epoch``.
|
||||||
|
@ -114,7 +114,7 @@ func int_to_bytes4*(x: uint64): array[4, byte] =
|
||||||
result[2] = ((x shr 16) and 0xff).byte
|
result[2] = ((x shr 16) and 0xff).byte
|
||||||
result[3] = ((x shr 24) and 0xff).byte
|
result[3] = ((x shr 24) and 0xff).byte
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#compute_domain
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#compute_domain
|
||||||
func compute_domain*(
|
func compute_domain*(
|
||||||
domain_type: DomainType,
|
domain_type: DomainType,
|
||||||
fork_version: array[4, byte] = [0'u8, 0, 0, 0]): Domain =
|
fork_version: array[4, byte] = [0'u8, 0, 0, 0]): Domain =
|
||||||
|
@ -122,7 +122,7 @@ func compute_domain*(
|
||||||
result[0..3] = int_to_bytes4(domain_type.uint64)
|
result[0..3] = int_to_bytes4(domain_type.uint64)
|
||||||
result[4..7] = fork_version
|
result[4..7] = fork_version
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#get_domain
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#get_domain
|
||||||
func get_domain*(
|
func get_domain*(
|
||||||
fork: Fork, domain_type: DomainType, epoch: Epoch): Domain =
|
fork: Fork, domain_type: DomainType, epoch: Epoch): Domain =
|
||||||
## Return the signature domain (fork version concatenated with domain type)
|
## Return the signature domain (fork version concatenated with domain type)
|
||||||
|
@ -144,7 +144,7 @@ func get_domain*(
|
||||||
func get_domain*(state: BeaconState, domain_type: DomainType): Domain =
|
func get_domain*(state: BeaconState, domain_type: DomainType): Domain =
|
||||||
get_domain(state, domain_type, get_current_epoch(state))
|
get_domain(state, domain_type, get_current_epoch(state))
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#get_seed
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#get_seed
|
||||||
func get_seed*(state: BeaconState, epoch: Epoch, domain_type: DomainType): Eth2Digest =
|
func get_seed*(state: BeaconState, epoch: Epoch, domain_type: DomainType): Eth2Digest =
|
||||||
# Return the seed at ``epoch``.
|
# Return the seed at ``epoch``.
|
||||||
|
|
||||||
|
|
|
@ -153,12 +153,12 @@ const
|
||||||
|
|
||||||
# Fork choice
|
# Fork choice
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/configs/mainnet.yaml#L26
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/configs/mainnet.yaml#L26
|
||||||
SAFE_SLOTS_TO_UPDATE_JUSTIFIED* = 8 # 96 seconds
|
SAFE_SLOTS_TO_UPDATE_JUSTIFIED* = 8 # 96 seconds
|
||||||
|
|
||||||
# Validators
|
# Validators
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/configs/mainnet.yaml#L32
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/configs/mainnet.yaml#L32
|
||||||
ETH1_FOLLOW_DISTANCE* = 1024 # blocks ~ 4 hours
|
ETH1_FOLLOW_DISTANCE* = 1024 # blocks ~ 4 hours
|
||||||
TARGET_AGGREGATORS_PER_COMMITTEE* = 16 # validators
|
TARGET_AGGREGATORS_PER_COMMITTEE* = 16 # validators
|
||||||
RANDOM_SUBNETS_PER_VALIDATOR* = 1 # subnet
|
RANDOM_SUBNETS_PER_VALIDATOR* = 1 # subnet
|
||||||
|
@ -166,7 +166,7 @@ const
|
||||||
|
|
||||||
# Phase 1 - Sharding
|
# Phase 1 - Sharding
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/1_shard-data-chains.md#time-parameters
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/1_shard-data-chains.md#time-parameters
|
||||||
# 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
|
||||||
|
@ -176,7 +176,7 @@ const
|
||||||
|
|
||||||
# Phase 1 - Custody game
|
# Phase 1 - Custody game
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/1_custody-game.md#constants
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/1_custody-game.md#constants
|
||||||
# TODO those are included in minimal.yaml but not mainnet.yaml
|
# TODO those are included in minimal.yaml but not mainnet.yaml
|
||||||
# Why?
|
# Why?
|
||||||
# EARLY_DERIVED_SECRET_PENALTY_MAX_FUTURE_EPOCHS* = 4096 # epochs
|
# EARLY_DERIVED_SECRET_PENALTY_MAX_FUTURE_EPOCHS* = 4096 # epochs
|
||||||
|
|
|
@ -38,7 +38,7 @@ const
|
||||||
|
|
||||||
# Constants
|
# Constants
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#constants
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#constants
|
||||||
# TODO "The following values are (non-configurable) constants" ...
|
# TODO "The following values are (non-configurable) constants" ...
|
||||||
# Unchanged
|
# Unchanged
|
||||||
BASE_REWARDS_PER_EPOCH* = 4
|
BASE_REWARDS_PER_EPOCH* = 4
|
||||||
|
@ -127,7 +127,7 @@ const
|
||||||
|
|
||||||
# Fork choice
|
# Fork choice
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/configs/minimal.yaml#L26
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/configs/minimal.yaml#L26
|
||||||
|
|
||||||
# Changed
|
# Changed
|
||||||
SAFE_SLOTS_TO_UPDATE_JUSTIFIED* = 2
|
SAFE_SLOTS_TO_UPDATE_JUSTIFIED* = 2
|
||||||
|
@ -146,7 +146,7 @@ const
|
||||||
|
|
||||||
# Phase 1 - Sharding
|
# Phase 1 - Sharding
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/configs/minimal.yaml#L153
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/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
|
||||||
|
|
|
@ -44,7 +44,7 @@ declareGauge beacon_previous_live_validators, "Number of active validators that
|
||||||
declareGauge beacon_pending_deposits, "Number of pending deposits (state.eth1_data.deposit_count - state.eth1_deposit_index)" # On block
|
declareGauge beacon_pending_deposits, "Number of pending deposits (state.eth1_data.deposit_count - state.eth1_deposit_index)" # On block
|
||||||
declareGauge beacon_processed_deposits_total, "Number of total deposits included on chain" # On block
|
declareGauge beacon_processed_deposits_total, "Number of total deposits included on chain" # On block
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#block-header
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#block-header
|
||||||
proc process_block_header*(
|
proc process_block_header*(
|
||||||
state: var BeaconState, blck: BeaconBlock, flags: UpdateFlags,
|
state: var BeaconState, blck: BeaconBlock, flags: UpdateFlags,
|
||||||
stateCache: var StateCache): bool {.nbench.}=
|
stateCache: var StateCache): bool {.nbench.}=
|
||||||
|
@ -125,21 +125,21 @@ proc process_randao(
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#eth1-data
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#eth1-data
|
||||||
func process_eth1_data(state: var BeaconState, body: BeaconBlockBody) {.nbench.}=
|
func process_eth1_data(state: var BeaconState, body: BeaconBlockBody) {.nbench.}=
|
||||||
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 >
|
||||||
SLOTS_PER_ETH1_VOTING_PERIOD:
|
SLOTS_PER_ETH1_VOTING_PERIOD:
|
||||||
state.eth1_data = body.eth1_data
|
state.eth1_data = body.eth1_data
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#is_slashable_validator
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#is_slashable_validator
|
||||||
func is_slashable_validator(validator: Validator, epoch: Epoch): bool =
|
func is_slashable_validator(validator: Validator, epoch: Epoch): bool =
|
||||||
# Check if ``validator`` is slashable.
|
# Check if ``validator`` is slashable.
|
||||||
(not validator.slashed) and
|
(not validator.slashed) and
|
||||||
(validator.activation_epoch <= epoch) and
|
(validator.activation_epoch <= epoch) and
|
||||||
(epoch < validator.withdrawable_epoch)
|
(epoch < validator.withdrawable_epoch)
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#proposer-slashings
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#proposer-slashings
|
||||||
proc process_proposer_slashing*(
|
proc process_proposer_slashing*(
|
||||||
state: var BeaconState, proposer_slashing: ProposerSlashing,
|
state: var BeaconState, proposer_slashing: ProposerSlashing,
|
||||||
flags: UpdateFlags, stateCache: var StateCache): bool {.nbench.}=
|
flags: UpdateFlags, stateCache: var StateCache): bool {.nbench.}=
|
||||||
|
@ -201,7 +201,7 @@ proc processProposerSlashings(
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#is_slashable_attestation_data
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#is_slashable_attestation_data
|
||||||
func is_slashable_attestation_data(
|
func is_slashable_attestation_data(
|
||||||
data_1: AttestationData, data_2: AttestationData): bool =
|
data_1: AttestationData, data_2: AttestationData): bool =
|
||||||
## Check if ``data_1`` and ``data_2`` are slashable according to Casper FFG
|
## Check if ``data_1`` and ``data_2`` are slashable according to Casper FFG
|
||||||
|
@ -213,7 +213,7 @@ func is_slashable_attestation_data(
|
||||||
(data_1.source.epoch < data_2.source.epoch and
|
(data_1.source.epoch < data_2.source.epoch and
|
||||||
data_2.target.epoch < data_1.target.epoch)
|
data_2.target.epoch < data_1.target.epoch)
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#attester-slashings
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#attester-slashings
|
||||||
proc process_attester_slashing*(
|
proc process_attester_slashing*(
|
||||||
state: var BeaconState,
|
state: var BeaconState,
|
||||||
attester_slashing: AttesterSlashing,
|
attester_slashing: AttesterSlashing,
|
||||||
|
@ -250,7 +250,7 @@ proc process_attester_slashing*(
|
||||||
return false
|
return false
|
||||||
return true
|
return true
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#attester-slashings
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#attester-slashings
|
||||||
proc processAttesterSlashings(state: var BeaconState, blck: BeaconBlock,
|
proc processAttesterSlashings(state: var BeaconState, blck: BeaconBlock,
|
||||||
stateCache: var StateCache): bool {.nbench.}=
|
stateCache: var StateCache): bool {.nbench.}=
|
||||||
# Process ``AttesterSlashing`` operation.
|
# Process ``AttesterSlashing`` operation.
|
||||||
|
@ -298,7 +298,7 @@ proc processDeposits(state: var BeaconState, blck: BeaconBlock): bool {.nbench.}
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#voluntary-exits
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#voluntary-exits
|
||||||
proc process_voluntary_exit*(
|
proc process_voluntary_exit*(
|
||||||
state: var BeaconState,
|
state: var BeaconState,
|
||||||
signed_voluntary_exit: SignedVoluntaryExit,
|
signed_voluntary_exit: SignedVoluntaryExit,
|
||||||
|
|
|
@ -63,7 +63,7 @@ declareGauge epoch_transition_final_updates, "Epoch transition final updates tim
|
||||||
# Spec
|
# Spec
|
||||||
# --------------------------------------------------------
|
# --------------------------------------------------------
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#get_total_active_balance
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#get_total_active_balance
|
||||||
func get_total_active_balance*(state: BeaconState): Gwei =
|
func get_total_active_balance*(state: BeaconState): Gwei =
|
||||||
# Return the combined effective balance of the active validators.
|
# Return the combined effective balance of the active validators.
|
||||||
# TODO it calls get_total_balance with set(g_a_v_i(...))
|
# TODO it calls get_total_balance with set(g_a_v_i(...))
|
||||||
|
@ -101,7 +101,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.3/specs/core/0_beacon-chain.md#justification-and-finalization
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/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) {.nbench.}=
|
state: var BeaconState, stateCache: var StateCache) {.nbench.}=
|
||||||
|
|
||||||
|
@ -140,11 +140,11 @@ proc process_justification_and_finalization*(
|
||||||
## matter -- in the next epoch, they'll be 2 epochs old, when BeaconState
|
## matter -- in the next epoch, they'll be 2 epochs old, when BeaconState
|
||||||
## tracks current_epoch_attestations and previous_epoch_attestations only
|
## tracks current_epoch_attestations and previous_epoch_attestations only
|
||||||
## per
|
## per
|
||||||
## https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#attestations
|
## https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#attestations
|
||||||
## and `get_matching_source_attestations(...)` via
|
## and `get_matching_source_attestations(...)` via
|
||||||
## https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#helper-functions-1
|
## https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#helper-functions-1
|
||||||
## and
|
## and
|
||||||
## https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#final-updates
|
## https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#final-updates
|
||||||
## after which the state.previous_epoch_attestations is replaced.
|
## after which the state.previous_epoch_attestations is replaced.
|
||||||
trace "Non-attesting indices in previous epoch",
|
trace "Non-attesting indices in previous epoch",
|
||||||
missing_all_validators=
|
missing_all_validators=
|
||||||
|
@ -338,7 +338,7 @@ func get_attestation_deltas(state: BeaconState, stateCache: var StateCache):
|
||||||
|
|
||||||
(rewards, penalties)
|
(rewards, penalties)
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#rewards-and-penalties-1
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#rewards-and-penalties-1
|
||||||
func process_rewards_and_penalties(
|
func process_rewards_and_penalties(
|
||||||
state: var BeaconState, cache: var StateCache) {.nbench.}=
|
state: var BeaconState, cache: var StateCache) {.nbench.}=
|
||||||
if get_current_epoch(state) == GENESIS_EPOCH:
|
if get_current_epoch(state) == GENESIS_EPOCH:
|
||||||
|
@ -350,7 +350,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.3/specs/core/0_beacon-chain.md#slashings
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/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)
|
||||||
|
@ -367,7 +367,7 @@ func process_slashings*(state: var BeaconState) =
|
||||||
let penalty = penalty_numerator div total_balance * increment
|
let penalty = penalty_numerator div total_balance * increment
|
||||||
decrease_balance(state, index.ValidatorIndex, penalty)
|
decrease_balance(state, index.ValidatorIndex, penalty)
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#final-updates
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#final-updates
|
||||||
func process_final_updates*(state: var BeaconState) {.nbench.}=
|
func process_final_updates*(state: var BeaconState) {.nbench.}=
|
||||||
let
|
let
|
||||||
current_epoch = get_current_epoch(state)
|
current_epoch = get_current_epoch(state)
|
||||||
|
@ -407,7 +407,7 @@ func process_final_updates*(state: var BeaconState) {.nbench.}=
|
||||||
state.previous_epoch_attestations = state.current_epoch_attestations
|
state.previous_epoch_attestations = state.current_epoch_attestations
|
||||||
state.current_epoch_attestations = @[]
|
state.current_epoch_attestations = @[]
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#epoch-processing
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#epoch-processing
|
||||||
proc process_epoch*(state: var BeaconState) {.nbench.}=
|
proc process_epoch*(state: var BeaconState) {.nbench.}=
|
||||||
# @proc are placeholders
|
# @proc are placeholders
|
||||||
|
|
||||||
|
@ -416,7 +416,7 @@ proc process_epoch*(state: var BeaconState) {.nbench.}=
|
||||||
|
|
||||||
var per_epoch_cache = get_empty_per_epoch_cache()
|
var per_epoch_cache = get_empty_per_epoch_cache()
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#justification-and-finalization
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#justification-and-finalization
|
||||||
process_justification_and_finalization(state, per_epoch_cache)
|
process_justification_and_finalization(state, per_epoch_cache)
|
||||||
|
|
||||||
trace "ran process_justification_and_finalization",
|
trace "ran process_justification_and_finalization",
|
||||||
|
@ -425,7 +425,7 @@ proc process_epoch*(state: var BeaconState) {.nbench.}=
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/core/0_beacon-chain.md#rewards-and-penalties-1
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.2/specs/core/0_beacon-chain.md#rewards-and-penalties-1
|
||||||
process_rewards_and_penalties(state, per_epoch_cache)
|
process_rewards_and_penalties(state, per_epoch_cache)
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#registry-updates
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#registry-updates
|
||||||
# Don't rely on caching here.
|
# Don't rely on caching here.
|
||||||
process_registry_updates(state)
|
process_registry_updates(state)
|
||||||
|
|
||||||
|
@ -436,12 +436,12 @@ proc process_epoch*(state: var BeaconState) {.nbench.}=
|
||||||
# @process_reveal_deadlines
|
# @process_reveal_deadlines
|
||||||
# @process_challenge_deadlines
|
# @process_challenge_deadlines
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#slashings
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#slashings
|
||||||
process_slashings(state)
|
process_slashings(state)
|
||||||
|
|
||||||
# @update_period_committee
|
# @update_period_committee
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#final-updates
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#final-updates
|
||||||
process_final_updates(state)
|
process_final_updates(state)
|
||||||
|
|
||||||
# @after_process_final_updates
|
# @after_process_final_updates
|
||||||
|
|
|
@ -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.3/specs/core/0_beacon-chain.md#helper-functions-1
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/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] =
|
||||||
|
|
|
@ -11,8 +11,8 @@ import
|
||||||
./datatypes, ./digest, ./helpers
|
./datatypes, ./digest, ./helpers
|
||||||
|
|
||||||
# TODO: Proceed to renaming and signature changes
|
# TODO: Proceed to renaming and signature changes
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#compute_shuffled_index
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#compute_shuffled_index
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#compute_committee
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#compute_committee
|
||||||
func get_shuffled_seq*(seed: Eth2Digest,
|
func get_shuffled_seq*(seed: Eth2Digest,
|
||||||
list_size: uint64,
|
list_size: uint64,
|
||||||
): seq[ValidatorIndex] =
|
): seq[ValidatorIndex] =
|
||||||
|
@ -78,7 +78,7 @@ func get_shuffled_seq*(seed: Eth2Digest,
|
||||||
|
|
||||||
result = shuffled_active_validator_indices
|
result = shuffled_active_validator_indices
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#get_previous_epoch
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#get_previous_epoch
|
||||||
func get_previous_epoch*(state: BeaconState): Epoch =
|
func get_previous_epoch*(state: BeaconState): Epoch =
|
||||||
# Return the previous epoch (unless the current epoch is ``GENESIS_EPOCH``).
|
# Return the previous epoch (unless the current epoch is ``GENESIS_EPOCH``).
|
||||||
let current_epoch = get_current_epoch(state)
|
let current_epoch = get_current_epoch(state)
|
||||||
|
@ -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.3/specs/core/0_beacon-chain.md#compute_committee
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/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``,
|
||||||
|
|
|
@ -97,7 +97,7 @@ proc process_slots*(state: var BeaconState, slot: Slot) {.nbench.}=
|
||||||
if is_epoch_transition:
|
if is_epoch_transition:
|
||||||
beacon_current_validators.set(get_epoch_validator_count(state))
|
beacon_current_validators.set(get_epoch_validator_count(state))
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#beacon-chain-state-transition-function
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#beacon-chain-state-transition-function
|
||||||
proc verifyStateRoot(state: BeaconState, blck: BeaconBlock): bool =
|
proc verifyStateRoot(state: BeaconState, blck: BeaconBlock): bool =
|
||||||
# This is inlined in state_transition(...) in spec.
|
# This is inlined in state_transition(...) in spec.
|
||||||
let state_root = hash_tree_root(state)
|
let state_root = hash_tree_root(state)
|
||||||
|
|
|
@ -14,7 +14,7 @@ type
|
||||||
## which blocks are valid - in particular, blocks are not valid if they
|
## which blocks are valid - in particular, blocks are not valid if they
|
||||||
## come from the future as seen from the local clock.
|
## come from the future as seen from the local clock.
|
||||||
##
|
##
|
||||||
## https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_fork-choice.md#fork-choice
|
## https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_fork-choice.md#fork-choice
|
||||||
##
|
##
|
||||||
# TODO replace time in chronos with a proper unit type, then this code can
|
# TODO replace time in chronos with a proper unit type, then this code can
|
||||||
# follow:
|
# follow:
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
# process_attestation (beaconstate.nim)
|
# process_attestation (beaconstate.nim)
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#attestations
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#attestations
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
|
|
||||||
{.used.}
|
{.used.}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
|
|
||||||
# process_deposit (beaconstate.nim)
|
# process_deposit (beaconstate.nim)
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.3/specs/core/0_beacon-chain.md#deposits
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#deposits
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
|
|
||||||
{.used.}
|
{.used.}
|
||||||
|
|
|
@ -10,8 +10,8 @@
|
||||||
import
|
import
|
||||||
options, sequtils, unittest, chronicles,
|
options, sequtils, unittest, chronicles,
|
||||||
./testutil, ./testblockutil,
|
./testutil, ./testblockutil,
|
||||||
../beacon_chain/spec/[beaconstate, datatypes, digest],
|
../beacon_chain/spec/[datatypes, digest],
|
||||||
../beacon_chain/[beacon_node_types, block_pool, beacon_chain_db, extras, ssz]
|
../beacon_chain/[beacon_node_types, block_pool, beacon_chain_db, ssz]
|
||||||
|
|
||||||
when const_preset == "minimal": # Too much stack space used on mainnet
|
when const_preset == "minimal": # Too much stack space used on mainnet
|
||||||
suite "Block pool processing" & preset():
|
suite "Block pool processing" & preset():
|
||||||
|
|
Loading…
Reference in New Issue