diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 3b699748b8..b49c22eed8 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -38,6 +38,7 @@ 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/ethconfig" "github.com/ethereum/go-ethereum/eth/gasestimator" "github.com/ethereum/go-ethereum/eth/tracers/logger" "github.com/ethereum/go-ethereum/internal/ethapi/override" @@ -1699,11 +1700,43 @@ func (api *TransactionAPI) Resend(ctx context.Context, sendArgs TransactionArgs, // namespace. type DebugAPI struct { b Backend + // contains filtered or unexported fields } -// NewDebugAPI creates a new instance of DebugAPI. +// NewDebugAPI creates a new DebugAPI instance. func NewDebugAPI(b Backend) *DebugAPI { - return &DebugAPI{b: b} + // Fill defaults based on the chain config + var gasLimit uint64 + if head := b.CurrentBlock(); head != nil { + gasLimit = head.GasLimit + } + // The geth console doesn't allow flags, so we depend on the configured backend. + return &DebugAPI{ + b: b, + defaultCallGas: gasLimit, + } +} + +// 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. + go func() { + err := api.b.Downloader().BeaconDevSync(ethconfig.FullSync, target, nil) + if err != nil { + log.Warn("debug_setSyncTarget: BeaconDevSync failed", "target", target, "err", err) + } else { + log.Info("debug_setSyncTarget: BeaconDevSync initiated", "target", target) + } + }() + return nil // API call returns immediately +} + +// 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. diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index 8ac8f44958..8dd29855e0 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -217,6 +217,11 @@ web3._extend({ call: 'debug_setHead', params: 1 }), + new web3._extend.Method({ + name: 'setSyncTarget', + call: 'debug_setSyncTarget', + params: 1 + }), new web3._extend.Method({ name: 'seedHash', call: 'debug_seedHash',