|
@@ -31,8 +31,10 @@ import (
|
|
|
"github.com/ethereum/go-ethereum/accounts"
|
|
"github.com/ethereum/go-ethereum/accounts"
|
|
|
"github.com/ethereum/go-ethereum/accounts/keystore"
|
|
"github.com/ethereum/go-ethereum/accounts/keystore"
|
|
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
|
|
|
|
+ "github.com/ethereum/go-ethereum/common"
|
|
|
"github.com/ethereum/go-ethereum/console"
|
|
"github.com/ethereum/go-ethereum/console"
|
|
|
"github.com/ethereum/go-ethereum/eth"
|
|
"github.com/ethereum/go-ethereum/eth"
|
|
|
|
|
+ "github.com/ethereum/go-ethereum/eth/downloader"
|
|
|
"github.com/ethereum/go-ethereum/ethclient"
|
|
"github.com/ethereum/go-ethereum/ethclient"
|
|
|
"github.com/ethereum/go-ethereum/internal/debug"
|
|
"github.com/ethereum/go-ethereum/internal/debug"
|
|
|
"github.com/ethereum/go-ethereum/log"
|
|
"github.com/ethereum/go-ethereum/log"
|
|
@@ -87,6 +89,7 @@ var (
|
|
|
utils.ULCTrustedNodesFlag,
|
|
utils.ULCTrustedNodesFlag,
|
|
|
utils.ULCMinTrustedFractionFlag,
|
|
utils.ULCMinTrustedFractionFlag,
|
|
|
utils.SyncModeFlag,
|
|
utils.SyncModeFlag,
|
|
|
|
|
+ utils.ExitWhenSyncedFlag,
|
|
|
utils.GCModeFlag,
|
|
utils.GCModeFlag,
|
|
|
utils.LightServFlag,
|
|
utils.LightServFlag,
|
|
|
utils.LightPeersFlag,
|
|
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
|
|
// Start auxiliary services if enabled
|
|
|
if ctx.GlobalBool(utils.MiningEnabledFlag.Name) || ctx.GlobalBool(utils.DeveloperFlag.Name) {
|
|
if ctx.GlobalBool(utils.MiningEnabledFlag.Name) || ctx.GlobalBool(utils.DeveloperFlag.Name) {
|
|
|
// Mining only makes sense if a full Ethereum node is running
|
|
// Mining only makes sense if a full Ethereum node is running
|