cmd/utils, eth/catalyst: terminate node wyen synctarget reached

This commit is contained in:
Péter Szilágyi 2023-09-28 13:07:19 +03:00
parent 48960d784b
commit 619649d6ea
2 changed files with 16 additions and 11 deletions

View file

@ -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)) log.Debug("Sanitizing Go's GC trigger", "percent", int(gogc))
godebug.SetGCPercent(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) cfg.SyncMode = *flags.GlobalTextMarshaler(ctx, SyncModeFlag.Name).(*downloader.SyncMode)
} }
if ctx.IsSet(NetworkIdFlag.Name) { if ctx.IsSet(NetworkIdFlag.Name) {

View file

@ -34,19 +34,21 @@ 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 {
api *ConsensusAPI stack *node.Node
target common.Hash backend *eth.Ethereum
closed chan struct{} target common.Hash
wg sync.WaitGroup closed chan struct{}
wg sync.WaitGroup
} }
// 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) (*FullSyncTester, error) {
cl := &FullSyncTester{ cl := &FullSyncTester{
api: newConsensusAPIWithoutHeartbeat(backend), stack: stack,
target: target, backend: backend,
closed: make(chan struct{}), target: target,
closed: make(chan struct{}),
} }
stack.RegisterLifecycle(cl) stack.RegisterLifecycle(cl)
return cl, nil return cl, nil
@ -60,7 +62,7 @@ func (tester *FullSyncTester) Start() error {
// Trigger beacon sync with the provided block hash as trusted // Trigger beacon sync with the provided block hash as trusted
// chain head. // 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 { if err != nil {
log.Info("Failed to trigger beacon sync", "err", err) log.Info("Failed to trigger beacon sync", "err", err)
} }
@ -72,11 +74,12 @@ func (tester *FullSyncTester) Start() error {
select { select {
case <-ticker.C: case <-ticker.C:
// Stop in case the target block is already stored locally. // Stop in case the target block is already stored locally.
// TODO(somehow terminate the node stack if target is reached). if block := tester.backend.BlockChain().GetBlockByHash(tester.target); block != nil {
if block := tester.api.eth.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
return return
} }
case <-tester.closed: case <-tester.closed:
return return
} }