aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/geth/main.go29
-rw-r--r--cmd/geth/usage.go1
-rw-r--r--cmd/utils/flags.go5
3 files changed, 34 insertions, 1 deletions
diff --git a/cmd/geth/main.go b/cmd/geth/main.go
index 77c04ff36..0d9f733de 100644
--- a/cmd/geth/main.go
+++ b/cmd/geth/main.go
@@ -31,8 +31,10 @@ import (
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/cmd/utils"
+ "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/console"
"github.com/ethereum/go-ethereum/eth"
+ "github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/internal/debug"
"github.com/ethereum/go-ethereum/log"
@@ -87,6 +89,7 @@ var (
utils.ULCTrustedNodesFlag,
utils.ULCMinTrustedFractionFlag,
utils.SyncModeFlag,
+ utils.ExitWhenSyncedFlag,
utils.GCModeFlag,
utils.LightServFlag,
utils.LightPeersFlag,
@@ -339,6 +342,32 @@ func startNode(ctx *cli.Context, stack *node.Node) {
}
}
}()
+
+ // Spawn a standalone goroutine for status synchronization monitoring,
+ // close the node when synchronization is complete if user required.
+ if ctx.GlobalBool(utils.ExitWhenSyncedFlag.Name) {
+ go func() {
+ sub := stack.EventMux().Subscribe(downloader.DoneEvent{})
+ defer sub.Unsubscribe()
+ for {
+ event := <-sub.Chan()
+ if event == nil {
+ continue
+ }
+ done, ok := event.Data.(downloader.DoneEvent)
+ if !ok {
+ continue
+ }
+ if timestamp := time.Unix(done.Latest.Time.Int64(), 0); time.Since(timestamp) < 10*time.Minute {
+ log.Info("Synchronisation completed", "latestnum", done.Latest.Number, "latesthash", done.Latest.Hash(),
+ "age", common.PrettyAge(timestamp))
+ stack.Stop()
+ }
+
+ }
+ }()
+ }
+
// Start auxiliary services if enabled
if ctx.GlobalBool(utils.MiningEnabledFlag.Name) || ctx.GlobalBool(utils.DeveloperFlag.Name) {
// Mining only makes sense if a full Ethereum node is running
diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go
index de2a3d073..a19ad1094 100644
--- a/cmd/geth/usage.go
+++ b/cmd/geth/usage.go
@@ -75,6 +75,7 @@ var AppHelpFlagGroups = []flagGroup{
utils.TestnetFlag,
utils.RinkebyFlag,
utils.SyncModeFlag,
+ utils.ExitWhenSyncedFlag,
utils.GCModeFlag,
utils.EthStatsURLFlag,
utils.IdentityFlag,
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go
index 3109bf962..1d8c7f378 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -162,6 +162,10 @@ var (
Usage: "Document Root for HTTPClient file scheme",
Value: DirectoryString{homeDir()},
}
+ ExitWhenSyncedFlag = cli.BoolFlag{
+ Name: "exitwhensynced",
+ Usage: "Exists syncing after block synchronisation",
+ }
ULCModeConfigFlag = cli.StringFlag{
Name: "ulc.config",
Usage: "Config file to use for ultra light client mode",
@@ -178,7 +182,6 @@ var (
Name: "ulc.trusted",
Usage: "List of trusted ULC servers",
}
-
defaultSyncMode = eth.DefaultConfig.SyncMode
SyncModeFlag = TextMarshalerFlag{
Name: "syncmode",