From 69e745c537e442d4086986b02c01741d2a314cf1 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 27 Oct 2014 16:52:58 +0100 Subject: Return erroneous txs (so we can remove them from the pool) --- ethchain/transaction_pool.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'ethchain/transaction_pool.go') diff --git a/ethchain/transaction_pool.go b/ethchain/transaction_pool.go index 063688aa8..7f8a5de42 100644 --- a/ethchain/transaction_pool.go +++ b/ethchain/transaction_pool.go @@ -35,6 +35,14 @@ type TxMsg struct { Type TxMsgTy } +func EachTx(pool *list.List, it func(*Transaction, *list.Element) bool) { + for e := pool.Front(); e != nil; e = e.Next() { + if it(e.Value.(*Transaction), e) { + break + } + } +} + func FindTx(pool *list.List, finder func(*Transaction, *list.Element) bool) *Transaction { for e := pool.Front(); e != nil; e = e.Next() { if tx, ok := e.Value.(*Transaction); ok { @@ -191,6 +199,9 @@ func (pool *TxPool) CurrentTransactions() []*Transaction { } func (pool *TxPool) RemoveInvalid(state *ethstate.State) { + pool.mutex.Lock() + defer pool.mutex.Unlock() + for e := pool.pool.Front(); e != nil; e = e.Next() { tx := e.Value.(*Transaction) sender := state.GetAccount(tx.Sender()) @@ -201,6 +212,21 @@ func (pool *TxPool) RemoveInvalid(state *ethstate.State) { } } +func (self *TxPool) RemoveSet(txs Transactions) { + self.mutex.Lock() + defer self.mutex.Unlock() + + for _, tx := range txs { + EachTx(self.pool, func(t *Transaction, element *list.Element) bool { + if t == tx { + self.pool.Remove(element) + return true // To stop the loop + } + return false + }) + } +} + func (pool *TxPool) Flush() []*Transaction { txList := pool.CurrentTransactions() -- cgit