diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-08-08 16:59:34 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2017-08-08 17:22:01 +0800 |
commit | 1c45f2f42e6578258e74c790d063b8639ec58bc6 (patch) | |
tree | c991999fc5f15ec38e87f56aa89bd9a2f98aacde /core/tx_pool.go | |
parent | 971079822ee6c12d9348ec78f212fe91c9b83edf (diff) | |
download | dexon-1c45f2f42e6578258e74c790d063b8639ec58bc6.tar dexon-1c45f2f42e6578258e74c790d063b8639ec58bc6.tar.gz dexon-1c45f2f42e6578258e74c790d063b8639ec58bc6.tar.bz2 dexon-1c45f2f42e6578258e74c790d063b8639ec58bc6.tar.lz dexon-1c45f2f42e6578258e74c790d063b8639ec58bc6.tar.xz dexon-1c45f2f42e6578258e74c790d063b8639ec58bc6.tar.zst dexon-1c45f2f42e6578258e74c790d063b8639ec58bc6.zip |
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) |