From 8c3091edc10cd4fdc34c3d382faa70362720cbec Mon Sep 17 00:00:00 2001 From: Zsolt Felfoldi Date: Mon, 17 Mar 2025 09:10:47 +0100 Subject: [PATCH] common, core/filtermaps: moved rlp encoding of Range to filtermaps --- common/range.go | 19 ------------------- core/filtermaps/filtermaps.go | 10 ++++++---- core/rawdb/accessors_indexes.go | 10 +++++----- 3 files changed, 11 insertions(+), 28 deletions(-) diff --git a/common/range.go b/common/range.go index 63c7e2a0b1..d6b4eaba53 100644 --- a/common/range.go +++ b/common/range.go @@ -17,10 +17,7 @@ package common import ( - "io" "iter" - - "github.com/ethereum/go-ethereum/rlp" ) // Range represents a range of integers. @@ -33,22 +30,6 @@ func NewRange[T uint32 | uint64](first, count T) Range[T] { return Range[T]{first, first + count} } -// EncodeRLP implements rlp.Encoder. -func (r *Range[T]) EncodeRLP(w io.Writer) error { - if err := rlp.Encode(w, &r.first); err != nil { - return err - } - return rlp.Encode(w, &r.afterLast) -} - -// DecodeRLP implements rlp.Decoder. -func (r *Range[T]) DecodeRLP(s *rlp.Stream) error { - if err := s.Decode(&r.first); err != nil { - return err - } - return s.Decode(&r.afterLast) -} - // First returns the first element of the range. func (r Range[T]) First() T { return r.first diff --git a/core/filtermaps/filtermaps.go b/core/filtermaps/filtermaps.go index 528d24c62e..390932313a 100644 --- a/core/filtermaps/filtermaps.go +++ b/core/filtermaps/filtermaps.go @@ -202,8 +202,8 @@ func NewFilterMaps(db ethdb.KeyValueStore, initView *ChainView, historyCutoff, f initialized: initialized, headIndexed: rs.HeadIndexed, headDelimiter: rs.HeadDelimiter, - blocks: rs.Blocks, - maps: rs.Maps, + blocks: common.NewRange[uint64](rs.BlocksFirst, rs.BlocksAfterLast-rs.BlocksFirst), + maps: common.NewRange[uint32](rs.MapsFirst, rs.MapsAfterLast-rs.MapsFirst), tailPartialEpoch: rs.TailPartialEpoch, }, matcherSyncCh: make(chan *FilterMapsMatcherBackend), @@ -381,8 +381,10 @@ func (f *FilterMaps) setRange(batch ethdb.KeyValueWriter, newView *ChainView, ne rs := rawdb.FilterMapsRange{ HeadIndexed: newRange.headIndexed, HeadDelimiter: newRange.headDelimiter, - Blocks: newRange.blocks, - Maps: newRange.maps, + BlocksFirst: newRange.blocks.First(), + BlocksAfterLast: newRange.blocks.AfterLast(), + MapsFirst: newRange.maps.First(), + MapsAfterLast: newRange.maps.AfterLast(), TailPartialEpoch: newRange.tailPartialEpoch, } rawdb.WriteFilterMapsRange(batch, rs) diff --git a/core/rawdb/accessors_indexes.go b/core/rawdb/accessors_indexes.go index 70482e1847..9f3d55aa3f 100644 --- a/core/rawdb/accessors_indexes.go +++ b/core/rawdb/accessors_indexes.go @@ -442,11 +442,11 @@ func DeleteBlockLvPointers(db ethdb.KeyValueRangeDeleter, blocks common.Range[ui // FilterMapsRange is a storage representation of the block range covered by the // filter maps structure and the corresponting log value index range. type FilterMapsRange struct { - HeadIndexed bool - HeadDelimiter uint64 - Blocks common.Range[uint64] - Maps common.Range[uint32] - TailPartialEpoch uint32 + HeadIndexed bool + HeadDelimiter uint64 + BlocksFirst, BlocksAfterLast uint64 + MapsFirst, MapsAfterLast uint32 + TailPartialEpoch uint32 } // ReadFilterMapsRange retrieves the filter maps range data. Note that if the