diff --git a/cmd/downloader/downloader/torrentcfg/logger.go b/cmd/downloader/downloader/torrentcfg/logger.go index cec2ac6e1..e5a8a3188 100644 --- a/cmd/downloader/downloader/torrentcfg/logger.go +++ b/cmd/downloader/downloader/torrentcfg/logger.go @@ -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{} diff --git a/cmd/downloader/downloader/torrentcfg/torrentcfg.go b/cmd/downloader/downloader/torrentcfg/torrentcfg.go index 462763f3d..a31c968df 100644 --- a/cmd/downloader/downloader/torrentcfg/torrentcfg.go +++ b/cmd/downloader/downloader/torrentcfg/torrentcfg.go @@ -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 diff --git a/cmd/downloader/main.go b/cmd/downloader/main.go index 7324cb615..b82c7c237 100644 --- a/cmd/downloader/main.go +++ b/cmd/downloader/main.go @@ -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 diff --git a/cmd/txpool/main.go b/cmd/txpool/main.go index ec3bf5448..e09807036 100644 --- a/cmd/txpool/main.go +++ b/cmd/txpool/main.go @@ -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 diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index a19a87270..9e064e0fa 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -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 {