Skip to content

eth: add debug_syncTarget API #32126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions eth/api_debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/internal/ethapi"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"
Expand Down Expand Up @@ -443,3 +444,25 @@ func (api *DebugAPI) GetTrieFlushInterval() (string, error) {
}
return api.eth.blockchain.GetTrieFlushInterval().String(), nil
}

// SyncTarget sets the sync target for the downloader to a specific block hash.
func (api *DebugAPI) SyncTarget(target common.Hash) error {
if header := api.eth.BlockChain().GetHeaderByHash(target); header != nil {
return errors.New("sync target is already known in the chain")
}

dl := api.eth.Downloader()
header, err := dl.GetHeader(target)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to retry a bit if this fails.

if err != nil {
return fmt.Errorf("failed to retrieve header for target %s: %w", target, err)
}

// Trigger beacon sync with the new target
err = dl.BeaconSync(ethconfig.FullSync, header, header)
if err != nil {
return fmt.Errorf("failed to start beacon sync to target %s: %w", target, err)
}

log.Info("BeaconSync set target to", "target", target, "number", header.Number)
return nil
}
5 changes: 5 additions & 0 deletions internal/web3ext/web3ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ web3._extend({
call: 'debug_setHead',
params: 1
}),
new web3._extend.Method({
name: 'syncTarget',
call: 'debug_syncTarget',
params: 1
}),
new web3._extend.Method({
name: 'seedHash',
call: 'debug_seedHash',
Expand Down