|
|
|
@ -1,191 +0,0 @@
|
|
|
|
|
{.push raises: [].}
|
|
|
|
|
|
|
|
|
|
# Types specific to phase0 (i.e. known to have changed across hard forks) - see
|
|
|
|
|
# `base` for types and guidelines common across forks
|
|
|
|
|
|
|
|
|
|
# TODO Careful, not nil analysis is broken / incomplete and the semantics will
|
|
|
|
|
# likely change in future versions of the language:
|
|
|
|
|
# https://github.com/nim-lang/RFCs/issues/250
|
|
|
|
|
{.experimental: "notnil".}
|
|
|
|
|
|
|
|
|
|
import
|
|
|
|
|
./base
|
|
|
|
|
|
|
|
|
|
export base
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.6/specs/phase0/beacon-chain.md#beaconstate
|
|
|
|
|
BeaconState* = object
|
|
|
|
|
# Versioning
|
|
|
|
|
genesis_time*: uint64
|
|
|
|
|
genesis_validators_root*: Eth2Digest
|
|
|
|
|
slot*: Slot
|
|
|
|
|
fork*: Fork
|
|
|
|
|
|
|
|
|
|
# History
|
|
|
|
|
latest_block_header*: BeaconBlockHeader
|
|
|
|
|
## `latest_block_header.state_root == ZERO_HASH` temporarily
|
|
|
|
|
|
|
|
|
|
block_roots*: HashArray[Limit SLOTS_PER_HISTORICAL_ROOT, Eth2Digest]
|
|
|
|
|
## Needed to process attestations, older to newer
|
|
|
|
|
|
|
|
|
|
state_roots*: HashArray[Limit SLOTS_PER_HISTORICAL_ROOT, Eth2Digest]
|
|
|
|
|
historical_roots*: HashList[Eth2Digest, Limit HISTORICAL_ROOTS_LIMIT]
|
|
|
|
|
|
|
|
|
|
# Eth1
|
|
|
|
|
eth1_data*: Eth1Data
|
|
|
|
|
eth1_data_votes*:
|
|
|
|
|
HashList[Eth1Data, Limit(EPOCHS_PER_ETH1_VOTING_PERIOD * SLOTS_PER_EPOCH)]
|
|
|
|
|
eth1_deposit_index*: uint64
|
|
|
|
|
|
|
|
|
|
# Registry
|
|
|
|
|
validators*: HashList[Validator, Limit VALIDATOR_REGISTRY_LIMIT]
|
|
|
|
|
balances*: HashList[Gwei, Limit VALIDATOR_REGISTRY_LIMIT]
|
|
|
|
|
|
|
|
|
|
# Randomness
|
|
|
|
|
randao_mixes*: HashArray[Limit EPOCHS_PER_HISTORICAL_VECTOR, Eth2Digest]
|
|
|
|
|
|
|
|
|
|
# Slashings
|
|
|
|
|
slashings*: HashArray[Limit EPOCHS_PER_SLASHINGS_VECTOR, Gwei]
|
|
|
|
|
## Per-epoch sums of slashed effective balances
|
|
|
|
|
|
|
|
|
|
# Attestations
|
|
|
|
|
previous_epoch_attestations*:
|
|
|
|
|
HashList[PendingAttestation, Limit(MAX_ATTESTATIONS * SLOTS_PER_EPOCH)]
|
|
|
|
|
current_epoch_attestations*:
|
|
|
|
|
HashList[PendingAttestation, Limit(MAX_ATTESTATIONS * SLOTS_PER_EPOCH)]
|
|
|
|
|
|
|
|
|
|
# Finality
|
|
|
|
|
justification_bits*: JustificationBits
|
|
|
|
|
## Bit set for every recent justified epoch
|
|
|
|
|
|
|
|
|
|
previous_justified_checkpoint*: Checkpoint
|
|
|
|
|
## Previous epoch snapshot
|
|
|
|
|
|
|
|
|
|
current_justified_checkpoint*: Checkpoint
|
|
|
|
|
finalized_checkpoint*: Checkpoint
|
|
|
|
|
|
|
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.6/specs/phase0/beacon-chain.md#get_total_balance
|
|
|
|
|
TotalBalances* = object
|
|
|
|
|
# The total effective balance of all active validators during the _current_
|
|
|
|
|
# epoch.
|
|
|
|
|
current_epoch_raw*: Gwei
|
|
|
|
|
# The total effective balance of all active validators during the _previous_
|
|
|
|
|
# epoch.
|
|
|
|
|
previous_epoch_raw*: Gwei
|
|
|
|
|
# The total effective balance of all validators who attested during the
|
|
|
|
|
# _current_ epoch.
|
|
|
|
|
current_epoch_attesters_raw*: Gwei
|
|
|
|
|
# The total effective balance of all validators who attested during the
|
|
|
|
|
# _current_ epoch and agreed with the state about the beacon block at the
|
|
|
|
|
# first slot of the _current_ epoch.
|
|
|
|
|
current_epoch_target_attesters_raw*: Gwei
|
|
|
|
|
# The total effective balance of all validators who attested during the
|
|
|
|
|
# _previous_ epoch.
|
|
|
|
|
previous_epoch_attesters_raw*: Gwei
|
|
|
|
|
# The total effective balance of all validators who attested during the
|
|
|
|
|
# _previous_ epoch and agreed with the state about the beacon block at the
|
|
|
|
|
# first slot of the _previous_ epoch.
|
|
|
|
|
previous_epoch_target_attesters_raw*: Gwei
|
|
|
|
|
# The total effective balance of all validators who attested during the
|
|
|
|
|
# _previous_ epoch and agreed with the state about the beacon block at the
|
|
|
|
|
# time of attestation.
|
|
|
|
|
previous_epoch_head_attesters_raw*: Gwei
|
|
|
|
|
|
|
|
|
|
# TODO Careful, not nil analysis is broken / incomplete and the semantics will
|
|
|
|
|
# likely change in future versions of the language:
|
|
|
|
|
# https://github.com/nim-lang/RFCs/issues/250
|
|
|
|
|
BeaconStateRef* = ref BeaconState not nil
|
|
|
|
|
NilableBeaconStateRef* = ref BeaconState
|
|
|
|
|
|
|
|
|
|
# TODO: There should be only a single generic HashedBeaconState definition
|
|
|
|
|
HashedBeaconState* = object
|
|
|
|
|
data*: BeaconState
|
|
|
|
|
root*: Eth2Digest # hash_tree_root(data)
|
|
|
|
|
|
|
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.6/specs/phase0/beacon-chain.md#beaconblock
|
|
|
|
|
BeaconBlock* = object
|
|
|
|
|
## 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
|
|
|
|
|
## validators that will have a chance to vote on it through attestations.
|
|
|
|
|
## Each block collects attestations, or votes, on past blocks, thus a chain
|
|
|
|
|
## is formed.
|
|
|
|
|
|
|
|
|
|
slot*: Slot
|
|
|
|
|
proposer_index*: uint64 # `ValidatorIndex` after validation
|
|
|
|
|
|
|
|
|
|
parent_root*: Eth2Digest
|
|
|
|
|
## Root hash of the previous block
|
|
|
|
|
|
|
|
|
|
state_root*: Eth2Digest
|
|
|
|
|
## The state root, _after_ this block has been processed
|
|
|
|
|
|
|
|
|
|
body*: BeaconBlockBody
|
|
|
|
|
|
|
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.6/specs/phase0/beacon-chain.md#beaconblockbody
|
|
|
|
|
BeaconBlockBody* = object
|
|
|
|
|
randao_reveal*: ValidatorSig
|
|
|
|
|
eth1_data*: Eth1Data
|
|
|
|
|
## Eth1 data vote
|
|
|
|
|
|
|
|
|
|
graffiti*: GraffitiBytes
|
|
|
|
|
## Arbitrary data
|
|
|
|
|
|
|
|
|
|
# Operations
|
|
|
|
|
proposer_slashings*: List[ProposerSlashing, Limit MAX_PROPOSER_SLASHINGS]
|
|
|
|
|
attester_slashings*: List[AttesterSlashing, Limit MAX_ATTESTER_SLASHINGS]
|
|
|
|
|
attestations*: List[Attestation, Limit MAX_ATTESTATIONS]
|
|
|
|
|
deposits*: List[Deposit, Limit MAX_DEPOSITS]
|
|
|
|
|
voluntary_exits*: List[SignedVoluntaryExit, Limit MAX_VOLUNTARY_EXITS]
|
|
|
|
|
|
|
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.6/specs/phase0/beacon-chain.md#signedbeaconblock
|
|
|
|
|
SignedBeaconBlock* = object
|
|
|
|
|
message*: BeaconBlock
|
|
|
|
|
signature*: ValidatorSig
|
|
|
|
|
|
|
|
|
|
root* {.dontSerialize.}: Eth2Digest # cached root of signed beacon block
|
|
|
|
|
|
|
|
|
|
SomeSignedBeaconBlock* = SignedBeaconBlock
|
|
|
|
|
SomeBeaconBlock* = BeaconBlock
|
|
|
|
|
SomeBeaconBlockBody* = BeaconBlockBody
|
|
|
|
|
|
|
|
|
|
EpochInfo* = object
|
|
|
|
|
## Information about the outcome of epoch processing
|
|
|
|
|
validators*: seq[RewardStatus]
|
|
|
|
|
balances*: TotalBalances
|
|
|
|
|
|
|
|
|
|
func clear*(info: var EpochInfo) =
|
|
|
|
|
info.validators.setLen(0)
|
|
|
|
|
info.balances = TotalBalances()
|
|
|
|
|
|
|
|
|
|
func shortLog*(v: SomeBeaconBlock): auto =
|
|
|
|
|
(
|
|
|
|
|
slot: shortLog(v.slot),
|
|
|
|
|
proposer_index: v.proposer_index,
|
|
|
|
|
parent_root: shortLog(v.parent_root),
|
|
|
|
|
state_root: shortLog(v.state_root),
|
|
|
|
|
eth1data: v.body.eth1_data,
|
|
|
|
|
graffiti: $v.body.graffiti,
|
|
|
|
|
proposer_slashings_len: v.body.proposer_slashings.len(),
|
|
|
|
|
attester_slashings_len: v.body.attester_slashings.len(),
|
|
|
|
|
attestations_len: v.body.attestations.len(),
|
|
|
|
|
deposits_len: v.body.deposits.len(),
|
|
|
|
|
voluntary_exits_len: v.body.voluntary_exits.len(),
|
|
|
|
|
sync_committee_participants: -1, # Altair logging compatibility
|
|
|
|
|
block_number: 0'u64, # Bellatrix compat
|
|
|
|
|
block_hash: "", # Bellatrix compat
|
|
|
|
|
parent_hash: "", # Bellatrix compat
|
|
|
|
|
fee_recipient: "", # Bellatrix compat
|
|
|
|
|
bls_to_execution_changes_len: 0, # Capella compat
|
|
|
|
|
blob_kzg_commitments_len: 0, # Deneb compat
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# TODO: There should be only a single generic HashedBeaconState definition
|
|
|
|
|
func initHashedBeaconState*(s: BeaconState): HashedBeaconState =
|
|
|
|
|
HashedBeaconState(data: s)
|
|
|
|
|
|
|
|
|
|
func shortLog*(v: SomeSignedBeaconBlock): auto =
|
|
|
|
|
(
|
|
|
|
|
blck: shortLog(v.message),
|
|
|
|
|
signature: shortLog(v.signature)
|
|
|
|
|
)
|