Skip to content

Commit

Permalink
fix panic issue in initializeStateAntiquaryIfNeeded (#11608) (#11624)
Browse files Browse the repository at this point in the history
related to #11482
  • Loading branch information
domiwei authored Aug 15, 2024
1 parent d24e5d4 commit 617308b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 9 additions & 3 deletions cl/antiquary/state_antiquary.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,9 @@ func (s *Antiquary) initializeStateAntiquaryIfNeeded(ctx context.Context, tx kv.
return err
}
// We want to backoff by some slots until we get a correct state from DB.
// we start from 1 * clparams.SlotsPerDump.
backoffStep := uint64(10)
// we start from 10 * clparams.SlotsPerDump.
backoffStrides := uint64(10)
backoffStep := backoffStrides

historicalReader := historical_states_reader.NewHistoricalStatesReader(s.cfg, s.snReader, s.validatorsTable, s.genesisState)

Expand All @@ -447,6 +448,11 @@ func (s *Antiquary) initializeStateAntiquaryIfNeeded(ctx context.Context, tx kv.
if err != nil {
return fmt.Errorf("failed to read historical state at slot %d: %w", attempt, err)
}
if s.currentState == nil {
log.Warn("historical state not found, backoff more and try again", "slot", attempt)
backoffStep += backoffStrides
continue
}

computedBlockRoot, err := s.currentState.BlockRoot()
if err != nil {
Expand All @@ -459,7 +465,7 @@ func (s *Antiquary) initializeStateAntiquaryIfNeeded(ctx context.Context, tx kv.
if computedBlockRoot != expectedBlockRoot {
log.Debug("Block root mismatch, trying again", "slot", attempt, "expected", expectedBlockRoot)
// backoff more
backoffStep += 10
backoffStep += backoffStrides
continue
}
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
"github.com/ledgerwatch/erigon/cl/phase1/core/state/lru"
"github.com/ledgerwatch/erigon/turbo/snapshotsync/freezeblocks"
"github.com/ledgerwatch/log/v3"

libcommon "github.com/ledgerwatch/erigon-lib/common"
)
Expand Down Expand Up @@ -62,6 +63,7 @@ func (r *HistoricalStatesReader) ReadHistoricalState(ctx context.Context, tx kv.

// If this happens, we need to update our static tables
if slot > latestProcessedState || slot > r.validatorTable.Slot() {
log.Warn("slot is ahead of the latest processed state", "slot", slot, "latestProcessedState", latestProcessedState, "validatorTableSlot", r.validatorTable.Slot())
return nil, nil
}

Expand All @@ -74,6 +76,7 @@ func (r *HistoricalStatesReader) ReadHistoricalState(ctx context.Context, tx kv.
return nil, err
}
if block == nil {
log.Warn("block not found", "slot", slot)
return nil, nil
}
blockHeader := block.SignedBeaconBlockHeader().Header
Expand All @@ -84,6 +87,7 @@ func (r *HistoricalStatesReader) ReadHistoricalState(ctx context.Context, tx kv.
return nil, err
}
if slotData == nil {
log.Warn("slot data not found", "slot", slot)
return nil, nil
}
roundedSlot := r.cfg.RoundSlotToEpoch(slot)
Expand All @@ -93,6 +97,7 @@ func (r *HistoricalStatesReader) ReadHistoricalState(ctx context.Context, tx kv.
return nil, fmt.Errorf("failed to read epoch data: %w", err)
}
if epochData == nil {
log.Warn("epoch data not found", "slot", slot, "roundedSlot", roundedSlot)
return nil, nil
}

Expand Down

0 comments on commit 617308b

Please sign in to comment.