Add filtering to get providers function #497
Open
DarkLord017 wants to merge 6 commits intoFilOzone:masterfrom
Open
Add filtering to get providers function #497DarkLord017 wants to merge 6 commits intoFilOzone:masterfrom
DarkLord017 wants to merge 6 commits intoFilOzone:masterfrom
Conversation
Contributor
|
@DarkLord017 : Thank you for contributing. My guess is this PR won't get looked at for a bit because #147 isn't in our GA milestone. Just letting you know to set expectations. |
wjmelements
reviewed
Feb 3, 2026
| private _shuffle<T>(array: T[]): T[] { | ||
| // Fisher-Yates shuffle | ||
| const arr = array.slice() | ||
| for (let i = arr.length - 1; i > 0; i--) { |
Contributor
There was a problem hiding this comment.
I usually write this loop condition like for (let i = arr.length; i-- > 0;)
wjmelements
requested changes
Feb 3, 2026
| return providers | ||
| } | ||
|
|
||
| private _shuffle<T>(array: T[]): T[] { |
Contributor
There was a problem hiding this comment.
this can be static because it doesn't use this.
Contributor
There was a problem hiding this comment.
consider moving it to rand.ts
| ) | ||
| }) | ||
|
|
||
| return filter.randomize ? this._shuffle(result) : result |
Contributor
There was a problem hiding this comment.
is the order without randomize well-defined?
Contributor
Author
There was a problem hiding this comment.
They are sorted by ids see this in service provider registry contract
for (uint256 i = 1; i <= numProviders && resultIndex < limit; i++) {
if (providers[i].isActive) {
if (currentIndex >= offset && currentIndex < offset + limit) {
providerIds[resultIndex++] = i;
}
currentIndex++;
}
}
and in synapse
if (providerIds.length > 0) {
const ids = providerIds.map((id: bigint) => Number(id))
providerPromises.push(this.getProviders(ids))
}
offset += pageSize
}
// Wait for all provider details to be fetched and flatten the results
const providerBatches = await Promise.all(providerPromises)
return providerBatches.flat()
wjmelements
reviewed
Feb 4, 2026
34901f3 to
c19de80
Compare
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.
Fixes #147
Provider filtering feature:
ProviderFilterOptionsinterface insp-registry/types.tsto specify filtering criteria such astype,location, piece size, IPNI support, service status, price, proving period, and randomization.providerFilteringmethod inSPRegistryServiceto filter providers according to the given options and optionally randomize the output._shuffleutility method to randomize provider lists when requested.)