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

chore: config typescript #904

Merged
merged 12 commits into from
Apr 15, 2021
Merged

chore: config typescript #904

merged 12 commits into from
Apr 15, 2021

Conversation

vasco-santos
Copy link
Member

@vasco-santos vasco-santos commented Mar 26, 2021

This PR aims to:

  • update dependencies
  • switch protons to protobufjs
    • a bunch of files were automatically generated by this, which is a significant part of the PR changes
      • "src/circuit/protocol/index.js" and "...d.ts"
      • "src/insecure/proto.js" and "...d.ts"
      • "src/peer-store/persistent/pb/address-book.js" and "...d.ts"
      • "src/peer-store/persistent/pb/proto-book.js" and "...d.ts"
      • "src/record/peer-record/peer-record.js" and "...d.ts"
      • "src/record/envelope/envelope.js" and "...d.ts"
  • update aegir to latest version
    • fix types per no explicitly any allowed
    • added esbuild
  • guarantee all the possible libp2p configurations documented on GettingStarted.md and Configuration.md completely work with typescript projects
    • added test ts project
  • some bugs fixed, comments inline in review
  • restructure github actions into a new workflow for examples

There are internal breaking changes in the Dialer and Keychain property names to match what comes from the external config

Needs:

Unblocks:

Closes: #891
Solves some of the items from #830 (DHT, Config and Keychain)

BREAKING CHANGES:

top level types were updated, multiaddr@9.0.0 is used, dialer and keychain internal property names changed and connectionManager minPeers is not supported anymore

@@ -12,10 +12,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: yarn
- run: yarn lint
- run: npm install
Copy link
Member Author

Choose a reason for hiding this comment

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

Because yarn does not run prepare in the dependencies, libp2p-interfaces branch does not have types

concurrency = MAX_PARALLEL_DIALS,
timeout = DIAL_TIMEOUT,
perPeerLimit = MAX_PER_PEER_DIALS,
maxParallelDials = MAX_PARALLEL_DIALS,
Copy link
Member Author

Choose a reason for hiding this comment

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

This is an internal breaking change. No one should be creating a dialer from here though. If we don't want to change this, we can create a separate typedef for core options and keep things as they were. However, keeping different names for the same things does not seem the best call

Copy link

Choose a reason for hiding this comment

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

"No one should be" famous last words, how much confidence do you have in this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Does not make sense to require the Dialer and use it as a specific piece. However, I agree and it will be safe to just ship a breaking change at this point

Copy link
Member

Choose a reason for hiding this comment

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

If you're adding types it's good to ship as a major anyway as there will almost certainly be some disruption.

* @property {number} [interval = 300e3]
* @property {number} [timeout = 10e3]
*
* @typedef {Object} DhtOptions
Copy link
Member Author

Choose a reason for hiding this comment

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

This should probably go away when we work on the configuration improvements project. We currently also specify the DHT options in https://github.com/libp2p/js-libp2p/blob/master/src/config.js#L52 , but in theory we should accept other DHT implementations and this might mean different configurations.

