mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
upgrade filter system
This commit is contained in:
parent
4ffc292bd4
commit
c2ebc1cd91
2 changed files with 12 additions and 10 deletions
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue