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_sqlite: Track all transparent spends. #1496

Merged
merged 8 commits into from
Aug 19, 2024

Conversation

nuttycom
Copy link
Contributor

Prior to this change, the mark_transparent_utxo_spent method assumed that the UTXO information for outputs belonging to the wallet would be known to exist before their spends could be detected. However, this is not true in transparent history recovery: the spends are detected first. We now cache the information about those spends so that we can then correctly record the spend when the output being spent is eventually detected.

At present, data from this spend cache is never deleted. This is because such deletions could undermine history recovery in some narrow cases related to chain reorgs.

Prior to this change, the `mark_transparent_utxo_spent` method assumed
that the UTXO information for outputs belonging to the wallet would be
known to exist before their spends could be detected. However, this is
not true in transparent history recovery: the spends are detected first.
We now cache the information about those spends so that we can then
correctly record the spend when the output being spent is eventually
detected.

At present, data from this spend cache is never deleted. This is because
such deletions could undermine history recovery in some narrow cases
related to chain reorgs.
Copy link

codecov bot commented Aug 15, 2024

Codecov Report

Attention: Patch coverage is 59.84556% with 104 lines in your changes missing coverage. Please review.

Project coverage is 61.14%. Comparing base (3b74284) to head (5a32d3b).
Report is 11 commits behind head on main.

Files Patch % Lines
zcash_client_sqlite/src/wallet.rs 55.24% 81 Missing ⚠️
zcash_client_sqlite/src/wallet/init.rs 0.00% 14 Missing ⚠️
zcash_client_sqlite/src/wallet/transparent.rs 66.66% 7 Missing ⚠️
...e/src/wallet/init/migrations/tx_retrieval_queue.rs 90.47% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1496      +/-   ##
==========================================
+ Coverage   61.12%   61.14%   +0.01%     
==========================================
  Files         141      141              
  Lines       16650    16658       +8     
==========================================
+ Hits        10178    10185       +7     
- Misses       6472     6473       +1     

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

@nuttycom nuttycom requested a review from daira August 15, 2024 23:17
daira
daira previously approved these changes Aug 16, 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

daira
daira previously approved these changes Aug 16, 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

Comment on lines 105 to 115
wallet::store_decrypted_tx(
transaction,
&self.params,
DecryptedTransaction::new(mined_height, &tx, vec![], vec![]),
)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. This is a very complicated function to be calling in a migration. If we need to change it, will we duplicate it like we do for code called in other migrations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What I would like to do with store_decrypted_tx in general is to refactor it to abstract over the database operations (i.e. factor out the business logic) and perhaps even move the main logic to zcash_client_backend (relying upon some lower-level data access API trait.) That will make it easier to modularize it in a way that makes the migration maintenance less annoying.

daira
daira previously approved these changes Aug 16, 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

This permits this method to be used in a migration.
daira
daira previously approved these changes Aug 16, 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

…quests do not exceed the chain tip.

`lightwalletd` will return an error in the case that the requested end
height exceeds the chain tip. This should be considered a bug in
lightwalletd, but for now we will work around it in the wallet.
// `lightwalletd` will return an error for `GetTaddressTxids` requests having an end height
// greater than the current chain tip height, so we take the chain tip height into account
// here in order to make this pothole easier for clients of the API to avoid.
let chain_tip_height = super::chain_tip_height(conn)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Incidentally, why does the doc for wallet::chain_tip_height say

/// Returns the minimum and maximum heights of blocks in the chain which may be scanned.

when it actually only returns (optionally) a single height?

Copy link
Contributor

Choose a reason for hiding this comment

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

Filed #1498.

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

@nuttycom nuttycom merged commit b59d027 into zcash:main Aug 19, 2024
26 of 27 checks passed
@nuttycom nuttycom deleted the fix/transparent_spend_recording branch August 19, 2024 20: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