Skip to content

Commit 21fa291

Browse files
committed
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.
1 parent 6d817e1 commit 21fa291

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

common/types.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package common
22

33
import (
4+
"fmt"
45
"math/big"
56
"math/rand"
67
"reflect"
@@ -95,3 +96,13 @@ func (a *Address) Set(other Address) {
9596
a[i] = v
9697
}
9798
}
99+
100+
// PP Pretty Prints a byte slice in the following format:
101+
// hex(value[:4])...(hex[len(value)-4:])
102+
func PP(value []byte) string {
103+
if len(value) <= 8 {
104+
return Bytes2Hex(value)
105+
}
106+
107+
return fmt.Sprintf("%x...%x", value[:4], value[len(value)-4])
108+
}

core/transaction_pool.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ var (
2828
ErrNegativeValue = errors.New("Negative value")
2929
)
3030

31+
const (
32+
maxQueued = 200 // max limit of queued txs per address
33+
)
34+
3135
type stateFn func() *state.StateDB
3236

3337
// TxPool contains all currently known transactions. Transactions
@@ -224,6 +228,21 @@ func (self *TxPool) queueTx(hash common.Hash, tx *types.Transaction) {
224228
self.queue[from] = make(map[common.Hash]*types.Transaction)
225229
}
226230
self.queue[from][hash] = tx
231+
232+
if len(self.queue[from]) > maxQueued {
233+
var (
234+
worstHash common.Hash
235+
worstNonce uint64
236+
)
237+
for hash, tx := range self.queue[from] {
238+
if tx.Nonce() > worstNonce {
239+
worstNonce = tx.Nonce()
240+
worstHash = hash
241+
}
242+
}
243+
glog.V(logger.Debug).Infof("Queued tx limit exceeded for %x. Removed worst nonce tx: %x\n", common.PP(from[:]), common.PP(worstHash[:]))
244+
delete(self.queue[from], worstHash)
245+
}
227246
}
228247

229248
// addTx will add a transaction to the pending (processable queue) list of transactions

0 commit comments

Comments
 (0)