2022-03-11 20:28:10 +00:00
|
|
|
# beacon_chain
|
|
|
|
# Copyright (c) 2022 Status Research & Development GmbH
|
|
|
|
# Licensed and distributed under either of
|
|
|
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
|
|
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
2022-07-29 10:53:42 +00:00
|
|
|
when (NimMajor, NimMinor) < (1, 4):
|
|
|
|
{.push raises: [Defect].}
|
|
|
|
else:
|
|
|
|
{.push raises: [].}
|
2022-03-11 20:28:10 +00:00
|
|
|
|
|
|
|
import
|
|
|
|
# Beacon chain internals
|
|
|
|
../spec/datatypes/altair,
|
2022-07-04 20:46:32 +00:00
|
|
|
../beacon_chain_db_light_client,
|
2022-03-11 20:28:10 +00:00
|
|
|
./block_dag
|
|
|
|
|
|
|
|
type
|
2022-06-14 09:03:39 +00:00
|
|
|
LightClientDataImportMode* {.pure.} = enum
|
2022-03-11 20:28:10 +00:00
|
|
|
## Controls which classes of light client data are imported.
|
|
|
|
None = "none"
|
2022-08-02 12:23:03 +00:00
|
|
|
## Do not import new light client data.
|
2022-03-11 20:28:10 +00:00
|
|
|
OnlyNew = "only-new"
|
2022-08-02 12:23:03 +00:00
|
|
|
## Incrementally import new light client data.
|
2022-03-11 20:28:10 +00:00
|
|
|
Full = "full"
|
2022-08-02 12:23:03 +00:00
|
|
|
## Import historic light client data (slow startup).
|
2022-03-11 20:28:10 +00:00
|
|
|
OnDemand = "on-demand"
|
2022-08-02 12:23:03 +00:00
|
|
|
## Like `full`, but import on demand instead of on start.
|
2022-03-11 20:28:10 +00:00
|
|
|
|
2022-06-24 14:57:50 +00:00
|
|
|
OnLightClientFinalityUpdateCallback* =
|
|
|
|
proc(data: altair.LightClientFinalityUpdate) {.gcsafe, raises: [Defect].}
|
|
|
|
OnLightClientOptimisticUpdateCallback* =
|
|
|
|
proc(data: altair.LightClientOptimisticUpdate) {.gcsafe, raises: [Defect].}
|
|
|
|
|
2022-03-11 20:28:10 +00:00
|
|
|
CachedLightClientData* = object
|
|
|
|
## Cached data from historical non-finalized states to improve speed when
|
|
|
|
## creating future `LightClientUpdate` and `LightClientBootstrap` instances.
|
2022-06-28 05:52:23 +00:00
|
|
|
current_sync_committee_branch*: altair.CurrentSyncCommitteeBranch
|
|
|
|
next_sync_committee_branch*: altair.NextSyncCommitteeBranch
|
2022-03-11 20:28:10 +00:00
|
|
|
|
2022-05-23 12:02:54 +00:00
|
|
|
finalized_slot*: Slot
|
2022-06-28 05:52:23 +00:00
|
|
|
finality_branch*: altair.FinalityBranch
|
2022-03-11 20:28:10 +00:00
|
|
|
|
2022-06-24 14:57:50 +00:00
|
|
|
LightClientDataCache* = object
|
2022-03-11 20:28:10 +00:00
|
|
|
data*: Table[BlockId, CachedLightClientData]
|
|
|
|
## Cached data for creating future `LightClientUpdate` instances.
|
|
|
|
## Key is the block ID of which the post state was used to get the data.
|
2022-05-23 12:02:54 +00:00
|
|
|
## Data stored for the finalized head block and all non-finalized blocks.
|
2022-03-11 20:28:10 +00:00
|
|
|
|
2022-05-23 12:02:54 +00:00
|
|
|
pendingBest*:
|
2022-03-11 20:28:10 +00:00
|
|
|
Table[(SyncCommitteePeriod, Eth2Digest), altair.LightClientUpdate]
|
2022-06-28 05:52:23 +00:00
|
|
|
## Same as `bestUpdates`, but for `SyncCommitteePeriod` with not yet
|
|
|
|
## finalized `next_sync_committee`. Key is `(attested_period,
|
2022-03-11 20:28:10 +00:00
|
|
|
## hash_tree_root(current_sync_committee | next_sync_committee)`.
|
|
|
|
|
2022-05-23 12:02:54 +00:00
|
|
|
latest*: altair.LightClientFinalityUpdate
|
|
|
|
## Tracks light client data for the latest slot that was signed by
|
|
|
|
## at least `MIN_SYNC_COMMITTEE_PARTICIPANTS`. May be older than head.
|
2022-03-11 20:28:10 +00:00
|
|
|
|
2022-06-27 11:24:38 +00:00
|
|
|
tailSlot*: Slot
|
2022-05-23 12:02:54 +00:00
|
|
|
## The earliest slot for which light client data is imported.
|
2022-06-24 14:57:50 +00:00
|
|
|
|
2022-06-28 20:52:29 +00:00
|
|
|
LightClientDataConfig* = object
|
|
|
|
serve*: bool
|
|
|
|
## Whether to make local light client data available or not
|
|
|
|
importMode*: LightClientDataImportMode
|
|
|
|
## Which classes of light client data to import
|
|
|
|
maxPeriods*: Option[uint64]
|
|
|
|
## Maximum number of sync committee periods to retain light client data
|
|
|
|
onLightClientFinalityUpdate*: OnLightClientFinalityUpdateCallback
|
|
|
|
## On new `LightClientFinalityUpdate` callback
|
|
|
|
onLightClientOptimisticUpdate*: OnLightClientOptimisticUpdateCallback
|
|
|
|
## On new `LightClientOptimisticUpdate` callback
|
|
|
|
|
2022-06-24 14:57:50 +00:00
|
|
|
LightClientDataStore* = object
|
|
|
|
# -----------------------------------
|
|
|
|
# Light client data
|
|
|
|
|
|
|
|
cache*: LightClientDataCache
|
2022-06-28 05:52:23 +00:00
|
|
|
## Cached data to accelerate creating light client data
|
2022-06-30 13:04:39 +00:00
|
|
|
db*: LightClientDataDB
|
|
|
|
## Persistent light client data to avoid expensive recomputations
|
2022-06-24 14:57:50 +00:00
|
|
|
|
|
|
|
# -----------------------------------
|
|
|
|
# Config
|
|
|
|
|
|
|
|
serve*: bool
|
|
|
|
## Whether to make local light client data available or not
|
|
|
|
importMode*: LightClientDataImportMode
|
|
|
|
## Which classes of light client data to import
|
2022-06-27 11:24:38 +00:00
|
|
|
maxPeriods*: uint64
|
|
|
|
## Maximum number of sync committee periods to retain light client data
|
2022-06-24 14:57:50 +00:00
|
|
|
|
|
|
|
# -----------------------------------
|
|
|
|
# Callbacks
|
|
|
|
|
|
|
|
onLightClientFinalityUpdate*: OnLightClientFinalityUpdateCallback
|
|
|
|
## On new `LightClientFinalityUpdate` callback
|
|
|
|
onLightClientOptimisticUpdate*: OnLightClientOptimisticUpdateCallback
|
|
|
|
## On new `LightClientOptimisticUpdate` callback
|