Configurable tx pool. (#4240)

* AccountQueue & GlobalQueue.

* Lifetime duration.

* [pool] make flags configurable

* [pool] use 4096 as default `GlobalSlots`

* [rosetta] update default values of tx pool

* [test] update value to default

* PriceLimit and PriceBump.

* Fix tests.

* Fix price limit & bump.

* Updated, fixed migrate version and tests.

* Rebased.

* Fix go toml version.

---------

Co-authored-by: Konstantin <k.potapov@softpro.com>
Co-authored-by: MaxMustermann2 <82761650+MaxMustermann2@users.noreply.github.com>
pull/4395/head
Konstantin 2 years ago committed by GitHub
parent 49609d99d5
commit a1775465d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      cmd/harmony/config_migrations.go
  2. 26
      cmd/harmony/config_migrations_test.go
  3. 10
      cmd/harmony/config_test.go
  4. 12
      cmd/harmony/default.go
  5. 68
      cmd/harmony/flags.go
  6. 54
      cmd/harmony/flags_test.go
  7. 31
      core/tx_pool.go
  8. 2
      go.sum
  9. 29
      internal/configs/harmony/harmony.go
  10. 37
      internal/configs/harmony/harmony_test.go
  11. 15
      node/node.go
  12. 6
      rosetta/infra/harmony-mainnet.conf
  13. 6
      rosetta/infra/harmony-pstn.conf

@ -8,7 +8,7 @@ import (
"strings" "strings"
goversion "github.com/hashicorp/go-version" goversion "github.com/hashicorp/go-version"
"github.com/pelletier/go-toml" "github.com/pelletier/go-toml" // TODO support go-toml/v2
"github.com/harmony-one/harmony/api/service/legacysync" "github.com/harmony-one/harmony/api/service/legacysync"
harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony" harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony"
@ -357,6 +357,27 @@ func init() {
return confTree return confTree
} }
migrations["2.5.13"] = func(confTree *toml.Tree) *toml.Tree {
if confTree.Get("TxPool.AccountQueue") == nil {
confTree.Set("TxPool.AccountQueue", defaultConfig.TxPool.AccountQueue)
}
if confTree.Get("TxPool.GlobalQueue") == nil {
confTree.Set("TxPool.GlobalQueue", defaultConfig.TxPool.GlobalQueue)
}
if confTree.Get("TxPool.Lifetime") == nil {
confTree.Set("TxPool.Lifetime", defaultConfig.TxPool.Lifetime.String())
}
if confTree.Get("TxPool.PriceLimit") == nil {
confTree.Set("TxPool.PriceLimit", defaultConfig.TxPool.PriceLimit)
}
if confTree.Get("TxPool.PriceBump") == nil {
confTree.Set("TxPool.PriceBump", defaultConfig.TxPool.PriceBump)
}
confTree.Set("Version", "2.5.14")
return confTree
}
// check that the latest version here is the same as in default.go // check that the latest version here is the same as in default.go
largestKey := getNextVersion(migrations) largestKey := getNextVersion(migrations)
if largestKey != tomlConfigVersion { if largestKey != tomlConfigVersion {

@ -1,10 +1,10 @@
package main package main
import ( import (
"reflect"
"testing" "testing"
harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony" harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony"
"github.com/stretchr/testify/require"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node" nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
) )
@ -72,6 +72,11 @@ Version = "1.0.2"
[TxPool] [TxPool]
BlacklistFile = "./.hmy/blacklist.txt" BlacklistFile = "./.hmy/blacklist.txt"
LocalAccountsFile = "./.hmy/locals.txt" LocalAccountsFile = "./.hmy/locals.txt"
AccountQueue = 64
GlobalQueue = 5120
Lifetime = "30m"
PriceBump = 1
PriceLimit = 100e9
[WS] [WS]
Enabled = true Enabled = true
@ -142,6 +147,11 @@ Version = "1.0.3"
[TxPool] [TxPool]
BlacklistFile = "./.hmy/blacklist.txt" BlacklistFile = "./.hmy/blacklist.txt"
LocalAccountsFile = "./.hmy/locals.txt" LocalAccountsFile = "./.hmy/locals.txt"
AccountQueue = 64
GlobalQueue = 5120
Lifetime = "30m"
PriceBump = 1
PriceLimit = 100e9
[WS] [WS]
Enabled = true Enabled = true
@ -224,6 +234,11 @@ Version = "1.0.4"
[TxPool] [TxPool]
BlacklistFile = "./.hmy/blacklist.txt" BlacklistFile = "./.hmy/blacklist.txt"
LocalAccountsFile = "./.hmy/locals.txt" LocalAccountsFile = "./.hmy/locals.txt"
AccountQueue = 64
GlobalQueue = 5120
Lifetime = "30m"
PriceBump = 1
PriceLimit = 100e9
[WS] [WS]
Enabled = true Enabled = true
@ -314,6 +329,11 @@ Version = "1.0.4"
BlacklistFile = "./.hmy/blacklist.txt" BlacklistFile = "./.hmy/blacklist.txt"
LocalAccountsFile = "./.hmy/locals.txt" LocalAccountsFile = "./.hmy/locals.txt"
AllowedTxsFile = "./.hmy/allowedtxs.txt" AllowedTxsFile = "./.hmy/allowedtxs.txt"
AccountQueue = 64
GlobalQueue = 5120
Lifetime = "30m"
PriceBump = 1
PriceLimit = 100e9
[WS] [WS]
Enabled = true Enabled = true
@ -389,9 +409,7 @@ func Test_migrateConf(t *testing.T) {
t.Errorf("migrateConf() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("migrateConf() error = %v, wantErr %v", err, tt.wantErr)
return return
} }
if !reflect.DeepEqual(got, tt.want) { require.Equal(t, tt.want, got)
t.Errorf("migrateConf() = %+v, want %+v", got, tt.want)
}
}) })
} }
} }

