aboutsummaryrefslogtreecommitdiffstats
path: root/core/tx_journal.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2018-05-18 16:45:52 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-05-18 17:08:24 +0800
commit49719e21bcd740c5890334f8c0ec8ac3777fb4c6 (patch)
tree81caf3f5e52d25597f16a21b61b4d91ee4e023b0 /core/tx_journal.go
parenta2e43d28d01ef9642c7f6992b78b86bd0696c847 (diff)
downloadgo-tangerine-49719e21bcd740c5890334f8c0ec8ac3777fb4c6.tar
go-tangerine-49719e21bcd740c5890334f8c0ec8ac3777fb4c6.tar.gz
go-tangerine-49719e21bcd740c5890334f8c0ec8ac3777fb4c6.tar.bz2
go-tangerine-49719e21bcd740c5890334f8c0ec8ac3777fb4c6.tar.lz
go-tangerine-49719e21bcd740c5890334f8c0ec8ac3777fb4c6.tar.xz
go-tangerine-49719e21bcd740c5890334f8c0ec8ac3777fb4c6.tar.zst
go-tangerine-49719e21bcd740c5890334f8c0ec8ac3777fb4c6.zip
core, eth: minor txpool event cleanups
Diffstat (limited to 'core/tx_journal.go')
-rw-r--r--core/tx_journal.go29
1 files changed, 14 insertions, 15 deletions
diff --git a/core/tx_journal.go b/core/tx_journal.go
index b344690b6..1397e9fd3 100644
--- a/core/tx_journal.go
+++ b/core/tx_journal.go
@@ -76,22 +76,21 @@ func (journal *txJournal) load(add func([]*types.Transaction) []error) error {
stream := rlp.NewStream(input, 0)
total, dropped := 0, 0
- // flush imports a batch of transactions and bump the appropriate progress counters
- flush := func(txs types.Transactions) {
- errs := add(txs)
- for _, err := range errs {
+ // Create a method to load a limited batch of transactions and bump the
+ // appropriate progress counters. Then use this method to load all the
+ // journalled transactions in small-ish batches.
+ loadBatch := func(txs types.Transactions) {
+ for _, err := range add(txs) {
if err != nil {
log.Debug("Failed to add journaled transaction", "err", err)
dropped++
}
}
}
-
var (
failure error
- txs types.Transactions
+ batch types.Transactions
)
-
for {
// Parse the next transaction and terminate on error
tx := new(types.Transaction)
@@ -99,19 +98,19 @@ func (journal *txJournal) load(add func([]*types.Transaction) []error) error {
if err != io.EOF {
failure = err
}
+ if batch.Len() > 0 {
+ loadBatch(batch)
+ }
break
}
- txs = append(txs, tx)
+ // New transaction parsed, queue up for later, import if threnshold is reached
total++
- if txs.Len() > 1024 {
- flush(txs)
- txs = types.Transactions{}
+
+ if batch = append(batch, tx); batch.Len() > 1024 {
+ loadBatch(batch)
+ batch = batch[:0]
}
}
- if txs.Len() > 0 {
- flush(txs)
- txs = types.Transactions{}
- }
log.Info("Loaded local transaction journal", "transactions", total, "dropped", dropped)
return failure