From 1c45f2f42e6578258e74c790d063b8639ec58bc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Tue, 8 Aug 2017 11:59:34 +0300 Subject: core: fix txpool journal and test races --- core/tx_pool.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'core/tx_pool.go') diff --git a/core/tx_pool.go b/core/tx_pool.go index 16f774265..b0c251f92 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -207,7 +207,7 @@ func NewTxPool(config TxPoolConfig, chainconfig *params.ChainConfig, eventMux *e } pool.locals = newAccountSet(pool.signer) pool.priced = newTxPricedList(&pool.all) - pool.resetState() + pool.reset() // If local transactions and journaling is enabled, load from disk if !config.NoLocals && config.Journal != "" { @@ -261,7 +261,7 @@ func (pool *TxPool) loop() { pool.homestead = true } } - pool.resetState() + pool.reset() pool.mu.Unlock() case RemovedTransactionEvent: @@ -300,15 +300,28 @@ func (pool *TxPool) loop() { // Handle local transaction journal rotation case <-journal.C: if pool.journal != nil { + pool.mu.Lock() if err := pool.journal.rotate(pool.local()); err != nil { log.Warn("Failed to rotate local tx journal", "err", err) } + pool.mu.Unlock() } } } } -func (pool *TxPool) resetState() { +// lockedReset is a wrapper around reset to allow calling it in a thread safe +// manner. This method is only ever used in the tester! +func (pool *TxPool) lockedReset() { + pool.mu.Lock() + defer pool.mu.Unlock() + + pool.reset() +} + +// reset retrieves the current state of the blockchain and ensures the content +// of the transaction pool is valid with regard to the chain state. +func (pool *TxPool) reset() { currentState, err := pool.currentState() if err != nil { log.Error("Failed reset txpool state", "err", err) -- cgit v1.2.3