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!: 2.0 breaking changes #2663

Merged
merged 8 commits into from
Sep 6, 2024
Merged

feat!: 2.0 breaking changes #2663

merged 8 commits into from
Sep 6, 2024

Conversation

achingbrain
Copy link
Member

This PR is of the branch containing all changes for the v2 release.

Important - it must not be squashed on merge, otherwise the changelog/release notes will not be generated with all of the breaking changes listed.

@achingbrain achingbrain changed the title fix!: remove CustomEvent export from @libp2p/interface (#2656) feat!: 2.0 breaking changes Aug 14, 2024
@achingbrain achingbrain added the version-2.0 PRs that will be released in libp2p v2 label Aug 15, 2024
@achingbrain achingbrain marked this pull request as ready for review September 6, 2024 07:05
@achingbrain achingbrain requested a review from a team as a code owner September 6, 2024 07:05
`CustomEvent` is global in Node.js as of `v18.7.0`. We support LTS
and Current which means `v20+`, and Electron has upgraded to node
20 so the polyfill isn't necessary any more.

BREAKING CHANGE: `@libp2p/interface` no longer exports a `CustomEvent` polyfill
achingbrain and others added 7 commits September 6, 2024 10:40
To better align with [[email protected]](https://github.com/libp2p/go-libp2p/releases/tag/v0.34.0)
rename "transient" connections to "limited".

BREAKING CHANGE: There are three breaking API changes:
  * Connections have an optional `.limits` property
  * The `runOnTransientConnection` property of `libp2p.handle` and `libp2p.dialProtocol` has been renamed to `runOnLimitedConnection`
  * The `notifyOnTransient` property of `libp2p.register` has been renamed `notifyOnLimitedConnection`

Refs: #2622
Requiring the local peer id in connection encryption appears to be historical cruft. The more current approach would be to have a `ConnectionEncrypter` be specific to a single peer id, passed in during instantiation in its Components.

BREAKING CHANGE: removes `localPeer: PeerId` first parameter from `secureInbound` and `secureOutbound` in `ConnectionEncrypter`

---------

Co-authored-by: Alex Potsides <[email protected]>
JavaScript errors have a `.name` property that can be used to
disambiguate the type of error.

libp2p has used the `.code` property for this until now, but we will
soon use that field to indicate remote errors, so switch to using
the `.name` property.

BREAKING CHANGE: The `.code` property has been removed from most errors, use `.name` instead
The autodialer is a feature from an older time when the DHT was less reliable and we didn't have things like the random walk component.

There's not a lot of benefit in opening connections to any old peer, instead protocols now have better ways of targetting the kind of peers they require.

Actively dialing peers harms platforms where connections are extremely expensive such as react-native so this feature has been removed.

Closes #2621
Fixes #2418

BREAKING CHANGE: the autodialer has been removed as well as the corresponding config keys

---------

Co-authored-by: Russell Dempsey <[email protected]>
To allow doing things like having a single `AbortSignal` that can be used as a timeout for incoming connection establishment, allow passing it as an option to the `ConnectionEncrypter` `secureOutbound` and `secureInbound` methods.

Previously we'd wrap the stream to be secured in an `AbortableSource`, however this has some [serious performance implications](ChainSafe/js-libp2p-gossipsub#361) and it's generally better to just use a signal to cancel an ongoing operation instead of racing every chunk that comes out of the source.

BREAKING CHANGE: the final argument to `secureOutbound` and `secureInbound` in the `ConnectionEncrypter` interface is now an options object

---------

Co-authored-by: chad <[email protected]>
The only time you should ever see a private key on a `PeerId` is for the id of the currently running node.  An exception to this is the keychain which used `PeerId`s to export private keys, but a nicer API there is to just deal with `PrivateKey` instances directly.

At runtime a service can obtain the unmarshaled private key by adding a `privateKey: PrivateKey` field to it's components map so there's no need to have the field on every `PeerId`.

The `publicKey` field of a `PeerId` was a `Uint8Array` which (if present) held the public key bytes in a protobuf wrapper along with a field saying what type of key it was.  This was because we wanted to avoid pulling `@libp2p/crypto` into front ends, since it had a dependency on `node-forge` which was a large blob of untreeshakable CSJ code.  This dependency has been removed so `@libp2p/crypto` is now comparatively lightweight so we can use the `PublicKey` type instead of `Uint8Array`, which also saves CPU time since we don't need to unmarshal the key before we can use it.

Fixes #2659

BREAKING CHANGE:
  - The `.privateKey` field of the `PeerId` interface has been removed
  - The `.publicKey` field of the `PeerId` interface is now a `PublicKey` instead of a `Uint8Array`
  - `createLibp2p` now accepts a `privateKey` instead of a `peerId`
  - The keychain operates on `PrivateKey` instances instead of `PeerId`s with `.privateKey` fields
  - `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead
Adds instructions for how to upgrade from v1.x to v2.x

---------

Co-authored-by: Russell Dempsey <[email protected]>
@achingbrain achingbrain merged commit 1bc7c01 into main Sep 6, 2024
21 checks passed
@achingbrain achingbrain deleted the release-v2.0 branch September 6, 2024 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
version-2.0 PRs that will be released in libp2p v2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants