mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 21:56:43 +00:00
eth: add debug_syncTarget API
This commit is contained in:
parent
7c180f851c
commit
d2b6ce3801
2 changed files with 28 additions and 0 deletions
|
|
@ -28,6 +28,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/state"
|
"github.com/ethereum/go-ethereum/core/state"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"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/internal/ethapi"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
|
|
@ -443,3 +444,25 @@ func (api *DebugAPI) GetTrieFlushInterval() (string, error) {
|
||||||
}
|
}
|
||||||
return api.eth.blockchain.GetTrieFlushInterval().String(), nil
|
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)
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -217,6 +217,11 @@ web3._extend({
|
||||||
call: 'debug_setHead',
|
call: 'debug_setHead',
|
||||||
params: 1
|
params: 1
|
||||||
}),
|
}),
|
||||||
|
new web3._extend.Method({
|
||||||
|
name: 'syncTarget',
|
||||||
|
call: 'debug_syncTarget',
|
||||||
|
params: 1
|
||||||
|
}),
|
||||||
new web3._extend.Method({
|
new web3._extend.Method({
|
||||||
name: 'seedHash',
|
name: 'seedHash',
|
||||||
call: 'debug_seedHash',
|
call: 'debug_seedHash',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue