2018-11-28 19:49:03 +00:00
|
|
|
# beacon_chain
|
2019-02-25 14:48:36 +00:00
|
|
|
# Copyright (c) 2018-2019 Status Research & Development GmbH
|
2018-11-28 19:49:03 +00:00
|
|
|
# Licensed and distributed under either of
|
|
|
|
# * 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).
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
|
|
|
import
|
2018-12-13 16:00:55 +00:00
|
|
|
chronicles, math, options, sequtils,
|
2018-12-11 17:55:45 +00:00
|
|
|
../extras, ../ssz,
|
2019-03-20 20:01:48 +00:00
|
|
|
./bitfield, ./crypto, ./datatypes, ./digest, ./helpers, ./validator
|
2018-11-28 19:49:03 +00:00
|
|
|
|
2019-03-16 19:52:37 +00:00
|
|
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.5.0/specs/core/0_beacon-chain.md#get_effective_balance
|
|
|
|
func get_effective_balance*(state: BeaconState, index: ValidatorIndex): Gwei =
|
2019-02-07 23:07:15 +00:00
|
|
|
## Return the effective balance (also known as "balance at stake") for a
|
|
|
|
## validator with the given ``index``.
|
2019-01-21 18:26:58 +00:00
|
|
|
min(state.validator_balances[index], MAX_DEPOSIT_AMOUNT)
|
2018-12-27 20:14:37 +00:00
|
|
|
|
2019-03-18 15:42:42 +00:00
|
|
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.5.0/specs/core/0_beacon-chain.md#verify_merkle_branch
|
|
|
|
func verify_merkle_branch(leaf: Eth2Digest, proof: openarray[Eth2Digest], depth: uint64, index: uint64, root: Eth2Digest): bool =
|
|
|
|
## Verify that the given ``leaf`` is on the merkle branch ``proof``
|
|
|
|
## starting with the given ``root``.
|
|
|
|
var
|
|
|
|
value = leaf
|
|
|
|
buf: array[64, byte]
|
|
|
|
|
|
|
|
for i in 0 ..< depth.int:
|
|
|
|
if (index div (1'u64 shl i)) mod 2 != 0:
|
|
|
|
buf[0..31] = proof[i.int].data
|
|
|
|
buf[32..63] = value.data
|
|
|
|
else:
|
|
|
|
buf[0..31] = value.data
|
|
|
|
buf[32..63] = proof[i.int].data
|
|
|
|
value = eth2hash(buf)
|
|
|
|
value == root
|
|
|
|
|
2019-03-24 18:21:23 +00:00
|
|
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.5.1/specs/core/0_beacon-chain.md#process_deposit
|
|
|
|
func process_deposit*(state: var BeaconState, deposit: Deposit): bool =
|
2018-12-13 16:00:55 +00:00
|
|
|
## Process a deposit from Ethereum 1.0.
|
2019-03-08 17:44:31 +00:00
|
|
|
## Note that this function mutates ``state``.
|
|
|
|
|
|
|
|
let deposit_input = deposit.deposit_data.deposit_input
|
2018-12-13 16:00:55 +00:00
|
|
|
|
2019-03-18 15:42:42 +00:00
|
|
|
## Should equal 8 bytes for deposit_data.amount +
|
|
|
|
## 8 bytes for deposit_data.timestamp +
|
|
|
|
## 176 bytes for deposit_data.deposit_input
|
|
|
|
## It should match the deposit_data in the eth1.0 deposit contract
|
|
|
|
## TODO actual serialize func useful after all
|
|
|
|
var serialized_deposit_data: array[8 + 8 + 176, byte]
|
|
|
|
serialized_deposit_data[0..7] = deposit.deposit_data.amount.int_to_bytes8()
|
|
|
|
serialized_deposit_data[8..15] =
|
|
|
|
deposit.deposit_data.timestamp.int_to_bytes8()
|
|
|
|
serialized_deposit_data[16..63] = deposit_input.pubkey.getBytes()
|
|
|
|
serialized_deposit_data[64..95] = deposit_input.withdrawal_credentials.data
|
|
|
|
serialized_deposit_data[96..191] =
|
|
|
|
deposit_input.proof_of_possession.getBytes()
|
|
|
|
|
|
|
|
# Verify the Merkle branch
|
|
|
|
let merkle_branch_is_valid = verify_merkle_branch(
|
|
|
|
eth2hash(serialized_deposit_data),
|
|
|
|
deposit.proof,
|
|
|
|
DEPOSIT_CONTRACT_TREE_DEPTH,
|
|
|
|
deposit.index,
|
|
|
|
state.latest_eth1_data.deposit_root)
|
|
|
|
## TODO enable this check, after using merkle_root (not in spec anymore, but
|
|
|
|
## useful to construct proofs) to build proofs (i.e. the other child in each
|
|
|
|
## pair of children at each level of the merkle tree), and injecting a proof
|
|
|
|
## sequence corresponding to their hash values, into the `Deposits`, in that
|
|
|
|
## tests/testutil.nim area of code. Currently it's checking against garbage,
|
|
|
|
## either when creating genesis states or in the block processing of deposit
|
|
|
|
## lists from Eth1Data.
|
|
|
|
# doAssert merkle_branch_is_valid
|
|
|
|
|
|
|
|
## Increment the next deposit index we are expecting. Note that this
|
|
|
|
## needs to be done here because while the deposit contract will never
|
|
|
|
## create an invalid Merkle branch, it may admit an invalid deposit
|
|
|
|
## object, and we need to be able to skip over it
|
|
|
|
state.deposit_index += 1
|
|
|
|
|
2019-03-08 17:44:31 +00:00
|
|
|
## if not validate_proof_of_possession(
|
|
|
|
## state, pubkey, proof_of_possession, withdrawal_credentials):
|
|
|
|
## return
|
|
|
|
## TODO re-enable (but it wasn't running to begin with, and
|
|
|
|
## PoP isn't really a phase 0 concern, so this isn't meaningful
|
|
|
|
## regardless.
|
2018-12-27 23:40:22 +00:00
|
|
|
|
2019-03-08 17:44:31 +00:00
|
|
|
let
|
|
|
|
validator_pubkeys = state.validator_registry.mapIt(it.pubkey)
|
|
|
|
pubkey = deposit_input.pubkey
|
|
|
|
amount = deposit.deposit_data.amount
|
|
|
|
withdrawal_credentials = deposit_input.withdrawal_credentials
|
2018-12-13 16:00:55 +00:00
|
|
|
|
|
|
|
if pubkey notin validator_pubkeys:
|
|
|
|
# Add new validator
|
2019-01-17 18:27:11 +00:00
|
|
|
let validator = Validator(
|
2018-12-13 16:00:55 +00:00
|
|
|
pubkey: pubkey,
|
|
|
|
withdrawal_credentials: withdrawal_credentials,
|
2019-01-29 03:22:22 +00:00
|
|
|
activation_epoch: FAR_FUTURE_EPOCH,
|
|
|
|
exit_epoch: FAR_FUTURE_EPOCH,
|
2019-02-19 23:07:56 +00:00
|
|
|
withdrawable_epoch: FAR_FUTURE_EPOCH,
|
2019-03-08 17:44:31 +00:00
|
|
|
initiated_exit: false,
|
|
|
|
slashed: false,
|
2018-12-13 16:00:55 +00:00
|
|
|
)
|
|
|
|
|
2019-02-20 20:35:27 +00:00
|
|
|
## Note: In phase 2 registry indices that have been withdrawn for a long
|
|
|
|
## time will be recycled.
|
2019-01-30 08:41:07 +00:00
|
|
|
state.validator_registry.add(validator)
|
|
|
|
state.validator_balances.add(amount)
|
2018-12-13 16:00:55 +00:00
|
|
|
else:
|
2019-01-16 12:20:44 +00:00
|
|
|
# Increase balance by deposit amount
|
2018-12-13 16:00:55 +00:00
|
|
|
let index = validator_pubkeys.find(pubkey)
|
|
|
|
let validator = addr state.validator_registry[index]
|
2019-03-08 17:44:31 +00:00
|
|
|
doAssert state.validator_registry[index].withdrawal_credentials ==
|
2018-12-27 20:14:37 +00:00
|
|
|
withdrawal_credentials
|
2018-12-13 16:00:55 +00:00
|
|
|
|
2019-01-30 08:41:07 +00:00
|
|
|
state.validator_balances[index] += amount
|
2018-12-13 16:00:55 +00:00
|
|
|
|
2019-03-24 18:21:23 +00:00
|
|
|
true
|
|
|
|
|
2019-03-16 19:52:37 +00:00
|
|
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.5.0/specs/core/0_beacon-chain.md#get_delayed_activation_exit_epoch
|
2019-03-11 15:33:24 +00:00
|
|
|
func get_delayed_activation_exit_epoch*(epoch: Epoch): Epoch =
|
2019-03-12 09:59:43 +00:00
|
|
|
## Return the epoch at which an activation or exit triggered in ``epoch``
|
|
|
|
## takes effect.
|
2019-02-19 23:07:56 +00:00
|
|
|
epoch + 1 + ACTIVATION_EXIT_DELAY
|
2019-01-29 03:22:22 +00:00
|
|
|
|
2019-03-16 19:52:37 +00:00
|
|
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.5.0/specs/core/0_beacon-chain.md#activate_validator
|
2018-12-13 16:00:55 +00:00
|
|
|
func activate_validator(state: var BeaconState,
|
2019-01-29 04:15:00 +00:00
|
|
|
index: ValidatorIndex,
|
2019-03-11 15:33:24 +00:00
|
|
|
is_genesis: bool) =
|
2018-12-13 16:00:55 +00:00
|
|
|
## Activate the validator with the given ``index``.
|
2019-02-14 03:16:51 +00:00
|
|
|
## Note that this function mutates ``state``.
|
2018-12-13 16:00:55 +00:00
|
|
|
let validator = addr state.validator_registry[index]
|
|
|
|
|
2019-02-20 20:35:27 +00:00
|
|
|
validator.activation_epoch =
|
2019-03-11 15:33:24 +00:00
|
|
|
if is_genesis:
|
2019-02-20 20:35:27 +00:00
|
|
|
GENESIS_EPOCH
|
|
|
|
else:
|
2019-03-11 15:33:24 +00:00
|
|
|
get_delayed_activation_exit_epoch(get_current_epoch(state))
|
2018-12-13 16:00:55 +00:00
|
|
|
|
2019-03-16 19:52:37 +00:00
|
|
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.5.0/specs/core/0_beacon-chain.md#initiate_validator_exit
|
2019-02-22 17:53:37 +00:00
|
|
|
func initiate_validator_exit*(state: var BeaconState,
|
|
|
|
index: ValidatorIndex) =
|
2018-12-13 16:00:55 +00:00
|
|
|
## Initiate exit for the validator with the given ``index``.
|
2019-02-14 03:16:51 +00:00
|
|
|
## Note that this function mutates ``state``.
|
2019-02-20 20:35:27 +00:00
|
|
|
var validator = addr state.validator_registry[index]
|
2019-03-08 17:44:31 +00:00
|
|
|
validator.initiated_exit = true
|
2018-12-13 16:00:55 +00:00
|
|
|
|
2019-03-18 15:42:42 +00:00
|
|
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.5.0/specs/core/0_beacon-chain.md#exit_validator
|
2019-01-16 12:20:44 +00:00
|
|
|
func exit_validator*(state: var BeaconState,
|
2019-01-29 04:15:00 +00:00
|
|
|
index: ValidatorIndex) =
|
2018-12-13 16:00:55 +00:00
|
|
|
## Exit the validator with the given ``index``.
|
2019-02-14 03:16:51 +00:00
|
|
|
## Note that this function mutates ``state``.
|
2018-12-13 16:00:55 +00:00
|
|
|
|
2019-03-18 15:42:42 +00:00
|
|
|
let
|
|
|
|
validator = addr state.validator_registry[index]
|
|
|
|
delayed_activation_exit_epoch =
|
|
|
|
get_delayed_activation_exit_epoch(get_current_epoch(state))
|
2018-12-13 16:00:55 +00:00
|
|
|
|
2019-01-17 21:01:55 +00:00
|
|
|
# The following updates only occur if not previous exited
|
2019-03-18 15:42:42 +00:00
|
|
|
if validator.exit_epoch <= delayed_activation_exit_epoch:
|
2018-12-13 16:00:55 +00:00
|
|
|
return
|
|
|
|
|
2019-03-18 15:42:42 +00:00
|
|
|
validator.exit_epoch = delayed_activation_exit_epoch
|
2018-12-13 16:00:55 +00:00
|
|
|
|
2019-03-01 23:50:01 +00:00
|
|
|
func reduce_balance*(balance: var uint64, amount: uint64) =
|
|
|
|
# Not in spec, but useful to avoid underflow.
|
|
|
|
balance -= min(amount, balance)
|
|
|
|
|
2019-03-16 19:52:37 +00:00
|
|
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.5.0/specs/core/0_beacon-chain.md#slash_validator
|
2019-02-20 20:35:27 +00:00
|
|
|
func slash_validator*(state: var BeaconState, index: ValidatorIndex) =
|
|
|
|
## Slash the validator with index ``index``.
|
2019-02-14 03:16:51 +00:00
|
|
|
## Note that this function mutates ``state``.
|
2019-02-20 20:35:27 +00:00
|
|
|
|
|
|
|
let validator = addr state.validator_registry[index]
|
2019-02-22 09:56:45 +00:00
|
|
|
doAssert state.slot < get_epoch_start_slot(validator.withdrawable_epoch) ##\
|
2019-02-20 20:35:27 +00:00
|
|
|
## [TO BE REMOVED IN PHASE 2]
|
|
|
|
|
|
|
|
exit_validator(state, index)
|
|
|
|
state.latest_slashed_balances[
|
|
|
|
(get_current_epoch(state) mod LATEST_SLASHED_EXIT_LENGTH).int
|
|
|
|
] += get_effective_balance(state, index)
|
|
|
|
|
2019-01-29 03:22:22 +00:00
|
|
|
let
|
2019-02-20 20:35:27 +00:00
|
|
|
whistleblower_index = get_beacon_proposer_index(state, state.slot)
|
|
|
|
whistleblower_reward = get_effective_balance(state, index) div
|
|
|
|
WHISTLEBLOWER_REWARD_QUOTIENT
|
2019-01-16 13:39:34 +00:00
|
|
|
|
2019-03-08 17:44:31 +00:00
|
|
|
## TODO here and elsewhere, if reduce_balance can't reduce balance by full
|
|
|
|
## whistleblower_reward (to prevent underflow) should increase be full? It
|
|
|
|
## seems wrong for the amounts to differ.
|
2019-02-20 20:35:27 +00:00
|
|
|
state.validator_balances[whistleblower_index] += whistleblower_reward
|
2019-03-01 23:50:01 +00:00
|
|
|
reduce_balance(state.validator_balances[index], whistleblower_reward)
|
2019-03-08 17:44:31 +00:00
|
|
|
validator.slashed = true
|
|
|
|
validator.withdrawable_epoch =
|
|
|
|
get_current_epoch(state) + LATEST_SLASHED_EXIT_LENGTH
|
2019-01-16 13:39:34 +00:00
|
|
|
|
2019-03-05 19:10:36 +00:00
|
|
|
func update_shuffling_cache*(state: var BeaconState) =
|
|
|
|
let
|
|
|
|
list_size = state.validator_registry.len.uint64
|
|
|
|
shuffling_seq = mapIt(
|
|
|
|
get_shuffled_seq(state.current_shuffling_seed, list_size),
|
|
|
|
# No intrinsic reason for this conversion; SSZ requirement artifact.
|
|
|
|
it.int)
|
|
|
|
|
|
|
|
doAssert state.shuffling_cache.index in [0, 1]
|
|
|
|
|
|
|
|
# Do a dance to keep everything JSON-encodable.
|
|
|
|
state.shuffling_cache.seeds[state.shuffling_cache.index] =
|
|
|
|
state.current_shuffling_seed
|
|
|
|
state.shuffling_cache.list_sizes[state.shuffling_cache.index] = list_size
|
|
|
|
if state.shuffling_cache.index == 0:
|
|
|
|
state.shuffling_cache.shuffling_0 = shuffling_seq
|
|
|
|
else:
|
|
|
|
state.shuffling_cache.shuffling_1 = shuffling_seq
|
|
|
|
state.shuffling_cache.index = 1 - state.shuffling_cache.index
|
|
|
|
|
2019-03-24 18:21:23 +00:00
|
|
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.5.1/specs/core/0_beacon-chain.md#get_temporary_block_header
|
2019-03-16 19:52:37 +00:00
|
|
|
func get_temporary_block_header*(blck: BeaconBlock): BeaconBlockHeader =
|
|
|
|
## Return the block header corresponding to a block with ``state_root`` set
|
|
|
|
## to ``ZERO_HASH``.
|
|
|
|
BeaconBlockHeader(
|
|
|
|
slot: blck.slot.uint64,
|
|
|
|
previous_block_root: blck.previous_block_root,
|
|
|
|
state_root: ZERO_HASH,
|
2019-03-25 16:46:31 +00:00
|
|
|
block_body_root: hash_tree_root(blck.body),
|
2019-03-24 18:21:23 +00:00
|
|
|
# signed_root(block) is used for block id purposes so signature is a stub
|
2019-03-21 16:02:50 +00:00
|
|
|
signature: EMPTY_SIGNATURE,
|
|
|
|
)
|
2019-03-16 19:52:37 +00:00
|
|
|
|
2019-03-24 18:21:23 +00:00
|
|
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.5.1/specs/core/0_beacon-chain.md#on-genesis
|
2019-03-16 19:52:37 +00:00
|
|
|
func get_empty_block*(): BeaconBlock =
|
2019-03-24 18:21:23 +00:00
|
|
|
# Nim default values fill this in mostly correctly.
|
2019-03-16 19:52:37 +00:00
|
|
|
result.slot = GENESIS_SLOT
|
|
|
|
|
2019-02-22 09:56:45 +00:00
|
|
|
func get_genesis_beacon_state*(
|
2019-03-08 17:44:31 +00:00
|
|
|
genesis_validator_deposits: openArray[Deposit],
|
2018-12-19 04:36:10 +00:00
|
|
|
genesis_time: uint64,
|
2019-03-24 18:21:23 +00:00
|
|
|
genesis_eth1_data: Eth1Data,
|
2018-12-27 23:40:22 +00:00
|
|
|
flags: UpdateFlags = {}): BeaconState =
|
2019-02-22 09:56:45 +00:00
|
|
|
## Get the genesis ``BeaconState``.
|
2018-11-29 05:23:40 +00:00
|
|
|
##
|
|
|
|
## Before the beacon chain starts, validators will register in the Eth1 chain
|
|
|
|
## and deposit ETH. When enough many validators have registered, a
|
|
|
|
## `ChainStart` log will be emitted and the beacon chain can start beaconing.
|
|
|
|
##
|
|
|
|
## Because the state root hash is part of the genesis block, the beacon state
|
|
|
|
## must be calculated before creating the genesis block.
|
2018-12-13 16:00:55 +00:00
|
|
|
|
2018-11-29 05:23:40 +00:00
|
|
|
# Induct validators
|
2019-02-20 01:33:58 +00:00
|
|
|
# Not in spec: the system doesn't work unless there are at least SLOTS_PER_EPOCH
|
2018-11-29 22:11:05 +00:00
|
|
|
# validators - there needs to be at least one member in each committee -
|
|
|
|
# good to know for testing, though arguably the system is not that useful at
|
|
|
|
# at that point :)
|
2019-03-08 17:44:31 +00:00
|
|
|
doAssert genesis_validator_deposits.len >= SLOTS_PER_EPOCH
|
2018-11-29 05:23:40 +00:00
|
|
|
|
2018-12-13 16:00:55 +00:00
|
|
|
var state = BeaconState(
|
|
|
|
# Misc
|
2019-01-16 10:21:06 +00:00
|
|
|
slot: GENESIS_SLOT,
|
2018-12-13 16:00:55 +00:00
|
|
|
genesis_time: genesis_time,
|
2019-01-29 03:22:22 +00:00
|
|
|
fork: Fork(
|
2019-01-29 04:15:00 +00:00
|
|
|
previous_version: GENESIS_FORK_VERSION,
|
|
|
|
current_version: GENESIS_FORK_VERSION,
|
2019-01-30 08:41:07 +00:00
|
|
|
epoch: GENESIS_EPOCH,
|
2018-12-13 16:00:55 +00:00
|
|
|
),
|
2018-12-03 21:41:24 +00:00
|
|
|
|
2019-01-29 03:22:22 +00:00
|
|
|
validator_registry_update_epoch: GENESIS_EPOCH,
|
2019-02-14 03:16:51 +00:00
|
|
|
|
2019-02-22 09:56:45 +00:00
|
|
|
# validator_registry and validator_balances automatically initalized
|
2018-12-03 21:41:24 +00:00
|
|
|
|
2019-01-16 11:39:16 +00:00
|
|
|
# Randomness and committees
|
2019-02-22 09:56:45 +00:00
|
|
|
# latest_randao_mixes automatically initialized
|
2019-02-19 23:07:56 +00:00
|
|
|
previous_shuffling_start_shard: GENESIS_START_SHARD,
|
|
|
|
current_shuffling_start_shard: GENESIS_START_SHARD,
|
|
|
|
previous_shuffling_epoch: GENESIS_EPOCH,
|
|
|
|
current_shuffling_epoch: GENESIS_EPOCH,
|
|
|
|
previous_shuffling_seed: ZERO_HASH,
|
|
|
|
current_shuffling_seed: ZERO_HASH,
|
2019-01-16 11:39:16 +00:00
|
|
|
|
2018-12-03 21:41:24 +00:00
|
|
|
# Finality
|
2019-03-24 18:21:23 +00:00
|
|
|
# previous_epoch_attestations and current_epoch_attestations automatically
|
|
|
|
# initialized
|
2019-01-29 03:22:22 +00:00
|
|
|
previous_justified_epoch: GENESIS_EPOCH,
|
2019-03-16 19:52:37 +00:00
|
|
|
current_justified_epoch: GENESIS_EPOCH,
|
2019-01-16 11:39:16 +00:00
|
|
|
justification_bitfield: 0,
|
2019-01-29 03:22:22 +00:00
|
|
|
finalized_epoch: GENESIS_EPOCH,
|
2019-03-24 18:21:23 +00:00
|
|
|
finalized_root: ZERO_HASH,
|
2019-02-22 09:56:45 +00:00
|
|
|
|
|
|
|
# Recent state
|
2019-03-24 18:21:23 +00:00
|
|
|
# latest_block_roots, latest_state_roots, latest_active_index_roots,
|
|
|
|
# latest_slashed_balances, and latest_slashed_balances automatically
|
|
|
|
# initialized
|
2019-03-16 19:52:37 +00:00
|
|
|
latest_block_header: get_temporary_block_header(get_empty_block()),
|
2019-03-24 18:21:23 +00:00
|
|
|
|
|
|
|
# Ethereum 1.0 chain data
|
|
|
|
# eth1_data_votes automatically initialized
|
|
|
|
latest_eth1_data: genesis_eth1_data,
|
|
|
|
deposit_index: 0,
|
2018-11-29 05:23:40 +00:00
|
|
|
)
|
|
|
|
|
2019-02-27 13:58:07 +00:00
|
|
|
for i in 0 ..< SHARD_COUNT:
|
|
|
|
state.latest_crosslinks[i] = Crosslink(
|
2019-03-13 21:23:01 +00:00
|
|
|
epoch: GENESIS_EPOCH, crosslink_data_root: ZERO_HASH)
|
2019-03-08 17:44:31 +00:00
|
|
|
|
|
|
|
# Process genesis deposits
|
|
|
|
for deposit in genesis_validator_deposits:
|
2019-03-24 18:21:23 +00:00
|
|
|
discard process_deposit(state, deposit)
|
2019-01-16 12:20:44 +00:00
|
|
|
|
2019-03-08 17:44:31 +00:00
|
|
|
# Process genesis activations
|
2019-01-21 18:26:58 +00:00
|
|
|
for validator_index in 0 ..< state.validator_registry.len:
|
2019-01-29 04:15:00 +00:00
|
|
|
let vi = validator_index.ValidatorIndex
|
2019-01-30 08:41:07 +00:00
|
|
|
if get_effective_balance(state, vi) >= MAX_DEPOSIT_AMOUNT:
|
2019-01-21 18:26:58 +00:00
|
|
|
activate_validator(state, vi, true)
|
2018-12-13 16:00:55 +00:00
|
|
|
|
2019-03-25 16:46:31 +00:00
|
|
|
let genesis_active_index_root = hash_tree_root(
|
|
|
|
get_active_validator_indices(state.validator_registry, GENESIS_EPOCH))
|
2019-02-22 09:56:45 +00:00
|
|
|
for index in 0 ..< LATEST_ACTIVE_INDEX_ROOTS_LENGTH:
|
|
|
|
state.latest_active_index_roots[index] = genesis_active_index_root
|
|
|
|
state.current_shuffling_seed = generate_seed(state, GENESIS_EPOCH)
|
|
|
|
|
2019-03-08 17:44:31 +00:00
|
|
|
# Not in spec.
|
2019-03-05 19:10:36 +00:00
|
|
|
update_shuffling_cache(state)
|
|
|
|
|
2018-12-13 16:00:55 +00:00
|
|
|
state
|
|
|
|
|
2019-02-21 04:42:17 +00:00
|
|
|
# TODO candidate for spec?
|
2019-03-12 09:59:43 +00:00
|
|
|
# https://github.com/ethereum/eth2.0-specs/blob/0.4.0/specs/core/0_beacon-chain.md#on-genesis
|
2019-02-21 04:42:17 +00:00
|
|
|
func get_initial_beacon_block*(state: BeaconState): BeaconBlock =
|
|
|
|
BeaconBlock(
|
|
|
|
slot: GENESIS_SLOT,
|
2019-03-25 16:46:31 +00:00
|
|
|
state_root: hash_tree_root(state)
|
2019-03-12 09:59:43 +00:00
|
|
|
# parent_root, randao_reveal, eth1_data, signature, and body automatically
|
|
|
|
# initialized to default values.
|
2019-02-21 04:42:17 +00:00
|
|
|
)
|
|
|
|
|
2019-03-16 19:52:37 +00:00
|
|
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.5.0/specs/core/0_beacon-chain.md#get_block_root
|
2018-12-11 21:53:18 +00:00
|
|
|
func get_block_root*(state: BeaconState,
|
2019-02-20 01:33:58 +00:00
|
|
|
slot: Slot): Eth2Digest =
|
2019-02-13 10:26:32 +00:00
|
|
|
# Return the block root at a recent ``slot``.
|
|
|
|
|
2019-03-16 19:52:37 +00:00
|
|
|
doAssert state.slot <= slot + SLOTS_PER_HISTORICAL_ROOT
|
2018-12-14 16:12:39 +00:00
|
|
|
doAssert slot < state.slot
|
2019-03-16 19:52:37 +00:00
|
|
|
state.latest_block_roots[slot mod SLOTS_PER_HISTORICAL_ROOT]
|
2018-11-29 05:23:40 +00:00
|
|
|
|
2019-03-22 18:33:12 +00:00
|
|
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.5.1/specs/core/0_beacon-chain.md#get_attestation_participants
|
2018-12-04 18:45:30 +00:00
|
|
|
func get_attestation_participants*(state: BeaconState,
|
2018-12-03 21:41:24 +00:00
|
|
|
attestation_data: AttestationData,
|
2019-03-20 20:01:48 +00:00
|
|
|
bitfield: BitField): seq[ValidatorIndex] =
|
2019-02-13 10:26:32 +00:00
|
|
|
## Return the participant indices at for the ``attestation_data`` and
|
|
|
|
## ``bitfield``.
|
2018-11-29 18:18:12 +00:00
|
|
|
## Attestation participants in the attestation data are called out in a
|
2019-02-13 10:26:32 +00:00
|
|
|
## bit field that corresponds to the committee of the shard at the time;
|
|
|
|
## this function converts it to list of indices in to BeaconState.validators
|
|
|
|
##
|
2018-11-29 18:18:12 +00:00
|
|
|
## Returns empty list if the shard is not found
|
2019-02-07 23:07:15 +00:00
|
|
|
## Return the participant indices at for the ``attestation_data`` and ``bitfield``.
|
2019-02-13 10:26:32 +00:00
|
|
|
##
|
2018-11-29 22:11:05 +00:00
|
|
|
# TODO Linear search through shard list? borderline ok, it's a small list
|
|
|
|
# TODO iterator candidate
|
2019-01-26 19:32:10 +00:00
|
|
|
|
2019-03-22 18:33:12 +00:00
|
|
|
# Find the committee in the list with the desired shard
|
2019-02-20 20:35:27 +00:00
|
|
|
let crosslink_committees = get_crosslink_committees_at_slot(
|
2019-03-14 13:33:56 +00:00
|
|
|
state, attestation_data.slot)
|
2019-03-22 18:33:12 +00:00
|
|
|
|
2019-03-09 04:23:14 +00:00
|
|
|
doAssert anyIt(
|
2019-01-26 19:32:10 +00:00
|
|
|
crosslink_committees,
|
2019-02-06 19:37:25 +00:00
|
|
|
it[1] == attestation_data.shard)
|
2019-01-26 19:32:10 +00:00
|
|
|
let crosslink_committee = mapIt(
|
2019-02-06 19:37:25 +00:00
|
|
|
filterIt(crosslink_committees, it.shard == attestation_data.shard),
|
|
|
|
it.committee)[0]
|
2019-02-07 23:07:15 +00:00
|
|
|
|
2019-03-09 04:23:14 +00:00
|
|
|
# TODO this and other attestation-based fields need validation so we don't
|
|
|
|
# crash on a malicious attestation!
|
2019-03-06 14:21:13 +00:00
|
|
|
doAssert verify_bitfield(bitfield, len(crosslink_committee))
|
2019-01-26 19:32:10 +00:00
|
|
|
|
|
|
|
# Find the participating attesters in the committee
|
|
|
|
result = @[]
|
|
|
|
for i, validator_index in crosslink_committee:
|
2019-02-07 23:07:15 +00:00
|
|
|
let aggregation_bit = get_bitfield_bit(bitfield, i)
|
2019-03-20 20:01:48 +00:00
|
|
|
if aggregation_bit:
|
2019-01-26 19:32:10 +00:00
|
|
|
result.add(validator_index)
|
2018-12-04 18:45:30 +00:00
|
|
|
|
2019-03-20 02:19:46 +00:00
|
|
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.5.0/specs/core/0_beacon-chain.md#ejections
|
2019-03-08 17:44:31 +00:00
|
|
|
func process_ejections*(state: var BeaconState) =
|
2019-03-07 16:53:44 +00:00
|
|
|
## Iterate through the validator registry and eject active validators with
|
|
|
|
## balance below ``EJECTION_BALANCE``
|
2019-03-08 17:44:31 +00:00
|
|
|
for index in get_active_validator_indices(
|
|
|
|
state.validator_registry, get_current_epoch(state)):
|
2018-12-27 20:14:37 +00:00
|
|
|
if state.validator_balances[index] < EJECTION_BALANCE:
|
2019-01-17 21:01:55 +00:00
|
|
|
exit_validator(state, index)
|
2018-12-11 17:55:45 +00:00
|
|
|
|
2019-03-16 19:52:37 +00:00
|
|
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.5.0/specs/core/0_beacon-chain.md#get_total_balance
|
2019-03-06 14:21:13 +00:00
|
|
|
func get_total_balance*(state: BeaconState, validators: auto): Gwei =
|
2019-02-22 18:46:45 +00:00
|
|
|
# Return the combined effective balance of an array of validators.
|
|
|
|
foldl(validators, a + get_effective_balance(state, b), 0'u64)
|
|
|
|
|
2019-03-16 19:52:37 +00:00
|
|
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.5.0/specs/core/0_beacon-chain.md#validator-registry-and-shuffling-seed-data
|
|
|
|
func should_update_validator_registry*(state: BeaconState): bool =
|
|
|
|
# Must have finalized a new block
|
|
|
|
if state.finalized_epoch <= state.validator_registry_update_epoch:
|
|
|
|
return false
|
|
|
|
# Must have processed new crosslinks on all shards of the current epoch
|
|
|
|
allIt(0 ..< get_current_epoch_committee_count(state).int,
|
|
|
|
not (state.latest_crosslinks[
|
|
|
|
((state.current_shuffling_start_shard + it.uint64) mod
|
|
|
|
SHARD_COUNT).int].epoch <= state.validator_registry_update_epoch))
|
|
|
|
|
2018-12-11 17:55:45 +00:00
|
|
|
func update_validator_registry*(state: var BeaconState) =
|
2019-02-28 21:24:43 +00:00
|
|
|
## Update validator registry.
|
|
|
|
## Note that this function mutates ``state``.
|
2018-12-27 20:14:37 +00:00
|
|
|
let
|
2019-01-29 03:22:22 +00:00
|
|
|
current_epoch = get_current_epoch(state)
|
2019-02-28 21:24:43 +00:00
|
|
|
# The active validators
|
2018-12-27 20:14:37 +00:00
|
|
|
active_validator_indices =
|
2019-02-28 21:24:43 +00:00
|
|
|
get_active_validator_indices(state.validator_registry, current_epoch)
|
2018-12-27 20:14:37 +00:00
|
|
|
# The total effective balance of active validators
|
2019-02-22 18:46:45 +00:00
|
|
|
total_balance = get_total_balance(state, active_validator_indices)
|
2018-12-27 20:14:37 +00:00
|
|
|
|
|
|
|
# The maximum balance churn in Gwei (for deposits and exits separately)
|
|
|
|
max_balance_churn = max(
|
2019-01-21 18:26:58 +00:00
|
|
|
MAX_DEPOSIT_AMOUNT,
|
2018-12-27 20:14:37 +00:00
|
|
|
total_balance div (2 * MAX_BALANCE_CHURN_QUOTIENT)
|
|
|
|
)
|
|
|
|
|
|
|
|
# Activate validators within the allowable balance churn
|
|
|
|
var balance_churn = 0'u64
|
|
|
|
for index, validator in state.validator_registry:
|
2019-03-08 17:44:31 +00:00
|
|
|
if validator.activation_epoch == FAR_FUTURE_EPOCH and
|
2019-01-21 18:26:58 +00:00
|
|
|
state.validator_balances[index] >= MAX_DEPOSIT_AMOUNT:
|
2018-12-27 20:14:37 +00:00
|
|
|
# Check the balance churn would be within the allowance
|
2019-01-29 04:15:00 +00:00
|
|
|
balance_churn += get_effective_balance(state, index.ValidatorIndex)
|
2018-12-27 20:14:37 +00:00
|
|
|
if balance_churn > max_balance_churn:
|
|
|
|
break
|
|
|
|
|
|
|
|
# Activate validator
|
2019-01-29 04:15:00 +00:00
|
|
|
activate_validator(state, index.ValidatorIndex, false)
|
2018-12-27 20:14:37 +00:00
|
|
|
|
|
|
|
# Exit validators within the allowable balance churn
|
|
|
|
balance_churn = 0
|
|
|
|
for index, validator in state.validator_registry:
|
2019-03-08 17:44:31 +00:00
|
|
|
if validator.activation_epoch == FAR_FUTURE_EPOCH and
|
|
|
|
validator.initiated_exit:
|
2018-12-27 20:14:37 +00:00
|
|
|
# Check the balance churn would be within the allowance
|
2019-01-29 04:15:00 +00:00
|
|
|
balance_churn += get_effective_balance(state, index.ValidatorIndex)
|
2018-12-27 20:14:37 +00:00
|
|
|
if balance_churn > max_balance_churn:
|
|
|
|
break
|
|
|
|
|
|
|
|
# Exit validator
|
2019-01-29 04:15:00 +00:00
|
|
|
exit_validator(state, index.ValidatorIndex)
|
2018-12-27 20:14:37 +00:00
|
|
|
|
2019-01-29 03:22:22 +00:00
|
|
|
state.validator_registry_update_epoch = current_epoch
|
|
|
|
|
2019-03-22 18:33:12 +00:00
|
|
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.5.1/specs/core/0_beacon-chain.md#attestations
|
2018-12-27 23:40:22 +00:00
|
|
|
proc checkAttestation*(
|
2019-03-21 15:31:36 +00:00
|
|
|
state: var BeaconState, attestation: Attestation, flags: UpdateFlags): bool =
|
2018-12-11 17:55:45 +00:00
|
|
|
## Check that an attestation follows the rules of being included in the state
|
2018-12-27 20:14:37 +00:00
|
|
|
## at the current slot. When acting as a proposer, the same rules need to
|
|
|
|
## be followed!
|
2018-12-11 17:55:45 +00:00
|
|
|
|
2019-03-21 15:31:36 +00:00
|
|
|
# Can't submit attestations that are too far in history (or in prehistory)
|
2019-03-08 17:44:31 +00:00
|
|
|
if not (attestation.data.slot >= GENESIS_SLOT):
|
|
|
|
warn("Attestation predates genesis slot",
|
|
|
|
attestation_slot = attestation.data.slot,
|
|
|
|
state_slot = humaneSlotNum(state.slot))
|
|
|
|
return
|
2019-02-25 14:53:01 +00:00
|
|
|
|
2019-03-21 15:31:36 +00:00
|
|
|
if not (state.slot <= attestation.data.slot + SLOTS_PER_EPOCH):
|
|
|
|
warn("Attestation too old",
|
2019-02-28 21:21:29 +00:00
|
|
|
attestation_slot = humaneSlotNum(attestation.data.slot),
|
|
|
|
state_slot = humaneSlotNum(state.slot))
|
2018-12-11 17:55:45 +00:00
|
|
|
return
|
|
|
|
|
2019-03-21 15:31:36 +00:00
|
|
|
# Can't submit attestations too quickly
|
|
|
|
if not (
|
|
|
|
attestation.data.slot + MIN_ATTESTATION_INCLUSION_DELAY <= state.slot):
|
|
|
|
warn("Can't submit attestations too quickly",
|
2019-02-28 21:21:29 +00:00
|
|
|
attestation_slot = humaneSlotNum(attestation.data.slot),
|
|
|
|
state_slot = humaneSlotNum(state.slot))
|
2018-12-11 17:55:45 +00:00
|
|
|
return
|
|
|
|
|
2019-03-21 15:31:36 +00:00
|
|
|
# # Verify that the justified epoch and root is correct
|
|
|
|
if slot_to_epoch(attestation.data.slot) >= get_current_epoch(state):
|
|
|
|
# Case 1: current epoch attestations
|
|
|
|
if not (attestation.data.source_epoch == state.current_justified_epoch):
|
|
|
|
warn("Source epoch is not current justified epoch",
|
|
|
|
attestation_slot = humaneSlotNum(attestation.data.slot),
|
|
|
|
state_slot = humaneSlotNum(state.slot))
|
|
|
|
return
|
|
|
|
|
|
|
|
if not (attestation.data.source_root == state.current_justified_root):
|
|
|
|
warn("Source root is not current justified root",
|
|
|
|
attestation_slot = humaneSlotNum(attestation.data.slot),
|
|
|
|
state_slot = humaneSlotNum(state.slot))
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
# Case 2: previous epoch attestations
|
|
|
|
if not (attestation.data.source_epoch == state.previous_justified_epoch):
|
|
|
|
warn("Source epoch is not previous justified epoch",
|
|
|
|
attestation_slot = humaneSlotNum(attestation.data.slot),
|
|
|
|
state_slot = humaneSlotNum(state.slot))
|
|
|
|
return
|
|
|
|
|
|
|
|
if not (attestation.data.source_root == state.previous_justified_root):
|
|
|
|
warn("Source root is not previous justified root",
|
|
|
|
attestation_slot = humaneSlotNum(attestation.data.slot),
|
|
|
|
state_slot = humaneSlotNum(state.slot))
|
|
|
|
return
|
2018-12-11 17:55:45 +00:00
|
|
|
|
2019-03-22 18:33:12 +00:00
|
|
|
# Check that the crosslink data is valid
|
|
|
|
let acceptable_crosslink_data = @[
|
|
|
|
# Case 1: Latest crosslink matches the one in the state
|
|
|
|
attestation.data.previous_crosslink,
|
|
|
|
|
|
|
|
# Case 2: State has already been updated, state's latest crosslink matches
|
|
|
|
# the crosslink the attestation is trying to create
|
|
|
|
Crosslink(
|
|
|
|
crosslink_data_root: attestation.data.crosslink_data_root,
|
|
|
|
epoch: slot_to_epoch(attestation.data.slot)
|
|
|
|
)
|
|
|
|
]
|
|
|
|
if not (state.latest_crosslinks[attestation.data.shard] in
|
|
|
|
acceptable_crosslink_data):
|
2019-02-27 13:58:07 +00:00
|
|
|
warn("Unexpected crosslink shard",
|
|
|
|
state_latest_crosslinks_attestation_data_shard =
|
|
|
|
state.latest_crosslinks[attestation.data.shard],
|
2019-03-18 15:42:42 +00:00
|
|
|
attestation_data_previous_crosslink = attestation.data.previous_crosslink,
|
2019-03-21 15:31:36 +00:00
|
|
|
epoch = humaneEpochNum(slot_to_epoch(attestation.data.slot)),
|
2019-03-22 18:33:12 +00:00
|
|
|
actual_epoch = slot_to_epoch(attestation.data.slot),
|
|
|
|
crosslink_data_root = attestation.data.crosslink_data_root,
|
|
|
|
acceptable_crosslink_data = acceptable_crosslink_data)
|
2018-12-11 17:55:45 +00:00
|
|
|
return
|
|
|
|
|
2019-03-22 18:33:12 +00:00
|
|
|
# Attestation must be nonempty!
|
2019-03-20 20:01:48 +00:00
|
|
|
doAssert anyIt(attestation.aggregation_bitfield.bits, it != 0)
|
2019-02-11 14:32:27 +00:00
|
|
|
|
2019-03-22 18:33:12 +00:00
|
|
|
# Custody must be empty (to be removed in phase 1)
|
|
|
|
doAssert allIt(attestation.custody_bitfield.bits, it == 0)
|
|
|
|
|
|
|
|
# Get the committee for the specific shard that this attestation is for
|
2019-02-11 14:32:27 +00:00
|
|
|
let crosslink_committee = mapIt(
|
2019-03-21 15:31:36 +00:00
|
|
|
filterIt(get_crosslink_committees_at_slot(state, attestation.data.slot),
|
2019-02-11 14:32:27 +00:00
|
|
|
it.shard == attestation.data.shard),
|
|
|
|
it.committee)[0]
|
|
|
|
|
2019-03-22 18:33:12 +00:00
|
|
|
# Custody bitfield must be a subset of the attestation bitfield
|
2019-03-13 23:04:43 +00:00
|
|
|
doAssert allIt(0 ..< len(crosslink_committee),
|
2019-03-20 20:01:48 +00:00
|
|
|
if not get_bitfield_bit(attestation.aggregation_bitfield, it):
|
|
|
|
not get_bitfield_bit(attestation.custody_bitfield, it)
|
2019-02-11 15:32:22 +00:00
|
|
|
else:
|
|
|
|
true)
|
2019-02-11 14:32:27 +00:00
|
|
|
|
2019-03-22 18:33:12 +00:00
|
|
|
# Verify aggregate signature
|
2018-12-11 17:55:45 +00:00
|
|
|
let
|
|
|
|
participants = get_attestation_participants(
|
2019-02-06 20:37:21 +00:00
|
|
|
state, attestation.data, attestation.aggregation_bitfield)
|
2019-02-11 14:32:27 +00:00
|
|
|
|
|
|
|
## TODO when the custody_bitfield assertion-to-emptiness disappears do this
|
|
|
|
## and fix the custody_bit_0_participants check to depend on it.
|
|
|
|
# custody_bit_1_participants = {nothing, always, because assertion above}
|
|
|
|
custody_bit_1_participants: seq[ValidatorIndex] = @[]
|
|
|
|
custody_bit_0_participants = participants
|
|
|
|
|
2018-12-27 23:40:22 +00:00
|
|
|
if skipValidation notin flags:
|
|
|
|
# Verify that aggregate_signature verifies using the group pubkey.
|
2019-03-13 23:04:43 +00:00
|
|
|
doAssert bls_verify_multiple(
|
2019-02-11 14:32:27 +00:00
|
|
|
@[
|
|
|
|
bls_aggregate_pubkeys(mapIt(custody_bit_0_participants,
|
|
|
|
state.validator_registry[it].pubkey)),
|
|
|
|
bls_aggregate_pubkeys(mapIt(custody_bit_1_participants,
|
|
|
|
state.validator_registry[it].pubkey)),
|
|
|
|
],
|
|
|
|
@[
|
|
|
|
hash_tree_root(AttestationDataAndCustodyBit(
|
|
|
|
data: attestation.data, custody_bit: false)),
|
|
|
|
hash_tree_root(AttestationDataAndCustodyBit(
|
|
|
|
data: attestation.data, custody_bit: true)),
|
|
|
|
],
|
|
|
|
attestation.aggregate_signature,
|
2019-03-14 13:33:56 +00:00
|
|
|
get_domain(state.fork, slot_to_epoch(attestation.data.slot),
|
2019-02-11 14:32:27 +00:00
|
|
|
DOMAIN_ATTESTATION),
|
|
|
|
)
|
2018-12-11 17:55:45 +00:00
|
|
|
|
2019-03-22 18:33:12 +00:00
|
|
|
# Crosslink data root is zero (to be removed in phase 1)
|
2019-03-08 17:44:31 +00:00
|
|
|
if attestation.data.crosslink_data_root != ZERO_HASH:
|
|
|
|
warn("Invalid crosslink data root")
|
2018-12-11 17:55:45 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
true
|
2019-02-13 10:26:32 +00:00
|
|
|
|
2019-03-16 19:52:37 +00:00
|
|
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.5.0/specs/core/0_beacon-chain.md#prepare_validator_for_withdrawal
|
2019-02-26 09:54:08 +00:00
|
|
|
func prepare_validator_for_withdrawal*(state: var BeaconState, index: ValidatorIndex) =
|
2019-02-20 20:35:27 +00:00
|
|
|
## Set the validator with the given ``index`` as withdrawable
|
|
|
|
## ``MIN_VALIDATOR_WITHDRAWABILITY_DELAY`` after the current epoch.
|
2019-02-14 03:16:51 +00:00
|
|
|
## Note that this function mutates ``state``.
|
|
|
|
var validator = addr state.validator_registry[index]
|
2019-02-20 20:35:27 +00:00
|
|
|
validator.withdrawable_epoch = get_current_epoch(state) +
|
2019-03-08 17:44:31 +00:00
|
|
|
MIN_VALIDATOR_WITHDRAWABILITY_DELAY
|
2019-03-09 04:23:14 +00:00
|
|
|
|
|
|
|
proc makeAttestationData*(
|
|
|
|
state: BeaconState, shard: uint64,
|
|
|
|
beacon_block_root: Eth2Digest): AttestationData =
|
|
|
|
## Fine points:
|
|
|
|
## Head must be the head state during the slot that validator is
|
|
|
|
## part of committee - notably, it can't be a newer or older state (!)
|
|
|
|
|
|
|
|
# TODO update when https://github.com/ethereum/eth2.0-specs/issues/742
|
|
|
|
let
|
|
|
|
epoch_start_slot = get_epoch_start_slot(slot_to_epoch(state.slot))
|
|
|
|
epoch_boundary_root =
|
|
|
|
if epoch_start_slot == state.slot: beacon_block_root
|
|
|
|
else: get_block_root(state, epoch_start_slot)
|
2019-03-16 19:52:37 +00:00
|
|
|
justified_slot = get_epoch_start_slot(state.current_justified_epoch)
|
2019-03-09 04:23:14 +00:00
|
|
|
justified_block_root = get_block_root(state, justified_slot)
|
|
|
|
|
|
|
|
AttestationData(
|
2019-03-13 21:23:01 +00:00
|
|
|
slot: state.slot,
|
2019-03-09 04:23:14 +00:00
|
|
|
shard: shard,
|
|
|
|
beacon_block_root: beacon_block_root,
|
|
|
|
crosslink_data_root: Eth2Digest(), # Stub in phase0
|
2019-03-18 15:42:42 +00:00
|
|
|
previous_crosslink: state.latest_crosslinks[shard],
|
|
|
|
source_epoch: state.current_justified_epoch,
|
2019-03-09 04:23:14 +00:00
|
|
|
)
|