mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
cmd, eth: 16400 Add an option to stop geth once in sync.
This commit is contained in:
parent
7ea50b7264
commit
52b38e0f56
5 changed files with 11 additions and 10 deletions
|
|
@ -34,6 +34,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/cmd/utils"
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||||
"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/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"
|
||||||
|
|
@ -83,7 +84,7 @@ var (
|
||||||
utils.TxPoolGlobalQueueFlag,
|
utils.TxPoolGlobalQueueFlag,
|
||||||
utils.TxPoolLifetimeFlag,
|
utils.TxPoolLifetimeFlag,
|
||||||
utils.FastSyncFlag,
|
utils.FastSyncFlag,
|
||||||
utils.ExitWhenSynced,
|
utils.ExitWhenSyncedFlag,
|
||||||
utils.LightModeFlag,
|
utils.LightModeFlag,
|
||||||
utils.SyncModeFlag,
|
utils.SyncModeFlag,
|
||||||
utils.GCModeFlag,
|
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() {
|
go func() {
|
||||||
|
//TODO addd in light mode support
|
||||||
if ctx.GlobalBool(utils.LightModeFlag.Name) || ctx.GlobalString(utils.SyncModeFlag.Name) == "light" {
|
if ctx.GlobalBool(utils.LightModeFlag.Name) || ctx.GlobalString(utils.SyncModeFlag.Name) == "light" {
|
||||||
log.Warn("Exit after block synchronisation disabled for light mode")
|
|
||||||
} else {
|
} else {
|
||||||
var ethereum *eth.Ethereum
|
var ethereum *eth.Ethereum
|
||||||
if err := stack.Service(ðereum); err != nil {
|
if err := stack.Service(ðereum); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ var AppHelpFlagGroups = []flagGroup{
|
||||||
utils.TestnetFlag,
|
utils.TestnetFlag,
|
||||||
utils.RinkebyFlag,
|
utils.RinkebyFlag,
|
||||||
utils.SyncModeFlag,
|
utils.SyncModeFlag,
|
||||||
utils.ExitWhenSynced,
|
utils.ExitWhenSyncedFlag,
|
||||||
utils.GCModeFlag,
|
utils.GCModeFlag,
|
||||||
utils.EthStatsURLFlag,
|
utils.EthStatsURLFlag,
|
||||||
utils.IdentityFlag,
|
utils.IdentityFlag,
|
||||||
|
|
|
||||||
|
|
@ -162,7 +162,7 @@ var (
|
||||||
Name: "fast",
|
Name: "fast",
|
||||||
Usage: "Enable fast syncing through state downloads (replaced by --syncmode)",
|
Usage: "Enable fast syncing through state downloads (replaced by --syncmode)",
|
||||||
}
|
}
|
||||||
ExitWhenSynced = cli.DurationFlag{
|
ExitWhenSyncedFlag = cli.DurationFlag{
|
||||||
Name: "exitwhensynced",
|
Name: "exitwhensynced",
|
||||||
Usage: "Exists syncing by given time (default 0) after block synchronisation",
|
Usage: "Exists syncing by given time (default 0) after block synchronisation",
|
||||||
Value: -1,
|
Value: -1,
|
||||||
|
|
@ -1082,9 +1082,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
|
||||||
if ctx.GlobalIsSet(NetworkIdFlag.Name) {
|
if ctx.GlobalIsSet(NetworkIdFlag.Name) {
|
||||||
cfg.NetworkId = ctx.GlobalUint64(NetworkIdFlag.Name)
|
cfg.NetworkId = ctx.GlobalUint64(NetworkIdFlag.Name)
|
||||||
}
|
}
|
||||||
if ctx.GlobalIsSet(ExitWhenSynced.Name) {
|
cfg.ExitWhenSynced = ctx.GlobalDuration(ExitWhenSyncedFlag.Name)
|
||||||
cfg.NetworkId = ctx.GlobalUint64(ExitWhenSynced.Name)
|
|
||||||
}
|
|
||||||
if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheDatabaseFlag.Name) {
|
if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheDatabaseFlag.Name) {
|
||||||
cfg.DatabaseCache = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheDatabaseFlag.Name) / 100
|
cfg.DatabaseCache = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheDatabaseFlag.Name) / 100
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,7 @@ type Config struct {
|
||||||
DocRoot string `toml:"-"`
|
DocRoot string `toml:"-"`
|
||||||
|
|
||||||
// specify time to exit after syncing
|
// specify time to exit after syncing
|
||||||
ExitInSync time.Duration
|
ExitWhenSynced time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
type configMarshaling struct {
|
type configMarshaling struct {
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ type lightFetcher struct {
|
||||||
lastUpdateStats *updateStatsEntry
|
lastUpdateStats *updateStatsEntry
|
||||||
syncing bool
|
syncing bool
|
||||||
syncDone chan *peer
|
syncDone chan *peer
|
||||||
|
SyncedCh chan bool
|
||||||
reqMu sync.RWMutex // reqMu protects access to sent header fetch requests
|
reqMu sync.RWMutex // reqMu protects access to sent header fetch requests
|
||||||
requested map[uint64]fetchRequest
|
requested map[uint64]fetchRequest
|
||||||
deliverChn chan fetchResponse
|
deliverChn chan fetchResponse
|
||||||
|
|
@ -116,6 +116,7 @@ func newLightFetcher(pm *ProtocolManager) *lightFetcher {
|
||||||
timeoutChn: make(chan uint64),
|
timeoutChn: make(chan uint64),
|
||||||
requestChn: make(chan bool, 100),
|
requestChn: make(chan bool, 100),
|
||||||
syncDone: make(chan *peer),
|
syncDone: make(chan *peer),
|
||||||
|
SyncedCh: make(chan bool, 1),
|
||||||
maxConfirmedTd: big.NewInt(0),
|
maxConfirmedTd: big.NewInt(0),
|
||||||
}
|
}
|
||||||
pm.peers.notify(f)
|
pm.peers.notify(f)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue