Commit Graph

204 Commits

Author SHA1 Message Date
Kris Nuttycombe 214a3750c5 zcash_client_backend: Make `Balance` and `AccountBalance` fields private.
Public methods for mutation of these fields have been provided that
perform checking for overflow of the valid monetary range as part
of their operation.
2023-12-04 13:53:27 -07:00
Jack Grigg 0d06e561bb Update Sapling imports to migrate off re-exports at old paths 2023-11-28 03:40:41 +00:00
Kris Nuttycombe 33169719ce zcash_client_backend: Add serialization & parsing for protobuf Proposal representation. 2023-11-09 20:07:16 -07:00
Kris Nuttycombe 27f78d1894 zcash_client_backend: Add Orchard note commitment tree size to block metadata. 2023-11-08 16:46:44 -07:00
Kris Nuttycombe aa063ae3fd zcash_client_backend: Factor out input source traits from `WalletRead`
Prior to this change, it's necessary to implement the entirety of the
`WalletRead` trait in order to be able to use the input selection
functionality provided by `zcash_client_backend::data_api::input_selection`.
This change factors out the minimal operations required for transaction
proposal construction to better reflect the principle of least authority
and make the input selection code reusable in more contexts.

In order to minimize the operations of the newly-created `InputSource`
and `ShieldingSource` traits, this change also removes the
`min_confirmations` field from transaction proposals, in favor of
storing explicit target and anchor heights. This has the effect of
limiting the lifetime of transaction proposals to `PRUNING_DEPTH -
min_confirmations` blocks.
2023-11-08 12:41:49 -07:00
Kris Nuttycombe a0935b5ecd zcash_client_backend: remove `WalletRead::is_valid_account_extfvk` 2023-10-27 15:01:26 -06:00
Kris Nuttycombe f7527e14c9 Use `NonNegativeAmount` for note and utxo value fields 2023-10-23 12:59:26 -06:00
Kris Nuttycombe 29c676ff12
Merge pull request #1009 from tw0po1nt/fix_txn_builder_panic
Gracefully handle when given an Orchard-only UA
2023-10-12 18:15:36 -06:00
Matthew Watt a788cc4c4d Fix merge conflicts 2023-10-12 06:16:22 -05:00
Kris Nuttycombe 1447d8ea01 zcash_client_backend: Move change memos into the `ChangeValue` components of `Proposal`s.
The existing API limited change outputs to having only a single memo
repeated across each change output. This change makes it so that each
proposed change output can have its own associated memo, and leaves it
up to the input selector to determine how requested change memos are
associated with change outputs.
2023-10-11 14:15:19 -06:00
Kris Nuttycombe a2b5c2c784 zcash_client_backend: Use `NonNegativeAmount` for fee and change amounts.
In order to use `uint64` for amounts that must be nonnegative in the
`proposal.proto` file, it is useful to update fee and change computation
to use `NonNegativeAmount` where possible.
2023-10-10 16:12:47 -06:00
Matthew Watt 73f263682e Remove unnecessary local 2023-10-10 07:50:07 -05:00
Matthew Watt 2a4d9e06da Run fmt 2023-10-10 07:47:08 -05:00
Matthew Watt b548e00c10
Update zcash_client_sqlite/src/wallet.rs
Co-authored-by: Daira Emma Hopwood <daira@jacaranda.org>
2023-10-10 06:36:40 -05:00
Matthew Watt 0e5a58b0b0
Update zcash_client_sqlite/src/wallet.rs
Co-authored-by: Daira Emma Hopwood <daira@jacaranda.org>
2023-10-10 06:36:20 -05:00
Matthew Watt c4175342ac Cleanup 2023-10-09 06:46:12 -05:00
Matthew Watt 94f2240e08 Provide PoolType to UnsupportedPoolType case; stylistic changes 2023-10-08 19:05:50 -05:00
Jack Grigg f6d7714efe zcash_client_sqlite: Replace internal height tuples with `RangeInclusive`
We don't need to iterate over them, but the `*_extrema` internal methods
are semantically returning inclusive ranges, and using `RangeInclusive`
avoids bugs where the wrong half of the tuple is used (instead moving
the location of the tuple handling inside the `*_extrema` methods, which
cuts the number of occurrences from linear in the number of function
calls to constant).
2023-09-27 16:34:58 +00:00
Jack Grigg b76b028b3a zcash_client_sqlite: Set chain tip to truncation height when truncating
We don't know at truncation time what the latest chain tip is; the chain
might have reorged to a shorter heavier chain, or the reorg depth might
only be a few blocks. `WalletDb::chain_height` uses the scan queue as
its source of truth, so the `Verify` range we add during truncation
(to prioritise determining whether the rewind was sufficient) can't
extend beyond the block height we know to exist.

The next call to `WalletDb::update_chain_tip` will add additional ranges
beyond this height, which might include a `Verify` range that ends up
merging with the one added during truncation.
2023-09-22 21:09:23 +00:00
Jack Grigg 625a5ff594 zcash_client_sqlite: Remove is-mined checks from transparent balance
The `LEFT OUTER JOIN` was causing the `tx.block IS NULL` check to alias
two cases: an unspent transparent output, and a transparent output spent
in an unmined transaction. The latter only makes sense to include in the
UTXO count if the transaction is expired, and (due to limitations of the
transparent data model in the current wallet) if that expiry won't be
undone by a reorg. We now handle these two cases directly.

Partly reverts 8828276361.
Closes zcash/librustzcash#983.

Co-authored-by: Kris Nuttycombe <kris@nutty.land>
2023-09-22 21:09:23 +00:00
Jack Grigg cd6c962719 zcash_client_sqlite: Write a test for transparent balance behaviour 2023-09-22 17:20:10 +00:00
Jack Grigg 9e4fa96dd7 zcash_client_sqlite: Clean up existing transparent input test 2023-09-22 17:01:00 +00: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 f56c5d8f4b Measure scan progress from wallet birthday, not the fully scanned height. 2023-09-06 12:07:18 -06:00
Kris Nuttycombe 65420f59df zcash_client_backend: Add `WalletRead::block_max_scanned`
Fixes #941
2023-09-06 08:49:43 -06: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
Kris Nuttycombe dd60f51d3c Address unresovled code review comments from #907 2023-09-05 09:30:17 -06: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 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 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