From 27ce4eb78bdf5d9b742ed05babe9b86a434733a1 Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Thu, 20 Dec 2018 07:00:58 -0600 Subject: [PATCH] core: sanitize more TxPoolConfig fields (#17210) * core: sanitize more TxPoolConfig fields * core: fix TestTransactionPendingMinimumAllowance --- core/tx_pool.go | 20 ++++++++++++++++++++ core/tx_pool_test.go | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/core/tx_pool.go b/core/tx_pool.go index fc35d1f243..552d3692b3 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -172,6 +172,26 @@ func (config *TxPoolConfig) sanitize() TxPoolConfig { log.Warn("Sanitizing invalid txpool price bump", "provided", conf.PriceBump, "updated", DefaultTxPoolConfig.PriceBump) conf.PriceBump = DefaultTxPoolConfig.PriceBump } + if conf.AccountSlots < 1 { + log.Warn("Sanitizing invalid txpool account slots", "provided", conf.AccountSlots, "updated", DefaultTxPoolConfig.AccountSlots) + conf.AccountSlots = DefaultTxPoolConfig.AccountSlots + } + if conf.GlobalSlots < 1 { + log.Warn("Sanitizing invalid txpool global slots", "provided", conf.GlobalSlots, "updated", DefaultTxPoolConfig.GlobalSlots) + conf.GlobalSlots = DefaultTxPoolConfig.GlobalSlots + } + if conf.AccountQueue < 1 { + log.Warn("Sanitizing invalid txpool account queue", "provided", conf.AccountQueue, "updated", DefaultTxPoolConfig.AccountQueue) + conf.AccountQueue = DefaultTxPoolConfig.AccountQueue + } + if conf.GlobalQueue < 1 { + log.Warn("Sanitizing invalid txpool global queue", "provided", conf.GlobalQueue, "updated", DefaultTxPoolConfig.GlobalQueue) + conf.GlobalQueue = DefaultTxPoolConfig.GlobalQueue + } + if conf.Lifetime < 1 { + log.Warn("Sanitizing invalid txpool lifetime", "provided", conf.Lifetime, "updated", DefaultTxPoolConfig.Lifetime) + conf.Lifetime = DefaultTxPoolConfig.Lifetime + } return conf } diff --git a/core/tx_pool_test.go b/core/tx_pool_test.go index 5a59205442..6d3bd7a5a5 100644 --- a/core/tx_pool_test.go +++ b/core/tx_pool_test.go @@ -1095,7 +1095,7 @@ func TestTransactionPendingMinimumAllowance(t *testing.T) { blockchain := &testBlockChain{statedb, 1000000, new(event.Feed)} config := testTxPoolConfig - config.GlobalSlots = 0 + config.GlobalSlots = 1 pool := NewTxPool(config, params.TestChainConfig, blockchain) defer pool.Stop()