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

wasm: handle spend transaction planner requests in planner #1801

Merged
merged 16 commits into from
Oct 2, 2024

Conversation

TalDerei
Copy link
Contributor

@TalDerei TalDerei commented Sep 21, 2024

references #1660, and partially references #692.

Implements wasm bindgen unit tests for sanity-checking the critical logic paths and safety checks for the send max feature.

#1698 to follow.

@TalDerei TalDerei self-assigned this Sep 21, 2024
Copy link

changeset-bot bot commented Sep 21, 2024

🦋 Changeset detected

Latest commit: b1e87c4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@penumbra-zone/wasm Minor
@penumbra-zone/perspective Major
@penumbra-zone/query Major
@penumbra-zone/services Major
@penumbra-zone/storage Major
minifront Patch
@penumbra-zone/ui Patch
node-status Patch
@repo/tailwind-config Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@TalDerei TalDerei marked this pull request as draft September 21, 2024 13:43
@TalDerei TalDerei marked this pull request as ready for review September 30, 2024 02:38
@TalDerei TalDerei changed the base branch from main to reenable-spend-max September 30, 2024 03:01
@TalDerei TalDerei changed the base branch from reenable-spend-max to main September 30, 2024 03:03
@TalDerei TalDerei requested a review from a team September 30, 2024 04:47
@TalDerei TalDerei added wasm Rust crate updates security and removed security wasm Rust crate updates labels Sep 30, 2024
// Constraint: validate the transaction planner request is constructed with a single spend request.
if request.spends.len() > 1 {
let error_message =
"Invalid transaction: The transaction was constructed improperly.".to_string();
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: think we can be more descriptive of the error, like:

"Invalid transaction: only one Spend action allowed in planner request."

Copy link
Contributor Author

@TalDerei TalDerei Oct 1, 2024

Choose a reason for hiding this comment

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

this constraint is triggered when the consumer attempts to construct a TPR with multiple spend requests. The original intention was to use a single, unified error message for the entire feature, but I'll implement more specific and descriptive error messages.

I modified the error message per your suggestion.

packages/wasm/crate/src/planner.rs Outdated Show resolved Hide resolved
Comment on lines 562 to 563
let error_message =
"Invalid transaction: The transaction was constructed improperly.".to_string();
Copy link
Collaborator

Choose a reason for hiding this comment

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

issue: let's reflect the error more specifically here in the error message

Copy link
Contributor Author

@TalDerei TalDerei Oct 1, 2024

Choose a reason for hiding this comment

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

suggesting "Invalid transaction: The requested spend amount does not match the available balance."?

packages/wasm/crate/src/planner.rs Outdated Show resolved Hide resolved
packages/wasm/crate/src/planner.rs Outdated Show resolved Hide resolved
// }
// }
// }
for tpr::Spend { value, address } in request.spends.clone() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

question: Why is it necessary to clone()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

borrow of moved value; we check if request.spends.len() > 1

packages/wasm/crate/src/storage.rs Show resolved Hide resolved
packages/wasm/crate/tests/test_planner_send_max.rs Outdated Show resolved Hide resolved
packages/wasm/crate/tests/test_planner_send_max.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

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

question: do you check this case?

- // Constraint: check if the requested spend amount is equal to the accumulated note balance.

Copy link
Collaborator

Choose a reason for hiding this comment

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

question: are you asserting the change address in a successful result?

Copy link
Collaborator

Choose a reason for hiding this comment

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

question: do you have any success cases?

Copy link
Contributor Author

@TalDerei TalDerei Oct 1, 2024

Choose a reason for hiding this comment

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

question: do you check this case?

we already check this constraint (see constraint 3 in the test code). To improve test clarity and reduce potential confusion, I reordered the unit tests to match the sequence of constraints as they appear in the planner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

question: are you asserting the change address in a successful result?

thanks for the suggestion; I'll add assertions around sanity checking the change address.

@grod220
Copy link
Collaborator

grod220 commented Oct 1, 2024

Amazing testing btw!

@TalDerei TalDerei requested a review from grod220 October 2, 2024 03:08
Copy link
Collaborator

@grod220 grod220 left a comment

Choose a reason for hiding this comment

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

Nice job! As we want to get this into the next release, going to take this over and merge. Well done with those tests 🎊

@grod220 grod220 merged commit 735e22b into main Oct 2, 2024
1 check passed
@grod220 grod220 deleted the spend-tpr-wasm branch October 2, 2024 09:26
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.

2 participants