From dcad05892ad1f172488126b196553f4710fc40d0 Mon Sep 17 00:00:00 2001 From: 0xcb9ff9 <0xcb9ff9@proton.me> Date: Wed, 1 Nov 2023 11:48:18 +0800 Subject: [PATCH] fix: pendingLogs nil pointer error --- eth/filters/filter.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/eth/filters/filter.go b/eth/filters/filter.go index b684ebb091..82677df8af 100644 --- a/eth/filters/filter.go +++ b/eth/filters/filter.go @@ -151,7 +151,7 @@ func (f *Filter) Logs(ctx context.Context) ([]*types.Log, error) { var ( head = header.Number.Uint64() end = uint64(f.end) - pending = f.end == rpc.LatestBlockNumber.Int64() + pending = f.end == rpc.PendingBlockNumber.Int64() ) if f.begin == rpc.LatestBlockNumber.Int64() { f.begin = int64(head) @@ -306,6 +306,10 @@ func (f *Filter) checkMatches(ctx context.Context, header *types.Header) (logs [ // pendingLogs returns the logs matching the filter criteria within the pending block. func (f *Filter) pendingLogs() ([]*types.Log, error) { block, receipts := f.backend.PendingBlockAndReceipts() + // the pending block might be nil if the miner is disabled + if block == nil || len(receipts) == 0 { + return nil, nil + } if bloomFilter(block.Bloom(), f.addresses, f.topics) { var unfiltered []*types.Log for _, r := range receipts {