diff options
author | rjl493456442 <garyrong0905@gmail.com> | 2018-05-10 15:04:45 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2018-05-18 16:46:44 +0800 |
commit | a2e43d28d01ef9642c7f6992b78b86bd0696c847 (patch) | |
tree | 2f5d3444071125e84155321db6fd79d941cfee0b /core/tx_journal.go | |
parent | 6286c255f16a914b39ffd3389cba154a53e66a13 (diff) | |
download | dexon-a2e43d28d01ef9642c7f6992b78b86bd0696c847.tar dexon-a2e43d28d01ef9642c7f6992b78b86bd0696c847.tar.gz dexon-a2e43d28d01ef9642c7f6992b78b86bd0696c847.tar.bz2 dexon-a2e43d28d01ef9642c7f6992b78b86bd0696c847.tar.lz dexon-a2e43d28d01ef9642c7f6992b78b86bd0696c847.tar.xz dexon-a2e43d28d01ef9642c7f6992b78b86bd0696c847.tar.zst dexon-a2e43d28d01ef9642c7f6992b78b86bd0696c847.zip |
all: collate new transaction events together
Diffstat (limited to 'core/tx_journal.go')
-rw-r--r-- | core/tx_journal.go | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/core/tx_journal.go b/core/tx_journal.go index e872d7b53..b344690b6 100644 --- a/core/tx_journal.go +++ b/core/tx_journal.go @@ -56,7 +56,7 @@ func newTxJournal(path string) *txJournal { // load parses a transaction journal dump from disk, loading its contents into // the specified pool. -func (journal *txJournal) load(add func(*types.Transaction) error) error { +func (journal *txJournal) load(add func([]*types.Transaction) []error) error { // Skip the parsing if the journal file doens't exist at all if _, err := os.Stat(journal.path); os.IsNotExist(err) { return nil @@ -76,7 +76,22 @@ func (journal *txJournal) load(add func(*types.Transaction) error) error { stream := rlp.NewStream(input, 0) total, dropped := 0, 0 - var failure error + // flush imports a batch of transactions and bump the appropriate progress counters + flush := func(txs types.Transactions) { + errs := add(txs) + for _, err := range errs { + if err != nil { + log.Debug("Failed to add journaled transaction", "err", err) + dropped++ + } + } + } + + var ( + failure error + txs types.Transactions + ) + for { // Parse the next transaction and terminate on error tx := new(types.Transaction) @@ -86,14 +101,17 @@ func (journal *txJournal) load(add func(*types.Transaction) error) error { } break } - // Import the transaction and bump the appropriate progress counters + txs = append(txs, tx) total++ - if err = add(tx); err != nil { - log.Debug("Failed to add journaled transaction", "err", err) - dropped++ - continue + if txs.Len() > 1024 { + flush(txs) + txs = types.Transactions{} } } + if txs.Len() > 0 { + flush(txs) + txs = types.Transactions{} + } log.Info("Loaded local transaction journal", "transactions", total, "dropped", dropped) return failure |