2023-01-12 17:11:38 +00:00
|
|
|
# beacon_chain
|
2024-01-16 22:54:20 +00:00
|
|
|
# Copyright (c) 2023-2024 Status Research & Development GmbH
|
2023-01-12 17:11:38 +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: [].}
|
2023-01-12 17:11:38 +00:00
|
|
|
|
|
|
|
import
|
2024-04-03 14:43:43 +00:00
|
|
|
./datatypes/[phase0, altair, bellatrix, capella, deneb, electra],
|
2023-01-18 14:32:57 +00:00
|
|
|
./eth2_merkleization
|
2023-01-12 17:11:38 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
LightClientDataFork* {.pure.} = enum # Append only, used in DB data!
|
|
|
|
None = 0, # only use non-0 in DB to detect accidentally uninitialized data
|
2023-01-18 14:32:57 +00:00
|
|
|
Altair = 1,
|
2023-01-19 22:53:37 +00:00
|
|
|
Capella = 2,
|
2024-06-21 13:02:01 +00:00
|
|
|
Deneb = 3,
|
|
|
|
Electra = 4
|
|
|
|
|
|
|
|
ForkyCurrentSyncCommitteeBranch* =
|
|
|
|
altair.CurrentSyncCommitteeBranch |
|
|
|
|
electra.CurrentSyncCommitteeBranch
|
2023-01-12 17:11:38 +00:00
|
|
|
|
|
|
|
ForkyLightClientHeader* =
|
2023-01-18 14:32:57 +00:00
|
|
|
altair.LightClientHeader |
|
2023-01-19 22:53:37 +00:00
|
|
|
capella.LightClientHeader |
|
2024-06-21 13:02:01 +00:00
|
|
|
deneb.LightClientHeader |
|
|
|
|
electra.LightClientHeader
|
2023-01-12 17:11:38 +00:00
|
|
|
|
|
|
|
ForkyLightClientBootstrap* =
|
2023-01-18 14:32:57 +00:00
|
|
|
altair.LightClientBootstrap |
|
2023-01-19 22:53:37 +00:00
|
|
|
capella.LightClientBootstrap |
|
2024-06-21 13:02:01 +00:00
|
|
|
deneb.LightClientBootstrap |
|
|
|
|
electra.LightClientBootstrap
|
2023-01-12 17:11:38 +00:00
|
|
|
|
|
|
|
ForkyLightClientUpdate* =
|
2023-01-18 14:32:57 +00:00
|
|
|
altair.LightClientUpdate |
|
2023-01-19 22:53:37 +00:00
|
|
|
capella.LightClientUpdate |
|
2024-06-21 13:02:01 +00:00
|
|
|
deneb.LightClientUpdate |
|
|
|
|
electra.LightClientUpdate
|
2023-01-12 17:11:38 +00:00
|
|
|
|
|
|
|
ForkyLightClientFinalityUpdate* =
|
2023-01-18 14:32:57 +00:00
|
|
|
altair.LightClientFinalityUpdate |
|
2023-01-19 22:53:37 +00:00
|
|
|
capella.LightClientFinalityUpdate |
|
2024-06-21 13:02:01 +00:00
|
|
|
deneb.LightClientFinalityUpdate |
|
|
|
|
electra.LightClientFinalityUpdate
|
2023-01-12 17:11:38 +00:00
|
|
|
|
|
|
|
ForkyLightClientOptimisticUpdate* =
|
2023-01-18 14:32:57 +00:00
|
|
|
altair.LightClientOptimisticUpdate |
|
2023-01-19 22:53:37 +00:00
|
|
|
capella.LightClientOptimisticUpdate |
|
2024-06-21 13:02:01 +00:00
|
|
|
deneb.LightClientOptimisticUpdate |
|
|
|
|
electra.LightClientOptimisticUpdate
|
2023-01-12 17:11:38 +00:00
|
|
|
|
|
|
|
SomeForkyLightClientUpdateWithSyncCommittee* =
|
|
|
|
ForkyLightClientUpdate
|
|
|
|
|
|
|
|
SomeForkyLightClientUpdateWithFinality* =
|
|
|
|
ForkyLightClientUpdate |
|
|
|
|
ForkyLightClientFinalityUpdate
|
|
|
|
|
|
|
|
SomeForkyLightClientUpdate* =
|
|
|
|
ForkyLightClientUpdate |
|
|
|
|
ForkyLightClientFinalityUpdate |
|
|
|
|
ForkyLightClientOptimisticUpdate
|
|
|
|
|
|
|
|
SomeForkyLightClientObject* =
|
|
|
|
ForkyLightClientBootstrap |
|
|
|
|
SomeForkyLightClientUpdate
|
|
|
|
|
2023-01-14 21:19:50 +00:00
|
|
|
ForkyLightClientStore* =
|
2023-01-18 14:32:57 +00:00
|
|
|
altair.LightClientStore |
|
2023-01-19 22:53:37 +00:00
|
|
|
capella.LightClientStore |
|
2024-06-21 13:02:01 +00:00
|
|
|
deneb.LightClientStore |
|
|
|
|
electra.LightClientStore
|
2023-01-14 21:19:50 +00:00
|
|
|
|
2023-01-16 15:53:45 +00:00
|
|
|
ForkedLightClientHeader* = object
|
|
|
|
case kind*: LightClientDataFork
|
|
|
|
of LightClientDataFork.None:
|
|
|
|
discard
|
|
|
|
of LightClientDataFork.Altair:
|
|
|
|
altairData*: altair.LightClientHeader
|
2023-01-18 14:32:57 +00:00
|
|
|
of LightClientDataFork.Capella:
|
|
|
|
capellaData*: capella.LightClientHeader
|
2023-03-10 17:16:26 +00:00
|
|
|
of LightClientDataFork.Deneb:
|
|
|
|
denebData*: deneb.LightClientHeader
|
2024-06-21 13:02:01 +00:00
|
|
|
of LightClientDataFork.Electra:
|
|
|
|
electraData*: electra.LightClientHeader
|
2023-01-16 15:53:45 +00:00
|
|
|
|
2023-01-12 17:11:38 +00:00
|
|
|
ForkedLightClientBootstrap* = object
|
|
|
|
case kind*: LightClientDataFork
|
|
|
|
of LightClientDataFork.None:
|
|
|
|
discard
|
|
|
|
of LightClientDataFork.Altair:
|
|
|
|
altairData*: altair.LightClientBootstrap
|
2023-01-18 14:32:57 +00:00
|
|
|
of LightClientDataFork.Capella:
|
|
|
|
capellaData*: capella.LightClientBootstrap
|
2023-03-10 17:16:26 +00:00
|
|
|
of LightClientDataFork.Deneb:
|
|
|
|
denebData*: deneb.LightClientBootstrap
|
2024-06-21 13:02:01 +00:00
|
|
|
of LightClientDataFork.Electra:
|
|
|
|
electraData*: electra.LightClientBootstrap
|
2023-01-12 17:11:38 +00:00
|
|
|
|
|
|
|
ForkedLightClientUpdate* = object
|
|
|
|
case kind*: LightClientDataFork
|
|
|
|
of LightClientDataFork.None:
|
|
|
|
discard
|
|
|
|
of LightClientDataFork.Altair:
|
|
|
|
altairData*: altair.LightClientUpdate
|
2023-01-18 14:32:57 +00:00
|
|
|
of LightClientDataFork.Capella:
|
|
|
|
capellaData*: capella.LightClientUpdate
|
2023-03-10 17:16:26 +00:00
|
|
|
of LightClientDataFork.Deneb:
|
|
|
|
denebData*: deneb.LightClientUpdate
|
2024-06-21 13:02:01 +00:00
|
|
|
of LightClientDataFork.Electra:
|
|
|
|
electraData*: electra.LightClientUpdate
|
2023-01-12 17:11:38 +00:00
|
|
|
|
|
|
|
ForkedLightClientFinalityUpdate* = object
|
|
|
|
case kind*: LightClientDataFork
|
|
|
|
of LightClientDataFork.None:
|
|
|
|
discard
|
|
|
|
of LightClientDataFork.Altair:
|
|
|
|
altairData*: altair.LightClientFinalityUpdate
|
2023-01-18 14:32:57 +00:00
|
|
|
of LightClientDataFork.Capella:
|
|
|
|
capellaData*: capella.LightClientFinalityUpdate
|
2023-03-10 17:16:26 +00:00
|
|
|
of LightClientDataFork.Deneb:
|
|
|
|
denebData*: deneb.LightClientFinalityUpdate
|
2024-06-21 13:02:01 +00:00
|
|
|
of LightClientDataFork.Electra:
|
|
|
|
electraData*: electra.LightClientFinalityUpdate
|
2023-01-12 17:11:38 +00:00
|
|
|
|
|
|
|
ForkedLightClientOptimisticUpdate* = object
|
|
|
|
case kind*: LightClientDataFork
|
|
|
|
of LightClientDataFork.None:
|
|
|
|
discard
|
|
|
|
of LightClientDataFork.Altair:
|
|
|
|
altairData*: altair.LightClientOptimisticUpdate
|
2023-01-18 14:32:57 +00:00
|
|
|
of LightClientDataFork.Capella:
|
|
|
|
capellaData*: capella.LightClientOptimisticUpdate
|
2023-03-10 17:16:26 +00:00
|
|
|
of LightClientDataFork.Deneb:
|
|
|
|
denebData*: deneb.LightClientOptimisticUpdate
|
2024-06-21 13:02:01 +00:00
|
|
|
of LightClientDataFork.Electra:
|
|
|
|
electraData*: electra.LightClientOptimisticUpdate
|
2023-01-12 17:11:38 +00:00
|
|
|
|
2023-01-14 21:19:50 +00:00
|
|
|
SomeForkedLightClientUpdateWithSyncCommittee* =
|
|
|
|
ForkedLightClientUpdate
|
|
|
|
|
|
|
|
SomeForkedLightClientUpdateWithFinality* =
|
|
|
|
ForkedLightClientUpdate |
|
|
|
|
ForkedLightClientFinalityUpdate
|
|
|
|
|
2023-01-12 17:11:38 +00:00
|
|
|
SomeForkedLightClientUpdate* =
|
|
|
|
ForkedLightClientUpdate |
|
|
|
|
ForkedLightClientFinalityUpdate |
|
|
|
|
ForkedLightClientOptimisticUpdate
|
|
|
|
|
|
|
|
SomeForkedLightClientObject* =
|
|
|
|
ForkedLightClientBootstrap |
|
|
|
|
SomeForkedLightClientUpdate
|
|
|
|
|
2023-01-14 21:19:50 +00:00
|
|
|
ForkedLightClientStore* = object
|
|
|
|
case kind*: LightClientDataFork
|
|
|
|
of LightClientDataFork.None:
|
|
|
|
discard
|
|
|
|
of LightClientDataFork.Altair:
|
|
|
|
altairData*: altair.LightClientStore
|
2023-01-18 14:32:57 +00:00
|
|
|
of LightClientDataFork.Capella:
|
|
|
|
capellaData*: capella.LightClientStore
|
2023-03-10 17:16:26 +00:00
|
|
|
of LightClientDataFork.Deneb:
|
|
|
|
denebData*: deneb.LightClientStore
|
2024-06-21 13:02:01 +00:00
|
|
|
of LightClientDataFork.Electra:
|
|
|
|
electraData*: electra.LightClientStore
|
2023-01-14 21:19:50 +00:00
|
|
|
|
2023-01-12 17:11:38 +00:00
|
|
|
func lcDataForkAtEpoch*(
|
|
|
|
cfg: RuntimeConfig, epoch: Epoch): LightClientDataFork =
|
2024-06-21 13:02:01 +00:00
|
|
|
static: doAssert LightClientDataFork.high == LightClientDataFork.Electra
|
|
|
|
if epoch >= cfg.ELECTRA_FORK_EPOCH:
|
|
|
|
LightClientDataFork.Electra
|
|
|
|
elif epoch >= cfg.DENEB_FORK_EPOCH:
|
2023-03-10 17:16:26 +00:00
|
|
|
LightClientDataFork.Deneb
|
2023-01-19 22:53:37 +00:00
|
|
|
elif epoch >= cfg.CAPELLA_FORK_EPOCH:
|
2023-01-18 14:32:57 +00:00
|
|
|
LightClientDataFork.Capella
|
|
|
|
elif epoch >= cfg.ALTAIR_FORK_EPOCH:
|
2023-01-12 17:11:38 +00:00
|
|
|
LightClientDataFork.Altair
|
|
|
|
else:
|
|
|
|
LightClientDataFork.None
|
|
|
|
|
2023-01-14 21:19:50 +00:00
|
|
|
template kind*(
|
|
|
|
x: typedesc[ # `SomeLightClientObject` doesn't work here (Nim 1.6)
|
|
|
|
altair.LightClientHeader |
|
|
|
|
altair.LightClientBootstrap |
|
|
|
|
altair.LightClientUpdate |
|
|
|
|
altair.LightClientFinalityUpdate |
|
|
|
|
altair.LightClientOptimisticUpdate |
|
|
|
|
altair.LightClientStore]): LightClientDataFork =
|
2023-01-12 17:11:38 +00:00
|
|
|
LightClientDataFork.Altair
|
|
|
|
|
2023-01-18 14:32:57 +00:00
|
|
|
template kind*(
|
|
|
|
x: typedesc[ # `SomeLightClientObject` doesn't work here (Nim 1.6)
|
|
|
|
capella.LightClientHeader |
|
|
|
|
capella.LightClientBootstrap |
|
|
|
|
capella.LightClientUpdate |
|
|
|
|
capella.LightClientFinalityUpdate |
|
|
|
|
capella.LightClientOptimisticUpdate |
|
|
|
|
capella.LightClientStore]): LightClientDataFork =
|
|
|
|
LightClientDataFork.Capella
|
|
|
|
|
2023-01-19 22:53:37 +00:00
|
|
|
template kind*(
|
|
|
|
x: typedesc[ # `SomeLightClientObject` doesn't work here (Nim 1.6)
|
2023-02-20 08:45:49 +00:00
|
|
|
deneb.LightClientHeader |
|
|
|
|
deneb.LightClientBootstrap |
|
|
|
|
deneb.LightClientUpdate |
|
|
|
|
deneb.LightClientFinalityUpdate |
|
|
|
|
deneb.LightClientOptimisticUpdate |
|
|
|
|
deneb.LightClientStore]): LightClientDataFork =
|
2023-03-10 17:16:26 +00:00
|
|
|
LightClientDataFork.Deneb
|
2023-01-19 22:53:37 +00:00
|
|
|
|
2024-06-21 13:02:01 +00:00
|
|
|
template kind*(
|
|
|
|
x: typedesc[ # `SomeLightClientObject` doesn't work here (Nim 1.6)
|
|
|
|
electra.LightClientHeader |
|
|
|
|
electra.LightClientBootstrap |
|
|
|
|
electra.LightClientUpdate |
|
|
|
|
electra.LightClientFinalityUpdate |
|
|
|
|
electra.LightClientOptimisticUpdate |
|
|
|
|
electra.LightClientStore]): LightClientDataFork =
|
|
|
|
LightClientDataFork.Electra
|
|
|
|
|
|
|
|
template FINALIZED_ROOT_GINDEX*(
|
|
|
|
kind: static LightClientDataFork): GeneralizedIndex =
|
|
|
|
when kind >= LightClientDataFork.Electra:
|
|
|
|
electra.FINALIZED_ROOT_GINDEX
|
|
|
|
elif kind >= LightClientDataFork.Altair:
|
|
|
|
altair.FINALIZED_ROOT_GINDEX
|
|
|
|
else:
|
|
|
|
static: raiseAssert "Unreachable"
|
|
|
|
|
|
|
|
template FinalityBranch*(kind: static LightClientDataFork): auto =
|
|
|
|
when kind >= LightClientDataFork.Electra:
|
|
|
|
typedesc[electra.FinalityBranch]
|
|
|
|
elif kind >= LightClientDataFork.Altair:
|
|
|
|
typedesc[altair.FinalityBranch]
|
|
|
|
else:
|
|
|
|
static: raiseAssert "Unreachable"
|
|
|
|
|
|
|
|
template CURRENT_SYNC_COMMITTEE_GINDEX*(
|
|
|
|
kind: static LightClientDataFork): GeneralizedIndex =
|
|
|
|
when kind >= LightClientDataFork.Electra:
|
|
|
|
electra.CURRENT_SYNC_COMMITTEE_GINDEX
|
|
|
|
elif kind >= LightClientDataFork.Altair:
|
|
|
|
altair.CURRENT_SYNC_COMMITTEE_GINDEX
|
|
|
|
else:
|
|
|
|
static: raiseAssert "Unreachable"
|
|
|
|
|
|
|
|
template CurrentSyncCommitteeBranch*(kind: static LightClientDataFork): auto =
|
|
|
|
when kind >= LightClientDataFork.Electra:
|
|
|
|
typedesc[electra.CurrentSyncCommitteeBranch]
|
|
|
|
elif kind >= LightClientDataFork.Altair:
|
|
|
|
typedesc[altair.CurrentSyncCommitteeBranch]
|
|
|
|
else:
|
|
|
|
static: raiseAssert "Unreachable"
|
|
|
|
|
|
|
|
template NEXT_SYNC_COMMITTEE_GINDEX*(
|
|
|
|
kind: static LightClientDataFork): GeneralizedIndex =
|
|
|
|
when kind >= LightClientDataFork.Electra:
|
|
|
|
electra.NEXT_SYNC_COMMITTEE_GINDEX
|
|
|
|
elif kind >= LightClientDataFork.Altair:
|
|
|
|
altair.NEXT_SYNC_COMMITTEE_GINDEX
|
|
|
|
else:
|
|
|
|
static: raiseAssert "Unreachable"
|
|
|
|
|
|
|
|
template NextSyncCommitteeBranch*(kind: static LightClientDataFork): auto =
|
|
|
|
when kind >= LightClientDataFork.Electra:
|
|
|
|
typedesc[electra.NextSyncCommitteeBranch]
|
|
|
|
elif kind >= LightClientDataFork.Altair:
|
|
|
|
typedesc[altair.NextSyncCommitteeBranch]
|
|
|
|
else:
|
|
|
|
static: raiseAssert "Unreachable"
|
|
|
|
|
2023-01-14 21:19:50 +00:00
|
|
|
template LightClientHeader*(kind: static LightClientDataFork): auto =
|
2024-06-21 13:02:01 +00:00
|
|
|
when kind == LightClientDataFork.Electra:
|
|
|
|
typedesc[electra.LightClientHeader]
|
|
|
|
elif kind == LightClientDataFork.Deneb:
|
2023-02-25 01:03:34 +00:00
|
|
|
typedesc[deneb.LightClientHeader]
|
2023-01-19 22:53:37 +00:00
|
|
|
elif kind == LightClientDataFork.Capella:
|
2023-01-18 14:32:57 +00:00
|
|
|
typedesc[capella.LightClientHeader]
|
|
|
|
elif kind == LightClientDataFork.Altair:
|
2023-01-13 15:46:35 +00:00
|
|
|
typedesc[altair.LightClientHeader]
|
2023-01-12 17:11:38 +00:00
|
|
|
else:
|
|
|
|
static: raiseAssert "Unreachable"
|
|
|
|
|
2023-01-14 21:19:50 +00:00
|
|
|
template LightClientBootstrap*(kind: static LightClientDataFork): auto =
|
2024-06-21 13:02:01 +00:00
|
|
|
when kind == LightClientDataFork.Electra:
|
|
|
|
typedesc[electra.LightClientBootstrap]
|
|
|
|
elif kind == LightClientDataFork.Deneb:
|
2023-03-02 20:09:24 +00:00
|
|
|
typedesc[deneb.LightClientBootstrap]
|
2023-01-19 22:53:37 +00:00
|
|
|
elif kind == LightClientDataFork.Capella:
|
2023-01-18 14:32:57 +00:00
|
|
|
typedesc[capella.LightClientBootstrap]
|
|
|
|
elif kind == LightClientDataFork.Altair:
|
2023-01-12 17:11:38 +00:00
|
|
|
typedesc[altair.LightClientBootstrap]
|
|
|
|
else:
|
|
|
|
static: raiseAssert "Unreachable"
|
|
|
|
|
2023-01-14 21:19:50 +00:00
|
|
|
template LightClientUpdate*(kind: static LightClientDataFork): auto =
|
2024-06-21 13:02:01 +00:00
|
|
|
when kind == LightClientDataFork.Electra:
|
|
|
|
typedesc[electra.LightClientUpdate]
|
|
|
|
elif kind == LightClientDataFork.Deneb:
|
2023-02-25 01:03:34 +00:00
|
|
|
typedesc[deneb.LightClientUpdate]
|
2023-01-19 22:53:37 +00:00
|
|
|
elif kind == LightClientDataFork.Capella:
|
2023-01-18 14:32:57 +00:00
|
|
|
typedesc[capella.LightClientUpdate]
|
|
|
|
elif kind == LightClientDataFork.Altair:
|
2023-01-12 17:11:38 +00:00
|
|
|
typedesc[altair.LightClientUpdate]
|
|
|
|
else:
|
|
|
|
static: raiseAssert "Unreachable"
|
|
|
|
|
2023-01-14 21:19:50 +00:00
|
|
|
template LightClientFinalityUpdate*(kind: static LightClientDataFork): auto =
|
2024-06-21 13:02:01 +00:00
|
|
|
when kind == LightClientDataFork.Electra:
|
|
|
|
typedesc[electra.LightClientFinalityUpdate]
|
|
|
|
elif kind == LightClientDataFork.Deneb:
|
2023-03-09 00:34:17 +00:00
|
|
|
typedesc[deneb.LightClientFinalityUpdate]
|
2023-01-19 22:53:37 +00:00
|
|
|
elif kind == LightClientDataFork.Capella:
|
2023-01-18 14:32:57 +00:00
|
|
|
typedesc[capella.LightClientFinalityUpdate]
|
|
|
|
elif kind == LightClientDataFork.Altair:
|
2023-01-12 17:11:38 +00:00
|
|
|
typedesc[altair.LightClientFinalityUpdate]
|
|
|
|
else:
|
|
|
|
static: raiseAssert "Unreachable"
|
|
|
|
|
2023-01-14 21:19:50 +00:00
|
|
|
template LightClientOptimisticUpdate*(kind: static LightClientDataFork): auto =
|
2024-06-21 13:02:01 +00:00
|
|
|
when kind == LightClientDataFork.Electra:
|
|
|
|
typedesc[electra.LightClientOptimisticUpdate]
|
|
|
|
elif kind == LightClientDataFork.Deneb:
|
2023-03-02 20:09:24 +00:00
|
|
|
typedesc[deneb.LightClientOptimisticUpdate]
|
2023-01-19 22:53:37 +00:00
|
|
|
elif kind == LightClientDataFork.Capella:
|
2023-01-18 14:32:57 +00:00
|
|
|
typedesc[capella.LightClientOptimisticUpdate]
|
|
|
|
elif kind == LightClientDataFork.Altair:
|
2023-01-12 17:11:38 +00:00
|
|
|
typedesc[altair.LightClientOptimisticUpdate]
|
|
|
|
else:
|
|
|
|
static: raiseAssert "Unreachable"
|
|
|
|
|
2023-01-14 21:19:50 +00:00
|
|
|
template LightClientStore*(kind: static LightClientDataFork): auto =
|
2024-06-21 13:02:01 +00:00
|
|
|
when kind == LightClientDataFork.Electra:
|
|
|
|
typedesc[electra.LightClientStore]
|
|
|
|
elif kind == LightClientDataFork.Deneb:
|
2023-02-25 01:03:34 +00:00
|
|
|
typedesc[deneb.LightClientStore]
|
2023-01-19 22:53:37 +00:00
|
|
|
elif kind == LightClientDataFork.Capella:
|
2023-01-18 14:32:57 +00:00
|
|
|
typedesc[capella.LightClientStore]
|
|
|
|
elif kind == LightClientDataFork.Altair:
|
2023-01-14 21:19:50 +00:00
|
|
|
typedesc[altair.LightClientStore]
|
|
|
|
else:
|
|
|
|
static: raiseAssert "Unreachable"
|
|
|
|
|
2023-01-16 15:53:45 +00:00
|
|
|
template Forky*(
|
|
|
|
x: typedesc[ForkedLightClientHeader],
|
|
|
|
kind: static LightClientDataFork): auto =
|
|
|
|
kind.LightClientHeader
|
|
|
|
|
2023-01-14 21:19:50 +00:00
|
|
|
template Forky*(
|
|
|
|
x: typedesc[ForkedLightClientBootstrap],
|
|
|
|
kind: static LightClientDataFork): auto =
|
|
|
|
kind.LightClientBootstrap
|
|
|
|
|
|
|
|
template Forky*(
|
|
|
|
x: typedesc[ForkedLightClientUpdate],
|
|
|
|
kind: static LightClientDataFork): auto =
|
|
|
|
kind.LightClientUpdate
|
|
|
|
|
|
|
|
template Forky*(
|
|
|
|
x: typedesc[ForkedLightClientFinalityUpdate],
|
|
|
|
kind: static LightClientDataFork): auto =
|
|
|
|
kind.LightClientFinalityUpdate
|
|
|
|
|
|
|
|
template Forky*(
|
|
|
|
x: typedesc[ForkedLightClientOptimisticUpdate],
|
|
|
|
kind: static LightClientDataFork): auto =
|
|
|
|
kind.LightClientOptimisticUpdate
|
|
|
|
|
|
|
|
template Forky*(
|
|
|
|
x: typedesc[ForkedLightClientStore],
|
|
|
|
kind: static LightClientDataFork): auto =
|
|
|
|
kind.LightClientStore
|
|
|
|
|
2023-01-16 15:53:45 +00:00
|
|
|
template Forked*(x: typedesc[ForkyLightClientHeader]): auto =
|
|
|
|
typedesc[ForkedLightClientHeader]
|
|
|
|
|
2023-01-14 21:19:50 +00:00
|
|
|
template Forked*(x: typedesc[ForkyLightClientBootstrap]): auto =
|
2023-01-12 17:11:38 +00:00
|
|
|
typedesc[ForkedLightClientBootstrap]
|
|
|
|
|
2023-01-14 21:19:50 +00:00
|
|
|
template Forked*(x: typedesc[ForkyLightClientUpdate]): auto =
|
2023-01-12 17:11:38 +00:00
|
|
|
typedesc[ForkedLightClientUpdate]
|
|
|
|
|
2023-01-14 21:19:50 +00:00
|
|
|
template Forked*(x: typedesc[ForkyLightClientFinalityUpdate]): auto =
|
2023-01-12 17:11:38 +00:00
|
|
|
typedesc[ForkedLightClientFinalityUpdate]
|
|
|
|
|
2023-01-14 21:19:50 +00:00
|
|
|
template Forked*(x: typedesc[ForkyLightClientOptimisticUpdate]): auto =
|
2023-01-12 17:11:38 +00:00
|
|
|
typedesc[ForkedLightClientOptimisticUpdate]
|
|
|
|
|
2023-01-14 21:19:50 +00:00
|
|
|
template Forked*(x: typedesc[ForkyLightClientStore]): auto =
|
|
|
|
typedesc[ForkedLightClientStore]
|
|
|
|
|
|
|
|
template withAll*(
|
|
|
|
x: typedesc[LightClientDataFork], body: untyped): untyped =
|
2024-06-21 13:02:01 +00:00
|
|
|
static: doAssert LightClientDataFork.high == LightClientDataFork.Electra
|
|
|
|
block:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Electra
|
|
|
|
body
|
2023-01-19 22:53:37 +00:00
|
|
|
block:
|
2023-03-10 17:16:26 +00:00
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Deneb
|
2023-01-19 22:53:37 +00:00
|
|
|
body
|
2023-01-18 14:32:57 +00:00
|
|
|
block:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Capella
|
|
|
|
body
|
2023-01-14 21:19:50 +00:00
|
|
|
block:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Altair
|
|
|
|
body
|
|
|
|
block:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.None
|
|
|
|
body
|
|
|
|
|
|
|
|
template withLcDataFork*(
|
|
|
|
x: LightClientDataFork, body: untyped): untyped =
|
|
|
|
case x
|
2024-06-21 13:02:01 +00:00
|
|
|
of LightClientDataFork.Electra:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Electra
|
|
|
|
body
|
2023-03-10 17:16:26 +00:00
|
|
|
of LightClientDataFork.Deneb:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Deneb
|
2023-01-19 22:53:37 +00:00
|
|
|
body
|
2023-01-18 14:32:57 +00:00
|
|
|
of LightClientDataFork.Capella:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Capella
|
|
|
|
body
|
2023-01-14 21:19:50 +00:00
|
|
|
of LightClientDataFork.Altair:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Altair
|
|
|
|
body
|
|
|
|
of LightClientDataFork.None:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.None
|
|
|
|
body
|
|
|
|
|
2023-01-16 15:53:45 +00:00
|
|
|
template withForkyHeader*(
|
|
|
|
x: ForkedLightClientHeader, body: untyped): untyped =
|
|
|
|
case x.kind
|
2024-06-21 13:02:01 +00:00
|
|
|
of LightClientDataFork.Electra:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Electra
|
|
|
|
template forkyHeader: untyped {.inject, used.} = x.electraData
|
|
|
|
body
|
2023-03-10 17:16:26 +00:00
|
|
|
of LightClientDataFork.Deneb:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Deneb
|
|
|
|
template forkyHeader: untyped {.inject, used.} = x.denebData
|
2023-01-19 22:53:37 +00:00
|
|
|
body
|
2023-01-18 14:32:57 +00:00
|
|
|
of LightClientDataFork.Capella:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Capella
|
|
|
|
template forkyHeader: untyped {.inject, used.} = x.capellaData
|
|
|
|
body
|
2023-01-16 15:53:45 +00:00
|
|
|
of LightClientDataFork.Altair:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Altair
|
|
|
|
template forkyHeader: untyped {.inject, used.} = x.altairData
|
|
|
|
body
|
|
|
|
of LightClientDataFork.None:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.None
|
|
|
|
body
|
|
|
|
|
2023-01-12 17:11:38 +00:00
|
|
|
template withForkyBootstrap*(
|
|
|
|
x: ForkedLightClientBootstrap, body: untyped): untyped =
|
|
|
|
case x.kind
|
2024-06-21 13:02:01 +00:00
|
|
|
of LightClientDataFork.Electra:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Electra
|
|
|
|
template forkyBootstrap: untyped {.inject, used.} = x.electraData
|
|
|
|
body
|
2023-03-10 17:16:26 +00:00
|
|
|
of LightClientDataFork.Deneb:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Deneb
|
|
|
|
template forkyBootstrap: untyped {.inject, used.} = x.denebData
|
2023-01-19 22:53:37 +00:00
|
|
|
body
|
2023-01-18 14:32:57 +00:00
|
|
|
of LightClientDataFork.Capella:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Capella
|
|
|
|
template forkyBootstrap: untyped {.inject, used.} = x.capellaData
|
|
|
|
body
|
2023-01-12 17:11:38 +00:00
|
|
|
of LightClientDataFork.Altair:
|
2023-01-14 21:19:50 +00:00
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Altair
|
|
|
|
template forkyBootstrap: untyped {.inject, used.} = x.altairData
|
2023-01-12 17:11:38 +00:00
|
|
|
body
|
|
|
|
of LightClientDataFork.None:
|
2023-01-14 21:19:50 +00:00
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.None
|
2023-01-12 17:11:38 +00:00
|
|
|
body
|
|
|
|
|
|
|
|
template withForkyUpdate*(
|
|
|
|
x: ForkedLightClientUpdate, body: untyped): untyped =
|
|
|
|
case x.kind
|
2024-06-21 13:02:01 +00:00
|
|
|
of LightClientDataFork.Electra:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Electra
|
|
|
|
template forkyUpdate: untyped {.inject, used.} = x.electraData
|
|
|
|
body
|
2023-03-10 17:16:26 +00:00
|
|
|
of LightClientDataFork.Deneb:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Deneb
|
|
|
|
template forkyUpdate: untyped {.inject, used.} = x.denebData
|
2023-01-19 22:53:37 +00:00
|
|
|
body
|
2023-01-18 14:32:57 +00:00
|
|
|
of LightClientDataFork.Capella:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Capella
|
|
|
|
template forkyUpdate: untyped {.inject, used.} = x.capellaData
|
|
|
|
body
|
2023-01-12 17:11:38 +00:00
|
|
|
of LightClientDataFork.Altair:
|
2023-01-14 21:19:50 +00:00
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Altair
|
|
|
|
template forkyUpdate: untyped {.inject, used.} = x.altairData
|
2023-01-12 17:11:38 +00:00
|
|
|
body
|
|
|
|
of LightClientDataFork.None:
|
2023-01-14 21:19:50 +00:00
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.None
|
2023-01-12 17:11:38 +00:00
|
|
|
body
|
|
|
|
|
|
|
|
template withForkyFinalityUpdate*(
|
|
|
|
x: ForkedLightClientFinalityUpdate, body: untyped): untyped =
|
|
|
|
case x.kind
|
2024-06-21 13:02:01 +00:00
|
|
|
of LightClientDataFork.Electra:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Electra
|
|
|
|
template forkyFinalityUpdate: untyped {.inject, used.} = x.electraData
|
|
|
|
body
|
2023-03-10 17:16:26 +00:00
|
|
|
of LightClientDataFork.Deneb:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Deneb
|
|
|
|
template forkyFinalityUpdate: untyped {.inject, used.} = x.denebData
|
2023-01-19 22:53:37 +00:00
|
|
|
body
|
2023-01-18 14:32:57 +00:00
|
|
|
of LightClientDataFork.Capella:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Capella
|
|
|
|
template forkyFinalityUpdate: untyped {.inject, used.} = x.capellaData
|
|
|
|
body
|
2023-01-12 17:11:38 +00:00
|
|
|
of LightClientDataFork.Altair:
|
2023-01-14 21:19:50 +00:00
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Altair
|
|
|
|
template forkyFinalityUpdate: untyped {.inject, used.} = x.altairData
|
2023-01-12 17:11:38 +00:00
|
|
|
body
|
|
|
|
of LightClientDataFork.None:
|
2023-01-14 21:19:50 +00:00
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.None
|
2023-01-12 17:11:38 +00:00
|
|
|
body
|
|
|
|
|
|
|
|
template withForkyOptimisticUpdate*(
|
|
|
|
x: ForkedLightClientOptimisticUpdate, body: untyped): untyped =
|
|
|
|
case x.kind
|
2024-06-21 13:02:01 +00:00
|
|
|
of LightClientDataFork.Electra:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Electra
|
|
|
|
template forkyOptimisticUpdate: untyped {.inject, used.} = x.electraData
|
|
|
|
body
|
2023-03-10 17:16:26 +00:00
|
|
|
of LightClientDataFork.Deneb:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Deneb
|
|
|
|
template forkyOptimisticUpdate: untyped {.inject, used.} = x.denebData
|
2023-01-19 22:53:37 +00:00
|
|
|
body
|
2023-01-18 14:32:57 +00:00
|
|
|
of LightClientDataFork.Capella:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Capella
|
|
|
|
template forkyOptimisticUpdate: untyped {.inject, used.} = x.capellaData
|
|
|
|
body
|
2023-01-12 17:11:38 +00:00
|
|
|
of LightClientDataFork.Altair:
|
2023-01-14 21:19:50 +00:00
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Altair
|
|
|
|
template forkyOptimisticUpdate: untyped {.inject, used.} = x.altairData
|
2023-01-12 17:11:38 +00:00
|
|
|
body
|
|
|
|
of LightClientDataFork.None:
|
2023-01-14 21:19:50 +00:00
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.None
|
2023-01-12 17:11:38 +00:00
|
|
|
body
|
|
|
|
|
|
|
|
template withForkyObject*(
|
|
|
|
x: SomeForkedLightClientObject, body: untyped): untyped =
|
|
|
|
case x.kind
|
2024-06-21 13:02:01 +00:00
|
|
|
of LightClientDataFork.Electra:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Electra
|
|
|
|
template forkyObject: untyped {.inject, used.} = x.electraData
|
|
|
|
body
|
2023-03-10 17:16:26 +00:00
|
|
|
of LightClientDataFork.Deneb:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Deneb
|
|
|
|
template forkyObject: untyped {.inject, used.} = x.denebData
|
2023-01-19 22:53:37 +00:00
|
|
|
body
|
2023-01-18 14:32:57 +00:00
|
|
|
of LightClientDataFork.Capella:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Capella
|
|
|
|
template forkyObject: untyped {.inject, used.} = x.capellaData
|
|
|
|
body
|
2023-01-12 17:11:38 +00:00
|
|
|
of LightClientDataFork.Altair:
|
2023-01-14 21:19:50 +00:00
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Altair
|
|
|
|
template forkyObject: untyped {.inject, used.} = x.altairData
|
|
|
|
body
|
|
|
|
of LightClientDataFork.None:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.None
|
|
|
|
body
|
|
|
|
|
|
|
|
template withForkyStore*(
|
|
|
|
x: ForkedLightClientStore, body: untyped): untyped =
|
|
|
|
case x.kind
|
2024-06-21 13:02:01 +00:00
|
|
|
of LightClientDataFork.Electra:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Electra
|
|
|
|
template forkyStore: untyped {.inject, used.} = x.electraData
|
|
|
|
body
|
2023-03-10 17:16:26 +00:00
|
|
|
of LightClientDataFork.Deneb:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Deneb
|
|
|
|
template forkyStore: untyped {.inject, used.} = x.denebData
|
2023-01-19 22:53:37 +00:00
|
|
|
body
|
2023-01-18 14:32:57 +00:00
|
|
|
of LightClientDataFork.Capella:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Capella
|
|
|
|
template forkyStore: untyped {.inject, used.} = x.capellaData
|
|
|
|
body
|
2023-01-14 21:19:50 +00:00
|
|
|
of LightClientDataFork.Altair:
|
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.Altair
|
|
|
|
template forkyStore: untyped {.inject, used.} = x.altairData
|
2023-01-12 17:11:38 +00:00
|
|
|
body
|
|
|
|
of LightClientDataFork.None:
|
2023-01-14 21:19:50 +00:00
|
|
|
const lcDataFork {.inject, used.} = LightClientDataFork.None
|
2023-01-12 17:11:38 +00:00
|
|
|
body
|
|
|
|
|
2023-10-04 16:11:45 +00:00
|
|
|
func init*(
|
|
|
|
x: typedesc[
|
|
|
|
ForkedLightClientHeader |
|
|
|
|
SomeForkedLightClientObject |
|
|
|
|
ForkedLightClientStore],
|
|
|
|
forkyData:
|
|
|
|
ForkyLightClientHeader |
|
|
|
|
SomeForkyLightClientObject |
|
|
|
|
ForkyLightClientStore): auto =
|
|
|
|
type ResultType = typeof(forkyData).Forked
|
|
|
|
static: doAssert ResultType is x
|
|
|
|
const kind = typeof(forkyData).kind
|
2024-06-21 13:02:01 +00:00
|
|
|
when kind == LightClientDataFork.Electra:
|
|
|
|
ResultType(kind: kind, electraData: forkyData)
|
|
|
|
elif kind == LightClientDataFork.Deneb:
|
2023-10-04 16:11:45 +00:00
|
|
|
ResultType(kind: kind, denebData: forkyData)
|
|
|
|
elif kind == LightClientDataFork.Capella:
|
|
|
|
ResultType(kind: kind, capellaData: forkyData)
|
|
|
|
elif kind == LightClientDataFork.Altair:
|
|
|
|
ResultType(kind: kind, altairData: forkyData)
|
|
|
|
else:
|
|
|
|
static: raiseAssert "Unreachable"
|
|
|
|
|
|
|
|
template forky*(
|
|
|
|
x:
|
|
|
|
ForkedLightClientHeader |
|
|
|
|
SomeForkedLightClientObject |
|
|
|
|
ForkedLightClientStore,
|
|
|
|
kind: static LightClientDataFork): untyped =
|
2024-06-21 13:02:01 +00:00
|
|
|
when kind == LightClientDataFork.Electra:
|
|
|
|
x.electraData
|
|
|
|
elif kind == LightClientDataFork.Deneb:
|
2023-10-04 16:11:45 +00:00
|
|
|
x.denebData
|
|
|
|
elif kind == LightClientDataFork.Capella:
|
|
|
|
x.capellaData
|
|
|
|
elif kind == LightClientDataFork.Altair:
|
|
|
|
x.altairData
|
|
|
|
else:
|
|
|
|
static: raiseAssert "Unreachable"
|
|
|
|
|
2023-01-23 19:38:03 +00:00
|
|
|
func toFull*(
|
|
|
|
update: SomeForkyLightClientUpdate): auto =
|
|
|
|
type ResultType = typeof(update).kind.LightClientUpdate
|
|
|
|
when update is ForkyLightClientUpdate:
|
2023-11-17 23:03:27 +00:00
|
|
|
static: doAssert update is ResultType
|
2023-01-23 19:38:03 +00:00
|
|
|
update
|
|
|
|
elif update is SomeForkyLightClientUpdateWithFinality:
|
|
|
|
ResultType(
|
|
|
|
attested_header: update.attested_header,
|
|
|
|
finalized_header: update.finalized_header,
|
|
|
|
finality_branch: update.finality_branch,
|
|
|
|
sync_aggregate: update.sync_aggregate,
|
|
|
|
signature_slot: update.signature_slot)
|
|
|
|
else:
|
|
|
|
ResultType(
|
|
|
|
attested_header: update.attested_header,
|
|
|
|
sync_aggregate: update.sync_aggregate,
|
|
|
|
signature_slot: update.signature_slot)
|
|
|
|
|
|
|
|
func toFull*(
|
2023-01-14 21:19:50 +00:00
|
|
|
update: SomeForkedLightClientUpdate): ForkedLightClientUpdate =
|
|
|
|
when update is ForkyLightClientUpdate:
|
|
|
|
update
|
|
|
|
else:
|
|
|
|
withForkyObject(update):
|
|
|
|
when lcDataFork > LightClientDataFork.None:
|
2023-10-04 16:11:45 +00:00
|
|
|
ForkedLightClientUpdate.init(forkyObject.toFull())
|
2023-01-14 21:19:50 +00:00
|
|
|
else:
|
|
|
|
default(ForkedLightClientUpdate)
|
|
|
|
|
2023-01-23 19:38:03 +00:00
|
|
|
func toFinality*(
|
|
|
|
update: SomeForkyLightClientUpdate): auto =
|
|
|
|
type ResultType = typeof(update).kind.LightClientFinalityUpdate
|
|
|
|
when update is ForkyLightClientFinalityUpdate:
|
|
|
|
update
|
|
|
|
elif update is SomeForkyLightClientUpdateWithFinality:
|
|
|
|
ResultType(
|
|
|
|
attested_header: update.attested_header,
|
|
|
|
finalized_header: update.finalized_header,
|
|
|
|
finality_branch: update.finality_branch,
|
|
|
|
sync_aggregate: update.sync_aggregate,
|
|
|
|
signature_slot: update.signature_slot)
|
|
|
|
else:
|
|
|
|
ResultType(
|
|
|
|
attested_header: update.attested_header,
|
|
|
|
sync_aggregate: update.sync_aggregate,
|
|
|
|
signature_slot: update.signature_slot)
|
|
|
|
|
|
|
|
func toFinality*(
|
2023-01-14 21:19:50 +00:00
|
|
|
update: SomeForkedLightClientUpdate): ForkedLightClientFinalityUpdate =
|
|
|
|
when update is ForkyLightClientFinalityUpdate:
|
|
|
|
update
|
|
|
|
else:
|
|
|
|
withForkyObject(update):
|
|
|
|
when lcDataFork > LightClientDataFork.None:
|
2023-10-04 16:11:45 +00:00
|
|
|
ForkedLightClientFinalityUpdate.init(forkyObject.toFinality())
|
2023-01-14 21:19:50 +00:00
|
|
|
else:
|
|
|
|
default(ForkedLightClientFinalityUpdate)
|
|
|
|
|
2023-01-23 19:38:03 +00:00
|
|
|
func toOptimistic*(
|
|
|
|
update: SomeForkyLightClientUpdate): auto =
|
|
|
|
type ResultType = typeof(update).kind.LightClientOptimisticUpdate
|
|
|
|
when update is ForkyLightClientOptimisticUpdate:
|
|
|
|
update
|
|
|
|
else:
|
|
|
|
ResultType(
|
|
|
|
attested_header: update.attested_header,
|
|
|
|
sync_aggregate: update.sync_aggregate,
|
|
|
|
signature_slot: update.signature_slot)
|
|
|
|
|
|
|
|
func toOptimistic*(
|
2023-01-12 17:11:38 +00:00
|
|
|
update: SomeForkedLightClientUpdate): ForkedLightClientOptimisticUpdate =
|
|
|
|
when update is ForkyLightClientOptimisticUpdate:
|
|
|
|
update
|
|
|
|
else:
|
|
|
|
withForkyObject(update):
|
2023-01-14 21:19:50 +00:00
|
|
|
when lcDataFork > LightClientDataFork.None:
|
2023-10-04 16:11:45 +00:00
|
|
|
ForkedLightClientOptimisticUpdate.init(forkyObject.toOptimistic())
|
2023-01-12 17:11:38 +00:00
|
|
|
else:
|
|
|
|
default(ForkedLightClientOptimisticUpdate)
|
|
|
|
|
2023-01-23 19:38:03 +00:00
|
|
|
func matches*[A, B: SomeForkyLightClientUpdate](a: A, b: B): bool =
|
|
|
|
static: doAssert typeof(A).kind == typeof(B).kind
|
|
|
|
if a.attested_header != b.attested_header:
|
|
|
|
return false
|
|
|
|
when a is SomeForkyLightClientUpdateWithSyncCommittee and
|
|
|
|
b is SomeForkyLightClientUpdateWithSyncCommittee:
|
|
|
|
if a.next_sync_committee != b.next_sync_committee:
|
|
|
|
return false
|
|
|
|
if a.next_sync_committee_branch != b.next_sync_committee_branch:
|
|
|
|
return false
|
|
|
|
when a is SomeForkyLightClientUpdateWithFinality and
|
|
|
|
b is SomeForkyLightClientUpdateWithFinality:
|
|
|
|
if a.finalized_header != b.finalized_header:
|
|
|
|
return false
|
|
|
|
if a.finality_branch != b.finality_branch:
|
|
|
|
return false
|
|
|
|
if a.sync_aggregate != b.sync_aggregate:
|
|
|
|
return false
|
|
|
|
if a.signature_slot != b.signature_slot:
|
|
|
|
return false
|
|
|
|
true
|
|
|
|
|
2023-01-12 17:11:38 +00:00
|
|
|
func matches*[A, B: SomeForkedLightClientUpdate](a: A, b: B): bool =
|
|
|
|
if a.kind != b.kind:
|
|
|
|
return false
|
|
|
|
withForkyObject(a):
|
2023-01-14 21:19:50 +00:00
|
|
|
when lcDataFork > LightClientDataFork.None:
|
2023-01-12 17:11:38 +00:00
|
|
|
forkyObject.matches(b.forky(lcDataFork))
|
|
|
|
else:
|
|
|
|
true
|
|
|
|
|
2023-01-16 15:53:45 +00:00
|
|
|
func migrateToDataFork*(
|
|
|
|
x: var ForkedLightClientHeader,
|
|
|
|
newKind: static LightClientDataFork) =
|
|
|
|
if newKind == x.kind:
|
|
|
|
# Already at correct kind
|
|
|
|
discard
|
|
|
|
elif newKind < x.kind:
|
|
|
|
# Downgrade not supported, re-initialize
|
|
|
|
x = ForkedLightClientHeader(kind: newKind)
|
|
|
|
else:
|
|
|
|
# Upgrade to Altair
|
|
|
|
when newKind >= LightClientDataFork.Altair:
|
|
|
|
if x.kind == LightClientDataFork.None:
|
|
|
|
x = ForkedLightClientHeader(
|
|
|
|
kind: LightClientDataFork.Altair)
|
|
|
|
|
2023-01-18 14:32:57 +00:00
|
|
|
# Upgrade to Capella
|
|
|
|
when newKind >= LightClientDataFork.Capella:
|
|
|
|
if x.kind == LightClientDataFork.Altair:
|
|
|
|
x = ForkedLightClientHeader(
|
|
|
|
kind: LightClientDataFork.Capella,
|
|
|
|
capellaData: upgrade_lc_header_to_capella(
|
|
|
|
x.forky(LightClientDataFork.Altair)))
|
|
|
|
|
2023-03-10 17:16:26 +00:00
|
|
|
# Upgrade to Deneb
|
|
|
|
when newKind >= LightClientDataFork.Deneb:
|
2023-01-19 22:53:37 +00:00
|
|
|
if x.kind == LightClientDataFork.Capella:
|
|
|
|
x = ForkedLightClientHeader(
|
2023-03-10 17:16:26 +00:00
|
|
|
kind: LightClientDataFork.Deneb,
|
|
|
|
denebData: upgrade_lc_header_to_deneb(
|
2023-01-19 22:53:37 +00:00
|
|
|
x.forky(LightClientDataFork.Capella)))
|
|
|
|
|
2024-06-21 13:02:01 +00:00
|
|
|
# Upgrade to Electra
|
|
|
|
when newKind >= LightClientDataFork.Electra:
|
|
|
|
if x.kind == LightClientDataFork.Deneb:
|
|
|
|
x = ForkedLightClientHeader(
|
|
|
|
kind: LightClientDataFork.Electra,
|
|
|
|
electraData: upgrade_lc_header_to_electra(
|
|
|
|
x.forky(LightClientDataFork.Deneb)))
|
|
|
|
|
|
|
|
static: doAssert LightClientDataFork.high == LightClientDataFork.Electra
|
2023-01-16 15:53:45 +00:00
|
|
|
doAssert x.kind == newKind
|
|
|
|
|
2023-01-12 17:11:38 +00:00
|
|
|
func migrateToDataFork*(
|
|
|
|
x: var ForkedLightClientBootstrap,
|
|
|
|
newKind: static LightClientDataFork) =
|
|
|
|
if newKind == x.kind:
|
|
|
|
# Already at correct kind
|
|
|
|
discard
|
|
|
|
elif newKind < x.kind:
|
|
|
|
# Downgrade not supported, re-initialize
|
|
|
|
x = ForkedLightClientBootstrap(kind: newKind)
|
|
|
|
else:
|
|
|
|
# Upgrade to Altair
|
|
|
|
when newKind >= LightClientDataFork.Altair:
|
2023-01-14 21:19:50 +00:00
|
|
|
if x.kind == LightClientDataFork.None:
|
2023-01-12 17:11:38 +00:00
|
|
|
x = ForkedLightClientBootstrap(
|
|
|
|
kind: LightClientDataFork.Altair)
|
|
|
|
|
2023-01-18 14:32:57 +00:00
|
|
|
# Upgrade to Capella
|
|
|
|
when newKind >= LightClientDataFork.Capella:
|
|
|
|
if x.kind == LightClientDataFork.Altair:
|
|
|
|
x = ForkedLightClientBootstrap(
|
|
|
|
kind: LightClientDataFork.Capella,
|
|
|
|
capellaData: upgrade_lc_bootstrap_to_capella(
|
|
|
|
x.forky(LightClientDataFork.Altair)))
|
|
|
|
|
2023-03-10 17:16:26 +00:00
|
|
|
# Upgrade to Deneb
|
|
|
|
when newKind >= LightClientDataFork.Deneb:
|
2023-01-19 22:53:37 +00:00
|
|
|
if x.kind == LightClientDataFork.Capella:
|
|
|
|
x = ForkedLightClientBootstrap(
|
2023-03-10 17:16:26 +00:00
|
|
|
kind: LightClientDataFork.Deneb,
|
|
|
|
denebData: upgrade_lc_bootstrap_to_deneb(
|
2023-01-19 22:53:37 +00:00
|
|
|
x.forky(LightClientDataFork.Capella)))
|
|
|
|
|
2024-06-21 13:02:01 +00:00
|
|
|
# Upgrade to Electra
|
|
|
|
when newKind >= LightClientDataFork.Electra:
|
|
|
|
if x.kind == LightClientDataFork.Deneb:
|
|
|
|
x = ForkedLightClientBootstrap(
|
|
|
|
kind: LightClientDataFork.Electra,
|
|
|
|
electraData: upgrade_lc_bootstrap_to_electra(
|
|
|
|
x.forky(LightClientDataFork.Deneb)))
|
|
|
|
|
|
|
|
static: doAssert LightClientDataFork.high == LightClientDataFork.Electra
|
2023-01-12 17:11:38 +00:00
|
|
|
doAssert x.kind == newKind
|
|
|
|
|
|
|
|
func migrateToDataFork*(
|
|
|
|
x: var ForkedLightClientUpdate,
|
|
|
|
newKind: static LightClientDataFork) =
|
|
|
|
if newKind == x.kind:
|
|
|
|
# Already at correct kind
|
|
|
|
discard
|
|
|
|
elif newKind < x.kind:
|
|
|
|
# Downgrade not supported, re-initialize
|
|
|
|
x = ForkedLightClientUpdate(kind: newKind)
|
|
|
|
else:
|
|
|
|
# Upgrade to Altair
|
|
|
|
when newKind >= LightClientDataFork.Altair:
|
2023-01-14 21:19:50 +00:00
|
|
|
if x.kind == LightClientDataFork.None:
|
2023-01-12 17:11:38 +00:00
|
|
|
x = ForkedLightClientUpdate(
|
|
|
|
kind: LightClientDataFork.Altair)
|
|
|
|
|
2023-01-18 14:32:57 +00:00
|
|
|
# Upgrade to Capella
|
|
|
|
when newKind >= LightClientDataFork.Capella:
|
|
|
|
if x.kind == LightClientDataFork.Altair:
|
|
|
|
x = ForkedLightClientUpdate(
|
|
|
|
kind: LightClientDataFork.Capella,
|
|
|
|
capellaData: upgrade_lc_update_to_capella(
|
|
|
|
x.forky(LightClientDataFork.Altair)))
|
|
|
|
|
2023-03-10 17:16:26 +00:00
|
|
|
# Upgrade to Deneb
|
|
|
|
when newKind >= LightClientDataFork.Deneb:
|
2023-01-19 22:53:37 +00:00
|
|
|
if x.kind == LightClientDataFork.Capella:
|
|
|
|
x = ForkedLightClientUpdate(
|
2023-03-10 17:16:26 +00:00
|
|
|
kind: LightClientDataFork.Deneb,
|
|
|
|
denebData: upgrade_lc_update_to_deneb(
|
2023-01-19 22:53:37 +00:00
|
|
|
x.forky(LightClientDataFork.Capella)))
|
|
|
|
|
2024-06-21 13:02:01 +00:00
|
|
|
# Upgrade to Electra
|
|
|
|
when newKind >= LightClientDataFork.Electra:
|
|
|
|
if x.kind == LightClientDataFork.Deneb:
|
|
|
|
x = ForkedLightClientUpdate(
|
|
|
|
kind: LightClientDataFork.Electra,
|
|
|
|
electraData: upgrade_lc_update_to_electra(
|
|
|
|
x.forky(LightClientDataFork.Deneb)))
|
|
|
|
|
|
|
|
static: doAssert LightClientDataFork.high == LightClientDataFork.Electra
|
2023-01-12 17:11:38 +00:00
|
|
|
doAssert x.kind == newKind
|
|
|
|
|
|
|
|
func migrateToDataFork*(
|
|
|
|
x: var ForkedLightClientFinalityUpdate,
|
|
|
|
newKind: static LightClientDataFork) =
|
|
|
|
if newKind == x.kind:
|
|
|
|
# Already at correct kind
|
|
|
|
discard
|
|
|
|
elif newKind < x.kind:
|
|
|
|
# Downgrade not supported, re-initialize
|
|
|
|
x = ForkedLightClientFinalityUpdate(kind: newKind)
|
|
|
|
else:
|
|
|
|
# Upgrade to Altair
|
|
|
|
when newKind >= LightClientDataFork.Altair:
|
2023-01-14 21:19:50 +00:00
|
|
|
if x.kind == LightClientDataFork.None:
|
2023-01-12 17:11:38 +00:00
|
|
|
x = ForkedLightClientFinalityUpdate(
|
|
|
|
kind: LightClientDataFork.Altair)
|
|
|
|
|
2023-01-18 14:32:57 +00:00
|
|
|
# Upgrade to Capella
|
|
|
|
when newKind >= LightClientDataFork.Capella:
|
|
|
|
if x.kind == LightClientDataFork.Altair:
|
|
|
|
x = ForkedLightClientFinalityUpdate(
|
|
|
|
kind: LightClientDataFork.Capella,
|
|
|
|
capellaData: upgrade_lc_finality_update_to_capella(
|
|
|
|
x.forky(LightClientDataFork.Altair)))
|
|
|
|
|
2023-03-10 17:16:26 +00:00
|
|
|
# Upgrade to Deneb
|
|
|
|
when newKind >= LightClientDataFork.Deneb:
|
2023-01-19 22:53:37 +00:00
|
|
|
if x.kind == LightClientDataFork.Capella:
|
|
|
|
x = ForkedLightClientFinalityUpdate(
|
2023-03-10 17:16:26 +00:00
|
|
|
kind: LightClientDataFork.Deneb,
|
|
|
|
denebData: upgrade_lc_finality_update_to_deneb(
|
2023-01-19 22:53:37 +00:00
|
|
|
x.forky(LightClientDataFork.Capella)))
|
|
|
|
|
2024-06-21 13:02:01 +00:00
|
|
|
# Upgrade to Electra
|
|
|
|
when newKind >= LightClientDataFork.Electra:
|
|
|
|
if x.kind == LightClientDataFork.Deneb:
|
|
|
|
x = ForkedLightClientFinalityUpdate(
|
|
|
|
kind: LightClientDataFork.Electra,
|
|
|
|
electraData: upgrade_lc_finality_update_to_electra(
|
|
|
|
x.forky(LightClientDataFork.Deneb)))
|
|
|
|
|
|
|
|
static: doAssert LightClientDataFork.high == LightClientDataFork.Electra
|
2023-01-12 17:11:38 +00:00
|
|
|
doAssert x.kind == newKind
|
|
|
|
|
|
|
|
func migrateToDataFork*(
|
|
|
|
x: var ForkedLightClientOptimisticUpdate,
|
|
|
|
newKind: static LightClientDataFork) =
|
|
|
|
if newKind == x.kind:
|
|
|
|
# Already at correct kind
|
|
|
|
discard
|
|
|
|
elif newKind < x.kind:
|
|
|
|
# Downgrade not supported, re-initialize
|
|
|
|
x = ForkedLightClientOptimisticUpdate(kind: newKind)
|
|
|
|
else:
|
|
|
|
# Upgrade to Altair
|
|
|
|
when newKind >= LightClientDataFork.Altair:
|
2023-01-14 21:19:50 +00:00
|
|
|
if x.kind == LightClientDataFork.None:
|
2023-01-12 17:11:38 +00:00
|
|
|
x = ForkedLightClientOptimisticUpdate(
|
|
|
|
kind: LightClientDataFork.Altair)
|
|
|
|
|
2023-01-18 14:32:57 +00:00
|
|
|
# Upgrade to Capella
|
|
|
|
when newKind >= LightClientDataFork.Capella:
|
|
|
|
if x.kind == LightClientDataFork.Altair:
|
|
|
|
x = ForkedLightClientOptimisticUpdate(
|
|
|
|
kind: LightClientDataFork.Capella,
|
|
|
|
capellaData: upgrade_lc_optimistic_update_to_capella(
|
|
|
|
x.forky(LightClientDataFork.Altair)))
|
|
|
|
|
2023-03-10 17:16:26 +00:00
|
|
|
# Upgrade to Deneb
|
|
|
|
when newKind >= LightClientDataFork.Deneb:
|
2023-01-19 22:53:37 +00:00
|
|
|
if x.kind == LightClientDataFork.Capella:
|
|
|
|
x = ForkedLightClientOptimisticUpdate(
|
2023-03-10 17:16:26 +00:00
|
|
|
kind: LightClientDataFork.Deneb,
|
|
|
|
denebData: upgrade_lc_optimistic_update_to_deneb(
|
2023-01-19 22:53:37 +00:00
|
|
|
x.forky(LightClientDataFork.Capella)))
|
|
|
|
|
2024-06-21 13:02:01 +00:00
|
|
|
# Upgrade to Electra
|
|
|
|
when newKind >= LightClientDataFork.Electra:
|
|
|
|
if x.kind == LightClientDataFork.Deneb:
|
|
|
|
x = ForkedLightClientOptimisticUpdate(
|
|
|
|
kind: LightClientDataFork.Electra,
|
|
|
|
electraData: upgrade_lc_optimistic_update_to_electra(
|
|
|
|
x.forky(LightClientDataFork.Deneb)))
|
|
|
|
|
|
|
|
static: doAssert LightClientDataFork.high == LightClientDataFork.Electra
|
2023-01-12 17:11:38 +00:00
|
|
|
doAssert x.kind == newKind
|
|
|
|
|
2023-01-14 21:19:50 +00:00
|
|
|
func migrateToDataFork*(
|
|
|
|
x: var ForkedLightClientStore,
|
|
|
|
newKind: static LightClientDataFork) =
|
|
|
|
if newKind == x.kind:
|
|
|
|
# Already at correct kind
|
|
|
|
discard
|
|
|
|
elif newKind < x.kind:
|
|
|
|
# Downgrade not supported, re-initialize
|
|
|
|
x = ForkedLightClientStore(kind: newKind)
|
|
|
|
else:
|
|
|
|
# Upgrade to Altair
|
|
|
|
when newKind >= LightClientDataFork.Altair:
|
|
|
|
if x.kind == LightClientDataFork.None:
|
|
|
|
x = ForkedLightClientStore(
|
|
|
|
kind: LightClientDataFork.Altair)
|
|
|
|
|
2023-01-18 14:32:57 +00:00
|
|
|
# Upgrade to Capella
|
|
|
|
when newKind >= LightClientDataFork.Capella:
|
|
|
|
if x.kind == LightClientDataFork.Altair:
|
|
|
|
x = ForkedLightClientStore(
|
|
|
|
kind: LightClientDataFork.Capella,
|
|
|
|
capellaData: upgrade_lc_store_to_capella(
|
|
|
|
x.forky(LightClientDataFork.Altair)))
|
|
|
|
|
2023-03-10 17:16:26 +00:00
|
|
|
# Upgrade to Deneb
|
|
|
|
when newKind >= LightClientDataFork.Deneb:
|
2023-01-19 22:53:37 +00:00
|
|
|
if x.kind == LightClientDataFork.Capella:
|
|
|
|
x = ForkedLightClientStore(
|
2023-03-10 17:16:26 +00:00
|
|
|
kind: LightClientDataFork.Deneb,
|
|
|
|
denebData: upgrade_lc_store_to_deneb(
|
2023-01-19 22:53:37 +00:00
|
|
|
x.forky(LightClientDataFork.Capella)))
|
|
|
|
|
2024-06-21 13:02:01 +00:00
|
|
|
# Upgrade to Electra
|
|
|
|
when newKind >= LightClientDataFork.Electra:
|
|
|
|
if x.kind == LightClientDataFork.Deneb:
|
|
|
|
x = ForkedLightClientStore(
|
|
|
|
kind: LightClientDataFork.Electra,
|
|
|
|
electraData: upgrade_lc_store_to_electra(
|
|
|
|
x.forky(LightClientDataFork.Deneb)))
|
|
|
|
|
|
|
|
static: doAssert LightClientDataFork.high == LightClientDataFork.Electra
|
2023-01-14 21:19:50 +00:00
|
|
|
doAssert x.kind == newKind
|
|
|
|
|
|
|
|
func migratingToDataFork*[
|
2023-01-16 15:53:45 +00:00
|
|
|
T:
|
|
|
|
ForkedLightClientHeader |
|
|
|
|
SomeForkedLightClientObject |
|
|
|
|
ForkedLightClientStore](
|
2023-01-12 17:11:38 +00:00
|
|
|
x: T, newKind: static LightClientDataFork): T =
|
|
|
|
var upgradedObject = x
|
|
|
|
upgradedObject.migrateToDataFork(newKind)
|
|
|
|
upgradedObject
|
2023-01-13 15:46:35 +00:00
|
|
|
|
2023-12-05 02:34:45 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.5/specs/altair/light-client/full-node.md#block_to_light_client_header
|
2023-01-14 21:19:50 +00:00
|
|
|
func toAltairLightClientHeader(
|
|
|
|
blck: # `SomeSignedBeaconBlock` doesn't work here (Nim 1.6)
|
|
|
|
phase0.SignedBeaconBlock | phase0.TrustedSignedBeaconBlock |
|
|
|
|
altair.SignedBeaconBlock | altair.TrustedSignedBeaconBlock |
|
2023-01-18 14:32:57 +00:00
|
|
|
bellatrix.SignedBeaconBlock | bellatrix.TrustedSignedBeaconBlock
|
2023-01-14 21:19:50 +00:00
|
|
|
): altair.LightClientHeader =
|
|
|
|
altair.LightClientHeader(
|
|
|
|
beacon: blck.message.toBeaconBlockHeader())
|
|
|
|
|
2023-12-16 02:27:06 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.5/specs/capella/light-client/full-node.md#modified-block_to_light_client_header
|
2023-01-18 14:32:57 +00:00
|
|
|
func toCapellaLightClientHeader(
|
|
|
|
blck: # `SomeSignedBeaconBlock` doesn't work here (Nim 1.6)
|
|
|
|
phase0.SignedBeaconBlock | phase0.TrustedSignedBeaconBlock |
|
|
|
|
altair.SignedBeaconBlock | altair.TrustedSignedBeaconBlock |
|
|
|
|
bellatrix.SignedBeaconBlock | bellatrix.TrustedSignedBeaconBlock
|
|
|
|
): capella.LightClientHeader =
|
|
|
|
# Note that during fork transitions, `finalized_header` may still
|
|
|
|
# point to earlier forks. While Bellatrix blocks also contain an
|
|
|
|
# `ExecutionPayload` (minus `withdrawals_root`), it was not included
|
|
|
|
# in the corresponding light client data. To ensure compatibility
|
|
|
|
# with legacy data going through `upgrade_lc_header_to_capella`,
|
|
|
|
# leave out execution data.
|
|
|
|
capella.LightClientHeader(
|
|
|
|
beacon: blck.message.toBeaconBlockHeader())
|
|
|
|
|
|
|
|
func toCapellaLightClientHeader(
|
|
|
|
blck: # `SomeSignedBeaconBlock` doesn't work here (Nim 1.6)
|
2023-01-19 22:53:37 +00:00
|
|
|
capella.SignedBeaconBlock | capella.TrustedSignedBeaconBlock
|
2023-01-18 14:32:57 +00:00
|
|
|
): capella.LightClientHeader =
|
|
|
|
template payload: untyped = blck.message.body.execution_payload
|
|
|
|
capella.LightClientHeader(
|
|
|
|
beacon: blck.message.toBeaconBlockHeader(),
|
|
|
|
execution: capella.ExecutionPayloadHeader(
|
|
|
|
parent_hash: payload.parent_hash,
|
|
|
|
fee_recipient: payload.fee_recipient,
|
|
|
|
state_root: payload.state_root,
|
|
|
|
receipts_root: payload.receipts_root,
|
|
|
|
logs_bloom: payload.logs_bloom,
|
|
|
|
prev_randao: payload.prev_randao,
|
|
|
|
block_number: payload.block_number,
|
|
|
|
gas_limit: payload.gas_limit,
|
|
|
|
gas_used: payload.gas_used,
|
|
|
|
timestamp: payload.timestamp,
|
|
|
|
extra_data: payload.extra_data,
|
|
|
|
base_fee_per_gas: payload.base_fee_per_gas,
|
|
|
|
block_hash: payload.block_hash,
|
|
|
|
transactions_root: hash_tree_root(payload.transactions),
|
|
|
|
withdrawals_root: hash_tree_root(payload.withdrawals)),
|
|
|
|
execution_branch: blck.message.body.build_proof(
|
2023-11-09 12:54:44 +00:00
|
|
|
capella.EXECUTION_PAYLOAD_GINDEX).get)
|
2023-01-18 14:32:57 +00:00
|
|
|
|
2023-05-25 22:14:28 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-alpha.0/specs/deneb/light-client/full-node.md#modified-block_to_light_client_header
|
2023-03-10 17:16:26 +00:00
|
|
|
func toDenebLightClientHeader(
|
2023-01-19 22:53:37 +00:00
|
|
|
blck: # `SomeSignedBeaconBlock` doesn't work here (Nim 1.6)
|
|
|
|
phase0.SignedBeaconBlock | phase0.TrustedSignedBeaconBlock |
|
|
|
|
altair.SignedBeaconBlock | altair.TrustedSignedBeaconBlock |
|
|
|
|
bellatrix.SignedBeaconBlock | bellatrix.TrustedSignedBeaconBlock
|
2023-02-20 08:45:49 +00:00
|
|
|
): deneb.LightClientHeader =
|
2023-01-19 22:53:37 +00:00
|
|
|
# Note that during fork transitions, `finalized_header` may still
|
|
|
|
# point to earlier forks. While Bellatrix blocks also contain an
|
|
|
|
# `ExecutionPayload` (minus `withdrawals_root`), it was not included
|
|
|
|
# in the corresponding light client data. To ensure compatibility
|
|
|
|
# with legacy data going through `upgrade_lc_header_to_capella`,
|
|
|
|
# leave out execution data.
|
2023-02-20 08:45:49 +00:00
|
|
|
deneb.LightClientHeader(
|
2023-01-19 22:53:37 +00:00
|
|
|
beacon: blck.message.toBeaconBlockHeader())
|
|
|
|
|
2023-03-10 17:16:26 +00:00
|
|
|
func toDenebLightClientHeader(
|
2023-01-19 22:53:37 +00:00
|
|
|
blck: # `SomeSignedBeaconBlock` doesn't work here (Nim 1.6)
|
|
|
|
capella.SignedBeaconBlock | capella.TrustedSignedBeaconBlock
|
2023-02-20 08:45:49 +00:00
|
|
|
): deneb.LightClientHeader =
|
2023-01-19 22:53:37 +00:00
|
|
|
template payload: untyped = blck.message.body.execution_payload
|
2023-02-20 08:45:49 +00:00
|
|
|
deneb.LightClientHeader(
|
2023-01-19 22:53:37 +00:00
|
|
|
beacon: blck.message.toBeaconBlockHeader(),
|
2023-02-20 08:45:49 +00:00
|
|
|
execution: deneb.ExecutionPayloadHeader(
|
2023-01-19 22:53:37 +00:00
|
|
|
parent_hash: payload.parent_hash,
|
|
|
|
fee_recipient: payload.fee_recipient,
|
|
|
|
state_root: payload.state_root,
|
|
|
|
receipts_root: payload.receipts_root,
|
|
|
|
logs_bloom: payload.logs_bloom,
|
|
|
|
prev_randao: payload.prev_randao,
|
|
|
|
block_number: payload.block_number,
|
|
|
|
gas_limit: payload.gas_limit,
|
|
|
|
gas_used: payload.gas_used,
|
|
|
|
timestamp: payload.timestamp,
|
|
|
|
extra_data: payload.extra_data,
|
|
|
|
base_fee_per_gas: payload.base_fee_per_gas,
|
|
|
|
block_hash: payload.block_hash,
|
|
|
|
transactions_root: hash_tree_root(payload.transactions),
|
|
|
|
withdrawals_root: hash_tree_root(payload.withdrawals)),
|
|
|
|
execution_branch: blck.message.body.build_proof(
|
2023-11-09 12:54:44 +00:00
|
|
|
capella.EXECUTION_PAYLOAD_GINDEX).get)
|
2023-01-19 22:53:37 +00:00
|
|
|
|
2023-03-10 17:16:26 +00:00
|
|
|
func toDenebLightClientHeader(
|
2023-01-19 22:53:37 +00:00
|
|
|
blck: # `SomeSignedBeaconBlock` doesn't work here (Nim 1.6)
|
2023-02-20 08:45:49 +00:00
|
|
|
deneb.SignedBeaconBlock | deneb.TrustedSignedBeaconBlock
|
|
|
|
): deneb.LightClientHeader =
|
2023-01-19 22:53:37 +00:00
|
|
|
template payload: untyped = blck.message.body.execution_payload
|
2023-02-20 08:45:49 +00:00
|
|
|
deneb.LightClientHeader(
|
2023-01-19 22:53:37 +00:00
|
|
|
beacon: blck.message.toBeaconBlockHeader(),
|
2023-02-20 08:45:49 +00:00
|
|
|
execution: deneb.ExecutionPayloadHeader(
|
2023-01-19 22:53:37 +00:00
|
|
|
parent_hash: payload.parent_hash,
|
|
|
|
fee_recipient: payload.fee_recipient,
|
|
|
|
state_root: payload.state_root,
|
|
|
|
receipts_root: payload.receipts_root,
|
|
|
|
logs_bloom: payload.logs_bloom,
|
|
|
|
prev_randao: payload.prev_randao,
|
|
|
|
block_number: payload.block_number,
|
|
|
|
gas_limit: payload.gas_limit,
|
|
|
|
gas_used: payload.gas_used,
|
|
|
|
timestamp: payload.timestamp,
|
|
|
|
extra_data: payload.extra_data,
|
|
|
|
base_fee_per_gas: payload.base_fee_per_gas,
|
|
|
|
block_hash: payload.block_hash,
|
|
|
|
transactions_root: hash_tree_root(payload.transactions),
|
2023-05-05 23:15:47 +00:00
|
|
|
withdrawals_root: hash_tree_root(payload.withdrawals),
|
2024-01-16 22:54:20 +00:00
|
|
|
blob_gas_used: payload.blob_gas_used,
|
2023-08-02 22:07:57 +00:00
|
|
|
excess_blob_gas: payload.excess_blob_gas),
|
2023-01-19 22:53:37 +00:00
|
|
|
execution_branch: blck.message.body.build_proof(
|
2023-11-09 12:54:44 +00:00
|
|
|
capella.EXECUTION_PAYLOAD_GINDEX).get)
|
2023-01-19 22:53:37 +00:00
|
|
|
|
2024-06-21 13:02:01 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.3/specs/electra/light-client/full-node.md#modified-block_to_light_client_header
|
|
|
|
func toElectraLightClientHeader(
|
|
|
|
blck: # `SomeSignedBeaconBlock` doesn't work here (Nim 1.6)
|
|
|
|
phase0.SignedBeaconBlock | phase0.TrustedSignedBeaconBlock |
|
|
|
|
altair.SignedBeaconBlock | altair.TrustedSignedBeaconBlock |
|
|
|
|
bellatrix.SignedBeaconBlock | bellatrix.TrustedSignedBeaconBlock
|
|
|
|
): electra.LightClientHeader =
|
|
|
|
# Note that during fork transitions, `finalized_header` may still
|
|
|
|
# point to earlier forks. While Bellatrix blocks also contain an
|
|
|
|
# `ExecutionPayload` (minus `withdrawals_root`), it was not included
|
|
|
|
# in the corresponding light client data. To ensure compatibility
|
|
|
|
# with legacy data going through `upgrade_lc_header_to_capella`,
|
|
|
|
# leave out execution data.
|
|
|
|
electra.LightClientHeader(
|
|
|
|
beacon: blck.message.toBeaconBlockHeader())
|
|
|
|
|
|
|
|
func toElectraLightClientHeader(
|
|
|
|
blck: # `SomeSignedBeaconBlock` doesn't work here (Nim 1.6)
|
|
|
|
capella.SignedBeaconBlock | capella.TrustedSignedBeaconBlock
|
|
|
|
): electra.LightClientHeader =
|
|
|
|
template payload: untyped = blck.message.body.execution_payload
|
|
|
|
electra.LightClientHeader(
|
|
|
|
beacon: blck.message.toBeaconBlockHeader(),
|
|
|
|
execution: electra.ExecutionPayloadHeader(
|
|
|
|
parent_hash: payload.parent_hash,
|
|
|
|
fee_recipient: payload.fee_recipient,
|
|
|
|
state_root: payload.state_root,
|
|
|
|
receipts_root: payload.receipts_root,
|
|
|
|
logs_bloom: payload.logs_bloom,
|
|
|
|
prev_randao: payload.prev_randao,
|
|
|
|
block_number: payload.block_number,
|
|
|
|
gas_limit: payload.gas_limit,
|
|
|
|
gas_used: payload.gas_used,
|
|
|
|
timestamp: payload.timestamp,
|
|
|
|
extra_data: payload.extra_data,
|
|
|
|
base_fee_per_gas: payload.base_fee_per_gas,
|
|
|
|
block_hash: payload.block_hash,
|
|
|
|
transactions_root: hash_tree_root(payload.transactions),
|
|
|
|
withdrawals_root: hash_tree_root(payload.withdrawals)),
|
|
|
|
execution_branch: blck.message.body.build_proof(
|
|
|
|
capella.EXECUTION_PAYLOAD_GINDEX).get)
|
|
|
|
|
|
|
|
func toElectraLightClientHeader(
|
|
|
|
blck: # `SomeSignedBeaconBlock` doesn't work here (Nim 1.6)
|
|
|
|
deneb.SignedBeaconBlock | deneb.TrustedSignedBeaconBlock
|
|
|
|
): electra.LightClientHeader =
|
|
|
|
template payload: untyped = blck.message.body.execution_payload
|
|
|
|
electra.LightClientHeader(
|
|
|
|
beacon: blck.message.toBeaconBlockHeader(),
|
|
|
|
execution: electra.ExecutionPayloadHeader(
|
|
|
|
parent_hash: payload.parent_hash,
|
|
|
|
fee_recipient: payload.fee_recipient,
|
|
|
|
state_root: payload.state_root,
|
|
|
|
receipts_root: payload.receipts_root,
|
|
|
|
logs_bloom: payload.logs_bloom,
|
|
|
|
prev_randao: payload.prev_randao,
|
|
|
|
block_number: payload.block_number,
|
|
|
|
gas_limit: payload.gas_limit,
|
|
|
|
gas_used: payload.gas_used,
|
|
|
|
timestamp: payload.timestamp,
|
|
|
|
extra_data: payload.extra_data,
|
|
|
|
base_fee_per_gas: payload.base_fee_per_gas,
|
|
|
|
block_hash: payload.block_hash,
|
|
|
|
transactions_root: hash_tree_root(payload.transactions),
|
|
|
|
withdrawals_root: hash_tree_root(payload.withdrawals),
|
|
|
|
blob_gas_used: payload.blob_gas_used,
|
|
|
|
excess_blob_gas: payload.excess_blob_gas),
|
|
|
|
execution_branch: blck.message.body.build_proof(
|
|
|
|
capella.EXECUTION_PAYLOAD_GINDEX).get)
|
|
|
|
|
|
|
|
func toElectraLightClientHeader(
|
|
|
|
blck: # `SomeSignedBeaconBlock` doesn't work here (Nim 1.6)
|
|
|
|
electra.SignedBeaconBlock | electra.TrustedSignedBeaconBlock
|
|
|
|
): electra.LightClientHeader =
|
|
|
|
template payload: untyped = blck.message.body.execution_payload
|
|
|
|
electra.LightClientHeader(
|
|
|
|
beacon: blck.message.toBeaconBlockHeader(),
|
|
|
|
execution: electra.ExecutionPayloadHeader(
|
|
|
|
parent_hash: payload.parent_hash,
|
|
|
|
fee_recipient: payload.fee_recipient,
|
|
|
|
state_root: payload.state_root,
|
|
|
|
receipts_root: payload.receipts_root,
|
|
|
|
logs_bloom: payload.logs_bloom,
|
|
|
|
prev_randao: payload.prev_randao,
|
|
|
|
block_number: payload.block_number,
|
|
|
|
gas_limit: payload.gas_limit,
|
|
|
|
gas_used: payload.gas_used,
|
|
|
|
timestamp: payload.timestamp,
|
|
|
|
extra_data: payload.extra_data,
|
|
|
|
base_fee_per_gas: payload.base_fee_per_gas,
|
|
|
|
block_hash: payload.block_hash,
|
|
|
|
transactions_root: hash_tree_root(payload.transactions),
|
|
|
|
withdrawals_root: hash_tree_root(payload.withdrawals),
|
|
|
|
blob_gas_used: payload.blob_gas_used,
|
|
|
|
excess_blob_gas: payload.excess_blob_gas,
|
|
|
|
deposit_requests_root: hash_tree_root(payload.deposit_requests),
|
|
|
|
withdrawal_requests_root: hash_tree_root(payload.withdrawal_requests),
|
|
|
|
consolidation_requests_root:
|
|
|
|
hash_tree_root(payload.consolidation_requests)),
|
|
|
|
execution_branch: blck.message.body.build_proof(
|
|
|
|
capella.EXECUTION_PAYLOAD_GINDEX).get)
|
|
|
|
|
2023-01-13 15:46:35 +00:00
|
|
|
func toLightClientHeader*(
|
|
|
|
blck: # `SomeSignedBeaconBlock` doesn't work here (Nim 1.6)
|
|
|
|
phase0.SignedBeaconBlock | phase0.TrustedSignedBeaconBlock |
|
|
|
|
altair.SignedBeaconBlock | altair.TrustedSignedBeaconBlock |
|
|
|
|
bellatrix.SignedBeaconBlock | bellatrix.TrustedSignedBeaconBlock |
|
|
|
|
capella.SignedBeaconBlock | capella.TrustedSignedBeaconBlock |
|
2024-04-03 14:43:43 +00:00
|
|
|
deneb.SignedBeaconBlock | deneb.TrustedSignedBeaconBlock |
|
|
|
|
electra.SignedBeaconBlock | electra.TrustedSignedBeaconBlock,
|
2023-01-13 15:46:35 +00:00
|
|
|
kind: static LightClientDataFork): auto =
|
2024-06-21 13:02:01 +00:00
|
|
|
when kind == LightClientDataFork.Electra:
|
|
|
|
blck.toElectraLightClientHeader()
|
2024-04-03 14:43:43 +00:00
|
|
|
elif kind == LightClientDataFork.Deneb:
|
2023-03-10 17:16:26 +00:00
|
|
|
blck.toDenebLightClientHeader()
|
2023-01-19 22:53:37 +00:00
|
|
|
elif kind == LightClientDataFork.Capella:
|
2023-01-18 14:32:57 +00:00
|
|
|
blck.toCapellaLightClientHeader()
|
|
|
|
elif kind == LightClientDataFork.Altair:
|
2023-01-14 21:19:50 +00:00
|
|
|
blck.toAltairLightClientHeader()
|
|
|
|
else:
|
|
|
|
static: raiseAssert "Unreachable"
|
2023-04-13 15:26:17 +00:00
|
|
|
|
|
|
|
import chronicles
|
|
|
|
|
|
|
|
func shortLog*[
|
|
|
|
T:
|
|
|
|
ForkedLightClientHeader |
|
|
|
|
SomeForkedLightClientObject |
|
|
|
|
ForkedLightClientStore](
|
|
|
|
x: T): auto =
|
|
|
|
type ResultType = object
|
|
|
|
case kind: LightClientDataFork
|
|
|
|
of LightClientDataFork.None:
|
|
|
|
discard
|
|
|
|
of LightClientDataFork.Altair:
|
|
|
|
altairData: typeof(x.altairData.shortLog())
|
|
|
|
of LightClientDataFork.Capella:
|
|
|
|
capellaData: typeof(x.capellaData.shortLog())
|
|
|
|
of LightClientDataFork.Deneb:
|
|
|
|
denebData: typeof(x.denebData.shortLog())
|
2024-06-21 13:02:01 +00:00
|
|
|
of LightClientDataFork.Electra:
|
|
|
|
electraData: typeof(x.electraData.shortLog())
|
2023-04-13 15:26:17 +00:00
|
|
|
|
|
|
|
let xKind = x.kind # Nim 1.6.12: Using `kind: x.kind` inside case is broken
|
|
|
|
case xKind
|
2024-06-21 13:02:01 +00:00
|
|
|
of LightClientDataFork.Electra:
|
|
|
|
ResultType(kind: xKind, electraData: x.electraData.shortLog())
|
2023-04-13 15:26:17 +00:00
|
|
|
of LightClientDataFork.Deneb:
|
|
|
|
ResultType(kind: xKind, denebData: x.denebData.shortLog())
|
|
|
|
of LightClientDataFork.Capella:
|
|
|
|
ResultType(kind: xKind, capellaData: x.capellaData.shortLog())
|
|
|
|
of LightClientDataFork.Altair:
|
|
|
|
ResultType(kind: xKind, altairData: x.altairData.shortLog())
|
|
|
|
of LightClientDataFork.None:
|
|
|
|
ResultType(kind: xKind)
|
|
|
|
|
|
|
|
chronicles.formatIt ForkedLightClientHeader: it.shortLog
|
|
|
|
chronicles.formatIt SomeForkedLightClientObject: it.shortLog
|
|
|
|
chronicles.formatIt ForkedLightClientStore: it.shortLog
|