From 619649d6eaa3cce9b49a84e368836fdda3b14b5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Thu, 28 Sep 2023 13:07:19 +0300 Subject: [PATCH] cmd/utils, eth/catalyst: terminate node wyen synctarget reached --- cmd/utils/flags.go | 4 +++- eth/catalyst/tester.go | 23 +++++++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 372832d30f..9743a7b9ca 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1687,7 +1687,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { log.Debug("Sanitizing Go's GC trigger", "percent", int(gogc)) godebug.SetGCPercent(int(gogc)) - if ctx.IsSet(SyncModeFlag.Name) { + if ctx.IsSet(SyncTargetFlag.Name) { + cfg.SyncMode = downloader.FullSync // dev sync target forces full sync + } else if ctx.IsSet(SyncModeFlag.Name) { cfg.SyncMode = *flags.GlobalTextMarshaler(ctx, SyncModeFlag.Name).(*downloader.SyncMode) } if ctx.IsSet(NetworkIdFlag.Name) { diff --git a/eth/catalyst/tester.go b/eth/catalyst/tester.go index 9ae9ec7fc0..0922ac0ba6 100644 --- a/eth/catalyst/tester.go +++ b/eth/catalyst/tester.go @@ -34,19 +34,21 @@ import ( // This tester can be applied to different networks, no matter it's pre-merge or // post-merge, but only for full-sync. type FullSyncTester struct { - api *ConsensusAPI - target common.Hash - closed chan struct{} - wg sync.WaitGroup + stack *node.Node + backend *eth.Ethereum + target common.Hash + closed chan struct{} + wg sync.WaitGroup } // RegisterFullSyncTester registers the full-sync tester service into the node // stack for launching and stopping the service controlled by node. func RegisterFullSyncTester(stack *node.Node, backend *eth.Ethereum, target common.Hash) (*FullSyncTester, error) { cl := &FullSyncTester{ - api: newConsensusAPIWithoutHeartbeat(backend), - target: target, - closed: make(chan struct{}), + stack: stack, + backend: backend, + target: target, + closed: make(chan struct{}), } stack.RegisterLifecycle(cl) return cl, nil @@ -60,7 +62,7 @@ func (tester *FullSyncTester) Start() error { // Trigger beacon sync with the provided block hash as trusted // chain head. - err := tester.api.eth.Downloader().BeaconDevSync(downloader.FullSync, tester.target, tester.closed) + err := tester.backend.Downloader().BeaconDevSync(downloader.FullSync, tester.target, tester.closed) if err != nil { log.Info("Failed to trigger beacon sync", "err", err) } @@ -72,11 +74,12 @@ func (tester *FullSyncTester) Start() error { select { case <-ticker.C: // Stop in case the target block is already stored locally. - // TODO(somehow terminate the node stack if target is reached). - if block := tester.api.eth.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()) + go tester.stack.Close() // async since we need to close ourselves return } + case <-tester.closed: return }