fix light client data collection for checkpoint sync (#3498)
When doing checkpoint sync, collecting light client data of known blocks and states incorrectly assumes that `finalized_checkpoint` information is also known. Hardens collection to only collect finalized checkpoint data after `dag.computeEarliestLightClientSlot`.
This commit is contained in:
parent
d0223d1f28
commit
18bd6df1b4
|
@ -249,11 +249,11 @@ OK: 3/3 Fail: 0/3 Skip: 0/3
|
|||
OK: 9/9 Fail: 0/9 Skip: 0/9
|
||||
## Light client [Preset: mainnet]
|
||||
```diff
|
||||
Init from checkpoint Skip
|
||||
+ Init from checkpoint OK
|
||||
+ Light client sync OK
|
||||
+ Pre-Altair OK
|
||||
```
|
||||
OK: 2/3 Fail: 0/3 Skip: 1/3
|
||||
OK: 3/3 Fail: 0/3 Skip: 0/3
|
||||
## Light client processor [Preset: mainnet]
|
||||
```diff
|
||||
+ Duplicate bootstrap [Preset: mainnet] OK
|
||||
|
@ -529,4 +529,4 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
|
|||
OK: 1/1 Fail: 0/1 Skip: 0/1
|
||||
|
||||
---TOTAL---
|
||||
OK: 293/299 Fail: 0/299 Skip: 6/299
|
||||
OK: 294/299 Fail: 0/299 Skip: 5/299
|
||||
|
|
|
@ -146,10 +146,14 @@ proc cacheLightClientData*(
|
|||
|
||||
template finalized_checkpoint(): auto = state.data.finalized_checkpoint
|
||||
let
|
||||
earliestSlot = dag.computeEarliestLightClientSlot
|
||||
bid =
|
||||
BlockId(root: blck.root, slot: blck.message.slot)
|
||||
finalized_bid =
|
||||
dag.getBlockIdAtSlot(finalized_checkpoint.epoch.start_slot).expect("TODO").bid
|
||||
if finalized_checkpoint.epoch.start_slot >= earliestSlot:
|
||||
dag.getBlockIdAtSlot(finalized_checkpoint.epoch.start_slot).expect("TODO").bid
|
||||
else:
|
||||
default(BlockId)
|
||||
if dag.lightClientCache.data.hasKeyOrPut(
|
||||
bid,
|
||||
CachedLightClientData(
|
||||
|
@ -788,7 +792,8 @@ proc initLightClientCache*(dag: ChainDAGRef) =
|
|||
# Note that light client finality proofs refer to checkpoint blocks
|
||||
# at their original slot, without advancing to an epoch boundary.
|
||||
# This is because light clients are unable to advance slots.
|
||||
if checkpoint.root != dag.finalizedHead.blck.root:
|
||||
if checkpoint.root != dag.finalizedHead.blck.root and
|
||||
checkpoint.epoch.start_slot >= earliestSlot:
|
||||
let cpRef =
|
||||
dag.getBlockIdAtSlot(checkpoint.epoch.start_slot).expect("TODO").bid
|
||||
if cpRef.slot >= earliestSlot:
|
||||
|
|
|
@ -165,12 +165,6 @@ suite "Light client" & preset():
|
|||
|
||||
test "Init from checkpoint":
|
||||
# Fetch genesis state
|
||||
if true:
|
||||
# TODO The TODO code in `blockchain_dag_light_client` needs attention
|
||||
# before this test is enabled
|
||||
skip
|
||||
return
|
||||
|
||||
let genesisState = assignClone dag.headState
|
||||
|
||||
# Advance to target slot for checkpoint
|
||||
|
|
Loading…
Reference in New Issue