mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
eth/filters: use min and max in filter
This commit is contained in:
parent
90297009c1
commit
ab49290ce7
1 changed files with 8 additions and 20 deletions
|
|
@ -170,19 +170,15 @@ func (f *Filter) rangeLogs(ctx context.Context, firstBlock, lastBlock uint64) ([
|
||||||
if syncRange.IndexedBlocks.IsEmpty() {
|
if syncRange.IndexedBlocks.IsEmpty() {
|
||||||
// fallback to completely unindexed search
|
// fallback to completely unindexed search
|
||||||
headNum := syncRange.HeadNumber
|
headNum := syncRange.HeadNumber
|
||||||
if firstBlock > headNum {
|
firstBlock = min(firstBlock, headNum)
|
||||||
firstBlock = headNum
|
lastBlock = min(lastBlock, headNum)
|
||||||
}
|
|
||||||
if lastBlock > headNum {
|
|
||||||
lastBlock = headNum
|
|
||||||
}
|
|
||||||
if f.rangeLogsTestHook != nil {
|
if f.rangeLogsTestHook != nil {
|
||||||
f.rangeLogsTestHook <- rangeLogsTestEvent{rangeLogsTestUnindexed, firstBlock, lastBlock}
|
f.rangeLogsTestHook <- rangeLogsTestEvent{rangeLogsTestUnindexed, firstBlock, lastBlock}
|
||||||
}
|
}
|
||||||
return f.unindexedLogs(ctx, firstBlock, lastBlock)
|
return f.unindexedLogs(ctx, firstBlock, lastBlock)
|
||||||
}
|
}
|
||||||
|
|
||||||
headBlock := syncRange.HeadNumber // Head is guaranteed != nil
|
headBlock := syncRange.HeadNumber
|
||||||
// if haveMatches == true then matches correspond to the block number range
|
// if haveMatches == true then matches correspond to the block number range
|
||||||
// between matchFirst and matchLast
|
// between matchFirst and matchLast
|
||||||
var (
|
var (
|
||||||
|
|
@ -216,15 +212,11 @@ func (f *Filter) rangeLogs(ctx context.Context, firstBlock, lastBlock uint64) ([
|
||||||
// determine range to be searched; for simplicity we only extend the most
|
// determine range to be searched; for simplicity we only extend the most
|
||||||
// recent end of the existing match set by matching between searchFirst
|
// recent end of the existing match set by matching between searchFirst
|
||||||
// and searchLast.
|
// and searchLast.
|
||||||
searchFirst, searchLast := firstBlock, lastBlock
|
searchFirst := min(firstBlock, headBlock)
|
||||||
if searchFirst > headBlock {
|
searchLast := min(lastBlock, headBlock)
|
||||||
searchFirst = headBlock
|
|
||||||
}
|
|
||||||
if searchLast > headBlock {
|
|
||||||
searchLast = headBlock
|
|
||||||
}
|
|
||||||
trimMatches(searchFirst, searchLast)
|
trimMatches(searchFirst, searchLast)
|
||||||
if haveMatches && matchFirst == searchFirst && matchLast == searchLast {
|
if haveMatches && matchFirst == searchFirst && matchLast == searchLast {
|
||||||
|
// The entire search range was explored.
|
||||||
return matches, nil
|
return matches, nil
|
||||||
}
|
}
|
||||||
var trimTailIfNotValid uint64
|
var trimTailIfNotValid uint64
|
||||||
|
|
@ -254,12 +246,8 @@ func (f *Filter) rangeLogs(ctx context.Context, firstBlock, lastBlock uint64) ([
|
||||||
forceUnindexed = true
|
forceUnindexed = true
|
||||||
}
|
}
|
||||||
if !forceUnindexed {
|
if !forceUnindexed {
|
||||||
if syncRange.IndexedBlocks.First() > searchFirst {
|
searchFirst = max(searchFirst, syncRange.IndexedBlocks.First())
|
||||||
searchFirst = syncRange.IndexedBlocks.First()
|
searchLast = min(searchLast, syncRange.IndexedBlocks.Last())
|
||||||
}
|
|
||||||
if syncRange.IndexedBlocks.Last() < searchLast {
|
|
||||||
searchLast = syncRange.IndexedBlocks.Last()
|
|
||||||
}
|
|
||||||
if f.rangeLogsTestHook != nil {
|
if f.rangeLogsTestHook != nil {
|
||||||
f.rangeLogsTestHook <- rangeLogsTestEvent{rangeLogsTestIndexed, searchFirst, searchLast}
|
f.rangeLogsTestHook <- rangeLogsTestEvent{rangeLogsTestIndexed, searchFirst, searchLast}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue