-
Notifications
You must be signed in to change notification settings - Fork 13
Check data integrity for EVM events #529
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
Changes from all commits
1f60169
67855f0
75361ce
9666919
2be3802
8d6f49f
f0d4880
6ff9cb5
2b1ee91
76d544c
3c9ead3
deac76b
8f23141
89d918e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -146,7 +146,19 @@ func (r *RPCSubscriber) subscribe(ctx context.Context, height uint64, opts ...ac | |
| return | ||
| } | ||
|
|
||
| events <- models.NewBlockEvents(blockEvents) | ||
| evts := models.NewBlockEvents(blockEvents) | ||
| if evts.Err != nil { | ||
|
Contributor
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. we should test this in the subscriber_test I think ti shouldn't be hard |
||
| r.logger.Warn().Err(err).Msgf( | ||
| "failed to parse EVM block events for Flow height: %d, retrying with gRPC API...", | ||
| blockEvents.Height, | ||
| ) | ||
| // call the `GetEventsForHeightRange` gRPC API endpoint to fetch | ||
| // the EVM-related events, when event streaming returned an | ||
| // inconsistent response. | ||
| events <- r.fetchBlockEvents(ctx, blockEvents) | ||
|
Contributor
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. add a commnet something like:
Collaborator
Author
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. Added in 76d544c |
||
| } else { | ||
| events <- models.NewBlockEvents(blockEvents) | ||
| } | ||
|
|
||
| case err, ok := <-errChan: | ||
| if !ok { | ||
|
|
@@ -252,3 +264,46 @@ func (r *RPCSubscriber) blocksFilter() flow.EventFilter { | |
| }, | ||
| } | ||
| } | ||
|
|
||
| // fetchBlockEvents is used as a backup mechanism for fetching EVM-related | ||
| // events, when the event streaming API returns an inconsistent response. | ||
| // An inconsistent response could be an EVM block that references EVM | ||
| // transactions which are not present in the response. | ||
| // Under the hood, it uses the `GetEventsForHeightRange` gRPC API endpoint, | ||
| // making sure that we receive the expected events length for each event type | ||
| // and Flow height. | ||
| func (r *RPCSubscriber) fetchBlockEvents( | ||
|
Contributor
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. add a comment explaining what this function does and how it is used for backup
Collaborator
Author
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. Good point 👍 |
||
| ctx context.Context, | ||
| blockEvents flow.BlockEvents, | ||
| ) models.BlockEvents { | ||
| blkEvents := flow.BlockEvents{ | ||
| BlockID: blockEvents.BlockID, | ||
| Height: blockEvents.Height, | ||
| BlockTimestamp: blockEvents.BlockTimestamp, | ||
| } | ||
| for _, eventType := range r.blocksFilter().EventTypes { | ||
| recoveredEvents, err := r.client.GetEventsForHeightRange( | ||
| ctx, | ||
| eventType, | ||
| blockEvents.Height, | ||
| blockEvents.Height, | ||
| ) | ||
| if err != nil { | ||
| return models.NewBlockEventsError(err) | ||
| } | ||
|
|
||
| if len(recoveredEvents) != 1 { | ||
| return models.NewBlockEventsError( | ||
| fmt.Errorf( | ||
| "received %d but expected 1 event for height %d", | ||
| len(recoveredEvents), | ||
| blockEvents.Height, | ||
| ), | ||
| ) | ||
| } | ||
|
|
||
| blkEvents.Events = append(blkEvents.Events, recoveredEvents[0].Events...) | ||
| } | ||
|
|
||
| return models.NewBlockEvents(blkEvents) | ||
| } | ||
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.