@@ -127,9 +127,10 @@ func (indexer *txIndexer) loop(chain *BlockChain) {
127127
128128 // Listening to chain events and manipulate the transaction indexes.
129129 var (
130- stop chan struct {} // Non-nil if background routine is active.
131- done chan struct {} // Non-nil if background routine is active.
132- lastHead uint64 // The latest announced chain head (whose tx indexes are assumed created)
130+ stop chan struct {} // Non-nil if background routine is active.
131+ done chan struct {} // Non-nil if background routine is active.
132+ lastHead uint64 // The latest announced chain head (whose tx indexes are assumed created)
133+ lastTail = rawdb .ReadTxIndexTail (indexer .db ) // The oldest indexed block, nil means nothing indexed
133134
134135 headCh = make (chan ChainHeadEvent )
135136 sub = chain .SubscribeChainHeadEvent (headCh )
@@ -156,8 +157,9 @@ func (indexer *txIndexer) loop(chain *BlockChain) {
156157 case <- done :
157158 stop = nil
158159 done = nil
160+ lastTail = rawdb .ReadTxIndexTail (indexer .db )
159161 case ch := <- indexer .progress :
160- ch <- indexer .report (lastHead )
162+ ch <- indexer .report (lastHead , lastTail )
161163 case ch := <- indexer .term :
162164 if stop != nil {
163165 close (stop )
@@ -173,11 +175,7 @@ func (indexer *txIndexer) loop(chain *BlockChain) {
173175}
174176
175177// report returns the tx indexing progress.
176- func (indexer * txIndexer ) report (head uint64 ) TxIndexProgress {
177- var (
178- remaining uint64
179- tail = rawdb .ReadTxIndexTail (indexer .db )
180- )
178+ func (indexer * txIndexer ) report (head uint64 , tail * uint64 ) TxIndexProgress {
181179 total := indexer .limit
182180 if indexer .limit == 0 || total > head {
183181 total = head + 1 // genesis included
@@ -188,6 +186,7 @@ func (indexer *txIndexer) report(head uint64) TxIndexProgress {
188186 }
189187 // The value of indexed might be larger than total if some blocks need
190188 // to be unindexed, avoiding a negative remaining.
189+ var remaining uint64
191190 if indexed < total {
192191 remaining = total - indexed
193192 }
0 commit comments