-
Notifications
You must be signed in to change notification settings - Fork 20.9k
core/filtermaps: fix log index initialization #31750
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -244,6 +244,8 @@ func NewFilterMaps(db ethdb.KeyValueStore, initView *ChainView, historyCutoff, f | |
disabledCh: make(chan struct{}), | ||
exportFileName: config.ExportFileName, | ||
Params: params, | ||
targetView: initView, | ||
indexedView: initView, | ||
indexedRange: filterMapsRange{ | ||
initialized: initialized, | ||
headIndexed: rs.HeadIndexed, | ||
|
@@ -265,16 +267,8 @@ func NewFilterMaps(db ethdb.KeyValueStore, initView *ChainView, historyCutoff, f | |
baseRowsCache: lru.NewCache[uint64, [][]uint32](cachedBaseRows), | ||
renderSnapshots: lru.NewCache[uint64, *renderedMap](cachedRenderSnapshots), | ||
} | ||
f.checkRevertRange() // revert maps that are inconsistent with the current chain view | ||
|
||
// Set initial indexer target. | ||
f.targetView = initView | ||
if f.indexedRange.initialized { | ||
f.indexedView = f.initChainView(f.targetView) | ||
f.indexedRange.headIndexed = f.indexedRange.blocks.AfterLast() == f.indexedView.HeadNumber()+1 | ||
if !f.indexedRange.headIndexed { | ||
f.indexedRange.headDelimiter = 0 | ||
} | ||
} | ||
if f.indexedRange.hasIndexedBlocks() { | ||
log.Info("Initialized log indexer", | ||
"first block", f.indexedRange.blocks.First(), "last block", f.indexedRange.blocks.Last(), | ||
|
@@ -303,29 +297,40 @@ func (f *FilterMaps) Stop() { | |
f.closeWg.Wait() | ||
} | ||
|
||
// initChainView returns a chain view consistent with both the current target | ||
// view and the current state of the log index as found in the database, based | ||
// on the last block of stored maps. | ||
// Note that the returned view might be shorter than the existing index if | ||
// the latest maps are not consistent with targetView. | ||
func (f *FilterMaps) initChainView(chainView *ChainView) *ChainView { | ||
mapIndex := f.indexedRange.maps.AfterLast() | ||
for { | ||
var ok bool | ||
mapIndex, ok = f.lastMapBoundaryBefore(mapIndex) | ||
if !ok { | ||
break | ||
// checkRevertRange checks whether the existing index is consistent with the | ||
// current indexed view and reverts inconsistent maps if necessary. | ||
func (f *FilterMaps) checkRevertRange() { | ||
if f.indexedRange.maps.Count() == 0 { | ||
return | ||
} | ||
lastMap := f.indexedRange.maps.Last() | ||
lastBlockNumber, lastBlockId, err := f.getLastBlockOfMap(lastMap) | ||
if err != nil { | ||
log.Error("Error initializing log index database; resetting log index", "error", err) | ||
f.reset() | ||
return | ||
} | ||
for lastBlockNumber > f.indexedView.HeadNumber() || f.indexedView.BlockId(lastBlockNumber) != lastBlockId { | ||
// revert last map | ||
if f.indexedRange.maps.Count() == 1 { | ||
f.reset() // reset database if no rendered maps remained | ||
return | ||
} | ||
lastBlockNumber, lastBlockId, err := f.getLastBlockOfMap(mapIndex) | ||
lastMap-- | ||
newRange := f.indexedRange | ||
newRange.maps.SetLast(lastMap) | ||
lastBlockNumber, lastBlockId, err = f.getLastBlockOfMap(lastMap) | ||
if err != nil { | ||
log.Error("Could not initialize indexed chain view", "error", err) | ||
break | ||
} | ||
if lastBlockNumber <= chainView.HeadNumber() && chainView.BlockId(lastBlockNumber) == lastBlockId { | ||
return chainView.limitedView(lastBlockNumber) | ||
log.Error("Error initializing log index database; resetting log index", "error", err) | ||
f.reset() | ||
return | ||
} | ||
newRange.blocks.SetAfterLast(lastBlockNumber) // lastBlockNumber is probably partially indexed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This status is very weird.
This status is very weird; the if the map is full, it's usually written with headIndexed = false; If the map is not full but all blocks have been indexed, then the headIndexed = true; The initialized status of indexedRange is actually an invalid one (the last block is not the real one corresponds to the map) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EDIT, never mind. It's correct. |
||
newRange.headIndexed = false | ||
newRange.headDelimiter = 0 | ||
// only shorten range and leave map data; next head render will overwrite it | ||
f.setRange(f.db, f.indexedView, newRange, false) | ||
} | ||
return chainView.limitedView(0) | ||
} | ||
|
||
// reset un-initializes the FilterMaps structure and removes all related data from | ||
|
Uh oh!
There was an error while loading. Please reload this page.