From 2b9c3500607f1bface883e8d5d87f634d826222c Mon Sep 17 00:00:00 2001 From: jsvisa Date: Thu, 6 Nov 2025 10:24:11 +0800 Subject: [PATCH] eth/syncer: use current head instead --- eth/syncer/syncer.go | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/eth/syncer/syncer.go b/eth/syncer/syncer.go index 96b15d1f27..83fe3ad230 100644 --- a/eth/syncer/syncer.go +++ b/eth/syncer/syncer.go @@ -138,20 +138,6 @@ func (s *Syncer) run() { continue } - // Set the finalized and safe markers relative to the sync target. - // The finalized marker is set two epochs behind the target, - // and the safe marker is set one epoch behind the target. - if header := s.backend.BlockChain().GetHeaderByNumber(target.Number.Uint64() - params.EpochLength*2); header != nil { - if final := s.backend.BlockChain().CurrentFinalBlock(); final == nil || final.Number.Cmp(header.Number) < 0 { - s.backend.BlockChain().SetFinalized(header) - } - } - if header := s.backend.BlockChain().GetHeaderByNumber(target.Number.Uint64() - params.EpochLength); header != nil { - if safe := s.backend.BlockChain().CurrentSafeBlock(); safe == nil || safe.Number.Cmp(header.Number) < 0 { - s.backend.BlockChain().SetSafe(header) - } - } - // Terminate the node if the target has been reached if s.exitWhenSynced { if block := s.backend.BlockChain().GetBlockByHash(target.Hash()); block != nil { @@ -161,6 +147,24 @@ func (s *Syncer) run() { } } + // Set the finalized and safe markers relative to the current head. + // The finalized marker is set two epochs behind the target, + // and the safe marker is set one epoch behind the target. + head := s.backend.BlockChain().CurrentHeader() + if head == nil { + continue + } + if header := s.backend.BlockChain().GetHeaderByNumber(head.Number.Uint64() - params.EpochLength*2); header != nil { + if final := s.backend.BlockChain().CurrentFinalBlock(); final == nil || final.Number.Cmp(header.Number) < 0 { + s.backend.BlockChain().SetFinalized(header) + } + } + if header := s.backend.BlockChain().GetHeaderByNumber(head.Number.Uint64() - params.EpochLength); header != nil { + if safe := s.backend.BlockChain().CurrentSafeBlock(); safe == nil || safe.Number.Cmp(header.Number) < 0 { + s.backend.BlockChain().SetSafe(header) + } + } + case <-s.closed: return }