cmd, eth: 16400 Add an option to stop geth once in sync.

This commit is contained in:
Lucas Hendren 2018-08-06 01:14:19 -04:00
parent 7ea50b7264
commit 52b38e0f56
5 changed files with 11 additions and 10 deletions

View file

@ -34,6 +34,7 @@ import (
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/console"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/internal/debug"
"github.com/ethereum/go-ethereum/log"
@ -83,7 +84,7 @@ var (
utils.TxPoolGlobalQueueFlag,
utils.TxPoolLifetimeFlag,
utils.FastSyncFlag,
utils.ExitWhenSynced,
utils.ExitWhenSyncedFlag,
utils.LightModeFlag,
utils.SyncModeFlag,
utils.GCModeFlag,
@ -319,10 +320,11 @@ func startNode(ctx *cli.Context, stack *node.Node) {
}
}()
if exitWhenSynced := ctx.GlobalDuration(utils.ExitWhenSynced.Name); exitWhenSynced >= 0 {
if exitWhenSynced := ctx.GlobalDuration(utils.ExitWhenSyncedFlag.Name); exitWhenSynced >= 0 {
go func() {
//TODO addd in light mode support
if ctx.GlobalBool(utils.LightModeFlag.Name) || ctx.GlobalString(utils.SyncModeFlag.Name) == "light" {
log.Warn("Exit after block synchronisation disabled for light mode")
} else {
var ethereum *eth.Ethereum
if err := stack.Service(&ethereum); err != nil {

View file

@ -75,7 +75,7 @@ var AppHelpFlagGroups = []flagGroup{
utils.TestnetFlag,
utils.RinkebyFlag,
utils.SyncModeFlag,
utils.ExitWhenSynced,
utils.ExitWhenSyncedFlag,
utils.GCModeFlag,
utils.EthStatsURLFlag,
utils.IdentityFlag,

View file

@ -162,7 +162,7 @@ var (
Name: "fast",
Usage: "Enable fast syncing through state downloads (replaced by --syncmode)",
}
ExitWhenSynced = cli.DurationFlag{
ExitWhenSyncedFlag = cli.DurationFlag{
Name: "exitwhensynced",
Usage: "Exists syncing by given time (default 0) after block synchronisation",
Value: -1,
@ -1082,9 +1082,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
if ctx.GlobalIsSet(NetworkIdFlag.Name) {
cfg.NetworkId = ctx.GlobalUint64(NetworkIdFlag.Name)
}
if ctx.GlobalIsSet(ExitWhenSynced.Name) {
cfg.NetworkId = ctx.GlobalUint64(ExitWhenSynced.Name)
}
cfg.ExitWhenSynced = ctx.GlobalDuration(ExitWhenSyncedFlag.Name)
if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheDatabaseFlag.Name) {
cfg.DatabaseCache = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheDatabaseFlag.Name) / 100
}

View file

@ -116,7 +116,7 @@ type Config struct {
DocRoot string `toml:"-"`
// specify time to exit after syncing
ExitInSync time.Duration
ExitWhenSynced time.Duration
}
type configMarshaling struct {

View file

@ -50,7 +50,7 @@ type lightFetcher struct {
lastUpdateStats *updateStatsEntry
syncing bool
syncDone chan *peer
SyncedCh chan bool
reqMu sync.RWMutex // reqMu protects access to sent header fetch requests
requested map[uint64]fetchRequest
deliverChn chan fetchResponse
@ -116,6 +116,7 @@ func newLightFetcher(pm *ProtocolManager) *lightFetcher {
timeoutChn: make(chan uint64),
requestChn: make(chan bool, 100),
syncDone: make(chan *peer),
SyncedCh: make(chan bool, 1),
maxConfirmedTd: big.NewInt(0),
}
pm.peers.notify(f)