@ -9,6 +9,7 @@ import (
"testing" "testing"
harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony" harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony"
"github.com/stretchr/testify/require"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node" nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
) )
@ -86,6 +87,11 @@ Version = "1.0.4"
BlacklistFile = "./.hmy/blacklist.txt" BlacklistFile = "./.hmy/blacklist.txt"
LocalAccountsFile = "./.hmy/locals.txt" LocalAccountsFile = "./.hmy/locals.txt"
AllowedTxsFile = "./.hmy/allowedtxs.txt" AllowedTxsFile = "./.hmy/allowedtxs.txt"
AccountQueue = 64
GlobalQueue = 5120
Lifetime = "30m"
PriceBump = 1
PriceLimit = 100e9
[Sync] [Sync]
Downloader = false Downloader = false
@ -136,9 +142,7 @@ Version = "1.0.4"
t.Errorf("Expected config version: 1.0.4, not %v", config.Version) t.Errorf("Expected config version: 1.0.4, not %v", config.Version)
} }
config.Version = defConf.Version // Shortcut for testing, value checked above config.Version = defConf.Version // Shortcut for testing, value checked above
if !reflect.DeepEqual(config, defConf) { require.Equal(t, config, defConf)
t.Errorf("Unexpected config \n\t%+v \n\t%+v", config, defaultConfig)
}
} }
func TestPersistConfig(t *testing.T) { func TestPersistConfig(t *testing.T) {

@ -1,11 +1,12 @@
package main package main
import ( import (
"github.com/harmony-one/harmony/core"
harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony" harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node" nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
) )
const tomlConfigVersion = "2.5.13" const tomlConfigVersion = "2.5.14"
const ( const (
defNetworkType = nodeconfig.Mainnet defNetworkType = nodeconfig.Mainnet
@ -81,9 +82,14 @@ var defaultConfig = harmonyconfig.HarmonyConfig{
BlacklistFile: "./.hmy/blacklist.txt", BlacklistFile: "./.hmy/blacklist.txt",
AllowedTxsFile: "./.hmy/allowedtxs.txt", AllowedTxsFile: "./.hmy/allowedtxs.txt",
RosettaFixFile: "", RosettaFixFile: "",
AccountSlots: 16, AccountSlots: core.DefaultTxPoolConfig.AccountSlots,
LocalAccountsFile: "./.hmy/locals.txt", LocalAccountsFile: "./.hmy/locals.txt",
GlobalSlots: 5120, GlobalSlots: core.DefaultTxPoolConfig.GlobalSlots,
AccountQueue: core.DefaultTxPoolConfig.AccountQueue,
GlobalQueue: core.DefaultTxPoolConfig.GlobalQueue,
Lifetime: core.DefaultTxPoolConfig.Lifetime,
PriceLimit: harmonyconfig.PriceLimit(core.DefaultTxPoolConfig.PriceLimit),
PriceBump: core.DefaultTxPoolConfig.PriceBump,
}, },
Sync: getDefaultSyncConfig(defNetworkType), Sync: getDefaultSyncConfig(defNetworkType),
Pprof: harmonyconfig.PprofConfig{ Pprof: harmonyconfig.PprofConfig{

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"strconv" "strconv"
"strings" "strings"
"time"
harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony" harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony"
@ -139,12 +140,17 @@ var (
txPoolFlags = []cli.Flag{ txPoolFlags = []cli.Flag{
tpAccountSlotsFlag, tpAccountSlotsFlag,
tpGlobalSlotsFlag,
tpAccountQueueFlag,
tpGlobalQueueFlag,
tpLifetimeFlag,
rosettaFixFileFlag, rosettaFixFileFlag,
tpBlacklistFileFlag, tpBlacklistFileFlag,
legacyTPBlacklistFileFlag, legacyTPBlacklistFileFlag,
localAccountsFileFlag, localAccountsFileFlag,
allowedTxsFileFlag, allowedTxsFileFlag,
tpGlobalSlotsFlag, tpPriceLimitFlag,
tpPriceBumpFlag,
} }
pprofFlags = []cli.Flag{ pprofFlags = []cli.Flag{
@ -1186,6 +1192,31 @@ var (
Usage: "maximum global number of non-executable transactions in the pool", Usage: "maximum global number of non-executable transactions in the pool",
DefValue: int(defaultConfig.TxPool.GlobalSlots), DefValue: int(defaultConfig.TxPool.GlobalSlots),
} }
tpAccountQueueFlag = cli.IntFlag{
Name: "txpool.accountqueue",
Usage: "capacity of queued transactions for account in the pool",
DefValue: int(defaultConfig.TxPool.AccountQueue),
}
tpGlobalQueueFlag = cli.IntFlag{
Name: "txpool.globalqueue",
Usage: "global capacity for queued transactions in the pool",
DefValue: int(defaultConfig.TxPool.GlobalQueue),
}
tpLifetimeFlag = cli.StringFlag{
Name: "txpool.lifetime",
Usage: "maximum lifetime of transactions in the pool as a golang duration string",
DefValue: defaultConfig.TxPool.Lifetime.String(),
}
tpPriceLimitFlag = cli.IntFlag{
Name: "txpool.pricelimit",
Usage: "minimum gas price to enforce for acceptance into the pool",
DefValue: int(defaultConfig.TxPool.PriceLimit),
}
tpPriceBumpFlag = cli.IntFlag{
Name: "txpool.pricebump",
Usage: "minimum price bump to replace an already existing transaction (nonce)",
DefValue: int(defaultConfig.TxPool.PriceLimit),
}
) )
func applyTxPoolFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) { func applyTxPoolFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
@ -1206,6 +1237,20 @@ func applyTxPoolFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
} }
config.TxPool.GlobalSlots = uint64(value) config.TxPool.GlobalSlots = uint64(value)
} }
if cli.IsFlagChanged(cmd, tpAccountQueueFlag) {
value := cli.GetIntFlagValue(cmd, tpAccountQueueFlag)
if value <= 0 {
panic("Must provide positive value for txpool.accountqueue")
}
config.TxPool.AccountQueue = uint64(value)
}
if cli.IsFlagChanged(cmd, tpGlobalQueueFlag) {
value := cli.GetIntFlagValue(cmd, tpGlobalQueueFlag)
if value <= 0 {
panic("Must provide positive value for txpool.globalqueue")
}
config.TxPool.GlobalQueue = uint64(value)
}
if cli.IsFlagChanged(cmd, tpBlacklistFileFlag) { if cli.IsFlagChanged(cmd, tpBlacklistFileFlag) {
config.TxPool.BlacklistFile = cli.GetStringFlagValue(cmd, tpBlacklistFileFlag) config.TxPool.BlacklistFile = cli.GetStringFlagValue(cmd, tpBlacklistFileFlag)
} else if cli.IsFlagChanged(cmd, legacyTPBlacklistFileFlag) { } else if cli.IsFlagChanged(cmd, legacyTPBlacklistFileFlag) {
@ -1217,6 +1262,27 @@ func applyTxPoolFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
if cli.IsFlagChanged(cmd, allowedTxsFileFlag) { if cli.IsFlagChanged(cmd, allowedTxsFileFlag) {
config.TxPool.AllowedTxsFile = cli.GetStringFlagValue(cmd, allowedTxsFileFlag) config.TxPool.AllowedTxsFile = cli.GetStringFlagValue(cmd, allowedTxsFileFlag)
} }
if cli.IsFlagChanged(cmd, tpLifetimeFlag) {
value, err := time.ParseDuration(cli.GetStringFlagValue(cmd, tpLifetimeFlag))
if err != nil {
panic(fmt.Sprintf("Invalid value for txpool.lifetime: %v", err))
}
config.TxPool.Lifetime = value
}
if cli.IsFlagChanged(cmd, tpPriceLimitFlag) {
value := cli.GetIntFlagValue(cmd, tpPriceLimitFlag)
if value <= 0 {
panic("Must provide positive value for txpool.pricelimit")
}
config.TxPool.PriceLimit = harmonyconfig.PriceLimit(value)
}
if cli.IsFlagChanged(cmd, tpPriceBumpFlag) {
value := cli.GetIntFlagValue(cmd, tpPriceBumpFlag)
if value <= 0 {
panic("Must provide positive value for txpool.pricebump")
}
config.TxPool.PriceBump = uint64(value)
}
} }
// pprof flags // pprof flags

@ -5,6 +5,7 @@ import (
"reflect" "reflect"
"strings" "strings"
"testing" "testing"
"time"
harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony" harmonyconfig "github.com/harmony-one/harmony/internal/configs/harmony"
@ -118,8 +119,13 @@ func TestHarmonyFlags(t *testing.T) {
AllowedTxsFile: "./.hmy/allowedtxs.txt", AllowedTxsFile: "./.hmy/allowedtxs.txt",
RosettaFixFile: "", RosettaFixFile: "",
AccountSlots: 16, AccountSlots: 16,
GlobalSlots: 5120, GlobalSlots: 4096,
LocalAccountsFile: "./.hmy/locals.txt", LocalAccountsFile: "./.hmy/locals.txt",
AccountQueue: 64,
GlobalQueue: 5120,
Lifetime: 30 * time.Minute,
PriceLimit: 100e9,
PriceBump: 1,
}, },
Pprof: harmonyconfig.PprofConfig{ Pprof: harmonyconfig.PprofConfig{
Enabled: false, Enabled: false,
@ -1005,6 +1011,11 @@ func TestTxPoolFlags(t *testing.T) {
AccountSlots: defaultConfig.TxPool.AccountSlots, AccountSlots: defaultConfig.TxPool.AccountSlots,
LocalAccountsFile: defaultConfig.TxPool.LocalAccountsFile, LocalAccountsFile: defaultConfig.TxPool.LocalAccountsFile,
GlobalSlots: defaultConfig.TxPool.GlobalSlots, GlobalSlots: defaultConfig.TxPool.GlobalSlots,
AccountQueue: defaultConfig.TxPool.AccountQueue,
GlobalQueue: defaultConfig.TxPool.GlobalQueue,
Lifetime: defaultConfig.TxPool.Lifetime,
PriceLimit: 100e9,
PriceBump: 1,
}, },
}, },
{ {
@ -1015,7 +1026,12 @@ func TestTxPoolFlags(t *testing.T) {
RosettaFixFile: "rosettafix.file", RosettaFixFile: "rosettafix.file",
AccountSlots: defaultConfig.TxPool.AccountSlots, AccountSlots: defaultConfig.TxPool.AccountSlots,
GlobalSlots: defaultConfig.TxPool.GlobalSlots, GlobalSlots: defaultConfig.TxPool.GlobalSlots,
AccountQueue: defaultConfig.TxPool.AccountQueue,
GlobalQueue: defaultConfig.TxPool.GlobalQueue,
Lifetime: defaultConfig.TxPool.Lifetime,
LocalAccountsFile: defaultConfig.TxPool.LocalAccountsFile, LocalAccountsFile: defaultConfig.TxPool.LocalAccountsFile,
PriceLimit: 100e9,
PriceBump: 1,
}, },
}, },
{ {
@ -1026,7 +1042,12 @@ func TestTxPoolFlags(t *testing.T) {
AllowedTxsFile: defaultConfig.TxPool.AllowedTxsFile, AllowedTxsFile: defaultConfig.TxPool.AllowedTxsFile,
AccountSlots: defaultConfig.TxPool.AccountSlots, AccountSlots: defaultConfig.TxPool.AccountSlots,
GlobalSlots: defaultConfig.TxPool.GlobalSlots, GlobalSlots: defaultConfig.TxPool.GlobalSlots,
AccountQueue: defaultConfig.TxPool.AccountQueue,
GlobalQueue: defaultConfig.TxPool.GlobalQueue,
Lifetime: defaultConfig.TxPool.Lifetime,
LocalAccountsFile: defaultConfig.TxPool.LocalAccountsFile, LocalAccountsFile: defaultConfig.TxPool.LocalAccountsFile,
PriceLimit: 100e9,
PriceBump: 1,
}, },
}, },
{ {
@ -1038,6 +1059,11 @@ func TestTxPoolFlags(t *testing.T) {
RosettaFixFile: "rosettafix.file", RosettaFixFile: "rosettafix.file",
LocalAccountsFile: defaultConfig.TxPool.LocalAccountsFile, LocalAccountsFile: defaultConfig.TxPool.LocalAccountsFile,
GlobalSlots: defaultConfig.TxPool.GlobalSlots, GlobalSlots: defaultConfig.TxPool.GlobalSlots,
AccountQueue: defaultConfig.TxPool.AccountQueue,
GlobalQueue: defaultConfig.TxPool.GlobalQueue,
Lifetime: defaultConfig.TxPool.Lifetime,
PriceLimit: 100e9,
PriceBump: 1,
}, },
}, },
{ {
@ -1049,6 +1075,11 @@ func TestTxPoolFlags(t *testing.T) {
AccountSlots: defaultConfig.TxPool.AccountSlots, AccountSlots: defaultConfig.TxPool.AccountSlots,
LocalAccountsFile: "locals.txt", LocalAccountsFile: "locals.txt",
GlobalSlots: defaultConfig.TxPool.GlobalSlots, GlobalSlots: defaultConfig.TxPool.GlobalSlots,
AccountQueue: defaultConfig.TxPool.AccountQueue,
GlobalQueue: defaultConfig.TxPool.GlobalQueue,
Lifetime: defaultConfig.TxPool.Lifetime,
PriceLimit: 100e9,
PriceBump: 1,
}, },
}, },
{ {
@ -1060,6 +1091,27 @@ func TestTxPoolFlags(t *testing.T) {
AccountSlots: defaultConfig.TxPool.AccountSlots, AccountSlots: defaultConfig.TxPool.AccountSlots,
LocalAccountsFile: defaultConfig.TxPool.LocalAccountsFile, LocalAccountsFile: defaultConfig.TxPool.LocalAccountsFile,
GlobalSlots: 10240, GlobalSlots: 10240,
AccountQueue: defaultConfig.TxPool.AccountQueue,
GlobalQueue: defaultConfig.TxPool.GlobalQueue,
Lifetime: defaultConfig.TxPool.Lifetime,
PriceLimit: 100e9,
PriceBump: 1,
},
},
{
args: []string{"--txpool.accountqueue", "128", "--txpool.globalqueue", "10240", "--txpool.lifetime", "15m", "--txpool.pricelimit", "100", "--txpool.pricebump", "2"},
expConfig: harmonyconfig.TxPoolConfig{
BlacklistFile: defaultConfig.TxPool.BlacklistFile,
AllowedTxsFile: defaultConfig.TxPool.AllowedTxsFile,
RosettaFixFile: defaultConfig.TxPool.RosettaFixFile,
AccountSlots: defaultConfig.TxPool.AccountSlots,
LocalAccountsFile: defaultConfig.TxPool.LocalAccountsFile,
GlobalSlots: defaultConfig.TxPool.GlobalSlots,
AccountQueue: 128,
GlobalQueue: 10240,
Lifetime: 15 * time.Minute,
PriceLimit: 100,
PriceBump: 2,
}, },
}, },
} }

