diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-08-08 18:20:36 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-08 18:20:36 +0800 |
commit | 9a7e99f75d09dc7835d3335d97a37f153d480cc6 (patch) | |
tree | 471ba01b123b7bb130753ece9d8c77281b859eb9 /core/tx_pool.go | |
parent | 6f8c7b0defd4df773a1c9d630514016d3b914897 (diff) | |
parent | 1c45f2f42e6578258e74c790d063b8639ec58bc6 (diff) | |
download | dexon-9a7e99f75d09dc7835d3335d97a37f153d480cc6.tar dexon-9a7e99f75d09dc7835d3335d97a37f153d480cc6.tar.gz dexon-9a7e99f75d09dc7835d3335d97a37f153d480cc6.tar.bz2 dexon-9a7e99f75d09dc7835d3335d97a37f153d480cc6.tar.lz dexon-9a7e99f75d09dc7835d3335d97a37f153d480cc6.tar.xz dexon-9a7e99f75d09dc7835d3335d97a37f153d480cc6.tar.zst dexon-9a7e99f75d09dc7835d3335d97a37f153d480cc6.zip |
Merge pull request #14940 from karalabe/txpool-races
core: fix txpool journal and test races
Diffstat (limited to 'core/tx_pool.go')
-rw-r--r-- | core/tx_pool.go | 19 |
1 files changed, 16 insertions, 3 deletions
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) |