Skip to content

Commit 2df8a92

Browse files
committed
fix: disable validating historical blocks
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent 0a2b68c commit 2df8a92

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

database/plugin/metadata/sqlite/transaction.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,10 @@ func (d *MetadataStoreSqlite) SetTransaction(
207207
if tmpTx.ID == 0 {
208208
existingTx, err := d.GetTransactionByHash(txHash, txn)
209209
if err != nil {
210-
return fmt.Errorf("failed to fetch transaction ID after upsert: %w", err)
210+
return fmt.Errorf(
211+
"failed to fetch transaction ID after upsert: %w",
212+
err,
213+
)
211214
}
212215
if existingTx == nil {
213216
return fmt.Errorf("transaction not found after upsert: %x", txHash)

ledger/state.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)