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: Add account birthday management to the Data Access API #907

Merged
merged 5 commits into from
Sep 1, 2023

Conversation

nuttycom
Copy link
Contributor

@nuttycom nuttycom commented Aug 22, 2023

Closes #897.

@codecov
Copy link

codecov bot commented Aug 22, 2023

Codecov Report

Patch coverage is 66.97% of modified lines.

❗ Current head b845947 differs from pull request most recent head 5b3f544. Consider uploading reports for the commit 5b3f544 to get more accurate results

Files Changed Coverage
zcash_client_backend/src/proto.rs 0.00%
zcash_client_sqlite/src/chain.rs ø
zcash_client_sqlite/src/error.rs 0.00%
zcash_client_sqlite/src/wallet/init.rs ø
zcash_client_sqlite/src/lib.rs 20.00%
zcash_client_backend/src/data_api.rs 31.57%
zcash_client_sqlite/src/wallet/sapling.rs 36.36%
zcash_client_sqlite/src/wallet/scanning.rs 70.42%
zcash_client_sqlite/src/wallet.rs 75.00%
...rc/wallet/init/migrations/add_account_birthdays.rs 85.29%
... and 3 more

📢 Thoughts on this report? Let us know!.

@nuttycom nuttycom force-pushed the sbs/wallet_birthday branch 4 times, most recently from e04f345 to c2b1e41 Compare August 23, 2023 18:41
@nuttycom nuttycom force-pushed the sbs/wallet_birthday branch 4 times, most recently from 5811b8c to 578dc57 Compare August 24, 2023 17:55
@nuttycom nuttycom changed the title WIP: Add account birthdays. zcash_client_backend: Add account birthday management to the Data Access API Aug 24, 2023
@nuttycom nuttycom marked this pull request as ready for review August 24, 2023 17:57
@nuttycom nuttycom requested a review from str4d August 24, 2023 19:21
Copy link

@HonzaR HonzaR left a comment

Choose a reason for hiding this comment

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

From the Android SDK consumer view, it looks good. Thank you! The only question I have is that I see both init_blocks_table and init_accounts_table are replaced by create_account, which expects AccountBirthday, which is optional. Can you please describe what we should use in case of new or restored wallets for this parameter? Or should we leave it empty?

@nuttycom
Copy link
Contributor Author

nuttycom commented Aug 28, 2023

From the Android SDK consumer view, it looks good. Thank you! The only question I have is that I see both init_blocks_table and init_accounts_table are replaced by create_account, which expects AccountBirthday, which is optional. Can you please describe what we should use in case of new or restored wallets for this parameter? Or should we leave it empty?

There are two options:
(1) is to first call updateChainTip and then call this without specifying an AccountBirthday.
(2) call this with the arguments that you would have previously provided to init_blocks_table (block height and note commitment tree frontier at the chain tip).

In the Zashi wallet, you will usually want option (2) because the wallet only supports a single account. In the future, though, the SDK may support the creation of multiple accounts, and also we'll have to figure out something for when the wallets add Orchard support; I'm not sure whether we'll want to handle that by creating a new account, or by creating separate per-protocol birthdays.

@nuttycom nuttycom added this to the Spend-before-Sync milestone Aug 28, 2023
@nuttycom nuttycom force-pushed the sbs/wallet_birthday branch 2 times, most recently from 588f5c9 to 1c00f75 Compare August 29, 2023 02:26
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 my review for the first two commits (up to 12ddc7d).

zcash_client_sqlite/src/wallet/scanning.rs Outdated Show resolved Hide resolved
zcash_client_sqlite/src/wallet/scanning.rs Show resolved Hide resolved
zcash_client_backend/src/data_api.rs Outdated Show resolved Hide resolved
zcash_client_sqlite/CHANGELOG.md Outdated Show resolved Hide resolved
zcash_client_sqlite/src/chain.rs Outdated Show resolved Hide resolved
priority_code(&ScanPriority::Scanned),
),
"CREATE VIEW v_sapling_shard_unscanned_ranges AS
WITH wallet_birthday AS (SELECT MIN(birthday_height) AS height FROM accounts)
Copy link
Contributor

Choose a reason for hiding this comment

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

After the change to AccountBirthday, we are effectively changing the definition of the wallet_birthday column (to match its semantics for new accounts, i.e. last height we don't need to scan). Check that this works for the view, and adjust if necessary.

zcash_client_sqlite/src/wallet/init.rs Outdated Show resolved Hide resolved
zcash_client_sqlite/src/wallet/init.rs Outdated Show resolved Hide resolved
zcash_client_sqlite/src/wallet/init.rs Outdated Show resolved Hide resolved
…te_account`

This also removes the zcash_client_sqlite-specific database
initialization procedures in favor of a standardized approach using the
methods available via the data access API.
str4d
str4d previously approved these changes Sep 1, 2023
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.

Re-utACK 3a1d4a4

Co-authored-by: str4d <[email protected]>
Co-authored-by: Daira Emma Hopwood <[email protected]>
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.

Re-utACK 5b3f544.

@str4d str4d merged commit 229f6e8 into zcash:main Sep 1, 2023
8 of 10 checks passed
@nuttycom nuttycom deleted the sbs/wallet_birthday branch September 1, 2023 17:11
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.

Flushing comments.

zcash_client_sqlite/src/error.rs Show resolved Hide resolved
zcash_client_sqlite/src/wallet.rs Show resolved Hide resolved
zcash_client_sqlite/src/wallet.rs Show resolved Hide resolved
Comment on lines +61 to +65
u32::from(
self.params
.activation_height(NetworkUpgrade::Sapling)
.unwrap()
)
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is guaranteed to be an integer, nevertheless I would have used a named parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did this mostly for the sake of using execute_batch; as far as I know that is the only mechanism available for executing multiple SQL statements in a single call.

@@ -186,6 +198,15 @@ pub(crate) fn select_spendable_sapling_notes(
anchor_height: BlockHeight,
exclude: &[ReceivedNoteId],
) -> Result<Vec<ReceivedSaplingNote<ReceivedNoteId>>, SqliteClientError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

The partially duplicated code between this and get_spendable_sapling_notes seems like a maintenance hazard. I see that the SQL statement is different and has an extra :target_value parameter; can the rest of these methods be abstracted out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The fact that we have two separate such methods is a historical artifact. We should clean it up some day.

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.

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.

Too wide suggested ranges for Testnet
4 participants