|
|
|
@@ -178,7 +178,7 @@ func iterateTransactions(db ethdb.Database, from uint64, to uint64, reverse bool
|
|
|
|
|
//
|
|
|
|
|
// There is a passed channel, the whole procedure will be interrupted if any
|
|
|
|
|
// signal received.
|
|
|
|
|
func indexTransactions(db ethdb.Database, from uint64, to uint64, interrupt chan struct{}, hook func(uint64) bool) {
|
|
|
|
|
func indexTransactions(db ethdb.Database, from uint64, to uint64, interrupt chan struct{}, hook func(uint64) bool, report bool) {
|
|
|
|
|
// short circuit for invalid range
|
|
|
|
|
if from >= to {
|
|
|
|
|
return
|
|
|
|
@@ -188,13 +188,13 @@ func indexTransactions(db ethdb.Database, from uint64, to uint64, interrupt chan
|
|
|
|
|
batch = db.NewBatch()
|
|
|
|
|
start = time.Now()
|
|
|
|
|
logged = start.Add(-7 * time.Second)
|
|
|
|
|
|
|
|
|
|
// Since we iterate in reverse, we expect the first number to come
|
|
|
|
|
// in to be [to-1]. Therefore, setting lastNum to means that the
|
|
|
|
|
// prqueue gap-evaluation will work correctly
|
|
|
|
|
lastNum = to
|
|
|
|
|
queue = prque.New[int64, *blockTxHashes](nil)
|
|
|
|
|
// for stats reporting
|
|
|
|
|
blocks, txs = 0, 0
|
|
|
|
|
// queue gap-evaluation will work correctly
|
|
|
|
|
lastNum = to
|
|
|
|
|
queue = prque.New[int64, *blockTxHashes](nil)
|
|
|
|
|
blocks, txs = 0, 0 // for stats reporting
|
|
|
|
|
)
|
|
|
|
|
for chanDelivery := range hashesCh {
|
|
|
|
|
// Push the delivery into the queue and process contiguous ranges.
|
|
|
|
@@ -240,11 +240,15 @@ func indexTransactions(db ethdb.Database, from uint64, to uint64, interrupt chan
|
|
|
|
|
log.Crit("Failed writing batch to db", "error", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
logger := log.Debug
|
|
|
|
|
if report {
|
|
|
|
|
logger = log.Info
|
|
|
|
|
}
|
|
|
|
|
select {
|
|
|
|
|
case <-interrupt:
|
|
|
|
|
log.Debug("Transaction indexing interrupted", "blocks", blocks, "txs", txs, "tail", lastNum, "elapsed", common.PrettyDuration(time.Since(start)))
|
|
|
|
|
logger("Transaction indexing interrupted", "blocks", blocks, "txs", txs, "tail", lastNum, "elapsed", common.PrettyDuration(time.Since(start)))
|
|
|
|
|
default:
|
|
|
|
|
log.Debug("Indexed transactions", "blocks", blocks, "txs", txs, "tail", lastNum, "elapsed", common.PrettyDuration(time.Since(start)))
|
|
|
|
|
logger("Indexed transactions", "blocks", blocks, "txs", txs, "tail", lastNum, "elapsed", common.PrettyDuration(time.Since(start)))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -257,20 +261,20 @@ func indexTransactions(db ethdb.Database, from uint64, to uint64, interrupt chan
|
|
|
|
|
//
|
|
|
|
|
// There is a passed channel, the whole procedure will be interrupted if any
|
|
|
|
|
// signal received.
|
|
|
|
|
func IndexTransactions(db ethdb.Database, from uint64, to uint64, interrupt chan struct{}) {
|
|
|
|
|
indexTransactions(db, from, to, interrupt, nil)
|
|
|
|
|
func IndexTransactions(db ethdb.Database, from uint64, to uint64, interrupt chan struct{}, report bool) {
|
|
|
|
|
indexTransactions(db, from, to, interrupt, nil, report)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// indexTransactionsForTesting is the internal debug version with an additional hook.
|
|
|
|
|
func indexTransactionsForTesting(db ethdb.Database, from uint64, to uint64, interrupt chan struct{}, hook func(uint64) bool) {
|
|
|
|
|
indexTransactions(db, from, to, interrupt, hook)
|
|
|
|
|
indexTransactions(db, from, to, interrupt, hook, false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// unindexTransactions removes txlookup indices of the specified block range.
|
|
|
|
|
//
|
|
|
|
|
// There is a passed channel, the whole procedure will be interrupted if any
|
|
|
|
|
// signal received.
|
|
|
|
|
func unindexTransactions(db ethdb.Database, from uint64, to uint64, interrupt chan struct{}, hook func(uint64) bool) {
|
|
|
|
|
func unindexTransactions(db ethdb.Database, from uint64, to uint64, interrupt chan struct{}, hook func(uint64) bool, report bool) {
|
|
|
|
|
// short circuit for invalid range
|
|
|
|
|
if from >= to {
|
|
|
|
|
return
|
|
|
|
@@ -280,12 +284,12 @@ func unindexTransactions(db ethdb.Database, from uint64, to uint64, interrupt ch
|
|
|
|
|
batch = db.NewBatch()
|
|
|
|
|
start = time.Now()
|
|
|
|
|
logged = start.Add(-7 * time.Second)
|
|
|
|
|
|
|
|
|
|
// we expect the first number to come in to be [from]. Therefore, setting
|
|
|
|
|
// nextNum to from means that the prqueue gap-evaluation will work correctly
|
|
|
|
|
nextNum = from
|
|
|
|
|
queue = prque.New[int64, *blockTxHashes](nil)
|
|
|
|
|
// for stats reporting
|
|
|
|
|
blocks, txs = 0, 0
|
|
|
|
|
// nextNum to from means that the queue gap-evaluation will work correctly
|
|
|
|
|
nextNum = from
|
|
|
|
|
queue = prque.New[int64, *blockTxHashes](nil)
|
|
|
|
|
blocks, txs = 0, 0 // for stats reporting
|
|
|
|
|
)
|
|
|
|
|
// Otherwise spin up the concurrent iterator and unindexer
|
|
|
|
|
for delivery := range hashesCh {
|
|
|
|
@@ -332,11 +336,15 @@ func unindexTransactions(db ethdb.Database, from uint64, to uint64, interrupt ch
|
|
|
|
|
log.Crit("Failed writing batch to db", "error", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
logger := log.Debug
|
|
|
|
|
if report {
|
|
|
|
|
logger = log.Info
|
|
|
|
|
}
|
|
|
|
|
select {
|
|
|
|
|
case <-interrupt:
|
|
|
|
|
log.Debug("Transaction unindexing interrupted", "blocks", blocks, "txs", txs, "tail", to, "elapsed", common.PrettyDuration(time.Since(start)))
|
|
|
|
|
logger("Transaction unindexing interrupted", "blocks", blocks, "txs", txs, "tail", to, "elapsed", common.PrettyDuration(time.Since(start)))
|
|
|
|
|
default:
|
|
|
|
|
log.Debug("Unindexed transactions", "blocks", blocks, "txs", txs, "tail", to, "elapsed", common.PrettyDuration(time.Since(start)))
|
|
|
|
|
logger("Unindexed transactions", "blocks", blocks, "txs", txs, "tail", to, "elapsed", common.PrettyDuration(time.Since(start)))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -345,11 +353,11 @@ func unindexTransactions(db ethdb.Database, from uint64, to uint64, interrupt ch
|
|
|
|
|
//
|
|
|
|
|
// There is a passed channel, the whole procedure will be interrupted if any
|
|
|
|
|
// signal received.
|
|
|
|
|
func UnindexTransactions(db ethdb.Database, from uint64, to uint64, interrupt chan struct{}) {
|
|
|
|
|
unindexTransactions(db, from, to, interrupt, nil)
|
|
|
|
|
func UnindexTransactions(db ethdb.Database, from uint64, to uint64, interrupt chan struct{}, report bool) {
|
|
|
|
|
unindexTransactions(db, from, to, interrupt, nil, report)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// unindexTransactionsForTesting is the internal debug version with an additional hook.
|
|
|
|
|
func unindexTransactionsForTesting(db ethdb.Database, from uint64, to uint64, interrupt chan struct{}, hook func(uint64) bool) {
|
|
|
|
|
unindexTransactions(db, from, to, interrupt, hook)
|
|
|
|
|
unindexTransactions(db, from, to, interrupt, hook, false)
|
|
|
|
|
}
|
|
|
|
|