Skip to content

Commit

Permalink
persist LC data across restarts (#3823)
Browse files Browse the repository at this point in the history
* persist LC data across restarts

With the Altair spec `LightClientUpdate` structure taking its final form
it is finally possible to persist LC data across restarts without having
to worry about data migration due to spec changes. A separate `lcdataV1`
database is created in the `caches` subdirectory to hold known LC data.
A full database with default settings (129 periods) uses <15 MB disk.

* extend LC data DB rationale

* wording

* add `isSupportedBySQLite` helper and explicit return

* remove redundant `return`
  • Loading branch information
etan-status authored Jun 30, 2022
1 parent 24c435a commit 499abd9
Show file tree
Hide file tree
Showing 6 changed files with 482 additions and 81 deletions.
3 changes: 3 additions & 0 deletions beacon_chain/conf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,9 @@ func outWalletFile*(config: BeaconNodeConf): Option[OutFile] =
func databaseDir*(config: AnyConf): string =
config.dataDir / "db"

func cachesDir*(config: AnyConf): string =
config.databaseDir / "caches"

func runAsService*(config: BeaconNodeConf): bool =
config.cmd == noCommand and config.runAsServiceFlag

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import
stew/bitops2,
# Beacon chain internals
../spec/datatypes/altair,
../light_client_data_db,
./block_dag

type
Expand Down Expand Up @@ -49,15 +50,6 @@ type
## Key is the block ID of which the post state was used to get the data.
## Data stored for the finalized head block and all non-finalized blocks.

currentBranches*: Table[Slot, altair.CurrentSyncCommitteeBranch]
## Cached data for creating future `LightClientBootstrap` instances.
## Key is the block slot of which the post state was used to get the data.
## Data stored for all finalized epoch boundary blocks.

bestUpdates*: Table[SyncCommitteePeriod, altair.LightClientUpdate]
## Stores the `LightClientUpdate` with the most `sync_committee_bits` per
## `SyncCommitteePeriod`. Sync committee finality gives precedence.

pendingBest*:
Table[(SyncCommitteePeriod, Eth2Digest), altair.LightClientUpdate]
## Same as `bestUpdates`, but for `SyncCommitteePeriod` with not yet
Expand All @@ -72,6 +64,8 @@ type
## The earliest slot for which light client data is imported.

LightClientDataConfig* = object
dbDir*: Option[string]
## Directory to store light client data DB in
serve*: bool
## Whether to make local light client data available or not
importMode*: LightClientDataImportMode
Expand All @@ -89,6 +83,8 @@ type

cache*: LightClientDataCache
## Cached data to accelerate creating light client data
db*: LightClientDataDB
## Persistent light client data to avoid expensive recomputations

# -----------------------------------
# Config
Expand Down
1 change: 1 addition & 0 deletions beacon_chain/consensus_object_pools/blockchain_dag.nim
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ proc updateBeaconMetrics(
import blockchain_dag_light_client

export
blockchain_dag_light_client.closeLightClientDataStore,
blockchain_dag_light_client.getLightClientBootstrap,
blockchain_dag_light_client.getLightClientUpdateForPeriod,
blockchain_dag_light_client.getLightClientFinalityUpdate,
Expand Down
Loading

0 comments on commit 499abd9

Please sign in to comment.