mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
eth, internal/web3ext: admin flag to allow reenabling fast sync (#3139)
This commit is contained in:
parent
586f10ecb1
commit
881bdc289f
4 changed files with 33 additions and 10 deletions
19
eth/api.go
19
eth/api.go
|
|
@ -25,6 +25,8 @@ import (
|
|||
"math/big"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/ethash"
|
||||
|
|
@ -276,6 +278,23 @@ func (api *PrivateAdminAPI) ImportChain(file string) (bool, error) {
|
|||
return true, nil
|
||||
}
|
||||
|
||||
// FastSync reenables fast sync for a shot shot sync round. Use with extreme caution.
|
||||
func (api *PrivateAdminAPI) FastSync() {
|
||||
// Create a diplaimer warning message for the user
|
||||
message1 := fmt.Sprintf("Re-enabling fast sync. If you don't know what this means, quit now!")
|
||||
message2 := fmt.Sprintf("After fast sync completes, check eth.getBlock('latest') against an explorer!")
|
||||
separator := strings.Repeat("-", len(message2))
|
||||
|
||||
glog.V(logger.Warn).Info(separator)
|
||||
glog.V(logger.Warn).Info(message1)
|
||||
glog.V(logger.Warn).Info(message2)
|
||||
glog.V(logger.Warn).Info(separator)
|
||||
|
||||
// Reenable fast sync and abort any currently running sync cycle
|
||||
atomic.StoreUint32(&api.eth.protocolManager.fastSync, 1)
|
||||
api.eth.protocolManager.downloader.Cancel()
|
||||
}
|
||||
|
||||
// PublicDebugAPI is the collection of Etheruem full node APIs exposed
|
||||
// over the public debugging endpoint.
|
||||
type PublicDebugAPI struct {
|
||||
|
|
|
|||
|
|
@ -277,7 +277,7 @@ func (d *Downloader) UnregisterPeer(id string) error {
|
|||
d.cancelLock.RUnlock()
|
||||
|
||||
if master {
|
||||
d.cancel()
|
||||
d.Cancel()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -357,7 +357,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
|
||||
|
|
@ -478,7 +478,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
|
||||
|
|
@ -488,9 +488,8 @@ 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
|
||||
// if the cancel operation was completed.
|
||||
func (d *Downloader) cancel() {
|
||||
// Cancel cancels all of the operations and resets the queue.
|
||||
func (d *Downloader) Cancel() {
|
||||
// Close the current cancel channel
|
||||
d.cancelLock.Lock()
|
||||
if d.cancelCh != nil {
|
||||
|
|
@ -517,7 +516,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
|
||||
|
|
@ -940,7 +939,7 @@ func (d *Downloader) fetchNodeData() error {
|
|||
if err != nil {
|
||||
// If the node data processing failed, the root hash is very wrong, abort
|
||||
glog.V(logger.Error).Infof("peer %d: state processing failed: %v", packet.PeerId(), err)
|
||||
d.cancel()
|
||||
d.Cancel()
|
||||
return
|
||||
}
|
||||
// Processing succeeded, notify state fetcher of continuation
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -197,6 +197,11 @@ web3._extend({
|
|||
call: 'admin_importChain',
|
||||
params: 1
|
||||
}),
|
||||
new web3._extend.Method({
|
||||
name: 'fastSync',
|
||||
call: 'admin_fastSync',
|
||||
params: 0
|
||||
}),
|
||||
new web3._extend.Method({
|
||||
name: 'sleepBlocks',
|
||||
call: 'admin_sleepBlocks',
|
||||
|
|
|
|||
Loading…
Reference in a new issue