|
|
@ -127,9 +127,10 @@ func (indexer *txIndexer) loop(chain *BlockChain) { |
|
|
|
|
|
|
|
|
|
|
|
// Listening to chain events and manipulate the transaction indexes.
|
|
|
|
// Listening to chain events and manipulate the transaction indexes.
|
|
|
|
var ( |
|
|
|
var ( |
|
|
|
stop chan struct{} // Non-nil if background routine is active.
|
|
|
|
stop chan struct{} // Non-nil if background routine is active.
|
|
|
|
done chan struct{} // Non-nil if background routine is active.
|
|
|
|
done chan struct{} // Non-nil if background routine is active.
|
|
|
|
lastHead uint64 // The latest announced chain head (whose tx indexes are assumed created)
|
|
|
|
lastHead uint64 // The latest announced chain head (whose tx indexes are assumed created)
|
|
|
|
|
|
|
|
lastTail = rawdb.ReadTxIndexTail(indexer.db) // The oldest indexed block, nil means nothing indexed
|
|
|
|
|
|
|
|
|
|
|
|
headCh = make(chan ChainHeadEvent) |
|
|
|
headCh = make(chan ChainHeadEvent) |
|
|
|
sub = chain.SubscribeChainHeadEvent(headCh) |
|
|
|
sub = chain.SubscribeChainHeadEvent(headCh) |
|
|
@ -156,8 +157,9 @@ func (indexer *txIndexer) loop(chain *BlockChain) { |
|
|
|
case <-done: |
|
|
|
case <-done: |
|
|
|
stop = nil |
|
|
|
stop = nil |
|
|
|
done = nil |
|
|
|
done = nil |
|
|
|
|
|
|
|
lastTail = rawdb.ReadTxIndexTail(indexer.db) |
|
|
|
case ch := <-indexer.progress: |
|
|
|
case ch := <-indexer.progress: |
|
|
|
ch <- indexer.report(lastHead) |
|
|
|
ch <- indexer.report(lastHead, lastTail) |
|
|
|
case ch := <-indexer.term: |
|
|
|
case ch := <-indexer.term: |
|
|
|
if stop != nil { |
|
|
|
if stop != nil { |
|
|
|
close(stop) |
|
|
|
close(stop) |
|
|
@ -173,11 +175,7 @@ func (indexer *txIndexer) loop(chain *BlockChain) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// report returns the tx indexing progress.
|
|
|
|
// report returns the tx indexing progress.
|
|
|
|
func (indexer *txIndexer) report(head uint64) TxIndexProgress { |
|
|
|
func (indexer *txIndexer) report(head uint64, tail *uint64) TxIndexProgress { |
|
|
|
var ( |
|
|
|
|
|
|
|
remaining uint64 |
|
|
|
|
|
|
|
tail = rawdb.ReadTxIndexTail(indexer.db) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
total := indexer.limit |
|
|
|
total := indexer.limit |
|
|
|
if indexer.limit == 0 || total > head { |
|
|
|
if indexer.limit == 0 || total > head { |
|
|
|
total = head + 1 // genesis included
|
|
|
|
total = head + 1 // genesis included
|
|
|
@ -188,6 +186,7 @@ func (indexer *txIndexer) report(head uint64) TxIndexProgress { |
|
|
|
} |
|
|
|
} |
|
|
|
// The value of indexed might be larger than total if some blocks need
|
|
|
|
// The value of indexed might be larger than total if some blocks need
|
|
|
|
// to be unindexed, avoiding a negative remaining.
|
|
|
|
// to be unindexed, avoiding a negative remaining.
|
|
|
|
|
|
|
|
var remaining uint64 |
|
|
|
if indexed < total { |
|
|
|
if indexed < total { |
|
|
|
remaining = total - indexed |
|
|
|
remaining = total - indexed |
|
|
|
} |
|
|
|
} |
|
|
|