-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[swarm] Configurable and "infinite" scores for external addresses. #1842
Conversation
Extend address scores with an infinite cardinal, permitting addresses to be retained "forever" or until explicitly removed. Expose (external) address scores on the API.
Thanks for tackling this! In my opinion, this external addresses scoring system isn't great. It is a bit opaque, and multiple For example, the But if we go under the constraint that we keep this scoring system, which is the best short-term solution, then this PR does make sense. |
I tried to improve the documentation, but I'm not sure what you mean by different behaviours competing. If they both issue a report for the same address, the effect is cumulative. For different addresses the ones that are reported with the higher cumulative score (e.g. either more frequently or with higher scores) have the higher retention and priority. That seems to make sense to me, even under composition of behaviors. Of course behaviours / protocols should make an attempt at documenting how they go about reporting addresses, like I did for identify, to better reason about the composition. Nevertheless I'm open to alternative proposals on how to handle external addresses, i.e. feel free to open a new issue describing the problems with the current approach and possible alternatives, if you already have something in mind.
That was my current understanding at least, so I only looked into extending it, rather than replacing it. Unless we already have a clear idea of how a replacement should look like, I would also suggest to go with this for now. |
Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
That's indeed the only solution to this problem. When I say "It is very difficult to understand the behaviour of external addresses without knowing how the entirety of libp2p works.", what I mean is that you need to look at the precise documentation of every It would be preferable to me, although probably difficult to achieve, that adding a network behaviour to the stack never has any negative consequence on the others.
I didn't mention anything about keeping or replacing the current system because I also don't know how we could replace it. I'm fine with keeping it if there's no obvious suitable replacement. |
Motivation
It is currently not possible to add external addresses to a
Swarm
that are retained forever. All added or observed external addresses are added to an ordered list with a finite score (1
) for every new addition and thus subject to being purged eventually. It is desirable to be able to add addresses to this collection that are retained until explicitly removed and always sorted at the beginning, not influencing the existing semantics for the additional finite scores and expiring addresses. It also seems desirable to let the score of a particular address report / observation be chosen freely, instead of being fixed to1
. The motivation relates to paritytech/substrate#7518.To that end, this PR extends the address score arithmetic used for external addresses with an infinite cardinal, permitting addresses with such a score to be retained "forever" or until explicitly removed, thereby exposing address scores on the public API for more insight and configurability.
Implementation
u32
but anAddressScore
, i.e. eitherAddressScore::Finite(u32)
orAddressScore::Infinite
.Swarm::add_external_address
now takes both aMultiaddr
and anAddressScore
.NetworkBehaviourAction::ReportObservedAddr
now also takes anAddressScore
in addition to theMultiaddr
. TheIdentify
behaviour reports all addresses with a finite score of1
, i.e. the same semantics as before.Swarm::remove_external_address
for explicit removal, regardless of score. This allows for explicit curation of the external address list.AddressRecord
s.NetworkBehaviour::poll
are also accompanied by their score (again viaAddressRecord
s).