@ -185,12 +185,12 @@ var DefaultTxPoolConfig = TxPoolConfig{
PriceLimit: 100e9, // 100 Gwei/Nano PriceLimit: 100e9, // 100 Gwei/Nano
PriceBump: 1, // PriceBump is percent, 1% is enough PriceBump: 1, // PriceBump is percent, 1% is enough
AccountSlots: 16, AccountSlots: 16, // --txpool.accountslots
GlobalSlots: 4096, GlobalSlots: 4096, // --txpool.globalslots
AccountQueue: 64, AccountQueue: 64, // --txpool.accountqueue
GlobalQueue: 1024, GlobalQueue: 5120, // --txpool.globalqueue
Lifetime: 30 * time.Minute, Lifetime: 30 * time.Minute, // --txpool.lifetime
Blacklist: map[common.Address]struct{}{}, Blacklist: map[common.Address]struct{}{},
AllowedTxs: map[common.Address]AllowedTxData{}, AllowedTxs: map[common.Address]AllowedTxData{},
@ -243,6 +243,27 @@ func (config *TxPoolConfig) sanitize() TxPoolConfig {
Msg("Sanitizing invalid txpool global slots") Msg("Sanitizing invalid txpool global slots")
conf.GlobalSlots = DefaultTxPoolConfig.GlobalSlots conf.GlobalSlots = DefaultTxPoolConfig.GlobalSlots
} }
if conf.AccountQueue == 0 {
utils.Logger().Warn().
Uint64("provided", conf.AccountQueue).
Uint64("updated", DefaultTxPoolConfig.AccountQueue).
Msg("Sanitizing invalid txpool account queue")
conf.AccountQueue = DefaultTxPoolConfig.AccountQueue
}
if conf.GlobalQueue == 0 {
utils.Logger().Warn().
Uint64("provided", conf.GlobalQueue).
Uint64("updated", DefaultTxPoolConfig.GlobalQueue).
Msg("Sanitizing invalid txpool account queue")
conf.GlobalQueue = DefaultTxPoolConfig.GlobalQueue
}
if conf.Lifetime == 0 {
utils.Logger().Warn().
Dur("provided", conf.Lifetime).
Dur("updated", DefaultTxPoolConfig.Lifetime).
Msg("Sanitizing invalid txpool lifetime")
conf.Lifetime = DefaultTxPoolConfig.Lifetime
}
return conf return conf
} }

