diff options
-rw-r--r-- | ethchain/state_manager.go | 2 | ||||
-rw-r--r-- | ethchain/transaction_pool.go | 17 |
2 files changed, 16 insertions, 3 deletions
diff --git a/ethchain/state_manager.go b/ethchain/state_manager.go index f830f2022..57d56469b 100644 --- a/ethchain/state_manager.go +++ b/ethchain/state_manager.go @@ -199,6 +199,8 @@ func (sm *StateManager) ProcessBlock(block *Block, dontReact bool) error { } sm.Ethereum.Broadcast(ethwire.MsgBlockTy, []interface{}{block.Value().Val}) + + sm.Ethereum.TxPool().RemoveInvalid(sm.procState) } else { fmt.Println("total diff failed") } diff --git a/ethchain/transaction_pool.go b/ethchain/transaction_pool.go index 56deae0c6..6c0282dc6 100644 --- a/ethchain/transaction_pool.go +++ b/ethchain/transaction_pool.go @@ -210,9 +210,9 @@ func (pool *TxPool) CurrentTransactions() []*Transaction { txList := make([]*Transaction, pool.pool.Len()) i := 0 for e := pool.pool.Front(); e != nil; e = e.Next() { - if tx, ok := e.Value.(*Transaction); ok { - txList[i] = tx - } + tx := e.Value.(*Transaction) + + txList[i] = tx i++ } @@ -220,6 +220,17 @@ func (pool *TxPool) CurrentTransactions() []*Transaction { return txList } +func (pool *TxPool) RemoveInvalid(state *State) { + for e := pool.pool.Front(); e != nil; e = e.Next() { + tx := e.Value.(*Transaction) + sender := state.GetAccount(tx.Sender()) + err := pool.ValidateTransaction(tx) + if err != nil || sender.Nonce != tx.Nonce { + pool.pool.Remove(e) + } + } +} + func (pool *TxPool) Flush() []*Transaction { txList := pool.CurrentTransactions() |