-
Notifications
You must be signed in to change notification settings - Fork 20.9k
feat: add debug.setSyncTarget console command (#31375) #31665
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,8 @@ import ( | |
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/core/vm" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
"github.com/ethereum/go-ethereum/eth/downloader" | ||
"github.com/ethereum/go-ethereum/eth/ethconfig" | ||
"github.com/ethereum/go-ethereum/eth/gasestimator" | ||
"github.com/ethereum/go-ethereum/eth/tracers/logger" | ||
"github.com/ethereum/go-ethereum/internal/ethapi/override" | ||
|
@@ -1701,11 +1703,45 @@ type DebugAPI struct { | |
b Backend | ||
} | ||
|
||
// NewDebugAPI creates a new instance of DebugAPI. | ||
// NewDebugAPI creates a new DebugAPI instance. | ||
func NewDebugAPI(b Backend) *DebugAPI { | ||
return &DebugAPI{b: b} | ||
} | ||
|
||
// SetSyncTarget manually sets the target hash for full sync. | ||
// This is primarily intended for debugging and testing purposes, allowing | ||
// simulation of syncing to specific forks or targets without restarting the node. | ||
func (api *DebugAPI) SetSyncTarget(ctx context.Context, target common.Hash) error { | ||
// Note: BeaconDevSync might block; running in a goroutine to avoid blocking RPC/console. | ||
// Also, passing nil for the cancel channel as we don't provide a way to cancel via API. | ||
type Downloader interface { | ||
Downloader() *downloader.Downloader | ||
} | ||
backend, ok := api.b.(Downloader) | ||
if !ok { | ||
log.Error("Could not get downloader") | ||
} | ||
// retry 20 times to retrieve the header from random peers | ||
for range 20 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a big fan of this tbh, open for suggestions here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need the complete change here, please do let me know I am more than happy to work on it, Thanks for the reply . |
||
header, err := backend.Downloader().GetHeader(target) | ||
if err != nil { | ||
continue | ||
} | ||
if err := backend.Downloader().BeaconSync(ethconfig.FullSync, header, header); err != nil { | ||
return err | ||
} else { | ||
// Sync target set successfully, return | ||
return nil | ||
} | ||
} | ||
return errors.New("could not set sync target") | ||
} | ||
|
||
// ChainConfig returns the active chain configuration. | ||
func (api *DebugAPI) ChainConfig() *params.ChainConfig { | ||
return api.b.ChainConfig() | ||
} | ||
|
||
// GetRawHeader retrieves the RLP encoding for a single header. | ||
func (api *DebugAPI) GetRawHeader(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (hexutil.Bytes, error) { | ||
var hash common.Hash | ||
|
Uh oh!
There was an error while loading. Please reload this page.