Skip to content
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

Update Helia to fallback to trustless HTTP gateways #274

Closed
10 of 11 tasks
Tracked by #255
SgtPooki opened this issue Oct 2, 2023 · 14 comments
Closed
10 of 11 tasks
Tracked by #255

Update Helia to fallback to trustless HTTP gateways #274

SgtPooki opened this issue Oct 2, 2023 · 14 comments
Assignees

Comments

@SgtPooki
Copy link
Member

SgtPooki commented Oct 2, 2023

discussed in https://pl-strflt.notion.site/Helia-reliable-retrieval-technical-design-golden-path-255-15c4d3c25a404a85b6db8bf3f8d1f310?pvs=4

Should do #272 first

Tasks

  1. SgtPooki
  2. SgtPooki
  3. SgtPooki
  4. SgtPooki
  5. SgtPooki
@SgtPooki
Copy link
Member Author

SgtPooki commented Oct 4, 2023

#276 is still in progress, but I could use some input from @achingbrain that the direction i'm heading in works before I flesh everything out

@SgtPooki
Copy link
Member Author

SgtPooki commented Oct 9, 2023

some of this work was moved to #280 and also #281 on top of that

@SgtPooki
Copy link
Member Author

The work here is done and merged into the main branch but is not released on @latest tag on npm yet. You can experiment with the changes made on the @next tag.

@BigLep
Copy link
Contributor

BigLep commented Oct 17, 2023

@SgtPooki : what are the conditions for closing this?

  1. Helia release?
  2. Any additional docs we need to add? (or is that already in the API docs)? (If already in the API docs, can you point me to the relevant ones so I can look at them from a user's point of view?)
  3. ?

Thanks

@SgtPooki
Copy link
Member Author

@SgtPooki : what are the conditions for closing this?

  1. Helia release?

Yep. I discussed this with Alex and we talked about how we would let this sit in @next tagged release and request devs try it out for a bit before merging it. There's no guarantee that devs will try it, but I plan to.

  1. Any additional docs we need to add? (or is that already in the API docs)? (If already in the API docs, can you point me to the relevant ones so I can look at them from a user's point of view?)

Docs are not published yet but should be in https://helia.io/interfaces/helia.HeliaInit.html & https://helia.io/modules/_helia_interface.blocks.html when they are. You can see the docs that will be mentioned in the source here:

  • /**
    * A list of strategies used to fetch blocks when they are not present in
    * the local blockstore
    */
    blockBrokers?: Array<(components: any) => BlockBroker>
  • export type BlockRetrievalOptions<GetProgressOptions extends ProgressOptions = ProgressOptions> = AbortOptions & GetProgressOptions & {
    /**
    * A function that blockBrokers should call prior to returning a block to ensure it can maintain control
    * of the block request flow. e.g. TrustedGatewayBlockBroker will use this to ensure that the block
    * is valid from one of the gateways before assuming it's work is done. If the block is not valid, it should try another gateway
    * and WILL consider the gateway that returned the invalid blocks completely unreliable.
    */
    validateFn?(block: Uint8Array): Promise<void>
    }
    export interface BlockRetriever<GetProgressOptions extends ProgressOptions = ProgressOptions> {
    /**
    * Retrieve a block from a source
    */
    retrieve(cid: CID, options?: BlockRetrievalOptions<GetProgressOptions>): Promise<Uint8Array>
    }
    export interface BlockAnnouncer<NotifyProgressOptions extends ProgressOptions = ProgressOptions> {
    /**
    * Make a new block available to peers
    */
    announce(cid: CID, block: Uint8Array, options?: NotifyProgressOptions): void
    }
    export type BlockBroker = BlockRetriever | BlockAnnouncer

It could be worth adding some info to the wiki or README including the diagrams at #272 once we decide we will release these changes.

@pcfreak30
Copy link

I can actually confirm the trustless gateway works. The only issue are some of the gateways don't properly allow CORS which causes issues in browser when fetching CAR data.

@SgtPooki
Copy link
Member Author

@pcfreak30 thanks for the update! Which gateways were causing issues?

@pcfreak30
Copy link

@pcfreak30 thanks for the update! Which gateways were causing issues?

I would honestly test them all. I am using a rather complex system that is powered by webworkers inside iframes. The CORS should be such it allows everything.

@SgtPooki
Copy link
Member Author

Yea, will do. FYI, you can limit the gateway urls you enable by setting blockBrokers in the config object passed to createHelia:

import { createHelia, type Helia } from 'helia'
import { bitswap, trustlessGateway } from 'helia/block-brokers'

await createHelia({
      blockBrokers: [
        bitswap(),
        trustlessGateway({ gateways: ['https://dweb.link', 'https://ipfs.io'] })
      ]
    })

@SgtPooki
Copy link
Member Author

FYI that I threw a quick codepen together that shows this working fine for all default gateways: https://codepen.io/SgtPooki/pen/JjxYpZX

@pcfreak30
Copy link

I will update if I can replicate in my setup, thanks.

@pcfreak30
Copy link

@SgtPooki i was able to get a screenshot from a tester.

image

@BigLep
Copy link
Contributor

BigLep commented Jan 9, 2024

@SgtPooki : what is needed for closing out this issue?

@SgtPooki
Copy link
Member Author

I believe this is done except for #374. The spec work for other gateways is at ipfs/specs#423.

closing this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: 🏃‍♀️ In Progress
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants