-
Notifications
You must be signed in to change notification settings - Fork 15
Addenda to preimage tests #482
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found 3 issues in packages/shared/src/preimage.ts: one critical logic error regarding nonce usage, one performance/best-practice issue with array creation, and one documentation inconsistency.
| const oversizedBytesArray = Array(maxPreimageSize + 1).fill(1) | ||
| const oversizedBytes = client.api.createType('Bytes', oversizedBytesArray) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using Array(maxPreimageSize + 1) creates a sparse/dense array of numbers which is memory inefficient for binary data. Use new Uint8Array(maxPreimageSize + 1).fill(1) instead, which createType supports directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unit8Array was used before, and due to a SCALE + PJS interaction that I didn't delve too deeply into, the maximum allowed size of the preimage ended up being 64 bytes.
@andreitrand not a cabal answer, but here's the fix!
Follow-up to #471 . Closes #481 .