Skip to content

Commit c523bc4

Browse files
rjl493456442howjmay
authored andcommitted
cmd, eth/catalyst: exit geth only if exitWhenSynced is specified (ethereum#32149)
This pull request modifies the behavior of `--synctarget` to terminate the node only when `--exitWhenSynced` is explicitly specified.
1 parent 7e83450 commit c523bc4

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

cmd/geth/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ func makeFullNode(ctx *cli.Context) *node.Node {
268268
if len(hex) != common.HashLength {
269269
utils.Fatalf("invalid sync target length: have %d, want %d", len(hex), common.HashLength)
270270
}
271-
utils.RegisterFullSyncTester(stack, eth, common.BytesToHash(hex))
271+
utils.RegisterFullSyncTester(stack, eth, common.BytesToHash(hex), ctx.Bool(utils.ExitWhenSyncedFlag.Name))
272272
}
273273

274274
if ctx.IsSet(utils.DeveloperFlag.Name) {

cmd/utils/flags.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,9 +1998,9 @@ func RegisterFilterAPI(stack *node.Node, backend ethapi.Backend, ethcfg *ethconf
19981998
}
19991999

20002000
// RegisterFullSyncTester adds the full-sync tester service into node.
2001-
func RegisterFullSyncTester(stack *node.Node, eth *eth.Ethereum, target common.Hash) {
2002-
catalyst.RegisterFullSyncTester(stack, eth, target)
2003-
log.Info("Registered full-sync tester", "hash", target)
2001+
func RegisterFullSyncTester(stack *node.Node, eth *eth.Ethereum, target common.Hash, exitWhenSynced bool) {
2002+
catalyst.RegisterFullSyncTester(stack, eth, target, exitWhenSynced)
2003+
log.Info("Registered full-sync tester", "hash", target, "exitWhenSynced", exitWhenSynced)
20042004
}
20052005

20062006
// SetupMetrics configures the metrics system.

eth/catalyst/tester.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,23 @@ import (
3434
// This tester can be applied to different networks, no matter it's pre-merge or
3535
// post-merge, but only for full-sync.
3636
type FullSyncTester struct {
37-
stack *node.Node
38-
backend *eth.Ethereum
39-
target common.Hash
40-
closed chan struct{}
41-
wg sync.WaitGroup
37+
stack *node.Node
38+
backend *eth.Ethereum
39+
target common.Hash
40+
closed chan struct{}
41+
wg sync.WaitGroup
42+
exitWhenSynced bool
4243
}
4344

4445
// RegisterFullSyncTester registers the full-sync tester service into the node
4546
// stack for launching and stopping the service controlled by node.
46-
func RegisterFullSyncTester(stack *node.Node, backend *eth.Ethereum, target common.Hash) (*FullSyncTester, error) {
47+
func RegisterFullSyncTester(stack *node.Node, backend *eth.Ethereum, target common.Hash, exitWhenSynced bool) (*FullSyncTester, error) {
4748
cl := &FullSyncTester{
48-
stack: stack,
49-
backend: backend,
50-
target: target,
51-
closed: make(chan struct{}),
49+
stack: stack,
50+
backend: backend,
51+
target: target,
52+
closed: make(chan struct{}),
53+
exitWhenSynced: exitWhenSynced,
5254
}
5355
stack.RegisterLifecycle(cl)
5456
return cl, nil
@@ -76,7 +78,11 @@ func (tester *FullSyncTester) Start() error {
7678
// Stop in case the target block is already stored locally.
7779
if block := tester.backend.BlockChain().GetBlockByHash(tester.target); block != nil {
7880
log.Info("Full-sync target reached", "number", block.NumberU64(), "hash", block.Hash())
79-
go tester.stack.Close() // async since we need to close ourselves
81+
82+
if tester.exitWhenSynced {
83+
go tester.stack.Close() // async since we need to close ourselves
84+
log.Info("Terminating the node")
85+
}
8086
return
8187
}
8288

0 commit comments

Comments
 (0)