From 98f7ec9ee37470b66ad6473fa5696eb61a7c17f4 Mon Sep 17 00:00:00 2001 From: tersec Date: Fri, 22 Mar 2024 09:19:46 +0200 Subject: [PATCH] rm beacon_chain/spec/datatypes/phase0.nim --- beacon_chain/spec/datatypes/phase0.nim | 191 ------------------ beacon_chain/spec/eth2_merkleization.nim | 2 - beacon_chain/spec/eth2_ssz_serialization.nim | 10 +- beacon_chain/spec/forks.nim | 3 +- beacon_chain/validators/beacon_validators.nim | 5 +- beacon_chain/validators/message_router.nim | 2 - 6 files changed, 4 insertions(+), 209 deletions(-) delete mode 100644 beacon_chain/spec/datatypes/phase0.nim diff --git a/beacon_chain/spec/datatypes/phase0.nim b/beacon_chain/spec/datatypes/phase0.nim deleted file mode 100644 index d405d265d..000000000 --- a/beacon_chain/spec/datatypes/phase0.nim +++ /dev/null @@ -1,191 +0,0 @@ -{.push raises: [].} - -# Types specific to phase0 (i.e. known to have changed across hard forks) - see -# `base` for types and guidelines common across forks - -# TODO Careful, not nil analysis is broken / incomplete and the semantics will -# likely change in future versions of the language: -# https://github.com/nim-lang/RFCs/issues/250 -{.experimental: "notnil".} - -import - ./base - -export base - -type - # https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.6/specs/phase0/beacon-chain.md#beaconstate - BeaconState* = object - # Versioning - genesis_time*: uint64 - genesis_validators_root*: Eth2Digest - slot*: Slot - fork*: Fork - - # History - latest_block_header*: BeaconBlockHeader - ## `latest_block_header.state_root == ZERO_HASH` temporarily - - block_roots*: HashArray[Limit SLOTS_PER_HISTORICAL_ROOT, Eth2Digest] - ## Needed to process attestations, older to newer - - state_roots*: HashArray[Limit SLOTS_PER_HISTORICAL_ROOT, Eth2Digest] - historical_roots*: HashList[Eth2Digest, Limit HISTORICAL_ROOTS_LIMIT] - - # Eth1 - eth1_data*: Eth1Data - eth1_data_votes*: - HashList[Eth1Data, Limit(EPOCHS_PER_ETH1_VOTING_PERIOD * SLOTS_PER_EPOCH)] - eth1_deposit_index*: uint64 - - # Registry - validators*: HashList[Validator, Limit VALIDATOR_REGISTRY_LIMIT] - balances*: HashList[Gwei, Limit VALIDATOR_REGISTRY_LIMIT] - - # Randomness - randao_mixes*: HashArray[Limit EPOCHS_PER_HISTORICAL_VECTOR, Eth2Digest] - - # Slashings - slashings*: HashArray[Limit EPOCHS_PER_SLASHINGS_VECTOR, Gwei] - ## Per-epoch sums of slashed effective balances - - # Attestations - previous_epoch_attestations*: - HashList[PendingAttestation, Limit(MAX_ATTESTATIONS * SLOTS_PER_EPOCH)] - current_epoch_attestations*: - HashList[PendingAttestation, Limit(MAX_ATTESTATIONS * SLOTS_PER_EPOCH)] - - # Finality - justification_bits*: JustificationBits - ## Bit set for every recent justified epoch - - previous_justified_checkpoint*: Checkpoint - ## Previous epoch snapshot - - current_justified_checkpoint*: Checkpoint - finalized_checkpoint*: Checkpoint - - # https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.6/specs/phase0/beacon-chain.md#get_total_balance - TotalBalances* = object - # The total effective balance of all active validators during the _current_ - # epoch. - current_epoch_raw*: Gwei - # The total effective balance of all active validators during the _previous_ - # epoch. - previous_epoch_raw*: Gwei - # The total effective balance of all validators who attested during the - # _current_ epoch. - current_epoch_attesters_raw*: Gwei - # The total effective balance of all validators who attested during the - # _current_ epoch and agreed with the state about the beacon block at the - # first slot of the _current_ epoch. - current_epoch_target_attesters_raw*: Gwei - # The total effective balance of all validators who attested during the - # _previous_ epoch. - previous_epoch_attesters_raw*: Gwei - # The total effective balance of all validators who attested during the - # _previous_ epoch and agreed with the state about the beacon block at the - # first slot of the _previous_ epoch. - previous_epoch_target_attesters_raw*: Gwei - # The total effective balance of all validators who attested during the - # _previous_ epoch and agreed with the state about the beacon block at the - # time of attestation. - previous_epoch_head_attesters_raw*: Gwei - - # TODO Careful, not nil analysis is broken / incomplete and the semantics will - # likely change in future versions of the language: - # https://github.com/nim-lang/RFCs/issues/250 - BeaconStateRef* = ref BeaconState not nil - NilableBeaconStateRef* = ref BeaconState - - # TODO: There should be only a single generic HashedBeaconState definition - HashedBeaconState* = object - data*: BeaconState - root*: Eth2Digest # hash_tree_root(data) - - # https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.6/specs/phase0/beacon-chain.md#beaconblock - BeaconBlock* = object - ## For each slot, a proposer is chosen from the validator pool to propose - ## a new block. Once the block as been proposed, it is transmitted to - ## validators that will have a chance to vote on it through attestations. - ## Each block collects attestations, or votes, on past blocks, thus a chain - ## is formed. - - slot*: Slot - proposer_index*: uint64 # `ValidatorIndex` after validation - - parent_root*: Eth2Digest - ## Root hash of the previous block - - state_root*: Eth2Digest - ## The state root, _after_ this block has been processed - - body*: BeaconBlockBody - - # https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.6/specs/phase0/beacon-chain.md#beaconblockbody - BeaconBlockBody* = object - randao_reveal*: ValidatorSig - eth1_data*: Eth1Data - ## Eth1 data vote - - graffiti*: GraffitiBytes - ## Arbitrary data - - # Operations - proposer_slashings*: List[ProposerSlashing, Limit MAX_PROPOSER_SLASHINGS] - attester_slashings*: List[AttesterSlashing, Limit MAX_ATTESTER_SLASHINGS] - attestations*: List[Attestation, Limit MAX_ATTESTATIONS] - deposits*: List[Deposit, Limit MAX_DEPOSITS] - voluntary_exits*: List[SignedVoluntaryExit, Limit MAX_VOLUNTARY_EXITS] - - # https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.6/specs/phase0/beacon-chain.md#signedbeaconblock - SignedBeaconBlock* = object - message*: BeaconBlock - signature*: ValidatorSig - - root* {.dontSerialize.}: Eth2Digest # cached root of signed beacon block - - SomeSignedBeaconBlock* = SignedBeaconBlock - SomeBeaconBlock* = BeaconBlock - SomeBeaconBlockBody* = BeaconBlockBody - - EpochInfo* = object - ## Information about the outcome of epoch processing - validators*: seq[RewardStatus] - balances*: TotalBalances - -func clear*(info: var EpochInfo) = - info.validators.setLen(0) - info.balances = TotalBalances() - -func shortLog*(v: SomeBeaconBlock): auto = - ( - slot: shortLog(v.slot), - proposer_index: v.proposer_index, - parent_root: shortLog(v.parent_root), - state_root: shortLog(v.state_root), - eth1data: v.body.eth1_data, - graffiti: $v.body.graffiti, - proposer_slashings_len: v.body.proposer_slashings.len(), - attester_slashings_len: v.body.attester_slashings.len(), - attestations_len: v.body.attestations.len(), - deposits_len: v.body.deposits.len(), - voluntary_exits_len: v.body.voluntary_exits.len(), - sync_committee_participants: -1, # Altair logging compatibility - block_number: 0'u64, # Bellatrix compat - block_hash: "", # Bellatrix compat - parent_hash: "", # Bellatrix compat - fee_recipient: "", # Bellatrix compat - bls_to_execution_changes_len: 0, # Capella compat - blob_kzg_commitments_len: 0, # Deneb compat - ) - -# TODO: There should be only a single generic HashedBeaconState definition -func initHashedBeaconState*(s: BeaconState): HashedBeaconState = - HashedBeaconState(data: s) - -func shortLog*(v: SomeSignedBeaconBlock): auto = - ( - blck: shortLog(v.message), - signature: shortLog(v.signature) - ) diff --git a/beacon_chain/spec/eth2_merkleization.nim b/beacon_chain/spec/eth2_merkleization.nim index 72dd50ef0..5ed5d5592 100644 --- a/beacon_chain/spec/eth2_merkleization.nim +++ b/beacon_chain/spec/eth2_merkleization.nim @@ -5,8 +5,6 @@ import ./ssz_codec from ./datatypes/base import HashedValidatorPubKeyItem -from ./datatypes/phase0 import HashedBeaconState, SignedBeaconBlock - export ssz_codec, merkleization, proofs type diff --git a/beacon_chain/spec/eth2_ssz_serialization.nim b/beacon_chain/spec/eth2_ssz_serialization.nim index 6585d97a5..08be02a7f 100644 --- a/beacon_chain/spec/eth2_ssz_serialization.nim +++ b/beacon_chain/spec/eth2_ssz_serialization.nim @@ -1,10 +1,9 @@ import ssz_serialization, ./ssz_codec, - ./datatypes/phase0, ./eth2_merkleization -export phase0, ssz_codec, ssz_serialization, eth2_merkleization +export ssz_codec, ssz_serialization, eth2_merkleization proc readAndUpdateRoot( data: openArray[byte], val: var auto, updateRoot = true @@ -13,13 +12,6 @@ proc readAndUpdateRoot( if updateRoot: val.root = hash_tree_root(val.message) -# TODO this is an ugly way to get a stronger match than the generic readSszBytes -# and avoid ambiguities - `var` + typeclasses are problematic - -template readSszBytes*( - data: openArray[byte], val: var phase0.SignedBeaconBlock, updateRoot = true) = - readAndUpdateRoot(data, val, updateRoot) - template readSszBytes*( data: openArray[byte], val: var auto, updateRoot: bool) = readSszValue(data, val) diff --git a/beacon_chain/spec/forks.nim b/beacon_chain/spec/forks.nim index 9094eb9bf..86267ac31 100644 --- a/beacon_chain/spec/forks.nim +++ b/beacon_chain/spec/forks.nim @@ -1,7 +1,6 @@ import results, - "."/block_id, - ./datatypes/phase0 + "."/block_id type ConsensusFork* {.pure.} = enum diff --git a/beacon_chain/validators/beacon_validators.nim b/beacon_chain/validators/beacon_validators.nim index e79f14968..d6f09a14d 100644 --- a/beacon_chain/validators/beacon_validators.nim +++ b/beacon_chain/validators/beacon_validators.nim @@ -65,8 +65,7 @@ proc getValidatorForDuties( index: Opt.some 0.ValidatorIndex, validator: Opt.some Validator(pubkey: ValidatorPubKey.fromHex("891c64850444b66331ef7888c907b4af71ab6b2c883affe2cebd15d6c3644ac7ce6af96334192efdf95a64bab8ea425a")[])) -from ".."/spec/datatypes/phase0 import BeaconBlock, shortLog -proc makeBeaconBlock(): Result[phase0.BeaconBlock, cstring] = ok(default(phase0.BeaconBlock)) +proc makeBeaconBlock(): Result[Mock, cstring] = ok(default(Mock)) proc getProposalState( head: BlockRef, slot: Slot, cache: var StateCache): @@ -309,7 +308,7 @@ proc proposeBlockAux( if notSlashable.isErr: warn "Slashing protection activated for block proposal", blockRoot = shortLog(blockRoot), - blck = shortLog(default(phase0.BeaconBlock)), + blck = default(Mock), signingRoot = shortLog(signingRoot), existingProposal = notSlashable.error return head diff --git a/beacon_chain/validators/message_router.nim b/beacon_chain/validators/message_router.nim index cab623dd2..3644bee2a 100644 --- a/beacon_chain/validators/message_router.nim +++ b/beacon_chain/validators/message_router.nim @@ -21,8 +21,6 @@ func getBlockRef(root: Eth2Digest): Opt[BlockRef] = root, 0.Slot) return ok(newRef) -from ".."/spec/datatypes/phase0 import shortLog - proc addBlock( blck: ForkedSignedBeaconBlock, blobs: Opt[BlobSidecars], maybeFinalized = false,