aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-06-15 18:16:29 +0800
committerobscuren <geffobscura@gmail.com>2015-06-15 18:16:29 +0800
commit21fa29111b3cd12e3748fcb6310e6a18c5562f17 (patch)
tree511aef50b3d788a0ee109d1ec255d35153f8b3ff
parent6d817e16c1c17f7cad4a34fa91457e21f63f2de4 (diff)
downloadgo-tangerine-21fa29111b3cd12e3748fcb6310e6a18c5562f17.tar
go-tangerine-21fa29111b3cd12e3748fcb6310e6a18c5562f17.tar.gz
go-tangerine-21fa29111b3cd12e3748fcb6310e6a18c5562f17.tar.bz2
go-tangerine-21fa29111b3cd12e3748fcb6310e6a18c5562f17.tar.lz
go-tangerine-21fa29111b3cd12e3748fcb6310e6a18c5562f17.tar.xz
go-tangerine-21fa29111b3cd12e3748fcb6310e6a18c5562f17.tar.zst
go-tangerine-21fa29111b3cd12e3748fcb6310e6a18c5562f17.zip
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.
-rw-r--r--common/types.go11
-rw-r--r--core/transaction_pool.go19
2 files changed, 30 insertions, 0 deletions
diff --git a/common/types.go b/common/types.go
index 183d48fb3..d05c21eec 100644
--- a/common/types.go
+++ b/common/types.go
@@ -1,6 +1,7 @@
package common
import (
+ "fmt"
"math/big"
"math/rand"
"reflect"
@@ -95,3 +96,13 @@ func (a *Address) Set(other Address) {
a[i] = v
}
}
+
+// PP Pretty Prints a byte slice in the following format:
+// hex(value[:4])...(hex[len(value)-4:])
+func PP(value []byte) string {
+ if len(value) <= 8 {
+ return Bytes2Hex(value)
+ }
+
+ return fmt.Sprintf("%x...%x", value[:4], value[len(value)-4])
+}
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