refactor(libp2p): drop asMultiaddr, use composite sort#3492
Merged
Conversation
Required for the multiaddr-only sort comparators being relocated from libp2p to @libp2p/utils.
Move the four multiaddr-only sort comparators from libp2p into @libp2p/utils, retyped to take Multiaddr directly. The Address-aware composition stays in libp2p (next commit).
Drops the inline implementations of the four multiaddr-only comparators. The Address-aware composition (defaultAddressSorter, certifiedAddressesFirst) stays here, feeding utils comparators through a small asMultiaddr adapter. Sort order is preserved.
One focused test per comparator validating direction and no-op-on-tie behavior, with bare Multiaddr inputs.
Convenience wrapper that chains the four multiaddr-only comparators in the standard priority order. Lets bare-Multiaddr callers sort without composing their own chain.
defaultAddressSorter now uses a single .sort() with a ||-chained composite comparator instead of five chained .sort() calls. Stable sort makes the two forms equivalent; the priority order (loopback > public > circuit > certified > reliable) is preserved.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Replaces the five chained
.sort()calls indefaultAddressSorterwith a single.sort()using a||-chained composite comparator. Drops theasMultiaddrhelper.Array.prototype.sortis stable, so a chain of stable sorts and a single lexicographic composite sort produce the same order for the same key list. Priority is preserved verbatim — loopback (primary) > public > circuit > certified > reliable (innermost tiebreaker).Notes & open questions
Followup to #3488.
Change checklist