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
846d578cc3
commit
0562540086
2 changed files with 8 additions and 25 deletions
|
|
@ -436,16 +436,6 @@ func (f *Filter) checkMatches(ctx context.Context, header *types.Header) ([]*typ
|
||||||
return logs, nil
|
return logs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err := f.sys.cachedGetBody(ctx, cached, hash, header.Number.Uint64())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
for i, log := range logs {
|
|
||||||
// Copy log not to modify cache elements
|
|
||||||
logcopy := *log
|
|
||||||
logcopy.TxHash = body.Transactions[logcopy.TxIndex].Hash()
|
|
||||||
logs[i] = &logcopy
|
|
||||||
}
|
|
||||||
return logs, nil
|
return logs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -475,7 +465,7 @@ func filterLogs(logs []*types.Log, fromBlock, toBlock *big.Int, addresses []comm
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
var ret []*types.Log
|
var ret = make([]*types.Log, 0, len(logs))
|
||||||
for _, log := range logs {
|
for _, log := range logs {
|
||||||
if check(log) {
|
if check(log) {
|
||||||
ret = append(ret, log)
|
ret = append(ret, log)
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum"
|
"github.com/ethereum/go-ethereum"
|
||||||
|
|
@ -93,7 +92,6 @@ func NewFilterSystem(backend Backend, config Config) *FilterSystem {
|
||||||
|
|
||||||
type logCacheElem struct {
|
type logCacheElem struct {
|
||||||
logs []*types.Log
|
logs []*types.Log
|
||||||
body atomic.Pointer[types.Body]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// cachedLogElem loads block logs from the backend and caches the result.
|
// cachedLogElem loads block logs from the backend and caches the result.
|
||||||
|
|
@ -110,6 +108,12 @@ func (sys *FilterSystem) cachedLogElem(ctx context.Context, blockHash common.Has
|
||||||
if logs == nil {
|
if logs == nil {
|
||||||
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)
|
||||||
|
|
@ -119,6 +123,7 @@ 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)
|
||||||
|
|
@ -129,18 +134,6 @@ func (sys *FilterSystem) cachedLogElem(ctx context.Context, blockHash common.Has
|
||||||
return elem, nil
|
return elem, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sys *FilterSystem) cachedGetBody(ctx context.Context, elem *logCacheElem, hash common.Hash, number uint64) (*types.Body, error) {
|
|
||||||
if body := elem.body.Load(); body != nil {
|
|
||||||
return body, nil
|
|
||||||
}
|
|
||||||
body, err := sys.backend.GetBody(ctx, hash, rpc.BlockNumber(number))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
elem.body.Store(body)
|
|
||||||
return body, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Type determines the kind of filter and is used to put the filter in to
|
// Type determines the kind of filter and is used to put the filter in to
|
||||||
// the correct bucket when added.
|
// the correct bucket when added.
|
||||||
type Type byte
|
type Type byte
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue