@@ -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.
354358func (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.
386393func (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.
396405func (ix * Indexer ) updateTailState () {
397406 epoch := min (ix .targetTailEpoch , ix .activeViewTailEpoch )
398407 if epoch >= ix .tailEpoch && ix .tailRenderer != nil {
0 commit comments