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
This commit is contained in:
parent
c2ddfb343a
commit
77ca43a7d2
4 changed files with 33 additions and 10 deletions
19
eth/api.go
19
eth/api.go
|
|
@ -25,6 +25,8 @@ import (
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/ethash"
|
"github.com/ethereum/ethash"
|
||||||
|
|
@ -275,6 +277,23 @@ func (api *PrivateAdminAPI) ImportChain(file string) (bool, error) {
|
||||||
return true, nil
|
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
|
// PublicDebugAPI is the collection of Etheruem full node APIs exposed
|
||||||
// over the public debugging endpoint.
|
// over the public debugging endpoint.
|
||||||
type PublicDebugAPI struct {
|
type PublicDebugAPI struct {
|
||||||
|
|
|
||||||
|
|
@ -277,7 +277,7 @@ func (d *Downloader) UnregisterPeer(id string) error {
|
||||||
d.cancelLock.RUnlock()
|
d.cancelLock.RUnlock()
|
||||||
|
|
||||||
if master {
|
if master {
|
||||||
d.cancel()
|
d.Cancel()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -357,7 +357,7 @@ func (d *Downloader) synchronise(id string, hash common.Hash, td *big.Int, mode
|
||||||
d.cancelPeer = id
|
d.cancelPeer = id
|
||||||
d.cancelLock.Unlock()
|
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
|
// Set the requested sync mode, unless it's forbidden
|
||||||
d.mode = mode
|
d.mode = mode
|
||||||
|
|
@ -478,14 +478,13 @@ func (d *Downloader) spawnSync(origin uint64, fetchers ...func() error) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
d.queue.Close()
|
d.queue.Close()
|
||||||
d.cancel()
|
d.Cancel()
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
return err
|
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.
|
||||||
// if the cancel operation was completed.
|
func (d *Downloader) Cancel() {
|
||||||
func (d *Downloader) cancel() {
|
|
||||||
// Close the current cancel channel
|
// Close the current cancel channel
|
||||||
d.cancelLock.Lock()
|
d.cancelLock.Lock()
|
||||||
if d.cancelCh != nil {
|
if d.cancelCh != nil {
|
||||||
|
|
@ -512,7 +511,7 @@ func (d *Downloader) Terminate() {
|
||||||
d.quitLock.Unlock()
|
d.quitLock.Unlock()
|
||||||
|
|
||||||
// Cancel any pending download requests
|
// Cancel any pending download requests
|
||||||
d.cancel()
|
d.Cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetchHeight retrieves the head header of the remote peer to aid in estimating
|
// fetchHeight retrieves the head header of the remote peer to aid in estimating
|
||||||
|
|
@ -935,7 +934,7 @@ func (d *Downloader) fetchNodeData() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If the node data processing failed, the root hash is very wrong, abort
|
// 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)
|
glog.V(logger.Error).Infof("peer %d: state processing failed: %v", packet.PeerId(), err)
|
||||||
d.cancel()
|
d.Cancel()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Processing succeeded, notify state fetcher of continuation
|
// Processing succeeded, notify state fetcher of continuation
|
||||||
|
|
|
||||||
|
|
@ -974,7 +974,7 @@ func testCancel(t *testing.T, protocol int, mode SyncMode) {
|
||||||
tester.newPeer("peer", protocol, hashes, headers, blocks, receipts)
|
tester.newPeer("peer", protocol, hashes, headers, blocks, receipts)
|
||||||
|
|
||||||
// Make sure canceling works with a pristine downloader
|
// Make sure canceling works with a pristine downloader
|
||||||
tester.downloader.cancel()
|
tester.downloader.Cancel()
|
||||||
if !tester.downloader.queue.Idle() {
|
if !tester.downloader.queue.Idle() {
|
||||||
t.Errorf("download queue not idle")
|
t.Errorf("download queue not idle")
|
||||||
}
|
}
|
||||||
|
|
@ -982,7 +982,7 @@ func testCancel(t *testing.T, protocol int, mode SyncMode) {
|
||||||
if err := tester.sync("peer", nil, mode); err != nil {
|
if err := tester.sync("peer", nil, mode); err != nil {
|
||||||
t.Fatalf("failed to synchronise blocks: %v", err)
|
t.Fatalf("failed to synchronise blocks: %v", err)
|
||||||
}
|
}
|
||||||
tester.downloader.cancel()
|
tester.downloader.Cancel()
|
||||||
if !tester.downloader.queue.Idle() {
|
if !tester.downloader.queue.Idle() {
|
||||||
t.Errorf("download queue not idle")
|
t.Errorf("download queue not idle")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -197,6 +197,11 @@ web3._extend({
|
||||||
call: 'admin_importChain',
|
call: 'admin_importChain',
|
||||||
params: 1
|
params: 1
|
||||||
}),
|
}),
|
||||||
|
new web3._extend.Method({
|
||||||
|
name: 'fastSync',
|
||||||
|
call: 'admin_fastSync',
|
||||||
|
params: 0
|
||||||
|
}),
|
||||||
new web3._extend.Method({
|
new web3._extend.Method({
|
||||||
name: 'sleepBlocks',
|
name: 'sleepBlocks',
|
||||||
call: 'admin_sleepBlocks',
|
call: 'admin_sleepBlocks',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue