From e5d6f7d9330231998be167b51288aabc15cc6cef Mon Sep 17 00:00:00 2001 From: jsvisa Date: Fri, 20 Jun 2025 19:06:29 +0800 Subject: [PATCH] ethapi: add sanity check Signed-off-by: jsvisa --- internal/ethapi/api.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 8f736226c7..70aa22dafb 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1831,8 +1831,16 @@ func (api *DebugAPI) ChaindbCompact() error { } // 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)) + return nil } // NetAPI offers network related RPC methods