-
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
Streaming of logs #177
Merged
devbugging
merged 20 commits into
gregor/stream/transactions-broadcast
from
gregor/stream/logs-broadcast
Apr 4, 2024
Merged
Streaming of logs #177
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
3b0e184
add log broadcast
e89d81a
add logs stream
6460f2e
update api change
f899e46
add log stream test
1f3f0fc
update stream response type
16f0f4f
typo fix
1d26911
logs wip
5dba16f
use background context
8f8ca53
fix if nil
a878628
fix test api change
16f198d
add wildcard test
9d1bedb
refactor tests to use models
e473f5e
convert to correct type
b933bab
improve helpers
9372a42
check value of topic
7dfc13d
fix one off height
4a8242f
add test for specific topic subs
cad767e
Merge branch 'gregor/stream/transactions-broadcast' into gregor/strea…
92966ce
merge update
4eda15d
limit addresses and topics
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ import ( | |
"context" | ||
"errors" | ||
"fmt" | ||
"github.com/ethereum/go-ethereum/eth/filters" | ||
"github.com/onflow/flow-evm-gateway/services/logs" | ||
|
||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
"github.com/ethereum/go-ethereum/rpc" | ||
|
@@ -29,6 +31,7 @@ type StreamAPI struct { | |
receipts storage.ReceiptIndexer | ||
blocksBroadcaster *engine.Broadcaster | ||
transactionsBroadcaster *engine.Broadcaster | ||
logsBroadcaster *engine.Broadcaster | ||
} | ||
|
||
func NewStreamAPI( | ||
|
@@ -37,19 +40,19 @@ func NewStreamAPI( | |
blocks storage.BlockIndexer, | ||
transactions storage.TransactionIndexer, | ||
receipts storage.ReceiptIndexer, | ||
accounts storage.AccountIndexer, | ||
blocksBroadcaster *engine.Broadcaster, | ||
transactionsBroadcaster *engine.Broadcaster, | ||
logsBroadcaster *engine.Broadcaster, | ||
) *StreamAPI { | ||
return &StreamAPI{ | ||
logger: logger, | ||
config: config, | ||
blocks: blocks, | ||
transactions: transactions, | ||
receipts: receipts, | ||
accounts: accounts, | ||
blocksBroadcaster: blocksBroadcaster, | ||
transactionsBroadcaster: transactionsBroadcaster, | ||
logsBroadcaster: logsBroadcaster, | ||
} | ||
} | ||
|
||
|
@@ -85,7 +88,7 @@ func (s *StreamAPI) newSubscription( | |
s.config.StreamTimeout, | ||
s.config.StreamLimit, | ||
sub, | ||
).Stream(context.Background()) | ||
).Stream(context.Background()) // todo investigate why the passed in context is canceled so quickly | ||
|
||
go func() { | ||
for { | ||
|
@@ -177,3 +180,36 @@ func (s *StreamAPI) NewPendingTransactions(ctx context.Context, fullTx *bool) (* | |
}, | ||
) | ||
} | ||
|
||
// Logs creates a subscription that fires for all new log that match the given filter criteria. | ||
func (s *StreamAPI) Logs(ctx context.Context, criteria filters.FilterCriteria) (*rpc.Subscription, error) { | ||
if len(criteria.Topics) > maxTopics { | ||
return nil, errExceedMaxTopics | ||
} | ||
if len(criteria.Addresses) > maxAddresses { | ||
return nil, errExceedMaxAddresses | ||
} | ||
|
||
return s.newSubscription( | ||
ctx, | ||
s.logsBroadcaster, | ||
func(ctx context.Context, height uint64) (interface{}, error) { | ||
block, err := s.blocks.GetByHeight(height) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get block at height: %d: %w", height, err) | ||
} | ||
|
||
id, err := block.Hash() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// convert from the API type | ||
f := logs.FilterCriteria{ | ||
Addresses: criteria.Addresses, | ||
Topics: criteria.Topics, | ||
Comment on lines
+209
to
+210
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. do we need to validate these or is that already done by go-ethereum? |
||
} | ||
return logs.NewIDFilter(id, f, s.blocks, s.receipts).Match() | ||
}, | ||
) | ||
} |
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.
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.
Is this happening during the E2E tests? Or even in local environment?
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.
During tests yeah, didn't yet test otherwise. I'm not sure how the timeout is defined for tests, it might be that we fix the requests.