From 52b38e0f56a34bb2c2d42bca8f957eb03c67ce95 Mon Sep 17 00:00:00 2001 From: Lucas Hendren Date: Mon, 6 Aug 2018 01:14:19 -0400 Subject: [PATCH] cmd, eth: 16400 Add an option to stop geth once in sync. --- cmd/geth/main.go | 8 +++++--- cmd/geth/usage.go | 2 +- cmd/utils/flags.go | 6 ++---- eth/config.go | 2 +- les/fetcher.go | 3 ++- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 3e454c8b4a..8e70e63313 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -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(ðereum); err != nil { diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go index 4e08c9e94a..88cd514834 100644 --- a/cmd/geth/usage.go +++ b/cmd/geth/usage.go @@ -75,7 +75,7 @@ var AppHelpFlagGroups = []flagGroup{ utils.TestnetFlag, utils.RinkebyFlag, utils.SyncModeFlag, - utils.ExitWhenSynced, + utils.ExitWhenSyncedFlag, utils.GCModeFlag, utils.EthStatsURLFlag, utils.IdentityFlag, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 76cb405705..8813c9aff8 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -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 } diff --git a/eth/config.go b/eth/config.go index 78b582083a..bbdf9e60f6 100644 --- a/eth/config.go +++ b/eth/config.go @@ -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 { diff --git a/les/fetcher.go b/les/fetcher.go index cc539c42bf..eff58b8711 100644 --- a/les/fetcher.go +++ b/les/fetcher.go @@ -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)