From a117d37877754881d200c12f0225cee983fe6124 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Mon, 10 Jul 2017 16:21:42 +0300 Subject: [PATCH] core: journal replacement pending transactions too --- core/tx_pool.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/core/tx_pool.go b/core/tx_pool.go index c672aae027..13bc398341 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -521,6 +521,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (bool, error) { } pool.all[tx.Hash()] = tx pool.priced.Put(tx) + pool.journalTx(from, tx) log.Trace("Pooled new executable transaction", "hash", hash, "from", from, "to", tx.To()) return old != nil, nil @@ -531,15 +532,11 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (bool, error) { return false, err } // Mark local addresses and journal local transactions - local = local || pool.locals.contains(from) if local { pool.locals.add(from) - if pool.journal != nil { - if err := rlp.Encode(pool.journal, tx); err != nil { - log.Warn("Failed to journal local transaction", "err", err) - } - } } + pool.journalTx(from, tx) + log.Trace("Pooled new future transaction", "hash", hash, "from", from, "to", tx.To()) return replace, nil } @@ -570,6 +567,18 @@ func (pool *TxPool) enqueueTx(hash common.Hash, tx *types.Transaction) (bool, er return old != nil, nil } +// journalTx adds the specified transaction to the local disk journal if it is +// deemed to have been sent from a local account. +func (pool *TxPool) journalTx(from common.Address, tx *types.Transaction) { + // Only journal if it's enabled and the transaction is local + if pool.journal == nil || !pool.locals.contains(from) { + return + } + if err := rlp.Encode(pool.journal, tx); err != nil { + log.Warn("Failed to journal local transaction", "err", err) + } +} + // promoteTx adds a transaction to the pending (processable) list of transactions. // // Note, this method assumes the pool lock is held!