-
Notifications
You must be signed in to change notification settings - Fork 563
fix: OOM when eth_getLogs response too large #860
Conversation
ef05677
to
ab6b462
Compare
Codecov Report
@@ Coverage Diff @@
## main #860 +/- ##
==========================================
- Coverage 56.61% 56.55% -0.07%
==========================================
Files 72 72
Lines 6066 6076 +10
==========================================
+ Hits 3434 3436 +2
- Misses 2433 2441 +8
Partials 199 199
|
Closes: evmos#858 - add limit to number of logs of filter response - make block limit and log limit configurable
ab6b462
to
b07bb62
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a changelog entry too?
done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix @yihuang. I've added a comment about a potential overflow that could bypass this change and trigger the OOM.
filtered := FilterLogs(ethLog, f.criteria.FromBlock, f.criteria.ToBlock, f.criteria.Addresses, f.criteria.Topics) | ||
logs = append(logs, filtered...) | ||
// check logs limit | ||
if len(logs)+len(filtered) > logLimit { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I still want to trigger an OOM, I can ensure that len(logs) > maxint/2 as well as len(filtered) > maxint/2 which will bypass this check as they'll overflow and become negative in the addition len(logs)+len(filtered). To properly fix this, you mos def want to check arithmetic by subtraction and comparisons individually against len(logs) then len(filtered)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since len(logs) <= logLimit
and len(filtered) <= block gas limit / gas per log
, minimal gas per log is 375, a typical block gas limit is tens of millions, so it's pretty safe even for 32bit int, basically impossible for 64bit int.
* fix: OOM when eth_getLogs response too large Closes: evmos#858 - add limit to number of logs of filter response - make block limit and log limit configurable * return error if exceeds log limit * Apply suggestions from code review * parse from config * read cli flags * add to config template * fix bloomFilter * changelog * add validation Co-authored-by: Federico Kunze Küllmer <[email protected]>
* fix: OOM when eth_getLogs response too large Closes: evmos#858 - add limit to number of logs of filter response - make block limit and log limit configurable * return error if exceeds log limit * Apply suggestions from code review * parse from config * read cli flags * add to config template * fix bloomFilter * changelog * add validation Co-authored-by: Federico Kunze Küllmer <[email protected]> fix lint Update PR url in CHANGELOG
Closes: #858, #861
Description
For contributor use:
docs/
) or specification (x/<module>/spec/
)godoc
comments.Unreleased
section inCHANGELOG.md
Files changed
in the Github PR explorerFor admin use:
WIP
,R4R
,docs
, etc)