-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugfix log range filter #445
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
e22301b
fix how bloom is matched
sideninja 16c936e
test improvement variable
sideninja 0c08329
add randomness to bloom
sideninja 38a35bf
remove todo, not relevant anymore
sideninja 1ca6ee3
change non-standard declaration
sideninja 726d42e
increase total range
sideninja 156fc86
improve range test and add specific height in range test
sideninja 73dc218
change storage interface to use uint64 as height values
sideninja cdb08dc
use uint64 for heights
sideninja 120ef9a
change to uint64 for height in bloom height type
sideninja fd0869e
use uint64 for height in filter
sideninja abd02a2
update usage of uint64 for height
sideninja 5e6b280
don't use big int bytes
sideninja 06168b5
update filter test with uint64 types
sideninja ef0c378
update filter test with uint64 types
sideninja 9516618
update type change to uint64
sideninja 5498a03
make sure response is correctly serialized
sideninja cd5b182
fix filter test with uint64 type change
sideninja 12b6822
use nil return type
sideninja 8443c37
change bloom match logic
sideninja 6a8f471
Add test for single topic and single
sideninja 40d2a43
fix type changes
sideninja d6d0b66
Merge branch 'main' into gregor/log-filter-fix
sideninja bc23583
improve test
sideninja c99767a
Merge remote-tracking branch 'origin/gregor/log-filter-fix' into greg…
sideninja 41ff74b
test typo
sideninja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ package logs | |
import ( | ||
"errors" | ||
"fmt" | ||
"math/big" | ||
|
||
"github.com/onflow/go-ethereum/common" | ||
gethTypes "github.com/onflow/go-ethereum/core/types" | ||
|
@@ -49,32 +48,31 @@ func NewFilterCriteria(addresses []common.Address, topics [][]common.Hash) (*Fil | |
// RangeFilter matches all the indexed logs within the range defined as | ||
// start and end block height. The start must be strictly smaller or equal than end value. | ||
type RangeFilter struct { | ||
start, end *big.Int | ||
start, end uint64 | ||
criteria *FilterCriteria | ||
receipts storage.ReceiptIndexer | ||
} | ||
|
||
func NewRangeFilter( | ||
start, end big.Int, | ||
start, end uint64, | ||
criteria FilterCriteria, | ||
receipts storage.ReceiptIndexer, | ||
) (*RangeFilter, error) { | ||
if len(criteria.Topics) > maxTopics { | ||
return nil, fmt.Errorf("max topics exceeded, only %d allowed", maxTopics) | ||
} | ||
|
||
// check if both start and end don't have special values (negative values representing last block etc.) | ||
// if so, make sure that beginning number is not bigger than end | ||
if start.Cmp(big.NewInt(0)) > 0 && end.Cmp(big.NewInt(0)) > 0 && start.Cmp(&end) > 0 { | ||
// make sure that beginning number is not bigger than end | ||
if start > end { | ||
return nil, errors.Join( | ||
errs.ErrInvalid, | ||
fmt.Errorf("start block number must be smaller or equal to end block number"), | ||
) | ||
} | ||
|
||
return &RangeFilter{ | ||
start: &start, | ||
end: &end, | ||
start: start, | ||
end: end, | ||
criteria: &criteria, | ||
receipts: receipts, | ||
}, nil | ||
|
@@ -86,16 +84,26 @@ func (r *RangeFilter) Match() ([]*gethTypes.Log, error) { | |
return nil, err | ||
} | ||
|
||
logs := make([]*gethTypes.Log, 0) | ||
var bloomHeightMatches []uint64 | ||
var logs []*gethTypes.Log | ||
|
||
// first filter all the logs based on whether a bloom matches, | ||
// if bloom matches we fetch only that height later and do exact match | ||
for _, bloomHeight := range bloomsHeight { | ||
for _, bloom := range bloomHeight.Blooms { | ||
if !bloomMatch(*bloom, r.criteria) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was broken, probably got broken after changes, because it did nothing, so it didn't optimize next step. |
||
continue | ||
if bloomMatch(*bloom, r.criteria) { | ||
bloomHeightMatches = append(bloomHeightMatches, bloomHeight.Height) | ||
// if there's a match we add the height and skip to next height | ||
// even if there would be multiple matches for height we just want to have unique heights | ||
break | ||
} | ||
} | ||
} | ||
|
||
// todo do this concurrently | ||
receipts, err := r.receipts.GetByBlockHeight(bloomHeight.Height) | ||
// do exact matches only on subset of heights in the range that matched the bloom | ||
for _, height := range bloomHeightMatches { | ||
// todo do this concurrently but make sure order is correct | ||
receipts, err := r.receipts.GetByBlockHeight(height) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -147,7 +155,7 @@ func (i *IDFilter) Match() ([]*gethTypes.Log, error) { | |
return nil, err | ||
} | ||
|
||
receipts, err := i.receipts.GetByBlockHeight(big.NewInt(int64(blk.Height))) | ||
receipts, err := i.receipts.GetByBlockHeight(blk.Height) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this todo is not really true since we store blooms in storage