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

zcash_client_backend: Implement note management via change splitting. #1579

Merged
merged 7 commits into from
Oct 24, 2024

Conversation

nuttycom
Copy link
Contributor

@nuttycom nuttycom commented Oct 17, 2024

Best reviewed commit-by-commit, hiding whitespace changes.

Part of #1355.

Copy link

codecov bot commented Oct 17, 2024

Codecov Report

Attention: Patch coverage is 65.62009% with 219 lines in your changes missing coverage. Please review.

Project coverage is 56.40%. Comparing base (791b371) to head (47b1065).
Report is 40 commits behind head on main.

Files with missing lines Patch % Lines
zcash_client_backend/src/data_api/wallet.rs 54.45% 46 Missing ⚠️
zcash_client_backend/src/fees/common.rs 64.00% 45 Missing ⚠️
zcash_client_backend/src/data_api/testing/pool.rs 75.00% 42 Missing ⚠️
...ent_backend/src/data_api/wallet/input_selection.rs 39.39% 40 Missing ⚠️
...client_backend/src/data_api/testing/transparent.rs 0.00% 12 Missing ⚠️
zcash_client_sqlite/src/lib.rs 36.84% 12 Missing ⚠️
zcash_client_backend/src/data_api/testing.rs 72.22% 5 Missing ⚠️
zcash_client_backend/src/fees.rs 77.27% 5 Missing ⚠️
zcash_client_backend/src/data_api/error.rs 20.00% 4 Missing ⚠️
zcash_client_backend/src/data_api.rs 66.66% 3 Missing ⚠️
... and 3 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1579      +/-   ##
==========================================
+ Coverage   55.93%   56.40%   +0.46%     
==========================================
  Files         149      149              
  Lines       18728    19078     +350     
==========================================
+ Hits        10476    10760     +284     
- Misses       8252     8318      +66     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nuttycom nuttycom force-pushed the wallet/multi_output_change_strategy branch from 6387785 to e426b68 Compare October 17, 2024 02:12
@nuttycom nuttycom force-pushed the wallet/multi_output_change_strategy branch 6 times, most recently from 36a54aa to e6c1fa3 Compare October 17, 2024 20:12
@nuttycom nuttycom force-pushed the wallet/multi_output_change_strategy branch from e6c1fa3 to 6c95fd8 Compare October 17, 2024 22:32
@nuttycom
Copy link
Contributor Author

force-pushed to fix the name of quotient in DivRem.

Copy link
Contributor

@str4d str4d left a comment

Choose a reason for hiding this comment

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

Flushing comments from review up to 5738990 (I'm still reviewing the last commit).

zcash_client_backend/src/data_api.rs Outdated Show resolved Hide resolved
zcash_client_sqlite/src/wallet/common.rs Outdated Show resolved Hide resolved
zcash_client_backend/CHANGELOG.md Outdated Show resolved Hide resolved
zcash_client_backend/CHANGELOG.md Outdated Show resolved Hide resolved
zcash_client_backend/src/data_api/testing.rs Outdated Show resolved Hide resolved
zcash_client_backend/src/data_api/wallet.rs Show resolved Hide resolved
Copy link
Contributor

@str4d str4d left a comment

Choose a reason for hiding this comment

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

Reviewed 6c95fd8.

components/zcash_protocol/src/value.rs Outdated Show resolved Hide resolved
components/zcash_protocol/src/value.rs Outdated Show resolved Hide resolved
zcash_client_backend/src/fees.rs Show resolved Hide resolved
zcash_client_backend/src/fees.rs Outdated Show resolved Hide resolved
zcash_client_backend/src/fees/common.rs Outdated Show resolved Hide resolved
zcash_client_backend/src/fees/zip317.rs Outdated Show resolved Hide resolved
zcash_client_backend/src/fees/zip317.rs Outdated Show resolved Hide resolved
Comment on lines 405 to 447
let mut found_tx_change_memo = false;
let mut found_tx_empty_memo = false;
T::with_decrypted_pool_memos(&d_tx, |memo| {
if Memo::try_from(memo).unwrap() == change_memo {
found_tx_change_memo = true
}
if Memo::try_from(memo).unwrap() == Memo::Empty {
found_tx_empty_memo = true
}
});
assert!(found_tx_change_memo);
assert!(found_tx_empty_memo);

// Verify that the stored sent notes match what we're expecting
let sent_note_ids = st
.wallet()
.get_sent_note_ids(&sent_tx_id, T::SHIELDED_PROTOCOL)
.unwrap();
assert_eq!(sent_note_ids.len(), 3);

// The sent memo should be the empty memo for the sent output, and the
// change output's memo should be as specified.
let mut change_memo_count = 0;
let mut found_sent_empty_memo = false;
for sent_note_id in sent_note_ids {
match st
.wallet()
.get_memo(sent_note_id)
.expect("Note id is valid")
.as_ref()
{
Some(m) if m == &change_memo => {
change_memo_count += 1;
}
Some(m) if m == &Memo::Empty => {
found_sent_empty_memo = true;
}
Some(other) => panic!("Unexpected memo value: {:?}", other),
None => panic!("Memo should not be stored as NULL"),
}
}
assert_eq!(change_memo_count, 2);
assert!(found_sent_empty_memo);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think nothing here checks that it is specifically the sent note (that is, the one with value 100_0000 zatoshis sent to the to address) that has the empty memo.

@nuttycom nuttycom marked this pull request as draft October 20, 2024 16:41
@nuttycom nuttycom force-pushed the wallet/multi_output_change_strategy branch 5 times, most recently from eb28bfd to 5afea2e Compare October 20, 2024 19:56
@nuttycom
Copy link
Contributor Author

force-pushed to address comments from code review.

Then,

force-pushed to rebase on main.

@nuttycom nuttycom force-pushed the wallet/multi_output_change_strategy branch from 5afea2e to 4059a29 Compare October 21, 2024 20:56
@nuttycom
Copy link
Contributor Author

force-pushed to address additional comments from my pairing with @daira.

Copy link
Contributor

@pacu pacu left a comment

Choose a reason for hiding this comment

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

LGTM!

left some non-blocking suggestions

);

// If we don't have as many change outputs as we expected, recompute the fee.
let (fee_with_change, excess_fee) =
Copy link
Contributor

Choose a reason for hiding this comment

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

[non-blocking] This section of the code from L. 450 to L. 526 is pretty hard to read and follow (even with the generous comments). I wonder if there's a way to reduce its complexity in terms of lamdas and if-else statements so not only is more friendly to follow and maintain, but also to test.

nuttycom and others added 7 commits October 23, 2024 11:22
…allet metadata.

In the process this modifies input selection to take the change strategy
as an explicit argument, rather than being wrapped as part of the input
selector.
Co-authored-by: Jack Grigg <thestr4d@gmail.com>
Co-authored-by: Daira-Emma Hopwood <daira@jacaranda.org>
@nuttycom nuttycom force-pushed the wallet/multi_output_change_strategy branch from 4059a29 to 47b1065 Compare October 23, 2024 17:24
@nuttycom
Copy link
Contributor Author

force-pushed to rebase on main to fix changelog conflicts.

Copy link
Contributor

@str4d str4d left a comment

Choose a reason for hiding this comment

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

utACK 47b1065

@str4d str4d merged commit 01552bd into zcash:main Oct 24, 2024
27 checks passed
@nuttycom nuttycom deleted the wallet/multi_output_change_strategy branch October 24, 2024 14:54
} else {
Ok(0)
}
};

// Once we calculate the balance with and without change, there are five cases:
//
Copy link
Contributor

@daira daira Oct 25, 2024

Choose a reason for hiding this comment

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

"change output is added" -> "change output(s) are added" on line 337.

Also on line 345, it's unclear how many change outputs will be added in that case, so the comment should be clarified (there only needs to be one for the purpose of including a change memo, but that doesn't necessarily preserve indistinguishability).

Copy link
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

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

Post-hoc ACK with comments (please address them in #1590).

nuttycom added a commit to nuttycom/librustzcash that referenced this pull request Oct 25, 2024
Co-authored-by: Daira-Emma Hopwood <daira@jacaranda.org>
nuttycom added a commit to nuttycom/librustzcash that referenced this pull request Oct 25, 2024
Co-authored-by: Daira-Emma Hopwood <daira@jacaranda.org>
@str4d str4d added the C-tracked-feature Category: This is a feature for which we are tracking deployment to apps. label Oct 31, 2024
@str4d str4d removed the C-tracked-feature Category: This is a feature for which we are tracking deployment to apps. label Nov 11, 2024
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