@ -774,6 +774,8 @@ github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtP
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8= github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pelletier/go-toml/v2 v2.0.5 h1:ipoSadvV8oGUjnUbMub59IDPPwfxF694nG/jwbMiyQg= github.com/pelletier/go-toml/v2 v2.0.5 h1:ipoSadvV8oGUjnUbMub59IDPPwfxF694nG/jwbMiyQg=
github.com/pelletier/go-toml/v2 v2.0.5/go.mod h1:OMHamSCAODeSsVrwwvcJOaoN0LIUIaFVNZzmWyNfXas= github.com/pelletier/go-toml/v2 v2.0.5/go.mod h1:OMHamSCAODeSsVrwwvcJOaoN0LIUIaFVNZzmWyNfXas=
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0= github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0=

@ -1,6 +1,7 @@
package harmony package harmony
import ( import (
"fmt"
"reflect" "reflect"
"strings" "strings"
"time" "time"
@ -181,8 +182,13 @@ type TxPoolConfig struct {
AllowedTxsFile string AllowedTxsFile string
RosettaFixFile string RosettaFixFile string
AccountSlots uint64 AccountSlots uint64
AccountQueue uint64
GlobalQueue uint64
LocalAccountsFile string LocalAccountsFile string
GlobalSlots uint64 GlobalSlots uint64
Lifetime time.Duration
PriceLimit PriceLimit
PriceBump uint64
} }
type PprofConfig struct { type PprofConfig struct {
@ -318,3 +324,26 @@ type StagedSyncConfig struct {
UseMemDB bool // it uses memory by default. set it to false to use disk UseMemDB bool // it uses memory by default. set it to false to use disk
LogProgress bool // log the full sync progress in console LogProgress bool // log the full sync progress in console
} }
type PriceLimit int64
func (s *PriceLimit) UnmarshalTOML(data interface{}) error {
switch v := data.(type) {
case float64:
*s = PriceLimit(v)
case int64:
*s = PriceLimit(v)
case PriceLimit:
*s = v
default:
return fmt.Errorf("PriceLimit.UnmarshalTOML: %T", data)
}
return nil
}
func (s PriceLimit) MarshalTOML() ([]byte, error) {
if s > 1_000_000_000 {
return []byte(fmt.Sprintf("%de9", s/1_000_000_000)), nil
}
return []byte(fmt.Sprintf("%d", s)), nil
}

@ -6,7 +6,9 @@ import (
"time" "time"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node" nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
"github.com/pelletier/go-toml"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
) )
func TestToRPCServerConfig(t *testing.T) { func TestToRPCServerConfig(t *testing.T) {
@ -79,3 +81,38 @@ func TestToRPCServerConfig(t *testing.T) {
}) })
} }
} }
var data = `big = 100e9
small = 100
zero = 0
`
func TestPriceLimit_UnmarshalTOML(t *testing.T) {
type V struct {
Big PriceLimit `toml:"big"`
Small PriceLimit `toml:"small"`
Zero PriceLimit `toml:"zero"`
}
var v V
require.NoError(t, toml.Unmarshal([]byte(data), &v))
require.Equal(t, PriceLimit(100e9), v.Big)
require.Equal(t, PriceLimit(100), v.Small)
require.Equal(t, PriceLimit(0), v.Zero)
}
func TestPriceLimit_MarshalTOML(t *testing.T) {
type V struct {
Big PriceLimit `toml:"big"`
Small PriceLimit `toml:"small"`
Zero PriceLimit `toml:"zero"`
}
v := V{
Big: PriceLimit(100e9),
Small: PriceLimit(100),
Zero: PriceLimit(0),
}
e, err := toml.Marshal(v)
require.NoError(t, err)
require.Equal(t, data, string(e))
}

