initial migration from spec/datatypes/{merge => bellatrix} (#3249)
This commit is contained in:
parent
2a12d1c49f
commit
8242e57f41
|
@ -1,5 +1,5 @@
|
||||||
# beacon_chain
|
# beacon_chain
|
||||||
# Copyright (c) 2018-2021 Status Research & Development GmbH
|
# Copyright (c) 2018-2022 Status Research & Development GmbH
|
||||||
# Licensed and distributed under either of
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||||
|
@ -13,7 +13,7 @@ import
|
||||||
json_serialization/std/sets,
|
json_serialization/std/sets,
|
||||||
chronicles,
|
chronicles,
|
||||||
../extras,
|
../extras,
|
||||||
./datatypes/[phase0, altair, merge],
|
./datatypes/[phase0, altair, bellatrix],
|
||||||
"."/[eth2_merkleization, forks, signatures, validator]
|
"."/[eth2_merkleization, forks, signatures, validator]
|
||||||
|
|
||||||
export extras, forks, validator
|
export extras, forks, validator
|
||||||
|
@ -153,7 +153,7 @@ proc slash_validator*(
|
||||||
elif state is altair.BeaconState:
|
elif state is altair.BeaconState:
|
||||||
decrease_balance(state, slashed_index,
|
decrease_balance(state, slashed_index,
|
||||||
validator.effective_balance div MIN_SLASHING_PENALTY_QUOTIENT_ALTAIR)
|
validator.effective_balance div MIN_SLASHING_PENALTY_QUOTIENT_ALTAIR)
|
||||||
elif state is merge.BeaconState:
|
elif state is bellatrix.BeaconState:
|
||||||
decrease_balance(state, slashed_index,
|
decrease_balance(state, slashed_index,
|
||||||
validator.effective_balance div MIN_SLASHING_PENALTY_QUOTIENT_MERGE)
|
validator.effective_balance div MIN_SLASHING_PENALTY_QUOTIENT_MERGE)
|
||||||
else:
|
else:
|
||||||
|
@ -174,7 +174,7 @@ proc slash_validator*(
|
||||||
proposer_reward =
|
proposer_reward =
|
||||||
when state is phase0.BeaconState:
|
when state is phase0.BeaconState:
|
||||||
whistleblower_reward div PROPOSER_REWARD_QUOTIENT
|
whistleblower_reward div PROPOSER_REWARD_QUOTIENT
|
||||||
elif state is altair.BeaconState or state is merge.BeaconState:
|
elif state is altair.BeaconState or state is bellatrix.BeaconState:
|
||||||
whistleblower_reward * PROPOSER_WEIGHT div WEIGHT_DENOMINATOR
|
whistleblower_reward * PROPOSER_WEIGHT div WEIGHT_DENOMINATOR
|
||||||
else:
|
else:
|
||||||
raiseAssert "invalid BeaconState type"
|
raiseAssert "invalid BeaconState type"
|
||||||
|
@ -315,15 +315,15 @@ func get_initial_beacon_block*(state: altair.HashedBeaconState):
|
||||||
message: message, root: hash_tree_root(message))
|
message: message, root: hash_tree_root(message))
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/merge/beacon-chain.md#testing
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/merge/beacon-chain.md#testing
|
||||||
func get_initial_beacon_block*(state: merge.HashedBeaconState):
|
func get_initial_beacon_block*(state: bellatrix.HashedBeaconState):
|
||||||
merge.TrustedSignedBeaconBlock =
|
bellatrix.TrustedSignedBeaconBlock =
|
||||||
# The genesis block is implicitly trusted
|
# The genesis block is implicitly trusted
|
||||||
let message = merge.TrustedBeaconBlock(
|
let message = bellatrix.TrustedBeaconBlock(
|
||||||
slot: state.data.slot,
|
slot: state.data.slot,
|
||||||
state_root: state.root)
|
state_root: state.root)
|
||||||
# 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.
|
||||||
merge.TrustedSignedBeaconBlock(
|
bellatrix.TrustedSignedBeaconBlock(
|
||||||
message: message, root: hash_tree_root(message))
|
message: message, root: hash_tree_root(message))
|
||||||
|
|
||||||
func get_initial_beacon_block*(state: ForkedHashedBeaconState):
|
func get_initial_beacon_block*(state: ForkedHashedBeaconState):
|
||||||
|
@ -525,7 +525,7 @@ func check_attestation_index(
|
||||||
ok()
|
ok()
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#get_attestation_participation_flag_indices
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#get_attestation_participation_flag_indices
|
||||||
func get_attestation_participation_flag_indices(state: altair.BeaconState | merge.BeaconState,
|
func get_attestation_participation_flag_indices(state: altair.BeaconState | bellatrix.BeaconState,
|
||||||
data: AttestationData,
|
data: AttestationData,
|
||||||
inclusion_delay: uint64): seq[int] =
|
inclusion_delay: uint64): seq[int] =
|
||||||
## Return the flag indices that are satisfied by an attestation.
|
## Return the flag indices that are satisfied by an attestation.
|
||||||
|
@ -580,7 +580,7 @@ func get_base_reward_per_increment*(
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#get_base_reward
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#get_base_reward
|
||||||
func get_base_reward(
|
func get_base_reward(
|
||||||
state: altair.BeaconState | merge.BeaconState, index: ValidatorIndex,
|
state: altair.BeaconState | bellatrix.BeaconState, index: ValidatorIndex,
|
||||||
base_reward_per_increment: Gwei): Gwei =
|
base_reward_per_increment: Gwei): Gwei =
|
||||||
## Return the base reward for the validator defined by ``index`` with respect
|
## Return the base reward for the validator defined by ``index`` with respect
|
||||||
## to the current ``state``.
|
## to the current ``state``.
|
||||||
|
@ -689,7 +689,7 @@ proc process_attestation*(
|
||||||
addPendingAttestation(state.current_epoch_attestations)
|
addPendingAttestation(state.current_epoch_attestations)
|
||||||
else:
|
else:
|
||||||
addPendingAttestation(state.previous_epoch_attestations)
|
addPendingAttestation(state.previous_epoch_attestations)
|
||||||
elif state is altair.BeaconState or state is merge.BeaconState:
|
elif state is altair.BeaconState or state is bellatrix.BeaconState:
|
||||||
doAssert base_reward_per_increment > 0.Gwei
|
doAssert base_reward_per_increment > 0.Gwei
|
||||||
if attestation.data.target.epoch == get_current_epoch(state):
|
if attestation.data.target.epoch == get_current_epoch(state):
|
||||||
updateParticipationFlags(state.current_epoch_participation)
|
updateParticipationFlags(state.current_epoch_participation)
|
||||||
|
@ -701,7 +701,7 @@ proc process_attestation*(
|
||||||
ok()
|
ok()
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#get_next_sync_committee_indices
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#get_next_sync_committee_indices
|
||||||
func get_next_sync_committee_keys(state: altair.BeaconState | merge.BeaconState):
|
func get_next_sync_committee_keys(state: altair.BeaconState | bellatrix.BeaconState):
|
||||||
array[SYNC_COMMITTEE_SIZE, ValidatorPubKey] =
|
array[SYNC_COMMITTEE_SIZE, ValidatorPubKey] =
|
||||||
## Return the sequence of sync committee indices (which may include
|
## Return the sequence of sync committee indices (which may include
|
||||||
## duplicate indices) for the next sync committee, given a ``state`` at a
|
## duplicate indices) for the next sync committee, given a ``state`` at a
|
||||||
|
@ -737,7 +737,7 @@ func get_next_sync_committee_keys(state: altair.BeaconState | merge.BeaconState)
|
||||||
res
|
res
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#get_next_sync_committee
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#get_next_sync_committee
|
||||||
proc get_next_sync_committee*(state: altair.BeaconState | merge.BeaconState):
|
proc get_next_sync_committee*(state: altair.BeaconState | bellatrix.BeaconState):
|
||||||
SyncCommittee =
|
SyncCommittee =
|
||||||
## Return the *next* sync committee for a given ``state``.
|
## Return the *next* sync committee for a given ``state``.
|
||||||
var res: SyncCommittee
|
var res: SyncCommittee
|
||||||
|
@ -842,9 +842,9 @@ proc upgrade_to_altair*(cfg: RuntimeConfig, pre: phase0.BeaconState): ref altair
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/merge/fork.md#upgrading-the-state
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/merge/fork.md#upgrading-the-state
|
||||||
func upgrade_to_merge*(cfg: RuntimeConfig, pre: altair.BeaconState):
|
func upgrade_to_merge*(cfg: RuntimeConfig, pre: altair.BeaconState):
|
||||||
ref merge.BeaconState =
|
ref bellatrix.BeaconState =
|
||||||
let epoch = get_current_epoch(pre)
|
let epoch = get_current_epoch(pre)
|
||||||
(ref merge.BeaconState)(
|
(ref bellatrix.BeaconState)(
|
||||||
# Versioning
|
# Versioning
|
||||||
genesis_time: pre.genesis_time,
|
genesis_time: pre.genesis_time,
|
||||||
genesis_validators_root: pre.genesis_validators_root,
|
genesis_validators_root: pre.genesis_validators_root,
|
||||||
|
@ -926,7 +926,7 @@ func latest_block_root*(state: ForkyHashedBeaconState): Eth2Digest =
|
||||||
latest_block_root(state.data, state.root)
|
latest_block_root(state.data, state.root)
|
||||||
|
|
||||||
func get_sync_committee_cache*(
|
func get_sync_committee_cache*(
|
||||||
state: altair.BeaconState | merge.BeaconState, cache: var StateCache):
|
state: altair.BeaconState | bellatrix.BeaconState, cache: var StateCache):
|
||||||
SyncCommitteeCache =
|
SyncCommitteeCache =
|
||||||
let period = state.slot.sync_committee_period()
|
let period = state.slot.sync_committee_period()
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,390 @@
|
||||||
|
# beacon_chain
|
||||||
|
# Copyright (c) 2021-2022 Status Research & Development GmbH
|
||||||
|
# Licensed and distributed under either of
|
||||||
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||||
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
|
# 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".}
|
||||||
|
|
||||||
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
import
|
||||||
|
stew/[assign2, byteutils],
|
||||||
|
json_serialization,
|
||||||
|
ssz_serialization/types as sszTypes,
|
||||||
|
../digest,
|
||||||
|
"."/[base, phase0, altair]
|
||||||
|
|
||||||
|
export json_serialization, base
|
||||||
|
|
||||||
|
type
|
||||||
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/bellatrix/beacon-chain.md#custom-types
|
||||||
|
Transaction* = List[byte, Limit MAX_BYTES_PER_TRANSACTION]
|
||||||
|
|
||||||
|
ExecutionAddress* = object
|
||||||
|
data*: array[20, byte] # TODO there's a network_metadata type, but the import hierarchy's inconvenient
|
||||||
|
|
||||||
|
BloomLogs* = object
|
||||||
|
data*: array[BYTES_PER_LOGS_BLOOM, byte]
|
||||||
|
|
||||||
|
PayloadID* = array[8, byte]
|
||||||
|
|
||||||
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/merge/beacon-chain.md#executionpayload
|
||||||
|
ExecutionPayload* = object
|
||||||
|
parent_hash*: Eth2Digest
|
||||||
|
fee_recipient*: ExecutionAddress # 'beneficiary' in the yellow paper
|
||||||
|
state_root*: Eth2Digest
|
||||||
|
receipts_root*: Eth2Digest # 'receipts root' in the yellow paper
|
||||||
|
logs_bloom*: BloomLogs
|
||||||
|
random*: Eth2Digest # 'difficulty' in the yellow paper
|
||||||
|
block_number*: uint64 # 'number' in the yellow paper
|
||||||
|
gas_limit*: uint64
|
||||||
|
gas_used*: uint64
|
||||||
|
timestamp*: uint64
|
||||||
|
extra_data*: List[byte, MAX_EXTRA_DATA_BYTES]
|
||||||
|
base_fee_per_gas*: Eth2Digest # base fee introduced in EIP-1559, little-endian serialized
|
||||||
|
|
||||||
|
# Extra payload fields
|
||||||
|
block_hash*: Eth2Digest # Hash of execution block
|
||||||
|
transactions*: List[Transaction, MAX_TRANSACTIONS_PER_PAYLOAD]
|
||||||
|
|
||||||
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/merge/beacon-chain.md#executionpayloadheader
|
||||||
|
ExecutionPayloadHeader* = object
|
||||||
|
parent_hash*: Eth2Digest
|
||||||
|
fee_recipient*: ExecutionAddress
|
||||||
|
state_root*: Eth2Digest
|
||||||
|
receipts_root*: Eth2Digest
|
||||||
|
logs_bloom*: BloomLogs
|
||||||
|
random*: Eth2Digest
|
||||||
|
block_number*: uint64
|
||||||
|
gas_limit*: uint64
|
||||||
|
gas_used*: uint64
|
||||||
|
timestamp*: uint64
|
||||||
|
extra_data*: List[byte, MAX_EXTRA_DATA_BYTES]
|
||||||
|
base_fee_per_gas*: Eth2Digest # base fee introduced in EIP-1559, little-endian serialized
|
||||||
|
|
||||||
|
# Extra payload fields
|
||||||
|
block_hash*: Eth2Digest # Hash of execution block
|
||||||
|
transactions_root*: Eth2Digest
|
||||||
|
|
||||||
|
ExecutePayload* = proc(
|
||||||
|
execution_payload: ExecutionPayload): bool {.gcsafe, raises: [Defect].}
|
||||||
|
|
||||||
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/bellatrix/fork-choice.md#powblock
|
||||||
|
PowBlock* = object
|
||||||
|
block_hash*: Eth2Digest
|
||||||
|
parent_hash*: Eth2Digest
|
||||||
|
total_difficulty*: Eth2Digest # uint256
|
||||||
|
|
||||||
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/merge/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[uint64, Limit VALIDATOR_REGISTRY_LIMIT]
|
||||||
|
|
||||||
|
# Randomness
|
||||||
|
randao_mixes*: HashArray[Limit EPOCHS_PER_HISTORICAL_VECTOR, Eth2Digest]
|
||||||
|
|
||||||
|
# Slashings
|
||||||
|
slashings*: HashArray[Limit EPOCHS_PER_SLASHINGS_VECTOR, uint64] ##\
|
||||||
|
## Per-epoch sums of slashed effective balances
|
||||||
|
|
||||||
|
# Participation
|
||||||
|
previous_epoch_participation*:
|
||||||
|
HashList[ParticipationFlags, Limit VALIDATOR_REGISTRY_LIMIT]
|
||||||
|
current_epoch_participation*:
|
||||||
|
HashList[ParticipationFlags, Limit VALIDATOR_REGISTRY_LIMIT]
|
||||||
|
|
||||||
|
# Finality
|
||||||
|
justification_bits*: JustificationBits
|
||||||
|
|
||||||
|
previous_justified_checkpoint*: Checkpoint ##\
|
||||||
|
## Previous epoch snapshot
|
||||||
|
|
||||||
|
current_justified_checkpoint*: Checkpoint
|
||||||
|
finalized_checkpoint*: Checkpoint
|
||||||
|
|
||||||
|
# Inactivity
|
||||||
|
inactivity_scores*: HashList[uint64, Limit VALIDATOR_REGISTRY_LIMIT]
|
||||||
|
|
||||||
|
# Sync
|
||||||
|
current_sync_committee*: SyncCommittee
|
||||||
|
next_sync_committee*: SyncCommittee
|
||||||
|
|
||||||
|
# Execution
|
||||||
|
latest_execution_payload_header*: ExecutionPayloadHeader # [New in Merge]
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
HashedBeaconState* = object
|
||||||
|
data*: BeaconState
|
||||||
|
root*: Eth2Digest # hash_tree_root(data)
|
||||||
|
|
||||||
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/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
|
||||||
|
|
||||||
|
parent_root*: Eth2Digest ##\
|
||||||
|
## Root hash of the previous block
|
||||||
|
|
||||||
|
state_root*: Eth2Digest ##\
|
||||||
|
## The state root, _after_ this block has been processed
|
||||||
|
|
||||||
|
body*: BeaconBlockBody
|
||||||
|
|
||||||
|
SigVerifiedBeaconBlock* = object
|
||||||
|
## A BeaconBlock that contains verified signatures
|
||||||
|
## but that has not been verified for state transition
|
||||||
|
slot*: Slot
|
||||||
|
proposer_index*: uint64
|
||||||
|
|
||||||
|
parent_root*: Eth2Digest ##\
|
||||||
|
## Root hash of the previous block
|
||||||
|
|
||||||
|
state_root*: Eth2Digest ##\
|
||||||
|
## The state root, _after_ this block has been processed
|
||||||
|
|
||||||
|
body*: SigVerifiedBeaconBlockBody
|
||||||
|
|
||||||
|
TrustedBeaconBlock* = object
|
||||||
|
## When we receive blocks from outside sources, they are untrusted and go
|
||||||
|
## through several layers of validation. Blocks that have gone through
|
||||||
|
## validations can be trusted to be well-formed, with a correct signature,
|
||||||
|
## having a parent and applying cleanly to the state that their parent
|
||||||
|
## left them with.
|
||||||
|
##
|
||||||
|
## When loading such blocks from the database, to rewind states for example,
|
||||||
|
## it is expensive to redo the validations (in particular, the signature
|
||||||
|
## checks), thus `TrustedBlock` uses a `TrustedSig` type to mark that these
|
||||||
|
## checks can be skipped.
|
||||||
|
##
|
||||||
|
## TODO this could probably be solved with some type trickery, but there
|
||||||
|
## too many bugs in nim around generics handling, and we've used up
|
||||||
|
## the trickery budget in the serialization library already. Until
|
||||||
|
## then, the type must be manually kept compatible with its untrusted
|
||||||
|
## cousin.
|
||||||
|
slot*: Slot
|
||||||
|
proposer_index*: uint64
|
||||||
|
parent_root*: Eth2Digest ##\
|
||||||
|
state_root*: Eth2Digest ##\
|
||||||
|
body*: TrustedBeaconBlockBody
|
||||||
|
|
||||||
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/merge/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]
|
||||||
|
sync_aggregate*: SyncAggregate
|
||||||
|
|
||||||
|
# Execution
|
||||||
|
execution_payload*: ExecutionPayload # [New in Merge]
|
||||||
|
|
||||||
|
SigVerifiedBeaconBlockBody* = object
|
||||||
|
## A BeaconBlock body with signatures verified
|
||||||
|
## including:
|
||||||
|
## - Randao reveal
|
||||||
|
## - Attestations
|
||||||
|
## - ProposerSlashing (SignedBeaconBlockHeader)
|
||||||
|
## - AttesterSlashing (IndexedAttestation)
|
||||||
|
## - SignedVoluntaryExits
|
||||||
|
##
|
||||||
|
## - ETH1Data (Deposits) can contain invalid BLS signatures
|
||||||
|
##
|
||||||
|
## The block state transition has NOT been verified
|
||||||
|
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]
|
||||||
|
sync_aggregate*: SyncAggregate # TODO TrustedSyncAggregate after batching
|
||||||
|
|
||||||
|
# Execution
|
||||||
|
execution_payload*: ExecutionPayload # [New in Merge]
|
||||||
|
|
||||||
|
TrustedBeaconBlockBody* = object
|
||||||
|
## A full verified block
|
||||||
|
randao_reveal*: TrustedSig
|
||||||
|
eth1_data*: Eth1Data ##\
|
||||||
|
## Eth1 data vote
|
||||||
|
|
||||||
|
graffiti*: GraffitiBytes ##\
|
||||||
|
## Arbitrary data
|
||||||
|
|
||||||
|
# Operations
|
||||||
|
proposer_slashings*: List[TrustedProposerSlashing, Limit MAX_PROPOSER_SLASHINGS]
|
||||||
|
attester_slashings*: List[TrustedAttesterSlashing, Limit MAX_ATTESTER_SLASHINGS]
|
||||||
|
attestations*: List[TrustedAttestation, Limit MAX_ATTESTATIONS]
|
||||||
|
deposits*: List[Deposit, Limit MAX_DEPOSITS]
|
||||||
|
voluntary_exits*: List[TrustedSignedVoluntaryExit, Limit MAX_VOLUNTARY_EXITS]
|
||||||
|
sync_aggregate*: TrustedSyncAggregate
|
||||||
|
|
||||||
|
# Execution
|
||||||
|
execution_payload*: ExecutionPayload # [New in Merge]
|
||||||
|
|
||||||
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#signedbeaconblock
|
||||||
|
SignedBeaconBlock* = object
|
||||||
|
message*: BeaconBlock
|
||||||
|
signature*: ValidatorSig
|
||||||
|
|
||||||
|
root* {.dontSerialize.}: Eth2Digest # cached root of signed beacon block
|
||||||
|
|
||||||
|
SigVerifiedSignedBeaconBlock* = object
|
||||||
|
## A SignedBeaconBlock with signatures verified
|
||||||
|
## including:
|
||||||
|
## - Block signature
|
||||||
|
## - BeaconBlockBody
|
||||||
|
## - Randao reveal
|
||||||
|
## - Attestations
|
||||||
|
## - ProposerSlashing (SignedBeaconBlockHeader)
|
||||||
|
## - AttesterSlashing (IndexedAttestation)
|
||||||
|
## - SignedVoluntaryExits
|
||||||
|
##
|
||||||
|
## - ETH1Data (Deposits) can contain invalid BLS signatures
|
||||||
|
##
|
||||||
|
## The block state transition has NOT been verified
|
||||||
|
message*: SigVerifiedBeaconBlock
|
||||||
|
signature*: TrustedSig
|
||||||
|
|
||||||
|
root* {.dontSerialize.}: Eth2Digest # cached root of signed beacon block
|
||||||
|
|
||||||
|
TrustedSignedBeaconBlock* = object
|
||||||
|
message*: TrustedBeaconBlock
|
||||||
|
signature*: TrustedSig
|
||||||
|
|
||||||
|
root* {.dontSerialize.}: Eth2Digest # cached root of signed beacon block
|
||||||
|
|
||||||
|
SomeSignedBeaconBlock* = SignedBeaconBlock | SigVerifiedSignedBeaconBlock | TrustedSignedBeaconBlock
|
||||||
|
SomeBeaconBlock* = BeaconBlock | SigVerifiedBeaconBlock | TrustedBeaconBlock
|
||||||
|
SomeBeaconBlockBody* = BeaconBlockBody | SigVerifiedBeaconBlockBody | TrustedBeaconBlockBody
|
||||||
|
|
||||||
|
# TODO why does this fail?
|
||||||
|
#SomeSomeBeaconBlock* = SomeBeaconBlock | phase0.SomeBeaconBlock
|
||||||
|
SomeSomeBeaconBlock* =
|
||||||
|
BeaconBlock | SigVerifiedBeaconBlock | TrustedBeaconBlock |
|
||||||
|
altair.BeaconBlock | altair.SigVerifiedBeaconBlock | altair.TrustedBeaconBlock |
|
||||||
|
phase0.BeaconBlock | phase0.SigVerifiedBeaconBlock | phase0.TrustedBeaconBlock
|
||||||
|
|
||||||
|
# TODO see above, re why does it fail
|
||||||
|
SomeSomeBeaconBlockBody* =
|
||||||
|
BeaconBlockBody | SigVerifiedBeaconBlockBody | TrustedBeaconBlockBody |
|
||||||
|
altair.BeaconBlockBody | altair.SigVerifiedBeaconBlockBody | altair.TrustedBeaconBlockBody |
|
||||||
|
phase0.BeaconBlockBody | phase0.SigVerifiedBeaconBlockBody | phase0.TrustedBeaconBlockBody
|
||||||
|
#SomeSomeBeaconBlockBody* = SomeBeaconBlockBody | phase0.SomeBeaconBlockBody
|
||||||
|
|
||||||
|
SomeSomeSignedBeaconBlock* = SomeSignedBeaconBlock | altair.SomeSignedBeaconBlock | phase0.SomeSignedBeaconBlock
|
||||||
|
|
||||||
|
BlockParams* = object
|
||||||
|
parentHash*: string
|
||||||
|
timestamp*: string
|
||||||
|
|
||||||
|
BoolReturnValidRPC* = object
|
||||||
|
valid*: bool
|
||||||
|
|
||||||
|
BoolReturnSuccessRPC* = object
|
||||||
|
success*: bool
|
||||||
|
|
||||||
|
func encodeQuantityHex*(x: auto): string =
|
||||||
|
"0x" & x.toHex
|
||||||
|
|
||||||
|
proc fromHex*(T: typedesc[BloomLogs], s: string): T {.raises: [Defect, ValueError].} =
|
||||||
|
hexToByteArray(s, result.data)
|
||||||
|
|
||||||
|
proc fromHex*(T: typedesc[ExecutionAddress], s: string): T {.raises: [Defect, ValueError].} =
|
||||||
|
hexToByteArray(s, result.data)
|
||||||
|
|
||||||
|
proc writeValue*(w: var JsonWriter, a: ExecutionAddress) {.raises: [Defect, IOError, SerializationError].} =
|
||||||
|
w.writeValue $a
|
||||||
|
|
||||||
|
proc readValue*(r: var JsonReader, a: var ExecutionAddress) {.raises: [Defect, IOError, SerializationError].} =
|
||||||
|
try:
|
||||||
|
a = fromHex(type(a), r.readValue(string))
|
||||||
|
except ValueError:
|
||||||
|
raiseUnexpectedValue(r, "Hex string expected")
|
||||||
|
|
||||||
|
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: countOnes(v.body.sync_aggregate.sync_committee_bits)
|
||||||
|
)
|
||||||
|
|
||||||
|
func shortLog*(v: SomeSignedBeaconBlock): auto =
|
||||||
|
(
|
||||||
|
blck: shortLog(v.message),
|
||||||
|
signature: shortLog(v.signature)
|
||||||
|
)
|
||||||
|
|
||||||
|
template asSigned*(x: SigVerifiedSignedBeaconBlock | TrustedSignedBeaconBlock):
|
||||||
|
SignedBeaconBlock =
|
||||||
|
isomorphicCast[SignedBeaconBlock](x)
|
||||||
|
|
||||||
|
template asSigVerified*(x: SignedBeaconBlock | TrustedSignedBeaconBlock): SigVerifiedSignedBeaconBlock =
|
||||||
|
isomorphicCast[SigVerifiedSignedBeaconBlock](x)
|
||||||
|
|
||||||
|
template asTrusted*(
|
||||||
|
x: SignedBeaconBlock | SigVerifiedSignedBeaconBlock): TrustedSignedBeaconBlock =
|
||||||
|
isomorphicCast[TrustedSignedBeaconBlock](x)
|
|
@ -1,390 +1,2 @@
|
||||||
# beacon_chain
|
import ./bellatrix
|
||||||
# Copyright (c) 2021-2022 Status Research & Development GmbH
|
export bellatrix
|
||||||
# Licensed and distributed under either of
|
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
|
||||||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
|
||||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
||||||
|
|
||||||
# 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".}
|
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
|
||||||
|
|
||||||
import
|
|
||||||
stew/[assign2, byteutils],
|
|
||||||
json_serialization,
|
|
||||||
ssz_serialization/types as sszTypes,
|
|
||||||
../digest,
|
|
||||||
"."/[base, phase0, altair]
|
|
||||||
|
|
||||||
export json_serialization, base
|
|
||||||
|
|
||||||
type
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/bellatrix/beacon-chain.md#custom-types
|
|
||||||
Transaction* = List[byte, Limit MAX_BYTES_PER_TRANSACTION]
|
|
||||||
|
|
||||||
ExecutionAddress* = object
|
|
||||||
data*: array[20, byte] # TODO there's a network_metadata type, but the import hierarchy's inconvenient
|
|
||||||
|
|
||||||
BloomLogs* = object
|
|
||||||
data*: array[BYTES_PER_LOGS_BLOOM, byte]
|
|
||||||
|
|
||||||
PayloadID* = array[8, byte]
|
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/merge/beacon-chain.md#executionpayload
|
|
||||||
ExecutionPayload* = object
|
|
||||||
parent_hash*: Eth2Digest
|
|
||||||
fee_recipient*: ExecutionAddress # 'beneficiary' in the yellow paper
|
|
||||||
state_root*: Eth2Digest
|
|
||||||
receipts_root*: Eth2Digest # 'receipts root' in the yellow paper
|
|
||||||
logs_bloom*: BloomLogs
|
|
||||||
random*: Eth2Digest # 'difficulty' in the yellow paper
|
|
||||||
block_number*: uint64 # 'number' in the yellow paper
|
|
||||||
gas_limit*: uint64
|
|
||||||
gas_used*: uint64
|
|
||||||
timestamp*: uint64
|
|
||||||
extra_data*: List[byte, MAX_EXTRA_DATA_BYTES]
|
|
||||||
base_fee_per_gas*: Eth2Digest # base fee introduced in EIP-1559, little-endian serialized
|
|
||||||
|
|
||||||
# Extra payload fields
|
|
||||||
block_hash*: Eth2Digest # Hash of execution block
|
|
||||||
transactions*: List[Transaction, MAX_TRANSACTIONS_PER_PAYLOAD]
|
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/merge/beacon-chain.md#executionpayloadheader
|
|
||||||
ExecutionPayloadHeader* = object
|
|
||||||
parent_hash*: Eth2Digest
|
|
||||||
fee_recipient*: ExecutionAddress
|
|
||||||
state_root*: Eth2Digest
|
|
||||||
receipts_root*: Eth2Digest
|
|
||||||
logs_bloom*: BloomLogs
|
|
||||||
random*: Eth2Digest
|
|
||||||
block_number*: uint64
|
|
||||||
gas_limit*: uint64
|
|
||||||
gas_used*: uint64
|
|
||||||
timestamp*: uint64
|
|
||||||
extra_data*: List[byte, MAX_EXTRA_DATA_BYTES]
|
|
||||||
base_fee_per_gas*: Eth2Digest # base fee introduced in EIP-1559, little-endian serialized
|
|
||||||
|
|
||||||
# Extra payload fields
|
|
||||||
block_hash*: Eth2Digest # Hash of execution block
|
|
||||||
transactions_root*: Eth2Digest
|
|
||||||
|
|
||||||
ExecutePayload* = proc(
|
|
||||||
execution_payload: ExecutionPayload): bool {.gcsafe, raises: [Defect].}
|
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/bellatrix/fork-choice.md#powblock
|
|
||||||
PowBlock* = object
|
|
||||||
block_hash*: Eth2Digest
|
|
||||||
parent_hash*: Eth2Digest
|
|
||||||
total_difficulty*: Eth2Digest # uint256
|
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/merge/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[uint64, Limit VALIDATOR_REGISTRY_LIMIT]
|
|
||||||
|
|
||||||
# Randomness
|
|
||||||
randao_mixes*: HashArray[Limit EPOCHS_PER_HISTORICAL_VECTOR, Eth2Digest]
|
|
||||||
|
|
||||||
# Slashings
|
|
||||||
slashings*: HashArray[Limit EPOCHS_PER_SLASHINGS_VECTOR, uint64] ##\
|
|
||||||
## Per-epoch sums of slashed effective balances
|
|
||||||
|
|
||||||
# Participation
|
|
||||||
previous_epoch_participation*:
|
|
||||||
HashList[ParticipationFlags, Limit VALIDATOR_REGISTRY_LIMIT]
|
|
||||||
current_epoch_participation*:
|
|
||||||
HashList[ParticipationFlags, Limit VALIDATOR_REGISTRY_LIMIT]
|
|
||||||
|
|
||||||
# Finality
|
|
||||||
justification_bits*: JustificationBits
|
|
||||||
|
|
||||||
previous_justified_checkpoint*: Checkpoint ##\
|
|
||||||
## Previous epoch snapshot
|
|
||||||
|
|
||||||
current_justified_checkpoint*: Checkpoint
|
|
||||||
finalized_checkpoint*: Checkpoint
|
|
||||||
|
|
||||||
# Inactivity
|
|
||||||
inactivity_scores*: HashList[uint64, Limit VALIDATOR_REGISTRY_LIMIT]
|
|
||||||
|
|
||||||
# Sync
|
|
||||||
current_sync_committee*: SyncCommittee
|
|
||||||
next_sync_committee*: SyncCommittee
|
|
||||||
|
|
||||||
# Execution
|
|
||||||
latest_execution_payload_header*: ExecutionPayloadHeader # [New in Merge]
|
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
HashedBeaconState* = object
|
|
||||||
data*: BeaconState
|
|
||||||
root*: Eth2Digest # hash_tree_root(data)
|
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/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
|
|
||||||
|
|
||||||
parent_root*: Eth2Digest ##\
|
|
||||||
## Root hash of the previous block
|
|
||||||
|
|
||||||
state_root*: Eth2Digest ##\
|
|
||||||
## The state root, _after_ this block has been processed
|
|
||||||
|
|
||||||
body*: BeaconBlockBody
|
|
||||||
|
|
||||||
SigVerifiedBeaconBlock* = object
|
|
||||||
## A BeaconBlock that contains verified signatures
|
|
||||||
## but that has not been verified for state transition
|
|
||||||
slot*: Slot
|
|
||||||
proposer_index*: uint64
|
|
||||||
|
|
||||||
parent_root*: Eth2Digest ##\
|
|
||||||
## Root hash of the previous block
|
|
||||||
|
|
||||||
state_root*: Eth2Digest ##\
|
|
||||||
## The state root, _after_ this block has been processed
|
|
||||||
|
|
||||||
body*: SigVerifiedBeaconBlockBody
|
|
||||||
|
|
||||||
TrustedBeaconBlock* = object
|
|
||||||
## When we receive blocks from outside sources, they are untrusted and go
|
|
||||||
## through several layers of validation. Blocks that have gone through
|
|
||||||
## validations can be trusted to be well-formed, with a correct signature,
|
|
||||||
## having a parent and applying cleanly to the state that their parent
|
|
||||||
## left them with.
|
|
||||||
##
|
|
||||||
## When loading such blocks from the database, to rewind states for example,
|
|
||||||
## it is expensive to redo the validations (in particular, the signature
|
|
||||||
## checks), thus `TrustedBlock` uses a `TrustedSig` type to mark that these
|
|
||||||
## checks can be skipped.
|
|
||||||
##
|
|
||||||
## TODO this could probably be solved with some type trickery, but there
|
|
||||||
## too many bugs in nim around generics handling, and we've used up
|
|
||||||
## the trickery budget in the serialization library already. Until
|
|
||||||
## then, the type must be manually kept compatible with its untrusted
|
|
||||||
## cousin.
|
|
||||||
slot*: Slot
|
|
||||||
proposer_index*: uint64
|
|
||||||
parent_root*: Eth2Digest ##\
|
|
||||||
state_root*: Eth2Digest ##\
|
|
||||||
body*: TrustedBeaconBlockBody
|
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/merge/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]
|
|
||||||
sync_aggregate*: SyncAggregate
|
|
||||||
|
|
||||||
# Execution
|
|
||||||
execution_payload*: ExecutionPayload # [New in Merge]
|
|
||||||
|
|
||||||
SigVerifiedBeaconBlockBody* = object
|
|
||||||
## A BeaconBlock body with signatures verified
|
|
||||||
## including:
|
|
||||||
## - Randao reveal
|
|
||||||
## - Attestations
|
|
||||||
## - ProposerSlashing (SignedBeaconBlockHeader)
|
|
||||||
## - AttesterSlashing (IndexedAttestation)
|
|
||||||
## - SignedVoluntaryExits
|
|
||||||
##
|
|
||||||
## - ETH1Data (Deposits) can contain invalid BLS signatures
|
|
||||||
##
|
|
||||||
## The block state transition has NOT been verified
|
|
||||||
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]
|
|
||||||
sync_aggregate*: SyncAggregate # TODO TrustedSyncAggregate after batching
|
|
||||||
|
|
||||||
# Execution
|
|
||||||
execution_payload*: ExecutionPayload # [New in Merge]
|
|
||||||
|
|
||||||
TrustedBeaconBlockBody* = object
|
|
||||||
## A full verified block
|
|
||||||
randao_reveal*: TrustedSig
|
|
||||||
eth1_data*: Eth1Data ##\
|
|
||||||
## Eth1 data vote
|
|
||||||
|
|
||||||
graffiti*: GraffitiBytes ##\
|
|
||||||
## Arbitrary data
|
|
||||||
|
|
||||||
# Operations
|
|
||||||
proposer_slashings*: List[TrustedProposerSlashing, Limit MAX_PROPOSER_SLASHINGS]
|
|
||||||
attester_slashings*: List[TrustedAttesterSlashing, Limit MAX_ATTESTER_SLASHINGS]
|
|
||||||
attestations*: List[TrustedAttestation, Limit MAX_ATTESTATIONS]
|
|
||||||
deposits*: List[Deposit, Limit MAX_DEPOSITS]
|
|
||||||
voluntary_exits*: List[TrustedSignedVoluntaryExit, Limit MAX_VOLUNTARY_EXITS]
|
|
||||||
sync_aggregate*: TrustedSyncAggregate
|
|
||||||
|
|
||||||
# Execution
|
|
||||||
execution_payload*: ExecutionPayload # [New in Merge]
|
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#signedbeaconblock
|
|
||||||
SignedBeaconBlock* = object
|
|
||||||
message*: BeaconBlock
|
|
||||||
signature*: ValidatorSig
|
|
||||||
|
|
||||||
root* {.dontSerialize.}: Eth2Digest # cached root of signed beacon block
|
|
||||||
|
|
||||||
SigVerifiedSignedBeaconBlock* = object
|
|
||||||
## A SignedBeaconBlock with signatures verified
|
|
||||||
## including:
|
|
||||||
## - Block signature
|
|
||||||
## - BeaconBlockBody
|
|
||||||
## - Randao reveal
|
|
||||||
## - Attestations
|
|
||||||
## - ProposerSlashing (SignedBeaconBlockHeader)
|
|
||||||
## - AttesterSlashing (IndexedAttestation)
|
|
||||||
## - SignedVoluntaryExits
|
|
||||||
##
|
|
||||||
## - ETH1Data (Deposits) can contain invalid BLS signatures
|
|
||||||
##
|
|
||||||
## The block state transition has NOT been verified
|
|
||||||
message*: SigVerifiedBeaconBlock
|
|
||||||
signature*: TrustedSig
|
|
||||||
|
|
||||||
root* {.dontSerialize.}: Eth2Digest # cached root of signed beacon block
|
|
||||||
|
|
||||||
TrustedSignedBeaconBlock* = object
|
|
||||||
message*: TrustedBeaconBlock
|
|
||||||
signature*: TrustedSig
|
|
||||||
|
|
||||||
root* {.dontSerialize.}: Eth2Digest # cached root of signed beacon block
|
|
||||||
|
|
||||||
SomeSignedBeaconBlock* = SignedBeaconBlock | SigVerifiedSignedBeaconBlock | TrustedSignedBeaconBlock
|
|
||||||
SomeBeaconBlock* = BeaconBlock | SigVerifiedBeaconBlock | TrustedBeaconBlock
|
|
||||||
SomeBeaconBlockBody* = BeaconBlockBody | SigVerifiedBeaconBlockBody | TrustedBeaconBlockBody
|
|
||||||
|
|
||||||
# TODO why does this fail?
|
|
||||||
#SomeSomeBeaconBlock* = SomeBeaconBlock | phase0.SomeBeaconBlock
|
|
||||||
SomeSomeBeaconBlock* =
|
|
||||||
BeaconBlock | SigVerifiedBeaconBlock | TrustedBeaconBlock |
|
|
||||||
altair.BeaconBlock | altair.SigVerifiedBeaconBlock | altair.TrustedBeaconBlock |
|
|
||||||
phase0.BeaconBlock | phase0.SigVerifiedBeaconBlock | phase0.TrustedBeaconBlock
|
|
||||||
|
|
||||||
# TODO see above, re why does it fail
|
|
||||||
SomeSomeBeaconBlockBody* =
|
|
||||||
BeaconBlockBody | SigVerifiedBeaconBlockBody | TrustedBeaconBlockBody |
|
|
||||||
altair.BeaconBlockBody | altair.SigVerifiedBeaconBlockBody | altair.TrustedBeaconBlockBody |
|
|
||||||
phase0.BeaconBlockBody | phase0.SigVerifiedBeaconBlockBody | phase0.TrustedBeaconBlockBody
|
|
||||||
#SomeSomeBeaconBlockBody* = SomeBeaconBlockBody | phase0.SomeBeaconBlockBody
|
|
||||||
|
|
||||||
SomeSomeSignedBeaconBlock* = SomeSignedBeaconBlock | altair.SomeSignedBeaconBlock | phase0.SomeSignedBeaconBlock
|
|
||||||
|
|
||||||
BlockParams* = object
|
|
||||||
parentHash*: string
|
|
||||||
timestamp*: string
|
|
||||||
|
|
||||||
BoolReturnValidRPC* = object
|
|
||||||
valid*: bool
|
|
||||||
|
|
||||||
BoolReturnSuccessRPC* = object
|
|
||||||
success*: bool
|
|
||||||
|
|
||||||
func encodeQuantityHex*(x: auto): string =
|
|
||||||
"0x" & x.toHex
|
|
||||||
|
|
||||||
proc fromHex*(T: typedesc[BloomLogs], s: string): T {.raises: [Defect, ValueError].} =
|
|
||||||
hexToByteArray(s, result.data)
|
|
||||||
|
|
||||||
proc fromHex*(T: typedesc[ExecutionAddress], s: string): T {.raises: [Defect, ValueError].} =
|
|
||||||
hexToByteArray(s, result.data)
|
|
||||||
|
|
||||||
proc writeValue*(w: var JsonWriter, a: ExecutionAddress) {.raises: [Defect, IOError, SerializationError].} =
|
|
||||||
w.writeValue $a
|
|
||||||
|
|
||||||
proc readValue*(r: var JsonReader, a: var ExecutionAddress) {.raises: [Defect, IOError, SerializationError].} =
|
|
||||||
try:
|
|
||||||
a = fromHex(type(a), r.readValue(string))
|
|
||||||
except ValueError:
|
|
||||||
raiseUnexpectedValue(r, "Hex string expected")
|
|
||||||
|
|
||||||
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: countOnes(v.body.sync_aggregate.sync_committee_bits)
|
|
||||||
)
|
|
||||||
|
|
||||||
func shortLog*(v: SomeSignedBeaconBlock): auto =
|
|
||||||
(
|
|
||||||
blck: shortLog(v.message),
|
|
||||||
signature: shortLog(v.signature)
|
|
||||||
)
|
|
||||||
|
|
||||||
template asSigned*(x: SigVerifiedSignedBeaconBlock | TrustedSignedBeaconBlock):
|
|
||||||
SignedBeaconBlock =
|
|
||||||
isomorphicCast[SignedBeaconBlock](x)
|
|
||||||
|
|
||||||
template asSigVerified*(x: SignedBeaconBlock | TrustedSignedBeaconBlock): SigVerifiedSignedBeaconBlock =
|
|
||||||
isomorphicCast[SigVerifiedSignedBeaconBlock](x)
|
|
||||||
|
|
||||||
template asTrusted*(
|
|
||||||
x: SignedBeaconBlock | SigVerifiedSignedBeaconBlock): TrustedSignedBeaconBlock =
|
|
||||||
isomorphicCast[TrustedSignedBeaconBlock](x)
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import stew/[assign2, results, base10, byteutils, endians2], presto/common,
|
||||||
libp2p/peerid, nimcrypto/utils as ncrutils,
|
libp2p/peerid, nimcrypto/utils as ncrutils,
|
||||||
serialization, json_serialization, json_serialization/std/[options, net, sets]
|
serialization, json_serialization, json_serialization/std/[options, net, sets]
|
||||||
import ".."/[eth2_ssz_serialization, forks],
|
import ".."/[eth2_ssz_serialization, forks],
|
||||||
".."/datatypes/[phase0, altair, merge],
|
".."/datatypes/[phase0, altair, bellatrix],
|
||||||
"."/[rest_types, rest_keymanager_types]
|
"."/[rest_types, rest_keymanager_types]
|
||||||
|
|
||||||
export
|
export
|
||||||
|
@ -747,10 +747,10 @@ proc readValue*(reader: var JsonReader[RestJson],
|
||||||
of BeaconBlockFork.Bellatrix:
|
of BeaconBlockFork.Bellatrix:
|
||||||
let res =
|
let res =
|
||||||
try:
|
try:
|
||||||
some(RestJson.decode(string(data.get()), merge.BeaconBlock,
|
some(RestJson.decode(string(data.get()), bellatrix.BeaconBlock,
|
||||||
requireAllFields = true))
|
requireAllFields = true))
|
||||||
except SerializationError:
|
except SerializationError:
|
||||||
none[merge.BeaconBlock]()
|
none[bellatrix.BeaconBlock]()
|
||||||
if res.isNone():
|
if res.isNone():
|
||||||
reader.raiseUnexpectedValue("Incorrect merge block format")
|
reader.raiseUnexpectedValue("Incorrect merge block format")
|
||||||
value = ForkedBeaconBlock.init(res.get())
|
value = ForkedBeaconBlock.init(res.get())
|
||||||
|
@ -833,10 +833,10 @@ proc readValue*(reader: var JsonReader[RestJson],
|
||||||
of BeaconBlockFork.Bellatrix:
|
of BeaconBlockFork.Bellatrix:
|
||||||
let res =
|
let res =
|
||||||
try:
|
try:
|
||||||
some(RestJson.decode(string(data.get()), merge.SignedBeaconBlock,
|
some(RestJson.decode(string(data.get()), bellatrix.SignedBeaconBlock,
|
||||||
requireAllFields = true))
|
requireAllFields = true))
|
||||||
except SerializationError:
|
except SerializationError:
|
||||||
none[merge.SignedBeaconBlock]()
|
none[bellatrix.SignedBeaconBlock]()
|
||||||
if res.isNone():
|
if res.isNone():
|
||||||
reader.raiseUnexpectedValue("Incorrect merge block format")
|
reader.raiseUnexpectedValue("Incorrect merge block format")
|
||||||
value = ForkedSignedBeaconBlock.init(res.get())
|
value = ForkedSignedBeaconBlock.init(res.get())
|
||||||
|
@ -925,7 +925,7 @@ proc readValue*(reader: var JsonReader[RestJson],
|
||||||
of BeaconStateFork.Bellatrix:
|
of BeaconStateFork.Bellatrix:
|
||||||
try:
|
try:
|
||||||
tmp[].mergeData.data = RestJson.decode(
|
tmp[].mergeData.data = RestJson.decode(
|
||||||
string(data.get()), merge.BeaconState, requireAllFields = true)
|
string(data.get()), bellatrix.BeaconState, requireAllFields = true)
|
||||||
except SerializationError:
|
except SerializationError:
|
||||||
reader.raiseUnexpectedValue("Incorrect altair beacon state format")
|
reader.raiseUnexpectedValue("Incorrect altair beacon state format")
|
||||||
toValue(mergeData)
|
toValue(mergeData)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# beacon_chain
|
# beacon_chain
|
||||||
# Copyright (c) 2018-2021 Status Research & Development GmbH
|
# Copyright (c) 2018-2022 Status Research & Development GmbH
|
||||||
# Licensed and distributed under either of
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
import
|
import
|
||||||
ssz_serialization,
|
ssz_serialization,
|
||||||
./ssz_codec,
|
./ssz_codec,
|
||||||
./datatypes/[phase0, altair, merge],
|
./datatypes/[phase0, altair, bellatrix],
|
||||||
./eth2_merkleization
|
./eth2_merkleization
|
||||||
|
|
||||||
export phase0, altair, ssz_codec, ssz_serialization, eth2_merkleization
|
export phase0, altair, ssz_codec, ssz_serialization, eth2_merkleization
|
||||||
|
@ -40,10 +40,10 @@ template readSszBytes*(
|
||||||
data: openArray[byte], val: var altair.TrustedSignedBeaconBlock, updateRoot = true) =
|
data: openArray[byte], val: var altair.TrustedSignedBeaconBlock, updateRoot = true) =
|
||||||
readAndUpdateRoot(data, val, updateRoot)
|
readAndUpdateRoot(data, val, updateRoot)
|
||||||
template readSszBytes*(
|
template readSszBytes*(
|
||||||
data: openArray[byte], val: var merge.SignedBeaconBlock, updateRoot = true) =
|
data: openArray[byte], val: var bellatrix.SignedBeaconBlock, updateRoot = true) =
|
||||||
readAndUpdateRoot(data, val, updateRoot)
|
readAndUpdateRoot(data, val, updateRoot)
|
||||||
template readSszBytes*(
|
template readSszBytes*(
|
||||||
data: openArray[byte], val: var merge.TrustedSignedBeaconBlock, updateRoot = true) =
|
data: openArray[byte], val: var bellatrix.TrustedSignedBeaconBlock, updateRoot = true) =
|
||||||
readAndUpdateRoot(data, val, updateRoot)
|
readAndUpdateRoot(data, val, updateRoot)
|
||||||
|
|
||||||
template readSszBytes*(
|
template readSszBytes*(
|
||||||
|
|
|
@ -12,10 +12,10 @@ import
|
||||||
chronicles,
|
chronicles,
|
||||||
../extras,
|
../extras,
|
||||||
"."/[eth2_merkleization, eth2_ssz_serialization, presets],
|
"."/[eth2_merkleization, eth2_ssz_serialization, presets],
|
||||||
./datatypes/[phase0, altair, merge]
|
./datatypes/[phase0, altair, bellatrix]
|
||||||
|
|
||||||
export
|
export
|
||||||
extras, phase0, altair, merge, eth2_merkleization, eth2_ssz_serialization,
|
extras, phase0, altair, bellatrix, eth2_merkleization, eth2_ssz_serialization,
|
||||||
presets
|
presets
|
||||||
|
|
||||||
# This file contains helpers for dealing with forks - we have two ways we can
|
# This file contains helpers for dealing with forks - we have two ways we can
|
||||||
|
@ -43,18 +43,18 @@ type
|
||||||
ForkyBeaconState* =
|
ForkyBeaconState* =
|
||||||
phase0.BeaconState |
|
phase0.BeaconState |
|
||||||
altair.BeaconState |
|
altair.BeaconState |
|
||||||
merge.BeaconState
|
bellatrix.BeaconState
|
||||||
|
|
||||||
ForkyHashedBeaconState* =
|
ForkyHashedBeaconState* =
|
||||||
phase0.HashedBeaconState |
|
phase0.HashedBeaconState |
|
||||||
altair.HashedBeaconState |
|
altair.HashedBeaconState |
|
||||||
merge.HashedBeaconState
|
bellatrix.HashedBeaconState
|
||||||
|
|
||||||
ForkedHashedBeaconState* = object
|
ForkedHashedBeaconState* = object
|
||||||
case kind*: BeaconStateFork
|
case kind*: BeaconStateFork
|
||||||
of BeaconStateFork.Phase0: phase0Data*: phase0.HashedBeaconState
|
of BeaconStateFork.Phase0: phase0Data*: phase0.HashedBeaconState
|
||||||
of BeaconStateFork.Altair: altairData*: altair.HashedBeaconState
|
of BeaconStateFork.Altair: altairData*: altair.HashedBeaconState
|
||||||
of BeaconStateFork.Bellatrix: mergeData*: merge.HashedBeaconState
|
of BeaconStateFork.Bellatrix: mergeData*: bellatrix.HashedBeaconState
|
||||||
|
|
||||||
BeaconBlockFork* {.pure.} = enum
|
BeaconBlockFork* {.pure.} = enum
|
||||||
Phase0
|
Phase0
|
||||||
|
@ -64,46 +64,46 @@ type
|
||||||
ForkyBeaconBlock* =
|
ForkyBeaconBlock* =
|
||||||
phase0.BeaconBlock |
|
phase0.BeaconBlock |
|
||||||
altair.BeaconBlock |
|
altair.BeaconBlock |
|
||||||
merge.BeaconBlock
|
bellatrix.BeaconBlock
|
||||||
|
|
||||||
ForkyTrustedBeaconBlock* =
|
ForkyTrustedBeaconBlock* =
|
||||||
phase0.TrustedBeaconBlock |
|
phase0.TrustedBeaconBlock |
|
||||||
altair.TrustedBeaconBlock |
|
altair.TrustedBeaconBlock |
|
||||||
merge.TrustedBeaconBlock
|
bellatrix.TrustedBeaconBlock
|
||||||
|
|
||||||
ForkedBeaconBlock* = object
|
ForkedBeaconBlock* = object
|
||||||
case kind*: BeaconBlockFork
|
case kind*: BeaconBlockFork
|
||||||
of BeaconBlockFork.Phase0: phase0Data*: phase0.BeaconBlock
|
of BeaconBlockFork.Phase0: phase0Data*: phase0.BeaconBlock
|
||||||
of BeaconBlockFork.Altair: altairData*: altair.BeaconBlock
|
of BeaconBlockFork.Altair: altairData*: altair.BeaconBlock
|
||||||
of BeaconBlockFork.Bellatrix: mergeData*: merge.BeaconBlock
|
of BeaconBlockFork.Bellatrix: mergeData*: bellatrix.BeaconBlock
|
||||||
|
|
||||||
ForkedTrustedBeaconBlock* = object
|
ForkedTrustedBeaconBlock* = object
|
||||||
case kind*: BeaconBlockFork
|
case kind*: BeaconBlockFork
|
||||||
of BeaconBlockFork.Phase0: phase0Data*: phase0.TrustedBeaconBlock
|
of BeaconBlockFork.Phase0: phase0Data*: phase0.TrustedBeaconBlock
|
||||||
of BeaconBlockFork.Altair: altairData*: altair.TrustedBeaconBlock
|
of BeaconBlockFork.Altair: altairData*: altair.TrustedBeaconBlock
|
||||||
of BeaconBlockFork.Bellatrix: mergeData*: merge.TrustedBeaconBlock
|
of BeaconBlockFork.Bellatrix: mergeData*: bellatrix.TrustedBeaconBlock
|
||||||
|
|
||||||
ForkySignedBeaconBlock* =
|
ForkySignedBeaconBlock* =
|
||||||
phase0.SignedBeaconBlock |
|
phase0.SignedBeaconBlock |
|
||||||
altair.SignedBeaconBlock |
|
altair.SignedBeaconBlock |
|
||||||
merge.SignedBeaconBlock
|
bellatrix.SignedBeaconBlock
|
||||||
|
|
||||||
ForkedSignedBeaconBlock* = object
|
ForkedSignedBeaconBlock* = object
|
||||||
case kind*: BeaconBlockFork
|
case kind*: BeaconBlockFork
|
||||||
of BeaconBlockFork.Phase0: phase0Data*: phase0.SignedBeaconBlock
|
of BeaconBlockFork.Phase0: phase0Data*: phase0.SignedBeaconBlock
|
||||||
of BeaconBlockFork.Altair: altairData*: altair.SignedBeaconBlock
|
of BeaconBlockFork.Altair: altairData*: altair.SignedBeaconBlock
|
||||||
of BeaconBlockFork.Bellatrix: mergeData*: merge.SignedBeaconBlock
|
of BeaconBlockFork.Bellatrix: mergeData*: bellatrix.SignedBeaconBlock
|
||||||
|
|
||||||
ForkyTrustedSignedBeaconBlock* =
|
ForkyTrustedSignedBeaconBlock* =
|
||||||
phase0.TrustedSignedBeaconBlock |
|
phase0.TrustedSignedBeaconBlock |
|
||||||
altair.TrustedSignedBeaconBlock |
|
altair.TrustedSignedBeaconBlock |
|
||||||
merge.TrustedSignedBeaconBlock
|
bellatrix.TrustedSignedBeaconBlock
|
||||||
|
|
||||||
ForkedTrustedSignedBeaconBlock* = object
|
ForkedTrustedSignedBeaconBlock* = object
|
||||||
case kind*: BeaconBlockFork
|
case kind*: BeaconBlockFork
|
||||||
of BeaconBlockFork.Phase0: phase0Data*: phase0.TrustedSignedBeaconBlock
|
of BeaconBlockFork.Phase0: phase0Data*: phase0.TrustedSignedBeaconBlock
|
||||||
of BeaconBlockFork.Altair: altairData*: altair.TrustedSignedBeaconBlock
|
of BeaconBlockFork.Altair: altairData*: altair.TrustedSignedBeaconBlock
|
||||||
of BeaconBlockFork.Bellatrix: mergeData*: merge.TrustedSignedBeaconBlock
|
of BeaconBlockFork.Bellatrix: mergeData*: bellatrix.TrustedSignedBeaconBlock
|
||||||
|
|
||||||
EpochInfoFork* {.pure.} = enum
|
EpochInfoFork* {.pure.} = enum
|
||||||
Phase0
|
Phase0
|
||||||
|
@ -128,7 +128,7 @@ template toFork*[T: phase0.BeaconState | phase0.HashedBeaconState](
|
||||||
template toFork*[T: altair.BeaconState | altair.HashedBeaconState](
|
template toFork*[T: altair.BeaconState | altair.HashedBeaconState](
|
||||||
t: type T): BeaconStateFork =
|
t: type T): BeaconStateFork =
|
||||||
BeaconStateFork.Altair
|
BeaconStateFork.Altair
|
||||||
template toFork*[T: merge.BeaconState | merge.HashedBeaconState](
|
template toFork*[T: bellatrix.BeaconState | bellatrix.HashedBeaconState](
|
||||||
t: type T): BeaconStateFork =
|
t: type T): BeaconStateFork =
|
||||||
BeaconStateFork.Bellatrix
|
BeaconStateFork.Bellatrix
|
||||||
|
|
||||||
|
@ -136,28 +136,28 @@ template init*(T: type ForkedHashedBeaconState, data: phase0.HashedBeaconState):
|
||||||
T(kind: BeaconStateFork.Phase0, phase0Data: data)
|
T(kind: BeaconStateFork.Phase0, phase0Data: data)
|
||||||
template init*(T: type ForkedHashedBeaconState, data: altair.HashedBeaconState): T =
|
template init*(T: type ForkedHashedBeaconState, data: altair.HashedBeaconState): T =
|
||||||
T(kind: BeaconStateFork.Altair, altairData: data)
|
T(kind: BeaconStateFork.Altair, altairData: data)
|
||||||
template init*(T: type ForkedHashedBeaconState, data: merge.HashedBeaconState): T =
|
template init*(T: type ForkedHashedBeaconState, data: bellatrix.HashedBeaconState): T =
|
||||||
T(kind: BeaconStateFork.Bellatrix, mergeData: data)
|
T(kind: BeaconStateFork.Bellatrix, mergeData: data)
|
||||||
|
|
||||||
template init*(T: type ForkedBeaconBlock, blck: phase0.BeaconBlock): T =
|
template init*(T: type ForkedBeaconBlock, blck: phase0.BeaconBlock): T =
|
||||||
T(kind: BeaconBlockFork.Phase0, phase0Data: blck)
|
T(kind: BeaconBlockFork.Phase0, phase0Data: blck)
|
||||||
template init*(T: type ForkedBeaconBlock, blck: altair.BeaconBlock): T =
|
template init*(T: type ForkedBeaconBlock, blck: altair.BeaconBlock): T =
|
||||||
T(kind: BeaconBlockFork.Altair, altairData: blck)
|
T(kind: BeaconBlockFork.Altair, altairData: blck)
|
||||||
template init*(T: type ForkedBeaconBlock, blck: merge.BeaconBlock): T =
|
template init*(T: type ForkedBeaconBlock, blck: bellatrix.BeaconBlock): T =
|
||||||
T(kind: BeaconBlockFork.Bellatrix, mergeData: blck)
|
T(kind: BeaconBlockFork.Bellatrix, mergeData: blck)
|
||||||
|
|
||||||
template init*(T: type ForkedTrustedBeaconBlock, blck: phase0.TrustedBeaconBlock): T =
|
template init*(T: type ForkedTrustedBeaconBlock, blck: phase0.TrustedBeaconBlock): T =
|
||||||
T(kind: BeaconBlockFork.Phase0, phase0Data: blck)
|
T(kind: BeaconBlockFork.Phase0, phase0Data: blck)
|
||||||
template init*(T: type ForkedTrustedBeaconBlock, blck: altair.TrustedBeaconBlock): T =
|
template init*(T: type ForkedTrustedBeaconBlock, blck: altair.TrustedBeaconBlock): T =
|
||||||
T(kind: BeaconBlockFork.Altair, altairData: blck)
|
T(kind: BeaconBlockFork.Altair, altairData: blck)
|
||||||
template init*(T: type ForkedTrustedBeaconBlock, blck: merge.TrustedBeaconBlock): T =
|
template init*(T: type ForkedTrustedBeaconBlock, blck: bellatrix.TrustedBeaconBlock): T =
|
||||||
T(kind: BeaconBlockFork.Bellatrix, mergeData: blck)
|
T(kind: BeaconBlockFork.Bellatrix, mergeData: blck)
|
||||||
|
|
||||||
template init*(T: type ForkedSignedBeaconBlock, blck: phase0.SignedBeaconBlock): T =
|
template init*(T: type ForkedSignedBeaconBlock, blck: phase0.SignedBeaconBlock): T =
|
||||||
T(kind: BeaconBlockFork.Phase0, phase0Data: blck)
|
T(kind: BeaconBlockFork.Phase0, phase0Data: blck)
|
||||||
template init*(T: type ForkedSignedBeaconBlock, blck: altair.SignedBeaconBlock): T =
|
template init*(T: type ForkedSignedBeaconBlock, blck: altair.SignedBeaconBlock): T =
|
||||||
T(kind: BeaconBlockFork.Altair, altairData: blck)
|
T(kind: BeaconBlockFork.Altair, altairData: blck)
|
||||||
template init*(T: type ForkedSignedBeaconBlock, blck: merge.SignedBeaconBlock): T =
|
template init*(T: type ForkedSignedBeaconBlock, blck: bellatrix.SignedBeaconBlock): T =
|
||||||
T(kind: BeaconBlockFork.Bellatrix, mergeData: blck)
|
T(kind: BeaconBlockFork.Bellatrix, mergeData: blck)
|
||||||
|
|
||||||
template init*(T: type ForkedSignedBeaconBlock, forked: ForkedBeaconBlock,
|
template init*(T: type ForkedSignedBeaconBlock, forked: ForkedBeaconBlock,
|
||||||
|
@ -175,7 +175,7 @@ template init*(T: type ForkedSignedBeaconBlock, forked: ForkedBeaconBlock,
|
||||||
signature: signature))
|
signature: signature))
|
||||||
of BeaconBlockFork.Bellatrix:
|
of BeaconBlockFork.Bellatrix:
|
||||||
T(kind: BeaconBlockFork.Bellatrix,
|
T(kind: BeaconBlockFork.Bellatrix,
|
||||||
mergeData: merge.SignedBeaconBlock(message: forked.mergeData,
|
mergeData: bellatrix.SignedBeaconBlock(message: forked.mergeData,
|
||||||
root: blockRoot,
|
root: blockRoot,
|
||||||
signature: signature))
|
signature: signature))
|
||||||
|
|
||||||
|
@ -183,7 +183,7 @@ template init*(T: type ForkedTrustedSignedBeaconBlock, blck: phase0.TrustedSigne
|
||||||
T(kind: BeaconBlockFork.Phase0, phase0Data: blck)
|
T(kind: BeaconBlockFork.Phase0, phase0Data: blck)
|
||||||
template init*(T: type ForkedTrustedSignedBeaconBlock, blck: altair.TrustedSignedBeaconBlock): T =
|
template init*(T: type ForkedTrustedSignedBeaconBlock, blck: altair.TrustedSignedBeaconBlock): T =
|
||||||
T(kind: BeaconBlockFork.Altair, altairData: blck)
|
T(kind: BeaconBlockFork.Altair, altairData: blck)
|
||||||
template init*(T: type ForkedTrustedSignedBeaconBlock, blck: merge.TrustedSignedBeaconBlock): T =
|
template init*(T: type ForkedTrustedSignedBeaconBlock, blck: bellatrix.TrustedSignedBeaconBlock): T =
|
||||||
T(kind: BeaconBlockFork.Bellatrix, mergeData: blck)
|
T(kind: BeaconBlockFork.Bellatrix, mergeData: blck)
|
||||||
|
|
||||||
template toFork*[T: phase0.TrustedSignedBeaconBlock](
|
template toFork*[T: phase0.TrustedSignedBeaconBlock](
|
||||||
|
@ -192,7 +192,7 @@ template toFork*[T: phase0.TrustedSignedBeaconBlock](
|
||||||
template toFork*[T: altair.TrustedSignedBeaconBlock](
|
template toFork*[T: altair.TrustedSignedBeaconBlock](
|
||||||
t: type T): BeaconBlockFork =
|
t: type T): BeaconBlockFork =
|
||||||
BeaconBlockFork.Altair
|
BeaconBlockFork.Altair
|
||||||
template toFork*[T: merge.TrustedSignedBeaconBlock](
|
template toFork*[T: bellatrix.TrustedSignedBeaconBlock](
|
||||||
t: type T): BeaconBlockFork =
|
t: type T): BeaconBlockFork =
|
||||||
BeaconBlockFork.Bellatrix
|
BeaconBlockFork.Bellatrix
|
||||||
|
|
||||||
|
@ -232,7 +232,7 @@ template withEpochInfo*(
|
||||||
body
|
body
|
||||||
|
|
||||||
template withEpochInfo*(
|
template withEpochInfo*(
|
||||||
state: altair.BeaconState | merge.BeaconState, x: var ForkedEpochInfo,
|
state: altair.BeaconState | bellatrix.BeaconState, x: var ForkedEpochInfo,
|
||||||
body: untyped): untyped =
|
body: untyped): untyped =
|
||||||
x.kind = EpochInfoFork.Altair
|
x.kind = EpochInfoFork.Altair
|
||||||
template info: untyped {.inject.} = x.altairData
|
template info: untyped {.inject.} = x.altairData
|
||||||
|
|
|
@ -16,7 +16,7 @@ import
|
||||||
stew/[bitops2, byteutils, endians2],
|
stew/[bitops2, byteutils, endians2],
|
||||||
chronicles,
|
chronicles,
|
||||||
# Internal
|
# Internal
|
||||||
./datatypes/[phase0, altair, merge],
|
./datatypes/[phase0, altair, bellatrix],
|
||||||
"."/[eth2_merkleization, forks, ssz_codec]
|
"."/[eth2_merkleization, forks, ssz_codec]
|
||||||
|
|
||||||
# TODO although eth2_merkleization already exports ssz_codec, *sometimes* code
|
# TODO although eth2_merkleization already exports ssz_codec, *sometimes* code
|
||||||
|
@ -514,22 +514,22 @@ func get_subtree_index*(idx: GeneralizedIndex): uint64 =
|
||||||
uint64(idx mod (type(idx)(1) shl log2trunc(idx)))
|
uint64(idx mod (type(idx)(1) shl log2trunc(idx)))
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/bellatrix/beacon-chain.md#is_merge_transition_complete
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/bellatrix/beacon-chain.md#is_merge_transition_complete
|
||||||
func is_merge_transition_complete*(state: merge.BeaconState): bool =
|
func is_merge_transition_complete*(state: bellatrix.BeaconState): bool =
|
||||||
state.latest_execution_payload_header != default(ExecutionPayloadHeader)
|
state.latest_execution_payload_header != default(ExecutionPayloadHeader)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/bellatrix/beacon-chain.md#is_merge_transition_block
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/bellatrix/beacon-chain.md#is_merge_transition_block
|
||||||
func is_merge_transition_block(
|
func is_merge_transition_block(
|
||||||
state: merge.BeaconState,
|
state: bellatrix.BeaconState,
|
||||||
body: merge.BeaconBlockBody | merge.TrustedBeaconBlockBody |
|
body: bellatrix.BeaconBlockBody | bellatrix.TrustedBeaconBlockBody |
|
||||||
merge.SigVerifiedBeaconBlockBody): bool =
|
bellatrix.SigVerifiedBeaconBlockBody): bool =
|
||||||
not is_merge_transition_complete(state) and
|
not is_merge_transition_complete(state) and
|
||||||
body.execution_payload != default(merge.ExecutionPayload)
|
body.execution_payload != default(bellatrix.ExecutionPayload)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/bellatrix/beacon-chain.md#is_execution_enabled
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/bellatrix/beacon-chain.md#is_execution_enabled
|
||||||
func is_execution_enabled*(
|
func is_execution_enabled*(
|
||||||
state: merge.BeaconState,
|
state: bellatrix.BeaconState,
|
||||||
body: merge.BeaconBlockBody | merge.TrustedBeaconBlockBody |
|
body: bellatrix.BeaconBlockBody | bellatrix.TrustedBeaconBlockBody |
|
||||||
merge.SigVerifiedBeaconBlockBody): bool =
|
bellatrix.SigVerifiedBeaconBlockBody): bool =
|
||||||
is_merge_transition_block(state, body) or is_merge_transition_complete(state)
|
is_merge_transition_block(state, body) or is_merge_transition_complete(state)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/bellatrix/beacon-chain.md#compute_timestamp_at_slot
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/bellatrix/beacon-chain.md#compute_timestamp_at_slot
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# beacon_chain
|
# beacon_chain
|
||||||
# Copyright (c) 2018-2021 Status Research & Development GmbH
|
# Copyright (c) 2018-2022 Status Research & Development GmbH
|
||||||
# Licensed and distributed under either of
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
## functions.
|
## functions.
|
||||||
|
|
||||||
import
|
import
|
||||||
./datatypes/[phase0, altair, merge], ./helpers, ./eth2_merkleization
|
./datatypes/[phase0, altair, bellatrix], ./helpers, ./eth2_merkleization
|
||||||
|
|
||||||
export phase0, altair
|
export phase0, altair
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# beacon_chain
|
# beacon_chain
|
||||||
# Copyright (c) 2018-2021 Status Research & Development GmbH
|
# Copyright (c) 2018-2022 Status Research & Development GmbH
|
||||||
# Licensed and distributed under either of
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||||
|
@ -20,7 +20,7 @@ import
|
||||||
bearssl,
|
bearssl,
|
||||||
# Internal
|
# Internal
|
||||||
"."/[helpers, beaconstate, forks, signatures],
|
"."/[helpers, beaconstate, forks, signatures],
|
||||||
"."/datatypes/[altair, merge, phase0]
|
"."/datatypes/[altair, bellatrix, phase0]
|
||||||
|
|
||||||
export results, altair, phase0, taskpools, bearssl, signatures
|
export results, altair, phase0, taskpools, bearssl, signatures
|
||||||
|
|
||||||
|
@ -387,7 +387,7 @@ proc collectSignatureSets*(
|
||||||
withState(state):
|
withState(state):
|
||||||
when stateFork >= BeaconStateFork.Altair and
|
when stateFork >= BeaconStateFork.Altair and
|
||||||
(signed_block is altair.SignedBeaconBlock or
|
(signed_block is altair.SignedBeaconBlock or
|
||||||
signed_block is merge.SignedBeaconBlock):
|
signed_block is bellatrix.SignedBeaconBlock):
|
||||||
if signed_block.message.body.sync_aggregate.sync_committee_bits.countOnes() == 0:
|
if signed_block.message.body.sync_aggregate.sync_committee_bits.countOnes() == 0:
|
||||||
if signed_block.message.body.sync_aggregate.sync_committee_signature != ValidatorSig.infinity():
|
if signed_block.message.body.sync_aggregate.sync_committee_signature != ValidatorSig.infinity():
|
||||||
return err("collectSignatureSets: empty sync aggregates need signature of point at infinity")
|
return err("collectSignatureSets: empty sync aggregates need signature of point at infinity")
|
||||||
|
|
|
@ -46,14 +46,14 @@ import
|
||||||
stew/results,
|
stew/results,
|
||||||
metrics,
|
metrics,
|
||||||
../extras,
|
../extras,
|
||||||
./datatypes/[phase0, altair, merge],
|
./datatypes/[phase0, altair, bellatrix],
|
||||||
"."/[
|
"."/[
|
||||||
beaconstate, eth2_merkleization, forks, helpers, signatures,
|
beaconstate, eth2_merkleization, forks, helpers, signatures,
|
||||||
state_transition_block, state_transition_epoch, validator]
|
state_transition_block, state_transition_epoch, validator]
|
||||||
|
|
||||||
export extras, phase0, altair
|
export extras, phase0, altair
|
||||||
|
|
||||||
type Foo = phase0.SignedBeaconBlock | altair.SignedBeaconBlock | phase0.TrustedSignedBeaconBlock | altair.TrustedSignedBeaconBlock | phase0.SigVerifiedSignedBeaconBlock | altair.SigVerifiedSignedBeaconBlock | merge.TrustedSignedBeaconBlock | merge.SigVerifiedSignedBeaconBlock | merge.SignedBeaconBlock
|
type Foo = phase0.SignedBeaconBlock | altair.SignedBeaconBlock | phase0.TrustedSignedBeaconBlock | altair.TrustedSignedBeaconBlock | phase0.SigVerifiedSignedBeaconBlock | altair.SigVerifiedSignedBeaconBlock | bellatrix.TrustedSignedBeaconBlock | bellatrix.SigVerifiedSignedBeaconBlock | bellatrix.SignedBeaconBlock
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
|
||||||
proc verify_block_signature(
|
proc verify_block_signature(
|
||||||
|
@ -78,7 +78,7 @@ proc verify_block_signature(
|
||||||
true
|
true
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
|
||||||
proc verifyStateRoot(state: ForkyBeaconState, blck: phase0.BeaconBlock or phase0.SigVerifiedBeaconBlock or altair.BeaconBlock or altair.SigVerifiedBeaconBlock or merge.BeaconBlock or merge.SigVerifiedBeaconBlock or merge.TrustedBeaconBlock): bool =
|
proc verifyStateRoot(state: ForkyBeaconState, blck: phase0.BeaconBlock or phase0.SigVerifiedBeaconBlock or altair.BeaconBlock or altair.SigVerifiedBeaconBlock or bellatrix.BeaconBlock or bellatrix.SigVerifiedBeaconBlock or bellatrix.TrustedBeaconBlock): 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)
|
||||||
if state_root != blck.state_root:
|
if state_root != blck.state_root:
|
||||||
|
@ -96,7 +96,7 @@ func verifyStateRoot(state: altair.BeaconState, blck: altair.TrustedBeaconBlock)
|
||||||
# This is inlined in state_transition(...) in spec.
|
# This is inlined in state_transition(...) in spec.
|
||||||
true
|
true
|
||||||
|
|
||||||
func verifyStateRoot(state: merge.BeaconState, blck: merge.TrustedBeaconBlock): bool =
|
func verifyStateRoot(state: bellatrix.BeaconState, blck: bellatrix.TrustedBeaconBlock): bool =
|
||||||
# This is inlined in state_transition(...) in spec.
|
# This is inlined in state_transition(...) in spec.
|
||||||
true
|
true
|
||||||
|
|
||||||
|
@ -106,11 +106,11 @@ func verifyStateRoot(state: altair.BeaconState, blck: phase0.TrustedBeaconBlock)
|
||||||
# This is inlined in state_transition(...) in spec.
|
# This is inlined in state_transition(...) in spec.
|
||||||
true
|
true
|
||||||
|
|
||||||
func verifyStateRoot(state: merge.BeaconState, blck: phase0.TrustedBeaconBlock): bool =
|
func verifyStateRoot(state: bellatrix.BeaconState, blck: phase0.TrustedBeaconBlock): bool =
|
||||||
# This is inlined in state_transition(...) in spec.
|
# This is inlined in state_transition(...) in spec.
|
||||||
true
|
true
|
||||||
|
|
||||||
func verifyStateRoot(state: merge.BeaconState, blck: altair.TrustedBeaconBlock): bool =
|
func verifyStateRoot(state: bellatrix.BeaconState, blck: altair.TrustedBeaconBlock): bool =
|
||||||
# This is inlined in state_transition(...) in spec.
|
# This is inlined in state_transition(...) in spec.
|
||||||
true
|
true
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ func noRollback*() =
|
||||||
type
|
type
|
||||||
RollbackHashedProc* = proc(state: var phase0.HashedBeaconState) {.gcsafe, raises: [Defect].}
|
RollbackHashedProc* = proc(state: var phase0.HashedBeaconState) {.gcsafe, raises: [Defect].}
|
||||||
RollbackAltairHashedProc* = proc(state: var altair.HashedBeaconState) {.gcsafe, raises: [Defect].}
|
RollbackAltairHashedProc* = proc(state: var altair.HashedBeaconState) {.gcsafe, raises: [Defect].}
|
||||||
RollbackMergeHashedProc* = proc(state: var merge.HashedBeaconState) {.gcsafe, raises: [Defect].}
|
RollbackMergeHashedProc* = proc(state: var bellatrix.HashedBeaconState) {.gcsafe, raises: [Defect].}
|
||||||
|
|
||||||
# Hashed-state transition functions
|
# Hashed-state transition functions
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
|
@ -186,8 +186,8 @@ func noRollback*(state: var phase0.HashedBeaconState) =
|
||||||
func noRollback*(state: var altair.HashedBeaconState) =
|
func noRollback*(state: var altair.HashedBeaconState) =
|
||||||
trace "Skipping rollback of broken Altair state"
|
trace "Skipping rollback of broken Altair state"
|
||||||
|
|
||||||
func noRollback*(state: var merge.HashedBeaconState) =
|
func noRollback*(state: var bellatrix.HashedBeaconState) =
|
||||||
trace "Skipping rollback of broken Merge state"
|
trace "Skipping rollback of broken Bellatrix state"
|
||||||
|
|
||||||
proc maybeUpgradeStateToAltair(
|
proc maybeUpgradeStateToAltair(
|
||||||
cfg: RuntimeConfig, state: var ForkedHashedBeaconState) =
|
cfg: RuntimeConfig, state: var ForkedHashedBeaconState) =
|
||||||
|
@ -210,7 +210,7 @@ func maybeUpgradeStateToBellatrix(
|
||||||
var newState = upgrade_to_merge(cfg, state.altairData.data)
|
var newState = upgrade_to_merge(cfg, state.altairData.data)
|
||||||
state = (ref ForkedHashedBeaconState)(
|
state = (ref ForkedHashedBeaconState)(
|
||||||
kind: BeaconStateFork.Bellatrix,
|
kind: BeaconStateFork.Bellatrix,
|
||||||
mergeData: merge.HashedBeaconState(
|
mergeData: bellatrix.HashedBeaconState(
|
||||||
root: hash_tree_root(newState[]), data: newState[]))[]
|
root: hash_tree_root(newState[]), data: newState[]))[]
|
||||||
|
|
||||||
proc maybeUpgradeState*(
|
proc maybeUpgradeState*(
|
||||||
|
@ -252,8 +252,8 @@ proc state_transition_block_aux(
|
||||||
signedBlock: phase0.SignedBeaconBlock | phase0.SigVerifiedSignedBeaconBlock |
|
signedBlock: phase0.SignedBeaconBlock | phase0.SigVerifiedSignedBeaconBlock |
|
||||||
phase0.TrustedSignedBeaconBlock | altair.SignedBeaconBlock |
|
phase0.TrustedSignedBeaconBlock | altair.SignedBeaconBlock |
|
||||||
altair.SigVerifiedSignedBeaconBlock | altair.TrustedSignedBeaconBlock |
|
altair.SigVerifiedSignedBeaconBlock | altair.TrustedSignedBeaconBlock |
|
||||||
merge.TrustedSignedBeaconBlock | merge.SigVerifiedSignedBeaconBlock |
|
bellatrix.TrustedSignedBeaconBlock | bellatrix.SigVerifiedSignedBeaconBlock |
|
||||||
merge.SignedBeaconBlock,
|
bellatrix.SignedBeaconBlock,
|
||||||
cache: var StateCache, flags: UpdateFlags): bool =
|
cache: var StateCache, flags: UpdateFlags): bool =
|
||||||
# Block updates - these happen when there's a new block being suggested
|
# Block updates - these happen when there's a new block being suggested
|
||||||
# by the block proposer. Every actor in the network will update its state
|
# by the block proposer. Every actor in the network will update its state
|
||||||
|
@ -303,8 +303,8 @@ proc state_transition_block*(
|
||||||
signedBlock: phase0.SignedBeaconBlock | phase0.SigVerifiedSignedBeaconBlock |
|
signedBlock: phase0.SignedBeaconBlock | phase0.SigVerifiedSignedBeaconBlock |
|
||||||
phase0.TrustedSignedBeaconBlock |
|
phase0.TrustedSignedBeaconBlock |
|
||||||
altair.SignedBeaconBlock | altair.SigVerifiedSignedBeaconBlock |
|
altair.SignedBeaconBlock | altair.SigVerifiedSignedBeaconBlock |
|
||||||
altair.TrustedSignedBeaconBlock | merge.TrustedSignedBeaconBlock |
|
altair.TrustedSignedBeaconBlock | bellatrix.TrustedSignedBeaconBlock |
|
||||||
merge.SigVerifiedSignedBeaconBlock | merge.SignedBeaconBlock,
|
bellatrix.SigVerifiedSignedBeaconBlock | bellatrix.SignedBeaconBlock,
|
||||||
cache: var StateCache, flags: UpdateFlags,
|
cache: var StateCache, flags: UpdateFlags,
|
||||||
rollback: RollbackForkedHashedProc): bool =
|
rollback: RollbackForkedHashedProc): bool =
|
||||||
## `rollback` is called if the transition fails and the given state has been
|
## `rollback` is called if the transition fails and the given state has been
|
||||||
|
@ -331,8 +331,8 @@ proc state_transition*(
|
||||||
state: var ForkedHashedBeaconState,
|
state: var ForkedHashedBeaconState,
|
||||||
signedBlock: phase0.SignedBeaconBlock | phase0.SigVerifiedSignedBeaconBlock |
|
signedBlock: phase0.SignedBeaconBlock | phase0.SigVerifiedSignedBeaconBlock |
|
||||||
phase0.TrustedSignedBeaconBlock | altair.SignedBeaconBlock |
|
phase0.TrustedSignedBeaconBlock | altair.SignedBeaconBlock |
|
||||||
altair.TrustedSignedBeaconBlock | merge.TrustedSignedBeaconBlock |
|
altair.TrustedSignedBeaconBlock | bellatrix.TrustedSignedBeaconBlock |
|
||||||
merge.SignedBeaconBlock,
|
bellatrix.SignedBeaconBlock,
|
||||||
cache: var StateCache, info: var ForkedEpochInfo, flags: UpdateFlags,
|
cache: var StateCache, info: var ForkedEpochInfo, flags: UpdateFlags,
|
||||||
rollback: RollbackForkedHashedProc): bool =
|
rollback: RollbackForkedHashedProc): bool =
|
||||||
## Apply a block to the state, advancing the slot counter as necessary. The
|
## Apply a block to the state, advancing the slot counter as necessary. The
|
||||||
|
@ -499,7 +499,7 @@ proc makeBeaconBlock*(
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.3/specs/merge/validator.md#block-proposal
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.3/specs/merge/validator.md#block-proposal
|
||||||
template partialBeaconBlock(
|
template partialBeaconBlock(
|
||||||
cfg: RuntimeConfig,
|
cfg: RuntimeConfig,
|
||||||
state: var merge.HashedBeaconState,
|
state: var bellatrix.HashedBeaconState,
|
||||||
proposer_index: ValidatorIndex,
|
proposer_index: ValidatorIndex,
|
||||||
randao_reveal: ValidatorSig,
|
randao_reveal: ValidatorSig,
|
||||||
eth1_data: Eth1Data,
|
eth1_data: Eth1Data,
|
||||||
|
@ -508,12 +508,12 @@ template partialBeaconBlock(
|
||||||
deposits: seq[Deposit],
|
deposits: seq[Deposit],
|
||||||
exits: BeaconBlockExits,
|
exits: BeaconBlockExits,
|
||||||
sync_aggregate: SyncAggregate,
|
sync_aggregate: SyncAggregate,
|
||||||
executionPayload: ExecutionPayload): merge.BeaconBlock =
|
executionPayload: ExecutionPayload): bellatrix.BeaconBlock =
|
||||||
merge.BeaconBlock(
|
bellatrix.BeaconBlock(
|
||||||
slot: state.data.slot,
|
slot: state.data.slot,
|
||||||
proposer_index: proposer_index.uint64,
|
proposer_index: proposer_index.uint64,
|
||||||
parent_root: state.latest_block_root(),
|
parent_root: state.latest_block_root(),
|
||||||
body: merge.BeaconBlockBody(
|
body: bellatrix.BeaconBlockBody(
|
||||||
randao_reveal: randao_reveal,
|
randao_reveal: randao_reveal,
|
||||||
eth1_data: eth1data,
|
eth1_data: eth1data,
|
||||||
graffiti: graffiti,
|
graffiti: graffiti,
|
||||||
|
@ -527,7 +527,7 @@ template partialBeaconBlock(
|
||||||
|
|
||||||
proc makeBeaconBlock*(
|
proc makeBeaconBlock*(
|
||||||
cfg: RuntimeConfig,
|
cfg: RuntimeConfig,
|
||||||
state: var merge.HashedBeaconState,
|
state: var bellatrix.HashedBeaconState,
|
||||||
proposer_index: ValidatorIndex,
|
proposer_index: ValidatorIndex,
|
||||||
randao_reveal: ValidatorSig,
|
randao_reveal: ValidatorSig,
|
||||||
eth1_data: Eth1Data,
|
eth1_data: Eth1Data,
|
||||||
|
@ -538,7 +538,7 @@ proc makeBeaconBlock*(
|
||||||
sync_aggregate: SyncAggregate,
|
sync_aggregate: SyncAggregate,
|
||||||
executionPayload: ExecutionPayload,
|
executionPayload: ExecutionPayload,
|
||||||
rollback: RollbackMergeHashedProc,
|
rollback: RollbackMergeHashedProc,
|
||||||
cache: var StateCache): Result[merge.BeaconBlock, string] =
|
cache: var StateCache): Result[bellatrix.BeaconBlock, string] =
|
||||||
## Create a block for the given state. The latest block applied to it will
|
## Create a block for the given state. The latest block applied to it will
|
||||||
## be used for the parent_root value, and the slot will be take from
|
## be used for the parent_root value, and the slot will be take from
|
||||||
## state.slot meaning process_slots must be called up to the slot for which
|
## state.slot meaning process_slots must be called up to the slot for which
|
||||||
|
|
|
@ -23,7 +23,7 @@ import
|
||||||
std/[algorithm, options, sequtils, sets, tables],
|
std/[algorithm, options, sequtils, sets, tables],
|
||||||
chronicles, metrics,
|
chronicles, metrics,
|
||||||
../extras,
|
../extras,
|
||||||
./datatypes/[phase0, altair, merge],
|
./datatypes/[phase0, altair, bellatrix],
|
||||||
"."/[beaconstate, eth2_merkleization, helpers, validator, signatures]
|
"."/[beaconstate, eth2_merkleization, helpers, validator, signatures]
|
||||||
|
|
||||||
export extras, phase0, altair
|
export extras, phase0, altair
|
||||||
|
@ -304,7 +304,7 @@ proc process_deposit*(cfg: RuntimeConfig,
|
||||||
static: doAssert state.balances.maxLen == state.validators.maxLen
|
static: doAssert state.balances.maxLen == state.validators.maxLen
|
||||||
raiseAssert "adding validator succeeded, so should balances"
|
raiseAssert "adding validator succeeded, so should balances"
|
||||||
|
|
||||||
when state is altair.BeaconState or state is merge.BeaconState:
|
when state is altair.BeaconState or state is bellatrix.BeaconState:
|
||||||
if not state.previous_epoch_participation.add(ParticipationFlags(0)):
|
if not state.previous_epoch_participation.add(ParticipationFlags(0)):
|
||||||
return err("process_deposit: too many validators (previous_epoch_participation)")
|
return err("process_deposit: too many validators (previous_epoch_participation)")
|
||||||
if not state.current_epoch_participation.add(ParticipationFlags(0)):
|
if not state.current_epoch_participation.add(ParticipationFlags(0)):
|
||||||
|
@ -427,7 +427,7 @@ proc process_operations(cfg: RuntimeConfig,
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.0-alpha.6/specs/altair/beacon-chain.md#sync-committee-processing
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.0-alpha.6/specs/altair/beacon-chain.md#sync-committee-processing
|
||||||
proc process_sync_aggregate*(
|
proc process_sync_aggregate*(
|
||||||
state: var (altair.BeaconState | merge.BeaconState),
|
state: var (altair.BeaconState | bellatrix.BeaconState),
|
||||||
aggregate: SomeSyncAggregate, total_active_balance: Gwei,
|
aggregate: SomeSyncAggregate, total_active_balance: Gwei,
|
||||||
cache: var StateCache):
|
cache: var StateCache):
|
||||||
Result[void, cstring] =
|
Result[void, cstring] =
|
||||||
|
@ -490,7 +490,7 @@ proc process_sync_aggregate*(
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/bellatrix/beacon-chain.md#process_execution_payload
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/bellatrix/beacon-chain.md#process_execution_payload
|
||||||
proc process_execution_payload*(
|
proc process_execution_payload*(
|
||||||
state: var merge.BeaconState, payload: ExecutionPayload,
|
state: var bellatrix.BeaconState, payload: ExecutionPayload,
|
||||||
execute_payload: ExecutePayload): Result[void, cstring] =
|
execute_payload: ExecutePayload): Result[void, cstring] =
|
||||||
## Verify consistency of the parent hash with respect to the previous
|
## Verify consistency of the parent hash with respect to the previous
|
||||||
## execution payload header
|
## execution payload header
|
||||||
|
@ -558,7 +558,7 @@ proc process_block*(
|
||||||
|
|
||||||
proc process_block*(
|
proc process_block*(
|
||||||
cfg: RuntimeConfig,
|
cfg: RuntimeConfig,
|
||||||
state: var merge.BeaconState, blck: SomePhase0Block, flags: UpdateFlags,
|
state: var bellatrix.BeaconState, blck: SomePhase0Block, flags: UpdateFlags,
|
||||||
cache: var StateCache): Result[void, cstring] =
|
cache: var StateCache): Result[void, cstring] =
|
||||||
err("process_block: Merge state with Phase 0 block")
|
err("process_block: Merge state with Phase 0 block")
|
||||||
|
|
||||||
|
@ -593,10 +593,10 @@ proc process_block*(
|
||||||
|
|
||||||
# TODO workaround for https://github.com/nim-lang/Nim/issues/18095
|
# TODO workaround for https://github.com/nim-lang/Nim/issues/18095
|
||||||
type SomeMergeBlock =
|
type SomeMergeBlock =
|
||||||
merge.BeaconBlock | merge.SigVerifiedBeaconBlock | merge.TrustedBeaconBlock
|
bellatrix.BeaconBlock | bellatrix.SigVerifiedBeaconBlock | bellatrix.TrustedBeaconBlock
|
||||||
proc process_block*(
|
proc process_block*(
|
||||||
cfg: RuntimeConfig,
|
cfg: RuntimeConfig,
|
||||||
state: var merge.BeaconState, blck: SomeMergeBlock, flags: UpdateFlags,
|
state: var bellatrix.BeaconState, blck: SomeMergeBlock, flags: UpdateFlags,
|
||||||
cache: var StateCache): Result[void, cstring]=
|
cache: var StateCache): Result[void, cstring]=
|
||||||
## When there's a new block, we need to verify that the block is sane and
|
## When there's a new block, we need to verify that the block is sane and
|
||||||
## update the state accordingly - the state is left in an unknown state when
|
## update the state accordingly - the state is left in an unknown state when
|
||||||
|
@ -642,6 +642,6 @@ proc process_block*(
|
||||||
|
|
||||||
proc process_block*(
|
proc process_block*(
|
||||||
cfg: RuntimeConfig,
|
cfg: RuntimeConfig,
|
||||||
state: var merge.BeaconState, blck: SomeAltairBlock, flags: UpdateFlags,
|
state: var bellatrix.BeaconState, blck: SomeAltairBlock, flags: UpdateFlags,
|
||||||
cache: var StateCache): Result[void, cstring]=
|
cache: var StateCache): Result[void, cstring]=
|
||||||
err("process_block: Merge state with Altair block")
|
err("process_block: Merge state with Altair block")
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# beacon_chain
|
# beacon_chain
|
||||||
# Copyright (c) 2018-2021 Status Research & Development GmbH
|
# Copyright (c) 2018-2022 Status Research & Development GmbH
|
||||||
# Licensed and distributed under either of
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||||
|
@ -24,7 +24,7 @@ import
|
||||||
std/[algorithm, math],
|
std/[algorithm, math],
|
||||||
stew/bitops2, chronicles,
|
stew/bitops2, chronicles,
|
||||||
../extras,
|
../extras,
|
||||||
./datatypes/[phase0, altair, merge],
|
./datatypes/[phase0, altair, bellatrix],
|
||||||
"."/[beaconstate, eth2_merkleization, helpers, validator]
|
"."/[beaconstate, eth2_merkleization, helpers, validator]
|
||||||
|
|
||||||
export extras, phase0, altair
|
export extras, phase0, altair
|
||||||
|
@ -169,7 +169,7 @@ func is_eligible_validator*(validator: ParticipationInfo): bool =
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#get_unslashed_participating_indices
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#get_unslashed_participating_indices
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_total_balance
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_total_balance
|
||||||
func get_unslashed_participating_balances*(state: altair.BeaconState | merge.BeaconState):
|
func get_unslashed_participating_balances*(state: altair.BeaconState | bellatrix.BeaconState):
|
||||||
UnslashedParticipatingBalances =
|
UnslashedParticipatingBalances =
|
||||||
let
|
let
|
||||||
previous_epoch = get_previous_epoch(state)
|
previous_epoch = get_previous_epoch(state)
|
||||||
|
@ -220,7 +220,7 @@ func get_unslashed_participating_balances*(state: altair.BeaconState | merge.Bea
|
||||||
res
|
res
|
||||||
|
|
||||||
func is_unslashed_participating_index(
|
func is_unslashed_participating_index(
|
||||||
state: altair.BeaconState | merge.BeaconState, flag_index: int, epoch: Epoch,
|
state: altair.BeaconState | bellatrix.BeaconState, flag_index: int, epoch: Epoch,
|
||||||
validator_index: ValidatorIndex): bool =
|
validator_index: ValidatorIndex): bool =
|
||||||
doAssert epoch in [get_previous_epoch(state), get_current_epoch(state)]
|
doAssert epoch in [get_previous_epoch(state), get_current_epoch(state)]
|
||||||
# TODO hoist this conditional
|
# TODO hoist this conditional
|
||||||
|
@ -335,7 +335,7 @@ proc process_justification_and_finalization*(state: var phase0.BeaconState,
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#justification-and-finalization
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#justification-and-finalization
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#justification-and-finalization
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#justification-and-finalization
|
||||||
# TODO merge these things -- effectively, the phase0 process_justification_and_finalization is mostly a stub in this world
|
# TODO merge these things -- effectively, the phase0 process_justification_and_finalization is mostly a stub in this world
|
||||||
proc weigh_justification_and_finalization(state: var (altair.BeaconState | merge.BeaconState),
|
proc weigh_justification_and_finalization(state: var (altair.BeaconState | bellatrix.BeaconState),
|
||||||
total_active_balance: Gwei,
|
total_active_balance: Gwei,
|
||||||
previous_epoch_target_balance: Gwei,
|
previous_epoch_target_balance: Gwei,
|
||||||
current_epoch_target_balance: Gwei,
|
current_epoch_target_balance: Gwei,
|
||||||
|
@ -429,7 +429,7 @@ proc weigh_justification_and_finalization(state: var (altair.BeaconState | merge
|
||||||
current_epoch = current_epoch,
|
current_epoch = current_epoch,
|
||||||
checkpoint = shortLog(state.finalized_checkpoint)
|
checkpoint = shortLog(state.finalized_checkpoint)
|
||||||
|
|
||||||
proc process_justification_and_finalization*(state: var (altair.BeaconState | merge.BeaconState),
|
proc process_justification_and_finalization*(state: var (altair.BeaconState | bellatrix.BeaconState),
|
||||||
balances: UnslashedParticipatingBalances,
|
balances: UnslashedParticipatingBalances,
|
||||||
flags: UpdateFlags = {}) =
|
flags: UpdateFlags = {}) =
|
||||||
# Initial FFG checkpoint values have a `0x00` stub for `root`.
|
# Initial FFG checkpoint values have a `0x00` stub for `root`.
|
||||||
|
@ -467,7 +467,7 @@ func get_finality_delay(state: ForkyBeaconState): uint64 =
|
||||||
get_previous_epoch(state) - state.finalized_checkpoint.epoch
|
get_previous_epoch(state) - state.finalized_checkpoint.epoch
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#rewards-and-penalties-1
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#rewards-and-penalties-1
|
||||||
func is_in_inactivity_leak(state: altair.BeaconState | merge.BeaconState): bool =
|
func is_in_inactivity_leak(state: altair.BeaconState | bellatrix.BeaconState): bool =
|
||||||
# TODO remove this, see above
|
# TODO remove this, see above
|
||||||
get_finality_delay(state) > MIN_EPOCHS_TO_INACTIVITY_PENALTY
|
get_finality_delay(state) > MIN_EPOCHS_TO_INACTIVITY_PENALTY
|
||||||
|
|
||||||
|
@ -615,7 +615,7 @@ func get_attestation_deltas(state: phase0.BeaconState, info: var phase0.EpochInf
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#get_base_reward
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#get_base_reward
|
||||||
func get_base_reward_increment(
|
func get_base_reward_increment(
|
||||||
state: altair.BeaconState | merge.BeaconState, index: ValidatorIndex,
|
state: altair.BeaconState | bellatrix.BeaconState, index: ValidatorIndex,
|
||||||
base_reward_per_increment: Gwei): Gwei =
|
base_reward_per_increment: Gwei): Gwei =
|
||||||
## Return the base reward for the validator defined by ``index`` with respect
|
## Return the base reward for the validator defined by ``index`` with respect
|
||||||
## to the current ``state``.
|
## to the current ``state``.
|
||||||
|
@ -625,7 +625,7 @@ func get_base_reward_increment(
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#get_flag_index_deltas
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#get_flag_index_deltas
|
||||||
iterator get_flag_index_deltas*(
|
iterator get_flag_index_deltas*(
|
||||||
state: altair.BeaconState | merge.BeaconState, flag_index: int,
|
state: altair.BeaconState | bellatrix.BeaconState, flag_index: int,
|
||||||
base_reward_per_increment: Gwei,
|
base_reward_per_increment: Gwei,
|
||||||
info: var altair.EpochInfo):
|
info: var altair.EpochInfo):
|
||||||
(ValidatorIndex, RewardDelta) =
|
(ValidatorIndex, RewardDelta) =
|
||||||
|
@ -699,7 +699,7 @@ iterator get_inactivity_penalty_deltas*(
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.4/specs/merge/beacon-chain.md#modified-get_inactivity_penalty_deltas
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.4/specs/merge/beacon-chain.md#modified-get_inactivity_penalty_deltas
|
||||||
iterator get_inactivity_penalty_deltas*(
|
iterator get_inactivity_penalty_deltas*(
|
||||||
cfg: RuntimeConfig, state: merge.BeaconState, info: altair.EpochInfo):
|
cfg: RuntimeConfig, state: bellatrix.BeaconState, info: altair.EpochInfo):
|
||||||
(ValidatorIndex, Gwei) =
|
(ValidatorIndex, Gwei) =
|
||||||
## Return the inactivity penalty deltas by considering timely target
|
## Return the inactivity penalty deltas by considering timely target
|
||||||
## participation flags and inactivity scores.
|
## participation flags and inactivity scores.
|
||||||
|
@ -745,7 +745,7 @@ func process_rewards_and_penalties(
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#rewards-and-penalties
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#rewards-and-penalties
|
||||||
func process_rewards_and_penalties(
|
func process_rewards_and_penalties(
|
||||||
cfg: RuntimeConfig, state: var (altair.BeaconState | merge.BeaconState),
|
cfg: RuntimeConfig, state: var (altair.BeaconState | bellatrix.BeaconState),
|
||||||
info: var altair.EpochInfo)
|
info: var altair.EpochInfo)
|
||||||
=
|
=
|
||||||
if get_current_epoch(state) == GENESIS_EPOCH:
|
if get_current_epoch(state) == GENESIS_EPOCH:
|
||||||
|
@ -840,7 +840,7 @@ func process_slashings*(state: var ForkyBeaconState, total_balance: Gwei) =
|
||||||
PROPORTIONAL_SLASHING_MULTIPLIER
|
PROPORTIONAL_SLASHING_MULTIPLIER
|
||||||
elif state is altair.BeaconState:
|
elif state is altair.BeaconState:
|
||||||
PROPORTIONAL_SLASHING_MULTIPLIER_ALTAIR
|
PROPORTIONAL_SLASHING_MULTIPLIER_ALTAIR
|
||||||
elif state is merge.BeaconState:
|
elif state is bellatrix.BeaconState:
|
||||||
PROPORTIONAL_SLASHING_MULTIPLIER_MERGE
|
PROPORTIONAL_SLASHING_MULTIPLIER_MERGE
|
||||||
else:
|
else:
|
||||||
raiseAssert "process_slashings: incorrect BeaconState type")
|
raiseAssert "process_slashings: incorrect BeaconState type")
|
||||||
|
@ -928,7 +928,7 @@ func process_participation_record_updates*(state: var phase0.BeaconState) =
|
||||||
swap(state.previous_epoch_attestations, state.current_epoch_attestations)
|
swap(state.previous_epoch_attestations, state.current_epoch_attestations)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#participation-flags-updates
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#participation-flags-updates
|
||||||
func process_participation_flag_updates*(state: var (altair.BeaconState | merge.BeaconState)) =
|
func process_participation_flag_updates*(state: var (altair.BeaconState | bellatrix.BeaconState)) =
|
||||||
state.previous_epoch_participation = state.current_epoch_participation
|
state.previous_epoch_participation = state.current_epoch_participation
|
||||||
|
|
||||||
const zero = 0.ParticipationFlags
|
const zero = 0.ParticipationFlags
|
||||||
|
@ -942,7 +942,7 @@ func process_participation_flag_updates*(state: var (altair.BeaconState | merge.
|
||||||
state.current_epoch_participation.resetCache()
|
state.current_epoch_participation.resetCache()
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#sync-committee-updates
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#sync-committee-updates
|
||||||
proc process_sync_committee_updates*(state: var (altair.BeaconState | merge.BeaconState)) =
|
proc process_sync_committee_updates*(state: var (altair.BeaconState | bellatrix.BeaconState)) =
|
||||||
let next_epoch = get_current_epoch(state) + 1
|
let next_epoch = get_current_epoch(state) + 1
|
||||||
if next_epoch mod EPOCHS_PER_SYNC_COMMITTEE_PERIOD == 0:
|
if next_epoch mod EPOCHS_PER_SYNC_COMMITTEE_PERIOD == 0:
|
||||||
state.current_sync_committee = state.next_sync_committee
|
state.current_sync_committee = state.next_sync_committee
|
||||||
|
@ -950,7 +950,7 @@ proc process_sync_committee_updates*(state: var (altair.BeaconState | merge.Beac
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#inactivity-scores
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#inactivity-scores
|
||||||
func process_inactivity_updates*(
|
func process_inactivity_updates*(
|
||||||
cfg: RuntimeConfig, state: var (altair.BeaconState | merge.BeaconState),
|
cfg: RuntimeConfig, state: var (altair.BeaconState | bellatrix.BeaconState),
|
||||||
info: altair.EpochInfo) =
|
info: altair.EpochInfo) =
|
||||||
# Score updates based on previous epoch participation, skip genesis epoch
|
# Score updates based on previous epoch participation, skip genesis epoch
|
||||||
if get_current_epoch(state) == GENESIS_EPOCH:
|
if get_current_epoch(state) == GENESIS_EPOCH:
|
||||||
|
@ -1016,7 +1016,7 @@ proc process_epoch*(
|
||||||
|
|
||||||
func init*(
|
func init*(
|
||||||
info: var altair.EpochInfo,
|
info: var altair.EpochInfo,
|
||||||
state: altair.BeaconState | merge.BeaconState) =
|
state: altair.BeaconState | bellatrix.BeaconState) =
|
||||||
# init participation, overwriting the full structure
|
# init participation, overwriting the full structure
|
||||||
info.balances = get_unslashed_participating_balances(state)
|
info.balances = get_unslashed_participating_balances(state)
|
||||||
info.validators.setLen(state.validators.len())
|
info.validators.setLen(state.validators.len())
|
||||||
|
@ -1032,12 +1032,12 @@ func init*(
|
||||||
)
|
)
|
||||||
|
|
||||||
func init*(
|
func init*(
|
||||||
T: type altair.EpochInfo, state: altair.BeaconState | merge.BeaconState): T =
|
T: type altair.EpochInfo, state: altair.BeaconState | bellatrix.BeaconState): T =
|
||||||
init(result, state)
|
init(result, state)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#epoch-processing
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#epoch-processing
|
||||||
proc process_epoch*(
|
proc process_epoch*(
|
||||||
cfg: RuntimeConfig, state: var (altair.BeaconState | merge.BeaconState),
|
cfg: RuntimeConfig, state: var (altair.BeaconState | bellatrix.BeaconState),
|
||||||
flags: UpdateFlags, cache: var StateCache, info: var altair.EpochInfo)
|
flags: UpdateFlags, cache: var StateCache, info: var altair.EpochInfo)
|
||||||
=
|
=
|
||||||
let currentEpoch = get_current_epoch(state)
|
let currentEpoch = get_current_epoch(state)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Copyright (c) 2018-2021 Status Research & Development GmbH
|
# Copyright (c) 2018-2022 Status Research & Development GmbH
|
||||||
# Licensed and distributed under either of
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||||
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[options, math, tables],
|
std/[options, math, tables],
|
||||||
./datatypes/[phase0, altair, merge],
|
./datatypes/[phase0, altair, bellatrix],
|
||||||
./helpers
|
./helpers
|
||||||
|
|
||||||
export helpers
|
export helpers
|
||||||
|
|
|
@ -9,7 +9,7 @@ import
|
||||||
# Beacon chain internals
|
# Beacon chain internals
|
||||||
../../beacon_chain/spec/
|
../../beacon_chain/spec/
|
||||||
[forks, helpers, signatures, state_transition, validator],
|
[forks, helpers, signatures, state_transition, validator],
|
||||||
../../beacon_chain/spec/datatypes/[phase0, altair, merge],
|
../../beacon_chain/spec/datatypes/[phase0, altair, bellatrix],
|
||||||
# Test utilities
|
# Test utilities
|
||||||
../testblockutil
|
../testblockutil
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ func sign_block(state: ForkyBeaconState, blck: var ForkySignedBeaconBlock) =
|
||||||
privkey).toValidatorSig()
|
privkey).toValidatorSig()
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py#L1-L31
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py#L1-L31
|
||||||
func build_empty_execution_payload(state: merge.BeaconState): ExecutionPayload =
|
func build_empty_execution_payload(state: bellatrix.BeaconState): ExecutionPayload =
|
||||||
## Assuming a pre-state of the same slot, build a valid ExecutionPayload
|
## Assuming a pre-state of the same slot, build a valid ExecutionPayload
|
||||||
## without any transactions.
|
## without any transactions.
|
||||||
let
|
let
|
||||||
|
|
|
@ -11,7 +11,7 @@ import
|
||||||
options, stew/endians2,
|
options, stew/endians2,
|
||||||
../beacon_chain/consensus_object_pools/sync_committee_msg_pool,
|
../beacon_chain/consensus_object_pools/sync_committee_msg_pool,
|
||||||
../beacon_chain/validators/validator_pool,
|
../beacon_chain/validators/validator_pool,
|
||||||
../beacon_chain/spec/datatypes/merge,
|
../beacon_chain/spec/datatypes/bellatrix,
|
||||||
../beacon_chain/spec/[
|
../beacon_chain/spec/[
|
||||||
beaconstate, helpers, keystore, signatures, state_transition, validator]
|
beaconstate, helpers, keystore, signatures, state_transition, validator]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue