Skip to content

Commit

Permalink
--txpool.commit.every panic handling (erigontech#7163)
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored and calmbeing committed Apr 24, 2023
1 parent 4e3b63f commit 7117ef2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
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())
}

0 comments on commit 7117ef2

Please sign in to comment.