From 21fa29111b3cd12e3748fcb6310e6a18c5562f17 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 15 Jun 2015 12:16:29 +0200 Subject: core: reduce max allowed queued txs per address Transactions in the queue are now capped to a maximum of 200 transactions. This number is completely arbitrary. --- core/transaction_pool.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'core/transaction_pool.go') diff --git a/core/transaction_pool.go b/core/transaction_pool.go index 8f917e96a..ce6fed1a9 100644 --- a/core/transaction_pool.go +++ b/core/transaction_pool.go @@ -28,6 +28,10 @@ var ( ErrNegativeValue = errors.New("Negative value") ) +const ( + maxQueued = 200 // max limit of queued txs per address +) + type stateFn func() *state.StateDB // TxPool contains all currently known transactions. Transactions @@ -224,6 +228,21 @@ func (self *TxPool) queueTx(hash common.Hash, tx *types.Transaction) { self.queue[from] = make(map[common.Hash]*types.Transaction) } self.queue[from][hash] = tx + + if len(self.queue[from]) > maxQueued { + var ( + worstHash common.Hash + worstNonce uint64 + ) + for hash, tx := range self.queue[from] { + if tx.Nonce() > worstNonce { + worstNonce = tx.Nonce() + worstHash = hash + } + } + glog.V(logger.Debug).Infof("Queued tx limit exceeded for %x. Removed worst nonce tx: %x\n", common.PP(from[:]), common.PP(worstHash[:])) + delete(self.queue[from], worstHash) + } } // addTx will add a transaction to the pending (processable queue) list of transactions -- cgit v1.2.3