eth/downloader: add more logs

This commit is contained in:
Gary Rong 2025-12-19 13:55:23 +08:00
parent af8e152501
commit 1a5f94b5d9
4 changed files with 12 additions and 5 deletions

View file

@ -114,7 +114,9 @@ func (b *beaconBackfiller) resume() {
if b.success != nil { if b.success != nil {
b.success() b.success()
} }
log.Debug("Backfilling completed")
}() }()
log.Debug("Backfilling started")
} }
// SetBadBlockCallback sets the callback to run when a bad block is hit by the // SetBadBlockCallback sets the callback to run when a bad block is hit by the

View file

@ -367,7 +367,7 @@ func (d *Downloader) synchronise(beaconPing chan struct{}) (err error) {
} }
// Obtain the synchronized used in this cycle // Obtain the synchronized used in this cycle
mode := d.moder.get() mode := d.moder.get(true)
defer func() { defer func() {
if err == nil && mode == ethconfig.SnapSync { if err == nil && mode == ethconfig.SnapSync {
d.moder.disableSnap() d.moder.disableSnap()
@ -424,7 +424,7 @@ func (d *Downloader) getMode() SyncMode {
// ConfigSyncMode returns the sync mode configured for the node. // ConfigSyncMode returns the sync mode configured for the node.
// The actual running sync mode can differ from this. // The actual running sync mode can differ from this.
func (d *Downloader) ConfigSyncMode() SyncMode { func (d *Downloader) ConfigSyncMode() SyncMode {
return d.moder.get() return d.moder.get(false)
} }
// syncToHead starts a block synchronization based on the hash chain from // syncToHead starts a block synchronization based on the hash chain from

View file

@ -510,6 +510,7 @@ func (s *skeleton) sync(head *types.Header) (*types.Header, error) {
// The skeleton chain is no longer linked to the local chain for some reason // The skeleton chain is no longer linked to the local chain for some reason
// (e.g. debug_setHead was used to trim the local chain). Re-schedule the // (e.g. debug_setHead was used to trim the local chain). Re-schedule the
// skeleton sync to fill the chain gap. // skeleton sync to fill the chain gap.
log.Warn("Local chain has been trimmed", "tailnumber", s.scratchHead, "tailhash", s.progress.Subchains[0].Next)
return nil, errSyncTrimmed return nil, errSyncTrimmed
} }
} }

View file

@ -75,7 +75,7 @@ func newSyncModer(mode ethconfig.SyncMode, chain BlockChain, disk ethdb.KeyValue
// get retrieves the current sync mode, either explicitly set, or derived // get retrieves the current sync mode, either explicitly set, or derived
// from the chain status. // from the chain status.
func (m *syncModer) get() ethconfig.SyncMode { func (m *syncModer) get(report bool) ethconfig.SyncMode {
m.lock.Lock() m.lock.Lock()
defer m.lock.Unlock() defer m.lock.Unlock()
@ -83,12 +83,16 @@ func (m *syncModer) get() ethconfig.SyncMode {
if m.mode == ethconfig.SnapSync { if m.mode == ethconfig.SnapSync {
return ethconfig.SnapSync return ethconfig.SnapSync
} }
logger := log.Debug
if report {
logger = log.Info
}
// We are probably in full sync, but we might have rewound to before the // We are probably in full sync, but we might have rewound to before the
// snap sync pivot, check if we should re-enable snap sync. // snap sync pivot, check if we should re-enable snap sync.
head := m.chain.CurrentBlock() head := m.chain.CurrentBlock()
if pivot := rawdb.ReadLastPivotNumber(m.disk); pivot != nil { if pivot := rawdb.ReadLastPivotNumber(m.disk); pivot != nil {
if head.Number.Uint64() < *pivot { if head.Number.Uint64() < *pivot {
log.Info("Reenabled snap-sync as chain is lagging behind the pivot", "head", head.Number, "pivot", pivot) logger("Reenabled snap-sync as chain is lagging behind the pivot", "head", head.Number, "pivot", pivot)
return ethconfig.SnapSync return ethconfig.SnapSync
} }
} }
@ -96,7 +100,7 @@ func (m *syncModer) get() ethconfig.SyncMode {
// the head state, forcefully rerun the snap sync. Note it doesn't mean the // the head state, forcefully rerun the snap sync. Note it doesn't mean the
// persistent state is corrupted, just mismatch with the head block. // persistent state is corrupted, just mismatch with the head block.
if !m.chain.HasState(head.Root) { if !m.chain.HasState(head.Root) {
log.Info("Reenabled snap-sync as chain is stateless") logger("Reenabled snap-sync as chain is stateless")
return ethconfig.SnapSync return ethconfig.SnapSync
} }
// Nope, we're really full syncing // Nope, we're really full syncing