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

graphql: return correct logs for tx #25612

Merged
merged 3 commits into from Aug 31, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion graphql/graphql.go
Expand Up @@ -478,8 +478,11 @@ func (t *Transaction) getLogs(ctx context.Context) (*[]*Log, error) {
if err != nil {
return nil, err
}
ret := make([]*Log, 0, len(logs))
ret := make([]*Log, 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ret := make([]*Log, 0)
var ret []*Log

for _, log := range logs {
if uint64(log.TxIndex) != t.index {
continue
Copy link
Contributor

@fjl fjl Aug 27, 2022

Choose a reason for hiding this comment

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

logs is sorted by TxIndex, so this could be improved to skip most iteration:

ix := sort.Search(len(logs), func (i int) bool { return logs[i].TxIndex == t.index })
for ix < len(logs) && logs[ix].TxIndex == t.index {
    ret = append(ret, logs[ix])
    ix++
}

Copy link
Contributor

@fjl fjl Aug 27, 2022

Choose a reason for hiding this comment

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

Also, it's kind of weird to use a filter here. We could just call t.r.backend.GetLogs to get the block logs.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, just realized that the filter is used here exactly because GetLogs doesn't have access to the cache.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I kind of like the simplicity even tho it's slightly less fast, if you don't have a strong feeling about it.

Choose a reason for hiding this comment

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

Fix tested working on my personal node.
Would deploy 1.10.23 + your_fix on prod if no 1.10.24 official version before the merge (currently using 1.10.21 + TTD set in CLI params)

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm slightly in favor of @fjl's suggestion.

}
ret = append(ret, &Log{
r: t.r,
transaction: t,
Expand Down