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

[#1411] Refactor AccountBalance to use Balance for transparent funds #1570

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

pacu
Copy link
Contributor

@pacu pacu commented Oct 13, 2024

fixes #1411

Copy link

codecov bot commented Oct 17, 2024

Codecov Report

Attention: Patch coverage is 88.28829% with 13 lines in your changes missing coverage. Please review.

Project coverage is 56.67%. Comparing base (8b49ca8) to head (bb12eb6).

Files with missing lines Patch % Lines
...client_backend/src/data_api/testing/transparent.rs 92.22% 7 Missing ⚠️
zcash_client_sqlite/src/wallet.rs 0.00% 4 Missing ⚠️
zcash_client_sqlite/src/wallet/transparent.rs 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1570      +/-   ##
==========================================
+ Coverage   56.30%   56.67%   +0.36%     
==========================================
  Files         148      148              
  Lines       19062    19137      +75     
==========================================
+ Hits        10733    10845     +112     
+ Misses       8329     8292      -37     

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

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.

Changes required.

Note that tests passed despite the bug of not checking the overflow invariant in AccountBalance::add_unshielded_value. The suggested replacement code obviously does maintain the invariant because it only uses other public methods, but still we might want more test coverage here.

@pacu
Copy link
Contributor Author

pacu commented Oct 18, 2024

Thank you for the thorough review! I'll be addressing these comments shortly.

@pacu pacu force-pushed the feature/transparent-balance branch from 3734cda to 68b9725 Compare October 22, 2024 22:25
@pacu pacu force-pushed the feature/transparent-balance branch from d49ebd3 to f706b33 Compare October 24, 2024 22:30
@pacu pacu marked this pull request as ready for review October 24, 2024 22:30
@pacu pacu requested a review from daira October 24, 2024 22:30
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.

Changes needed.

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.

The changes to AccountBalance should be documented in the CHANGELOG for zcash_client_backend, not zcash_primitives. (This was fixed.)

Also, the fix to zcash_client_sqlite's implementation of get_wallet_summary, along with its remaining limitations, should be documented in the CHANGELOG for zcash_client_sqlite: (This was also fixed.)

### Fixed
- `zcash_client_sqlite::WalletDb`'s implementation of
  `zcash_client_backend::data_api::WalletRead::get_wallet_summary` has been
  fixed to take account of `min_confirmations` for transparent balances.
  Note that this implementation treats `min_confirmations == 0` the same
  as `min_confirmations == 1` for both shielded and transparent TXOs.
  It also does not currently distinguish between pending change and
  non-change; the pending value is all counted as non-change (issue
  [#1592](https://github.com/zcash/librustzcash/issues/1592)).

daira
daira previously approved these changes Oct 27, 2024
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.

utACK with minor comments on the changelogs.

WHERE (
t.mined_height < :mempool_height -- tx is mined
AND :mempool_height - t.mined_height >= :min_confirmations -- has at least min_confirmations
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks wrong to me. mempool_height is typically chain_tip_height + 1. mined_height is at most the chain tip height, or null, so changing the query in this fashion is introducing a footgun for zero-conf shielding.

Also, :mempool_height - t.mined_height will be NULL when mined_height IS NULL, which then will always cause this condition to fail.

Instead of using :mempool_height directly, compute a balance_height outside of the query from the mempool height and min_confirmations, and then query against that height here, accounting for mined_height being allowed to be null in the case that min_confirmations == 0.

Copy link
Contributor Author

@pacu pacu Oct 30, 2024

Choose a reason for hiding this comment

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

This looks wrong to me. mempool_height is typically chain_tip_height + 1. mined_height is at most the chain tip height, or null, so changing the query in this fashion is introducing a footgun for zero-conf shielding.

Is Zero-conf shielding something that should be address here? I understood it was not.

Also, :mempool_height - t.mined_height will be NULL when mined_height IS NULL, which then will always cause this condition to fail.

In this particular query a pre-condition is that the TX is mined so I guess desirable that the condition is evaluated to FALSE.

Instead of using :mempool_height directly, compute a balance_height outside of the query from the mempool height and min_confirmations, and then query against that height here, accounting for mined_height being allowed to be null in the case that min_confirmations == 0.

This sounds like a good idea.

Copy link
Contributor

@daira daira Oct 30, 2024

Choose a reason for hiding this comment

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

Is Zero-conf shielding something that should be address here? I understood it was not.

No, we'll need another PR for that. The current code appears to work as documented: min_confirmations == 0 behaves the same as min_confirmations == 1. I don't think we should complicate this PR to make zero-conf shielding work; it's obvious that this code will need to change to support that, and there's no regression for any case as of this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Btw @nuttycom did you see this? #1413 (comment)

daira
daira previously approved these changes Oct 30, 2024
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.

re-utACK (last commit was doc-only)

…unds

closes zcash#1411

- Adds min_confirmations to transparent account balances
- Adds a new `transparent_balance_spendability` test to verify
transparent funds spendability.
- cargo clippy + cargo fmt

Refactor: Extract Method on lambda `check_balance`
properly verify `min_confirmations` assumptions
@pacu pacu force-pushed the feature/transparent-balance branch from 78a5927 to f96f045 Compare November 4, 2024 18:18
@pacu
Copy link
Contributor Author

pacu commented Nov 4, 2024

I think I chewed a doc commit with this rebase from main and fix. I'll review all the changes and then ask for review

daira
daira previously approved these changes Nov 5, 2024
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.

utACK. (The complaint about redundancy in the test code is non-blocking.)

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.

Refactor AccountBalance to use Balance for transparent funds
3 participants