diff --git a/cmd/harmony/config_migrations.go b/cmd/harmony/config_migrations.go index 23e2e9bea..e273dcfbb 100644 --- a/cmd/harmony/config_migrations.go +++ b/cmd/harmony/config_migrations.go @@ -220,4 +220,13 @@ func init() { confTree.Set("Version", "2.5.0") return confTree } + + migrations["2.5.0"] = func(confTree *toml.Tree) *toml.Tree { + if confTree.Get("TxPool.AccountSlots") == nil { + confTree.Set("TxPool.AccountSlots", defaultConfig.TxPool.AccountSlots) + } + + confTree.Set("Version", "2.5.1") + return confTree + } } diff --git a/cmd/harmony/default.go b/cmd/harmony/default.go index 1ceeb3f4c..2aed3ec20 100644 --- a/cmd/harmony/default.go +++ b/cmd/harmony/default.go @@ -5,7 +5,7 @@ import ( nodeconfig "github.com/harmony-one/harmony/internal/configs/node" ) -const tomlConfigVersion = "2.5.0" +const tomlConfigVersion = "2.5.1" // bump from 2.5.0 for AccountSlots const ( defNetworkType = nodeconfig.Mainnet @@ -65,6 +65,7 @@ var defaultConfig = harmonyconfig.HarmonyConfig{ TxPool: harmonyconfig.TxPoolConfig{ BlacklistFile: "./.hmy/blacklist.txt", RosettaFixFile: "", + AccountSlots: 16, }, Sync: getDefaultSyncConfig(defNetworkType), Pprof: harmonyconfig.PprofConfig{ diff --git a/cmd/harmony/flags.go b/cmd/harmony/flags.go index 72b4ca3e6..1080855c0 100644 --- a/cmd/harmony/flags.go +++ b/cmd/harmony/flags.go @@ -123,6 +123,7 @@ var ( } txPoolFlags = []cli.Flag{ + tpAccountSlotsFlag, rosettaFixFileFlag, tpBlacklistFileFlag, legacyTPBlacklistFileFlag, @@ -977,6 +978,11 @@ func applyConsensusFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig // transaction pool flags var ( + tpAccountSlotsFlag = cli.IntFlag{ + Name: "txpool.accountslots", + Usage: "number of executable transaction slots guaranteed per account", + DefValue: int(defaultConfig.TxPool.AccountSlots), + } tpBlacklistFileFlag = cli.StringFlag{ Name: "txpool.blacklist", Usage: "file of blacklisted wallet addresses", @@ -999,7 +1005,13 @@ func applyTxPoolFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) { if cli.IsFlagChanged(cmd, rosettaFixFileFlag) { config.TxPool.RosettaFixFile = cli.GetStringFlagValue(cmd, rosettaFixFileFlag) } - + if cli.IsFlagChanged(cmd, tpAccountSlotsFlag) { + value := cli.GetIntFlagValue(cmd, tpAccountSlotsFlag) // int, so fits in uint64 when positive + if value <= 0 { + panic("Must provide positive for txpool.accountslots") + } + config.TxPool.AccountSlots = uint64(cli.GetIntFlagValue(cmd, tpAccountSlotsFlag)) + } if cli.IsFlagChanged(cmd, tpBlacklistFileFlag) { config.TxPool.BlacklistFile = cli.GetStringFlagValue(cmd, tpBlacklistFileFlag) } else if cli.IsFlagChanged(cmd, legacyTPBlacklistFileFlag) { diff --git a/cmd/harmony/flags_test.go b/cmd/harmony/flags_test.go index a662ed524..feb5e54c3 100644 --- a/cmd/harmony/flags_test.go +++ b/cmd/harmony/flags_test.go @@ -102,6 +102,7 @@ func TestHarmonyFlags(t *testing.T) { TxPool: harmonyconfig.TxPoolConfig{ BlacklistFile: "./.hmy/blacklist.txt", RosettaFixFile: "", + AccountSlots: 16, }, Pprof: harmonyconfig.PprofConfig{ Enabled: false, @@ -780,6 +781,7 @@ func TestTxPoolFlags(t *testing.T) { expConfig: harmonyconfig.TxPoolConfig{ BlacklistFile: defaultConfig.TxPool.BlacklistFile, RosettaFixFile: defaultConfig.TxPool.RosettaFixFile, + AccountSlots: defaultConfig.TxPool.AccountSlots, }, }, { @@ -787,6 +789,7 @@ func TestTxPoolFlags(t *testing.T) { expConfig: harmonyconfig.TxPoolConfig{ BlacklistFile: "blacklist.file", RosettaFixFile: "rosettafix.file", + AccountSlots: 16, // default }, }, { @@ -794,6 +797,15 @@ func TestTxPoolFlags(t *testing.T) { expConfig: harmonyconfig.TxPoolConfig{ BlacklistFile: "blacklist.file", RosettaFixFile: "rosettafix.file", + AccountSlots: 16, // default + }, + }, + { + args: []string{"--txpool.accountslots", "5", "--txpool.blacklist", "blacklist.file", "--txpool.rosettafixfile", "rosettafix.file"}, + expConfig: harmonyconfig.TxPoolConfig{ + AccountSlots: 5, + BlacklistFile: "blacklist.file", + RosettaFixFile: "rosettafix.file", }, }, } diff --git a/core/tx_pool.go b/core/tx_pool.go index ec0e61e58..11e0c3a6b 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -213,6 +213,13 @@ func (config *TxPoolConfig) sanitize() TxPoolConfig { utils.Logger().Warn().Msg("Sanitizing nil blacklist set") conf.Blacklist = DefaultTxPoolConfig.Blacklist } + if conf.AccountSlots == 0 { + utils.Logger().Warn(). + Uint64("provided", conf.AccountSlots). + Uint64("updated", DefaultTxPoolConfig.AccountSlots). + Msg("Sanitizing invalid txpool account slots") + conf.AccountSlots = DefaultTxPoolConfig.AccountSlots + } return conf } diff --git a/internal/configs/harmony/harmony.go b/internal/configs/harmony/harmony.go index a73004d71..b1079e4c9 100644 --- a/internal/configs/harmony/harmony.go +++ b/internal/configs/harmony/harmony.go @@ -88,6 +88,7 @@ type BlsConfig struct { type TxPoolConfig struct { BlacklistFile string RosettaFixFile string + AccountSlots uint64 } type PprofConfig struct { diff --git a/node/node.go b/node/node.go index 4c77c2c40..4b6b78446 100644 --- a/node/node.go +++ b/node/node.go @@ -1034,6 +1034,9 @@ func New( txPoolConfig.PriceLimit = 1e9 txPoolConfig.PriceBump = 10 } + if harmonyconfig != nil { + txPoolConfig.AccountSlots = harmonyconfig.TxPool.AccountSlots + } txPoolConfig.Blacklist = blacklist txPoolConfig.Journal = fmt.Sprintf("%v/%v", node.NodeConfig.DBDir, txPoolConfig.Journal) diff --git a/rosetta/infra/harmony-mainnet.conf b/rosetta/infra/harmony-mainnet.conf index dd77d06e3..6d2936d93 100644 --- a/rosetta/infra/harmony-mainnet.conf +++ b/rosetta/infra/harmony-mainnet.conf @@ -1,4 +1,4 @@ -Version = "2.5.0" +Version = "2.5.1" [BLSKeys] KMSConfigFile = "" @@ -90,6 +90,7 @@ Version = "2.5.0" [TxPool] BlacklistFile = "./.hmy/blacklist.txt" RosettaFixFile = "./rosetta_local_fix.csv" + AccountSlots = 16 [WS] AuthPort = 9801 diff --git a/rosetta/infra/harmony-pstn.conf b/rosetta/infra/harmony-pstn.conf index 7d78c7012..7b2645e9f 100644 --- a/rosetta/infra/harmony-pstn.conf +++ b/rosetta/infra/harmony-pstn.conf @@ -1,4 +1,4 @@ -Version = "2.5.0" +Version = "2.5.1" [BLSKeys] KMSConfigFile = "" @@ -89,6 +89,7 @@ Version = "2.5.0" [TxPool] BlacklistFile = "./.hmy/blacklist.txt" + AccountSlots = 16 [WS] AuthPort = 9801