Skip to content

Commit 08959bb

Browse files
committed
cmd, core, eth: configurable txpool parameters
1 parent dd5ed01 commit 08959bb

File tree

10 files changed

+241
-105
lines changed

10 files changed

+241
-105
lines changed

cmd/geth/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ var (
6666
utils.EthashDatasetDirFlag,
6767
utils.EthashDatasetsInMemoryFlag,
6868
utils.EthashDatasetsOnDiskFlag,
69+
utils.TxPoolPriceLimitFlag,
70+
utils.TxPoolPriceBumpFlag,
71+
utils.TxPoolAccountSlotsFlag,
72+
utils.TxPoolGlobalSlotsFlag,
73+
utils.TxPoolAccountQueueFlag,
74+
utils.TxPoolGlobalQueueFlag,
75+
utils.TxPoolLifetimeFlag,
6976
utils.FastSyncFlag,
7077
utils.LightModeFlag,
7178
utils.SyncModeFlag,

cmd/geth/usage.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ var AppHelpFlagGroups = []flagGroup{
9292
utils.EthashDatasetsOnDiskFlag,
9393
},
9494
},
95+
{
96+
Name: "TRANSACTION POOL",
97+
Flags: []cli.Flag{
98+
utils.TxPoolPriceLimitFlag,
99+
utils.TxPoolPriceBumpFlag,
100+
utils.TxPoolAccountSlotsFlag,
101+
utils.TxPoolGlobalSlotsFlag,
102+
utils.TxPoolAccountQueueFlag,
103+
utils.TxPoolGlobalQueueFlag,
104+
utils.TxPoolLifetimeFlag,
105+
},
106+
},
95107
{
96108
Name: "PERFORMANCE TUNING",
97109
Flags: []cli.Flag{

cmd/utils/flags.go

Lines changed: 91 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -123,35 +123,6 @@ var (
123123
Name: "nousb",
124124
Usage: "Disables monitoring for and managine USB hardware wallets",
125125
}
126-
EthashCacheDirFlag = DirectoryFlag{
127-
Name: "ethash.cachedir",
128-
Usage: "Directory to store the ethash verification caches (default = inside the datadir)",
129-
}
130-
EthashCachesInMemoryFlag = cli.IntFlag{
131-
Name: "ethash.cachesinmem",
132-
Usage: "Number of recent ethash caches to keep in memory (16MB each)",
133-
Value: eth.DefaultConfig.EthashCachesInMem,
134-
}
135-
EthashCachesOnDiskFlag = cli.IntFlag{
136-
Name: "ethash.cachesondisk",
137-
Usage: "Number of recent ethash caches to keep on disk (16MB each)",
138-
Value: eth.DefaultConfig.EthashCachesOnDisk,
139-
}
140-
EthashDatasetDirFlag = DirectoryFlag{
141-
Name: "ethash.dagdir",
142-
Usage: "Directory to store the ethash mining DAGs (default = inside home folder)",
143-
Value: DirectoryString{eth.DefaultConfig.EthashDatasetDir},
144-
}
145-
EthashDatasetsInMemoryFlag = cli.IntFlag{
146-
Name: "ethash.dagsinmem",
147-
Usage: "Number of recent ethash mining DAGs to keep in memory (1+GB each)",
148-
Value: eth.DefaultConfig.EthashDatasetsInMem,
149-
}
150-
EthashDatasetsOnDiskFlag = cli.IntFlag{
151-
Name: "ethash.dagsondisk",
152-
Usage: "Number of recent ethash mining DAGs to keep on disk (1+GB each)",
153-
Value: eth.DefaultConfig.EthashDatasetsOnDisk,
154-
}
155126
NetworkIdFlag = cli.Uint64Flag{
156127
Name: "networkid",
157128
Usage: "Network identifier (integer, 1=Frontier, 2=Morden (disused), 3=Ropsten, 4=Rinkeby)",
@@ -207,6 +178,72 @@ var (
207178
Name: "lightkdf",
208179
Usage: "Reduce key-derivation RAM & CPU usage at some expense of KDF strength",
209180
}
181+
// Ethash settings
182+
EthashCacheDirFlag = DirectoryFlag{
183+
Name: "ethash.cachedir",
184+
Usage: "Directory to store the ethash verification caches (default = inside the datadir)",
185+
}
186+
EthashCachesInMemoryFlag = cli.IntFlag{
187+
Name: "ethash.cachesinmem",
188+
Usage: "Number of recent ethash caches to keep in memory (16MB each)",
189+
Value: eth.DefaultConfig.EthashCachesInMem,
190+
}
191+
EthashCachesOnDiskFlag = cli.IntFlag{
192+
Name: "ethash.cachesondisk",
193+
Usage: "Number of recent ethash caches to keep on disk (16MB each)",
194+
Value: eth.DefaultConfig.EthashCachesOnDisk,
195+
}
196+
EthashDatasetDirFlag = DirectoryFlag{
197+
Name: "ethash.dagdir",
198+
Usage: "Directory to store the ethash mining DAGs (default = inside home folder)",
199+
Value: DirectoryString{eth.DefaultConfig.EthashDatasetDir},
200+
}
201+
EthashDatasetsInMemoryFlag = cli.IntFlag{
202+
Name: "ethash.dagsinmem",
203+
Usage: "Number of recent ethash mining DAGs to keep in memory (1+GB each)",
204+
Value: eth.DefaultConfig.EthashDatasetsInMem,
205+
}
206+
EthashDatasetsOnDiskFlag = cli.IntFlag{
207+
Name: "ethash.dagsondisk",
208+
Usage: "Number of recent ethash mining DAGs to keep on disk (1+GB each)",
209+
Value: eth.DefaultConfig.EthashDatasetsOnDisk,
210+
}
211+
// Transaction pool settings
212+
TxPoolPriceLimitFlag = cli.Uint64Flag{
213+
Name: "txpool.pricelimit",
214+
Usage: "Minimum gas price limit to enforce for acceptance into the pool",
215+
Value: eth.DefaultConfig.TxPool.PriceLimit,
216+
}
217+
TxPoolPriceBumpFlag = cli.Uint64Flag{
218+
Name: "txpool.pricebump",
219+
Usage: "Price bump percentage to replace an already existing transaction",
220+
Value: eth.DefaultConfig.TxPool.PriceBump,
221+
}
222+
TxPoolAccountSlotsFlag = cli.Uint64Flag{
223+
Name: "txpool.accountslots",
224+
Usage: "Minimum number of executable transaction slots guaranteed per account",
225+
Value: eth.DefaultConfig.TxPool.AccountSlots,
226+
}
227+
TxPoolGlobalSlotsFlag = cli.Uint64Flag{
228+
Name: "txpool.globalslots",
229+
Usage: "Maximum number of executable transaction slots for all accounts",
230+
Value: eth.DefaultConfig.TxPool.GlobalSlots,
231+
}
232+
TxPoolAccountQueueFlag = cli.Uint64Flag{
233+
Name: "txpool.accountqueue",
234+
Usage: "Maximum number of non-executable transaction slots permitted per account",
235+
Value: eth.DefaultConfig.TxPool.AccountQueue,
236+
}
237+
TxPoolGlobalQueueFlag = cli.Uint64Flag{
238+
Name: "txpool.globalqueue",
239+
Usage: "Maximum number of non-executable transaction slots for all accounts",
240+
Value: eth.DefaultConfig.TxPool.GlobalQueue,
241+
}
242+
TxPoolLifetimeFlag = cli.DurationFlag{
243+
Name: "txpool.lifetime",
244+
Usage: "Maximum amount of time non-executable transaction are queued",
245+
Value: eth.DefaultConfig.TxPool.Lifetime,
246+
}
210247
// Performance tuning settings
211248
CacheFlag = cli.IntFlag{
212249
Name: "cache",
@@ -784,6 +821,30 @@ func setGPO(ctx *cli.Context, cfg *gasprice.Config) {
784821
}
785822
}
786823

824+
func setTxPool(ctx *cli.Context, cfg *core.TxPoolConfig) {
825+
if ctx.GlobalIsSet(TxPoolPriceLimitFlag.Name) {
826+
cfg.PriceLimit = ctx.GlobalUint64(TxPoolPriceLimitFlag.Name)
827+
}
828+
if ctx.GlobalIsSet(TxPoolPriceBumpFlag.Name) {
829+
cfg.PriceBump = ctx.GlobalUint64(TxPoolPriceBumpFlag.Name)
830+
}
831+
if ctx.GlobalIsSet(TxPoolAccountSlotsFlag.Name) {
832+
cfg.AccountSlots = ctx.GlobalUint64(TxPoolAccountSlotsFlag.Name)
833+
}
834+
if ctx.GlobalIsSet(TxPoolGlobalSlotsFlag.Name) {
835+
cfg.GlobalSlots = ctx.GlobalUint64(TxPoolGlobalSlotsFlag.Name)
836+
}
837+
if ctx.GlobalIsSet(TxPoolAccountQueueFlag.Name) {
838+
cfg.AccountQueue = ctx.GlobalUint64(TxPoolAccountQueueFlag.Name)
839+
}
840+
if ctx.GlobalIsSet(TxPoolGlobalQueueFlag.Name) {
841+
cfg.GlobalQueue = ctx.GlobalUint64(TxPoolGlobalQueueFlag.Name)
842+
}
843+
if ctx.GlobalIsSet(TxPoolLifetimeFlag.Name) {
844+
cfg.Lifetime = ctx.GlobalDuration(TxPoolLifetimeFlag.Name)
845+
}
846+
}
847+
787848
func setEthash(ctx *cli.Context, cfg *eth.Config) {
788849
if ctx.GlobalIsSet(EthashCacheDirFlag.Name) {
789850
cfg.EthashCacheDir = ctx.GlobalString(EthashCacheDirFlag.Name)
@@ -826,6 +887,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
826887
ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
827888
setEtherbase(ctx, ks, cfg)
828889
setGPO(ctx, &cfg.GPO)
890+
setTxPool(ctx, &cfg.TxPool)
829891
setEthash(ctx, cfg)
830892

831893
switch {

core/tx_list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,11 @@ func (l *txList) Overlaps(tx *types.Transaction) bool {
246246
//
247247
// If the new transaction is accepted into the list, the lists' cost threshold
248248
// is also potentially updated.
249-
func (l *txList) Add(tx *types.Transaction) (bool, *types.Transaction) {
249+
func (l *txList) Add(tx *types.Transaction, priceBump uint64) (bool, *types.Transaction) {
250250
// If there's an older better transaction, abort
251251
old := l.txs.Get(tx.Nonce())
252252
if old != nil {
253-
threshold := new(big.Int).Div(new(big.Int).Mul(old.GasPrice(), big.NewInt(100+minPriceBumpPercent)), big.NewInt(100))
253+
threshold := new(big.Int).Div(new(big.Int).Mul(old.GasPrice(), big.NewInt(100+int64(priceBump))), big.NewInt(100))
254254
if threshold.Cmp(tx.GasPrice()) >= 0 {
255255
return false, nil
256256
}

core/tx_list_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestStrictTxListAdd(t *testing.T) {
3838
// Insert the transactions in a random order
3939
list := newTxList(true)
4040
for _, v := range rand.Perm(len(txs)) {
41-
list.Add(txs[v])
41+
list.Add(txs[v], DefaultTxPoolConfig.PriceBump)
4242
}
4343
// Verify internal state
4444
if len(list.txs.items) != len(txs) {

0 commit comments

Comments
 (0)