Skip to content

Commit c808f17

Browse files
authored
update to latest light client libp2p protocol (#3623)
Incorporates the latest changes to the light client sync protocol based on Devconnect AMS feedback. Note that this breaks compatibility with the previous prototype, due to changes to data structures and endpoints. See ethereum/consensus-specs#2802
1 parent 82677c6 commit c808f17

34 files changed

+1611
-1420
lines changed

AllTests-mainnet.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,11 @@ OK: 3/3 Fail: 0/3 Skip: 0/3
265265
## Light client processor [Preset: mainnet]
266266
```diff
267267
+ Duplicate bootstrap [Preset: mainnet] OK
268-
+ Forced update [Preset: mainnet] OK
269268
+ Invalid bootstrap [Preset: mainnet] OK
269+
+ Missing bootstrap (finality update) [Preset: mainnet] OK
270270
+ Missing bootstrap (optimistic update) [Preset: mainnet] OK
271271
+ Missing bootstrap (update) [Preset: mainnet] OK
272-
+ Standard sync [Preset: mainnet] OK
272+
+ Sync [Preset: mainnet] OK
273273
```
274274
OK: 6/6 Fail: 0/6 Skip: 0/6
275275
## ListKeys requests [Preset: mainnet]

ConsensusSpecPreset-mainnet.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,11 @@ OK: 35/35 Fail: 0/35 Skip: 0/35
804804
All tests Skip
805805
```
806806
OK: 0/1 Fail: 0/1 Skip: 1/1
807+
## EF - Altair - Sync protocol - Update ranking [Preset: mainnet]
808+
```diff
809+
All tests Skip
810+
```
811+
OK: 0/1 Fail: 0/1 Skip: 1/1
807812
## EF - Altair - Unittests - Sync protocol [Preset: mainnet]
808813
```diff
809814
+ process_light_client_update_finality_updated OK
@@ -1215,4 +1220,4 @@ OK: 44/44 Fail: 0/44 Skip: 0/44
12151220
OK: 27/27 Fail: 0/27 Skip: 0/27
12161221

12171222
---TOTAL---
1218-
OK: 1035/1037 Fail: 0/1037 Skip: 2/1037
1223+
OK: 1035/1038 Fail: 0/1038 Skip: 3/1038

ConsensusSpecPreset-minimal.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,11 @@ OK: 35/35 Fail: 0/35 Skip: 0/35
845845
All tests Skip
846846
```
847847
OK: 0/1 Fail: 0/1 Skip: 1/1
848+
## EF - Altair - Sync protocol - Update ranking [Preset: minimal]
849+
```diff
850+
All tests Skip
851+
```
852+
OK: 0/1 Fail: 0/1 Skip: 1/1
848853
## EF - Altair - Unittests - Sync protocol [Preset: minimal]
849854
```diff
850855
+ process_light_client_update_finality_updated OK
@@ -1292,4 +1297,4 @@ OK: 48/48 Fail: 0/48 Skip: 0/48
12921297
OK: 30/30 Fail: 0/30 Skip: 0/30
12931298

12941299
---TOTAL---
1295-
OK: 1085/1106 Fail: 0/1106 Skip: 21/1106
1300+
OK: 1085/1107 Fail: 0/1107 Skip: 22/1107

beacon_chain/beacon_node.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type
5050
quarantine*: ref Quarantine
5151
attestationPool*: ref AttestationPool
5252
syncCommitteeMsgPool*: ref SyncCommitteeMsgPool
53+
lightClientPool*: ref LightClientPool
5354
exitPool*: ref ExitPool
5455
eth1Monitor*: Eth1Monitor
5556
rpcServer*: RpcServer

beacon_chain/consensus_object_pools/block_pools_types.nim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,10 @@ type
216216
## On beacon chain reorganization
217217
onFinHappened*: OnFinalizedCallback
218218
## On finalization callback
219-
onOptimisticLightClientUpdate*: OnOptimisticLightClientUpdateCallback
220-
## On `OptimisticLightClientUpdate` updated callback
219+
onLightClientFinalityUpdate*: OnLightClientFinalityUpdateCallback
220+
## On new `LightClientFinalityUpdate` callback
221+
onLightClientOptimisticUpdate*: OnLightClientOptimisticUpdateCallback
222+
## On new `LightClientOptimisticUpdate` callback
221223

222224
headSyncCommittees*: SyncCommitteeCache
223225
## A cache of the sync committees, as they appear in the head state -

beacon_chain/consensus_object_pools/block_pools_types_light_client.nim

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ import
1818
./block_dag
1919

2020
type
21-
OnOptimisticLightClientUpdateCallback* =
22-
proc(data: OptimisticLightClientUpdate) {.gcsafe, raises: [Defect].}
21+
OnLightClientFinalityUpdateCallback* =
22+
proc(data: altair.LightClientFinalityUpdate) {.gcsafe, raises: [Defect].}
23+
OnLightClientOptimisticUpdateCallback* =
24+
proc(data: altair.LightClientOptimisticUpdate) {.gcsafe, raises: [Defect].}
2325

2426
ImportLightClientData* {.pure.} = enum
2527
## Controls which classes of light client data are imported.
@@ -30,18 +32,17 @@ type
3032
Full = "full"
3133
## Import light client data for entire weak subjectivity period.
3234
OnDemand = "on-demand"
33-
## No precompute of historic data. Is slow and may miss validator duties.
35+
## Don't precompute historic data. Slow, may miss validator duties.
3436

3537
CachedLightClientData* = object
3638
## Cached data from historical non-finalized states to improve speed when
3739
## creating future `LightClientUpdate` and `LightClientBootstrap` instances.
3840
current_sync_committee_branch*:
3941
array[log2trunc(altair.CURRENT_SYNC_COMMITTEE_INDEX), Eth2Digest]
40-
4142
next_sync_committee_branch*:
4243
array[log2trunc(altair.NEXT_SYNC_COMMITTEE_INDEX), Eth2Digest]
4344

44-
finalized_bid*: BlockId
45+
finalized_slot*: Slot
4546
finality_branch*:
4647
array[log2trunc(altair.FINALIZED_ROOT_INDEX), Eth2Digest]
4748

@@ -55,40 +56,26 @@ type
5556
data*: Table[BlockId, CachedLightClientData]
5657
## Cached data for creating future `LightClientUpdate` instances.
5758
## Key is the block ID of which the post state was used to get the data.
58-
## Data is stored for the most recent 4 finalized checkpoints, as well as
59-
## for all non-finalized blocks.
59+
## Data stored for the finalized head block and all non-finalized blocks.
6060

6161
bootstrap*: Table[Slot, CachedLightClientBootstrap]
6262
## Cached data for creating future `LightClientBootstrap` instances.
6363
## Key is the block slot of which the post state was used to get the data.
64-
## Data is stored for finalized epoch boundary blocks.
65-
66-
latestCheckpoints*: array[4, Checkpoint]
67-
## Keeps track of the latest four `finalized_checkpoint` references
68-
## leading to `finalizedHead`. Used to prune `data`.
69-
## Non-finalized states may only refer to these checkpoints.
64+
## Data stored for all finalized epoch boundary blocks.
7065

71-
lastCheckpointIndex*: int
72-
## Last index that was modified in `latestCheckpoints`.
73-
74-
bestUpdates*: Table[SyncCommitteePeriod, altair.LightClientUpdate]
66+
best*: Table[SyncCommitteePeriod, altair.LightClientUpdate]
7567
## Stores the `LightClientUpdate` with the most `sync_committee_bits` per
76-
## `SyncCommitteePeriod`. Updates with a finality proof have precedence.
68+
## `SyncCommitteePeriod`. Sync committee finality gives precedence.
7769

78-
pendingBestUpdates*:
70+
pendingBest*:
7971
Table[(SyncCommitteePeriod, Eth2Digest), altair.LightClientUpdate]
80-
## Same as `bestUpdates`, but for `SyncCommitteePeriod` with
81-
## `next_sync_committee` that are not finalized. Key is `(period,
72+
## Same as `best`, but for `SyncCommitteePeriod` with not yet finalized
73+
## `next_sync_committee`. Key is `(attested_period,
8274
## hash_tree_root(current_sync_committee | next_sync_committee)`.
8375

84-
latestUpdate*: altair.LightClientUpdate
85-
## Tracks the `LightClientUpdate` for the latest slot. This may be older
86-
## than head for empty slots or if not signed by sync committee.
87-
88-
optimisticUpdate*: OptimisticLightClientUpdate
89-
## Tracks the `OptimisticLightClientUpdate` for the latest slot. This may
90-
## be older than head for empty slots or if not signed by sync committee.
76+
latest*: altair.LightClientFinalityUpdate
77+
## Tracks light client data for the latest slot that was signed by
78+
## at least `MIN_SYNC_COMMITTEE_PARTICIPANTS`. May be older than head.
9179

9280
importTailSlot*: Slot
93-
## The earliest slot for which light client data is collected.
94-
## Only relevant for `ImportLightClientData.OnlyNew`.
81+
## The earliest slot for which light client data is imported.

beacon_chain/consensus_object_pools/blockchain_dag.nim

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -556,10 +556,10 @@ proc updateBeaconMetrics(
556556
import blockchain_dag_light_client
557557

558558
export
559-
blockchain_dag_light_client.getBestLightClientUpdateForPeriod,
560-
blockchain_dag_light_client.getLatestLightClientUpdate,
561-
blockchain_dag_light_client.getOptimisticLightClientUpdate,
562-
blockchain_dag_light_client.getLightClientBootstrap
559+
blockchain_dag_light_client.getLightClientBootstrap,
560+
blockchain_dag_light_client.getLightClientUpdateForPeriod,
561+
blockchain_dag_light_client.getLightClientFinalityUpdate,
562+
blockchain_dag_light_client.getLightClientOptimisticUpdate
563563

564564
proc getViableHead(cfg: RuntimeConfig, db: BeaconChainDB): Opt[BlockId] =
565565
# When the database has been written with a pre-fork version of the
@@ -659,9 +659,9 @@ proc init*(T: type ChainDAGRef, cfg: RuntimeConfig, db: BeaconChainDB,
659659
validatorMonitor: ref ValidatorMonitor, updateFlags: UpdateFlags,
660660
eraPath = ".",
661661
onBlockCb: OnBlockCallback = nil, onHeadCb: OnHeadCallback = nil,
662-
onReorgCb: OnReorgCallback = nil,
663-
onFinCb: OnFinalizedCallback = nil,
664-
onOptimisticLCUpdateCb: OnOptimisticLightClientUpdateCallback = nil,
662+
onReorgCb: OnReorgCallback = nil, onFinCb: OnFinalizedCallback = nil,
663+
onLCFinalityUpdateCb: OnLightClientFinalityUpdateCallback = nil,
664+
onLCOptimisticUpdateCb: OnLightClientOptimisticUpdateCallback = nil,
665665
serveLightClientData = false,
666666
importLightClientData = ImportLightClientData.None): ChainDAGRef =
667667
# TODO move fork version sanity checking elsewhere?
@@ -712,7 +712,8 @@ proc init*(T: type ChainDAGRef, cfg: RuntimeConfig, db: BeaconChainDB,
712712
onHeadChanged: onHeadCb,
713713
onReorgHappened: onReorgCb,
714714
onFinHappened: onFinCb,
715-
onOptimisticLightClientUpdate: onOptimisticLCUpdateCb
715+
onLightClientFinalityUpdate: onLCFinalityUpdateCb,
716+
onLightClientOptimisticUpdate: onLCOptimisticUpdateCb
716717
)
717718
loadTick = Moment.now()
718719

@@ -1636,6 +1637,7 @@ proc updateHead*(
16361637
justified = shortLog(getStateField(
16371638
dag.headState, current_justified_checkpoint)),
16381639
finalized = shortLog(getStateField(dag.headState, finalized_checkpoint))
1640+
let oldFinalizedHead = dag.finalizedHead
16391641

16401642
block:
16411643
# Update `dag.finalizedBlocks` with all newly finalized blocks (those
@@ -1663,7 +1665,7 @@ proc updateHead*(
16631665
dag.pruneBlocksDAG()
16641666

16651667
# Update light client data
1666-
dag.processFinalizationForLightClient()
1668+
dag.processFinalizationForLightClient(oldFinalizedHead)
16671669

16681670
# Send notification about new finalization point via callback.
16691671
if not(isNil(dag.onFinHappened)):

0 commit comments

Comments
 (0)