@@ -611,7 +611,6 @@ func (ls *LedgerState) ledgerProcessBlocks() {
611611 var nextBatch , cachedNextBatch []ledger.Block
612612 var delta * LedgerDelta
613613 var deltaBatch LedgerDeltaBatch
614- shouldValidate := ls .config .ValidateHistorical
615614 for {
616615 if needsEpochRollover {
617616 ls .Lock ()
@@ -691,29 +690,31 @@ func (ls *LedgerState) ledgerProcessBlocks() {
691690 nextBatch = nil
692691 break
693692 }
694- // Enable validation using the k-slot window from ShelleyGenesis.
695- // Only recalculate if validation is not already enabled
696- if ! shouldValidate && i == 0 {
697- var cutoffSlot uint64
693+ // Determine if this block should be validated
694+ // Skip validation of historical blocks when ValidateHistorical=false, as they
695+ // were already validated by the network. However, validate blocks within the
696+ // k-slot stability window to ensure live blocks near the tip are validated.
697+ var shouldValidateBlock bool
698+ if ls .config .ValidateHistorical {
699+ shouldValidateBlock = true
700+ } else {
698701 stabilityWindow := ls .calculateStabilityWindow ()
699702 currentTipSlot := ls .currentTip .Point .Slot
700703 blockSlot := next .SlotNumber ()
704+ var cutoffSlot uint64
701705 if currentTipSlot >= stabilityWindow {
702706 cutoffSlot = currentTipSlot - stabilityWindow
703707 } else {
704708 cutoffSlot = 0
705709 }
706-
707- // Validate blocks within k-slot window, or historical blocks if ValidateHistorical enabled
708- shouldValidate = blockSlot >= cutoffSlot ||
709- ls .config .ValidateHistorical
710+ shouldValidateBlock = blockSlot >= cutoffSlot
710711 }
711712 // Process block
712713 delta , err = ls .ledgerProcessBlock (
713714 txn ,
714715 tmpPoint ,
715716 next ,
716- shouldValidate ,
717+ shouldValidateBlock ,
717718 )
718719 if err != nil {
719720 return err
0 commit comments