Skip to content
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

[Indexer] Implement log providers and filters #33

Merged
merged 44 commits into from
Feb 27, 2024

Conversation

sideninja
Copy link
Contributor

@sideninja sideninja commented Jan 30, 2024

Closes: #28

Description

This PR implements logs filters. This will be used to implement log filtering based on addresses and topics and will allow for multiple sources either logs indexed in the storage and being queried by block height range, or by subscribing to new stream of logs directly from the network.

There are three log filters:

  • Range filter: filters logs from block range identified by start and end height
  • ID filter: filter logs from a single block
  • Stream filter: filters logs from the event stream of receipts

All the filters reuse the same filter criteria which defines the Addresses and Topics.

The filters are fetched from two different sources:

  • Storage provider: is the storage log provider that contains historic indexed logs and can be queried by height range,
  • Stream provider: is log provider that gets logs directly from the stream and is pushed to subscribers

Providers use bloom filters to determine if a log is relevant or not in order to optimize loading all the data.

The implementation follows the design:

Screenshot 2024-01-31 at 15 23 36


For contributor use:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the standards mentioned here.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

@sideninja sideninja changed the base branch from main to gregor/index/storage-base January 30, 2024 16:16
@sideninja sideninja changed the base branch from gregor/index/storage-base to gregor/index/storage-index January 30, 2024 16:19
@sideninja sideninja self-assigned this Jan 30, 2024
@sideninja sideninja marked this pull request as ready for review January 31, 2024 17:27
@sideninja sideninja requested a review from m-Peter January 31, 2024 17:27
Copy link
Collaborator

@m-Peter m-Peter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! 🚀 Just a couple minor comments.

Copy link
Contributor

@ramtinms ramtinms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🪄

services/logs/filter.go Outdated Show resolved Hide resolved
gethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/onflow/flow-evm-gateway/storage"
"math/big"
"slices"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"slices"
"golang.org/x/exp/slices"

Copy link
Contributor

@peterargue peterargue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good. mostly small comments.

Comment on lines +4 to +8
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/onflow/cadence"
cdcCommon "github.com/onflow/cadence/runtime/common"
"github.com/onflow/flow-go/fvm/evm/types"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: split stdlib and external imports (here and elsewhere)

Suggested change
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/onflow/cadence"
cdcCommon "github.com/onflow/cadence/runtime/common"
"github.com/onflow/flow-go/fvm/evm/types"
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/onflow/cadence"
cdcCommon "github.com/onflow/cadence/runtime/common"
"github.com/onflow/flow-go/fvm/evm/types"

}

receipt := &gethTypes.Receipt{
Type: 0, // todo check
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

were you planning to address these todos in this PR or a future one? is there an issue tracking them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#87

services/logs/filter.go Outdated Show resolved Hide resolved
services/logs/filter.go Outdated Show resolved Hide resolved
}
}

func (s *StreamFilter) Match() (chan *gethTypes.Log, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

best to only return the channel receiver, otherwise it could be written to or closed

Suggested change
func (s *StreamFilter) Match() (chan *gethTypes.Log, error) {
func (s *StreamFilter) Match() (<-chan *gethTypes.Log, error) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point

defer close(logs)

for {
select {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need this select since there's only one condition

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol habit

services/logs/filter.go Outdated Show resolved Hide resolved

// exactMatch checks the topic and address values of the log match the filer exactly.
func exactMatch(log *gethTypes.Log, criteria FilterCriteria) bool {
if len(criteria.Topics) > len(log.Topics) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be?

Suggested change
if len(criteria.Topics) > len(log.Topics) {
if len(criteria.Topics) != len(log.Topics) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't because the criteria can have less topics than the log, in case where topics are wildcards.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a comment

@sideninja sideninja merged commit 500cb9f into gregor/index/storage-index Feb 27, 2024
@m-Peter m-Peter deleted the gregor/index/storage-filter branch March 8, 2024 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

Implement querying events by topic
5 participants