Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add flag txpool.commit_every #7062

Merged
merged 1 commit into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion cmd/txpool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package main

import (
"context"
"crypto/rand"
"errors"
"fmt"
"math/big"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -50,6 +52,8 @@ var (
priceLimit uint64
accountSlots uint64
priceBump uint64

commitEvery time.Duration
)

func init() {
Expand All @@ -71,6 +75,7 @@ func init() {
rootCmd.PersistentFlags().Uint64Var(&priceLimit, "txpool.pricelimit", txpool.DefaultConfig.MinFeeCap, "Minimum gas price (fee cap) limit to enforce for acceptance into the pool")
rootCmd.PersistentFlags().Uint64Var(&accountSlots, "txpool.accountslots", txpool.DefaultConfig.AccountSlots, "Minimum number of executable transaction slots guaranteed per account")
rootCmd.PersistentFlags().Uint64Var(&priceBump, "txpool.pricebump", txpool.DefaultConfig.PriceBump, "Price bump percentage to replace an already existing transaction")
rootCmd.PersistentFlags().DurationVar(&commitEvery, utils.TxPoolCommitEveryFlag.Name, utils.TxPoolCommitEveryFlag.Value, utils.TxPoolCommitEveryFlag.Usage)
rootCmd.Flags().StringSliceVar(&traceSenders, utils.TxPoolTraceSendersFlag.Name, []string{}, utils.TxPoolTraceSendersFlag.Usage)
}

Expand Down Expand Up @@ -131,7 +136,12 @@ func doTxpool(ctx context.Context) error {
dirs := datadir.New(datadirCli)

cfg.DBDir = dirs.TxPool
cfg.CommitEvery = 30 * time.Second

randDuration, err := rand.Int(rand.Reader, big.NewInt(int64(2*time.Second)))
if err != nil {
return fmt.Errorf("generating random additional value for --txpool.commit.every: %w", err)
}
cfg.CommitEvery = commitEvery + time.Duration(randDuration.Int64())
cfg.PendingSubPoolLimit = pendingPoolLimit
cfg.BaseFeeSubPoolLimit = baseFeePoolLimit
cfg.QueuedSubPoolLimit = queuedPoolLimit
Expand Down
15 changes: 15 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ package utils

import (
"crypto/ecdsa"
"crypto/rand"
"fmt"
"math/big"
"path/filepath"
"runtime"
"strconv"
"strings"
"time"

"github.com/c2h5oh/datasize"
"github.com/ledgerwatch/erigon-lib/chain"
Expand Down Expand Up @@ -193,6 +195,11 @@ var (
Usage: "Comma separared list of addresses, whoes transactions will traced in transaction pool with debug printing",
Value: "",
}
TxPoolCommitEveryFlag = cli.DurationFlag{
Name: "txpool.commit.every",
Usage: "How often transactions should be committed to the storage",
Value: txpool.DefaultConfig.CommitEvery,
}
// Miner settings
MiningEnabledFlag = cli.BoolFlag{
Name: "mine",
Expand Down Expand Up @@ -1246,6 +1253,14 @@ func setTxPool(ctx *cli.Context, cfg *core.TxPoolConfig) {
cfg.TracedSenders[i] = string(sender[:])
}
}
if ctx.IsSet(TxPoolCommitEveryFlag.Name) {
cfg.CommitEvery = ctx.Duration(TxPoolCommitEveryFlag.Name)
randDuration, err := rand.Int(rand.Reader, big.NewInt(int64(2*time.Second)))
if err != nil {
Fatalf("Generating random additional value for --txpool.commit.every: %s", err)
}
cfg.CommitEvery += time.Duration(randDuration.Int64())
}
}

func setEthash(ctx *cli.Context, datadir string, cfg *ethconfig.Config) {
Expand Down
2 changes: 2 additions & 0 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type TxPoolConfig struct {
Lifetime time.Duration // Maximum amount of time non-executable transaction are queued
StartOnInit bool
TracedSenders []string // List of senders for which tx pool should print out debugging info
CommitEvery time.Duration
}

// DeprecatedDefaultTxPoolConfig contains the default configurations for the transaction
Expand Down Expand Up @@ -105,6 +106,7 @@ var DefaultTxPool2Config = func(pool1Cfg TxPoolConfig) txpool.Config {
cfg.LogEvery = 1 * time.Minute
cfg.CommitEvery = 5 * time.Minute
cfg.TracedSenders = pool1Cfg.TracedSenders
cfg.CommitEvery = pool1Cfg.CommitEvery

return cfg
}
1 change: 1 addition & 0 deletions turbo/cli/default_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var DefaultFlags = []cli.Flag{
&utils.TxPoolGlobalQueueFlag,
&utils.TxPoolLifetimeFlag,
&utils.TxPoolTraceSendersFlag,
&utils.TxPoolCommitEveryFlag,
&PruneFlag,
&PruneHistoryFlag,
&PruneReceiptFlag,
Expand Down
7 changes: 7 additions & 0 deletions turbo/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"fmt"
"github.com/ledgerwatch/erigon-lib/txpool"
"strings"
"time"

Expand Down Expand Up @@ -194,6 +195,12 @@ var (
Usage: "Maximum amount of time to wait for the answer from EVM call.",
Value: rpccfg.DefaultEvmCallTimeout,
}

TxPoolCommitEvery = cli.DurationFlag{
Name: "txpool.commit.every",
Usage: "How often transactions should be committed to the storage",
Value: txpool.DefaultConfig.CommitEvery,
}
)

func ApplyFlagsForEthConfig(ctx *cli.Context, cfg *ethconfig.Config) {
Expand Down