mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
[go-eth-16400] Add an option to stop geth once in sync
This commit is contained in:
parent
d2fe83dc5c
commit
1ae875829e
5 changed files with 34 additions and 0 deletions
|
|
@ -107,6 +107,7 @@ var (
|
|||
utils.DeveloperPeriodFlag,
|
||||
utils.TestnetFlag,
|
||||
utils.RinkebyFlag,
|
||||
utils.ExitWhenSyncedFlag,
|
||||
utils.VMEnableDebugFlag,
|
||||
utils.NetworkIdFlag,
|
||||
utils.RPCCORSDomainFlag,
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@ var AppHelpFlagGroups = []flagGroup{
|
|||
utils.NetworkIdFlag,
|
||||
utils.TestnetFlag,
|
||||
utils.RinkebyFlag,
|
||||
utils.ExitWhenSyncedFlag,
|
||||
utils.SyncModeFlag,
|
||||
utils.GCModeFlag,
|
||||
utils.EthStatsURLFlag,
|
||||
|
|
|
|||
|
|
@ -139,6 +139,11 @@ var (
|
|||
Name: "rinkeby",
|
||||
Usage: "Rinkeby network: pre-configured proof-of-authority test network",
|
||||
}
|
||||
ExitWhenSyncedFlag = cli.IntFlag{
|
||||
Name: "exit-when-synced",
|
||||
Usage: "Exit after the chain is in sync",
|
||||
Value: 0,
|
||||
}
|
||||
DeveloperFlag = cli.BoolFlag{
|
||||
Name: "dev",
|
||||
Usage: "Ephemeral proof-of-authority network with a pre-funded developer account, mining enabled",
|
||||
|
|
@ -1034,6 +1039,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
|
|||
if ctx.GlobalIsSet(LightServFlag.Name) {
|
||||
cfg.LightServ = ctx.GlobalInt(LightServFlag.Name)
|
||||
}
|
||||
if ctx.GlobalIsSet(ExitWhenSyncedFlag.Name) {
|
||||
cfg.ExitWhenSynced = ctx.GlobalInt(ExitWhenSyncedFlag.Name)
|
||||
}
|
||||
if ctx.GlobalIsSet(LightPeersFlag.Name) {
|
||||
cfg.LightPeers = ctx.GlobalInt(LightPeersFlag.Name)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,6 +87,9 @@ type Config struct {
|
|||
LightServ int `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests
|
||||
LightPeers int `toml:",omitempty"` // Maximum number of LES client peers
|
||||
|
||||
// Exit when sycned options
|
||||
ExitWhenSynced int `toml:",omitempty"`
|
||||
|
||||
// Database options
|
||||
SkipBcVersionCheck bool `toml:"-"`
|
||||
DatabaseHandles int `toml:"-"`
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package downloader
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"sync"
|
||||
|
|
@ -1094,6 +1095,26 @@ func (d *Downloader) fetchParts(errCancel error, deliveryCh chan dataPack, deliv
|
|||
// If there's nothing more to fetch, wait or terminate
|
||||
if pending() == 0 {
|
||||
if !inFlight() && finished {
|
||||
// Exit when synced param should be executed after defined 'value' in seconds
|
||||
// TODO:
|
||||
// 1. Get the flag value - ctx.GlobalInt(util.ExitWhenSyncedFlag.Name)
|
||||
// 2. Figure out where to put this
|
||||
exitWhenSynced := 5
|
||||
if exitWhenSynced > 0 {
|
||||
exitCounter := exitWhenSynced
|
||||
ticker := time.NewTicker(time.Second * 1)
|
||||
go func() {
|
||||
for range ticker.C {
|
||||
fmt.Println("Exiting sync process in ", exitCounter)
|
||||
exitCounter -= 1
|
||||
}
|
||||
}()
|
||||
time.Sleep(time.Second * time.Duration(exitWhenSynced))
|
||||
ticker.Stop()
|
||||
fmt.Println("Exiting sync process in ", exitCounter)
|
||||
}
|
||||
fmt.Println("Exit sync")
|
||||
os.Exit(3)
|
||||
log.Debug("Data fetching completed", "type", kind)
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue