Skip to content

Commit

Permalink
Enforce max block range of 10k blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
jdowning100 committed Dec 10, 2024
1 parent 9f6d6bc commit cac6151
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions quai/filters/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (

const (
c_pendingHeaderChSize = 20
MaxFilterRange = 10000
)

// filter is a helper struct that holds meta information over the filter type
Expand Down Expand Up @@ -535,6 +536,11 @@ func (api *PublicFilterAPI) GetLogs(ctx context.Context, crit FilterCriteria) ([
if crit.ToBlock != nil {
end = crit.ToBlock.Int64()
}
if begin > end {
return nil, errors.New("fromBlock must be less than or equal to toBlock")
} else if end-begin > MaxFilterRange {
return nil, fmt.Errorf("filter range must be less than or equal to %d", MaxFilterRange)
}
// Construct the range filter
filter = NewRangeFilter(api.backend, begin, end, addresses, crit.Topics, api.backend.Logger())
}
Expand Down
5 changes: 5 additions & 0 deletions quai/filters/filter_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ func (es *EventSystem) SubscribeLogs(crit quai.FilterQuery, logs chan []*types.L
to = rpc.BlockNumber(crit.ToBlock.Int64())
}

// Enforce max range of 10,000 blocks
if from >= 0 && to >= 0 && to > from && to-from > MaxFilterRange {
return nil, fmt.Errorf("invalid from and to block combination: block range > %d", MaxFilterRange)
}

// only interested in pending logs
if from == rpc.PendingBlockNumber && to == rpc.PendingBlockNumber {
return es.subscribePendingLogs(crit, logs), nil
Expand Down

0 comments on commit cac6151

Please sign in to comment.