ethapi: add sanity check

Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
jsvisa 2025-06-20 19:06:29 +08:00
parent 35dd61a3bf
commit e5d6f7d933

View file

@ -1831,8 +1831,16 @@ func (api *DebugAPI) ChaindbCompact() error {
} }
// SetHead rewinds the head of the blockchain to a previous block. // SetHead rewinds the head of the blockchain to a previous block.
func (api *DebugAPI) SetHead(number hexutil.Uint64) { func (api *DebugAPI) SetHead(number hexutil.Uint64) error {
header := api.b.CurrentHeader()
if header == nil {
return errors.New("current header is not available")
}
if header.Number.Uint64() <= uint64(number) {
return errors.New("not allowed to rewind to a later block")
}
api.b.SetHead(uint64(number)) api.b.SetHead(uint64(number))
return nil
} }
// NetAPI offers network related RPC methods // NetAPI offers network related RPC methods