-
Notifications
You must be signed in to change notification settings - Fork 134
Description
Hi 👋
I'd like to request a way to disable the forced provider order randomization in HTTPGatewayRouter
. I've debugged spotty gateway retrievals for a while, and found the source to be this in findProviders
.
Background
Some content that the service I'm writing needs to retrieve and pin can only be fetched from ipfs.desci.com (which has noFetch: true
, and hence fails fast), and a disjoint set is available from pub.desci.com (which doesn't, and times out).
I configured Helia routing with this HTTPGatewayRouter
, expecting it to try them in order. This would always be optimal in this use case.
httpGatewayRouting({
gateways: ["https://ipfs.desci.com", "https://pub.desci.com"],
}),
Issue
However, there is a "mandatory" randomization in HTTPGatewayRouter
that shuffles the providers every time, which means that only half of my requests first check the fast gateway, and the other half only after the other gateway times out looking for content only available over the other gateway.
async * findProviders (cid: CID<unknown, number, number, Version>, options?: RoutingOptions | undefined): AsyncIterable<Provider> {
// TODO: opt out of this random sort
yield * this.gateways.toSorted(() => Math.random() > 0.5 ? 1 : -1).map(info => ({
...info,
protocols: ['transport-ipfs-gateway-http']
}))
}
Suggested fix
I would like to request the option of passing args down to opt out from this randomization, to enable working with gateway tiers like in our use case.