aboutsummaryrefslogtreecommitdiffstats
path: root/core/transaction_pool.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-06-04 23:28:09 +0800
committerobscuren <geffobscura@gmail.com>2015-06-05 01:28:39 +0800
commit912cf7ba049e4bcd5e497c62bb7cb96e7502f1b9 (patch)
tree7c573e1cad38ef08c9502488d24968c122b40b85 /core/transaction_pool.go
parent0f51ee6c88f0697cec368d6e2c88b35cc173e37a (diff)
downloaddexon-912cf7ba049e4bcd5e497c62bb7cb96e7502f1b9.tar
dexon-912cf7ba049e4bcd5e497c62bb7cb96e7502f1b9.tar.gz
dexon-912cf7ba049e4bcd5e497c62bb7cb96e7502f1b9.tar.bz2
dexon-912cf7ba049e4bcd5e497c62bb7cb96e7502f1b9.tar.lz
dexon-912cf7ba049e4bcd5e497c62bb7cb96e7502f1b9.tar.xz
dexon-912cf7ba049e4bcd5e497c62bb7cb96e7502f1b9.tar.zst
dexon-912cf7ba049e4bcd5e497c62bb7cb96e7502f1b9.zip
core: added fork test & double nonce test
Diffstat (limited to 'core/transaction_pool.go')
-rw-r--r--core/transaction_pool.go46
1 files changed, 26 insertions, 20 deletions
diff --git a/core/transaction_pool.go b/core/transaction_pool.go
index 462159fa7..27dc1b0d1 100644
--- a/core/transaction_pool.go
+++ b/core/transaction_pool.go
@@ -68,31 +68,37 @@ func (pool *TxPool) Start() {
pool.events = pool.eventMux.Subscribe(ChainEvent{})
for _ = range pool.events.Chan() {
pool.mu.Lock()
- pool.state = state.ManageState(pool.currentState())
-
- // validate the pool of pending transactions, this will remove
- // any transactions that have been included in the block or
- // have been invalidated because of another transaction (e.g.
- // higher gas price)
- pool.validatePool()
-
- // Loop over the pending transactions and base the nonce of the new
- // pending transaction set.
- for _, tx := range pool.pending {
- if addr, err := tx.From(); err == nil {
- // Set the nonce. Transaction nonce can never be lower
- // than the state nonce; validatePool took care of that.
- pool.state.SetNonce(addr, tx.Nonce())
- }
- }
- // Check the queue and move transactions over to the pending if possible
- // or remove those that have become invalid
- pool.checkQueue()
+ pool.resetState()
+
pool.mu.Unlock()
}
}
+func (pool *TxPool) resetState() {
+ pool.state = state.ManageState(pool.currentState())
+
+ // validate the pool of pending transactions, this will remove
+ // any transactions that have been included in the block or
+ // have been invalidated because of another transaction (e.g.
+ // higher gas price)
+ pool.validatePool()
+
+ // Loop over the pending transactions and base the nonce of the new
+ // pending transaction set.
+ for _, tx := range pool.pending {
+ if addr, err := tx.From(); err == nil {
+ // Set the nonce. Transaction nonce can never be lower
+ // than the state nonce; validatePool took care of that.
+ pool.state.SetNonce(addr, tx.Nonce())
+ }
+ }
+
+ // Check the queue and move transactions over to the pending if possible
+ // or remove those that have become invalid
+ pool.checkQueue()
+}
+
func (pool *TxPool) Stop() {
pool.pending = make(map[common.Hash]*types.Transaction)
close(pool.quit)