@ -1084,15 +1084,20 @@ func New(
node.BeaconBlockChannel = make(chan *types.Block) node.BeaconBlockChannel = make(chan *types.Block)
txPoolConfig := core.DefaultTxPoolConfig txPoolConfig := core.DefaultTxPoolConfig
// Temporarily not updating other networks to make the rpc tests pass
if node.NodeConfig.GetNetworkType() != nodeconfig.Mainnet && node.NodeConfig.GetNetworkType() != nodeconfig.Testnet {
txPoolConfig.PriceLimit = 1e9
txPoolConfig.PriceBump = 10
}
if harmonyconfig != nil { if harmonyconfig != nil {
txPoolConfig.AccountSlots = harmonyconfig.TxPool.AccountSlots txPoolConfig.AccountSlots = harmonyconfig.TxPool.AccountSlots
txPoolConfig.GlobalSlots = harmonyconfig.TxPool.GlobalSlots txPoolConfig.GlobalSlots = harmonyconfig.TxPool.GlobalSlots
txPoolConfig.Locals = append(txPoolConfig.Locals, localAccounts...) txPoolConfig.Locals = append(txPoolConfig.Locals, localAccounts...)
txPoolConfig.AccountQueue = harmonyconfig.TxPool.AccountQueue
txPoolConfig.GlobalQueue = harmonyconfig.TxPool.GlobalQueue
txPoolConfig.Lifetime = harmonyconfig.TxPool.Lifetime
txPoolConfig.PriceLimit = uint64(harmonyconfig.TxPool.PriceLimit)
txPoolConfig.PriceBump = harmonyconfig.TxPool.PriceBump
}
// Temporarily not updating other networks to make the rpc tests pass
if node.NodeConfig.GetNetworkType() != nodeconfig.Mainnet && node.NodeConfig.GetNetworkType() != nodeconfig.Testnet {
txPoolConfig.PriceLimit = 1e9
txPoolConfig.PriceBump = 10
} }
txPoolConfig.Blacklist = blacklist txPoolConfig.Blacklist = blacklist

@ -133,6 +133,12 @@ Version = "2.5.13"
GlobalSlots = 5120 GlobalSlots = 5120
LocalAccountsFile = "./.hmy/locals.txt" LocalAccountsFile = "./.hmy/locals.txt"
RosettaFixFile = "./rosetta_local_fix.csv" RosettaFixFile = "./rosetta_local_fix.csv"
GlobalSlots = 4096
GlobalQueue = 5120
AccountQueue = 64
Lifetime = "30m"
PriceBump = 1
PriceLimit = 100e9
[WS] [WS]
AuthPort = 9801 AuthPort = 9801

@ -133,6 +133,12 @@ Version = "2.5.13"
GlobalSlots = 5120 GlobalSlots = 5120
LocalAccountsFile = "./.hmy/locals.txt" LocalAccountsFile = "./.hmy/locals.txt"
RosettaFixFile = "" RosettaFixFile = ""
GlobalSlots = 4096
GlobalQueue = 5120
AccountQueue = 64
Lifetime = "30m"
PriceBump = 1
PriceLimit = 100e9
[WS] [WS]
AuthPort = 9801 AuthPort = 9801

Loading…
Cancel
Save