From 1daa013b4e22a13ac283813cf92c40dec352f2d9 Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi Date: Fri, 26 Aug 2022 16:26:07 +0200 Subject: [PATCH 1/3] graphql: fix tx logs --- graphql/graphql.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/graphql/graphql.go b/graphql/graphql.go index 97b460c205ce..f85424f8d565 100644 --- a/graphql/graphql.go +++ b/graphql/graphql.go @@ -478,13 +478,15 @@ 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) for _, log := range logs { - ret = append(ret, &Log{ - r: t.r, - transaction: t, - log: log, - }) + if uint64(log.TxIndex) == t.index { + ret = append(ret, &Log{ + r: t.r, + transaction: t, + log: log, + }) + } } return &ret, nil } From 108da0e5a667e962eba495fc3775c33e1747eb5c Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi Date: Fri, 26 Aug 2022 16:30:58 +0200 Subject: [PATCH 2/3] minor --- graphql/graphql.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/graphql/graphql.go b/graphql/graphql.go index f85424f8d565..611f263def1a 100644 --- a/graphql/graphql.go +++ b/graphql/graphql.go @@ -480,13 +480,14 @@ func (t *Transaction) getLogs(ctx context.Context) (*[]*Log, error) { } ret := make([]*Log, 0) for _, log := range logs { - if uint64(log.TxIndex) == t.index { - ret = append(ret, &Log{ - r: t.r, - transaction: t, - log: log, - }) + if uint64(log.TxIndex) != t.index { + continue } + ret = append(ret, &Log{ + r: t.r, + transaction: t, + log: log, + }) } return &ret, nil } From 6a329681ff7d09b8c04803e861e8189c37067bde Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi Date: Wed, 31 Aug 2022 12:41:20 +0200 Subject: [PATCH 3/3] Use optimized search for selecting tx logs --- graphql/graphql.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/graphql/graphql.go b/graphql/graphql.go index 611f263def1a..66c25841db98 100644 --- a/graphql/graphql.go +++ b/graphql/graphql.go @@ -22,6 +22,7 @@ import ( "errors" "fmt" "math/big" + "sort" "strconv" "github.com/ethereum/go-ethereum" @@ -478,16 +479,16 @@ func (t *Transaction) getLogs(ctx context.Context) (*[]*Log, error) { if err != nil { return nil, err } - ret := make([]*Log, 0) - for _, log := range logs { - if uint64(log.TxIndex) != t.index { - continue - } + var ret []*Log + // Select tx logs from all block logs + ix := sort.Search(len(logs), func(i int) bool { return uint64(logs[i].TxIndex) == t.index }) + for ix < len(logs) && uint64(logs[ix].TxIndex) == t.index { ret = append(ret, &Log{ r: t.r, transaction: t, - log: log, + log: logs[ix], }) + ix++ } return &ret, nil }