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

[consts] Make upper bound numbers hardcoded #247

Merged
merged 3 commits into from
Jan 3, 2024
Merged

Conversation

gregnazario
Copy link
Collaborator

@gregnazario gregnazario commented Jan 3, 2024

Description

Doing powers of bigints doesn't work on older versions of node, and it seems to be hard to reproduce, but still occurs. Hardcoding these should have the same behavior, without these quirks.

Fixes aptos-labs/aptos-wallet-adapter#223

Test Plan

TBD, making a test now with an older version of node to check

Related Links

Related aptos-labs/aptos-core#11540

@gregnazario gregnazario requested review from 0xmaayan, 0xmigo, heliuchuan and a team as code owners January 3, 2024 17:59
@gregnazario gregnazario enabled auto-merge (rebase) January 3, 2024 18:09
@0xmaayan
Copy link
Collaborator

0xmaayan commented Jan 3, 2024

are we sure this is the fix? Looks like adapter v1 works fine, and that version works with the legacy sdk that actually uses the same consts
https://github.com/aptos-labs/aptos-core/blob/main/ecosystem/typescript/sdk/src/bcs/consts.ts

@gregnazario
Copy link
Collaborator Author

are we sure this is the fix? Looks like adapter v1 works fine, and that version works with the legacy sdk that actually uses the same consts https://github.com/aptos-labs/aptos-core/blob/main/ecosystem/typescript/sdk/src/bcs/consts.ts

Ah... it is possible this happens on the old SDK as well. In the case of this particular individual no version of the wallet adapter worked for them. So, this would explain that.

@0xmaayan
Copy link
Collaborator

0xmaayan commented Jan 3, 2024

are we sure this is the fix? Looks like adapter v1 works fine, and that version works with the legacy sdk that actually uses the same consts https://github.com/aptos-labs/aptos-core/blob/main/ecosystem/typescript/sdk/src/bcs/consts.ts

Ah... it is possible this happens on the old SDK as well. In the case of this particular individual no version of the wallet adapter worked for them. So, this would explain that.

that's weird... I mean it works for others. It might be an issue with a specific prod env..?

@gregnazario
Copy link
Collaborator Author

gregnazario commented Jan 3, 2024

are we sure this is the fix? Looks like adapter v1 works fine, and that version works with the legacy sdk that actually uses the same consts https://github.com/aptos-labs/aptos-core/blob/main/ecosystem/typescript/sdk/src/bcs/consts.ts

Ah... it is possible this happens on the old SDK as well. In the case of this particular individual no version of the wallet adapter worked for them. So, this would explain that.

that's weird... I mean it works for others. It might be an issue with a specific prod env..?

That is possible. I'm working with him on it, but this also happened to me once, I don't remember how (then I used create-aptos-dapp and it was all fine).

I'm leaning towards this because it's a simple fix that could prevent some users from even running into this at all, since there are so many different platforms to support.

I think... I was using netlify and moved to vercel, then it just worked.

@0xmaayan
Copy link
Collaborator

0xmaayan commented Jan 3, 2024

are we sure this is the fix? Looks like adapter v1 works fine, and that version works with the legacy sdk that actually uses the same consts https://github.com/aptos-labs/aptos-core/blob/main/ecosystem/typescript/sdk/src/bcs/consts.ts

Ah... it is possible this happens on the old SDK as well. In the case of this particular individual no version of the wallet adapter worked for them. So, this would explain that.

that's weird... I mean it works for others. It might be an issue with a specific prod env..?

That is possible. I'm working with him on it, but this also happened to me once, I don't remember how (then I used create-aptos-dapp and it was all fine).

I'm leaning towards this because it's a simple fix that could prevent some users from even running into this at all, since there are so many different platforms to support.

I think... I was using netlify and moved to vercel, then it just worked.

yes I think your issue was with Netlify (tho you probably could have configured a specific node version to use) - we use BigInt a lot in the sdk, would it make more sense to simply say that in order to use the SDK is required to use Node version X and above? where x is the minimum version that supports BigInt

@gregnazario
Copy link
Collaborator Author

are we sure this is the fix? Looks like adapter v1 works fine, and that version works with the legacy sdk that actually uses the same consts https://github.com/aptos-labs/aptos-core/blob/main/ecosystem/typescript/sdk/src/bcs/consts.ts

