@cryptotaxi247 / kubo / commits / fb42b53f5

Fix RM errors when acceleratedDHT is active

Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>

Antonio Navarro Perez committed Nov 15, 2022 at 10:36 UTC fb42b53f58e989fd2897d814cd5edfa52eddcb62
3 files changed +30 -10
core/node/groups.go
+1 -1
@@ -147,7 +147,7 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config) fx.Option {
147 BaseLibP2P,
148
149 // Services (resource management)
150 - fx.Provide(libp2p.ResourceManager(cfg.Swarm)),
150 + fx.Provide(libp2p.ResourceManager(cfg.Swarm, cfg.Experimental.AcceleratedDHTClient)),
151 fx.Provide(libp2p.AddrFilters(cfg.Swarm.AddrFilters)),
152 fx.Provide(libp2p.AddrsFactory(cfg.Addresses.Announce, cfg.Addresses.AppendAnnounce, cfg.Addresses.NoAnnounce)),
153 fx.Provide(libp2p.SmuxTransport(cfg.Swarm.Transports)),
core/node/libp2p/rcmgr.go
+3 -3
@@ -29,7 +29,7 @@ const NetLimitTraceFilename = "rcmgr.json.gz"
29
30 var ErrNoResourceMgr = fmt.Errorf("missing ResourceMgr: make sure the daemon is running with Swarm.ResourceMgr.Enabled")
31
32 -func ResourceManager(cfg config.SwarmConfig) interface{} {
32 +func ResourceManager(cfg config.SwarmConfig, acceleratedDHT bool) interface{} {
33 return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, repo repo.Repo) (network.ResourceManager, Libp2pOpts, error) {
34 var manager network.ResourceManager
35 var opts Libp2pOpts
@@ -52,7 +52,7 @@ func ResourceManager(cfg config.SwarmConfig) interface{} {
52 return nil, opts, fmt.Errorf("opening IPFS_PATH: %w", err)
53 }
54
55 - limits, err := createDefaultLimitConfig(cfg)
55 + limits, err := createDefaultLimitConfig(cfg, acceleratedDHT)
56 if err != nil {
57 return nil, opts, err
58 }
@@ -513,7 +513,7 @@ func NetResetLimit(mgr network.ResourceManager, repo repo.Repo, scope string) (r
513 return result, fmt.Errorf("reading config to reset limit: %w", err)
514 }
515
516 - defaults, err := createDefaultLimitConfig(cfg.Swarm)
516 + defaults, err := createDefaultLimitConfig(cfg.Swarm, cfg.Experimental.AcceleratedDHTClient)
517 if err != nil {
518 return result, fmt.Errorf("creating default limit config: %w", err)
519 }
core/node/libp2p/rcmgr_defaults.go
+26 -6
@@ -89,7 +89,7 @@ var noLimitIncrease = rcmgr.BaseLimitIncrease{
89 // maxMemory, maxFD, or maxConns with Swarm.HighWater.ConnMgr.
90 // 3. Power user - They specify all the limits they want set via Swarm.ResourceMgr.Limits
91 // and we don't do any defaults/overrides. We pass that config blindly into libp2p resource manager.
92 -func createDefaultLimitConfig(cfg config.SwarmConfig) (rcmgr.LimitConfig, error) {
92 +func createDefaultLimitConfig(cfg config.SwarmConfig, acceleratedDHT bool) (rcmgr.LimitConfig, error) {
93 maxMemoryDefaultString := humanize.Bytes(uint64(memory.TotalMemory()) / 8)
94 maxMemoryString := cfg.ResourceMgr.MaxMemory.WithDefault(maxMemoryDefaultString)
95 maxMemory, err := humanize.ParseBytes(maxMemoryString)
@@ -132,9 +132,29 @@ func createDefaultLimitConfig(cfg config.SwarmConfig) (rcmgr.LimitConfig, error)
132 StreamsOutbound: 0,
133 },
134
135 - // Just go with what libp2p does
136 - TransientBaseLimit: rcmgr.DefaultLimits.TransientBaseLimit,
137 - TransientLimitIncrease: rcmgr.DefaultLimits.TransientLimitIncrease,
135 + TransientBaseLimit: rcmgr.BaseLimit{
136 + Streams: bigEnough,
137 + StreamsInbound: rcmgr.DefaultLimits.TransientBaseLimit.StreamsInbound,
138 + StreamsOutbound: bigEnough,
139 + Conns: bigEnough,
140 + ConnsInbound: rcmgr.DefaultLimits.TransientBaseLimit.ConnsInbound,
141 + ConnsOutbound: bigEnough,
142 + FD: rcmgr.DefaultLimits.TransientBaseLimit.FD,
143 + Memory: rcmgr.DefaultLimits.TransientBaseLimit.Memory,
144 + },
145 +
146 + TransientLimitIncrease: rcmgr.BaseLimitIncrease{
147 + Memory: rcmgr.DefaultLimits.TransientLimitIncrease.Memory,
148 + FDFraction: rcmgr.DefaultLimits.TransientLimitIncrease.FDFraction,
149 +
150 + Conns: 0,
151 + ConnsInbound: rcmgr.DefaultLimits.TransientLimitIncrease.ConnsInbound,
152 + ConnsOutbound: 0,
153 +
154 + Streams: 0,
155 + StreamsInbound: rcmgr.DefaultLimits.TransientLimitIncrease.StreamsInbound,
156 + StreamsOutbound: 0,
157 + },
158
159 // Lets get out of the way of the allow list functionality.
160 // If someone specified "Swarm.ResourceMgr.Allowlist" we should let it go through.
@@ -197,8 +217,8 @@ func createDefaultLimitConfig(cfg config.SwarmConfig) (rcmgr.LimitConfig, error)
217
218 defaultLimitConfig := scalingLimitConfig.Scale(int64(maxMemory), int(numFD))
219
200 - // If a high water mark is set:
201 - if cfg.ConnMgr.Type == "basic" {
220 + // If a high water mark is set (ignore when using accelerated DHT):
221 + if cfg.ConnMgr.Type == "basic" && !acceleratedDHT {
222 // set the connection limit higher than high water mark so that the ConnMgr has "space and time" to close "least useful" connections.
223 defaultLimitConfig.System.Conns = 2 * cfg.ConnMgr.HighWater
224 log.Info("adjusted default resource manager System.Conns limits to match ConnMgr.HighWater value of %s", cfg.ConnMgr.HighWater)