chainSyncer.nextSyncOp¶
| Source (upstream pre-purge) | Current | |
|---|---|---|
| File | eth/sync.go |
sync_pow.go |
| Symbol | chainSyncer.nextSyncOp |
chainSyncer.nextSyncOp |
| Ref | f4d53133f~1 |
etc/v1.17.3-full-node |
Removed post-merge conditions (beacon sync, TTD checks) — ETC is perpetual PoW
3-way merge — purge → getc ← upstream¶
pre-purgefork-only
↗// nextSyncOp determines whether sync is required at this time.
func (cs *chainSyncer) nextSyncOp() *chainSyncOp {
if cs.doneCh != nil {
return nil // Sync already running
}
↗ // Ensure we're at minimum peer count.
minPeers := defaultMinSyncPeers
if cs.forced {
minPeers = 1
} else if minPeers > cs.handler.maxPeers {
minPeers = cs.handler.maxPeers
}
if cs.handler.peers.len() < minPeers {
return nil
}
// We have enough peers, pick the one with the highest TD.
↗ peer := cs.handler.peers.peerWithHighestTD()
if peer == nil {
return nil
}
mode, ourTD := cs.modeAndLocalHead()
op := peerToSyncOp(mode, peer)
if op.td.Cmp(ourTD) <= 0 {
// We're in sync, check MESS activation
cs.checkMESSActivation()
↗ return nil // We're in sync
}
return op
}
core-geth validation — +4 -39
| | | |---|---| | File | [`sync.go`](https://github.com/etclabscore/core-geth/blob/v1.12.20/eth/sync.go) | | Symbol | `chainSyncer.nextSyncOp` | | Ref | `v1.12.20` |--- a/core-geth/eth/sync.go
+++ b/etc/eth/sync_pow.go
@@ -3,17 +3,6 @@
if cs.doneCh != nil {
return nil // Sync already running
}
- // If a beacon client once took over control, disable the entire legacy sync
- // path from here on end. Note, there is a slight "race" between reaching TTD
- // and the beacon client taking over. The downloader will enforce that nothing
- // above the first TTD will be delivered to the chain for import.
- //
- // An alternative would be to check the local chain for exceeding the TTD and
- // avoid triggering a sync in that case, but that could also miss sibling or
- // other family TTD block being accepted.
- if cs.handler.chain.Config().GetEthashTerminalTotalDifficultyPassed() || cs.handler.merger.TDDReached() {
- return nil
- }
// Ensure we're at minimum peer count.
minPeers := defaultMinSyncPeers
if cs.forced {
@@ -21,18 +10,10 @@
} else if minPeers > cs.handler.maxPeers {
minPeers = cs.handler.maxPeers
}
- if cs.handler.chain.IsArtificialFinalityEnabled() {
- if cs.handler.peers.len() < minArtificialFinalityPeers {
- // If artificial finality state is forcefully set (overridden) this will just be a noop.
- cs.handler.chain.EnableArtificialFinality(false, "reason", "low peers", "peers", cs.handler.peers.len())
- }
- }
if cs.handler.peers.len() < minPeers {
return nil
}
- // We have enough peers, pick the one with the highest TD, but avoid going
- // over the terminal total difficulty. Above that we expect the consensus
- // clients to direct the chain head to sync to.
+ // We have enough peers, pick the one with the highest TD.
peer := cs.handler.peers.peerWithHighestTD()
if peer == nil {
return nil
@@ -40,25 +21,9 @@
mode, ourTD := cs.modeAndLocalHead()
op := peerToSyncOp(mode, peer)
if op.td.Cmp(ourTD) <= 0 {
- // We seem to be in sync according to the legacy rules. In the merge
- // world, it can also mean we're stuck on the merge block, waiting for
- // a beacon client. In the latter case, notify the user.
- if ttd := cs.handler.chain.Config().GetEthashTerminalTotalDifficulty(); ttd != nil && ourTD.Cmp(ttd) >= 0 && time.Since(cs.warned) > 10*time.Second {
- log.Warn("Local chain is post-merge, waiting for beacon client sync switch-over...")
- cs.warned = time.Now()
- }
- // Enable artificial finality if parameters if should.
- // - In full sync mode.
- if op.mode == downloader.FullSync &&
- // - Have enough peers.
- cs.handler.peers.len() >= minArtificialFinalityPeers &&
- // - Head is not stale.
- !(time.Since(time.Unix(int64(cs.handler.chain.CurrentHeader().Time), 0)) > artificialFinalitySafetyInterval) &&
- // - AF is disabled (so we should reenable).
- !cs.handler.chain.IsArtificialFinalityEnabled() {
- cs.handler.chain.EnableArtificialFinality(true, "reason", "synced", "peers", cs.handler.peers.len())
- }
- return nil // We're in sync.
+ // We're in sync, check MESS activation
+ cs.checkMESSActivation()
+ return nil // We're in sync
}
return op
}