Skip to content

feat(pinner): support pre-created Libp2p instance#1100

Merged
pcfreak30 merged 1 commit into
developfrom
feat/pinner-pre-created-libp2p
Jul 9, 2026
Merged

feat(pinner): support pre-created Libp2p instance#1100
pcfreak30 merged 1 commit into
developfrom
feat/pinner-pre-created-libp2p

Conversation

@pcfreak30

@pcfreak30 pcfreak30 commented Jul 9, 2026

Copy link
Copy Markdown
Member

Problem

Helia v7's createHelia() calls withLibp2p(helia) without passing the libp2p option through — init.libp2p is silently ignored. This causes Helia to always invoke createLibp2p() / libp2pDefaults(), which configures WebRTC and UPnP transports that crash in environments without native addons (e.g. GitHub Actions runners).

The downstream effect: WebRTCDirectTransport.start()loadOrCreatePrivateKey()keychain.exportKey()UnstorageDatastore.get() throws a plain Error instead of NotFoundErrorDatastore item not found: /pkcs8/webrtc-direct-certificate-private-key crash.

Solution

When config.libp2p is provided, getHelia() bypasses createHelia() and manually composes the same pipeline:

createHeliaLight({...}) → withHTTP → withLibp2p(helia, libp2p) → withBitswap

The pre-created instance passes the isLibp2p() check in getLibp2p(), so createLibp2p() / libp2pDefaults() is skipped entirely — no WebRTC, no UPnP, no native addons loaded.

Changes

  • config.ts — Add libp2p?: Libp2p to PinnerConfig
  • car.ts — Add libp2p?: Libp2p to CarConfig; getHelia() uses manual composition when config.libp2p is provided, falls back to createHelia() otherwise
  • manager.ts — Pass libp2p through UploadManagerconfigureCar()
  • package.json — Add @helia/bitswap, @helia/libp2p, @ipld/dag-cbor, @ipld/dag-json, @libp2p/interface as dependencies
  • pnpm-workspace.yaml — Add catalog entries for new deps

Backward Compatibility

Fully backward compatible. When libp2p is not provided, createHelia() is used as before — no behavior change for existing consumers.


This pull request adds support for passing a pre-created Libp2p instance into the Pinner's Helia configuration. When a Libp2p instance is provided, the Pinner bypasses Helia's internal createLibp2p() / libp2pDefaults() flow and instead manually composes a lightweight Helia pipeline (createHeliaLightwithHTTPwithLibp2pwithBitswap). This avoids loading unnecessary transports such as WebRTC and UPnP, reducing overhead and giving callers full control over the Libp2p node used by Helia.

Key changes:

  • Added an optional libp2p property to both PinnerConfig and CarConfig interfaces.
  • Updated the Helia initialization in the CAR upload module to use the pre-created Libp2p instance when available, falling back to the standard createHelia() otherwise.
  • Threaded the libp2p config option through the UploadManager to the CAR configuration.
  • Added the necessary dependencies (@helia/bitswap, @helia/libp2p, @ipld/dag-cbor, @ipld/dag-json, @libp2p/interface) and updated the lockfile and workspace catalog.

Helia v7's createHelia() calls withLibp2p(helia) without passing
the libp2p option through — init.libp2p is silently ignored. This
causes Helia to always invoke createLibp2p() / libp2pDefaults(),
which configures WebRTC and UPnP transports that crash in
environments without native addons (e.g. GitHub Actions).

When config.libp2p is provided, getHelia() now manually composes
the pipeline: createHeliaLight → withHTTP → withLibp2p(helia,
libp2p) → withBitswap. The pre-created instance passes the
isLibp2p() check in getLibp2p(), skipping createLibp2p() entirely.

- Add libp2p field to PinnerConfig and CarConfig
- Flow libp2p through UploadManager → configureCar
- Add @helia/bitswap, @helia/libp2p, @ipld/dag-cbor, @ipld/dag-json,
  @libp2p/interface as dependencies
- Backward compatible: when libp2p is not provided, createHelia()
  is used as before
@kody-ai

kody-ai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Validate Business Logic: Ask Kody to validate your code against business rules by adding a comment with the @kody -v business-logic command.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug
Performance
Security
Business Logic

Access your configuration settings here.

Comment thread libs/pinner/src/upload/car.ts
@pcfreak30 pcfreak30 merged commit 27c6d51 into develop Jul 9, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant