From 43ddea2adfbc393b8888791584d5e6515863c23c Mon Sep 17 00:00:00 2001 From: Alex Sharov <AskAlexSharov@gmail.com> Date: Thu, 28 Apr 2022 11:38:16 +0700 Subject: [PATCH] Torrent: maxpeers flag were used incorrectly --- .../downloader/torrentcfg/torrentcfg.go | 21 +++++++------------ cmd/downloader/main.go | 2 +- cmd/utils/flags.go | 3 +-- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/cmd/downloader/downloader/torrentcfg/torrentcfg.go b/cmd/downloader/downloader/torrentcfg/torrentcfg.go index d42d16d604..e263773e21 100644 --- a/cmd/downloader/downloader/torrentcfg/torrentcfg.go +++ b/cmd/downloader/downloader/torrentcfg/torrentcfg.go @@ -45,15 +45,17 @@ func Default() *torrent.ClientConfig { return torrentConfig } -func New(snapshotsDir *dir.Rw, verbosity lg.Level, natif nat.Interface, downloadRate, uploadRate datasize.ByteSize, port, maxPeers, connsPerFile int, db kv.RwDB, downloadSlots int) (*Cfg, error) { +func New(snapshotsDir *dir.Rw, verbosity lg.Level, natif nat.Interface, downloadRate, uploadRate datasize.ByteSize, port, connsPerFile int, db kv.RwDB, downloadSlots int) (*Cfg, error) { torrentConfig := Default() // We would-like to reduce amount of goroutines in Erigon, so reducing next params - torrentConfig.EstablishedConnsPerTorrent = connsPerFile // default: 50 - torrentConfig.HalfOpenConnsPerTorrent = min(25, connsPerFile) // default: 25 - torrentConfig.TotalHalfOpenConns = 50 // default: 100 + torrentConfig.EstablishedConnsPerTorrent = connsPerFile // default: 50 - torrentConfig.TorrentPeersHighWater = maxPeers // default: 500 - torrentConfig.TorrentPeersLowWater = min(50, maxPeers) // 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.ListenPort = port torrentConfig.Seed = true @@ -104,10 +106,3 @@ func New(snapshotsDir *dir.Rw, verbosity lg.Level, natif nat.Interface, download torrentConfig.DefaultStorage = m return &Cfg{ClientConfig: torrentConfig, DB: db, CompletionCloser: m, DownloadSlots: downloadSlots}, nil } - -func min(a, b int) int { - if a < b { - return a - } - return b -} diff --git a/cmd/downloader/main.go b/cmd/downloader/main.go index 8cfeb52b58..295dc7e45a 100644 --- a/cmd/downloader/main.go +++ b/cmd/downloader/main.go @@ -150,7 +150,7 @@ func Downloader(ctx context.Context) error { return err } - cfg, err := torrentcfg.New(snapshotDir, torrentLogLevel, natif, downloadRate, uploadRate, torrentPort, torrentMaxPeers, torrentConnsPerFile, db, torrentDownloadSlots) + cfg, err := torrentcfg.New(snapshotDir, torrentLogLevel, natif, downloadRate, uploadRate, torrentPort, torrentConnsPerFile, db, torrentDownloadSlots) if err != nil { return err } diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index f7fafec6e9..171d7e812a 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -661,7 +661,7 @@ var ( TorrentMaxPeersFlag = cli.IntFlag{ Name: "torrent.maxpeers", Value: 100, - Usage: "limit amount of torrent peers", + Usage: "unused parameter (reserved for future use)", } TorrentConnsPerFileFlag = cli.IntFlag{ Name: "torrent.conns.perfile", @@ -1399,7 +1399,6 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *node.Config, cfg *ethconfig.Conf nodeConfig.P2P.NAT, downloadRate, uploadRate, ctx.GlobalInt(TorrentPortFlag.Name), - ctx.GlobalInt(TorrentMaxPeersFlag.Name), ctx.GlobalInt(TorrentConnsPerFileFlag.Name), db, ctx.GlobalInt(TorrentDownloadSlotsFlag.Name), -- GitLab