mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-02-26 07:37:20 +00:00
eth/filters: change error code for invalid parameter errors (#33320)
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:
parent
657c99f116
commit
73a2df2b0a
2 changed files with 21 additions and 6 deletions
|
|
@ -35,17 +35,29 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
errInvalidTopic = errors.New("invalid topic(s)")
|
||||
errFilterNotFound = errors.New("filter not found")
|
||||
errInvalidBlockRange = errors.New("invalid block range params")
|
||||
errInvalidTopic = invalidParamsErr("invalid topic(s)")
|
||||
errInvalidBlockRange = invalidParamsErr("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")
|
||||
errBlockHashWithRange = errors.New("can't specify fromBlock/toBlock with blockHash")
|
||||
errPendingLogsUnsupported = errors.New("pending logs are not supported")
|
||||
errFilterNotFound = errors.New("filter not found")
|
||||
errExceedMaxTopics = errors.New("exceed max topics")
|
||||
errExceedLogQueryLimit = errors.New("exceed max addresses or topics per search position")
|
||||
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 (
|
||||
// The maximum number of topic criteria allowed, vm.LOG4 - vm.LOG0
|
||||
maxTopics = 4
|
||||
|
|
|
|||
|
|
@ -221,9 +221,12 @@ func (s *searchSession) updateChainView() error {
|
|||
if lastBlock == math.MaxUint64 {
|
||||
lastBlock = head
|
||||
}
|
||||
if firstBlock > lastBlock || lastBlock > head {
|
||||
if firstBlock > lastBlock {
|
||||
return errInvalidBlockRange
|
||||
}
|
||||
if lastBlock > head {
|
||||
return errBlockRangeIntoFuture
|
||||
}
|
||||
s.searchRange = common.NewRange(firstBlock, lastBlock+1-firstBlock)
|
||||
|
||||
// Trim existing match set in case a reorg may have invalidated some results
|
||||
|
|
|
|||
Loading…
Reference in a new issue