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

feat: support p2p retrieval by default #130

Merged
merged 36 commits into from
Nov 21, 2024
Merged

feat: support p2p retrieval by default #130

merged 36 commits into from
Nov 21, 2024

Conversation

2color
Copy link
Member

@2color 2color commented Nov 5, 2024

Description

Notes & open questions

  • Does this direction make sense?

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if necessary (this includes comments as well)
  • I have added tests that prove my fix is effective or that my feature works

@2color 2color requested a review from a team as a code owner November 5, 2024 16:39
@2color
Copy link
Member Author

2color commented Nov 7, 2024

As discussed during Helia WG:

Moving forward suggestion we agreed on:
- Only using helia-p2p
- Remove the new options added by this PR

@2color 2color changed the title feat: add support for p2p retrieval feat: support p2p retrieval by default Nov 18, 2024
@SgtPooki
Copy link
Member

@2color I think we need to work on updating the deps across all packages and getting gateway conformance passing before this will pass. I'm focusing on updating the deps, and once that is done, we should be able to pass this one.

Copy link
Member

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

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

self review.

@2color this is fully updated. mind taking a look at the code?

packages/verified-fetch/src/index.ts Outdated Show resolved Hide resolved
],
dns: createDns(init?.dnsResolvers),
Copy link
Member

Choose a reason for hiding this comment

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

FYI: setting libp2pConfig.dns was causing some failures in tests. do we need that? dns should be handled at the helia layer shouldn't it?

cc @2color @achingbrain

Copy link
Member Author

Choose a reason for hiding this comment

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

I think both Helia and libp2p rely on the DNS type. For libp2p it's mostly for resolving dnsaddr multiaddrs.

@SgtPooki
Copy link
Member

SgtPooki commented Nov 18, 2024

NOTE: chrome browser tests are failing in CI because playwright isn't installed. I pinged IPDX on slack

@achingbrain
Copy link
Member

chrome browser tests are failing in CI because playwright isn't installed

They're failing because https://github.com/microsoft/playwright shipped a breaking change - the fix is here: hugomrdias/playwright-test#685

@achingbrain
Copy link
Member

The browser tests should run now but 74e27ac broke ts compilation so that'll need to be fixed first.

@2color
Copy link
Member Author

2color commented Nov 19, 2024

I realised that I didn't consider node.js in this PR. So some of the libp2p config modifications don't make sense.

For example, using a circuit relay listener in node.js is helpful for hole punching but isn't necessary in browsers. Same thing with the DHT client.

This is a bit of a hairy one, but I'm thinking that we may just want to have a browser override in this package and handle it like we do in Helia.

@SgtPooki SgtPooki self-requested a review November 19, 2024 17:49
Copy link
Member Author

Choose a reason for hiding this comment

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

I appreciate that you were able to fix this, but I'm worried that this is appeasing the TS compiler at the cost of the types actually helping us.

Copy link
Member

Choose a reason for hiding this comment

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

The thing with the services type is that we don't really care since we don't ever touch them.. but I mostly just wanted to unblock the build. I am working on adding a test now.

sometimes, you have to coerce types, and I think the pros of coercing types outweigh the cons of adding a bunch of direct deps on all the libp2p things

export interface Libp2pServices extends BaseServiceMap, DelegatedRoutingServices, Record<string, any> {
// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
export interface Libp2pServices extends BaseServiceMap, DelegatedRoutingServices {
[key: string]: any
Copy link
Member

Choose a reason for hiding this comment

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

This is a bit weird, Record<string, any> and { [key: string]: any } are the same type. How does the Record version break things?

Copy link
Member

Choose a reason for hiding this comment

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

[12:42:33] tsc [started]
src/index.ts(823,33): error TS2345: Argument of type 'VerifiedFetchLibp2p' is not assignable to parameter of type 'Libp2pOptions<{ [x: string]: ...; }> | undefined'.
  Type 'VerifiedFetchLibp2p' is not assignable to type 'Libp2pOptions<{ [x: string]: ...; }>'.
    Type 'VerifiedFetchLibp2p' is not assignable to type 'Libp2pInit<{ [x: string]: ...; }>'.
      Types of property 'services' are incompatible.
        Type 'Libp2pServices' is not assignable to type 'ServiceFactoryMap<{ [x: string]: ...; }>'.
          'string' index signatures are incompatible.
            Type 'unknown' is not assignable to type '(components: Components & { [x: string]: ...; }) => unknown'.
[12:42:34] tsc [failed]
[12:42:34] → Command failed with exit code 1: tsc

Copy link
Member

Choose a reason for hiding this comment

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

We can do something like

export type Libp2pServices<T extends ServiceMap = ServiceMap> = {
  [Property in keyof T]: (components: any & T) => T[Property]
} & BaseServiceMap & DelegatedRoutingServices

¯\_(ツ)_/¯

@SgtPooki
Copy link
Member

There are so many fixes here that have nothing to do with libp2p or enabling p2p by default.. these changes should probably be pulled out into #141

@SgtPooki
Copy link
Member

There are so many fixes here that have nothing to do with libp2p or enabling p2p by default.. these changes should probably be pulled out into #141

This is done in 70cde6f (#141)

@2color
Copy link
Member Author

2color commented Nov 21, 2024

I managed to somewhat simplify the types. Going to merge this so that we can publish the blog post that includes a runnable example. We can further iterate in followup PRs.

@2color 2color merged commit 9d33f89 into main Nov 21, 2024
20 checks passed
@2color 2color deleted the add-p2p branch November 21, 2024 12:03
github-actions bot pushed a commit that referenced this pull request Nov 21, 2024
## [@helia/verified-fetch-v2.2.0](https://github.com/ipfs/helia-verified-fetch/compare/@helia/verified-fetch-2.1.3...@helia/verified-fetch-2.2.0) (2024-11-21)

### Features

* support p2p retrieval by default ([#130](#130)) ([9d33f89](9d33f89))
Copy link

🎉 This PR is included in version @helia/verified-fetch-v2.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants