avoid pruning LC data pre dag.tail.slot (#4702)

When using `--history=prune`, `dag.tail.slot` may advance beyond the
configured light client data retention period. Update the LC logic so
that the `dag.tail.slot` is no longer considered for LC pruning.
It is still considered to check whether new data can be produced.
This commit is contained in:
Etan Kissling 2023-03-08 19:59:00 +01:00 committed by GitHub
parent 90640cce05
commit e499c709f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 4 deletions

View File

@ -150,7 +150,7 @@ func targetLightClientTailSlot(dag: ChainDAGRef): Slot =
let
maxPeriods = dag.lcDataStore.maxPeriods
headPeriod = dag.head.slot.sync_committee_period
lowSlot = max(dag.tail.slot, dag.cfg.ALTAIR_FORK_EPOCH.start_slot)
lowSlot = dag.cfg.ALTAIR_FORK_EPOCH.start_slot
tail = max(headPeriod + 1, maxPeriods.SyncCommitteePeriod) - maxPeriods
max(tail.start_slot, lowSlot)
@ -182,7 +182,8 @@ proc initLightClientBootstrapForPeriod(
let
periodStartSlot = period.start_slot
periodEndSlot = periodStartSlot + SLOTS_PER_SYNC_COMMITTEE_PERIOD - 1
lowSlot = max(periodStartSlot, dag.targetLightClientTailSlot)
tailSlot = max(dag.targetLightClientTailSlot, dag.tail.slot)
lowSlot = max(periodStartSlot, tailSlot)
highSlot = min(periodEndSlot, dag.finalizedHead.blck.slot)
lowBoundarySlot = lowSlot.nextEpochBoundarySlot
highBoundarySlot = highSlot.nextEpochBoundarySlot
@ -286,7 +287,8 @@ proc initLightClientUpdateForPeriod(
let
periodStartSlot = period.start_slot
periodEndSlot = periodStartSlot + SLOTS_PER_SYNC_COMMITTEE_PERIOD - 1
lowSlot = max(periodStartSlot, dag.targetLightClientTailSlot)
tailSlot = max(dag.targetLightClientTailSlot, dag.tail.slot)
lowSlot = max(periodStartSlot, tailSlot)
highSlot = min(periodEndSlot, dag.finalizedHead.blck.slot)
fullPeriodCovered = (dag.finalizedHead.slot > periodEndSlot)
highBsi = dag.getExistingBlockIdAtSlot(highSlot).valueOr:
@ -677,7 +679,7 @@ proc initLightClientDataCache*(dag: ChainDAGRef) =
dag.lcDataStore.db.delNonFinalizedPeriodsFrom(dag.firstNonFinalizedPeriod)
# Initialize tail slot
let targetTailSlot = dag.targetLightClientTailSlot
let targetTailSlot = max(dag.targetLightClientTailSlot, dag.tail.slot)
dag.lcDataStore.cache.tailSlot = max(dag.head.slot, targetTailSlot)
# Import head state