diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-03-22 08:37:24 +0800 |
---|---|---|
committer | Felix Lange <fjl@users.noreply.github.com> | 2017-03-22 08:37:24 +0800 |
commit | 9b84caf3a5f55cc2a14b50291118b9fab668b8c2 (patch) | |
tree | 0c9f92abf034f6a3e8f0cbc7458b209331fd7c8f /eth | |
parent | 06d6685eb58f6cb0eda4d7adc8ae91e5cdb88462 (diff) | |
download | go-tangerine-9b84caf3a5f55cc2a14b50291118b9fab668b8c2.tar go-tangerine-9b84caf3a5f55cc2a14b50291118b9fab668b8c2.tar.gz go-tangerine-9b84caf3a5f55cc2a14b50291118b9fab668b8c2.tar.bz2 go-tangerine-9b84caf3a5f55cc2a14b50291118b9fab668b8c2.tar.lz go-tangerine-9b84caf3a5f55cc2a14b50291118b9fab668b8c2.tar.xz go-tangerine-9b84caf3a5f55cc2a14b50291118b9fab668b8c2.tar.zst go-tangerine-9b84caf3a5f55cc2a14b50291118b9fab668b8c2.zip |
core, eth, les: support resuming fast sync on heavy rollback (#3743)
Diffstat (limited to 'eth')
-rw-r--r-- | eth/api_backend.go | 1 | ||||
-rw-r--r-- | eth/downloader/downloader.go | 16 | ||||
-rw-r--r-- | eth/downloader/downloader_test.go | 4 | ||||
-rw-r--r-- | eth/sync.go | 8 |
4 files changed, 19 insertions, 10 deletions
diff --git a/eth/api_backend.go b/eth/api_backend.go index 5a5c4c532..bce772900 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -51,6 +51,7 @@ func (b *EthApiBackend) CurrentBlock() *types.Block { } func (b *EthApiBackend) SetHead(number uint64) { + b.eth.protocolManager.downloader.Cancel() b.eth.blockchain.SetHead(number) } diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index f7aca031a..d26995782 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -277,7 +277,7 @@ func (d *Downloader) UnregisterPeer(id string) error { d.cancelLock.RUnlock() if master { - d.cancel() + d.Cancel() } return nil } @@ -352,7 +352,7 @@ func (d *Downloader) synchronise(id string, hash common.Hash, td *big.Int, mode d.cancelPeer = id d.cancelLock.Unlock() - defer d.cancel() // No matter what, we can't leave the cancel channel open + defer d.Cancel() // No matter what, we can't leave the cancel channel open // Set the requested sync mode, unless it's forbidden d.mode = mode @@ -473,7 +473,7 @@ func (d *Downloader) spawnSync(origin uint64, fetchers ...func() error) error { } } d.queue.Close() - d.cancel() + d.Cancel() wg.Wait() // If sync failed in the critical section, bump the fail counter @@ -483,9 +483,9 @@ func (d *Downloader) spawnSync(origin uint64, fetchers ...func() error) error { return err } -// cancel cancels all of the operations and resets the queue. It returns true +// Cancel cancels all of the operations and resets the queue. It returns true // if the cancel operation was completed. -func (d *Downloader) cancel() { +func (d *Downloader) Cancel() { // Close the current cancel channel d.cancelLock.Lock() if d.cancelCh != nil { @@ -512,7 +512,7 @@ func (d *Downloader) Terminate() { d.quitLock.Unlock() // Cancel any pending download requests - d.cancel() + d.Cancel() } // fetchHeight retrieves the head header of the remote peer to aid in estimating @@ -945,7 +945,7 @@ func (d *Downloader) fetchNodeData() error { if err != nil { // If the node data processing failed, the root hash is very wrong, abort log.Error("State processing failed", "peer", packet.PeerId(), "err", err) - d.cancel() + d.Cancel() return } // Processing succeeded, notify state fetcher of continuation @@ -1208,7 +1208,7 @@ func (d *Downloader) processHeaders(origin uint64, td *big.Int) error { if atomic.LoadUint32(&d.fsPivotFails) == 0 { for _, header := range rollback { if header.Number.Uint64() == pivot { - log.Warn("Fast-sync critical section failure, locked pivot to header", "number", pivot, "hash", header.Hash()) + log.Warn("Fast-sync pivot locked in", "number", pivot, "hash", header.Hash()) d.fsPivotLock = header } } diff --git a/eth/downloader/downloader_test.go b/eth/downloader/downloader_test.go index a9ea797ea..267a0def9 100644 --- a/eth/downloader/downloader_test.go +++ b/eth/downloader/downloader_test.go @@ -982,7 +982,7 @@ func testCancel(t *testing.T, protocol int, mode SyncMode) { tester.newPeer("peer", protocol, hashes, headers, blocks, receipts) // Make sure canceling works with a pristine downloader - tester.downloader.cancel() + tester.downloader.Cancel() if !tester.downloader.queue.Idle() { t.Errorf("download queue not idle") } @@ -990,7 +990,7 @@ func testCancel(t *testing.T, protocol int, mode SyncMode) { if err := tester.sync("peer", nil, mode); err != nil { t.Fatalf("failed to synchronise blocks: %v", err) } - tester.downloader.cancel() + tester.downloader.Cancel() if !tester.downloader.queue.Idle() { t.Errorf("download queue not idle") } diff --git a/eth/sync.go b/eth/sync.go index 6e2c7c432..f2cae6c19 100644 --- a/eth/sync.go +++ b/eth/sync.go @@ -175,6 +175,14 @@ func (pm *ProtocolManager) synchronise(peer *peer) { // Otherwise try to sync with the downloader mode := downloader.FullSync if atomic.LoadUint32(&pm.fastSync) == 1 { + // Fast sync was explicitly requested, and explicitly granted + mode = downloader.FastSync + } else if currentBlock.NumberU64() == 0 && pm.blockchain.CurrentFastBlock().NumberU64() > 0 { + // The database seems empty as the current block is the genesis. Yet the fast + // block is ahead, so fast sync was enabled for this node at a certain point. + // The only scenario where this can happen is if the user manually (or via a + // bad block) rolled back a fast sync node below the sync point. In this case + // however it's safe to reenable fast sync. mode = downloader.FastSync } if err := pm.downloader.Synchronise(peer.id, pHead, pTd, mode); err != nil { |