-
Notifications
You must be signed in to change notification settings - Fork 261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add option to collect light client data #3474
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
beacon_chain/consensus_object_pools/block_pools_types_light_client.nim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# 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. | ||
|
||
{.push raises: [Defect].} | ||
|
||
# This implements the pre-release proposal of the libp2p based light client sync | ||
# protocol. See https://github.com/ethereum/consensus-specs/pull/2802 | ||
|
||
import | ||
# Status libraries | ||
stew/bitops2, | ||
# Beacon chain internals | ||
../spec/datatypes/altair, | ||
./block_dag | ||
|
||
type | ||
OnOptimisticLightClientUpdateCallback* = | ||
proc(data: OptimisticLightClientUpdate) {.gcsafe, raises: [Defect].} | ||
|
||
ImportLightClientData* {.pure.} = enum | ||
## Controls which classes of light client data are imported. | ||
None = "none" | ||
## Import no light client data. | ||
OnlyNew = "only-new" | ||
## Import only new light client data. | ||
Full = "full" | ||
## Import light client data for entire weak subjectivity period. | ||
OnDemand = "on-demand" | ||
## No precompute of historic data. Is slow and may miss validator duties. | ||
|
||
CachedLightClientData* = object | ||
## Cached data from historical non-finalized states to improve speed when | ||
## creating future `LightClientUpdate` and `LightClientBootstrap` instances. | ||
current_sync_committee_branch*: | ||
array[log2trunc(altair.CURRENT_SYNC_COMMITTEE_INDEX), Eth2Digest] | ||
|
||
next_sync_committee_branch*: | ||
array[log2trunc(altair.NEXT_SYNC_COMMITTEE_INDEX), Eth2Digest] | ||
|
||
finalized_bid*: BlockId | ||
finality_branch*: | ||
array[log2trunc(altair.FINALIZED_ROOT_INDEX), Eth2Digest] | ||
|
||
CachedLightClientBootstrap* = object | ||
## Cached data from historical finalized epoch boundary blocks to improve | ||
## speed when creating future `LightClientBootstrap` instances. | ||
current_sync_committee_branch*: | ||
array[log2trunc(altair.CURRENT_SYNC_COMMITTEE_INDEX), Eth2Digest] | ||
|
||
LightClientCache* = object | ||
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. | ||
## Data is stored for the most recent 4 finalized checkpoints, as well as | ||
## for all non-finalized blocks. | ||
|
||
bootstrap*: Table[Slot, CachedLightClientBootstrap] | ||
## Cached data for creating future `LightClientBootstrap` instances. | ||
## Key is the block slot of which the post state was used to get the data. | ||
## Data is stored for finalized epoch boundary blocks. | ||
|
||
latestCheckpoints*: array[4, Checkpoint] | ||
## Keeps track of the latest four `finalized_checkpoint` references | ||
## leading to `finalizedHead`. Used to prune `data`. | ||
## Non-finalized states may only refer to these checkpoints. | ||
|
||
lastCheckpointIndex*: int | ||
## Last index that was modified in `latestCheckpoints`. | ||
|
||
bestUpdates*: Table[SyncCommitteePeriod, altair.LightClientUpdate] | ||
## Stores the `LightClientUpdate` with the most `sync_committee_bits` per | ||
## `SyncCommitteePeriod`. Updates with a finality proof have precedence. | ||
|
||
pendingBestUpdates*: | ||
Table[(SyncCommitteePeriod, Eth2Digest), altair.LightClientUpdate] | ||
## Same as `bestUpdates`, but for `SyncCommitteePeriod` with | ||
## `next_sync_committee` that are not finalized. Key is `(period, | ||
## hash_tree_root(current_sync_committee | next_sync_committee)`. | ||
|
||
latestUpdate*: altair.LightClientUpdate | ||
## Tracks the `LightClientUpdate` for the latest slot. This may be older | ||
## than head for empty slots or if not signed by sync committee. | ||
|
||
optimisticUpdate*: OptimisticLightClientUpdate | ||
## Tracks the `OptimisticLightClientUpdate` for the latest slot. This may | ||
## be older than head for empty slots or if not signed by sync committee. | ||
|
||
importTailSlot*: Slot | ||
## The earliest slot for which light client data is collected. | ||
## Only relevant for `ImportLightClientData.OnlyNew`. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
importTailSlot
forOnlyNew
import mode. Data is only collected from this slot onward.