mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 11:41:19 +00:00
Better validate --torrent.verbosity flag (#4257)
* lastDup no key * lastDup no key * lastDup no key
This commit is contained in:
parent
0d259384a0
commit
1eb9aec08a
@ -13,11 +13,12 @@ func init() {
|
||||
utp.Logger.Handlers = []lg.Handler{noopHandler{}}
|
||||
}
|
||||
|
||||
var String2LogLevel = map[string]lg.Level{
|
||||
lg.Debug.LogString(): lg.Debug,
|
||||
lg.Info.LogString(): lg.Info,
|
||||
lg.Warning.LogString(): lg.Warning,
|
||||
lg.Error.LogString(): lg.Error,
|
||||
func Str2LogLevel(in string) (lg.Level, error) {
|
||||
lvl := lg.Level{}
|
||||
if err := lvl.UnmarshalText([]byte(in)); err != nil {
|
||||
return lvl, err
|
||||
}
|
||||
return lvl, nil
|
||||
}
|
||||
|
||||
type noopHandler struct{}
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
lg "github.com/anacrolix/log"
|
||||
"github.com/anacrolix/torrent"
|
||||
@ -41,9 +40,18 @@ func Default() *torrent.ClientConfig {
|
||||
//torrentConfig.DisableWebseeds = true
|
||||
|
||||
// Reduce defaults - to avoid peers with very bad geography
|
||||
torrentConfig.MinDialTimeout = 1 * time.Second // default: 3sec
|
||||
torrentConfig.NominalDialTimeout = 10 * time.Second // default: 20sec
|
||||
torrentConfig.HandshakesTimeout = 1 * time.Second // default: 4sec
|
||||
//torrentConfig.MinDialTimeout = 1 * time.Second // default: 3sec
|
||||
//torrentConfig.NominalDialTimeout = 10 * time.Second // default: 20sec
|
||||
//torrentConfig.HandshakesTimeout = 1 * time.Second // default: 4sec
|
||||
|
||||
// see: https://en.wikipedia.org/wiki/TCP_half-open
|
||||
//torrentConfig.TotalHalfOpenConns = 100 // default: 100
|
||||
//torrentConfig.HalfOpenConnsPerTorrent = 25 // default: 25
|
||||
//torrentConfig.TorrentPeersHighWater = 500 // default: 500
|
||||
//torrentConfig.TorrentPeersLowWater = 50 // default: 50
|
||||
|
||||
torrentConfig.Seed = true
|
||||
torrentConfig.UpnpID = torrentConfig.UpnpID + "leecher"
|
||||
|
||||
return torrentConfig
|
||||
}
|
||||
@ -52,17 +60,7 @@ func New(snapDir string, verbosity lg.Level, natif nat.Interface, downloadRate,
|
||||
torrentConfig := Default()
|
||||
// We would-like to reduce amount of goroutines in Erigon, so reducing next params
|
||||
torrentConfig.EstablishedConnsPerTorrent = connsPerFile // default: 50
|
||||
|
||||
// see: https://en.wikipedia.org/wiki/TCP_half-open
|
||||
torrentConfig.TotalHalfOpenConns = 100 // default: 100
|
||||
torrentConfig.HalfOpenConnsPerTorrent = 25 // default: 25
|
||||
|
||||
torrentConfig.TorrentPeersHighWater = 500 // default: 500
|
||||
torrentConfig.TorrentPeersLowWater = 50 // default: 50
|
||||
|
||||
torrentConfig.Seed = true
|
||||
torrentConfig.DataDir = snapDir
|
||||
torrentConfig.UpnpID = torrentConfig.UpnpID + "leecher"
|
||||
|
||||
torrentConfig.ListenPort = port
|
||||
// check if ipv6 is enabled
|
||||
|
@ -113,9 +113,9 @@ var rootCmd = &cobra.Command{
|
||||
|
||||
func Downloader(ctx context.Context) error {
|
||||
snapDir := filepath.Join(datadir, "snapshots")
|
||||
torrentLogLevel, ok := torrentcfg.String2LogLevel[torrentVerbosity]
|
||||
if !ok {
|
||||
panic(fmt.Errorf("unexpected torrent.verbosity level: %s", torrentVerbosity))
|
||||
torrentLogLevel, err := torrentcfg.Str2LogLevel(torrentVerbosity)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var downloadRate, uploadRate datasize.ByteSize
|
||||
|
@ -113,7 +113,6 @@ var rootCmd = &cobra.Command{
|
||||
|
||||
cfg := txpool.DefaultConfig
|
||||
cfg.DBDir = filepath.Join(datadir, "txpool")
|
||||
cfg.LogEvery = 30 * time.Second
|
||||
cfg.CommitEvery = 30 * time.Second
|
||||
cfg.PendingSubPoolLimit = pendingPoolLimit
|
||||
cfg.BaseFeeSubPoolLimit = baseFeePoolLimit
|
||||
|
@ -31,7 +31,6 @@ import (
|
||||
|
||||
lg "github.com/anacrolix/log"
|
||||
"github.com/c2h5oh/datasize"
|
||||
"github.com/ledgerwatch/erigon-lib/kv"
|
||||
"github.com/ledgerwatch/erigon-lib/kv/kvcache"
|
||||
"github.com/ledgerwatch/erigon-lib/txpool"
|
||||
"github.com/ledgerwatch/erigon/cmd/downloader/downloader/torrentcfg"
|
||||
@ -642,7 +641,7 @@ var (
|
||||
TorrentVerbosityFlag = cli.StringFlag{
|
||||
Name: "torrent.verbosity",
|
||||
Value: lg.Warning.LogString(),
|
||||
Usage: "DEBUG | INFO | WARN | ERROR (must set --verbosity to equal or higher level)",
|
||||
Usage: "DBG | INF | WRN | ERR (must set --verbosity to equal or higher level)",
|
||||
}
|
||||
TorrentDownloadRateFlag = cli.StringFlag{
|
||||
Name: "torrent.download.rate",
|
||||
@ -1391,9 +1390,12 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *node.Config, cfg *ethconfig.Conf
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var err error
|
||||
lvl, err := torrentcfg.Str2LogLevel(ctx.GlobalString(TorrentVerbosityFlag.Name))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
cfg.Torrent, err = torrentcfg.New(cfg.SnapDir,
|
||||
torrentcfg.String2LogLevel[ctx.GlobalString(TorrentVerbosityFlag.Name)],
|
||||
lvl,
|
||||
nodeConfig.P2P.NAT,
|
||||
downloadRate, uploadRate,
|
||||
ctx.GlobalInt(TorrentPortFlag.Name),
|
||||
@ -1527,15 +1529,6 @@ func SplitTagsFlag(tagsFlag string) map[string]string {
|
||||
return tagsMap
|
||||
}
|
||||
|
||||
// MakeChainDatabase open a database using the flags passed to the client and will hard crash if it fails.
|
||||
func MakeChainDatabase(logger log.Logger, cfg *node.Config) kv.RwDB {
|
||||
chainDb, err := node.OpenDatabase(cfg, logger, kv.ChainDB)
|
||||
if err != nil {
|
||||
Fatalf("Could not open database: %v", err)
|
||||
}
|
||||
return chainDb
|
||||
}
|
||||
|
||||
// MakeConsolePreloads retrieves the absolute paths for the console JavaScript
|
||||
// scripts to preload before starting.
|
||||
func MakeConsolePreloads(ctx *cli.Context) []string {
|
||||
|
Loading…
Reference in New Issue
Block a user