Skip to content

Add filtering to get providers function #497

Open
DarkLord017 wants to merge 6 commits intoFilOzone:masterfrom
DarkLord017:feat/appfilteringforproviders
Open

Add filtering to get providers function #497
DarkLord017 wants to merge 6 commits intoFilOzone:masterfrom
DarkLord017:feat/appfilteringforproviders

Conversation

@DarkLord017
Copy link
Contributor

Fixes #147

Provider filtering feature:

  • Added a new ProviderFilterOptions interface in sp-registry/types.ts to specify filtering criteria such as type, location, piece size, IPNI support, service status, price, proving period, and randomization.
  • Implemented the providerFiltering method in SPRegistryService to filter providers according to the given options and optionally randomize the output.
  • Added a private _shuffle utility method to randomize provider lists when requested.
    )

@BigLep
Copy link
Contributor

BigLep commented Dec 17, 2025

@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.

@BigLep BigLep moved this from 📌 Triage to 🔎 Awaiting review in FOC Dec 17, 2025
private _shuffle<T>(array: T[]): T[] {
// Fisher-Yates shuffle
const arr = array.slice()
for (let i = arr.length - 1; i > 0; i--) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually write this loop condition like for (let i = arr.length; i-- > 0;)

return providers
}

private _shuffle<T>(array: T[]): T[] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be static because it doesn't use this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider moving it to rand.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

)
})

return filter.randomize ? this._shuffle(result) : result
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the order without randomize well-defined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

@github-project-automation github-project-automation bot moved this from 🔎 Awaiting review to ⌨️ In Progress in FOC Feb 3, 2026
@DarkLord017 DarkLord017 force-pushed the feat/appfilteringforproviders branch 2 times, most recently from 34901f3 to c19de80 Compare February 5, 2026 13:35
@BigLep BigLep moved this from ⌨️ In Progress to 🔎 Awaiting review in FOC Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🔎 Awaiting review

Development

Successfully merging this pull request may close these issues.

Add provider filtering and matching endpoint to Synapse API

3 participants