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

Build: Tweak Vite #150

Open
gbarkhatov opened this issue Dec 20, 2024 · 1 comment
Open

Build: Tweak Vite #150

gbarkhatov opened this issue Dec 20, 2024 · 1 comment

Comments

@gbarkhatov
Copy link
Contributor

gbarkhatov commented Dec 20, 2024

One of the issues we currently have is if we do

    rollupOptions: {
      external: [
        "@keystonehq/keystone-sdk"
      ],
      output: {
        sourcemapExcludeSources: true,
      },
    },

Then Keystone will generate not proper QR code. Even though both simple-staking and bbn-wallet-connect will have the same dependency version. If this is called: const ur = this.dataSdk.btc.generatePSBT(Buffer.from(psbtHex, "hex")); given the same input and same resulting buffer, the length of this.dataSdk.btc.generatePSBT will be different on bbn-wallet-connect storybook story and simple-staking (same psbt hex)

If we don't include it there, then @keystonehq/keystone-sdk becomes a part of a bundle and increases bbn-wallet-connect size from 800 Kb to 3.5+ MB

WIP PR that included this SDK in the bundle #151

@gbarkhatov
Copy link
Contributor Author

So we have bbn-wallet-connect that uses @keystonehq/keystone-sdk as a dependency

  • inside vite.config.ts @keystonehq/keystone-sdk marked as an external dependency. If it's inside this array, then npm run build will produce 800 kb files.
  • simple-staking installs bbn-wallet-connect and also installs @keystonehq/keystone-sdk as a dependency of bbn-wallet-connect

Inside src/core/wallets/btc/keystone/provider.ts we have this function

private sign = async (psbtHex: string): Promise<Psbt> => {
  if (!psbtHex) throw new Error("psbt hex is required");
  const ur = this.dataSdk.btc.generatePSBT(Buffer.from(psbtHex, "hex"));
  ...
}

If I open up 2 versions of Keystone playground - one Storybook story on bbn-wallet-connect and another one is the actual simple-staking trying to sign PSBTs, then I will see some problems.

For some reason:

  1. psbtHex: string is the same. So I pass X in both apps and it is indeed X
  2. Buffer.from(psbtHex, "hex") is the same. Buffer from this X is Y for both apps
  3. But this.dataSdk.btc.generatePSBT produces different results.
  • in case of bbn-wallet-connect ur will have 551 length, which is correct
  • in case of simple-staking ur will have 1014 length, which is incorrect

It will result in simple-staking inability to sign the PSBT.

Even though both bbn-wallet-connect and simple-staking use the same 0.9.0 version of that particular keystone library, the result is different.

Current solution - we exclude this keystone library from external, i.e. we include it into the build of bbn-wallet-connect, which applies vite build logic. The bundle size is increased from 800 kb to ~ 3.5 mb or so.

simple-staking bundle size is increased:

Route (app)                              Size     First Load JS
┌ ○ /                                    62.9 kB        2.51 MB
└ ○ /_not-found                          307 B           185 kB
+ First Load JS shared by all            185 kB
  ├ chunks/326-13edb57607594f74.js       91.8 kB
  ├ chunks/52774a7f-c102885068da3e4a.js  36.9 kB
  ├ chunks/fd9d1056-3d5cd1a99b2212d8.js  53.8 kB
  └ other shared chunks (total)          2.69 kB

Whereas if @keystonehq/keystone-sdk is not a part of vite build of the bbn-wallet-connect the size of simple-staking is:

Route (app)                              Size     First Load JS
┌ ○ /                                    62.9 kB        2.21 MB
└ ○ /_not-found                          307 B           185 kB
+ First Load JS shared by all            185 kB
  ├ chunks/326-13edb57607594f74.js       91.8 kB
  ├ chunks/52774a7f-c102885068da3e4a.js  36.9 kB
  ├ chunks/fd9d1056-3d5cd1a99b2212d8.js  53.8 kB
  └ other shared chunks (total)          2.69 kB

This is most likely to internal keystone dependencies inside simple-staking, like node_modules/@keystonehq/bc-ur-registry-btc/ etc and the linking between vite build and nextjs build

Here is the bump PR that solves the Keystone problem, after it is been built by vite (removed from external): babylonlabs-io/simple-staking#538

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

No branches or pull requests

1 participant