From c2ebc1cd91272b4e4d77c4f191c20f66e7bb1a6a Mon Sep 17 00:00:00 2001 From: maskpp Date: Fri, 18 Apr 2025 22:17:26 +0800 Subject: [PATCH] upgrade filter system --- eth/filters/filter.go | 4 ---- eth/filters/filter_system.go | 18 ++++++++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/eth/filters/filter.go b/eth/filters/filter.go index 2ef829d847..afddebd1be 100644 --- a/eth/filters/filter.go +++ b/eth/filters/filter.go @@ -431,10 +431,6 @@ func (f *Filter) checkMatches(ctx context.Context, header *types.Header) ([]*typ if len(logs) == 0 { return nil, nil } - // Most backends will deliver un-derived logs, but check nevertheless. - if len(logs) > 0 && logs[0].TxHash != (common.Hash{}) { - return logs, nil - } return logs, nil } diff --git a/eth/filters/filter_system.go b/eth/filters/filter_system.go index 1657112ea4..4b0b36de49 100644 --- a/eth/filters/filter_system.go +++ b/eth/filters/filter_system.go @@ -109,11 +109,6 @@ func (sys *FilterSystem) cachedLogElem(ctx context.Context, blockHash common.Has return nil, fmt.Errorf("failed to get logs for block #%d (0x%s)", number, blockHash.TerminalString()) } - body, err := sys.backend.GetBody(ctx, blockHash, rpc.BlockNumber(number)) - if err != nil { - return nil, err - } - // Database logs are un-derived. // Fill in whatever we can (txHash is inaccessible at this point). flattened := make([]*types.Log, 0) @@ -123,12 +118,23 @@ func (sys *FilterSystem) cachedLogElem(ctx context.Context, blockHash common.Has log.BlockHash = blockHash log.BlockNumber = number log.TxIndex = uint(i) - log.TxHash = body.Transactions[i].Hash() log.Index = logIdx logIdx++ flattened = append(flattened, log) } } + + // Most backends will deliver un-derived logs, but check nevertheless. + if len(flattened) > 0 && flattened[0].TxHash == (common.Hash{}) { + body, err := sys.backend.GetBody(ctx, blockHash, rpc.BlockNumber(number)) + if err != nil { + return nil, err + } + for _, log := range flattened { + log.TxHash = body.Transactions[log.TxIndex].Hash() + } + } + elem := &logCacheElem{logs: flattened} sys.logsCache.Add(blockHash, elem) return elem, nil