@@ -127,9 +127,10 @@ func (indexer *txIndexer) loop(chain *BlockChain) {
127
127
128
128
// Listening to chain events and manipulate the transaction indexes.
129
129
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
133
134
134
135
headCh = make (chan ChainHeadEvent )
135
136
sub = chain .SubscribeChainHeadEvent (headCh )
@@ -156,8 +157,9 @@ func (indexer *txIndexer) loop(chain *BlockChain) {
156
157
case <- done :
157
158
stop = nil
158
159
done = nil
160
+ lastTail = rawdb .ReadTxIndexTail (indexer .db )
159
161
case ch := <- indexer .progress :
160
- ch <- indexer .report (lastHead )
162
+ ch <- indexer .report (lastHead , lastTail )
161
163
case ch := <- indexer .term :
162
164
if stop != nil {
163
165
close (stop )
@@ -173,11 +175,7 @@ func (indexer *txIndexer) loop(chain *BlockChain) {
173
175
}
174
176
175
177
// 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 {
181
179
total := indexer .limit
182
180
if indexer .limit == 0 || total > head {
183
181
total = head + 1 // genesis included
@@ -188,6 +186,7 @@ func (indexer *txIndexer) report(head uint64) TxIndexProgress {
188
186
}
189
187
// The value of indexed might be larger than total if some blocks need
190
188
// to be unindexed, avoiding a negative remaining.
189
+ var remaining uint64
191
190
if indexed < total {
192
191
remaining = total - indexed
193
192
}
0 commit comments