Skip to content

Commit 66912c5

Browse files
committed
core/filtermaps: added comments
1 parent 2ee742c commit 66912c5

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

core/filtermaps/index_view.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ type IndexView struct {
3535
refCount, invalid int32
3636
storage *mapStorage
3737

38-
tailEpoch uint32
39-
blockRange common.Range[uint64]
38+
tailEpoch uint32 //TODO apply to read functions
39+
blockRange common.Range[uint64] //TODO apply to read functions
4040
headBlockHash common.Hash
4141
headLvPointer uint64 // points after head block delimiter
4242

core/filtermaps/indexer.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,15 @@ func NewIndexer(db ethdb.KeyValueStore, params Params, config Config) *Indexer {
102102
return ix
103103
}
104104

105-
func (ix *Indexer) GetIndexView(hash common.Hash) *IndexView {
105+
// GetIndexView returns an immutable IndexView corresponding to the given head
106+
// block hash if available. Note that each returned IndexView has to be released
107+
// after use with the Release funcion in order to avoid memory leakage.
108+
func (ix *Indexer) GetIndexView(headBlockHash common.Hash) *IndexView {
106109
if ix.config.Disabled {
107110
return nil
108111
}
109112
ix.snapshotsLock.RLock()
110-
iv := ix.snapshots[hash]
113+
iv := ix.snapshots[headBlockHash]
111114
ix.snapshotsLock.RUnlock()
112115
if iv == nil || iv.checkReleased() {
113116
return nil
@@ -351,6 +354,7 @@ func (ix *Indexer) revertMaps(mapIndex uint32) {
351354
}
352355
}
353356

357+
// updateTailEpoch recalculates the current tailEpoch and the targetTailEpoch.
354358
func (ix *Indexer) updateTailEpoch() {
355359
ix.tailEpoch = ix.storage.tailEpoch()
356360
if ix.config.History == 0 {
@@ -383,6 +387,9 @@ func (ix *Indexer) updateTailEpoch() {
383387
}
384388
}
385389

390+
// updateActiveViewTailEpoch recalculates activeViewTailEpoch which is the earliest
391+
// tail epoch required by an active IndexView. Tail unindexing is only allowed
392+
// if min(targetTailEpoch, activeViewTailEpoch) > tailEpoch.
386393
func (ix *Indexer) updateActiveViewTailEpoch() {
387394
ix.snapshotsLock.RLock()
388395
defer ix.snapshotsLock.RUnlock()
@@ -393,6 +400,8 @@ func (ix *Indexer) updateActiveViewTailEpoch() {
393400
}
394401
}
395402

403+
// updateTailState performs tail unindexing or initializes a new tailRenderer to
404+
// render a new tail epoch if necessary.
396405
func (ix *Indexer) updateTailState() {
397406
epoch := min(ix.targetTailEpoch, ix.activeViewTailEpoch)
398407
if epoch >= ix.tailEpoch && ix.tailRenderer != nil {

0 commit comments

Comments
 (0)