Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Commit

Permalink
Revert "Small simplification of startHandlingForkChoice (erigontech#4636
Browse files Browse the repository at this point in the history
)" (erigontech#4649)

This reverts commit cc75387.
  • Loading branch information
yperbasis committed Jul 6, 2022
1 parent 423b4f6 commit 45ac977
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion eth/stagedsync/stage_headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,34 @@ func startHandlingForkChoice(
cfg.hd.BeaconRequestList.Remove(requestId)

headerNumber := header.Number.Uint64()
cfg.hd.UpdateTopSeenHeightPoS(headerNumber)
// If header is canonical, then no reorgs are required
canonicalHash, err := rawdb.ReadCanonicalHash(tx, headerNumber)
if err != nil {
log.Warn(fmt.Sprintf("[%s] Fork choice err (reading canonical hash of %d)", s.LogPrefix(), headerNumber), "err", err)
cfg.hd.BeaconRequestList.Remove(requestId)
return nil, err
}

if headerHash == canonicalHash {
log.Info(fmt.Sprintf("[%s] Fork choice on previously known block", s.LogPrefix()))
cfg.hd.BeaconRequestList.Remove(requestId)
rawdb.WriteForkchoiceHead(tx, forkChoice.HeadBlockHash)
canonical, err := safeAndFinalizedBlocksAreCanonical(forkChoice, s, tx, cfg)
if err != nil {
log.Warn(fmt.Sprintf("[%s] Fork choice err", s.LogPrefix()), "err", err)
return nil, err
}
if canonical {
return &privateapi.PayloadStatus{
Status: remote.EngineStatus_VALID,
LatestValidHash: headerHash,
}, nil
} else {
return &privateapi.PayloadStatus{
CriticalError: &privateapi.InvalidForkchoiceStateErr,
}, nil
}
}

if cfg.memoryOverlay && headerHash == cfg.hd.GetNextForkHash() {
log.Info("Flushing in-memory state")
Expand All @@ -345,6 +372,7 @@ func startHandlingForkChoice(
}
}

cfg.hd.UpdateTopSeenHeightPoS(headerNumber)
forkingPoint := uint64(0)
if headerNumber > 0 {
parent, err := headerReader.Header(ctx, tx, header.ParentHash, headerNumber-1)
Expand Down

0 comments on commit 45ac977

Please sign in to comment.