Skip to content

eth/filters: implement log filter using new log index #31080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a5df454
core/filtermaps: do not split a log in half at a map boundary
zsfelfoldi Mar 13, 2025
7a057bf
core/filtermaps: add history cutoff point
zsfelfoldi Mar 14, 2025
8b3aa45
core/filtermaps: updated indexer test
zsfelfoldi Mar 14, 2025
8f2f37d
core/filtermaps: simplified matcher
zsfelfoldi Mar 14, 2025
25b51f2
core/filtermaps: un-embedded matcher processing
zsfelfoldi Mar 14, 2025
9031f90
core/filtermaps: fixed tail indexer finished log message
zsfelfoldi Mar 14, 2025
6a6deb1
common, core/filtermaps: use Range type
zsfelfoldi Mar 14, 2025
f30ec81
eth/filters: implement log filter using new log index
zsfelfoldi Jan 27, 2025
9c42b48
eth/backend: updated updateFilterMapsHeads
zsfelfoldi Mar 12, 2025
c27586d
eth/filters: fixed tests
zsfelfoldi Mar 12, 2025
0ca476b
eth/filters: fixed errors after rebase
zsfelfoldi Mar 14, 2025
90efe8f
eth/filters: SyncRange update
zsfelfoldi Mar 14, 2025
2309128
common: move Range to its own file and add Iter
fjl Mar 14, 2025
1363a69
common: use slices.Collect in tests
fjl Mar 14, 2025
9029700
core/filtermaps: use Range iterator
fjl Mar 14, 2025
ab49290
eth/filters: use min and max in filter
fjl Mar 14, 2025
c82b660
eth/filters: refactored filter logic
zsfelfoldi Mar 15, 2025
2961e72
added comments
zsfelfoldi Mar 15, 2025
c9fd101
core/filtermaps: updated checkpoints
zsfelfoldi Mar 17, 2025
8c3091e
common, core/filtermaps: moved rlp encoding of Range to filtermaps
zsfelfoldi Mar 17, 2025
c9610fb
common: shorten some comments
fjl Mar 17, 2025
f27166c
all: remove unnecessary type arguments for NewRange
fjl Mar 17, 2025
c150991
core/filtermaps: remove tautological nil check
fjl Mar 17, 2025
7c07261
core/filtermaps: use range-over-int
fjl Mar 17, 2025
03638e5
eth/filters: simplify loop
fjl Mar 17, 2025
fc8e4e0
eth/filters: simplify slice syntax
fjl Mar 17, 2025
ef465a3
eth/filters: remove unused parameter t in newTestFilterSystem
fjl Mar 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/geth/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ if one is set. Otherwise it prints the genesis from the datadir.`,
utils.VMTraceFlag,
utils.VMTraceJsonConfigFlag,
utils.TransactionHistoryFlag,
utils.LogHistoryFlag,
utils.LogNoHistoryFlag,
utils.LogExportCheckpointsFlag,
utils.StateHistoryFlag,
}, utils.DatabaseFlags),
Description: `
Expand Down
3 changes: 3 additions & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ var (
utils.TxLookupLimitFlag, // deprecated
utils.TransactionHistoryFlag,
utils.ChainHistoryFlag,
utils.LogHistoryFlag,
utils.LogNoHistoryFlag,
utils.LogExportCheckpointsFlag,
utils.StateHistoryFlag,
utils.LightServeFlag, // deprecated
utils.LightIngressFlag, // deprecated
Expand Down
26 changes: 26 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,23 @@ var (
Value: ethconfig.Defaults.HistoryMode.String(),
Category: flags.StateCategory,
}
LogHistoryFlag = &cli.Uint64Flag{
Name: "history.logs",
Usage: "Number of recent blocks to maintain log search index for (default = about one year, 0 = entire chain)",
Value: ethconfig.Defaults.LogHistory,
Category: flags.StateCategory,
}
LogNoHistoryFlag = &cli.BoolFlag{
Name: "history.logs.disable",
Usage: "Do not maintain log search index",
Category: flags.StateCategory,
}
LogExportCheckpointsFlag = &cli.StringFlag{
Name: "history.logs.export",
Usage: "Export checkpoints to file in go source file format",
Category: flags.StateCategory,
Value: "",
}
// Beacon client light sync settings
BeaconApiFlag = &cli.StringSliceFlag{
Name: "beacon.api",
Expand Down Expand Up @@ -1636,6 +1653,15 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
cfg.StateScheme = rawdb.HashScheme
log.Warn("Forcing hash state-scheme for archive mode")
}
if ctx.IsSet(LogHistoryFlag.Name) {
cfg.LogHistory = ctx.Uint64(LogHistoryFlag.Name)
}
if ctx.IsSet(LogNoHistoryFlag.Name) {
cfg.LogNoHistory = true
}
if ctx.IsSet(LogExportCheckpointsFlag.Name) {
cfg.LogExportCheckpoints = ctx.String(LogExportCheckpointsFlag.Name)
}
if ctx.IsSet(CacheFlag.Name) || ctx.IsSet(CacheTrieFlag.Name) {
cfg.TrieCleanCache = ctx.Int(CacheFlag.Name) * ctx.Int(CacheTrieFlag.Name) / 100
}
Expand Down
115 changes: 115 additions & 0 deletions common/range.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Copyright 2025 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

package common

import (
"iter"
)

// Range represents a range of integers.
type Range[T uint32 | uint64] struct {
first, afterLast T
}

// NewRange creates a new range based of first element and number of elements.
func NewRange[T uint32 | uint64](first, count T) Range[T] {
return Range[T]{first, first + count}
}

// First returns the first element of the range.
func (r Range[T]) First() T {
return r.first
}

// Last returns the last element of the range. This panics for empty ranges.
func (r Range[T]) Last() T {
if r.first == r.afterLast {
panic("last item of zero length range is not allowed")
}
return r.afterLast - 1
}

// AfterLast returns the first element after the range. This allows obtaining
// information about the end part of zero length ranges.
func (r Range[T]) AfterLast() T {
return r.afterLast
}

// Count returns the number of elements in the range.
func (r Range[T]) Count() T {
return r.afterLast - r.first
}

// IsEmpty returns true if the range is empty.
func (r Range[T]) IsEmpty() bool {
return r.first == r.afterLast
}

// Includes returns true if the given element is inside the range.
func (r Range[T]) Includes(v T) bool {
return v >= r.first && v < r.afterLast
}

// SetFirst updates the first element of the list.
func (r *Range[T]) SetFirst(v T) {
r.first = v
if r.afterLast < r.first {
r.afterLast = r.first
}
}

// SetAfterLast updates the end of the range by specifying the first element
// after the range. This allows setting zero length ranges.
func (r *Range[T]) SetAfterLast(v T) {
r.afterLast = v
if r.afterLast < r.first {
r.first = r.afterLast
}
}

// SetLast updates last element of the range.
func (r *Range[T]) SetLast(v T) {
r.SetAfterLast(v + 1)
}

// Intersection returns the intersection of two ranges.
func (r Range[T]) Intersection(q Range[T]) Range[T] {
i := Range[T]{first: max(r.first, q.first), afterLast: min(r.afterLast, q.afterLast)}
if i.first > i.afterLast {
return Range[T]{}
}
return i
}

// Union returns the union of two ranges. Panics for gapped ranges.
func (r Range[T]) Union(q Range[T]) Range[T] {
if max(r.first, q.first) > min(r.afterLast, q.afterLast) {
panic("cannot create union; gap between ranges")
}
return Range[T]{first: min(r.first, q.first), afterLast: max(r.afterLast, q.afterLast)}
}

// Iter iterates all integers in the range.
func (r Range[T]) Iter() iter.Seq[T] {
return func(yield func(T) bool) {
for i := r.first; i < r.afterLast; i++ {
if !yield(i) {
break
}
}
}
}
36 changes: 36 additions & 0 deletions common/range_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2025 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

package common

import (
"slices"
"testing"
)

func TestRangeIter(t *testing.T) {
r := NewRange[uint32](1, 7)
values := slices.Collect(r.Iter())
if !slices.Equal(values, []uint32{1, 2, 3, 4, 5, 6, 7}) {
t.Fatalf("wrong iter values: %v", values)
}

empty := NewRange[uint32](1, 0)
values = slices.Collect(empty.Iter())
if !slices.Equal(values, []uint32{}) {
t.Fatalf("wrong iter values: %v", values)
}
}
37 changes: 19 additions & 18 deletions core/filtermaps/checkpoints_holesky.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
[
{"blockNumber": 814411, "blockId": "0xf763e96fc3920359c5f706803024b78e83796a3a8563bb5a83c3ddd7cbfde287", "firstIndex": 67107637},
{"blockNumber": 914278, "blockId": "0x0678cf8d53c0d6d27896df657d98cc73bc63ca468b6295068003938ef9b0f927", "firstIndex": 134217671},
{"blockNumber": 1048874, "blockId": "0x3620c3d52a40ff4d9fc58c3104cfa2f327f55592caf6a2394c207a5e00b4f740", "firstIndex": 201326382},
{"blockNumber": 1144441, "blockId": "0x438fb42850f5a0d8e1666de598a4d0106b62da0f7448c62fe029b8cbad35d08d", "firstIndex": 268435440},
{"blockNumber": 1230411, "blockId": "0xf0ee07e60a93910723b259473a253dd9cf674e8b78c4f153b32ad7032efffeeb", "firstIndex": 335543079},
{"blockNumber": 1309112, "blockId": "0xc1646e5ef4b4343880a85b1a4111e3321d609a1225e9cebbe10d1c7abf99e58d", "firstIndex": 402653100},
{"blockNumber": 1380522, "blockId": "0x1617cae91989d97ac6335c4217aa6cc7f7f4c2837e20b3b5211d98d6f9e97e44", "firstIndex": 469761917},
{"blockNumber": 1476962, "blockId": "0xd978455d2618d093dfc685d7f43f61be6dae0fa8a9cb915ae459aa6e0a5525f0", "firstIndex": 536870773},
{"blockNumber": 1533518, "blockId": "0xe7d39d71bd9d5f1f3157c35e0329531a7950a19e3042407e38948b89b5384f78", "firstIndex": 603979664},
{"blockNumber": 1613787, "blockId": "0xa793168d135c075732a618ec367faaed5f359ffa81898c73cb4ec54ec2caa696", "firstIndex": 671088003},
{"blockNumber": 1719099, "blockId": "0xc4394c71a8a24efe64c5ff2afcdd1594f3708524e6084aa7dadd862bd704ab03", "firstIndex": 738196914},
{"blockNumber": 1973165, "blockId": "0xee3a9e959a437c707a3036736ec8d42a9261ac6100972c26f65eedcde315a81d", "firstIndex": 805306333},
{"blockNumber": 2274844, "blockId": "0x76e2d33653ed9282c63ad09d721e1f2e29064aa9c26202e20fc4cc73e8dfe5f6", "firstIndex": 872415141},
{"blockNumber": 2530503, "blockId": "0x59f4e45345f8b8f848be5004fe75c4a28f651864256c3aa9b2da63369432b718", "firstIndex": 939523693},
{"blockNumber": 2781903, "blockId": "0xc981e91c6fb69c5e8146ead738fcfc561831f11d7786d39c7fa533966fc37675", "firstIndex": 1006632906},
{"blockNumber": 3101713, "blockId": "0xc7baa577c91d8439e3fc79002d2113d07ca54a4724bf2f1f5af937b7ba8e1f32", "firstIndex": 1073741382},
{"blockNumber": 3221770, "blockId": "0xa6b8240b7883fcc71aa5001b5ba66c889975c5217e14c16edebdd6f6e23a9424", "firstIndex": 1140850360}
{"blockNumber": 814410, "blockId": "0x6c38f0d4ff2c23ae187f581cebb0963c0ec2dbf051b289de1582c369c98a3244", "firstIndex": 67107349},
{"blockNumber": 914268, "blockId": "0xeff161573a11eb6e2ab930674a5245b2c5ffc5e9e63093503344ec6fa60578a3", "firstIndex": 134216064},
{"blockNumber": 1048866, "blockId": "0xebd3b95415dad9ab7f2b1d25e48c791e299063c09427bbde54217029c3e215ad", "firstIndex": 201325914},
{"blockNumber": 1144433, "blockId": "0x0c895438ef12a2c835b4372c209e40a499ba2b18ed0e658846813784de391392", "firstIndex": 268434935},
{"blockNumber": 1230406, "blockId": "0xd3512e7241efc9853e46b1ad565403d302f62457b6dd84917c31ff375fabf487", "firstIndex": 335544096},
{"blockNumber": 1309104, "blockId": "0xcf108c6e002e7a5657bf7587adde03edf5f20d03e95b66a194eb8080daaf4f97", "firstIndex": 402653143},
{"blockNumber": 1380499, "blockId": "0x984b0f8b6bf06f1240bbca8c1df9bef3880bedafd5b5c2a55cbc2f64c9efb974", "firstIndex": 469759822},
{"blockNumber": 1476950, "blockId": "0x8323b528bb8d80a96b172de92452be0f45078a9ca311cb4be6675f089e25a426", "firstIndex": 536870335},
{"blockNumber": 1533506, "blockId": "0x737dc416070aa3b522a0c2ab813a70c1820f062c718f27597394f309f0004106", "firstIndex": 603979618},
{"blockNumber": 1613764, "blockId": "0x9d6a5a505afdda86b1ebcc2b10cb687a1f89c2e2b74315945a3ddc6a0b3c9cd6", "firstIndex": 671088253},
{"blockNumber": 1719073, "blockId": "0x17bf6a51d9c55a908c3e9e652f80b2aa464b049c697abf3bd5a537e461aff0b9", "firstIndex": 738197366},
{"blockNumber": 1973133, "blockId": "0x14b288d70e688de3334d09283670301aacfed21c193da8a56fd63767f8177705", "firstIndex": 805305624},
{"blockNumber": 2274761, "blockId": "0xf02790b273b04219e001d2fcc93e8e47708cb228364e96ad754bc8050d08a9aa", "firstIndex": 872414871},
{"blockNumber": 2530470, "blockId": "0x157ea98b1a7e66dd3f045da8e25219800671f9a000211d3d94006efd33d89a80", "firstIndex": 939523234},
{"blockNumber": 2781706, "blockId": "0xa723663a584e280700d2302eba03d1b3b6549333db70c6152576d33e2911f594", "firstIndex": 1006632936},
{"blockNumber": 3101669, "blockId": "0xa6e66a18fed64d33178c7088f273c404be597662c34f6e6884cf2e24f3ea4ace", "firstIndex": 1073741353},
{"blockNumber": 3221725, "blockId": "0xe771f897dece48b1583cc1d1d10de8015da57407eb1fdf239fdbe46eaab85143", "firstIndex": 1140850137},
{"blockNumber": 3357164, "blockId": "0x6252d0aa54c79623b0680069c88d7b5c47983f0d5c4845b6c811b8d9b5e8ff3c", "firstIndex": 1207959453},
{"blockNumber": 3447019, "blockId": "0xeb7d585e1e063f3cc05ed399fbf6c2df63c271f62f030acb804e9fb1e74b6dc1", "firstIndex": 1275067542}
]

Loading