Skip to content

Downloader.synchronisePoW

Source (upstream pre-purge) Current
File eth/downloader/downloader.go downloader_pow.go
Symbol Downloader.synchronise Downloader.synchronisePoW
Ref 45baf2111~1 etc/v1.17.3-full-node

Renamed from synchronise. Removed beaconMode/beaconPing params and ttd (not applicable to ETC perpetual PoW). Otherwise identical to pre-purge.

3-way merge — purge → getc ← upstream

pre-purgeupstreamcommon≈ adapted (origin inferred by similarity)fork-only
// synchronisePoW will select the peer and use it for synchronising. If an empty string is given
// it will use the best peer possible and synchronize if its TD is higher than our own. If any of the
// checks fail an error will be returned. This method is synchronous
func (d *Downloader) synchronisePoW(id string, hash common.Hash, td *big.Int, mode SyncMode) error {
// Make sure only one goroutine is ever allowed past this point at once
if !d.synchronising.CompareAndSwap(false, true) {
return errBusy
}
defer d.synchronising.Store(false)
// Post a user notification of the sync (only once per session)
if d.notified.CompareAndSwap(false, true) {
log.Info("Block synchronisation started")
}
if mode == ethconfig.SnapSync {
// Snap sync will directly modify the persistent state, making the entire
// trie database unusable until the state is fully synced. To prevent any
// subsequent state reads, explicitly disable the trie database and state
// syncer is responsible to address and correct any state missing.
if d.blockchain.TrieDB().Scheme() == rawdb.PathScheme {
if err := d.blockchain.TrieDB().Disable(); err != nil {
return err
}
}
// Snap sync uses the snapshot namespace to store potentially flaky data until
// sync completely heals and finishes. Pause snapshot maintenance in the mean-
// time to prevent access.
if snapshots := d.blockchain.Snapshots(); snapshots != nil { // Only nil in tests
snapshots.Disable()
}
}
// Reset the queue, peer set and wake channels to clean any internal leftover state
d.queue.Reset(blockCacheMaxItems, blockCacheInitialItems)
d.peers.Reset()
for _, ch := range []chan bool{d.queue.blockWakeCh, d.queue.receiptWakeCh} {
select {
case <-ch:
default:
}
}
for empty := false; !empty; {
select {
case <-d.headerProcCh:
default:
empty = true
}
}
// Create cancel channel for aborting mid-flight and mark the master peer
d.cancelLock.Lock()
d.cancelCh = make(chan struct{})
d.cancelPeer = id
d.cancelLock.Unlock()
defer d.Cancel() // No matter what, we can't leave the cancel channel open
// Atomically set the requested sync mode
d.mode.Store(uint32(mode))
// Retrieve the origin peer and initiate the downloading process
p := d.peers.Peer(id)
if p == nil {
return errUnknownPeer
}
return d.syncWithPeer(p, hash, td)
}
core-geth validation — +5 -35 | | | |---|---| | File | [`downloader.go`](https://github.com/etclabscore/core-geth/blob/v1.12.20/eth/downloader/downloader.go) | | Symbol | `Downloader.synchronise` | | Ref | `v1.12.20` |
--- a/core-geth/eth/downloader/downloader.go
+++ b/etc/eth/downloader/downloader_pow.go
@@ -1,26 +1,7 @@
-// synchronise will select the peer and use it for synchronising. If an empty string is given
+// synchronisePoW will select the peer and use it for synchronising. If an empty string is given
 // it will use the best peer possible and synchronize if its TD is higher than our own. If any of the
 // checks fail an error will be returned. This method is synchronous
-func (d *Downloader) synchronise(id string, hash common.Hash, td, ttd *big.Int, mode SyncMode, beaconMode bool, beaconPing chan struct{}) error {
-   // The beacon header syncer is async. It will start this synchronization and
-   // will continue doing other tasks. However, if synchronization needs to be
-   // cancelled, the syncer needs to know if we reached the startup point (and
-   // inited the cancel channel) or not yet. Make sure that we'll signal even in
-   // case of a failure.
-   if beaconPing != nil {
-       defer func() {
-           select {
-           case <-beaconPing: // already notified
-           default:
-               close(beaconPing) // weird exit condition, notify that it's safe to cancel (the nothing)
-           }
-       }()
-   }
-
-   // Mock out the synchronisation if testing
-   if d.synchroniseMock != nil {
-       return d.synchroniseMock(id, hash)
-   }
+func (d *Downloader) synchronisePoW(id string, hash common.Hash, td *big.Int, mode SyncMode) error {
    // Make sure only one goroutine is ever allowed past this point at once
    if !d.synchronising.CompareAndSwap(false, true) {
        return errBusy
@@ -31,7 +12,7 @@
    if d.notified.CompareAndSwap(false, true) {
        log.Info("Block synchronisation started")
    }
-   if mode == SnapSync {
+   if mode == ethconfig.SnapSync {
        // Snap sync will directly modify the persistent state, making the entire
        // trie database unusable until the state is fully synced. To prevent any
        // subsequent state reads, explicitly disable the trie database and state
@@ -58,10 +39,6 @@
        default:
        }
    }
-   select {
-   case <-d.totalDiffCh:
-   default:
-   }
    for empty := false; !empty; {
        select {
        case <-d.headerProcCh:
@@ -73,7 +50,6 @@
    d.cancelLock.Lock()
    d.cancelCh = make(chan struct{})
    d.cancelPeer = id
-   d.td = td
    d.cancelLock.Unlock()

    defer d.Cancel() // No matter what, we can't leave the cancel channel open
@@ -82,15 +58,9 @@
    d.mode.Store(uint32(mode))

    // Retrieve the origin peer and initiate the downloading process
-   var p *peerConnection
-   if !beaconMode { // Beacon mode doesn't need a peer to sync from
-       p = d.peers.Peer(id)
+   p := d.peers.Peer(id)
        if p == nil {
            return errUnknownPeer
        }
-   }
-   if beaconPing != nil {
-       close(beaconPing)
-   }
-   return d.syncWithPeer(p, hash, td, ttd, beaconMode)
+   return d.syncWithPeer(p, hash, td)
 }

← Sync & Downloader