mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
eth/filters: fast error if len(topics) > 4
Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
parent
470dba8fc1
commit
c5d8bb9772
2 changed files with 10 additions and 0 deletions
|
|
@ -29,6 +29,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/core/vm"
|
||||
"github.com/ethereum/go-ethereum/internal/ethapi"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
)
|
||||
|
|
@ -39,6 +40,9 @@ var (
|
|||
errInvalidBlockRange = errors.New("invalid block range params")
|
||||
)
|
||||
|
||||
// The maximum number of topic criteria allowed
|
||||
const maxTopics = int(vm.LOG4 - vm.LOG0)
|
||||
|
||||
// filter is a helper struct that holds meta information over the filter type
|
||||
// and associated subscription in the event system.
|
||||
type filter struct {
|
||||
|
|
@ -334,6 +338,9 @@ func (api *FilterAPI) NewFilter(crit FilterCriteria) (rpc.ID, error) {
|
|||
|
||||
// GetLogs returns logs matching the given argument that are stored within the state.
|
||||
func (api *FilterAPI) GetLogs(ctx context.Context, crit FilterCriteria) ([]*types.Log, error) {
|
||||
if len(crit.Topics) > maxTopics {
|
||||
return nil, errInvalidTopic
|
||||
}
|
||||
var filter *Filter
|
||||
if crit.BlockHash != nil {
|
||||
// Block filter requested, construct a single-shot filter
|
||||
|
|
|
|||
|
|
@ -299,6 +299,9 @@ func (es *EventSystem) subscribe(sub *subscription) *Subscription {
|
|||
// given criteria to the given logs channel. Default value for the from and to
|
||||
// block is "latest". If the fromBlock > toBlock an error is returned.
|
||||
func (es *EventSystem) SubscribeLogs(crit ethereum.FilterQuery, logs chan []*types.Log) (*Subscription, error) {
|
||||
if len(crit.Topics) > maxTopics {
|
||||
return nil, errInvalidTopic
|
||||
}
|
||||
var from, to rpc.BlockNumber
|
||||
if crit.FromBlock == nil {
|
||||
from = rpc.LatestBlockNumber
|
||||
|
|
|
|||
Loading…
Reference in a new issue