Skip to content

Add ZIP 317 fee calculation strategy.#694

Merged
nuttycom merged 4 commits into
zcash:mainfrom
nuttycom:wallet/zip_317
Nov 11, 2022
Merged

Add ZIP 317 fee calculation strategy.#694
nuttycom merged 4 commits into
zcash:mainfrom
nuttycom:wallet/zip_317

Conversation

@nuttycom
Copy link
Copy Markdown
Collaborator

@nuttycom nuttycom commented Nov 4, 2022

This builds atop #689

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 4, 2022

Codecov Report

Base: 72.58% // Head: 71.38% // Decreases project coverage by -1.20% ⚠️

Coverage data is based on head (796b5a4) compared to base (6f4a6aa).
Patch coverage: 57.48% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #694      +/-   ##
==========================================
- Coverage   72.58%   71.38%   -1.21%     
==========================================
  Files         107      115       +8     
  Lines       10932    11531     +599     
==========================================
+ Hits         7935     8231     +296     
- Misses       2997     3300     +303     
Impacted Files Coverage Δ
zcash_client_backend/src/address.rs 86.40% <ø> (ø)
zcash_client_backend/src/data_api.rs 25.00% <0.00%> (+0.64%) ⬆️
zcash_client_backend/src/zip321.rs 96.20% <0.00%> (-0.82%) ⬇️
zcash_client_sqlite/src/error.rs 4.76% <0.00%> (-3.94%) ⬇️
zcash_extensions/src/transparent/demo.rs 76.62% <ø> (ø)
zcash_primitives/src/sapling.rs 86.93% <ø> (ø)
...imitives/src/transaction/components/transparent.rs 90.24% <ø> (ø)
zcash_client_backend/src/data_api/error.rs 7.84% <12.12%> (-8.16%) ⬇️
...ives/src/transaction/components/sapling/builder.rs 74.54% <20.00%> (-2.75%) ⬇️
zcash_client_backend/src/data_api/chain/error.rs 21.42% <21.42%> (ø)
... and 32 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@nuttycom nuttycom force-pushed the wallet/zip_317 branch 7 times, most recently from 0bffbc1 to 041e457 Compare November 9, 2022 01:34
@nuttycom nuttycom marked this pull request as ready for review November 9, 2022 01:43
@nuttycom nuttycom force-pushed the wallet/zip_317 branch 5 times, most recently from b6a5039 to bac6024 Compare November 10, 2022 01:33
Copy link
Copy Markdown
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.

Partial review of bac6024f9e8b7fc93e2edd42a0b593829e53a299 (finished everything except zcash_client_backend::fees::zip317).

Comment thread zcash_client_backend/CHANGELOG.md Outdated
Comment thread zcash_primitives/CHANGELOG.md Outdated
Comment thread zcash_primitives/src/transaction/fees/zip317.rs Outdated
Comment on lines 89 to 127
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: this assumes the kind of each transparent input and output, such that p2pkh_standard_input_size and p2pkh_standard_output_size cancel out and cause the transparent contribution to only use the number of inputs and outputs. Instead it needs to use the as-serialized-in-transaction size of transparent_inputs and transparent_outputs (which can be calculated from the data accessible via transparent::{inputView, OutputView}).

Copy link
Copy Markdown
Collaborator Author

@nuttycom nuttycom Nov 10, 2022

Choose a reason for hiding this comment

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

I mean, this isn't a bug, this is a known not-fully-implemented. What I didn't implement was the DER encoding, because won't that vary based upon the value of the signature, which we can't get here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Resolved by making passing anything but a p2pkh input an error.

Comment thread zcash_primitives/src/transaction/fees/zip317.rs Outdated
Comment thread zcash_primitives/src/transaction/fees/zip317.rs Outdated
Comment thread zcash_client_backend/src/fees/zip317.rs Outdated
This adds a set of abstractions that allow wallets to provide
independent strategies for fee estimation and note selection, and
implementations of these strategies that perform these operations in the
same fashion as the existing `spend` and `shield_transparent_funds`
functions.

This required a somewhat hefty rework of the error handling in
zcash_client_backend. It fixes an issue with the error types whereby
callees needed to have a bit too much information about the error
types produced by their callers.

Reflect the updated note selection and error handling in zcash_client_sqlite.
The change selection algorithm has the most useful information for
determining whether or not a note is dust, so this adds a new error case
to `ChangeError` that allows the change selection to report the presence
of input notes without economic value back to its caller.
),
Err(Error::InsufficientFunds { available, required })
if available == Amount::from_u64(51000).unwrap()
&& required == Amount::from_u64(60000).unwrap()
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

A note here: we do not yet do anything to indicate that notes have been rejected as dust when performing wallet balance calculation. We might want to do that.

Copy link
Copy Markdown
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 73ab884

Comment thread zcash_client_backend/src/fees/zip317.rs Outdated
Comment on lines +106 to +107
// if we have available grace inputs, allocate them first to transparent dust
// and then to sapling dust
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

To clarify, the assumption here is that if any transparent inputs have been provided to this ChangeStrategy, the caller is okay with any of those inputs being spent, so we don't need to consider the privacy implications here. It might be useful to call these out in a comment.

Comment thread zcash_client_backend/src/fees/zip317.rs Outdated
Comment thread zcash_client_backend/src/fees/zip317.rs Outdated
@nuttycom nuttycom merged commit d8cedd2 into zcash:main Nov 11, 2022
@nuttycom nuttycom deleted the wallet/zip_317 branch November 11, 2022 01:55
Copy link
Copy Markdown
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

@str4d str4d mentioned this pull request Feb 6, 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.

3 participants