core/filtermaps: always clone cached slices before modification

This commit is contained in:
Zsolt Felfoldi 2025-04-20 10:15:51 +02:00
parent 7f574372d5
commit 2c163ec800
2 changed files with 5 additions and 3 deletions

View file

@ -573,7 +573,7 @@ func (f *FilterMaps) getFilterMapRow(mapIndex, rowIndex uint32, baseLayerOnly bo
} }
f.baseRowsCache.Add(baseMapRowIndex, baseRows) f.baseRowsCache.Add(baseMapRowIndex, baseRows)
} }
baseRow := baseRows[mapIndex&(f.baseRowGroupLength-1)] baseRow := slices.Clone(baseRows[mapIndex&(f.baseRowGroupLength-1)])
if baseLayerOnly { if baseLayerOnly {
return baseRow, nil return baseRow, nil
} }
@ -610,7 +610,9 @@ func (f *FilterMaps) storeFilterMapRowsOfGroup(batch ethdb.Batch, mapIndices []u
if uint32(len(mapIndices)) != f.baseRowGroupLength { // skip base rows read if all rows are replaced if uint32(len(mapIndices)) != f.baseRowGroupLength { // skip base rows read if all rows are replaced
var ok bool var ok bool
baseRows, ok = f.baseRowsCache.Get(baseMapRowIndex) baseRows, ok = f.baseRowsCache.Get(baseMapRowIndex)
if !ok { if ok {
baseRows = slices.Clone(baseRows)
} else {
var err error var err error
baseRows, err = rawdb.ReadFilterMapBaseRows(f.db, baseMapRowIndex, f.baseRowGroupLength, f.logMapWidth) baseRows, err = rawdb.ReadFilterMapBaseRows(f.db, baseMapRowIndex, f.baseRowGroupLength, f.logMapWidth)
if err != nil { if err != nil {

View file

@ -244,7 +244,7 @@ func (f *FilterMaps) loadHeadSnapshot() error {
} }
} }
f.renderSnapshots.Add(f.indexedRange.blocks.Last(), &renderedMap{ f.renderSnapshots.Add(f.indexedRange.blocks.Last(), &renderedMap{
filterMap: fm, filterMap: fm.fullCopy(),
mapIndex: f.indexedRange.maps.Last(), mapIndex: f.indexedRange.maps.Last(),
lastBlock: f.indexedRange.blocks.Last(), lastBlock: f.indexedRange.blocks.Last(),
lastBlockId: f.indexedView.BlockId(f.indexedRange.blocks.Last()), lastBlockId: f.indexedView.BlockId(f.indexedRange.blocks.Last()),