chainSyncer.modeAndLocalHead¶
| Source (upstream pre-purge) | Current | |
|---|---|---|
| File | eth/sync.go |
sync_pow.go |
| Symbol | chainSyncer.modeAndLocalHead |
chainSyncer.modeAndLocalHead |
| Ref | f4d53133f~1 |
etc/v1.17.3-full-node |
3-way merge — purge → getc ← upstream¶
pre-purgefork-only
↗func (cs *chainSyncer) modeAndLocalHead() (downloader.SyncMode, *big.Int) {
// If we're in snap sync mode, return that directly
if cs.handler.downloader.ConfigSyncMode() == ethconfig.SnapSync {
↗ block := cs.handler.chain.CurrentSnapBlock()
td := cs.handler.chain.GetTd(block.Hash(), block.Number.Uint64())
return downloader.SnapSync, td
}
// 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.
head := cs.handler.chain.CurrentBlock()
if pivot := rawdb.ReadLastPivotNumber(cs.handler.database); pivot != nil {
if head.Number.Uint64() < *pivot {
block := cs.handler.chain.CurrentSnapBlock()
td := cs.handler.chain.GetTd(block.Hash(), block.Number.Uint64())
return downloader.SnapSync, td
}
}
// We are in a full sync, but the associated head state is missing. To complete
// the head state, forcefully rerun the snap sync. Note it doesn't mean the
// persistent state is corrupted, just mismatch with the head block.
if !cs.handler.chain.HasState(head.Root) {
block := cs.handler.chain.CurrentSnapBlock()
td := cs.handler.chain.GetTd(block.Hash(), block.Number.Uint64())
log.Info("Reenabled snap sync as chain is stateless")
return downloader.SnapSync, td
}
// Nope, we're really full syncing
td := cs.handler.chain.GetTd(head.Hash(), head.Number.Uint64())
return downloader.FullSync, td
}
core-geth validation — +1 -1
| | | |---|---| | File | [`sync.go`](https://github.com/etclabscore/core-geth/blob/v1.12.20/eth/sync.go) | | Symbol | `chainSyncer.modeAndLocalHead` | | Ref | `v1.12.20` |--- a/core-geth/eth/sync.go
+++ b/etc/eth/sync_pow.go
@@ -1,6 +1,6 @@
func (cs *chainSyncer) modeAndLocalHead() (downloader.SyncMode, *big.Int) {
// If we're in snap sync mode, return that directly
- if cs.handler.snapSync.Load() {
+ if cs.handler.downloader.ConfigSyncMode() == ethconfig.SnapSync {
block := cs.handler.chain.CurrentSnapBlock()
td := cs.handler.chain.GetTd(block.Hash(), block.Number.Uint64())
return downloader.SnapSync, td