-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: capping mechanism for relay and service connections #3184
Conversation
You can find the image built from this PR at
Built from 96b37d4 |
2e420e4
to
fa97a4f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks so much!
Added just a couple questions/comments
@@ -993,6 +999,24 @@ proc new*( | |||
# Leave by default 20% of connections for service peers | |||
maxRelayPeersValue = maxConnections - (maxConnections div 5) | |||
|
|||
var maxServicePeersValue = 0 | |||
var d_low = 4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we shouldn't hardcode this and take it directly from WakuRelay
# relay has higher priority then service peers | ||
else: | ||
maxServicePeersValue = | ||
max(maxConnections - maxRelayPeersValue, maxConnections div 5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the logic of this line? Why the maxConnections div 5
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My logic is to reserve 20% for service peers if the user does not provide maxService, as we discuss in nwaku pm we need to change whole logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR doesn't compile snif snif :s
Re-thinking about this, I suggest doing the following:
We need to keep maxConnections
config param because this needs to be passed to the nim-libp2p-Switch object.
On the other hand, I would only add an additional parameter, named protoConnWeights
, a.k.a. proto-conn-weights
, with the following logic:
If proto-conn-weights
is not passed, then we apply the internal limits of 70% for relay, and the other 30% is evenly distributed for other protocols.
If proto-conn-weights=relay:80;services:20
, we apply the internal limits of 80% for relay, and the other 20% is evenly distributed for other protocols.
We need to make sure the relay limit is bigger than DHigh ( we can create a
public Constant
in waku_relay/protocol.nim
)
nwaku/waku/waku_relay/protocol.nim
Line 73 in 09f05fe
dHigh = 8, |
wdyt @NagyZoltanPeter , @gabrielmer , @darshankabariya ?
@@ -993,6 +995,20 @@ proc new*( | |||
# Leave by default 20% of connections for service peers | |||
maxRelayPeersValue = maxConnections - (maxConnections div 5) | |||
|
|||
var maxServicePeersValue = 0 | |||
var d_low = 4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will need to use the d_low value extracted from waku_relay
. Perhaps defining a const in waku_relay
and use that value
My bad, I pushed the code without a local build. I’ll update this PR until we finalize it. |
At the moment, we have parameters like Instead, I believe users generally don’t think in terms of absolute numbers for services and relays. From a psychological perspective, they might find it more intuitive to think in percentages—e.g., 80% for services, 20% for relays. My suggestion is to simplify this structure. We should keep If users don’t provide this percentage, we could default to a ratio, as Ivan suggested. I believe this would simplify the experience while maintaining flexibility. |
I like your idea! IMO I feel we still need hardcoded minimum still so that you can't, by mistake brick your node. |
Same opinion here, having 2 params, a maximum and a ratio to know how many to allocate for each should make things simple yet customizable :) |
Thanks @gabrielmer @SionoiS for reply ! i also like suggestion. If this approach looks good to you, I can begin the implementation. Just to confirm, we're only discussing the deprecation of the external configuration parameter, correct? I believe we still need to maxRelayPeer and maxServicePeer within the peerManager. Regarding your thoughts on the ratio, I have an idea: instead of using a float, we could represent it as a string, like 0.33 becoming 40:60 or 0.43 as 30:70. it's just need calculator 😂for some ratio, Let me know what you guys think, and I’ll implement accordingly. |
02fd08c
to
ab0c1d4
Compare
Yes! That would only be for the external configuration, we would then translate it into Regarding the format, I'm pretty neutral about it - no strong opinions. Would like to hear what others think :)) |
If that's simpler go for it! No strong opinion here either. |
d5a12ef
to
049fbea
Compare
4366e81
to
6d637a9
Compare
4f141a3
to
c9716b2
Compare
509fce5
to
eef0d11
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for it and the patience! 🙌
I think we still need to keep backward compatibility with the current max-relay-peers
param.
On the other hand, my dreamed nwaku only deals with Result
types, doesn't use discard
and doesn't raise Exception either ;P
try: | ||
let elements = ratio.split(":") | ||
if elements.len != 2: | ||
raise newException(ValueError, "expected format 'X:Y', ratio = " & ratio) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, sorry that I didn't mention before. Would it be possible to avoid raising an exception plz? Applies elsewhere. We already have the Resullt
returning type to tackle the err
conditions, unless I'm missing something :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it.
@@ -101,8 +101,15 @@ proc initNode( | |||
agentString = some(conf.agentString), | |||
) | |||
builder.withColocationLimit(conf.colocationLimit) | |||
|
|||
# Backword compatibility for maxRelayPeers | |||
if conf.maxRelayPeers.isSome(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this condition is true
, then we need to infer the relayServiceRation
based on the given conf.maxConnections
and conf.maxRelayPeers
. And we need to keep this temporarily within two consecutive versions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your review and patience. It’s now backward compatible and parse function without raising exceptions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for it! 💯 🥳
waku/factory/builder.nim
Outdated
) = | ||
builder.maxRelayPeers = maxRelayPeers | ||
builder.shardAware = shardAware | ||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe not needed to handle exception now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes ! we already handle in function.
var relayRatio: float64 | ||
var serviceRatio: float64 | ||
try: | ||
(relayRatio, serviceRatio) = parseRelayServiceRatio(relayServiceRatio).get() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome thanks! I think now we don't need to handle the exception
This PR prevents nodes from becoming isolated from the network by implementing a capping mechanism for service and relay peers. This ensures there is always room available for relay peers at any given time.
close #3163