Commit Graph

168 Commits

Author SHA1 Message Date
Kris Nuttycombe ff8104fa75 zcash_client_sqlite: (testing) Initialize wallets using an `AccountBirthday` struct. 2023-08-28 19:25:52 -06: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 7ba36c7bd2 zcash_client_sqlite: Move testing helper functions into module 2023-08-25 23:16:37 +00: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
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 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
Jack Grigg 0f6970aefd zcash_client_sqlite: Cache statement for `wallet::prune_nullifier_map` 2023-07-25 13:46:44 +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 fab68d217e zcash_client_sqlite: Fix `WalletDb::block_fully_scanned` implementation 2023-07-21 15:25:39 +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
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 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 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 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 c13c8c6678 Address comments from code review. 2023-07-03 17:08:01 -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 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 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 547634e210 zcash_client_sqlite: Move the SqliteShardStore implementation out of the `wallet::sapling` module. 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 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 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 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
Kris Nuttycombe 2674209818 zcash_client_sqlite: Remove the remainder of DataConnStmtCache 2023-06-16 15:09:14 -06:00
Kris Nuttycombe 21f82e539f zcash_client_sqlite: Use cached prepared statements for transparent UTXO operations. 2023-06-16 15:09:02 -06:00
Kris Nuttycombe 9f6831ea75 zcash_client_sqlite: Use cached statements for `insert_address` 2023-06-16 15:08:57 -06:00
Kris Nuttycombe 2354c8b48d zcash_client_sqlite: Use upsert & automatic caching of prepared statements for `put_sent_output` 2023-06-16 15:08:52 -06:00
Kris Nuttycombe 7917effe82 zcash_client_sqlite: Use upsert & automatic caching of prepared statements for `put_received_note` 2023-06-16 15:08:44 -06:00
Kris Nuttycombe 8d86ffd9c4 zcash_client_sqlite: Use `prepare_cached` instead of manual statement caching.
`rusqlite` includes a mechanism for creating prepared statements that
automatically caches them and reuses the caches when possible. This
means that it's unnecessary for us to do our own caching, and also
offers a minor performance improvement in that we don't need to eagerly
prepare statements that we may not execute in the lifetime of a given
`WalletDb` object. It also improves code locality, because the prepared
statements are now adjacent in the code to the parameter assignment
blocks that correspond to those statements.

This also updates a number of `put_x` methods to use sqlite upsert
functionality via the `ON CONFLICT` clause, instead of having to perform
separate inserts and updates.
2023-06-16 15:08:34 -06:00
Kris Nuttycombe 92d08b8504 Move `zcash_client_sqlite` Sapling wallet functionality to a dedicated module. 2023-06-02 10:59:17 -06:00
Kris Nuttycombe d99b4d4d6e Update memo retrieval API to reflect that memos may not be present.
Memos may be absent for both sent and received notes in cases where only
compact block information has been used to populate the wallet database.
This fixes a potential crash in the case that we attempt to decode a
SQLite `NULL` as a byte array. It does, however, introduce a slight
semantic confusion that will need to be considered in the case of future
updates where a note may not have an associated memo; at present, the
only reason we might not have the memo is that we might not have
retrieved the full transaction information from the chain, but in the
future there might be other possible reasons for this absence.

Fixes #384
2023-05-16 10:27:40 -06:00
Kris Nuttycombe 6f2cbfc7de Factor serialization out from merkle tree data structures. 2023-05-04 12:21:47 -06:00
Kris Nuttycombe ec57d23115 Use const generics to set commitment tree & incremental witness depths.
This is in preparation for extraction into the `incrementalmerkletree`
crate, which is not Sapling-specific and therefore cannot hard-code
the depths of these data structures.
2023-05-04 12:16:09 -06:00
Kris Nuttycombe 8e8388a9f6 Add migration to enable storage of unmined change notes. 2023-04-27 17:26:11 -06:00
Kris Nuttycombe fa282695da Store change notes as received for internal transfers. 2023-04-27 14:41:26 -06:00