2021-06-11 17:51:46 +00:00
|
|
|
# beacon_chain
|
2024-01-06 14:26:56 +00:00
|
|
|
# Copyright (c) 2021-2024 Status Research & Development GmbH
|
2021-06-11 17:51:46 +00:00
|
|
|
# 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.
|
|
|
|
|
2023-01-20 14:14:37 +00:00
|
|
|
{.push raises: [].}
|
2021-06-11 17:51:46 +00:00
|
|
|
|
|
|
|
import
|
2023-01-28 19:53:41 +00:00
|
|
|
std/macros,
|
2024-01-16 22:37:14 +00:00
|
|
|
results,
|
2022-01-05 14:24:15 +00:00
|
|
|
stew/assign2,
|
2021-06-11 17:51:46 +00:00
|
|
|
chronicles,
|
|
|
|
../extras,
|
2023-01-12 17:11:38 +00:00
|
|
|
"."/[
|
|
|
|
block_id, eth2_merkleization, eth2_ssz_serialization,
|
|
|
|
forks_light_client, presets],
|
2024-02-24 11:14:45 +00:00
|
|
|
./datatypes/[phase0, altair, bellatrix, capella, deneb, electra],
|
2024-04-08 08:34:15 +00:00
|
|
|
./mev/[bellatrix_mev, capella_mev, deneb_mev, electra_mev]
|
2021-06-11 17:51:46 +00:00
|
|
|
|
2021-11-05 07:34:34 +00:00
|
|
|
export
|
2024-02-24 13:43:58 +00:00
|
|
|
extras, block_id, phase0, altair, bellatrix, capella, deneb, electra,
|
2023-01-14 21:19:50 +00:00
|
|
|
eth2_merkleization, eth2_ssz_serialization, forks_light_client,
|
2024-04-08 08:34:15 +00:00
|
|
|
presets, deneb_mev, electra_mev
|
2021-11-05 07:34:34 +00:00
|
|
|
|
|
|
|
# This file contains helpers for dealing with forks - we have two ways we can
|
|
|
|
# deal with forks:
|
|
|
|
# * generics - this means using the static typing and differentiating forks
|
|
|
|
# at compile time - this is preferred in fork-specific code where the fork
|
|
|
|
# is known up-front, for example spec functions.
|
|
|
|
# * variants - this means using a variant object and determining the fork at
|
|
|
|
# runtime - this carries the obvious risk and complexity of dealing with
|
|
|
|
# runtime checking, but is of course needed for external data that may be
|
|
|
|
# of any fork kind.
|
|
|
|
#
|
|
|
|
# For generics, we define `Forky*` type classes that cover "similar" objects
|
|
|
|
# across forks - for variants, they're called `Forked*` instead.
|
|
|
|
# See withXxx and `init` for convenient ways of moving between these two worlds.
|
|
|
|
# A clever programmer would use templates, macros and dark magic to create all
|
|
|
|
# these types and converters :)
|
2021-08-12 13:08:20 +00:00
|
|
|
|
2021-06-11 17:51:46 +00:00
|
|
|
type
|
2023-01-28 19:53:41 +00:00
|
|
|
ConsensusFork* {.pure.} = enum
|
2021-10-18 16:37:27 +00:00
|
|
|
Phase0,
|
|
|
|
Altair,
|
2022-11-02 16:23:30 +00:00
|
|
|
Bellatrix,
|
2022-12-07 16:47:23 +00:00
|
|
|
Capella,
|
2024-04-03 14:43:43 +00:00
|
|
|
Deneb,
|
|
|
|
Electra
|
2021-06-11 17:51:46 +00:00
|
|
|
|
2021-11-05 07:34:34 +00:00
|
|
|
ForkyBeaconState* =
|
|
|
|
phase0.BeaconState |
|
|
|
|
altair.BeaconState |
|
2022-10-27 06:29:24 +00:00
|
|
|
bellatrix.BeaconState |
|
2022-12-06 12:40:13 +00:00
|
|
|
capella.BeaconState |
|
2024-02-24 11:14:45 +00:00
|
|
|
deneb.BeaconState |
|
|
|
|
electra.BeaconState
|
2021-11-05 07:34:34 +00:00
|
|
|
|
|
|
|
ForkyHashedBeaconState* =
|
|
|
|
phase0.HashedBeaconState |
|
|
|
|
altair.HashedBeaconState |
|
2022-11-02 16:23:30 +00:00
|
|
|
bellatrix.HashedBeaconState |
|
2022-12-07 16:47:23 +00:00
|
|
|
capella.HashedBeaconState |
|
2024-02-24 11:14:45 +00:00
|
|
|
deneb.HashedBeaconState |
|
|
|
|
electra.HashedBeaconState
|
2021-11-05 07:34:34 +00:00
|
|
|
|
2021-06-11 17:51:46 +00:00
|
|
|
ForkedHashedBeaconState* = object
|
2023-01-28 19:53:41 +00:00
|
|
|
case kind*: ConsensusFork
|
|
|
|
of ConsensusFork.Phase0: phase0Data*: phase0.HashedBeaconState
|
|
|
|
of ConsensusFork.Altair: altairData*: altair.HashedBeaconState
|
|
|
|
of ConsensusFork.Bellatrix: bellatrixData*: bellatrix.HashedBeaconState
|
|
|
|
of ConsensusFork.Capella: capellaData*: capella.HashedBeaconState
|
2023-03-04 22:23:52 +00:00
|
|
|
of ConsensusFork.Deneb: denebData*: deneb.HashedBeaconState
|
2024-04-03 14:43:43 +00:00
|
|
|
of ConsensusFork.Electra: electraData*: electra.HashedBeaconState
|
2021-07-07 09:09:47 +00:00
|
|
|
|
2022-12-20 19:00:56 +00:00
|
|
|
ForkyExecutionPayload* =
|
|
|
|
bellatrix.ExecutionPayload |
|
|
|
|
capella.ExecutionPayload |
|
2024-02-24 11:14:45 +00:00
|
|
|
deneb.ExecutionPayload |
|
|
|
|
electra.ExecutionPayload
|
2022-12-20 19:00:56 +00:00
|
|
|
|
2023-01-28 19:53:41 +00:00
|
|
|
ForkyExecutionPayloadHeader* =
|
|
|
|
bellatrix.ExecutionPayloadHeader |
|
|
|
|
capella.ExecutionPayloadHeader |
|
2023-02-20 08:45:49 +00:00
|
|
|
deneb.ExecutionPayloadHeader
|
2023-01-28 19:53:41 +00:00
|
|
|
|
2022-02-11 15:58:33 +00:00
|
|
|
ForkyBeaconBlockBody* =
|
|
|
|
phase0.BeaconBlockBody |
|
|
|
|
altair.BeaconBlockBody |
|
2022-11-07 18:37:48 +00:00
|
|
|
bellatrix.BeaconBlockBody |
|
2022-12-05 16:29:09 +00:00
|
|
|
capella.BeaconBlockBody |
|
2024-02-24 11:14:45 +00:00
|
|
|
deneb.BeaconBlockBody |
|
|
|
|
electra.BeaconBlockBody
|
2022-02-11 15:58:33 +00:00
|
|
|
|
|
|
|
ForkySigVerifiedBeaconBlockBody* =
|
|
|
|
phase0.SigVerifiedBeaconBlockBody |
|
|
|
|
altair.SigVerifiedBeaconBlockBody |
|
2022-11-07 18:37:48 +00:00
|
|
|
bellatrix.SigVerifiedBeaconBlockBody |
|
2022-12-05 16:29:09 +00:00
|
|
|
capella.SigVerifiedBeaconBlockBody |
|
2024-02-24 11:14:45 +00:00
|
|
|
deneb.SigVerifiedBeaconBlockBody |
|
|
|
|
electra.SigVerifiedBeaconBlockBody
|
2022-02-11 15:58:33 +00:00
|
|
|
|
|
|
|
ForkyTrustedBeaconBlockBody* =
|
|
|
|
phase0.TrustedBeaconBlockBody |
|
|
|
|
altair.TrustedBeaconBlockBody |
|
2022-11-07 18:37:48 +00:00
|
|
|
bellatrix.TrustedBeaconBlockBody |
|
2022-12-05 16:29:09 +00:00
|
|
|
capella.TrustedBeaconBlockBody |
|
2024-02-24 11:14:45 +00:00
|
|
|
deneb.TrustedBeaconBlockBody |
|
|
|
|
electra.TrustedBeaconBlockBody
|
2022-02-11 15:58:33 +00:00
|
|
|
|
|
|
|
SomeForkyBeaconBlockBody* =
|
|
|
|
ForkyBeaconBlockBody |
|
|
|
|
ForkySigVerifiedBeaconBlockBody |
|
|
|
|
ForkyTrustedBeaconBlockBody
|
|
|
|
|
2021-11-05 07:34:34 +00:00
|
|
|
ForkyBeaconBlock* =
|
|
|
|
phase0.BeaconBlock |
|
|
|
|
altair.BeaconBlock |
|
2022-10-27 06:29:24 +00:00
|
|
|
bellatrix.BeaconBlock |
|
2022-12-05 16:29:09 +00:00
|
|
|
capella.BeaconBlock |
|
2024-02-24 11:14:45 +00:00
|
|
|
deneb.BeaconBlock |
|
|
|
|
electra.BeaconBlock
|
2021-11-05 07:34:34 +00:00
|
|
|
|
2022-01-17 11:19:58 +00:00
|
|
|
ForkySigVerifiedBeaconBlock* =
|
|
|
|
phase0.SigVerifiedBeaconBlock |
|
|
|
|
altair.SigVerifiedBeaconBlock |
|
2022-11-02 16:23:30 +00:00
|
|
|
bellatrix.SigVerifiedBeaconBlock |
|
2022-12-05 16:29:09 +00:00
|
|
|
capella.SigVerifiedBeaconBlock |
|
2024-02-24 11:14:45 +00:00
|
|
|
deneb.SigVerifiedBeaconBlock |
|
|
|
|
electra.SigVerifiedBeaconBlock
|
2022-01-17 11:19:58 +00:00
|
|
|
|
2021-11-05 07:34:34 +00:00
|
|
|
ForkyTrustedBeaconBlock* =
|
|
|
|
phase0.TrustedBeaconBlock |
|
|
|
|
altair.TrustedBeaconBlock |
|
2022-11-02 16:23:30 +00:00
|
|
|
bellatrix.TrustedBeaconBlock |
|
2022-12-05 16:29:09 +00:00
|
|
|
capella.TrustedBeaconBlock |
|
2024-02-24 11:14:45 +00:00
|
|
|
deneb.TrustedBeaconBlock |
|
|
|
|
electra.TrustedBeaconBlock
|
2021-11-05 07:34:34 +00:00
|
|
|
|
2022-01-30 16:51:04 +00:00
|
|
|
SomeForkyBeaconBlock* =
|
|
|
|
ForkyBeaconBlock |
|
|
|
|
ForkySigVerifiedBeaconBlock |
|
|
|
|
ForkyTrustedBeaconBlock
|
|
|
|
|
2023-03-05 01:40:21 +00:00
|
|
|
ForkyExecutionPayloadForSigning* =
|
|
|
|
bellatrix.ExecutionPayloadForSigning |
|
|
|
|
capella.ExecutionPayloadForSigning |
|
2024-02-24 11:14:45 +00:00
|
|
|
deneb.ExecutionPayloadForSigning |
|
|
|
|
electra.ExecutionPayloadForSigning
|
2023-03-05 01:40:21 +00:00
|
|
|
|
2024-04-10 08:54:00 +00:00
|
|
|
ForkyBlindedBeaconBlock* =
|
|
|
|
deneb_mev.BlindedBeaconBlock |
|
|
|
|
electra_mev.BlindedBeaconBlock
|
2023-11-28 23:30:14 +00:00
|
|
|
|
2021-08-27 09:00:06 +00:00
|
|
|
ForkedBeaconBlock* = object
|
2023-01-28 19:53:41 +00:00
|
|
|
case kind*: ConsensusFork
|
|
|
|
of ConsensusFork.Phase0: phase0Data*: phase0.BeaconBlock
|
|
|
|
of ConsensusFork.Altair: altairData*: altair.BeaconBlock
|
|
|
|
of ConsensusFork.Bellatrix: bellatrixData*: bellatrix.BeaconBlock
|
|
|
|
of ConsensusFork.Capella: capellaData*: capella.BeaconBlock
|
2023-03-04 22:23:52 +00:00
|
|
|
of ConsensusFork.Deneb: denebData*: deneb.BeaconBlock
|
2024-04-03 14:43:43 +00:00
|
|
|
of ConsensusFork.Electra: electraData*: electra.BeaconBlock
|
2021-11-05 07:34:34 +00:00
|
|
|
|
2023-11-28 23:30:14 +00:00
|
|
|
ForkedMaybeBlindedBeaconBlock* = object
|
|
|
|
case kind*: ConsensusFork
|
|
|
|
of ConsensusFork.Phase0:
|
|
|
|
phase0Data*: phase0.BeaconBlock
|
|
|
|
of ConsensusFork.Altair:
|
|
|
|
altairData*: altair.BeaconBlock
|
|
|
|
of ConsensusFork.Bellatrix:
|
|
|
|
bellatrixData*: bellatrix.BeaconBlock
|
|
|
|
of ConsensusFork.Capella:
|
2024-02-28 18:27:26 +00:00
|
|
|
capellaData*: capella.BeaconBlock
|
2023-11-28 23:30:14 +00:00
|
|
|
of ConsensusFork.Deneb:
|
|
|
|
denebData*: deneb_mev.MaybeBlindedBeaconBlock
|
2024-04-03 14:43:43 +00:00
|
|
|
of ConsensusFork.Electra:
|
2024-04-08 12:49:03 +00:00
|
|
|
electraData*: electra_mev.MaybeBlindedBeaconBlock
|
2023-11-28 23:30:14 +00:00
|
|
|
consensusValue*: Opt[UInt256]
|
|
|
|
executionValue*: Opt[UInt256]
|
|
|
|
|
2022-08-01 06:41:47 +00:00
|
|
|
Web3SignerForkedBeaconBlock* = object
|
2023-06-29 09:36:43 +00:00
|
|
|
kind*: ConsensusFork
|
|
|
|
data*: BeaconBlockHeader
|
2022-05-17 16:55:03 +00:00
|
|
|
|
2022-10-31 17:39:03 +00:00
|
|
|
ForkedBlindedBeaconBlock* = object
|
2023-01-28 19:53:41 +00:00
|
|
|
case kind*: ConsensusFork
|
|
|
|
of ConsensusFork.Phase0: phase0Data*: phase0.BeaconBlock
|
|
|
|
of ConsensusFork.Altair: altairData*: altair.BeaconBlock
|
2023-02-21 13:21:38 +00:00
|
|
|
of ConsensusFork.Bellatrix: bellatrixData*: bellatrix_mev.BlindedBeaconBlock
|
|
|
|
of ConsensusFork.Capella: capellaData*: capella_mev.BlindedBeaconBlock
|
2023-10-20 01:39:47 +00:00
|
|
|
of ConsensusFork.Deneb: denebData*: deneb_mev.BlindedBeaconBlock
|
2024-04-08 12:49:03 +00:00
|
|
|
of ConsensusFork.Electra: electraData*: electra_mev.BlindedBeaconBlock
|
2022-10-31 17:39:03 +00:00
|
|
|
|
2021-11-05 07:34:34 +00:00
|
|
|
ForkySignedBeaconBlock* =
|
|
|
|
phase0.SignedBeaconBlock |
|
|
|
|
altair.SignedBeaconBlock |
|
2022-11-02 16:23:30 +00:00
|
|
|
bellatrix.SignedBeaconBlock |
|
2022-12-05 16:29:09 +00:00
|
|
|
capella.SignedBeaconBlock |
|
2024-02-24 11:14:45 +00:00
|
|
|
deneb.SignedBeaconBlock |
|
|
|
|
electra.SignedBeaconBlock
|
2021-08-27 09:00:06 +00:00
|
|
|
|
2021-07-07 09:09:47 +00:00
|
|
|
ForkedSignedBeaconBlock* = object
|
2023-01-28 19:53:41 +00:00
|
|
|
case kind*: ConsensusFork
|
|
|
|
of ConsensusFork.Phase0: phase0Data*: phase0.SignedBeaconBlock
|
|
|
|
of ConsensusFork.Altair: altairData*: altair.SignedBeaconBlock
|
|
|
|
of ConsensusFork.Bellatrix: bellatrixData*: bellatrix.SignedBeaconBlock
|
|
|
|
of ConsensusFork.Capella: capellaData*: capella.SignedBeaconBlock
|
2023-03-04 22:23:52 +00:00
|
|
|
of ConsensusFork.Deneb: denebData*: deneb.SignedBeaconBlock
|
2024-04-03 14:43:43 +00:00
|
|
|
of ConsensusFork.Electra: electraData*: electra.SignedBeaconBlock
|
2021-11-05 07:34:34 +00:00
|
|
|
|
2022-11-24 09:14:05 +00:00
|
|
|
ForkySignedBlindedBeaconBlock* =
|
|
|
|
phase0.SignedBeaconBlock |
|
|
|
|
altair.SignedBeaconBlock |
|
2024-01-31 03:18:55 +00:00
|
|
|
bellatrix_mev.SignedBlindedBeaconBlock |
|
|
|
|
capella_mev.SignedBlindedBeaconBlock |
|
2024-04-08 12:49:03 +00:00
|
|
|
deneb_mev.SignedBlindedBeaconBlock |
|
|
|
|
electra_mev.SignedBlindedBeaconBlock
|
2022-11-24 09:14:05 +00:00
|
|
|
|
|
|
|
ForkedSignedBlindedBeaconBlock* = object
|
2023-01-28 19:53:41 +00:00
|
|
|
case kind*: ConsensusFork
|
|
|
|
of ConsensusFork.Phase0: phase0Data*: phase0.SignedBeaconBlock
|
|
|
|
of ConsensusFork.Altair: altairData*: altair.SignedBeaconBlock
|
2023-02-21 13:21:38 +00:00
|
|
|
of ConsensusFork.Bellatrix: bellatrixData*: bellatrix_mev.SignedBlindedBeaconBlock
|
|
|
|
of ConsensusFork.Capella: capellaData*: capella_mev.SignedBlindedBeaconBlock
|
2023-10-20 01:39:47 +00:00
|
|
|
of ConsensusFork.Deneb: denebData*: deneb_mev.SignedBlindedBeaconBlock
|
2024-04-08 12:49:03 +00:00
|
|
|
of ConsensusFork.Electra: electraData*: electra_mev.SignedBlindedBeaconBlock
|
2022-11-24 09:14:05 +00:00
|
|
|
|
2022-01-11 10:01:54 +00:00
|
|
|
ForkySigVerifiedSignedBeaconBlock* =
|
|
|
|
phase0.SigVerifiedSignedBeaconBlock |
|
|
|
|
altair.SigVerifiedSignedBeaconBlock |
|
2022-11-02 16:23:30 +00:00
|
|
|
bellatrix.SigVerifiedSignedBeaconBlock |
|
2022-12-05 16:29:09 +00:00
|
|
|
capella.SigVerifiedSignedBeaconBlock |
|
2024-02-24 11:14:45 +00:00
|
|
|
deneb.SigVerifiedSignedBeaconBlock |
|
|
|
|
electra.SigVerifiedSignedBeaconBlock
|
2022-01-11 10:01:54 +00:00
|
|
|
|
2022-06-10 14:16:37 +00:00
|
|
|
ForkyMsgTrustedSignedBeaconBlock* =
|
|
|
|
phase0.MsgTrustedSignedBeaconBlock |
|
|
|
|
altair.MsgTrustedSignedBeaconBlock |
|
2022-11-02 16:23:30 +00:00
|
|
|
bellatrix.MsgTrustedSignedBeaconBlock |
|
2022-12-05 16:29:09 +00:00
|
|
|
capella.MsgTrustedSignedBeaconBlock |
|
2024-02-24 11:14:45 +00:00
|
|
|
deneb.MsgTrustedSignedBeaconBlock |
|
|
|
|
electra.MsgTrustedSignedBeaconBlock
|
2022-06-10 14:16:37 +00:00
|
|
|
|
2021-11-05 07:34:34 +00:00
|
|
|
ForkyTrustedSignedBeaconBlock* =
|
|
|
|
phase0.TrustedSignedBeaconBlock |
|
|
|
|
altair.TrustedSignedBeaconBlock |
|
2022-11-02 16:23:30 +00:00
|
|
|
bellatrix.TrustedSignedBeaconBlock |
|
2022-12-05 16:29:09 +00:00
|
|
|
capella.TrustedSignedBeaconBlock |
|
2024-02-24 11:14:45 +00:00
|
|
|
deneb.TrustedSignedBeaconBlock |
|
|
|
|
electra.TrustedSignedBeaconBlock
|
2021-07-07 09:09:47 +00:00
|
|
|
|
2022-06-10 14:16:37 +00:00
|
|
|
ForkedMsgTrustedSignedBeaconBlock* = object
|
2023-01-28 19:53:41 +00:00
|
|
|
case kind*: ConsensusFork
|
|
|
|
of ConsensusFork.Phase0: phase0Data*: phase0.MsgTrustedSignedBeaconBlock
|
|
|
|
of ConsensusFork.Altair: altairData*: altair.MsgTrustedSignedBeaconBlock
|
|
|
|
of ConsensusFork.Bellatrix: bellatrixData*: bellatrix.MsgTrustedSignedBeaconBlock
|
|
|
|
of ConsensusFork.Capella: capellaData*: capella.MsgTrustedSignedBeaconBlock
|
2023-03-04 22:23:52 +00:00
|
|
|
of ConsensusFork.Deneb: denebData*: deneb.MsgTrustedSignedBeaconBlock
|
2024-04-03 14:43:43 +00:00
|
|
|
of ConsensusFork.Electra: electraData*: electra.MsgTrustedSignedBeaconBlock
|
2022-06-10 14:16:37 +00:00
|
|
|
|
2021-07-07 09:09:47 +00:00
|
|
|
ForkedTrustedSignedBeaconBlock* = object
|
2023-01-28 19:53:41 +00:00
|
|
|
case kind*: ConsensusFork
|
|
|
|
of ConsensusFork.Phase0: phase0Data*: phase0.TrustedSignedBeaconBlock
|
|
|
|
of ConsensusFork.Altair: altairData*: altair.TrustedSignedBeaconBlock
|
|
|
|
of ConsensusFork.Bellatrix: bellatrixData*: bellatrix.TrustedSignedBeaconBlock
|
|
|
|
of ConsensusFork.Capella: capellaData*: capella.TrustedSignedBeaconBlock
|
2023-03-04 22:23:52 +00:00
|
|
|
of ConsensusFork.Deneb: denebData*: deneb.TrustedSignedBeaconBlock
|
2024-04-03 14:43:43 +00:00
|
|
|
of ConsensusFork.Electra: electraData*: electra.TrustedSignedBeaconBlock
|
2021-07-07 09:09:47 +00:00
|
|
|
|
2022-01-11 10:01:54 +00:00
|
|
|
SomeForkySignedBeaconBlock* =
|
|
|
|
ForkySignedBeaconBlock |
|
|
|
|
ForkySigVerifiedSignedBeaconBlock |
|
2022-06-10 14:16:37 +00:00
|
|
|
ForkyMsgTrustedSignedBeaconBlock |
|
2022-01-11 10:01:54 +00:00
|
|
|
ForkyTrustedSignedBeaconBlock
|
|
|
|
|
2021-10-13 14:24:36 +00:00
|
|
|
EpochInfoFork* {.pure.} = enum
|
|
|
|
Phase0
|
|
|
|
Altair
|
|
|
|
|
|
|
|
ForkedEpochInfo* = object
|
|
|
|
case kind*: EpochInfoFork
|
2021-11-05 07:34:34 +00:00
|
|
|
of EpochInfoFork.Phase0: phase0Data*: phase0.EpochInfo
|
|
|
|
of EpochInfoFork.Altair: altairData*: altair.EpochInfo
|
2021-10-13 14:24:36 +00:00
|
|
|
|
|
|
|
ForkyEpochInfo* = phase0.EpochInfo | altair.EpochInfo
|
|
|
|
|
2021-10-07 13:19:47 +00:00
|
|
|
ForkDigests* = object
|
2022-01-05 14:24:15 +00:00
|
|
|
phase0*: ForkDigest
|
|
|
|
altair*: ForkDigest
|
|
|
|
bellatrix*: ForkDigest
|
2022-06-03 14:42:40 +00:00
|
|
|
capella*: ForkDigest
|
2023-03-10 17:13:40 +00:00
|
|
|
deneb*: ForkDigest
|
2024-02-24 11:14:45 +00:00
|
|
|
electra*: ForkDigest
|
2021-07-07 09:09:47 +00:00
|
|
|
|
2023-09-05 13:59:17 +00:00
|
|
|
template kind*(
|
|
|
|
x: typedesc[
|
2023-09-27 15:10:28 +00:00
|
|
|
phase0.BeaconState |
|
|
|
|
phase0.HashedBeaconState |
|
|
|
|
phase0.BeaconBlock |
|
|
|
|
phase0.SignedBeaconBlock |
|
|
|
|
phase0.TrustedBeaconBlock |
|
|
|
|
phase0.BeaconBlockBody |
|
|
|
|
phase0.SigVerifiedBeaconBlockBody |
|
|
|
|
phase0.TrustedBeaconBlockBody |
|
|
|
|
phase0.SigVerifiedSignedBeaconBlock |
|
|
|
|
phase0.MsgTrustedSignedBeaconBlock |
|
|
|
|
phase0.TrustedSignedBeaconBlock]): ConsensusFork =
|
2023-09-05 13:59:17 +00:00
|
|
|
ConsensusFork.Phase0
|
|
|
|
|
|
|
|
template kind*(
|
|
|
|
x: typedesc[
|
2023-09-27 15:10:28 +00:00
|
|
|
altair.BeaconState |
|
|
|
|
altair.HashedBeaconState |
|
|
|
|
altair.BeaconBlock |
|
|
|
|
altair.SignedBeaconBlock |
|
|
|
|
altair.TrustedBeaconBlock |
|
|
|
|
altair.BeaconBlockBody |
|
|
|
|
altair.SigVerifiedBeaconBlockBody |
|
|
|
|
altair.TrustedBeaconBlockBody |
|
|
|
|
altair.SigVerifiedSignedBeaconBlock |
|
|
|
|
altair.MsgTrustedSignedBeaconBlock |
|
|
|
|
altair.TrustedSignedBeaconBlock]): ConsensusFork =
|
2023-09-05 13:59:17 +00:00
|
|
|
ConsensusFork.Altair
|
|
|
|
|
|
|
|
template kind*(
|
|
|
|
x: typedesc[
|
2023-09-27 15:10:28 +00:00
|
|
|
bellatrix.BeaconState |
|
|
|
|
bellatrix.HashedBeaconState |
|
|
|
|
bellatrix.ExecutionPayload |
|
|
|
|
bellatrix.ExecutionPayloadForSigning |
|
|
|
|
bellatrix.ExecutionPayloadHeader |
|
|
|
|
bellatrix.BeaconBlock |
|
|
|
|
bellatrix.SignedBeaconBlock |
|
|
|
|
bellatrix.TrustedBeaconBlock |
|
|
|
|
bellatrix.BeaconBlockBody |
|
|
|
|
bellatrix.SigVerifiedBeaconBlockBody |
|
|
|
|
bellatrix.TrustedBeaconBlockBody |
|
|
|
|
bellatrix.SigVerifiedSignedBeaconBlock |
|
|
|
|
bellatrix.MsgTrustedSignedBeaconBlock |
|
2024-01-31 03:18:55 +00:00
|
|
|
bellatrix.TrustedSignedBeaconBlock] |
|
|
|
|
bellatrix_mev.SignedBlindedBeaconBlock): ConsensusFork =
|
2023-09-05 13:59:17 +00:00
|
|
|
ConsensusFork.Bellatrix
|
|
|
|
|
|
|
|
template kind*(
|
|
|
|
x: typedesc[
|
2023-09-27 15:10:28 +00:00
|
|
|
capella.BeaconState |
|
|
|
|
capella.HashedBeaconState |
|
|
|
|
capella.ExecutionPayload |
|
|
|
|
capella.ExecutionPayloadForSigning |
|
|
|
|
capella.ExecutionPayloadHeader |
|
|
|
|
capella.BeaconBlock |
|
|
|
|
capella.SignedBeaconBlock |
|
|
|
|
capella.TrustedBeaconBlock |
|
|
|
|
capella.BeaconBlockBody |
|
|
|
|
capella.SigVerifiedBeaconBlockBody |
|
|
|
|
capella.TrustedBeaconBlockBody |
|
|
|
|
capella.SigVerifiedSignedBeaconBlock |
|
|
|
|
capella.MsgTrustedSignedBeaconBlock |
|
2023-11-16 00:20:13 +00:00
|
|
|
capella.TrustedSignedBeaconBlock |
|
|
|
|
capella_mev.SignedBlindedBeaconBlock]): ConsensusFork =
|
2023-09-05 13:59:17 +00:00
|
|
|
ConsensusFork.Capella
|
|
|
|
|
|
|
|
template kind*(
|
|
|
|
x: typedesc[
|
2023-09-27 15:10:28 +00:00
|
|
|
deneb.BeaconState |
|
|
|
|
deneb.HashedBeaconState |
|
|
|
|
deneb.ExecutionPayload |
|
|
|
|
deneb.ExecutionPayloadForSigning |
|
|
|
|
deneb.ExecutionPayloadHeader |
|
|
|
|
deneb.BeaconBlock |
|
|
|
|
deneb.SignedBeaconBlock |
|
|
|
|
deneb.TrustedBeaconBlock |
|
|
|
|
deneb.BeaconBlockBody |
|
|
|
|
deneb.SigVerifiedBeaconBlockBody |
|
|
|
|
deneb.TrustedBeaconBlockBody |
|
|
|
|
deneb.SigVerifiedSignedBeaconBlock |
|
|
|
|
deneb.MsgTrustedSignedBeaconBlock |
|
2023-11-16 00:20:13 +00:00
|
|
|
deneb.TrustedSignedBeaconBlock |
|
|
|
|
deneb_mev.SignedBlindedBeaconBlock]): ConsensusFork =
|
2023-09-05 13:59:17 +00:00
|
|
|
ConsensusFork.Deneb
|
|
|
|
|
2024-04-03 14:43:43 +00:00
|
|
|
template kind*(
|
|
|
|
x: typedesc[
|
|
|
|
electra.BeaconState |
|
|
|
|
electra.HashedBeaconState |
|
|
|
|
electra.ExecutionPayload |
|
|
|
|
electra.ExecutionPayloadForSigning |
|
|
|
|
electra.ExecutionPayloadHeader |
|
|
|
|
electra.BeaconBlock |
|
|
|
|
electra.SignedBeaconBlock |
|
|
|
|
electra.TrustedBeaconBlock |
|
|
|
|
electra.BeaconBlockBody |
|
|
|
|
electra.SigVerifiedBeaconBlockBody |
|
|
|
|
electra.TrustedBeaconBlockBody |
|
|
|
|
electra.SigVerifiedSignedBeaconBlock |
|
|
|
|
electra.MsgTrustedSignedBeaconBlock |
|
2024-04-08 16:03:20 +00:00
|
|
|
electra.TrustedSignedBeaconBlock |
|
|
|
|
electra_mev.SignedBlindedBeaconBlock]): ConsensusFork =
|
2024-04-03 14:43:43 +00:00
|
|
|
ConsensusFork.Electra
|
|
|
|
|
2023-09-29 13:26:34 +00:00
|
|
|
template BeaconState*(kind: static ConsensusFork): auto =
|
2024-04-03 14:43:43 +00:00
|
|
|
when kind == ConsensusFork.Electra:
|
|
|
|
typedesc[electra.BeaconState]
|
|
|
|
elif kind == ConsensusFork.Deneb:
|
2023-09-29 13:26:34 +00:00
|
|
|
typedesc[deneb.BeaconState]
|
|
|
|
elif kind == ConsensusFork.Capella:
|
|
|
|
typedesc[capella.BeaconState]
|
|
|
|
elif kind == ConsensusFork.Bellatrix:
|
|
|
|
typedesc[bellatrix.BeaconState]
|
|
|
|
elif kind == ConsensusFork.Altair:
|
|
|
|
typedesc[altair.BeaconState]
|
|
|
|
elif kind == ConsensusFork.Phase0:
|
|
|
|
typedesc[phase0.BeaconState]
|
|
|
|
else:
|
|
|
|
static: raiseAssert "Unreachable"
|
|
|
|
|
|
|
|
template BeaconBlock*(kind: static ConsensusFork): auto =
|
2024-04-06 13:11:47 +00:00
|
|
|
when kind == ConsensusFork.Electra:
|
|
|
|
typedesc[electra.BeaconBlock]
|
|
|
|
elif kind == ConsensusFork.Deneb:
|
2023-09-29 13:26:34 +00:00
|
|
|
typedesc[deneb.BeaconBlock]
|
|
|
|
elif kind == ConsensusFork.Capella:
|
|
|
|
typedesc[capella.BeaconBlock]
|
|
|
|
elif kind == ConsensusFork.Bellatrix:
|
|
|
|
typedesc[bellatrix.BeaconBlock]
|
|
|
|
elif kind == ConsensusFork.Altair:
|
|
|
|
typedesc[altair.BeaconBlock]
|
|
|
|
elif kind == ConsensusFork.Phase0:
|
|
|
|
typedesc[phase0.BeaconBlock]
|
|
|
|
else:
|
|
|
|
static: raiseAssert "Unreachable"
|
|
|
|
|
2023-10-05 12:01:40 +00:00
|
|
|
template BeaconBlockBody*(kind: static ConsensusFork): auto =
|
2024-04-03 14:43:43 +00:00
|
|
|
when kind == ConsensusFork.Electra:
|
|
|
|
typedesc[electra.BeaconBlockBody]
|
|
|
|
elif kind == ConsensusFork.Deneb:
|
2023-10-05 12:01:40 +00:00
|
|
|
typedesc[deneb.BeaconBlockBody]
|
|
|
|
elif kind == ConsensusFork.Capella:
|
|
|
|
typedesc[capella.BeaconBlockBody]
|
|
|
|
elif kind == ConsensusFork.Bellatrix:
|
|
|
|
typedesc[bellatrix.BeaconBlockBody]
|
|
|
|
elif kind == ConsensusFork.Altair:
|
|
|
|
typedesc[altair.BeaconBlockBody]
|
|
|
|
elif kind == ConsensusFork.Phase0:
|
|
|
|
typedesc[phase0.BeaconBlockBody]
|
|
|
|
else:
|
|
|
|
static: raiseAssert "Unreachable"
|
|
|
|
|
2023-05-16 07:46:41 +00:00
|
|
|
template SignedBeaconBlock*(kind: static ConsensusFork): auto =
|
2024-04-03 14:43:43 +00:00
|
|
|
when kind == ConsensusFork.Electra:
|
|
|
|
typedesc[electra.SignedBeaconBlock]
|
|
|
|
elif kind == ConsensusFork.Deneb:
|
2023-05-16 07:46:41 +00:00
|
|
|
typedesc[deneb.SignedBeaconBlock]
|
|
|
|
elif kind == ConsensusFork.Capella:
|
|
|
|
typedesc[capella.SignedBeaconBlock]
|
|
|
|
elif kind == ConsensusFork.Bellatrix:
|
|
|
|
typedesc[bellatrix.SignedBeaconBlock]
|
|
|
|
elif kind == ConsensusFork.Altair:
|
|
|
|
typedesc[altair.SignedBeaconBlock]
|
|
|
|
elif kind == ConsensusFork.Phase0:
|
|
|
|
typedesc[phase0.SignedBeaconBlock]
|
|
|
|
else:
|
|
|
|
static: raiseAssert "Unreachable"
|
|
|
|
|
2023-09-29 13:26:34 +00:00
|
|
|
template TrustedSignedBeaconBlock*(kind: static ConsensusFork): auto =
|
2024-04-03 14:43:43 +00:00
|
|
|
when kind == ConsensusFork.Electra:
|
|
|
|
typedesc[electra.TrustedSignedBeaconBlock]
|
|
|
|
elif kind == ConsensusFork.Deneb:
|
2023-09-29 13:26:34 +00:00
|
|
|
typedesc[deneb.TrustedSignedBeaconBlock]
|
|
|
|
elif kind == ConsensusFork.Capella:
|
|
|
|
typedesc[capella.TrustedSignedBeaconBlock]
|
|
|
|
elif kind == ConsensusFork.Bellatrix:
|
|
|
|
typedesc[bellatrix.TrustedSignedBeaconBlock]
|
|
|
|
elif kind == ConsensusFork.Altair:
|
|
|
|
typedesc[altair.TrustedSignedBeaconBlock]
|
|
|
|
elif kind == ConsensusFork.Phase0:
|
|
|
|
typedesc[phase0.TrustedSignedBeaconBlock]
|
|
|
|
else:
|
|
|
|
static: raiseAssert "Unreachable"
|
|
|
|
|
2023-03-11 20:11:33 +00:00
|
|
|
template ExecutionPayloadForSigning*(kind: static ConsensusFork): auto =
|
2024-04-03 14:43:43 +00:00
|
|
|
when kind == ConsensusFork.Electra:
|
|
|
|
typedesc[electra.ExecutionPayloadForSigning]
|
|
|
|
elif kind == ConsensusFork.Deneb:
|
2023-03-11 20:11:33 +00:00
|
|
|
typedesc[deneb.ExecutionPayloadForSigning]
|
|
|
|
elif kind == ConsensusFork.Capella:
|
|
|
|
typedesc[capella.ExecutionPayloadForSigning]
|
|
|
|
elif kind == ConsensusFork.Bellatrix:
|
|
|
|
typedesc[bellatrix.ExecutionPayloadForSigning]
|
|
|
|
else:
|
|
|
|
static: raiseAssert "Unreachable"
|
|
|
|
|
2023-11-28 23:30:14 +00:00
|
|
|
template BlindedBeaconBlock*(kind: static ConsensusFork): auto =
|
2024-04-10 08:54:00 +00:00
|
|
|
when kind == ConsensusFork.Electra:
|
|
|
|
typedesc[electra_mev.BlindedBeaconBlock]
|
|
|
|
elif kind == ConsensusFork.Deneb:
|
2023-11-28 23:30:14 +00:00
|
|
|
typedesc[deneb_mev.BlindedBeaconBlock]
|
2024-02-28 18:27:26 +00:00
|
|
|
elif kind == ConsensusFork.Capella or kind == ConsensusFork.Bellatrix:
|
2023-11-28 23:30:14 +00:00
|
|
|
static: raiseAssert "Unsupported"
|
|
|
|
else:
|
|
|
|
static: raiseAssert "Unreachable"
|
|
|
|
|
|
|
|
template MaybeBlindedBeaconBlock*(kind: static ConsensusFork): auto =
|
2024-04-08 12:49:03 +00:00
|
|
|
when kind == ConsensusFork.Electra:
|
|
|
|
typedesc[electra_mev.MaybeBlindedBeaconBlock]
|
|
|
|
elif kind == ConsensusFork.Deneb:
|
2023-11-28 23:30:14 +00:00
|
|
|
typedesc[deneb_mev.MaybeBlindedBeaconBlock]
|
2024-02-28 18:27:26 +00:00
|
|
|
elif kind == ConsensusFork.Capella or kind == ConsensusFork.Bellatrix:
|
2023-11-28 23:30:14 +00:00
|
|
|
static: raiseAssert "Unsupported"
|
|
|
|
else:
|
|
|
|
static: raiseAssert "Unreachable"
|
|
|
|
|
2023-11-16 00:20:13 +00:00
|
|
|
template SignedBlindedBeaconBlock*(kind: static ConsensusFork): auto =
|
2024-04-08 16:03:20 +00:00
|
|
|
when kind == ConsensusFork.Electra:
|
|
|
|
typedesc[electra_mev.SignedBlindedBeaconBlock]
|
|
|
|
elif kind == ConsensusFork.Deneb:
|
2023-11-16 00:20:13 +00:00
|
|
|
typedesc[deneb_mev.SignedBlindedBeaconBlock]
|
2024-02-28 18:27:26 +00:00
|
|
|
elif kind == ConsensusFork.Capella or kind == ConsensusFork.Bellatrix:
|
2023-11-16 00:20:13 +00:00
|
|
|
static: raiseAssert "Unsupported"
|
|
|
|
else:
|
|
|
|
static: raiseAssert "Unreachable"
|
|
|
|
|
2024-03-05 14:41:09 +00:00
|
|
|
template Forky*(
|
|
|
|
x: typedesc[ForkedSignedBeaconBlock],
|
|
|
|
kind: static ConsensusFork): auto =
|
|
|
|
kind.SignedBeaconBlock
|
|
|
|
|
2023-10-05 12:01:40 +00:00
|
|
|
template withAll*(
|
|
|
|
x: typedesc[ConsensusFork], body: untyped): untyped =
|
2024-04-03 14:43:43 +00:00
|
|
|
static: doAssert ConsensusFork.high == ConsensusFork.Electra
|
2024-04-04 03:17:31 +00:00
|
|
|
block:
|
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Electra
|
|
|
|
body
|
2023-10-05 12:01:40 +00:00
|
|
|
block:
|
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Deneb
|
|
|
|
body
|
|
|
|
block:
|
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Capella
|
|
|
|
body
|
|
|
|
block:
|
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Bellatrix
|
|
|
|
body
|
|
|
|
block:
|
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Altair
|
|
|
|
body
|
|
|
|
block:
|
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Phase0
|
|
|
|
body
|
|
|
|
|
2023-03-11 14:39:29 +00:00
|
|
|
template withConsensusFork*(
|
2023-01-28 19:53:41 +00:00
|
|
|
x: ConsensusFork, body: untyped): untyped =
|
2023-01-14 21:19:50 +00:00
|
|
|
case x
|
2024-04-03 14:43:43 +00:00
|
|
|
of ConsensusFork.Electra:
|
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Electra
|
|
|
|
body
|
2023-03-04 13:35:39 +00:00
|
|
|
of ConsensusFork.Deneb:
|
2023-03-11 00:35:52 +00:00
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Deneb
|
2023-01-14 21:19:50 +00:00
|
|
|
body
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Capella:
|
2023-03-11 00:35:52 +00:00
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Capella
|
2023-01-14 21:19:50 +00:00
|
|
|
body
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Bellatrix:
|
2023-03-11 00:35:52 +00:00
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Bellatrix
|
2023-01-14 21:19:50 +00:00
|
|
|
body
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Altair:
|
2023-03-11 00:35:52 +00:00
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Altair
|
2023-01-14 21:19:50 +00:00
|
|
|
body
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Phase0:
|
2023-03-11 00:35:52 +00:00
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Phase0
|
2023-01-14 21:19:50 +00:00
|
|
|
body
|
|
|
|
|
2023-11-28 23:30:14 +00:00
|
|
|
template BlockContents*(
|
|
|
|
kind: static ConsensusFork): auto =
|
2024-04-03 14:43:43 +00:00
|
|
|
when kind == ConsensusFork.Electra:
|
|
|
|
typedesc[electra.BlockContents]
|
|
|
|
elif kind == ConsensusFork.Deneb:
|
2023-11-28 23:30:14 +00:00
|
|
|
typedesc[deneb.BlockContents]
|
|
|
|
elif kind == ConsensusFork.Capella:
|
|
|
|
typedesc[capella.BeaconBlock]
|
|
|
|
elif kind == ConsensusFork.Bellatrix:
|
|
|
|
typedesc[bellatrix.BeaconBlock]
|
|
|
|
elif kind == ConsensusFork.Altair:
|
|
|
|
typedesc[altair.BeaconBlock]
|
|
|
|
elif kind == ConsensusFork.Phase0:
|
|
|
|
typedesc[phase0.BeaconBlock]
|
|
|
|
else:
|
|
|
|
{.error: "BlockContents does not support " & $kind.}
|
|
|
|
|
|
|
|
template BlindedBlockContents*(
|
|
|
|
kind: static ConsensusFork): auto =
|
2024-04-09 14:54:05 +00:00
|
|
|
when kind == ConsensusFork.Electra:
|
|
|
|
typedesc[electra_mev.BlindedBeaconBlock]
|
|
|
|
elif kind == ConsensusFork.Deneb:
|
2023-11-28 23:30:14 +00:00
|
|
|
typedesc[deneb_mev.BlindedBeaconBlock]
|
|
|
|
else:
|
|
|
|
{.error: "BlindedBlockContents does not support " & $kind.}
|
|
|
|
|
2023-12-07 17:10:22 +00:00
|
|
|
template PayloadAttributes*(
|
|
|
|
kind: static ConsensusFork): auto =
|
2023-12-08 02:50:38 +00:00
|
|
|
# This also determines what `engine_forkchoiceUpdated` version will be used.
|
2023-12-07 17:10:22 +00:00
|
|
|
when kind >= ConsensusFork.Deneb:
|
|
|
|
typedesc[PayloadAttributesV3]
|
|
|
|
elif kind >= ConsensusFork.Capella:
|
2023-12-08 02:50:38 +00:00
|
|
|
# https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.3/src/engine/shanghai.md#specification-1
|
|
|
|
# Consensus layer client MUST call this method instead of
|
|
|
|
# `engine_forkchoiceUpdatedV1` under any of the following conditions:
|
|
|
|
# `headBlockHash` references a block which `timestamp` is greater or
|
|
|
|
# equal to the Shanghai timestamp
|
2023-12-07 17:10:22 +00:00
|
|
|
typedesc[PayloadAttributesV2]
|
|
|
|
elif kind >= ConsensusFork.Bellatrix:
|
|
|
|
typedesc[PayloadAttributesV1]
|
|
|
|
else:
|
|
|
|
{.error: "PayloadAttributes does not support " & $kind.}
|
|
|
|
|
2024-02-06 18:57:53 +00:00
|
|
|
# `eth2_merkleization` cannot import `forks` (circular), so the check is here
|
2024-04-03 14:43:43 +00:00
|
|
|
static: doAssert ConsensusFork.high == ConsensusFork.Electra,
|
2024-02-25 19:42:44 +00:00
|
|
|
"eth2_merkleization has been checked and `hash_tree_root` is up to date"
|
2024-02-06 18:57:53 +00:00
|
|
|
|
2022-12-13 15:58:59 +00:00
|
|
|
# TODO when https://github.com/nim-lang/Nim/issues/21086 fixed, use return type
|
|
|
|
# `ref T`
|
|
|
|
func new*(T: type ForkedHashedBeaconState, data: phase0.BeaconState):
|
|
|
|
ref ForkedHashedBeaconState =
|
2023-01-28 19:53:41 +00:00
|
|
|
(ref T)(kind: ConsensusFork.Phase0, phase0Data: phase0.HashedBeaconState(
|
2022-12-13 15:58:59 +00:00
|
|
|
data: data, root: hash_tree_root(data)))
|
|
|
|
func new*(T: type ForkedHashedBeaconState, data: altair.BeaconState):
|
|
|
|
ref ForkedHashedBeaconState =
|
2023-01-28 19:53:41 +00:00
|
|
|
(ref T)(kind: ConsensusFork.Altair, altairData: altair.HashedBeaconState(
|
2022-12-13 15:58:59 +00:00
|
|
|
data: data, root: hash_tree_root(data)))
|
|
|
|
func new*(T: type ForkedHashedBeaconState, data: bellatrix.BeaconState):
|
|
|
|
ref ForkedHashedBeaconState =
|
2023-01-28 19:53:41 +00:00
|
|
|
(ref T)(kind: ConsensusFork.Bellatrix, bellatrixData: bellatrix.HashedBeaconState(
|
2022-12-13 15:58:59 +00:00
|
|
|
data: data, root: hash_tree_root(data)))
|
|
|
|
func new*(T: type ForkedHashedBeaconState, data: capella.BeaconState):
|
|
|
|
ref ForkedHashedBeaconState =
|
2023-01-28 19:53:41 +00:00
|
|
|
(ref T)(kind: ConsensusFork.Capella, capellaData: capella.HashedBeaconState(
|
2022-12-13 15:58:59 +00:00
|
|
|
data: data, root: hash_tree_root(data)))
|
2023-02-20 08:45:49 +00:00
|
|
|
func new*(T: type ForkedHashedBeaconState, data: deneb.BeaconState):
|
2022-12-13 15:58:59 +00:00
|
|
|
ref ForkedHashedBeaconState =
|
2023-03-04 22:23:52 +00:00
|
|
|
(ref T)(kind: ConsensusFork.Deneb, denebData: deneb.HashedBeaconState(
|
2022-12-13 15:58:59 +00:00
|
|
|
data: data, root: hash_tree_root(data)))
|
2024-04-23 07:58:32 +00:00
|
|
|
func new*(T: type ForkedHashedBeaconState, data: electra.BeaconState):
|
|
|
|
ref ForkedHashedBeaconState =
|
|
|
|
(ref T)(kind: ConsensusFork.Electra, electraData: electra.HashedBeaconState(
|
|
|
|
data: data, root: hash_tree_root(data)))
|
2021-07-07 09:09:47 +00:00
|
|
|
|
2021-08-27 09:00:06 +00:00
|
|
|
template init*(T: type ForkedBeaconBlock, blck: phase0.BeaconBlock): T =
|
2023-01-28 19:53:41 +00:00
|
|
|
T(kind: ConsensusFork.Phase0, phase0Data: blck)
|
2021-08-27 09:00:06 +00:00
|
|
|
template init*(T: type ForkedBeaconBlock, blck: altair.BeaconBlock): T =
|
2023-01-28 19:53:41 +00:00
|
|
|
T(kind: ConsensusFork.Altair, altairData: blck)
|
2022-01-06 11:25:35 +00:00
|
|
|
template init*(T: type ForkedBeaconBlock, blck: bellatrix.BeaconBlock): T =
|
2023-01-28 19:53:41 +00:00
|
|
|
T(kind: ConsensusFork.Bellatrix, bellatrixData: blck)
|
2022-11-24 07:53:04 +00:00
|
|
|
template init*(T: type ForkedBeaconBlock, blck: capella.BeaconBlock): T =
|
2023-01-28 19:53:41 +00:00
|
|
|
T(kind: ConsensusFork.Capella, capellaData: blck)
|
2023-02-20 08:45:49 +00:00
|
|
|
template init*(T: type ForkedBeaconBlock, blck: deneb.BeaconBlock): T =
|
2023-03-04 22:23:52 +00:00
|
|
|
T(kind: ConsensusFork.Deneb, denebData: blck)
|
2024-04-04 03:17:31 +00:00
|
|
|
template init*(T: type ForkedBeaconBlock, blck: electra.BeaconBlock): T =
|
|
|
|
T(kind: ConsensusFork.Electra, electraData: blck)
|
2021-08-27 09:00:06 +00:00
|
|
|
|
2021-07-14 12:18:52 +00:00
|
|
|
template init*(T: type ForkedSignedBeaconBlock, blck: phase0.SignedBeaconBlock): T =
|
2023-01-28 19:53:41 +00:00
|
|
|
T(kind: ConsensusFork.Phase0, phase0Data: blck)
|
2021-07-14 12:18:52 +00:00
|
|
|
template init*(T: type ForkedSignedBeaconBlock, blck: altair.SignedBeaconBlock): T =
|
2023-01-28 19:53:41 +00:00
|
|
|
T(kind: ConsensusFork.Altair, altairData: blck)
|
2022-01-06 11:25:35 +00:00
|
|
|
template init*(T: type ForkedSignedBeaconBlock, blck: bellatrix.SignedBeaconBlock): T =
|
2023-01-28 19:53:41 +00:00
|
|
|
T(kind: ConsensusFork.Bellatrix, bellatrixData: blck)
|
2022-11-02 16:23:30 +00:00
|
|
|
template init*(T: type ForkedSignedBeaconBlock, blck: capella.SignedBeaconBlock): T =
|
2023-01-28 19:53:41 +00:00
|
|
|
T(kind: ConsensusFork.Capella, capellaData: blck)
|
2023-02-20 08:45:49 +00:00
|
|
|
template init*(T: type ForkedSignedBeaconBlock, blck: deneb.SignedBeaconBlock): T =
|
2023-03-04 22:23:52 +00:00
|
|
|
T(kind: ConsensusFork.Deneb, denebData: blck)
|
2024-04-03 14:43:43 +00:00
|
|
|
template init*(T: type ForkedSignedBeaconBlock, blck: electra.SignedBeaconBlock): T =
|
|
|
|
T(kind: ConsensusFork.Electra, electraData: blck)
|
2021-07-14 12:18:52 +00:00
|
|
|
|
2022-11-24 09:14:05 +00:00
|
|
|
func init*(T: type ForkedSignedBeaconBlock, forked: ForkedBeaconBlock,
|
|
|
|
blockRoot: Eth2Digest, signature: ValidatorSig): T =
|
2021-08-27 09:00:06 +00:00
|
|
|
case forked.kind
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Phase0:
|
|
|
|
T(kind: ConsensusFork.Phase0,
|
2021-10-18 16:37:27 +00:00
|
|
|
phase0Data: phase0.SignedBeaconBlock(message: forked.phase0Data,
|
2021-11-05 07:34:34 +00:00
|
|
|
root: blockRoot,
|
|
|
|
signature: signature))
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Altair:
|
|
|
|
T(kind: ConsensusFork.Altair,
|
2021-10-18 16:37:27 +00:00
|
|
|
altairData: altair.SignedBeaconBlock(message: forked.altairData,
|
2021-11-05 07:34:34 +00:00
|
|
|
root: blockRoot,
|
|
|
|
signature: signature))
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Bellatrix:
|
|
|
|
T(kind: ConsensusFork.Bellatrix,
|
2022-01-24 16:23:13 +00:00
|
|
|
bellatrixData: bellatrix.SignedBeaconBlock(message: forked.bellatrixData,
|
|
|
|
root: blockRoot,
|
|
|
|
signature: signature))
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Capella:
|
|
|
|
T(kind: ConsensusFork.Capella,
|
2022-11-02 16:23:30 +00:00
|
|
|
capellaData: capella.SignedBeaconBlock(message: forked.capellaData,
|
|
|
|
root: blockRoot,
|
|
|
|
signature: signature))
|
2023-03-04 13:35:39 +00:00
|
|
|
of ConsensusFork.Deneb:
|
|
|
|
T(kind: ConsensusFork.Deneb,
|
2023-03-04 22:23:52 +00:00
|
|
|
denebData: deneb.SignedBeaconBlock(message: forked.denebData,
|
|
|
|
root: blockRoot,
|
|
|
|
signature: signature))
|
2024-04-03 14:43:43 +00:00
|
|
|
of ConsensusFork.Electra:
|
|
|
|
T(kind: ConsensusFork.Electra,
|
|
|
|
electraData: electra.SignedBeaconBlock(message: forked.electraData,
|
|
|
|
root: blockRoot,
|
|
|
|
signature: signature))
|
2021-08-27 09:00:06 +00:00
|
|
|
|
2022-11-24 09:14:05 +00:00
|
|
|
func init*(T: type ForkedSignedBlindedBeaconBlock,
|
|
|
|
forked: ForkedBlindedBeaconBlock, blockRoot: Eth2Digest,
|
|
|
|
signature: ValidatorSig): T =
|
|
|
|
case forked.kind
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Phase0:
|
|
|
|
T(kind: ConsensusFork.Phase0,
|
2022-11-24 09:14:05 +00:00
|
|
|
phase0Data: phase0.SignedBeaconBlock(message: forked.phase0Data,
|
|
|
|
root: blockRoot,
|
|
|
|
signature: signature))
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Altair:
|
|
|
|
T(kind: ConsensusFork.Altair,
|
2022-11-24 09:14:05 +00:00
|
|
|
altairData: altair.SignedBeaconBlock(message: forked.altairData,
|
|
|
|
root: blockRoot,
|
|
|
|
signature: signature))
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Bellatrix:
|
|
|
|
T(kind: ConsensusFork.Bellatrix,
|
2023-08-08 00:05:17 +00:00
|
|
|
bellatrixData: default(bellatrix_mev.SignedBlindedBeaconBlock))
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Capella:
|
|
|
|
T(kind: ConsensusFork.Capella,
|
2023-02-21 13:21:38 +00:00
|
|
|
capellaData: capella_mev.SignedBlindedBeaconBlock(message: forked.capellaData,
|
|
|
|
signature: signature))
|
2023-03-04 13:35:39 +00:00
|
|
|
of ConsensusFork.Deneb:
|
|
|
|
T(kind: ConsensusFork.Deneb,
|
2023-10-20 01:39:47 +00:00
|
|
|
denebData: deneb_mev.SignedBlindedBeaconBlock(message: forked.denebData,
|
|
|
|
signature: signature))
|
2024-04-03 14:43:43 +00:00
|
|
|
of ConsensusFork.Electra:
|
|
|
|
T(kind: ConsensusFork.Electra,
|
2024-04-08 12:49:03 +00:00
|
|
|
electraData: electra_mev.SignedBlindedBeaconBlock(message: forked.electraData,
|
|
|
|
signature: signature))
|
2022-11-24 09:14:05 +00:00
|
|
|
|
2024-02-02 15:24:40 +00:00
|
|
|
template init*(T: type ForkedSignedBlindedBeaconBlock,
|
|
|
|
blck: capella_mev.BlindedBeaconBlock, blockRoot: Eth2Digest,
|
|
|
|
signature: ValidatorSig): T =
|
|
|
|
T(kind: ConsensusFork.Capella,
|
|
|
|
capellaData: capella_mev.SignedBlindedBeaconBlock(
|
|
|
|
message: blck, signature: signature))
|
|
|
|
|
|
|
|
template init*(T: type ForkedSignedBlindedBeaconBlock,
|
|
|
|
blck: deneb_mev.BlindedBeaconBlock, blockRoot: Eth2Digest,
|
|
|
|
signature: ValidatorSig): T =
|
|
|
|
T(kind: ConsensusFork.Deneb,
|
|
|
|
denebData: deneb_mev.SignedBlindedBeaconBlock(
|
|
|
|
message: blck, signature: signature))
|
|
|
|
|
2024-04-08 12:49:03 +00:00
|
|
|
template init*(T: type ForkedSignedBlindedBeaconBlock,
|
|
|
|
blck: electra_mev.BlindedBeaconBlock, blockRoot: Eth2Digest,
|
|
|
|
signature: ValidatorSig): T =
|
|
|
|
T(kind: ConsensusFork.Electra,
|
|
|
|
electraData: electra_mev.SignedBlindedBeaconBlock(
|
|
|
|
message: blck, signature: signature))
|
|
|
|
|
2022-06-10 14:16:37 +00:00
|
|
|
template init*(T: type ForkedMsgTrustedSignedBeaconBlock, blck: phase0.MsgTrustedSignedBeaconBlock): T =
|
2023-01-28 19:53:41 +00:00
|
|
|
T(kind: ConsensusFork.Phase0, phase0Data: blck)
|
2022-06-10 14:16:37 +00:00
|
|
|
template init*(T: type ForkedMsgTrustedSignedBeaconBlock, blck: altair.MsgTrustedSignedBeaconBlock): T =
|
2023-01-28 19:53:41 +00:00
|
|
|
T(kind: ConsensusFork.Altair, altairData: blck)
|
2022-06-10 14:16:37 +00:00
|
|
|
template init*(T: type ForkedMsgTrustedSignedBeaconBlock, blck: bellatrix.MsgTrustedSignedBeaconBlock): T =
|
2023-01-28 19:53:41 +00:00
|
|
|
T(kind: ConsensusFork.Bellatrix, bellatrixData: blck)
|
2022-11-02 16:23:30 +00:00
|
|
|
template init*(T: type ForkedMsgTrustedSignedBeaconBlock, blck: capella.MsgTrustedSignedBeaconBlock): T =
|
2023-01-28 19:53:41 +00:00
|
|
|
T(kind: ConsensusFork.Capella, capellaData: blck)
|
2023-02-20 08:45:49 +00:00
|
|
|
template init*(T: type ForkedMsgTrustedSignedBeaconBlock, blck: deneb.MsgTrustedSignedBeaconBlock): T =
|
2023-03-11 00:28:19 +00:00
|
|
|
T(kind: ConsensusFork.Deneb, denebData: blck)
|
2022-12-05 16:29:09 +00:00
|
|
|
|
2021-07-14 12:18:52 +00:00
|
|
|
template init*(T: type ForkedTrustedSignedBeaconBlock, blck: phase0.TrustedSignedBeaconBlock): T =
|
2023-01-28 19:53:41 +00:00
|
|
|
T(kind: ConsensusFork.Phase0, phase0Data: blck)
|
2021-07-14 12:18:52 +00:00
|
|
|
template init*(T: type ForkedTrustedSignedBeaconBlock, blck: altair.TrustedSignedBeaconBlock): T =
|
2023-01-28 19:53:41 +00:00
|
|
|
T(kind: ConsensusFork.Altair, altairData: blck)
|
2022-01-06 11:25:35 +00:00
|
|
|
template init*(T: type ForkedTrustedSignedBeaconBlock, blck: bellatrix.TrustedSignedBeaconBlock): T =
|
2023-01-28 19:53:41 +00:00
|
|
|
T(kind: ConsensusFork.Bellatrix, bellatrixData: blck)
|
2022-11-02 16:23:30 +00:00
|
|
|
template init*(T: type ForkedTrustedSignedBeaconBlock, blck: capella.TrustedSignedBeaconBlock): T =
|
2023-01-28 19:53:41 +00:00
|
|
|
T(kind: ConsensusFork.Capella, capellaData: blck)
|
2023-02-20 08:45:49 +00:00
|
|
|
template init*(T: type ForkedTrustedSignedBeaconBlock, blck: deneb.TrustedSignedBeaconBlock): T =
|
2023-03-04 22:23:52 +00:00
|
|
|
T(kind: ConsensusFork.Deneb, denebData: blck)
|
2024-04-03 14:43:43 +00:00
|
|
|
template init*(T: type ForkedTrustedSignedBeaconBlock, blck: electra.TrustedSignedBeaconBlock): T =
|
|
|
|
T(kind: ConsensusFork.Electra, electraData: blck)
|
2021-07-14 12:18:52 +00:00
|
|
|
|
2023-01-28 19:53:41 +00:00
|
|
|
template toString*(kind: ConsensusFork): string =
|
2022-06-20 05:53:39 +00:00
|
|
|
case kind
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Phase0:
|
2022-06-20 05:53:39 +00:00
|
|
|
"phase0"
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Altair:
|
2022-06-20 05:53:39 +00:00
|
|
|
"altair"
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Bellatrix:
|
2022-06-20 05:53:39 +00:00
|
|
|
"bellatrix"
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Capella:
|
2022-11-02 16:23:30 +00:00
|
|
|
"capella"
|
2023-03-04 13:35:39 +00:00
|
|
|
of ConsensusFork.Deneb:
|
|
|
|
"deneb"
|
2024-04-03 14:43:43 +00:00
|
|
|
of ConsensusFork.Electra:
|
|
|
|
"electra"
|
2022-06-20 05:53:39 +00:00
|
|
|
|
2023-11-28 23:30:14 +00:00
|
|
|
template init*(T: typedesc[ConsensusFork], value: string): Opt[ConsensusFork] =
|
|
|
|
case value
|
2024-04-03 14:43:43 +00:00
|
|
|
of "electra":
|
|
|
|
Opt.some ConsensusFork.Electra
|
2023-11-28 23:30:14 +00:00
|
|
|
of "deneb":
|
|
|
|
Opt.some ConsensusFork.Deneb
|
|
|
|
of "capella":
|
|
|
|
Opt.some ConsensusFork.Capella
|
|
|
|
of "bellatrix":
|
|
|
|
Opt.some ConsensusFork.Bellatrix
|
|
|
|
of "altair":
|
|
|
|
Opt.some ConsensusFork.Altair
|
|
|
|
of "phase0":
|
|
|
|
Opt.some ConsensusFork.Phase0
|
|
|
|
else:
|
|
|
|
Opt.none(ConsensusFork)
|
|
|
|
|
|
|
|
static:
|
|
|
|
for fork in ConsensusFork:
|
|
|
|
doAssert ConsensusFork.init(fork.toString()).expect("init defined") == fork
|
|
|
|
|
2021-10-13 14:24:36 +00:00
|
|
|
template init*(T: type ForkedEpochInfo, info: phase0.EpochInfo): T =
|
2021-10-18 16:37:27 +00:00
|
|
|
T(kind: EpochInfoFork.Phase0, phase0Data: info)
|
2021-10-13 14:24:36 +00:00
|
|
|
template init*(T: type ForkedEpochInfo, info: altair.EpochInfo): T =
|
2021-10-18 16:37:27 +00:00
|
|
|
T(kind: EpochInfoFork.Altair, altairData: info)
|
2021-10-13 14:24:36 +00:00
|
|
|
|
2021-09-28 18:08:03 +00:00
|
|
|
template withState*(x: ForkedHashedBeaconState, body: untyped): untyped =
|
2021-10-18 16:37:27 +00:00
|
|
|
case x.kind
|
2024-04-03 14:43:43 +00:00
|
|
|
of ConsensusFork.Electra:
|
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Electra
|
|
|
|
template forkyState: untyped {.inject, used.} = x.electraData
|
|
|
|
body
|
2023-03-04 13:35:39 +00:00
|
|
|
of ConsensusFork.Deneb:
|
2023-03-11 00:35:52 +00:00
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Deneb
|
2023-03-04 22:23:52 +00:00
|
|
|
template forkyState: untyped {.inject, used.} = x.denebData
|
2022-12-07 16:47:23 +00:00
|
|
|
body
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Capella:
|
2023-03-11 00:35:52 +00:00
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Capella
|
2022-11-02 16:23:30 +00:00
|
|
|
template forkyState: untyped {.inject, used.} = x.capellaData
|
|
|
|
body
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Bellatrix:
|
2023-03-11 00:35:52 +00:00
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Bellatrix
|
2022-08-26 14:14:18 +00:00
|
|
|
template forkyState: untyped {.inject, used.} = x.bellatrixData
|
2021-09-28 18:08:03 +00:00
|
|
|
body
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Altair:
|
2023-03-11 00:35:52 +00:00
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Altair
|
2022-08-26 14:14:18 +00:00
|
|
|
template forkyState: untyped {.inject, used.} = x.altairData
|
2021-09-28 18:08:03 +00:00
|
|
|
body
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Phase0:
|
2023-03-11 00:35:52 +00:00
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Phase0
|
2022-08-26 14:14:18 +00:00
|
|
|
template forkyState: untyped {.inject, used.} = x.phase0Data
|
2021-09-28 18:08:03 +00:00
|
|
|
body
|
2021-06-11 17:51:46 +00:00
|
|
|
|
2023-11-15 02:21:03 +00:00
|
|
|
template forky*(
|
2023-11-28 23:30:14 +00:00
|
|
|
x:
|
|
|
|
ForkedBeaconBlock |
|
|
|
|
ForkedHashedBeaconState,
|
|
|
|
kind: static ConsensusFork): untyped =
|
2024-04-03 14:43:43 +00:00
|
|
|
when kind == ConsensusFork.Electra:
|
|
|
|
x.electraData
|
|
|
|
elif kind == ConsensusFork.Deneb:
|
2023-06-02 01:25:49 +00:00
|
|
|
x.denebData
|
|
|
|
elif kind == ConsensusFork.Capella:
|
|
|
|
x.capellaData
|
|
|
|
elif kind == ConsensusFork.Bellatrix:
|
|
|
|
x.bellatrixData
|
|
|
|
elif kind == ConsensusFork.Altair:
|
|
|
|
x.altairData
|
|
|
|
elif kind == ConsensusFork.Phase0:
|
|
|
|
x.phase0Data
|
|
|
|
else:
|
|
|
|
static: raiseAssert "Unreachable"
|
|
|
|
|
2021-10-13 14:24:36 +00:00
|
|
|
template withEpochInfo*(x: ForkedEpochInfo, body: untyped): untyped =
|
|
|
|
case x.kind
|
|
|
|
of EpochInfoFork.Phase0:
|
2023-11-01 04:53:09 +00:00
|
|
|
const infoFork {.inject, used.} = EpochInfoFork.Phase0
|
2021-10-18 16:37:27 +00:00
|
|
|
template info: untyped {.inject.} = x.phase0Data
|
2021-10-13 14:24:36 +00:00
|
|
|
body
|
|
|
|
of EpochInfoFork.Altair:
|
2023-11-01 04:53:09 +00:00
|
|
|
const infoFork {.inject, used.} = EpochInfoFork.Altair
|
2021-10-18 16:37:27 +00:00
|
|
|
template info: untyped {.inject.} = x.altairData
|
2021-10-13 14:24:36 +00:00
|
|
|
body
|
|
|
|
|
|
|
|
template withEpochInfo*(
|
|
|
|
state: phase0.BeaconState, x: var ForkedEpochInfo, body: untyped): untyped =
|
2022-12-01 12:36:44 +00:00
|
|
|
if x.kind != EpochInfoFork.Phase0:
|
|
|
|
# Rare, should never happen even, so efficiency a non-issue
|
|
|
|
x = ForkedEpochInfo(kind: EpochInfoFork.Phase0)
|
2021-10-18 16:37:27 +00:00
|
|
|
template info: untyped {.inject.} = x.phase0Data
|
2021-10-13 14:24:36 +00:00
|
|
|
body
|
|
|
|
|
|
|
|
template withEpochInfo*(
|
2022-12-07 16:47:23 +00:00
|
|
|
state: altair.BeaconState | bellatrix.BeaconState | capella.BeaconState |
|
2024-02-24 11:14:45 +00:00
|
|
|
deneb.BeaconState | electra.BeaconState,
|
2022-11-02 16:23:30 +00:00
|
|
|
x: var ForkedEpochInfo, body: untyped): untyped =
|
2022-12-01 12:36:44 +00:00
|
|
|
if x.kind != EpochInfoFork.Altair:
|
|
|
|
# Rare, so efficiency not critical
|
|
|
|
x = ForkedEpochInfo(kind: EpochInfoFork.Altair)
|
2021-10-18 16:37:27 +00:00
|
|
|
template info: untyped {.inject.} = x.altairData
|
2021-10-13 14:24:36 +00:00
|
|
|
body
|
|
|
|
|
2021-06-11 17:51:46 +00:00
|
|
|
func assign*(tgt: var ForkedHashedBeaconState, src: ForkedHashedBeaconState) =
|
2024-03-19 08:50:25 +00:00
|
|
|
if tgt.kind != src.kind:
|
|
|
|
# Avoid temporary with ref
|
|
|
|
tgt = (ref ForkedHashedBeaconState)(kind: src.kind)[]
|
|
|
|
|
|
|
|
withState(tgt):
|
|
|
|
template forkyTgt: untyped = forkyState
|
|
|
|
template forkySrc: untyped = src.forky(consensusFork)
|
|
|
|
assign(forkyTgt, forkySrc)
|
2021-06-11 17:51:46 +00:00
|
|
|
|
2021-09-28 18:08:03 +00:00
|
|
|
template getStateField*(x: ForkedHashedBeaconState, y: untyped): untyped =
|
2021-09-22 20:06:50 +00:00
|
|
|
# The use of `unsafeAddr` avoids excessive copying in certain situations, e.g.,
|
|
|
|
# ```
|
2022-05-10 10:03:40 +00:00
|
|
|
# for index, validator in getStateField(stateData.data, validators):
|
2021-09-22 20:06:50 +00:00
|
|
|
# ```
|
|
|
|
# Without `unsafeAddr`, the `validators` list would be copied to a temporary variable.
|
2023-06-12 12:03:59 +00:00
|
|
|
(block:
|
|
|
|
withState(x): unsafeAddr forkyState.data.y)[]
|
2021-06-11 17:51:46 +00:00
|
|
|
|
2021-09-28 18:08:03 +00:00
|
|
|
func getStateRoot*(x: ForkedHashedBeaconState): Eth2Digest =
|
2022-08-26 14:14:18 +00:00
|
|
|
withState(x): forkyState.root
|
2021-06-17 17:13:14 +00:00
|
|
|
|
2023-06-12 12:03:59 +00:00
|
|
|
{.push warning[ProveField]:off.} # https://github.com/nim-lang/Nim/issues/22060
|
2021-06-17 17:13:14 +00:00
|
|
|
func setStateRoot*(x: var ForkedHashedBeaconState, root: Eth2Digest) =
|
2022-08-26 14:14:18 +00:00
|
|
|
withState(x): forkyState.root = root
|
2023-06-12 12:03:59 +00:00
|
|
|
{.pop.}
|
2021-08-27 09:00:06 +00:00
|
|
|
|
2024-01-12 20:40:34 +00:00
|
|
|
func consensusForkEpoch*(
|
|
|
|
cfg: RuntimeConfig, consensusFork: ConsensusFork): Epoch =
|
|
|
|
case consensusFork
|
2024-04-03 14:43:43 +00:00
|
|
|
of ConsensusFork.Electra:
|
|
|
|
cfg.ELECTRA_FORK_EPOCH
|
2024-01-12 20:40:34 +00:00
|
|
|
of ConsensusFork.Deneb:
|
|
|
|
cfg.DENEB_FORK_EPOCH
|
|
|
|
of ConsensusFork.Capella:
|
|
|
|
cfg.CAPELLA_FORK_EPOCH
|
|
|
|
of ConsensusFork.Bellatrix:
|
|
|
|
cfg.BELLATRIX_FORK_EPOCH
|
|
|
|
of ConsensusFork.Altair:
|
|
|
|
cfg.ALTAIR_FORK_EPOCH
|
|
|
|
of ConsensusFork.Phase0:
|
|
|
|
GENESIS_EPOCH
|
|
|
|
|
2023-02-16 09:32:12 +00:00
|
|
|
func consensusForkAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): ConsensusFork =
|
2021-10-04 08:31:21 +00:00
|
|
|
## Return the current fork for the given epoch.
|
|
|
|
static:
|
2024-04-03 14:43:43 +00:00
|
|
|
doAssert high(ConsensusFork) == ConsensusFork.Electra
|
|
|
|
doAssert ConsensusFork.Electra > ConsensusFork.Deneb
|
2023-03-04 13:35:39 +00:00
|
|
|
doAssert ConsensusFork.Deneb > ConsensusFork.Capella
|
2023-01-28 19:53:41 +00:00
|
|
|
doAssert ConsensusFork.Capella > ConsensusFork.Bellatrix
|
|
|
|
doAssert ConsensusFork.Bellatrix > ConsensusFork.Altair
|
|
|
|
doAssert ConsensusFork.Altair > ConsensusFork.Phase0
|
2021-10-04 08:31:21 +00:00
|
|
|
doAssert GENESIS_EPOCH == 0
|
|
|
|
|
2024-04-03 14:43:43 +00:00
|
|
|
if epoch >= cfg.ELECTRA_FORK_EPOCH: ConsensusFork.Electra
|
|
|
|
elif epoch >= cfg.DENEB_FORK_EPOCH: ConsensusFork.Deneb
|
2023-01-28 19:53:41 +00:00
|
|
|
elif epoch >= cfg.CAPELLA_FORK_EPOCH: ConsensusFork.Capella
|
|
|
|
elif epoch >= cfg.BELLATRIX_FORK_EPOCH: ConsensusFork.Bellatrix
|
|
|
|
elif epoch >= cfg.ALTAIR_FORK_EPOCH: ConsensusFork.Altair
|
|
|
|
else: ConsensusFork.Phase0
|
2021-10-04 08:31:21 +00:00
|
|
|
|
2023-03-11 16:58:48 +00:00
|
|
|
func consensusForkForDigest*(
|
2023-01-28 19:53:41 +00:00
|
|
|
forkDigests: ForkDigests, forkDigest: ForkDigest): Opt[ConsensusFork] =
|
2024-04-03 14:43:43 +00:00
|
|
|
static: doAssert high(ConsensusFork) == ConsensusFork.Electra
|
|
|
|
if forkDigest == forkDigests.electra:
|
|
|
|
ok ConsensusFork.Electra
|
|
|
|
elif forkDigest == forkDigests.deneb:
|
2023-03-04 13:35:39 +00:00
|
|
|
ok ConsensusFork.Deneb
|
2022-12-06 16:43:11 +00:00
|
|
|
elif forkDigest == forkDigests.capella:
|
2023-01-28 19:53:41 +00:00
|
|
|
ok ConsensusFork.Capella
|
2022-11-02 16:23:30 +00:00
|
|
|
elif forkDigest == forkDigests.bellatrix:
|
2023-01-28 19:53:41 +00:00
|
|
|
ok ConsensusFork.Bellatrix
|
2022-05-23 12:02:54 +00:00
|
|
|
elif forkDigest == forkDigests.altair:
|
2023-01-28 19:53:41 +00:00
|
|
|
ok ConsensusFork.Altair
|
2022-05-23 12:02:54 +00:00
|
|
|
elif forkDigest == forkDigests.phase0:
|
2023-01-28 19:53:41 +00:00
|
|
|
ok ConsensusFork.Phase0
|
2022-05-23 12:02:54 +00:00
|
|
|
else:
|
|
|
|
err()
|
2021-10-18 12:32:54 +00:00
|
|
|
|
2023-03-11 14:39:29 +00:00
|
|
|
func atConsensusFork*(
|
2023-03-11 00:35:52 +00:00
|
|
|
forkDigests: ForkDigests, consensusFork: ConsensusFork): ForkDigest =
|
|
|
|
case consensusFork
|
2024-04-03 14:43:43 +00:00
|
|
|
of ConsensusFork.Electra:
|
|
|
|
forkDigests.electra
|
2023-03-04 13:35:39 +00:00
|
|
|
of ConsensusFork.Deneb:
|
2023-03-10 17:13:40 +00:00
|
|
|
forkDigests.deneb
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Capella:
|
2022-11-02 16:23:30 +00:00
|
|
|
forkDigests.capella
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Bellatrix:
|
2022-05-31 10:45:37 +00:00
|
|
|
forkDigests.bellatrix
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Altair:
|
2022-05-31 10:45:37 +00:00
|
|
|
forkDigests.altair
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Phase0:
|
2022-05-31 10:45:37 +00:00
|
|
|
forkDigests.phase0
|
|
|
|
|
|
|
|
template atEpoch*(
|
|
|
|
forkDigests: ForkDigests, epoch: Epoch, cfg: RuntimeConfig): ForkDigest =
|
2023-03-11 14:39:29 +00:00
|
|
|
forkDigests.atConsensusFork(cfg.consensusForkAtEpoch(epoch))
|
2022-05-31 10:45:37 +00:00
|
|
|
|
2022-06-10 14:16:37 +00:00
|
|
|
template asSigned*(
|
|
|
|
x: ForkedMsgTrustedSignedBeaconBlock |
|
2022-08-25 03:53:59 +00:00
|
|
|
ForkedTrustedSignedBeaconBlock
|
|
|
|
): ForkedSignedBeaconBlock =
|
2021-07-14 12:18:52 +00:00
|
|
|
isomorphicCast[ForkedSignedBeaconBlock](x)
|
|
|
|
|
2022-08-25 03:53:59 +00:00
|
|
|
template asSigned*(
|
|
|
|
x: ref ForkedMsgTrustedSignedBeaconBlock |
|
|
|
|
ref ForkedTrustedSignedBeaconBlock
|
|
|
|
): ref ForkedSignedBeaconBlock =
|
|
|
|
isomorphicCast[ref ForkedSignedBeaconBlock](x)
|
|
|
|
|
2022-06-10 14:16:37 +00:00
|
|
|
template asMsgTrusted*(
|
|
|
|
x: ForkedSignedBeaconBlock |
|
2022-08-25 03:53:59 +00:00
|
|
|
ForkedTrustedSignedBeaconBlock
|
|
|
|
): ForkedMsgTrustedSignedBeaconBlock =
|
2022-06-10 14:16:37 +00:00
|
|
|
isomorphicCast[ForkedMsgTrustedSignedBeaconBlock](x)
|
|
|
|
|
2022-08-25 03:53:59 +00:00
|
|
|
template asMsgTrusted*(
|
|
|
|
x: ref ForkedSignedBeaconBlock |
|
|
|
|
ref ForkedTrustedSignedBeaconBlock
|
|
|
|
): ref ForkedMsgTrustedSignedBeaconBlock =
|
|
|
|
isomorphicCast[ref ForkedMsgTrustedSignedBeaconBlock](x)
|
|
|
|
|
2022-06-10 14:16:37 +00:00
|
|
|
template asTrusted*(
|
|
|
|
x: ForkedSignedBeaconBlock |
|
2022-08-25 03:53:59 +00:00
|
|
|
ForkedMsgTrustedSignedBeaconBlock
|
|
|
|
): ForkedTrustedSignedBeaconBlock =
|
2021-07-14 12:18:52 +00:00
|
|
|
isomorphicCast[ForkedTrustedSignedBeaconBlock](x)
|
|
|
|
|
2022-08-25 03:53:59 +00:00
|
|
|
template asTrusted*(
|
|
|
|
x: ref ForkedSignedBeaconBlock |
|
|
|
|
ref ForkedMsgTrustedSignedBeaconBlock
|
|
|
|
): ref ForkedTrustedSignedBeaconBlock =
|
|
|
|
isomorphicCast[ref ForkedTrustedSignedBeaconBlock](x)
|
|
|
|
|
2021-10-06 17:05:06 +00:00
|
|
|
template withBlck*(
|
2023-06-29 09:36:43 +00:00
|
|
|
x: ForkedBeaconBlock |
|
2022-06-10 14:16:37 +00:00
|
|
|
ForkedSignedBeaconBlock | ForkedMsgTrustedSignedBeaconBlock |
|
2022-11-24 09:14:05 +00:00
|
|
|
ForkedTrustedSignedBeaconBlock | ForkedBlindedBeaconBlock |
|
|
|
|
ForkedSignedBlindedBeaconBlock,
|
2021-10-06 17:05:06 +00:00
|
|
|
body: untyped): untyped =
|
2021-07-14 12:18:52 +00:00
|
|
|
case x.kind
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Phase0:
|
2023-03-11 00:35:52 +00:00
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Phase0
|
2023-11-01 04:53:09 +00:00
|
|
|
template forkyBlck: untyped {.inject, used.} = x.phase0Data
|
2021-07-14 12:18:52 +00:00
|
|
|
body
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Altair:
|
2023-03-11 00:35:52 +00:00
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Altair
|
2023-11-01 04:53:09 +00:00
|
|
|
template forkyBlck: untyped {.inject, used.} = x.altairData
|
2021-07-14 12:18:52 +00:00
|
|
|
body
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Bellatrix:
|
2023-03-11 00:35:52 +00:00
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Bellatrix
|
2023-11-11 08:49:34 +00:00
|
|
|
template forkyBlck: untyped {.inject, used.} = x.bellatrixData
|
2021-09-27 14:22:58 +00:00
|
|
|
body
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Capella:
|
2023-03-11 00:35:52 +00:00
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Capella
|
2023-11-01 04:53:09 +00:00
|
|
|
template forkyBlck: untyped {.inject, used.} = x.capellaData
|
2022-11-02 16:23:30 +00:00
|
|
|
body
|
2023-03-04 13:35:39 +00:00
|
|
|
of ConsensusFork.Deneb:
|
2023-03-11 00:35:52 +00:00
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Deneb
|
2023-11-01 04:53:09 +00:00
|
|
|
template forkyBlck: untyped {.inject, used.} = x.denebData
|
2022-12-05 16:29:09 +00:00
|
|
|
body
|
2024-04-03 14:43:43 +00:00
|
|
|
of ConsensusFork.Electra:
|
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Electra
|
|
|
|
template forkyBlck: untyped {.inject, used.} = x.electraData
|
|
|
|
body
|
2021-07-14 12:18:52 +00:00
|
|
|
|
2021-09-28 18:08:03 +00:00
|
|
|
func proposer_index*(x: ForkedBeaconBlock): uint64 =
|
2023-09-21 10:49:14 +00:00
|
|
|
withBlck(x): forkyBlck.proposer_index
|
2021-09-28 18:08:03 +00:00
|
|
|
|
2023-06-29 09:36:43 +00:00
|
|
|
func hash_tree_root*(x: ForkedBeaconBlock): Eth2Digest =
|
2023-09-21 10:49:14 +00:00
|
|
|
withBlck(x): hash_tree_root(forkyBlck)
|
2021-09-28 18:08:03 +00:00
|
|
|
|
2023-06-29 09:36:43 +00:00
|
|
|
func hash_tree_root*(x: Web3SignerForkedBeaconBlock): Eth2Digest =
|
|
|
|
hash_tree_root(x.data)
|
|
|
|
|
2023-11-11 05:33:54 +00:00
|
|
|
func hash_tree_root*(_: Opt[auto]) {.error.}
|
|
|
|
|
2022-06-10 14:16:37 +00:00
|
|
|
template getForkedBlockField*(
|
|
|
|
x: ForkedSignedBeaconBlock |
|
|
|
|
ForkedMsgTrustedSignedBeaconBlock |
|
|
|
|
ForkedTrustedSignedBeaconBlock,
|
|
|
|
y: untyped): untyped =
|
2021-09-28 18:08:03 +00:00
|
|
|
# unsafeAddr avoids a copy of the field in some cases
|
|
|
|
(case x.kind
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Phase0: unsafeAddr x.phase0Data.message.y
|
|
|
|
of ConsensusFork.Altair: unsafeAddr x.altairData.message.y
|
|
|
|
of ConsensusFork.Bellatrix: unsafeAddr x.bellatrixData.message.y
|
|
|
|
of ConsensusFork.Capella: unsafeAddr x.capellaData.message.y
|
2024-04-03 14:43:43 +00:00
|
|
|
of ConsensusFork.Deneb: unsafeAddr x.denebData.message.y
|
|
|
|
of ConsensusFork.Electra: unsafeAddr x.electraData.message.y)[]
|
2021-07-14 12:18:52 +00:00
|
|
|
|
2022-06-10 14:16:37 +00:00
|
|
|
template signature*(x: ForkedSignedBeaconBlock |
|
2022-11-24 09:14:05 +00:00
|
|
|
ForkedMsgTrustedSignedBeaconBlock |
|
|
|
|
ForkedSignedBlindedBeaconBlock): ValidatorSig =
|
2023-09-21 10:49:14 +00:00
|
|
|
withBlck(x): forkyBlck.signature
|
2021-07-14 12:18:52 +00:00
|
|
|
|
|
|
|
template signature*(x: ForkedTrustedSignedBeaconBlock): TrustedSig =
|
2023-09-21 10:49:14 +00:00
|
|
|
withBlck(x): forkyBlck.signature
|
2021-07-14 12:18:52 +00:00
|
|
|
|
2022-06-10 14:16:37 +00:00
|
|
|
template root*(x: ForkedSignedBeaconBlock |
|
|
|
|
ForkedMsgTrustedSignedBeaconBlock |
|
|
|
|
ForkedTrustedSignedBeaconBlock): Eth2Digest =
|
2023-09-21 10:49:14 +00:00
|
|
|
withBlck(x): forkyBlck.root
|
2021-07-14 12:18:52 +00:00
|
|
|
|
2022-06-10 14:16:37 +00:00
|
|
|
template slot*(x: ForkedSignedBeaconBlock |
|
|
|
|
ForkedMsgTrustedSignedBeaconBlock |
|
|
|
|
ForkedTrustedSignedBeaconBlock): Slot =
|
2023-09-21 10:49:14 +00:00
|
|
|
withBlck(x): forkyBlck.message.slot
|
2021-07-07 09:09:47 +00:00
|
|
|
|
2022-11-24 09:14:05 +00:00
|
|
|
template shortLog*(x: ForkedBeaconBlock | ForkedBlindedBeaconBlock): auto =
|
2023-09-21 10:49:14 +00:00
|
|
|
withBlck(x): shortLog(forkyBlck)
|
2021-08-27 09:00:06 +00:00
|
|
|
|
2022-06-10 14:16:37 +00:00
|
|
|
template shortLog*(x: ForkedSignedBeaconBlock |
|
|
|
|
ForkedMsgTrustedSignedBeaconBlock |
|
2022-11-24 09:14:05 +00:00
|
|
|
ForkedTrustedSignedBeaconBlock |
|
|
|
|
ForkedSignedBlindedBeaconBlock): auto =
|
2023-09-21 10:49:14 +00:00
|
|
|
withBlck(x): shortLog(forkyBlck)
|
2021-07-07 09:09:47 +00:00
|
|
|
|
2021-08-27 09:00:06 +00:00
|
|
|
chronicles.formatIt ForkedBeaconBlock: it.shortLog
|
2021-07-14 12:18:52 +00:00
|
|
|
chronicles.formatIt ForkedSignedBeaconBlock: it.shortLog
|
2022-06-10 14:16:37 +00:00
|
|
|
chronicles.formatIt ForkedMsgTrustedSignedBeaconBlock: it.shortLog
|
2021-07-14 12:18:52 +00:00
|
|
|
chronicles.formatIt ForkedTrustedSignedBeaconBlock: it.shortLog
|
2021-08-09 12:54:45 +00:00
|
|
|
|
2023-11-28 23:30:14 +00:00
|
|
|
template withForkyMaybeBlindedBlck*(
|
|
|
|
b: ForkedMaybeBlindedBeaconBlock,
|
|
|
|
body: untyped): untyped =
|
|
|
|
case b.kind
|
2024-04-03 14:43:43 +00:00
|
|
|
of ConsensusFork.Electra:
|
2024-04-08 12:49:03 +00:00
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Electra
|
|
|
|
template d: untyped = b.electraData
|
|
|
|
case d.isBlinded:
|
|
|
|
of true:
|
|
|
|
const isBlinded {.inject, used.} = true
|
|
|
|
template forkyMaybeBlindedBlck: untyped {.inject, used.} = d.blindedData
|
|
|
|
body
|
|
|
|
of false:
|
|
|
|
const isBlinded {.inject, used.} = false
|
|
|
|
template forkyMaybeBlindedBlck: untyped {.inject, used.} = d.data
|
|
|
|
body
|
2023-11-28 23:30:14 +00:00
|
|
|
of ConsensusFork.Deneb:
|
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Deneb
|
|
|
|
template d: untyped = b.denebData
|
|
|
|
case d.isBlinded:
|
|
|
|
of true:
|
|
|
|
const isBlinded {.inject, used.} = true
|
|
|
|
template forkyMaybeBlindedBlck: untyped {.inject, used.} = d.blindedData
|
|
|
|
body
|
|
|
|
of false:
|
|
|
|
const isBlinded {.inject, used.} = false
|
|
|
|
template forkyMaybeBlindedBlck: untyped {.inject, used.} = d.data
|
|
|
|
body
|
|
|
|
of ConsensusFork.Capella:
|
2024-02-28 18:27:26 +00:00
|
|
|
const
|
|
|
|
consensusFork {.inject, used.} = ConsensusFork.Capella
|
|
|
|
isBlinded {.inject, used.} = false
|
|
|
|
template forkyMaybeBlindedBlck: untyped {.inject, used.} = b.capellaData
|
|
|
|
body
|
2023-11-28 23:30:14 +00:00
|
|
|
of ConsensusFork.Bellatrix:
|
|
|
|
const
|
|
|
|
consensusFork {.inject, used.} = ConsensusFork.Bellatrix
|
|
|
|
isBlinded {.inject, used.} = false
|
|
|
|
template forkyMaybeBlindedBlck: untyped {.inject, used.} = b.bellatrixData
|
|
|
|
body
|
|
|
|
of ConsensusFork.Altair:
|
|
|
|
const
|
|
|
|
consensusFork {.inject, used.} = ConsensusFork.Altair
|
|
|
|
isBlinded {.inject, used.} = false
|
|
|
|
template forkyMaybeBlindedBlck: untyped {.inject, used.} = b.altairData
|
|
|
|
body
|
|
|
|
of ConsensusFork.Phase0:
|
|
|
|
const
|
|
|
|
consensusFork {.inject, used.} = ConsensusFork.Phase0
|
|
|
|
isBlinded {.inject, used.} = false
|
|
|
|
template forkyMaybeBlindedBlck: untyped {.inject, used.} = b.phase0Data
|
|
|
|
body
|
|
|
|
|
2021-10-06 17:05:06 +00:00
|
|
|
template withStateAndBlck*(
|
|
|
|
s: ForkedHashedBeaconState,
|
|
|
|
b: ForkedBeaconBlock | ForkedSignedBeaconBlock |
|
2022-06-10 14:16:37 +00:00
|
|
|
ForkedMsgTrustedSignedBeaconBlock |
|
2021-10-06 17:05:06 +00:00
|
|
|
ForkedTrustedSignedBeaconBlock,
|
|
|
|
body: untyped): untyped =
|
2021-10-18 16:37:27 +00:00
|
|
|
case s.kind
|
2024-04-03 14:43:43 +00:00
|
|
|
of ConsensusFork.Electra:
|
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Electra
|
|
|
|
template forkyState: untyped {.inject.} = s.electraData
|
|
|
|
template forkyBlck: untyped {.inject.} = b.electraData
|
|
|
|
body
|
2023-03-04 13:35:39 +00:00
|
|
|
of ConsensusFork.Deneb:
|
2023-12-04 21:14:35 +00:00
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Deneb
|
2023-03-04 22:23:52 +00:00
|
|
|
template forkyState: untyped {.inject.} = s.denebData
|
2023-09-21 10:49:14 +00:00
|
|
|
template forkyBlck: untyped {.inject.} = b.denebData
|
2022-12-07 16:47:23 +00:00
|
|
|
body
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Capella:
|
2023-12-04 21:14:35 +00:00
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Capella
|
2022-11-02 16:23:30 +00:00
|
|
|
template forkyState: untyped {.inject.} = s.capellaData
|
2023-09-21 10:49:14 +00:00
|
|
|
template forkyBlck: untyped {.inject.} = b.capellaData
|
2022-11-02 16:23:30 +00:00
|
|
|
body
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Bellatrix:
|
2023-12-04 21:14:35 +00:00
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Bellatrix
|
2022-09-28 01:15:10 +00:00
|
|
|
template forkyState: untyped {.inject.} = s.bellatrixData
|
2023-09-21 10:49:14 +00:00
|
|
|
template forkyBlck: untyped {.inject.} = b.bellatrixData
|
2021-10-06 17:05:06 +00:00
|
|
|
body
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Altair:
|
2023-12-04 21:14:35 +00:00
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Altair
|
2022-09-28 01:15:10 +00:00
|
|
|
template forkyState: untyped {.inject.} = s.altairData
|
2023-09-21 10:49:14 +00:00
|
|
|
template forkyBlck: untyped {.inject.} = b.altairData
|
2021-10-06 17:05:06 +00:00
|
|
|
body
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Phase0:
|
2023-12-04 21:14:35 +00:00
|
|
|
const consensusFork {.inject, used.} = ConsensusFork.Phase0
|
2023-11-01 04:53:09 +00:00
|
|
|
template forkyState: untyped {.inject, used.} = s.phase0Data
|
|
|
|
template forkyBlck: untyped {.inject, used.} = b.phase0Data
|
2021-10-06 17:05:06 +00:00
|
|
|
body
|
|
|
|
|
2022-03-07 13:56:43 +00:00
|
|
|
func toBeaconBlockHeader*(
|
2024-04-08 12:49:03 +00:00
|
|
|
blck: SomeForkyBeaconBlock | deneb_mev.BlindedBeaconBlock |
|
|
|
|
electra_mev.BlindedBeaconBlock): BeaconBlockHeader =
|
2022-03-07 13:56:43 +00:00
|
|
|
## Reduce a given `BeaconBlock` to its `BeaconBlockHeader`.
|
|
|
|
BeaconBlockHeader(
|
|
|
|
slot: blck.slot,
|
|
|
|
proposer_index: blck.proposer_index,
|
|
|
|
parent_root: blck.parent_root,
|
|
|
|
state_root: blck.state_root,
|
|
|
|
body_root: blck.body.hash_tree_root())
|
|
|
|
|
|
|
|
template toBeaconBlockHeader*(
|
|
|
|
blck: SomeForkySignedBeaconBlock): BeaconBlockHeader =
|
|
|
|
## Reduce a given `SignedBeaconBlock` to its `BeaconBlockHeader`.
|
2023-11-06 06:48:43 +00:00
|
|
|
blck.message.toBeaconBlockHeader()
|
2022-03-07 13:56:43 +00:00
|
|
|
|
|
|
|
template toBeaconBlockHeader*(
|
2022-06-10 14:16:37 +00:00
|
|
|
blckParam: ForkedMsgTrustedSignedBeaconBlock |
|
|
|
|
ForkedTrustedSignedBeaconBlock): BeaconBlockHeader =
|
|
|
|
## Reduce a given signed beacon block to its `BeaconBlockHeader`.
|
2023-09-21 10:49:14 +00:00
|
|
|
withBlck(blckParam): forkyBlck.toBeaconBlockHeader()
|
2022-03-07 13:56:43 +00:00
|
|
|
|
2023-11-06 06:48:43 +00:00
|
|
|
func toSignedBeaconBlockHeader*(
|
|
|
|
signedBlock: SomeForkySignedBeaconBlock |
|
2024-03-02 00:12:48 +00:00
|
|
|
deneb_mev.SignedBlindedBeaconBlock): SignedBeaconBlockHeader =
|
2023-11-06 06:48:43 +00:00
|
|
|
## Reduce a given `SignedBeaconBlock` to its `SignedBeaconBlockHeader`.
|
|
|
|
SignedBeaconBlockHeader(
|
|
|
|
message: signedBlock.message.toBeaconBlockHeader(),
|
|
|
|
signature: signedBlock.signature)
|
|
|
|
|
2021-11-05 07:34:34 +00:00
|
|
|
func genesisFork*(cfg: RuntimeConfig): Fork =
|
|
|
|
Fork(
|
|
|
|
previous_version: cfg.GENESIS_FORK_VERSION,
|
|
|
|
current_version: cfg.GENESIS_FORK_VERSION,
|
|
|
|
epoch: GENESIS_EPOCH)
|
|
|
|
|
|
|
|
func altairFork*(cfg: RuntimeConfig): Fork =
|
|
|
|
Fork(
|
|
|
|
previous_version: cfg.GENESIS_FORK_VERSION,
|
|
|
|
current_version: cfg.ALTAIR_FORK_VERSION,
|
|
|
|
epoch: cfg.ALTAIR_FORK_EPOCH)
|
|
|
|
|
2022-01-24 16:23:13 +00:00
|
|
|
func bellatrixFork*(cfg: RuntimeConfig): Fork =
|
2021-11-05 07:34:34 +00:00
|
|
|
Fork(
|
|
|
|
previous_version: cfg.ALTAIR_FORK_VERSION,
|
2022-01-20 08:30:33 +00:00
|
|
|
current_version: cfg.BELLATRIX_FORK_VERSION,
|
2022-02-02 13:06:55 +00:00
|
|
|
epoch: cfg.BELLATRIX_FORK_EPOCH)
|
2021-11-05 07:34:34 +00:00
|
|
|
|
2022-11-02 16:23:30 +00:00
|
|
|
func capellaFork*(cfg: RuntimeConfig): Fork =
|
|
|
|
Fork(
|
|
|
|
previous_version: cfg.BELLATRIX_FORK_VERSION,
|
|
|
|
current_version: cfg.CAPELLA_FORK_VERSION,
|
|
|
|
epoch: cfg.CAPELLA_FORK_EPOCH)
|
|
|
|
|
2023-02-15 14:44:09 +00:00
|
|
|
func denebFork*(cfg: RuntimeConfig): Fork =
|
2022-12-05 16:29:09 +00:00
|
|
|
Fork(
|
|
|
|
previous_version: cfg.CAPELLA_FORK_VERSION,
|
2023-02-15 14:44:09 +00:00
|
|
|
current_version: cfg.DENEB_FORK_VERSION,
|
|
|
|
epoch: cfg.DENEB_FORK_EPOCH)
|
2022-12-05 16:29:09 +00:00
|
|
|
|
2024-02-24 11:14:45 +00:00
|
|
|
func electraFork*(cfg: RuntimeConfig): Fork =
|
|
|
|
Fork(
|
|
|
|
previous_version: cfg.DENEB_FORK_VERSION,
|
|
|
|
current_version: cfg.ELECTRA_FORK_VERSION,
|
|
|
|
epoch: cfg.ELECTRA_FORK_EPOCH)
|
|
|
|
|
2022-02-17 11:53:55 +00:00
|
|
|
func forkAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): Fork =
|
2023-02-16 09:32:12 +00:00
|
|
|
case cfg.consensusForkAtEpoch(epoch)
|
2024-04-03 14:43:43 +00:00
|
|
|
of ConsensusFork.Electra: cfg.electraFork
|
2023-03-04 13:35:39 +00:00
|
|
|
of ConsensusFork.Deneb: cfg.denebFork
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Capella: cfg.capellaFork
|
|
|
|
of ConsensusFork.Bellatrix: cfg.bellatrixFork
|
|
|
|
of ConsensusFork.Altair: cfg.altairFork
|
|
|
|
of ConsensusFork.Phase0: cfg.genesisFork
|
2021-08-09 12:54:45 +00:00
|
|
|
|
2022-02-17 11:53:55 +00:00
|
|
|
func forkVersionAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): Version =
|
2023-02-16 09:32:12 +00:00
|
|
|
case cfg.consensusForkAtEpoch(epoch)
|
2024-04-03 14:43:43 +00:00
|
|
|
of ConsensusFork.Electra: cfg.ELECTRA_FORK_VERSION
|
2023-03-04 13:35:39 +00:00
|
|
|
of ConsensusFork.Deneb: cfg.DENEB_FORK_VERSION
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Capella: cfg.CAPELLA_FORK_VERSION
|
|
|
|
of ConsensusFork.Bellatrix: cfg.BELLATRIX_FORK_VERSION
|
|
|
|
of ConsensusFork.Altair: cfg.ALTAIR_FORK_VERSION
|
|
|
|
of ConsensusFork.Phase0: cfg.GENESIS_FORK_VERSION
|
2021-08-09 12:54:45 +00:00
|
|
|
|
2022-02-17 11:53:55 +00:00
|
|
|
func nextForkEpochAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): Epoch =
|
2023-02-16 09:32:12 +00:00
|
|
|
case cfg.consensusForkAtEpoch(epoch)
|
2024-04-03 14:43:43 +00:00
|
|
|
of ConsensusFork.Electra: FAR_FUTURE_EPOCH
|
|
|
|
of ConsensusFork.Deneb: cfg.ELECTRA_FORK_EPOCH
|
2023-02-15 14:44:09 +00:00
|
|
|
of ConsensusFork.Capella: cfg.DENEB_FORK_EPOCH
|
2023-01-28 19:53:41 +00:00
|
|
|
of ConsensusFork.Bellatrix: cfg.CAPELLA_FORK_EPOCH
|
|
|
|
of ConsensusFork.Altair: cfg.BELLATRIX_FORK_EPOCH
|
|
|
|
of ConsensusFork.Phase0: cfg.ALTAIR_FORK_EPOCH
|
|
|
|
|
|
|
|
func forkVersion*(cfg: RuntimeConfig, consensusFork: ConsensusFork): Version =
|
|
|
|
case consensusFork
|
|
|
|
of ConsensusFork.Phase0: cfg.GENESIS_FORK_VERSION
|
|
|
|
of ConsensusFork.Altair: cfg.ALTAIR_FORK_VERSION
|
|
|
|
of ConsensusFork.Bellatrix: cfg.BELLATRIX_FORK_VERSION
|
|
|
|
of ConsensusFork.Capella: cfg.CAPELLA_FORK_VERSION
|
2023-03-04 13:35:39 +00:00
|
|
|
of ConsensusFork.Deneb: cfg.DENEB_FORK_VERSION
|
2024-04-03 14:43:43 +00:00
|
|
|
of ConsensusFork.Electra: cfg.ELECTRA_FORK_VERSION
|
2023-01-28 19:53:41 +00:00
|
|
|
|
2023-03-11 20:09:21 +00:00
|
|
|
func lcDataForkAtConsensusFork*(
|
|
|
|
consensusFork: ConsensusFork): LightClientDataFork =
|
2023-03-10 17:16:26 +00:00
|
|
|
static: doAssert LightClientDataFork.high == LightClientDataFork.Deneb
|
2023-03-11 00:35:52 +00:00
|
|
|
if consensusFork >= ConsensusFork.Deneb:
|
2023-03-10 17:16:26 +00:00
|
|
|
LightClientDataFork.Deneb
|
2023-03-11 00:35:52 +00:00
|
|
|
elif consensusFork >= ConsensusFork.Capella:
|
2023-01-18 14:32:57 +00:00
|
|
|
LightClientDataFork.Capella
|
2023-03-11 00:35:52 +00:00
|
|
|
elif consensusFork >= ConsensusFork.Altair:
|
2023-01-14 21:19:50 +00:00
|
|
|
LightClientDataFork.Altair
|
|
|
|
else:
|
|
|
|
LightClientDataFork.None
|
|
|
|
|
2022-12-08 16:21:53 +00:00
|
|
|
func getForkSchedule*(cfg: RuntimeConfig): array[5, Fork] =
|
2021-08-23 10:41:48 +00:00
|
|
|
## This procedure returns list of known and/or scheduled forks.
|
|
|
|
##
|
|
|
|
## This procedure is used by HTTP REST framework and validator client.
|
|
|
|
##
|
|
|
|
## NOTE: Update this procedure when new fork will be scheduled.
|
2022-12-08 16:21:53 +00:00
|
|
|
[cfg.genesisFork(), cfg.altairFork(), cfg.bellatrixFork(), cfg.capellaFork(),
|
2023-02-15 14:44:09 +00:00
|
|
|
cfg.denebFork()]
|
2021-11-05 07:34:34 +00:00
|
|
|
|
2021-11-10 11:39:08 +00:00
|
|
|
type
|
|
|
|
# The first few fields of a state, shared across all forks
|
2023-09-08 05:53:27 +00:00
|
|
|
BeaconStateHeader* = object
|
|
|
|
genesis_time*: uint64
|
|
|
|
genesis_validators_root*: Eth2Digest
|
|
|
|
slot*: Slot
|
2021-11-10 11:39:08 +00:00
|
|
|
|
2023-01-03 19:37:09 +00:00
|
|
|
func readSszForkedHashedBeaconState*(
|
2023-06-14 19:48:50 +00:00
|
|
|
consensusFork: ConsensusFork, data: openArray[byte]):
|
2023-08-25 09:29:07 +00:00
|
|
|
ForkedHashedBeaconState {.raises: [SszError].} =
|
2023-01-03 19:37:09 +00:00
|
|
|
# TODO https://github.com/nim-lang/Nim/issues/19357
|
2023-06-14 19:48:50 +00:00
|
|
|
result = ForkedHashedBeaconState(kind: consensusFork)
|
2023-01-03 19:37:09 +00:00
|
|
|
|
|
|
|
withState(result):
|
|
|
|
readSszBytes(data, forkyState.data)
|
|
|
|
forkyState.root = hash_tree_root(forkyState.data)
|
|
|
|
|
2023-06-14 19:48:50 +00:00
|
|
|
template readSszForkedHashedBeaconState*(
|
|
|
|
cfg: RuntimeConfig, slot: Slot, data: openArray[byte]):
|
|
|
|
ForkedHashedBeaconState =
|
|
|
|
cfg.consensusForkAtEpoch(slot.epoch()).readSszForkedHashedBeaconState(data)
|
|
|
|
|
2021-11-10 11:39:08 +00:00
|
|
|
func readSszForkedHashedBeaconState*(cfg: RuntimeConfig, data: openArray[byte]):
|
2023-06-15 16:29:13 +00:00
|
|
|
ForkedHashedBeaconState {.raises: [SerializationError].} =
|
2023-01-03 19:37:09 +00:00
|
|
|
## Read a state picking the right fork by first reading the slot from the byte
|
|
|
|
## source
|
2021-11-10 11:39:08 +00:00
|
|
|
if data.len() < sizeof(BeaconStateHeader):
|
|
|
|
raise (ref MalformedSszError)(msg: "Not enough data for BeaconState header")
|
|
|
|
let header = SSZ.decode(
|
|
|
|
data.toOpenArray(0, sizeof(BeaconStateHeader) - 1),
|
|
|
|
BeaconStateHeader)
|
2021-11-05 07:34:34 +00:00
|
|
|
|
2022-02-16 15:44:04 +00:00
|
|
|
# TODO https://github.com/nim-lang/Nim/issues/19357
|
2023-01-03 19:37:09 +00:00
|
|
|
result = readSszForkedHashedBeaconState(cfg, header.slot, data)
|
2021-11-05 07:34:34 +00:00
|
|
|
|
2021-11-10 11:39:08 +00:00
|
|
|
type
|
|
|
|
ForkedBeaconBlockHeader = object
|
|
|
|
message*: uint32 # message offset
|
|
|
|
signature*: ValidatorSig
|
|
|
|
slot: Slot # start of BeaconBlock
|
2021-11-05 07:34:34 +00:00
|
|
|
|
2022-01-06 07:38:40 +00:00
|
|
|
func readSszForkedSignedBeaconBlock*(
|
2021-11-10 11:39:08 +00:00
|
|
|
cfg: RuntimeConfig, data: openArray[byte]):
|
2023-06-15 16:29:13 +00:00
|
|
|
ForkedSignedBeaconBlock {.raises: [SerializationError].} =
|
2021-11-10 11:39:08 +00:00
|
|
|
## Helper to read a header from bytes when it's not certain what kind of block
|
|
|
|
## it is
|
2021-12-10 02:41:57 +00:00
|
|
|
if data.len() < sizeof(ForkedBeaconBlockHeader):
|
2021-11-10 11:39:08 +00:00
|
|
|
raise (ref MalformedSszError)(msg: "Not enough data for SignedBeaconBlock header")
|
|
|
|
let header = SSZ.decode(
|
|
|
|
data.toOpenArray(0, sizeof(ForkedBeaconBlockHeader) - 1),
|
|
|
|
ForkedBeaconBlockHeader)
|
2021-12-10 02:41:57 +00:00
|
|
|
|
2022-02-16 15:44:04 +00:00
|
|
|
# TODO https://github.com/nim-lang/Nim/issues/19357
|
2022-01-06 07:38:40 +00:00
|
|
|
result = ForkedSignedBeaconBlock(
|
2023-02-16 20:16:54 +00:00
|
|
|
kind: cfg.consensusForkAtEpoch(header.slot.epoch()))
|
2021-11-10 11:39:08 +00:00
|
|
|
|
|
|
|
withBlck(result):
|
2023-09-21 10:49:14 +00:00
|
|
|
readSszBytes(data, forkyBlck)
|
2021-11-05 07:34:34 +00:00
|
|
|
|
2024-04-18 01:00:04 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.4.0/specs/phase0/beacon-chain.md#compute_fork_data_root
|
2021-11-05 07:34:34 +00:00
|
|
|
func compute_fork_data_root*(current_version: Version,
|
|
|
|
genesis_validators_root: Eth2Digest): Eth2Digest =
|
|
|
|
## Return the 32-byte fork data root for the ``current_version`` and
|
|
|
|
## ``genesis_validators_root``.
|
|
|
|
## This is used primarily in signature domains to avoid collisions across
|
|
|
|
## forks/chains.
|
|
|
|
hash_tree_root(ForkData(
|
|
|
|
current_version: current_version,
|
|
|
|
genesis_validators_root: genesis_validators_root
|
|
|
|
))
|
|
|
|
|
2024-01-20 11:19:47 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.6/specs/phase0/beacon-chain.md#compute_fork_digest
|
2021-11-05 07:34:34 +00:00
|
|
|
func compute_fork_digest*(current_version: Version,
|
|
|
|
genesis_validators_root: Eth2Digest): ForkDigest =
|
|
|
|
## Return the 4-byte fork digest for the ``current_version`` and
|
|
|
|
## ``genesis_validators_root``.
|
|
|
|
## This is a digest primarily used for domain separation on the p2p layer.
|
|
|
|
## 4-bytes suffices for practical separation of forks/chains.
|
|
|
|
array[4, byte](result)[0..3] =
|
|
|
|
compute_fork_data_root(
|
|
|
|
current_version, genesis_validators_root).data.toOpenArray(0, 3)
|
|
|
|
|
|
|
|
func init*(T: type ForkDigests,
|
|
|
|
cfg: RuntimeConfig,
|
2022-04-08 16:22:49 +00:00
|
|
|
genesis_validators_root: Eth2Digest): T =
|
2024-04-03 14:43:43 +00:00
|
|
|
static: doAssert high(ConsensusFork) == ConsensusFork.Electra
|
2021-11-05 07:34:34 +00:00
|
|
|
T(
|
|
|
|
phase0:
|
2022-04-08 16:22:49 +00:00
|
|
|
compute_fork_digest(cfg.GENESIS_FORK_VERSION, genesis_validators_root),
|
2021-11-05 07:34:34 +00:00
|
|
|
altair:
|
2022-04-08 16:22:49 +00:00
|
|
|
compute_fork_digest(cfg.ALTAIR_FORK_VERSION, genesis_validators_root),
|
2022-01-05 14:24:15 +00:00
|
|
|
bellatrix:
|
2022-04-08 16:22:49 +00:00
|
|
|
compute_fork_digest(cfg.BELLATRIX_FORK_VERSION, genesis_validators_root),
|
2022-06-03 14:42:40 +00:00
|
|
|
capella:
|
2022-12-08 16:21:53 +00:00
|
|
|
compute_fork_digest(cfg.CAPELLA_FORK_VERSION, genesis_validators_root),
|
2023-03-10 17:13:40 +00:00
|
|
|
deneb:
|
2024-02-24 11:14:45 +00:00
|
|
|
compute_fork_digest(cfg.DENEB_FORK_VERSION, genesis_validators_root),
|
|
|
|
electra:
|
|
|
|
compute_fork_digest(cfg.ELECTRA_FORK_VERSION, genesis_validators_root)
|
2021-11-05 07:34:34 +00:00
|
|
|
)
|
2022-03-16 15:00:18 +00:00
|
|
|
|
2022-06-10 14:16:37 +00:00
|
|
|
func toBlockId*(header: BeaconBlockHeader): BlockId =
|
|
|
|
BlockId(root: header.hash_tree_root(), slot: header.slot)
|
|
|
|
|
2022-03-16 15:00:18 +00:00
|
|
|
func toBlockId*(blck: SomeForkySignedBeaconBlock): BlockId =
|
|
|
|
BlockId(root: blck.root, slot: blck.message.slot)
|
|
|
|
|
2022-06-10 14:16:37 +00:00
|
|
|
func toBlockId*(blck: ForkedSignedBeaconBlock |
|
|
|
|
ForkedMsgTrustedSignedBeaconBlock |
|
|
|
|
ForkedTrustedSignedBeaconBlock): BlockId =
|
2023-09-21 10:49:14 +00:00
|
|
|
withBlck(blck): BlockId(root: forkyBlck.root, slot: forkyBlck.message.slot)
|
2023-04-24 13:26:28 +00:00
|
|
|
|
|
|
|
func historical_summaries*(state: ForkedHashedBeaconState):
|
|
|
|
HashList[HistoricalSummary, Limit HISTORICAL_ROOTS_LIMIT] =
|
|
|
|
withState(state):
|
|
|
|
when consensusFork >= ConsensusFork.Capella:
|
|
|
|
forkyState.data.historical_summaries
|
|
|
|
else:
|
|
|
|
HashList[HistoricalSummary, Limit HISTORICAL_ROOTS_LIMIT]()
|
2023-11-28 23:30:14 +00:00
|
|
|
|
|
|
|
template init*(T: type ForkedMaybeBlindedBeaconBlock,
|
|
|
|
blck: phase0.BeaconBlock): T =
|
|
|
|
ForkedMaybeBlindedBeaconBlock(
|
|
|
|
kind: ConsensusFork.Phase0,
|
|
|
|
phase0Data: blck)
|
|
|
|
|
|
|
|
template init*(T: type ForkedMaybeBlindedBeaconBlock,
|
|
|
|
blck: altair.BeaconBlock): T =
|
|
|
|
ForkedMaybeBlindedBeaconBlock(
|
|
|
|
kind: ConsensusFork.Altair,
|
|
|
|
altairData: blck)
|
|
|
|
|
|
|
|
template init*(T: type ForkedMaybeBlindedBeaconBlock,
|
|
|
|
blck: bellatrix.BeaconBlock,
|
|
|
|
evalue: Opt[UInt256], cvalue: Opt[UInt256]): T =
|
|
|
|
ForkedMaybeBlindedBeaconBlock(
|
|
|
|
kind: ConsensusFork.Bellatrix,
|
|
|
|
bellatrixData: blck,
|
|
|
|
consensusValue: cvalue,
|
|
|
|
executionValue: evalue)
|
|
|
|
|
|
|
|
template init*(T: type ForkedMaybeBlindedBeaconBlock,
|
|
|
|
blck: capella.BeaconBlock,
|
|
|
|
evalue: Opt[UInt256], cvalue: Opt[UInt256]): T =
|
|
|
|
ForkedMaybeBlindedBeaconBlock(
|
|
|
|
kind: ConsensusFork.Capella,
|
2024-02-28 18:27:26 +00:00
|
|
|
capellaData: blck,
|
2023-11-28 23:30:14 +00:00
|
|
|
consensusValue: cvalue,
|
|
|
|
executionValue: evalue)
|
|
|
|
|
|
|
|
template init*(T: type ForkedMaybeBlindedBeaconBlock,
|
|
|
|
blck: deneb.BlockContents,
|
|
|
|
evalue: Opt[UInt256], cvalue: Opt[UInt256]): T =
|
|
|
|
ForkedMaybeBlindedBeaconBlock(
|
|
|
|
kind: ConsensusFork.Deneb,
|
|
|
|
denebData: deneb_mev.MaybeBlindedBeaconBlock(
|
|
|
|
isBlinded: false,
|
|
|
|
data: blck),
|
|
|
|
consensusValue: cvalue,
|
|
|
|
executionValue: evalue)
|
|
|
|
|
|
|
|
template init*(T: type ForkedMaybeBlindedBeaconBlock,
|
|
|
|
blck: deneb_mev.BlindedBeaconBlock,
|
|
|
|
evalue: Opt[UInt256], cvalue: Opt[UInt256]): T =
|
|
|
|
ForkedMaybeBlindedBeaconBlock(
|
|
|
|
kind: ConsensusFork.Deneb,
|
|
|
|
denebData: deneb_mev.MaybeBlindedBeaconBlock(
|
|
|
|
isBlinded: true,
|
|
|
|
blindedData: blck),
|
|
|
|
consensusValue: cvalue,
|
|
|
|
executionValue: evalue)
|
2024-04-09 14:54:05 +00:00
|
|
|
|
|
|
|
template init*(T: type ForkedMaybeBlindedBeaconBlock,
|
|
|
|
blck: electra.BlockContents,
|
|
|
|
evalue: Opt[UInt256], cvalue: Opt[UInt256]): T =
|
|
|
|
ForkedMaybeBlindedBeaconBlock(
|
|
|
|
kind: ConsensusFork.Electra,
|
|
|
|
electraData: electra_mev.MaybeBlindedBeaconBlock(
|
|
|
|
isBlinded: false,
|
|
|
|
data: blck),
|
|
|
|
consensusValue: cvalue,
|
|
|
|
executionValue: evalue)
|
|
|
|
|
|
|
|
template init*(T: type ForkedMaybeBlindedBeaconBlock,
|
|
|
|
blck: electra_mev.BlindedBeaconBlock,
|
|
|
|
evalue: Opt[UInt256], cvalue: Opt[UInt256]): T =
|
|
|
|
ForkedMaybeBlindedBeaconBlock(
|
|
|
|
kind: ConsensusFork.Electra,
|
|
|
|
electraData: electra_mev.MaybeBlindedBeaconBlock(
|
|
|
|
isBlinded: true,
|
|
|
|
blindedData: blck),
|
|
|
|
consensusValue: cvalue,
|
|
|
|
executionValue: evalue)
|
2024-05-17 15:34:46 +00:00
|
|
|
|
|
|
|
func committee_index*(
|
|
|
|
v: phase0.Attestation, on_chain: static bool = false): uint64 =
|
|
|
|
v.data.index
|
|
|
|
|
|
|
|
func committee_index*(v: electra.Attestation, on_chain: static bool): uint64 =
|
|
|
|
when on_chain:
|
|
|
|
{.error: "cannot get single committee_index for on_chain attestation".}
|
|
|
|
else:
|
|
|
|
uint64 v.committee_bits.get_committee_index_one().expect("network attestation")
|