upgrade filter system

This commit is contained in:
maskpp 2025-04-18 22:17:26 +08:00
parent 4ffc292bd4
commit c2ebc1cd91
2 changed files with 12 additions and 10 deletions

View file

@ -431,10 +431,6 @@ func (f *Filter) checkMatches(ctx context.Context, header *types.Header) ([]*typ
if len(logs) == 0 { if len(logs) == 0 {
return nil, nil 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 return logs, nil
} }

View file

@ -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()) 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. // Database logs are un-derived.
// Fill in whatever we can (txHash is inaccessible at this point). // Fill in whatever we can (txHash is inaccessible at this point).
flattened := make([]*types.Log, 0) flattened := make([]*types.Log, 0)
@ -123,12 +118,23 @@ func (sys *FilterSystem) cachedLogElem(ctx context.Context, blockHash common.Has
log.BlockHash = blockHash log.BlockHash = blockHash
log.BlockNumber = number log.BlockNumber = number
log.TxIndex = uint(i) log.TxIndex = uint(i)
log.TxHash = body.Transactions[i].Hash()
log.Index = logIdx log.Index = logIdx
logIdx++ logIdx++
flattened = append(flattened, log) 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} elem := &logCacheElem{logs: flattened}
sys.logsCache.Add(blockHash, elem) sys.logsCache.Add(blockHash, elem)
return elem, nil return elem, nil