eth/filters: change error code for invalid parameter errors (#33320)
Some checks failed
/ Linux Build (push) Has been cancelled
/ Linux Build (arm) (push) Has been cancelled
/ Keeper Build (push) Has been cancelled
/ Windows Build (push) Has been cancelled
/ Docker Image (push) Has been cancelled

This improves the error code for cases where invalid query parameters
are submitted to `eth_getLogs`. I also improved the error message that
is emitted when querying into the future.
This commit is contained in:
Felix Lange 2025-12-04 11:02:42 +01:00 committed by GitHub
parent 657c99f116
commit 73a2df2b0a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 6 deletions

View file

@ -35,17 +35,29 @@ import (
) )
var ( var (
errInvalidTopic = errors.New("invalid topic(s)") errInvalidTopic = invalidParamsErr("invalid topic(s)")
errFilterNotFound = errors.New("filter not found") errInvalidBlockRange = invalidParamsErr("invalid block range params")
errInvalidBlockRange = errors.New("invalid block range params") errBlockRangeIntoFuture = invalidParamsErr("block range extends beyond current head block")
errBlockHashWithRange = invalidParamsErr("can't specify fromBlock/toBlock with blockHash")
errPendingLogsUnsupported = invalidParamsErr("pending logs are not supported")
errUnknownBlock = errors.New("unknown block") errUnknownBlock = errors.New("unknown block")
errBlockHashWithRange = errors.New("can't specify fromBlock/toBlock with blockHash") errFilterNotFound = errors.New("filter not found")
errPendingLogsUnsupported = errors.New("pending logs are not supported")
errExceedMaxTopics = errors.New("exceed max topics") errExceedMaxTopics = errors.New("exceed max topics")
errExceedLogQueryLimit = errors.New("exceed max addresses or topics per search position") errExceedLogQueryLimit = errors.New("exceed max addresses or topics per search position")
errExceedMaxTxHashes = errors.New("exceed max number of transaction hashes allowed per transactionReceipts subscription") errExceedMaxTxHashes = errors.New("exceed max number of transaction hashes allowed per transactionReceipts subscription")
) )
type invalidParamsError struct {
err error
}
func (e invalidParamsError) Error() string { return e.err.Error() }
func (e invalidParamsError) ErrorCode() int { return -32602 }
func invalidParamsErr(format string, args ...any) error {
return invalidParamsError{fmt.Errorf(format, args...)}
}
const ( const (
// The maximum number of topic criteria allowed, vm.LOG4 - vm.LOG0 // The maximum number of topic criteria allowed, vm.LOG4 - vm.LOG0
maxTopics = 4 maxTopics = 4

View file

@ -221,9 +221,12 @@ func (s *searchSession) updateChainView() error {
if lastBlock == math.MaxUint64 { if lastBlock == math.MaxUint64 {
lastBlock = head lastBlock = head
} }
if firstBlock > lastBlock || lastBlock > head { if firstBlock > lastBlock {
return errInvalidBlockRange return errInvalidBlockRange
} }
if lastBlock > head {
return errBlockRangeIntoFuture
}
s.searchRange = common.NewRange(firstBlock, lastBlock+1-firstBlock) s.searchRange = common.NewRange(firstBlock, lastBlock+1-firstBlock)
// Trim existing match set in case a reorg may have invalidated some results // Trim existing match set in case a reorg may have invalidated some results