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: upgrade bn.js from 4.12 to 5.2 #1121

Closed
wants to merge 1 commit into from

Conversation

pradel
Copy link
Contributor

@pradel pradel commented Oct 19, 2021

Description

At the moment @stacks/connect is using bn.js version 5.2 and the packages of this repo the version 4.12. This means that when we use both connect and stacks.js packages in our app, we will end up having 2 versions of bn.js in our bundle.

What I did was to upgrade bn.js dependency from 4.12 to the next major 5.2 so both connect and stacks.js use the same version.

stacks-wallet-web is already using 5.2 too https://github.com/blockstack/stacks-wallet-web/blob/main/package.json#L71

Related to issue #1120, I noticed that bn.js is included twice in my bundle.

Type of Change

  • New feature
  • Bug fix
  • API reference/documentation update
  • Other

Does this introduce a breaking change?

All the tests are passing so not sure if this qualifies as a breaking change as users won't be impacted directly by this change.

Are documentation updates required?

I don't think so.

Checklist

  • Code is commented where needed
  • Unit test coverage for new or modified code paths
  • npm run test passes
  • Changelog is updated
  • Tag 1 of @yknl or @zone117x for review

@vercel
Copy link

vercel bot commented Oct 19, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/blockstack/stacks-js/3xmSah7pty8JFaaQPMjbdgVVN83r
✅ Preview: https://stacks-js-git-fork-pradel-feature-upgrade-bnjs-52-blockstack.vercel.app

@codecov
Copy link

codecov bot commented Oct 19, 2021

Codecov Report

Merging #1121 (0b58369) into master (8b4fdb5) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1121   +/-   ##
=======================================
  Coverage   62.64%   62.64%           
=======================================
  Files         113      113           
  Lines        8196     8196           
  Branches     1529     1529           
=======================================
  Hits         5134     5134           
  Misses       2947     2947           
  Partials      115      115           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8b4fdb5...0b58369. Read the comment docs.

@@ -31,11 +31,11 @@
},
"dependencies": {
"@stacks/common": "^2.0.1",
"@types/bn.js": "^4.11.6",
"@types/bn.js": "^5.1.0",
"@types/node": "^14.14.43",
"bip39": "^3.0.2",
"bitcoinjs-lib": "^5.2.0",
Copy link
Member

Choose a reason for hiding this comment

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

IIRC it was the bitcoinjs family of libs (this one and some of the bip libs) that were including bn.js v4. Have you tested that these dependencies don't end up requiring bn.js v4 to be bundled anyway?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Other packages are depending of v4, my idea was to do the upgrade gradually, here is the list of deps still using it (might have missed some):

  • @stacks/keychain
    • @blockstack/rpc-client 0.3.0-alpha.11
      • @blockstack/stacks-transactions 0.5.1
  • Used by multiple packages
    • jsontokens 3.0.0
      • asn1.js 5.4.1
  • @stacks/cli 2.0.1
    • blockstack 19.3.0
  • Used by multiple packages
    • elliptic 6.4.5
  • bitcoin-lib 5.2.0
    • tiny-secp256k1 1.1.6

The issue can be that some of them seem unmaintained, like indutny/asn1.js#118 where the pr was opened almost 2 years ago.

Copy link
Member

Choose a reason for hiding this comment

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

I'd be more concerned with getting the elliptic package and bitcoinjs-lib packages upgraded to bn.js v5. Is there anything in bn.js v5 that is needed? And would be more feasible to change projects using v5 to use v4 instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like bitcoin-js lib is working on removing the dependency to bn.js as they are dropping tiny-secp256k1 bitcoinjs/bitcoinjs-lib#1734. For elliptic it looks more challenging.
I have no idea if you are using v5 specific features on the other packages.

Copy link

Choose a reason for hiding this comment

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

We are only dropping bn.js from the main package, ecpair and bip32 will still use it until we can upgrade them to use WASM.

@diwakergupta
Copy link
Member

Hi @pradel -- based on the comments, it doesn't look like this PR would actually help reduce the bundle size. I'm going to close it for now, but please reopen if you disagree. Meanwhile, we are looking into all the different pain points with stacks.js, including bundle sizes, and hope to have a plan we can share with the community in the coming weeks. Thanks!

@pradel pradel deleted the feature/upgrade-bn.js-5.2 branch October 26, 2021 16:34
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.

4 participants