mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
cmd, eth: Added in the flag to step geth once sync based on input
This commit is contained in:
parent
7abedf9bbb
commit
7ea50b7264
5 changed files with 37 additions and 1 deletions
|
|
@ -83,6 +83,7 @@ var (
|
|||
utils.TxPoolGlobalQueueFlag,
|
||||
utils.TxPoolLifetimeFlag,
|
||||
utils.FastSyncFlag,
|
||||
utils.ExitWhenSynced,
|
||||
utils.LightModeFlag,
|
||||
utils.SyncModeFlag,
|
||||
utils.GCModeFlag,
|
||||
|
|
@ -317,6 +318,24 @@ func startNode(ctx *cli.Context, stack *node.Node) {
|
|||
}
|
||||
}
|
||||
}()
|
||||
|
||||
if exitWhenSynced := ctx.GlobalDuration(utils.ExitWhenSynced.Name); exitWhenSynced >= 0 {
|
||||
go func() {
|
||||
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 {
|
||||
utils.Fatalf("Ethereum service not running: %v", err)
|
||||
}
|
||||
<-ethereum.Downloader().SyncedCh
|
||||
log.Info("Synchronisation completed, exitting", "countdown", exitWhenSynced)
|
||||
time.Sleep(exitWhenSynced)
|
||||
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
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ var AppHelpFlagGroups = []flagGroup{
|
|||
utils.TestnetFlag,
|
||||
utils.RinkebyFlag,
|
||||
utils.SyncModeFlag,
|
||||
utils.ExitWhenSynced,
|
||||
utils.GCModeFlag,
|
||||
utils.EthStatsURLFlag,
|
||||
utils.IdentityFlag,
|
||||
|
|
|
|||
|
|
@ -162,6 +162,11 @@ var (
|
|||
Name: "fast",
|
||||
Usage: "Enable fast syncing through state downloads (replaced by --syncmode)",
|
||||
}
|
||||
ExitWhenSynced = cli.DurationFlag{
|
||||
Name: "exitwhensynced",
|
||||
Usage: "Exists syncing by given time (default 0) after block synchronisation",
|
||||
Value: -1,
|
||||
}
|
||||
LightModeFlag = cli.BoolFlag{
|
||||
Name: "light",
|
||||
Usage: "Enable light client mode (replaced by --syncmode)",
|
||||
|
|
@ -1077,7 +1082,9 @@ 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)
|
||||
}
|
||||
if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheDatabaseFlag.Name) {
|
||||
cfg.DatabaseCache = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheDatabaseFlag.Name) / 100
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,6 +114,9 @@ type Config struct {
|
|||
|
||||
// Miscellaneous options
|
||||
DocRoot string `toml:"-"`
|
||||
|
||||
// specify time to exit after syncing
|
||||
ExitInSync time.Duration
|
||||
}
|
||||
|
||||
type configMarshaling struct {
|
||||
|
|
|
|||
|
|
@ -128,6 +128,7 @@ type Downloader struct {
|
|||
bodyWakeCh chan bool // [eth/62] Channel to signal the block body fetcher of new tasks
|
||||
receiptWakeCh chan bool // [eth/63] Channel to signal the receipt fetcher of new tasks
|
||||
headerProcCh chan []*types.Header // [eth/62] Channel to feed the header processor new tasks
|
||||
SyncedCh chan bool
|
||||
|
||||
// for stateFetcher
|
||||
stateSyncStart chan *stateSync
|
||||
|
|
@ -226,6 +227,7 @@ func New(mode SyncMode, stateDb ethdb.Database, mux *event.TypeMux, chain BlockC
|
|||
syncStatsState: stateSyncStats{
|
||||
processed: rawdb.ReadFastTrieProgress(stateDb),
|
||||
},
|
||||
SyncedCh: make(chan bool, 1),
|
||||
trackStateReq: make(chan *stateReq),
|
||||
}
|
||||
go dl.qosTuner()
|
||||
|
|
@ -317,6 +319,10 @@ func (d *Downloader) Synchronise(id string, head common.Hash, td *big.Int, mode
|
|||
err := d.synchronise(id, head, td, mode)
|
||||
switch err {
|
||||
case nil:
|
||||
select {
|
||||
case d.SyncedCh <- true:
|
||||
default:
|
||||
}
|
||||
case errBusy:
|
||||
|
||||
case errTimeout, errBadPeer, errStallingPeer,
|
||||
|
|
|
|||
Loading…
Reference in a new issue