Skip to content

Commit

Permalink
cmd/utils, eth/catalyst: terminate node wyen synctarget reached
Browse files Browse the repository at this point in the history
  • Loading branch information
karalabe committed Sep 28, 2023
1 parent 48960d7 commit 619649d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
4 changes: 3 additions & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
23 changes: 13 additions & 10 deletions eth/catalyst/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand All @@ -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
}
Expand Down

0 comments on commit 619649d

Please sign in to comment.