Ah... it is possible this happens on the old SDK as well. In the case of this particular individual no version of the wallet adapter worked for them. So, this would explain that.

that's weird... I mean it works for others. It might be an issue with a specific prod env..?

That is possible. I'm working with him on it, but this also happened to me once, I don't remember how (then I used create-aptos-dapp and it was all fine).
I'm leaning towards this because it's a simple fix that could prevent some users from even running into this at all, since there are so many different platforms to support.
I think... I was using netlify and moved to vercel, then it just worked.

yes I think your issue was with Netlify (tho you probably could have configured a specific node version to use) - we use BigInt a lot in the sdk, would it make more sense to simply say that in order to use the SDK is required to use Node version X and above? where x is the minimum version that supports BigInt

Well that's where it's weird...

It supports BigInt, it just doesn't support the power Bigint(5) ** Bigint(2). Node 10+ supports BigInt, and a similar issue was here rollup/rollup#2626

And it looks like it needs to be ES7+ to support native ** exponent over pow https://www.designcise.com/web/tutorial/what-is-the-math-pow-alternative-for-bigint-values-in-javascript

It's one of those things though, Netlify didn't really let you configure some pieces, and that causes a headache depending on your deployment platform, that isn't something you necessarily have control over

@0xmaayan
Copy link
Collaborator

0xmaayan commented Jan 3, 2024

are we sure this is the fix? Looks like adapter v1 works fine, and that version works with the legacy sdk that actually uses the same consts https://github.com/aptos-labs/aptos-core/blob/main/ecosystem/typescript/sdk/src/bcs/consts.ts

Ah... it is possible this happens on the old SDK as well. In the case of this particular individual no version of the wallet adapter worked for them. So, this would explain that.

that's weird... I mean it works for others. It might be an issue with a specific prod env..?

That is possible. I'm working with him on it, but this also happened to me once, I don't remember how (then I used create-aptos-dapp and it was all fine).
I'm leaning towards this because it's a simple fix that could prevent some users from even running into this at all, since there are so many different platforms to support.
I think... I was using netlify and moved to vercel, then it just worked.

yes I think your issue was with Netlify (tho you probably could have configured a specific node version to use) - we use BigInt a lot in the sdk, would it make more sense to simply say that in order to use the SDK is required to use Node version X and above? where x is the minimum version that supports BigInt

Well that's where it's weird...

It supports BigInt, it just doesn't support the power Bigint(5) ** Bigint(2). Node 10+ supports BigInt, and a similar issue was here rollup/rollup#2626

And it looks like it needs to be ES7+ to support native ** exponent over pow https://www.designcise.com/web/tutorial/what-is-the-math-pow-alternative-for-bigint-values-in-javascript

It's one of those things though, Netlify didn't really let you configure some pieces, and that causes a headache depending on your deployment platform, that isn't something you necessarily have control over

yea... looks like you need ES10+ to use pow with BigInt, and ES7+ to use it with number primitives. tho ES10 was out in 2019 so most if not all should be using it.
Anyway, I am fine with this change but could we add some explanation on how we got to these numbers and this pow issue

export const MAX_U8_NUMBER: Uint8 = 255;
export const MAX_U16_NUMBER: Uint16 = 65535;
export const MAX_U32_NUMBER: Uint32 = 4294967295;
export const MAX_U64_BIG_INT: Uint64 = BigInt("18446744073709551615");
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit

Suggested change
export const MAX_U64_BIG_INT: Uint64 = BigInt("18446744073709551615");
export const MAX_U64_BIG_INT: Uint64 = 18446744073709551615n;

Doing powers of bigints doesn't work on older versions of node,
and it seems to be hard to reproduce, but still occurs.  Hardcoding
these should have the same behavior, without these quirks.

Fixes aptos-labs/aptos-wallet-adapter#223
@gregnazario gregnazario merged commit b7b6224 into main Jan 3, 2024
@gregnazario gregnazario deleted the support-older-node branch January 3, 2024 23:29
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.

React.js Deployment Issue: @aptos-labs/wallet-adapter-react Breaks After Deployment, Works Fine on Localhost
2 participants