mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-14 12:06:40 +00:00
cmd, eth/catalyst: exit geth only if exitWhenSynced is specified (#32149)
This pull request modifies the behavior of `--synctarget` to terminate the node only when `--exitWhenSynced` is explicitly specified.
This commit is contained in:
parent
b3131f00a3
commit
e71487b033
3 changed files with 21 additions and 15 deletions
|
|
@ -268,7 +268,7 @@ func makeFullNode(ctx *cli.Context) *node.Node {
|
||||||
if len(hex) != common.HashLength {
|
if len(hex) != common.HashLength {
|
||||||
utils.Fatalf("invalid sync target length: have %d, want %d", len(hex), common.HashLength)
|
utils.Fatalf("invalid sync target length: have %d, want %d", len(hex), common.HashLength)
|
||||||
}
|
}
|
||||||
utils.RegisterFullSyncTester(stack, eth, common.BytesToHash(hex))
|
utils.RegisterFullSyncTester(stack, eth, common.BytesToHash(hex), ctx.Bool(utils.ExitWhenSyncedFlag.Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.IsSet(utils.DeveloperFlag.Name) {
|
if ctx.IsSet(utils.DeveloperFlag.Name) {
|
||||||
|
|
|
||||||
|
|
@ -1998,9 +1998,9 @@ func RegisterFilterAPI(stack *node.Node, backend ethapi.Backend, ethcfg *ethconf
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterFullSyncTester adds the full-sync tester service into node.
|
// RegisterFullSyncTester adds the full-sync tester service into node.
|
||||||
func RegisterFullSyncTester(stack *node.Node, eth *eth.Ethereum, target common.Hash) {
|
func RegisterFullSyncTester(stack *node.Node, eth *eth.Ethereum, target common.Hash, exitWhenSynced bool) {
|
||||||
catalyst.RegisterFullSyncTester(stack, eth, target)
|
catalyst.RegisterFullSyncTester(stack, eth, target, exitWhenSynced)
|
||||||
log.Info("Registered full-sync tester", "hash", target)
|
log.Info("Registered full-sync tester", "hash", target, "exitWhenSynced", exitWhenSynced)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetupMetrics configures the metrics system.
|
// SetupMetrics configures the metrics system.
|
||||||
|
|
|
||||||
|
|
@ -34,21 +34,23 @@ import (
|
||||||
// This tester can be applied to different networks, no matter it's pre-merge or
|
// This tester can be applied to different networks, no matter it's pre-merge or
|
||||||
// post-merge, but only for full-sync.
|
// post-merge, but only for full-sync.
|
||||||
type FullSyncTester struct {
|
type FullSyncTester struct {
|
||||||
stack *node.Node
|
stack *node.Node
|
||||||
backend *eth.Ethereum
|
backend *eth.Ethereum
|
||||||
target common.Hash
|
target common.Hash
|
||||||
closed chan struct{}
|
closed chan struct{}
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
|
exitWhenSynced bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterFullSyncTester registers the full-sync tester service into the node
|
// RegisterFullSyncTester registers the full-sync tester service into the node
|
||||||
// stack for launching and stopping the service controlled by node.
|
// stack for launching and stopping the service controlled by node.
|
||||||
func RegisterFullSyncTester(stack *node.Node, backend *eth.Ethereum, target common.Hash) (*FullSyncTester, error) {
|
func RegisterFullSyncTester(stack *node.Node, backend *eth.Ethereum, target common.Hash, exitWhenSynced bool) (*FullSyncTester, error) {
|
||||||
cl := &FullSyncTester{
|
cl := &FullSyncTester{
|
||||||
stack: stack,
|
stack: stack,
|
||||||
backend: backend,
|
backend: backend,
|
||||||
target: target,
|
target: target,
|
||||||
closed: make(chan struct{}),
|
closed: make(chan struct{}),
|
||||||
|
exitWhenSynced: exitWhenSynced,
|
||||||
}
|
}
|
||||||
stack.RegisterLifecycle(cl)
|
stack.RegisterLifecycle(cl)
|
||||||
return cl, nil
|
return cl, nil
|
||||||
|
|
@ -76,7 +78,11 @@ func (tester *FullSyncTester) Start() error {
|
||||||
// Stop in case the target block is already stored locally.
|
// Stop in case the target block is already stored locally.
|
||||||
if block := tester.backend.BlockChain().GetBlockByHash(tester.target); block != nil {
|
if block := tester.backend.BlockChain().GetBlockByHash(tester.target); block != nil {
|
||||||
log.Info("Full-sync target reached", "number", block.NumberU64(), "hash", block.Hash())
|
log.Info("Full-sync target reached", "number", block.NumberU64(), "hash", block.Hash())
|
||||||
go tester.stack.Close() // async since we need to close ourselves
|
|
||||||
|
if tester.exitWhenSynced {
|
||||||
|
go tester.stack.Close() // async since we need to close ourselves
|
||||||
|
log.Info("Terminating the node")
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue