From e07438d3060f33581a1c0c077de8ca043007081d Mon Sep 17 00:00:00 2001 From: Sergei Tikhomirov Date: Thu, 10 Jul 2025 17:41:42 +0200 Subject: [PATCH] minor refactor for DRY --- waku/factory/node_factory.nim | 44 ++++++++++++++++------------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/waku/factory/node_factory.nim b/waku/factory/node_factory.nim index 7c7c71679..9080b755e 100644 --- a/waku/factory/node_factory.nim +++ b/waku/factory/node_factory.nim @@ -122,31 +122,27 @@ proc initNode( else: false - if conf.maxRelayPeers.isSome(): - let - maxRelayPeers = conf.maxRelayPeers.get() - maxConnections = conf.maxConnections - # Calculate the ratio as percentages - relayRatio = (maxRelayPeers.float / maxConnections.float) * 100 - serviceRatio = 100 - relayRatio + let relayServiceRatio = + if conf.maxRelayPeers.isSome(): + let + maxRelayPeers = conf.maxRelayPeers.get() + maxConnections = conf.maxConnections + # Calculate the ratio as percentages + relayRatio = (maxRelayPeers.float / maxConnections.float) * 100 + serviceRatio = 100 - relayRatio + + error "maxRelayPeers is deprecated. It is recommended to use relayServiceRatio instead. If relayServiceRatio is not set, it will be automatically calculated based on maxConnections and maxRelayPeers." + $relayRatio & ":" & $serviceRatio + else: + conf.relayServiceRatio - # FIXME: DRY - builder.withPeerManagerConfig( - maxConnections = conf.maxConnections, - relayServiceRatio = $relayRatio & ":" & $serviceRatio, - shardAware = conf.relayShardedPeerManagement, - eligibilityEnabled = eligibilityEnabled, - reputationEnabled = reputationEnabled, - ) - error "maxRelayPeers is deprecated. It is recommended to use relayServiceRatio instead. If relayServiceRatio is not set, it will be automatically calculated based on maxConnections and maxRelayPeers." - else: - builder.withPeerManagerConfig( - maxConnections = conf.maxConnections, - relayServiceRatio = conf.relayServiceRatio, - shardAware = conf.relayShardedPeerManagement, - eligibilityEnabled = eligibilityEnabled, - reputationEnabled = reputationEnabled, - ) + builder.withPeerManagerConfig( + maxConnections = conf.maxConnections, + relayServiceRatio = relayServiceRatio, + shardAware = conf.relayShardedPeerManagement, + eligibilityEnabled = eligibilityEnabled, + reputationEnabled = reputationEnabled, + ) builder.withRateLimit(conf.rateLimits) builder.withCircuitRelay(relay)