Skip to content

Commit a7aed7b

Browse files
authored
cmd, eth, internal: introduce debug_sync (#32177)
Alternative implementation of #32159
1 parent 0fe1bc0 commit a7aed7b

File tree

7 files changed

+219
-132
lines changed

7 files changed

+219
-132
lines changed

cmd/geth/config.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,14 +262,16 @@ func makeFullNode(ctx *cli.Context) *node.Node {
262262
if cfg.Ethstats.URL != "" {
263263
utils.RegisterEthStatsService(stack, backend, cfg.Ethstats.URL)
264264
}
265-
// Configure full-sync tester service if requested
265+
// Configure synchronization override service
266+
var synctarget common.Hash
266267
if ctx.IsSet(utils.SyncTargetFlag.Name) {
267268
hex := hexutil.MustDecode(ctx.String(utils.SyncTargetFlag.Name))
268269
if len(hex) != common.HashLength {
269270
utils.Fatalf("invalid sync target length: have %d, want %d", len(hex), common.HashLength)
270271
}
271-
utils.RegisterFullSyncTester(stack, eth, common.BytesToHash(hex), ctx.Bool(utils.ExitWhenSyncedFlag.Name))
272+
synctarget = common.BytesToHash(hex)
272273
}
274+
utils.RegisterSyncOverrideService(stack, eth, synctarget, ctx.Bool(utils.ExitWhenSyncedFlag.Name))
273275

274276
if ctx.IsSet(utils.DeveloperFlag.Name) {
275277
// Start dev mode.

cmd/utils/flags.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ import (
4949
"github.com/ethereum/go-ethereum/crypto"
5050
"github.com/ethereum/go-ethereum/crypto/kzg4844"
5151
"github.com/ethereum/go-ethereum/eth"
52-
"github.com/ethereum/go-ethereum/eth/catalyst"
5352
"github.com/ethereum/go-ethereum/eth/ethconfig"
5453
"github.com/ethereum/go-ethereum/eth/filters"
5554
"github.com/ethereum/go-ethereum/eth/gasprice"
55+
"github.com/ethereum/go-ethereum/eth/syncer"
5656
"github.com/ethereum/go-ethereum/eth/tracers"
5757
"github.com/ethereum/go-ethereum/ethdb"
5858
"github.com/ethereum/go-ethereum/ethdb/remotedb"
@@ -1997,10 +1997,14 @@ func RegisterFilterAPI(stack *node.Node, backend ethapi.Backend, ethcfg *ethconf
19971997
return filterSystem
19981998
}
19991999

2000-
// RegisterFullSyncTester adds the full-sync tester service into node.
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)
2000+
// RegisterSyncOverrideService adds the synchronization override service into node.
2001+
func RegisterSyncOverrideService(stack *node.Node, eth *eth.Ethereum, target common.Hash, exitWhenSynced bool) {
2002+
if target != (common.Hash{}) {
2003+
log.Info("Registered sync override service", "hash", target, "exitWhenSynced", exitWhenSynced)
2004+
} else {
2005+
log.Info("Registered sync override service")
2006+
}
2007+
syncer.Register(stack, eth, target, exitWhenSynced)
20042008
}
20052009

20062010
// SetupMetrics configures the metrics system.

eth/catalyst/tester.go

Lines changed: 0 additions & 103 deletions
This file was deleted.

eth/downloader/beacondevsync.go

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package downloader
1818

1919
import (
2020
"errors"
21-
"time"
2221

2322
"github.com/ethereum/go-ethereum/common"
2423
"github.com/ethereum/go-ethereum/core/types"
@@ -34,28 +33,14 @@ import (
3433
// Note, this must not be used in live code. If the forkchcoice endpoint where
3534
// to use this instead of giving us the payload first, then essentially nobody
3635
// in the network would have the block yet that we'd attempt to retrieve.
37-
func (d *Downloader) BeaconDevSync(mode SyncMode, hash common.Hash, stop chan struct{}) error {
36+
func (d *Downloader) BeaconDevSync(mode SyncMode, header *types.Header) error {
3837
// Be very loud that this code should not be used in a live node
3938
log.Warn("----------------------------------")
40-
log.Warn("Beacon syncing with hash as target", "hash", hash)
39+
log.Warn("Beacon syncing with hash as target", "number", header.Number, "hash", header.Hash())
4140
log.Warn("This is unhealthy for a live node!")
41+
log.Warn("This is incompatible with the consensus layer!")
4242
log.Warn("----------------------------------")
43-
44-
log.Info("Waiting for peers to retrieve sync target")
45-
for {
46-
// If the node is going down, unblock
47-
select {
48-
case <-stop:
49-
return errors.New("stop requested")
50-
default:
51-
}
52-
header, err := d.GetHeader(hash)
53-
if err != nil {
54-
time.Sleep(time.Second)
55-
continue
56-
}
57-
return d.BeaconSync(mode, header, header)
58-
}
43+
return d.BeaconSync(mode, header, header)
5944
}
6045

6146
// GetHeader tries to retrieve the header with a given hash from a random peer.

eth/downloader/fetchers.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ func (d *Downloader) fetchHeadersByHash(p *peerConnection, hash common.Hash, amo
4545
defer timeoutTimer.Stop()
4646

4747
select {
48-
case <-d.cancelCh:
49-
return nil, nil, errCanceled
50-
5148
case <-timeoutTimer.C:
5249
// Header retrieval timed out, update the metrics
5350
p.log.Debug("Header request timed out", "elapsed", ttl)

0 commit comments

Comments
 (0)