Skip to content

Commit

Permalink
avoid pruning LC data pre dag.tail.slot (#4702)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
etan-status authored Mar 8, 2023
1 parent 90640cc commit e499c70
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e499c70

Please sign in to comment.