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

Add queues to track the need for transaction enhancement and/or verification of mined status. #1473

Merged
merged 19 commits into from
Aug 9, 2024

Conversation

nuttycom
Copy link
Contributor

No description provided.

@nuttycom nuttycom marked this pull request as draft July 30, 2024 18:35
@nuttycom nuttycom force-pushed the wallet/enrichment_queue branch 3 times, most recently from ecee800 to 8749d37 Compare August 1, 2024 22:51
Copy link

codecov bot commented Aug 1, 2024

Codecov Report

Attention: Patch coverage is 79.27461% with 40 lines in your changes missing coverage. Please review.

Project coverage is 61.16%. Comparing base (7f7b685) to head (5a1645a).
Report is 8 commits behind head on main.

Files Patch % Lines
zcash_client_sqlite/src/wallet.rs 83.07% 11 Missing ⚠️
zcash_client_sqlite/src/wallet/transparent.rs 73.80% 11 Missing ⚠️
zcash_client_sqlite/src/lib.rs 86.00% 7 Missing ⚠️
zcash_client_backend/src/data_api.rs 28.57% 5 Missing ⚠️
...e/src/wallet/init/migrations/tx_retrieval_queue.rs 66.66% 4 Missing ⚠️
zcash_client_sqlite/src/wallet/orchard.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1473      +/-   ##
==========================================
+ Coverage   60.82%   61.16%   +0.34%     
==========================================
  Files         140      141       +1     
  Lines       16472    16650     +178     
==========================================
+ Hits        10019    10184     +165     
- Misses       6453     6466      +13     

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

@nuttycom nuttycom force-pushed the wallet/enrichment_queue branch 2 times, most recently from d3837d4 to 9ffcb8e Compare August 2, 2024 00:47
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 up to 40d94d0 (just before looking at db.rs).

zcash_client_sqlite/src/wallet/db.rs Show resolved Hide resolved
zcash_client_backend/src/data_api/wallet.rs Show resolved Hide resolved
zcash_client_backend/proto/service.proto Outdated Show resolved Hide resolved
zcash_client_backend/src/data_api.rs Outdated Show resolved Hide resolved
zcash_client_backend/src/data_api.rs Outdated Show resolved Hide resolved
zcash_client_backend/src/data_api.rs Outdated Show resolved Hide resolved
zcash_client_sqlite/src/wallet.rs Outdated Show resolved Hide resolved
@nuttycom nuttycom force-pushed the wallet/enrichment_queue branch 5 times, most recently from 7994e82 to cc3c34f Compare August 5, 2024 17:06
@nuttycom nuttycom force-pushed the wallet/enrichment_queue branch 3 times, most recently from 93d75b0 to 1cbced3 Compare August 5, 2024 17:57
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 1cbced3.

zcash_client_sqlite/src/wallet/db.rs Outdated Show resolved Hide resolved
zcash_client_sqlite/src/wallet/transparent.rs Outdated Show resolved Hide resolved
zcash_client_sqlite/src/wallet.rs Outdated Show resolved Hide resolved
zcash_client_backend/src/data_api.rs Show resolved Hide resolved
zcash_client_backend/src/data_api.rs Outdated Show resolved Hide resolved
zcash_client_sqlite/src/wallet/db.rs Show resolved Hide resolved
zcash_client_sqlite/src/wallet/transparent.rs Outdated Show resolved Hide resolved
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.

NACK, there seem to be some bugs.

Co-authored-by: Daira-Emma Hopwood <[email protected]>
@nuttycom nuttycom requested review from daira and str4d and removed request for str4d August 9, 2024 18:34
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 171cc3d once my concern about Enhancement results has been addressed (either by explaining why it's fine, or making a fix).

zcash_client_backend/src/data_api.rs Show resolved Hide resolved
zcash_client_backend/src/data_api.rs Show resolved Hide resolved
Comment on lines 1997 to 2002
// In order to have made a Status request, we must already have had the
// raw transaction (the only callers of `queue_tx_retrieval` are in contexts
// where we must have already called `put_tx_data`). Therefore, it is safe
// to unconditionally delete the request from `tx_retrieval_queue` below
// (both in the expired case and the case where it has been mined), because
// we already have all the data we need about this transaction.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is true for Status requests, but not true for Enhancement requests which subsume Status.

Copy link
Contributor

@daira daira Aug 9, 2024

Choose a reason for hiding this comment

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

Yes. I noticed that and the first commit of nuttycom#39 (nuttycom@239f7ff) fixes it. The implementation is fine, it's just the comment that is incorrect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It occurs to me that https://github.com/zcash/librustzcash/pull/1473/files#diff-a1724f7547ecabc613a07520eaf7917d9084d4277219d186698b0c8e352495a4R2425-R2427 is superfluous; we should never have a Status request for a transaction unless we have the raw data. So one way to fix this would be to remove the query type argument from the queue_tx_retrieval function, and to set it based upon the presence or absence of raw transaction data.

Copy link
Contributor

Choose a reason for hiding this comment

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

The comment change doesn't resolve my concern. GetStatus is indeed only generated when we have the raw transaction (as I noted), but Enhancement is generated by definition when we don't have the raw transaction, and its documentation states that when the caller is unable to look up the transaction, it must call this method.

The reason it is okay to delete for Enhancement requests is that:

  • If a transaction can't be enhanced, we assume that the caller calls this method with TransactionStatus::TxidNotRecognized (as the other two statuses mean that the chain data source knew about the transaction, and therefore must have observed it and could return its raw data), so we don't need to consider what happens in the other statuses.
  • We only delete for TransactionStatus::TxidNotRecognized if the transaction is expired, at which point we don't necessarily care about enhancement (though the user might still care about the memo), and it is very likely that we will be unable to ever enhance (as the tx will have been dropped from all mempools).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simplified in 5a1645a

Copy link
Contributor Author

@nuttycom nuttycom Aug 9, 2024

Choose a reason for hiding this comment

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

The fact is that an Enhancement request is a Status request. That's what it means for an Enhancement request to subsume a Status request. It's either "get me the status" or "get me the status and the data if it's available".

Copy link
Contributor

Choose a reason for hiding this comment

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

@daira Enhancement is getting the status; it subsumes / is a superset of GetStatus. That's why I raised my initial concern that this method was being written ostensibly assuming it would only be called via GetStatus, which was false.

As @nuttycom says, the actual implementation does correctly work with both GetStatus and Enhancement; the comment was just misleading.

Copy link
Contributor Author

@nuttycom nuttycom Aug 9, 2024

Choose a reason for hiding this comment

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

I have now updated this comment again. (b47c7bf)

Copy link
Contributor

Choose a reason for hiding this comment

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

The fact is that an Enhancement request is a Status request.

Not so. Otherwise it wouldn't have to requeue a Status request when queue_status_retrieval is true. It doesn't directly update the mined height in the case where d_tx.mined_height().is_none().

Copy link
Contributor Author

@nuttycom nuttycom Aug 9, 2024

Choose a reason for hiding this comment

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

Otherwise it wouldn't have to requeue a Status request when queue_status_retrieval is true.

The re-queueing is so that the wallet continues to monitor for when the transaction is eventually mined. A relevant case here is that store_decrypted_tx was called with a transaction that was read from the mempool; we have complete transaction data, but we don't know yet whether the transaction will be mined, so we stick the status request back on the queue. For a fully transparent transaction that we get from the mempool we have no other way of detecting that it becomes mined.

daira
daira previously approved these changes Aug 9, 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 modulo suggested changes in nuttycom#39 . We can either merge that PR into this one, or merge a copy of it separately. (I have checked that it passes tests locally.)

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 b47c7bf

@str4d str4d merged commit 52abb1f into zcash:main Aug 9, 2024
25 checks passed
@nuttycom nuttycom deleted the wallet/enrichment_queue branch August 9, 2024 23:41
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

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