aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-04-23 17:09:58 +0800
committerobscuren <geffobscura@gmail.com>2015-04-23 17:50:12 +0800
commit7f14fbd57936cf74627572da4a06585d35161ea9 (patch)
treed3c168060e3efffb945079be1d221d14b4ec79d1 /core
parent48135657c478ecffead52cdddaf2bbbaa89d388e (diff)
downloadgo-tangerine-7f14fbd57936cf74627572da4a06585d35161ea9.tar.gz
go-tangerine-7f14fbd57936cf74627572da4a06585d35161ea9.tar.zst
go-tangerine-7f14fbd57936cf74627572da4a06585d35161ea9.zip
core: pending txs now re-validated once every second
Diffstat (limited to 'core')
-rw-r--r--core/transaction_pool.go30
1 files changed, 27 insertions, 3 deletions
diff --git a/core/transaction_pool.go b/core/transaction_pool.go
index 7098dba23..392e17856 100644
--- a/core/transaction_pool.go
+++ b/core/transaction_pool.go
@@ -77,12 +77,18 @@ func NewTxPool(eventMux *event.TypeMux, currentStateFn stateFn) *TxPool {
}
func (pool *TxPool) Start() {
- ticker := time.NewTicker(300 * time.Millisecond)
+ // Queue timer will tick so we can attempt to move items from the queue to the
+ // main transaction pool.
+ queueTimer := time.NewTicker(300 * time.Millisecond)
+ // Removal timer will tick and attempt to remove bad transactions (account.nonce>tx.nonce)
+ removalTimer := time.NewTicker(1 * time.Second)
done:
for {
select {
- case <-ticker.C:
+ case <-queueTimer.C:
pool.checkQueue()
+ case <-removalTimer.C:
+ pool.validatePool()
case <-pool.quit:
break done
}
@@ -253,11 +259,12 @@ func (pool *TxPool) checkQueue() {
pool.mu.Lock()
defer pool.mu.Unlock()
+ statedb := pool.currentState()
for address, txs := range pool.queue {
sort.Sort(types.TxByNonce{txs})
var (
- nonce = pool.currentState().GetNonce(address)
+ nonce = statedb.GetNonce(address)
start int
)
// Clean up the transactions first and determine the start of the nonces
@@ -288,3 +295,20 @@ func (pool *TxPool) checkQueue() {
}
}
}
+
+func (pool *TxPool) validatePool() {
+ pool.mu.Lock()
+ defer pool.mu.Unlock()
+
+ statedb := pool.currentState()
+ for hash, tx := range pool.txs {
+ from, _ := tx.From()
+ if nonce := statedb.GetNonce(from); nonce > tx.Nonce() {
+ if glog.V(logger.Debug) {
+ glog.Infof("removed tx (%x) from pool due to nonce error. state=%d tx=%d\n", hash[:4], nonce, tx.Nonce())
+ }
+
+ delete(pool.txs, hash)
+ }
+ }
+}