@@ -118,8 +130,8 @@ class Keychain {
this.opts = mergeOptions(defaultOptions, options)

// Enforce NIST SP 800-132
if (this.opts.passPhrase && this.opts.passPhrase.length < 20) {
throw new Error('passPhrase must be least 20 characters')
if (this.opts.pass && this.opts.pass.length < 20) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Same situation as in the Dialer

@vasco-santos vasco-santos force-pushed the chore/config-ts branch 4 times, most recently from 718bc3d to 09fb967 Compare March 27, 2021 12:16
@@ -362,7 +365,7 @@ class ConnectionManager extends EventEmitter {
*/
_maybeDisconnectOne () {
if (this._options.minConnections < this.connections.size) {
const peerValues = Array.from(this._peerValues).sort(byPeerValue)
const peerValues = Array.from(new Map([...this._peerValues.entries()].sort((a, b) => a[1] - b[1])))
Copy link
Member Author

Choose a reason for hiding this comment

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

This was a bug! this.peerValues is a map<string, number>

for (const [, topology] of this.topologies) {
topology.disconnect(connection.remotePeer, error)
topology.disconnect(connection.remotePeer)
Copy link
Member Author

Choose a reason for hiding this comment

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

topology.disconnect only has one parameter

@vasco-santos vasco-santos force-pushed the chore/config-ts branch 3 times, most recently from 9c1d7da to 78019a1 Compare March 29, 2021 20:22
@@ -3,6 +3,7 @@
"version": "0.0.1",
"private": true,
"description": "",
"main": "dist/index.html",
Copy link

Choose a reason for hiding this comment

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

I'm guessing it's a parcel thing ..?

Copy link
Member Author

Choose a reason for hiding this comment

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

parcel thing per their new updates

package.json Outdated
@@ -127,22 +137,24 @@
"libp2p-delegated-peer-routing": "^0.8.0",
Copy link

Choose a reason for hiding this comment

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

lots of ^ in here for <1 dependencies, seems over-optimistic about how this is going to get consumed into the future

Copy link
Member Author

Choose a reason for hiding this comment

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

In the future, I would like that we get confidence in the APIs to ship v1 of all the things.

Copy link

Choose a reason for hiding this comment

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

My personal preference is to get to 1.0.0 ASAP (I've even set my default version to 1.0.0) because of the semver mess below 1 is just madness for signalling and ranges. The rules are basically "YOLO" which is useless for downstream users.
The problem with <0 is that your only signal for "breaking" changes is the minor version, but we've got ^ in here so there's no way to block breaking changes slipping in when we update one of these components. For <1, it's usually best to use ~ to account for the semver-minor bumps for breaking changes. Anyone using the current version of the library, even if they pin to the specific version, is going to get a newer, broken transitive dependency (like libp2p-delegated-peer-routing) when they do their next npm install because we've shipped with ^.
Alternatively, just don't treat 1.0.0 as anything special and ship it so we can use semver properly from there on.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes,I totally agree on this. The team has had a lot of concerns about shipping 1.0.0, but we need to have a plan to get to this point. I think that as part of sudo work we should create a plan on where should we be to land 1.0.0 on everything

Copy link
Member

Choose a reason for hiding this comment

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

Please ship v1 of things!

Alternatively, just don't treat 1.0.0 as anything special and ship it so we can use semver properly from there on.

Yes!

Copy link
Member Author

Choose a reason for hiding this comment

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

#680

we will need to do this refactor as part of the maintenance work and will affect most of our repos. So, this might be a good opportunity to ship v1 of libp2p modules

const { Exchange, KeyType } = require('./proto')
const protocol = '/plaintext/2.0.0'

/**
* @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
*/

/**
* @param {{ id: Uint8Array; pubkey: { Type: any, Data: Uint8Array; }; }} exchange
Copy link

Choose a reason for hiding this comment

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

potential candidate for a named type?

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed by relying on protobufjs instead of protons, which offers us all the types for protobuf definitions

@@ -82,7 +82,7 @@ class Stats extends EventEmitter {
/**
* Returns a clone of the internal movingAverages
*
* @returns {Object}
* @returns {typeof Object.assign}
Copy link

Choose a reason for hiding this comment

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

weird, can you explain this one?

Copy link
Member Author

Choose a reason for hiding this comment

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

No need for this, it can be inferred automatically. Good catch

Copy link

@rvagg rvagg left a comment

Choose a reason for hiding this comment

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

what's the versioning strategy going to be with this one? seems like a lot of potential to break for users - aside from the Dialer options the types might introduce breakage?

@vasco-santos
Copy link
Member Author

what's the versioning strategy going to be with this one? seems like a lot of potential to break for users - aside from the Dialer options the types might introduce breakage?

My initial idea was to ship a patch, but with all the types changes, I feel it will be safer to release a breaking change. This will have consequences on the release chain of upcoming releases (pinned issues), but they will probably be affected either way.

@rvagg rvagg mentioned this pull request Apr 10, 2021
77 tasks
src/index.js Outdated
@@ -152,7 +192,9 @@ class Libp2p extends EventEmitter {
this._discovery = new Map() // Discovery service instances/references

// Create the Connection Manager
if (this._options.connectionManager.minPeers) { // Remove in 0.29
// @ts-ignore deprecated, needs to be removed on breaking change
Copy link
Member Author

Choose a reason for hiding this comment

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

Since we are doing a breaking change, I am going to remove this!

Copy link
Member

@achingbrain achingbrain left a comment

Choose a reason for hiding this comment

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

LGTM, just some small nits.

.github/workflows/main.yml Outdated Show resolved Hide resolved
.github/workflows/main.yml Outdated Show resolved Hide resolved
@@ -12,11 +12,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: yarn
- run: yarn lint
- uses: gozala/typescript-error-reporter-action@v1.0.8
Copy link
Member

Choose a reason for hiding this comment

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

Did this get pulled out intentionally? It is quite useful.

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 changed based on: https://github.com/ipfs/aegir/blob/master/md/github-actions.md

Thought the recommendation was ts -p check

Copy link
Member

Choose a reason for hiding this comment

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

The error reporter action shows you which lines have errors in a visual form as part of the PR, the aegir command makes you dig through the console output. Both do the same thing and use the same rules but the action is a little more user friendly IMHO.

test/core/ping.node.js Outdated Show resolved Hide resolved
src/types.d.ts Outdated Show resolved Hide resolved
Co-authored-by: Alex Potsides <alex@achingbrain.net>
@vasco-santos vasco-santos merged commit 8506414 into master Apr 15, 2021
@vasco-santos vasco-santos deleted the chore/config-ts branch April 15, 2021 07:40
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.

3 participants