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

--txpool.commit.every panic handling #7163

Merged
merged 1 commit into from
Mar 23, 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
9 changes: 2 additions & 7 deletions cmd/txpool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package main

import (
"context"
"crypto/rand"
"errors"
"fmt"
"math/big"
"os"
"path/filepath"
"time"
Expand All @@ -24,6 +22,7 @@ import (
"github.com/ledgerwatch/erigon-lib/txpool/txpooluitl"
"github.com/ledgerwatch/erigon-lib/types"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/rpcdaemontest"
common2 "github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/ethdb/privateapi"
"github.com/ledgerwatch/log/v3"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -137,11 +136,7 @@ func doTxpool(ctx context.Context) error {

cfg.DBDir = dirs.TxPool

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.CommitEvery = common2.RandomizeDuration(commitEvery)
cfg.PendingSubPoolLimit = pendingPoolLimit
cfg.BaseFeeSubPoolLimit = baseFeePoolLimit
cfg.QueuedSubPoolLimit = queuedPoolLimit
Expand Down
13 changes: 3 additions & 10 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ 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 All @@ -37,6 +35,7 @@ import (
downloadercfg2 "github.com/ledgerwatch/erigon-lib/downloader/downloadercfg"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon-lib/txpool"
common2 "github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/log/v3"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -1269,14 +1268,8 @@ 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())
}

cfg.CommitEvery = common2.RandomizeDuration(ctx.Duration(TxPoolCommitEveryFlag.Name))
}

func setEthash(ctx *cli.Context, datadir string, cfg *ethconfig.Config) {
Expand Down
13 changes: 13 additions & 0 deletions common/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
package common

import (
"crypto/rand"
"fmt"
"math/big"
"os"
"runtime"
"runtime/debug"
"strings"
"time"
)

// Report gives off a warning requesting the user to submit an issue to the github tracker.
Expand Down Expand Up @@ -50,3 +53,13 @@ func PrintDepricationWarning(str string) {
`, line, emptyLine, str, emptyLine, line)
}

// RandomizeDuration - periodic parallel actions may interfere and resonance.
// Use this func to add small randomness to period
func RandomizeDuration(in time.Duration) time.Duration {
randDuration, err := rand.Int(rand.Reader, big.NewInt(int64(time.Second)))
if err != nil {
panic(err)
}
return in + time.Duration(randDuration.Uint64())
}