Commit Graph

696 Commits

Author SHA1 Message Date
Kris Nuttycombe 6d2c53111a zcash_client_backend 0.10.0-rc.3 2023-09-19 15:00:51 -06:00
Kris Nuttycombe c0e29ad103 zcash_client_sqlite: fix join to blocks table in `v_transactions`
This allows us to display additional block information when a
transparent UTXO was provided for a block that we have scanned.
Also, this ensures that memos from a wallet to itself are not
double-counted.

Co-authored-by: str4d <thestr4d@gmail.com>
2023-09-19 13:15:50 -06:00
Kris Nuttycombe 15bfb41773 Apply suggestions from code review.
Co-Authored-By: str4d <thestr4d@gmail.com>
Co-Authored-By: Daira Hopwood <daira@jacaranda.org>
2023-09-19 13:15:50 -06:00
Kris Nuttycombe 6ebd66da76 zcash_client_sqlite: Remove inner join between `transactions` and `utxos` from `v_transactions`
Under normal usage conditions, the `transactions` table is not currently
populated for transactions involving transparent UTXOs, and so this join
was always resulting in transparent UTXO information being filtered out
from the transaction history.

Fixes [zcash/ZcashLightClientKit#1271]
2023-09-19 13:15:50 -06:00
Kris Nuttycombe 1575f2db88 zcash_client_backend: make the `SpanningTree` type usable outside of `zcash_client_sqlite`
This adds the `data_api::scanning::spanning_tree` module under
a new `unstable-spanning-tree` feature flag, making it available to
other implementations who want to be able to write their own storage
backends without having to reinvent the spanning tree logic.
2023-09-18 11:22:35 -06:00
Kris Nuttycombe b32aa3d2a6 Fix missing zcash_client_backend feature dependency. 2023-09-12 09:35:18 -06:00
Kris Nuttycombe e6b34eeaa2 zcash_client_sqlite 0.8.0-rc.2 2023-09-12 08:32:34 -06:00
Kris Nuttycombe 24068cd63a zcash_client_backend 0.10.0-rc.2 2023-09-12 08:31:39 -06:00
Kris Nuttycombe 1e39daf6f8
Merge pull request #963 from nuttycom/bug/commitment_tree_depth
zcash_client_backend: Fix an error that can occur due to sparse `shardtree` checkpoints.
2023-09-12 08:05:50 -06:00
Kris Nuttycombe f2dcba3a34 Apply suggestions from code review
Co-authored-by: str4d <thestr4d@gmail.com>
2023-09-11 18:39:27 -06:00
Kris Nuttycombe 24e8c82546 zcash_client_backend: Get commitment tree depth for a given number of confirmations from the database.
This fixes the following bug:

Due to complexities related to non-linear scanning, checkpoints are only
added to the wallet's commitment tree in cases where there are notes
discovered within a scanned block. At present, the `shardtree` API only
makes it possible to add multiple checkpoints of the same tree state
when adding checkpoints at the chain tip, and this functionality is not
used by `zcash_client_backend` because we perform checkpoint insertion
in batches that may contain gaps in the case that multiple blocks
contain no Sapling notes. While it would be possible to fix this by
altering the `shardtree` API to permit explicit insertion of multiple
checkpoints of the same tree state at a given note position, this fix
takes a simpler approach.

Instead of ensuring that a checkpoint exists at every block and
computing the required checkpoint depth directly from the minimum number
of confirmations required when attempting a spend, we alter the
`WalletCommitmentTrees` API to allow internal information of the note
commitment tree to be used to determine this checkpoint depth, given the
minimum number of commitments as an argument. This allows us to select a
usable checkpoint from the sparse checkpoint set that resulted from the
sparse insertion of checkpoints described above.
2023-09-11 18:38:54 -06:00
Daira Emma Hopwood 101c9c0ea4 Add passing test for current behaviour of wallet restore from seed.
refs #936

Signed-off-by: Daira Emma Hopwood <daira@jacaranda.org>
2023-09-12 01:33:12 +01:00
Daira Emma Hopwood 401af23484 Improve wallet tests.
Signed-off-by: Daira Emma Hopwood <daira@jacaranda.org>
2023-09-12 01:33:12 +01:00
Kris Nuttycombe 771e4013c3 Move shardtree serialization to the `zcash_client_backend` crate 2023-09-11 18:18:08 -06:00
Kris Nuttycombe 28f1f7d296 zcash_client_sqlite: Add a test for when gaps exist in checkpoints. 2023-09-11 17:08:51 -06:00
Kris Nuttycombe 92237a5558 zcash_client_sqlite: `serialization` module should not have been public. 2023-09-11 16:48:13 -06:00
Jack Grigg 62e3299255 zcash_client_sqlite 0.8.0-rc.1 2023-09-08 19:58:46 +00:00
Jack Grigg 9db68c76ee zcash_client_backend 0.10.0-rc.1 2023-09-08 19:50:53 +00:00
Jack Grigg 87ca71b8db zcash_proofs 0.13.0-rc.1 2023-09-08 19:48:55 +00:00
Jack Grigg 67b84c25e0 zcash_primitives 0.13.0-rc.1 2023-09-08 19:45:54 +00:00
Jack Grigg 94c1f2413d Migrate to `incrementalmerkletree 0.5`, `orchard 0.6` 2023-09-08 18:57:25 +00:00
Kris Nuttycombe 61e06d2227 zcash_client_sqlite: Update CHANGELOG.md for 0.8.0 release 2023-09-08 11:02:37 -06:00
Jack Grigg 6e34e2d113 zcash_client_backend: Migrate to `prost 0.12`, `tonic 0.10` 2023-09-08 16:21:48 +00:00
Kris Nuttycombe aa039819df Fix formatting & clippy lints. 2023-09-08 08:46:20 -06:00
Jack Grigg 504efcfab7 zcash_client_sqlite: Fix scan range matching with incomplete shard
The `v_sapling_shard_scan_ranges` view pairs every scan range with every
shard range, such that each row shows an overlapping pair.

For the complete shards, this is an overlap check between two ranges,
which the previous query was performing correctly (if verbosely).

For the last incomplete shard, we have a half-open range that needs to
be handled separately. The previous query only handled the case where a
scan range was contained within the last shard, and did not handle the
case where the scan range contained the last shard.

This led to a puzzling bug, where `WalletDb::get_wallet_summary` was
sometimes treating any note received within the last shard as part of
the wallet's pending balance. If the wallet's scan queue contained a
range that encompassed the last incomplete shard, the bug in the
`v_sapling_shard_scan_ranges` view meant that it omitted any mention of
the last shard, which translated into these notes being considered
unmined when joining `sapling_received_notes` against the sub-view
`v_sapling_shards_scan_state`.

The bug was made harder to diagnose due to the previous commit's bug
that was causing scan ranges to not be correctly merged; this resulted
in smaller scan ranges that were more likely to be contained within the
last shard, making it visible in `v_sapling_shard_scan_ranges` and
enabling notes to be detected as mined.

The fixed view uses a simpler query that enables us to handle complete
and incomplete shards together.

Time spent investigating and fixing: 4.5 hours

Co-authored-by: Kris Nuttycombe <kris@nutty.land>
2023-09-08 04:04:10 +00:00
Jack Grigg 457c9d26dd zcash_client_sqlite: Prevent empty `FoundNote` ranges in `scan_complete`
In the sandblasting block ranges, shard trees only cover a few hundred
blocks at most. When scanning block ranges much larger than this, it is
likely that when a note is discovered, its parent shard tree is entirely
contained within the scan range. In this situation, `extended_range`
would be set to `range`, and then because an extended range existed,
ranges with `FoundNote` priority would always be created - that in this
case are empty.

In an effectively-linear-scanning wallet situation, this leads to a
`SpanningTree` being constructed with adjacent `Scanned` ranges,
separated by empty `FoundNote` ranges, which it was unable to merge.

We address this by both preventing generation of the empty `FoundNote`
ranges, and by defensively fixing `SpanningTree::into_vec` to skip empty
ranges.

Co-authored-by: Kris Nuttycombe <kris@nutty.land>
2023-09-08 03:57:21 +00:00
Jack Grigg 7a4954c242 zcash_client_sqlite: Fix off-by-one in `scan_complete`
Shard end heights are end-inclusive, while Rust `Range`s are
end-exclusive.

Co-authored-by: Kris Nuttycombe <kris@nutty.land>
2023-09-08 03:44:03 +00:00
Jack Grigg b54969953f zcash_client_sqlite: Simplify range query in `replace_queue_entries`
Co-authored-by: Kris Nuttycombe <kris@nutty.land>
2023-09-08 03:43:07 +00:00
Kris Nuttycombe 341379ee8d
Merge pull request #951 from nuttycom/wallet/balance_for_all_accounts
zcash_client_sqlite: Return a balance for every account from `get_wallet_summary`
2023-09-07 11:49:23 -06:00
Kris Nuttycombe 8dfab23683
Merge pull request #946 from nuttycom/test/unspendable_chain_tip
zcash_client_sqlite: Add a test demonstrating chain tip fund unavailability
2023-09-07 11:27:51 -06:00
Kris Nuttycombe 2131cd547e zcash_client_sqlite: Return a balance for every account from `get_wallet_summary`
Fixes #948
2023-09-07 11:02:59 -06:00
Kris Nuttycombe 0937c6a384 zcash_client_sqlite: Add a test demonstrating chain tip fund unavailability.
This also factors out and cleans up repeated code that checks for anchor
shard completeness.
2023-09-07 10:55:16 -06:00
Kris Nuttycombe 19582a4ca6
Apply suggestions from code review
Co-authored-by: str4d <thestr4d@gmail.com>
2023-09-07 10:29:21 -06:00
Kris Nuttycombe a6328a098f zcash_client_sqlite: Bound creation of scan ranges on wallet birthday.
This modifies `update_chain_tip` and `scan_complete` to ensure that
newly created scan ranged do not extend below the wallet birthday
height.

Fixes #947
2023-09-07 09:58:21 -06:00
Kris Nuttycombe f56c5d8f4b Measure scan progress from wallet birthday, not the fully scanned height. 2023-09-06 12:07:18 -06:00
Jack Grigg c9d58b223c zcash_client_sqlite: Fix bug in `check_shard_discontinuity`
The previous code was checking that the existing shard range was at
least partially inside the proposed insertion range, but this didn't
handle the case where the proposed insertion range was fully contained
by the existing shard range.
2023-09-06 17:13:12 +00:00
Kris Nuttycombe 65420f59df zcash_client_backend: Add `WalletRead::block_max_scanned`
Fixes #941
2023-09-06 08:49:43 -06:00
str4d b4772e948d
Merge pull request #938 from ebfull/check-subtree-discontinuity
Check for potential discontinuities when inserting into the `*_tree_shards` table
2023-09-06 01:05:18 +01:00
str4d 236e9f2cd0
Merge pull request #914 from nuttycom/sbs/nonlinear_sync_aware_balance
Add `get_wallet_summary` to `WalletRead`
2023-09-06 01:04:42 +01:00
str4d 1e12e9d0e6
Clarify zero-conf shielded note behaviour for `get_wallet_summary`
Co-authored-by: Daira Emma Hopwood <daira@jacaranda.org>
2023-09-06 00:18:11 +01:00
Kris Nuttycombe 6cbb107c71 zcash_client_sqlite: allow zero-conf transactions in unshielded balance. 2023-09-05 16:49:36 -06:00
Kris Nuttycombe 7abd1324de Apply suggestions from code review
Co-authored-by: Daira Emma Hopwood <daira@jacaranda.org>
Co-authored-by: Jack Grigg <jack@electriccoin.co>
2023-09-05 16:49:36 -06:00
Kris Nuttycombe f53ea2d778 Add `get_wallet_summary` to `WalletRead`
The intent of this API is to provide a single API which returns in a
single call:

* per-account balances, including pending values
* wallet sync progress

Fixes #865
Fixes #900
2023-09-05 16:06:55 -06:00
Sean Bowe 976b0f0931 Check for potential discontinuities when inserting into the `*_tree_shards` table.
Closes #924
2023-09-05 15:25:26 -06:00
Kris Nuttycombe 6478113855
Merge pull request #935 from nuttycom/sbs/post_907_cleanup
Address unresovled code review comments from #907
2023-09-05 10:42:43 -06:00
Kris Nuttycombe dd60f51d3c Address unresovled code review comments from #907 2023-09-05 09:30:17 -06:00
str4d f132af1f33
Documentation fixes
Co-authored-by: Daira Emma Hopwood <daira@jacaranda.org>
2023-09-05 15:54:15 +01:00
Jack Grigg afec2ee218 `zcash_client_sqlite`: Fix refactor bug: ignore pre-Sapling chain tips
The pre-refactor code did this correctly, but the comment was moved
without fully moving the logic.
2023-09-05 14:52:33 +00:00
Jack Grigg 81d7d9349c zcash_client_sqlite: Fix bugs in `update_chain_tip`
Co-authored-by: Kris Nuttycombe <kris@nutty.land>
2023-09-02 03:01:23 +00:00
Jack Grigg 9f9a1fb92f zcash_client_sqlite: Rework `update_chain_tip` tests to pin behaviour 2023-09-02 03:01:19 +00:00
Kris Nuttycombe 5b3f544102 Apply suggestions from code review
Co-authored-by: str4d <thestr4d@gmail.com>
Co-authored-by: Daira Emma Hopwood <daira@jacaranda.org>
2023-09-01 10:38:20 -06:00
Kris Nuttycombe a51712830f zcash_client_sqlite: ignore unscanned ranges below the birthday height in note selection 2023-09-01 10:12:19 -06:00
Kris Nuttycombe 0b0274cdc1 zcash_client_backend: Make wallet and account birthday heights available via the data access API 2023-09-01 10:11:43 -06:00
Kris Nuttycombe 459dc49b54 zcash_client_backend: Accept account birthday as a parameter to `create_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.
2023-09-01 10:08:17 -06:00
Kris Nuttycombe c99c0fc884 zcash_client_sqlite: Enable forced re-scanning of previously scanned ranges.
When `force_rescans` is set to `true` in a call to
`replace_queue_entries`, previously scanned ranges will have their
existing priority overwritten by the scan priority for a provided range;
otherwise, the existing scan priority dominance rule continues to be
enforced. This enables us to require previously scanned ranges be
re-scanned without interfering with higher-priority scan operations.
2023-09-01 08:13:11 -06:00
Kris Nuttycombe 8bcc3c1cc1 Fix unused imports. 2023-08-31 17:56:04 -06:00
Kris Nuttycombe fb8c3a178c zcash_client_sqlite: Ensure that fragmentation also can't occur at scan range ends. 2023-08-31 17:52:29 -06:00
Kris Nuttycombe 4fe9d61959
zcash_client_sqlite: Fix a comment on range inclusion.
Co-authored-by: str4d <thestr4d@gmail.com>
2023-08-31 15:07:07 -06:00
Kris Nuttycombe bcafb7d4b4 zcash_client_sqlite: Prevent scan range fragmentation.
Fixes #922

Co-authored-by: Sean Bowe <ewillbefull@gmail.com>
2023-08-31 14:18:30 -06:00
Kris Nuttycombe 22b6ddd754 Apply suggestions from code review
Co-authored-by: str4d <thestr4d@gmail.com>
2023-08-29 17:02:46 -06:00
Kris Nuttycombe ff8104fa75 zcash_client_sqlite: (testing) Initialize wallets using an `AccountBirthday` struct. 2023-08-28 19:25:52 -06:00
Kris Nuttycombe a238007e14 zcash_client_sqlite: Remove `testing::network` global accessor function. 2023-08-28 17:27:23 -06:00
Kris Nuttycombe 3be55ae964 zcash_client_backend: Add test-only convenience methods for default addresses. 2023-08-28 14:05:17 -06:00
Jack Grigg 8af74de931 `zcash_client_sqlite`: Add `TestState::propose_shielding`
Currently unused (causing an expected lint), but will be in an upcoming PR.
2023-08-28 18:58:37 +00:00
Jack Grigg 578eac15df zcash_client_sqlite: Rename `TestRunner` to `TestState` 2023-08-28 18:54:35 +00:00
Jack Grigg 84a5d5ca94 zcash_client_sqlite: Migrate all tests to `TestBuilder` 2023-08-28 16:55:51 +00:00
Jack Grigg ce3e4cd34a zcash_client_sqlite: Introduce `TestBuilder` and `TestRunner`
These provide a standard way to set up tests, and helper methods for
performing common test actions.
2023-08-28 16:55:51 +00:00
Jack Grigg 7ba36c7bd2 zcash_client_sqlite: Move testing helper functions into module 2023-08-25 23:16:37 +00:00
Kris Nuttycombe 4d6e236e23
zcash_client_sqlite: minor test documentation improvement.
Co-authored-by: Daira Emma Hopwood <daira@jacaranda.org>
2023-08-21 17:13:45 -06:00
Kris Nuttycombe 61ac79c006 Add debug logging of ignored block range in `init_blocks_table` 2023-08-21 12:26:56 -06:00
Kris Nuttycombe b3be0318c6 zcash_client_sqlite: Initialize the scan queue as part of `init_blocks_table`
Fixes #902
Fixes #898
2023-08-21 09:03:31 -06:00
Kris Nuttycombe 1f8108e8da zcash_client_sqlite: Use constant for SAPLING_SHARD_HEIGHT in v_sapling_shard_unscanned_ranges 2023-08-17 16:20:54 -06:00
Kris Nuttycombe 75ca045786 zcash_client_sqlite: Note selection requires commitment tree positions to be known.
Fixes #895
2023-08-17 16:20:54 -06:00
Kris Nuttycombe 0e7ee0ebd7 zcash_client_sqlite: Ensure that the shard at the chain tip is complete to anchor height.
If the tip shard has any un-scanned range below the anchor height, we
can't compute witnesses for any of our notes.
2023-08-17 16:20:54 -06:00
Kris Nuttycombe 50ea2a5b0f zcash_client_sqlite: Only select notes for which witnesses can be constructed.
This change modifies the implementation of `get_spendable_sapling_notes`
and `select_spendable_sapling_notes` to only return notes at positions
where the associated note commitment tree shard has been fully scanned.
This is slightly more conservative than it needs to be, because
there could be cases where witnesses imported into the tree in the
`shardtree_support` migration cover the complete range of a subtree (and
hence that subtree doesn't need to be re-scanned). However, we can't
detect or depend upon that condition in general without attempting to
create a witness for each note retrieved.

A possible alternative to this approach would be to not bound our query
results on the requested total, and instead attempt to construct a
witness for each note we retrieve, skipping the note if we cannot
construct a witness. However, given that accessing the note commitment
tree can be a costly operation requiring nontrivial deserialization
costs, the more conservative database-oriented approach is perhaps
better.
2023-08-17 16:20:54 -06:00
Kris Nuttycombe dee43854cb zcash_client_sqlite: Ensure that target and anchor heights are relative to the chain tip.
Prior to the scan-before-sync changes, the wallet was able to assume
that the maximum scanned block height at the time of the spend was
within a few blocks of the chain tip. However, under linear scanning
after the spend-before-sync changes this invariant no longer holds,
resulting in a situation where in linear sync conditions the wallet
could attempt to create transactions with already-past expiry heights.

This change separates the notion of "chain tip" from "max scanned
height", relying upon the `scan_queue` table to maintain the wallet's
view of the consensus chain height and using information from the
`blocks` table only in situations where the latest and/or earliest
scanned height is required.

As part of this change, the `WalletRead` interface is also modified to
disambiguate these concepts.
2023-08-16 11:53:24 -06:00
Jack Grigg 44abd3450b Require `BlockSource::with_blocks` fail on non-existent `from_height`
Previously this was not clearly specified, and the implementations in
`zcash_client_sqlite` behaved similarly to when `from_height = None`.

Closes zcash/librustzcash#892.
2023-08-09 17:57:00 +00:00
Kris Nuttycombe 1c4e63718f Add `Display` impl for `ReceivedNoteId` 2023-08-07 12:24:05 -06:00
Kris Nuttycombe f602ec125d Apply suggestions from code review
Co-authored-by: str4d <thestr4d@gmail.com>
2023-08-07 11:28:28 -06:00
Kris Nuttycombe d3b7dffa3c zcash_client_backend: Restrict use of backend-specific note identifiers.
In general, it is preferable to use globally relevant identifiers where
possible. This PR removes the `WalletRead::TxRef` associated type in
favor of using `TxId` directly for the transaction identifier, and
restricts the use of the `NoteRef` type to those scenarios where the
result of one query is intended to be used directly as the input to
another query.

Closes #834
2023-08-07 11:27:38 -06:00
str4d d7bd566b21
Merge pull request #889 from nuttycom/avoid_checkpoint_add_conflict
zcash_client_sqlite: Ensure that re-adding the same checkpoint information does not cause a database conflict.
2023-08-07 18:18:53 +01:00
Kris Nuttycombe 522f1e4da0 Apply suggestions from code review
Co-authored-by: str4d <thestr4d@gmail.com>
2023-08-07 08:07:21 -06:00
Kris Nuttycombe 027b3c9af8 zcash_client_sqlite: Ensure that re-adding the same checkpoint information does not cause a database conflict.
The `add_checkpoint` method is intended to be idempotent. In the case
that we add a checkpoint at an already-checkpointed block height, we
should only raise an error in the case that the note commitment tree
position or the set of notes spent in the checkpointed block has
changed.
2023-08-04 15:12:04 -06:00
Kris Nuttycombe 0ee45e40c4 zcash_client_sqlite: Replace Either-based definition of `wallet::commitment_tree::Error` with a bespoke error type. 2023-08-04 15:01:15 -06:00
Kris Nuttycombe cb0d16cfa9 Fix clippy complaint. 2023-08-04 14:35:58 -06:00
Kris Nuttycombe a5a8562ddd zcash_client_backend, zcash_client_sqlite: Ensure consistency between sent & stored memos. 2023-08-04 14:05:00 -06:00
Kris Nuttycombe f0b2fc3421 zcash_client_sqlite: Store the empty memo as a single 0xf6 byte. 2023-08-02 11:35:27 -06:00
Kris Nuttycombe e718e76989 zcash_client_sqlite: Add a test that demonstrates the expected behavior of `get_memo` for empty-memo situations. 2023-08-02 11:35:27 -06:00
Jack Grigg facd4ccac5 Migrate to latest `shardtree` revision 2023-07-25 20:57:49 +00:00
str4d b4f083f4eb
Merge pull request #883 from zcash/put_blocks-parallel-tree-building
zcash_client_sqlite: Build subtrees from new commitments in a threadpool
2023-07-25 18:24:41 +01:00
Jack Grigg 99ecdf3a89 zcash_client_sqlite: Build subtrees from new commitments in a threadpool
The new `multicore` feature flag can be used to disable this behaviour.
2023-07-25 15:59:03 +00:00
Jack Grigg 0f6970aefd zcash_client_sqlite: Cache statement for `wallet::prune_nullifier_map` 2023-07-25 13:46:44 +00:00
Jack Grigg e773cd3ed4 zcash_client_sqlite: Add index for foreign key of `nullifier_map` table
This greatly improves the performance of `wallet::prune_nullifier_map`
by speeding up `ON DELETE CASCADE`.
2023-07-25 13:45:52 +00:00
Jack Grigg ed06a37b09 zcash_client_sqlite: Mark existing blocks scanned in `shardtree` migration
The `shardtree` migration is applied to a database state that was
created via linear scanning, so we have complete wallet information for
those blocks.
2023-07-21 21:01:03 +00:00
Jack Grigg 97a3f818ec zcash_client_sqlite: Only import recent frontiers into `ShardTree`
We only need to load frontiers into the ShardTree that are close enough
to the wallet's known chain tip to fill `PRUNING_DEPTH` checkpoints, so
that ShardTree's witness generation will be able to correctly handle
anchor depths. Loading frontiers further back than this doesn't add any
useful nodes to the ShardTree (as we don't support rollbacks beyond
`PRUNING_DEPTH`, and we won't be finding notes in earlier blocks), and
hurts performance (as frontier importing has a significant Merkle tree
hashing cost).

Closes zcash/librustzcash#877.
2023-07-21 20:59:24 +00:00
Jack Grigg 0f2689b9c3 zcash_client_sqlite: Maintain a nullifier map from out-of-order scanning
Closes zcash/librustzcash#876.
2023-07-21 18:01:52 +00:00
Jack Grigg 4d2abd5c3a zcash_client_sqlite: Add test showing out-of-order balance problem 2023-07-21 17:53:14 +00:00
Jack Grigg fab68d217e zcash_client_sqlite: Fix `WalletDb::block_fully_scanned` implementation 2023-07-21 15:25:39 +00:00
Jack Grigg 963496d0ab Use an upsert for `FsBlockDb::write_block_metadata` 2023-07-19 16:41:01 +00:00
str4d c7b308b312 Rename `VALIDATION_DEPTH` constant to `VERIFY_LOOKAHEAD`
Co-authored-by: Daira Emma Hopwood <daira@jacaranda.org>
2023-07-19 16:03:02 +00:00
Sean Bowe e16aa41117 Add test for join_nonoverlapping. 2023-07-19 14:54:01 +00:00
Jack Grigg 359ff55ce3 Do nothing if `update_chain_tip` is given a tip lower than we can use
Previously it would panic due to constructing invalid `ScanRange`s.
2023-07-19 14:54:01 +00:00
Jack Grigg 98ea08e497 Migrate to latest `shardtree` to improve performance 2023-07-19 14:54:01 +00:00
Jack Grigg a87dca00e2 Documentation updates, fixes, and cleanups
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2023-07-19 14:54:01 +00:00
Jack Grigg 2a98f94f05 Add more debug and trace logging
The `Debug` impl for `sapling::Node` is updated to output hex-encoded
bytes for readability.
2023-07-18 17:23:57 +00:00
Jack Grigg 510944777c Transactionally modify the wallet DB in `replace_queue_entries`
We don't want to delete old scan range queue entries unless we are
guaranteed to write the updated queue entries.
2023-07-18 17:23:57 +00:00
Jack Grigg 281dbd5524 Ensure that `extended_range` in `scan_complete` is a superset of `range`
Previously `extended_range` only covered the extent of the leaves of
all subtrees in which notes were found during a scan. When the scanned
range was large, this was not guaranteed to be contained within the
subtree leaves, causing an assertion failure when an invalid `ScanRange`
was constructed.
2023-07-18 17:23:57 +00:00
Jack Grigg cb887efa06 Use correct levels for cap nodes in `put_shard_roots`
The Merkle hashes used for the note commitment trees are domain
separated by level, so when pretending that the subtree roots are leaves
of the cap tree, we need to adjust for their level not being zero.

Closes zcash/librustzcash#874.

Co-authored-by: Sean Bowe <ewillbefull@gmail.com>
2023-07-18 17:23:57 +00:00
Jack Grigg f7163e9dd9 Code simplifications
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2023-07-18 17:23:55 +00:00
Jack Grigg bb920341a6 Fix bug in `RightFirstDisjoint` insertion logic 2023-07-18 17:22:48 +00:00
Jack Grigg 2c0acac1bd Use explicit arguments for internal `suggest_scan_ranges` helper
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2023-07-18 17:22:48 +00:00
Jack Grigg e3aeb63e0a Fix off-by-one bugs with `ScanRange` end bounds
Maximum chain heights are end-inclusive, while `ScanRange` is
end-exclusive.

Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2023-07-12 16:27:52 +00:00
Kris Nuttycombe 352e1c709a Add a test for `scan_complete` and `update_chain_tip` 2023-07-07 20:13:45 -06:00
Kris Nuttycombe 6db4355fc4 Fix an error in dominance calculation. 2023-07-07 20:13:45 -06:00
Kris Nuttycombe 6fa0b46d8e Implement `suggest_scan_ranges` and `update_chain_tip`
This implements a priority queue backed by the wallet database for scan
range ordering. The scan queue is updated on each call to `put_blocks`
or to `update_chain_tip`.
2023-07-07 20:13:45 -06:00
Jack Grigg 8d792bb7b5 zcash_client_sqlite: Fix `WalletDb::get_transaction` for unmined txs 2023-07-06 22:24:59 +00:00
Kris Nuttycombe d55fa09464 Add a check to ensure that blocks passed to `put_blocks` are sequential. 2023-07-06 12:13:39 -06:00
Kris Nuttycombe 1b5a24a655 Batch data store writes of `put_block`
Instead of calling `put_block` for each block scanned,
`scan_cached_blocks` will now defer the block writes until the scan of a
batch is complete and will perform the block writes and note commitment
tree updates all within a single transaction.

This should ordinarily be fine in terms of memory consumption, because
the block data being saved is pruned to only that spend an output
information that is related to transactions in the wallet, which will
normally be sparse enough that the block range size that is appropriate
for a given platform to run within a batch scanner adequately bounds the
memory consumption of this pruned representation.
2023-07-06 12:13:39 -06:00
Kris Nuttycombe 98147e0d7d Make `from_height` and `limit` parameters to `scan_cached_blocks` non-optional. 2023-07-05 18:56:19 -06:00
Kris Nuttycombe faccf56f04 Split `PoolType` enum into `PoolType` and `ShieldedProtocol`
There are cases where we wish to return informaiton that is relevant to
a specific shielded protocol and `Transparent` is an invalid case. This
is a minor preparatory refactoring that makes this distinction
expressible.
2023-07-05 18:20:43 -06:00
Kris Nuttycombe 1e5b23aeba zcash_client_backend: Add `put_sapling_subtree_roots` to `WalletCommitmentTrees`
Also add the `zcash_client_sqlite` implementation & tests for the new
method.
2023-07-05 18:18:20 -06:00
Kris Nuttycombe c13c8c6678 Address comments from code review. 2023-07-03 17:08:01 -06:00
Kris Nuttycombe c363e71fa9 Rename proto::compact::{BlockMetadata => ChainMetadata} 2023-07-03 16:19:13 -06:00
Kris Nuttycombe 09a0096c74 Use valid serialized CommitmentTree values for migration tests. 2023-07-03 10:49:03 -06:00
Kris Nuttycombe e3aafdad19 Move chain continuity checks into `scan_block_with_runner`
In preparation for out-of-order range-based scanning, it is necessary
to ensure that the size of the Sapling note commitment tree is carried
along through the scan process and that stored blocks are always
persisted with the updated note commitment tree size.
2023-07-03 10:49:03 -06:00
Kris Nuttycombe 77b638012b Remove `zcash_client_backend::data_api::chain::validate_chain`
Local chain validation will be performed internal to
`scan_cached_blocks`, and as handling of chain reorgs will need to
change to support out-of-order scanning, the `validate_chain` method
will be superfluous. It is removed in advance of other changes in order
to avoid updating it to reflect the forthcoming changes.
2023-07-01 17:58:01 -06:00
Kris Nuttycombe e225a54d2e Use `NonZeroU32` for all `min_confirmations` values. 2023-06-30 12:37:41 -06:00
Kris Nuttycombe 8625e9a777 Handle parsing of the not-present `CommitmentTree` sentinel. 2023-06-30 12:08:06 -06:00
Kris Nuttycombe 70497a241c Only store z->t transaction data once, not once per Sapling output. 2023-06-30 10:42:48 -06:00
Kris Nuttycombe cd939f94c4 Ensure that checkpoints are ordered by position when querying for pruning. 2023-06-30 09:48:19 -06:00
Kris Nuttycombe 95745dd620 Use ruqlite::Rows::mapped to allow `collect` 2023-06-30 09:45:06 -06:00
Kris Nuttycombe 45177a51e1 Fix off-by-one error in scan_block_with_runner. 2023-06-30 09:30:24 -06:00
Kris Nuttycombe d65b129b43 Apply changelog, documentation & style suggestions from code review
Co-authored-by: str4d <thestr4d@gmail.com>
2023-06-30 09:30:24 -06:00
Kris Nuttycombe ba709177d3 Reorganize Sapling and Orchard note commitment tree sizes in CompactBlock.
We move thes fields out into a separate BlockMetadata struct to ensure
that future additions to block metadata are structurally separated from
future additions to block data.
2023-06-29 15:35:18 -06:00
Kris Nuttycombe 547634e210 zcash_client_sqlite: Move the SqliteShardStore implementation out of the `wallet::sapling` module. 2023-06-29 15:35:18 -06:00
Kris Nuttycombe 106669d977 zcash_client_sqlite: Generalize SQLite-backed ShardStore impl to make it reusable for Orchard. 2023-06-29 15:35:18 -06:00
Kris Nuttycombe 0a4236f725 zcash_client_sqlite: Add tests for sqlite-backed ShardTree & fix revealed issues. 2023-06-29 15:35:18 -06:00
Kris Nuttycombe 425b5e01d7 zcash_client_sqlite: Support shardtree checkpoint functionality 2023-06-29 15:35:18 -06:00
Kris Nuttycombe c42cffeb1d zcash_client_backend: Replace `WalletWrite::advance_by_block` with `WalletWrite::put_block`
Also, add assertions to prevent attempting the creation of zero-conf
shielded spends.
2023-06-29 15:35:18 -06:00
Kris Nuttycombe d11f3d2acc zcash_client_sqlite: Add shardtree truncation & checkpoint operations. 2023-06-29 15:35:18 -06:00
Kris Nuttycombe ade882d01c zcash_client_sqlite: Add shard & checkpoint insertion. 2023-06-29 15:35:18 -06:00
Kris Nuttycombe 9f2bb94a5e zcash_client_sqlite: Add shard persistence to wallet migration. 2023-06-29 15:35:18 -06:00
Kris Nuttycombe ed2e22b737 zcash_client_sqlite: Add shard serialization & parsing 2023-06-29 15:35:18 -06:00
Kris Nuttycombe 3e358bc1c9 zcash_client_backend: Use `shardtree` for note commitments in block scanning.
Also adds a skeleton `zcash_client_sqlite` implementation of
`shardtree::ShardStore` and a skeleton migration for related
database changes.
2023-06-29 15:35:18 -06:00
Kris Nuttycombe 06a7849cb7
Merge pull request #859 from nathan-at-least/rustsec-2022-0090-fix
[Impacts API versioning] Update dependencies to resolve RUSTSEC-2022-0090
2023-06-19 12:22:04 -06:00
Nate Wilcox 5ba44b9019 Update dependencies to resolve https://rustsec.org/advisories/RUSTSEC-2022-0090 2023-06-17 12:44:35 -07:00
Kris Nuttycombe 48434bb271 zcash_client_sqlite: Fix SQL identation errors. 2023-06-16 15:09:33 -06:00
Kris Nuttycombe 91f0f03d9d zcash_client_sqlite: Factor out common logic for the representation of stored memos. 2023-06-16 15:09:29 -06:00
Kris Nuttycombe 820e61caaa zcash_client_sqlite: Avoid swallowed errors in max-block-height queries. 2023-06-16 15:09:26 -06:00
Kris Nuttycombe 4b9180cb04 zcash_client_sqlite: Fix details of `put_sent_output` documentation.
Also address a minor naming issue from code review.
2023-06-16 15:09:19 -06:00