Commit Graph

11342 Commits

Author SHA1 Message Date
Jack Grigg 33367709f7 Merge most `cxx::bridge` definitions into a single bridge
This enables us to use Rust types across more bridged APIs, which we
can't do with multiple bridge definitions until `cxx` adds support.
2023-04-05 10:50:35 +00:00
Kris Nuttycombe 1feec6a3b4
Merge pull request #6494 from daira/examine
Improve code readability using `examine` macro
2023-04-04 16:32:04 -06:00
Kris Nuttycombe b3dbfb1ddd
Merge pull request #6527 from daira/zip317-computations
ZIP 317 preparation: fix bitrotted miner tests and add conventional fee computations
2023-04-04 16:30:51 -06:00
Daira Emma Hopwood 3adf580dc0 Refactor that avoids using exceptions for local flow control and is simpler.
Signed-off-by: Daira Emma Hopwood <daira@jacaranda.org>
2023-04-04 22:03:27 +01:00
Kris Nuttycombe 1afd532ba8
Merge pull request #6526 from sellout/split-cxxbridge
Split C++ generated from Rust into own lib
2023-04-04 14:58:48 -06:00
Daira Emma Hopwood ac3e345689 Refactoring to avoid an unnecessary temporary.
Signed-off-by: Daira Emma Hopwood <daira@jacaranda.org>
2023-04-04 21:26:52 +01:00
Daira Emma Hopwood 32e1d2eeeb Refactoring to avoid duplicated code.
Signed-off-by: Daira Emma Hopwood <daira@jacaranda.org>
2023-04-04 21:26:52 +01:00
Daira Emma Hopwood 6bb8c60f41 Use the new `examine` macro to replace all instances of
`std::visit(match {...}, specimen)`, improving code readability.

For ease of review, this commit includes only obviously correct
transformations that all follow the same pattern.

Signed-off-by: Daira Emma Hopwood <daira@jacaranda.org>
2023-04-04 21:26:39 +01:00
Daira Emma Hopwood 60755efaf1 Add `examine`, a wrapper around `std::visit` that reverses the arguments.
Co-authored-by: Greg Pfeil <greg@electriccoin.co>
Signed-off-by: Daira Emma Hopwood <daira@jacaranda.org>
2023-04-04 21:20:10 +01:00
Greg Pfeil 1aac7c0c32
Split C++ generated from Rust into own lib
This allows us to compile it with different flags. In particular, there are
warnings we can’t easily fix in the generated code.
2023-04-03 18:09:30 -06:00
Daira Emma Hopwood 4fd3493291 Implement ZIP 317 computations.
Signed-off-by: Daira Emma Hopwood <daira@jacaranda.org>
2023-04-03 23:05:50 +01:00
DeckerSU 78804dd438
InsertBlockIndex: pass const reference on hash, instead of hash
InsertBlockIndex should take a const reference to a uint256 instead of
just a uint256.

LoadBlockIndexGuts also assume std::function<CBlockIndex*(const uint256&)> insertBlockIndex
as an argument:

2d456afebe/src/txdb.h (L150)
2023-04-02 23:00:08 +02:00
Kris Nuttycombe 2d456afebe
Merge pull request #6408 from sellout/wallet_tx_builder/lock-notes
Lock notes (except Orchard) in wallet_tx_builder
2023-03-31 18:05:06 -06:00
Greg Pfeil 69ab52cb3e
Improve Doxygen for note locking 2023-03-30 14:22:34 -06:00
Kris Nuttycombe 564ef2a3ac
Merge pull request #6502 from rex4539/typos
Fix typos
2023-03-29 22:23:33 -06:00
Greg Pfeil 06553d1399
Lock notes (except Orchard) in wallet_tx_builder
This fixes an RPC test failure that tests specifically for this with
z_shieldcoinbase. This also exposed an issue where an overly-high fee resulted
in a negative Payment causing an exception too deep. Added an assert when
creating a Payment and guarded against it for z_shieldcoinbase.

Fixes #2621 and #5654 (but does not handle Orchard locking, which is tracked in
a separate issue).
2023-03-29 16:59:43 -06:00
Kris Nuttycombe f60d2c71e7
Refactor RPC privacyPolicy handling
Extracted from z_sendmany to be used across multiple transaction
operations. Previously, it also checked a `bool` to decide what “LegacyCompat”
means, but bools are too easy to concoct, so it now expects the sender and
recipients to be checked internally. Also, z_sendmany was generating the bool
only from the sender, illustrating how easy it is to miss something when you try
to precompute.
2023-03-29 16:56:20 -06:00
Dimitris Apostolou fdae3213ac Fix typos 2023-03-29 13:40:48 -06:00
Kris Nuttycombe 4892bf327d
Merge pull request #6470 from sellout/error-on-tmemos
Improve taddr no-memo check.
2023-03-29 09:17:23 -06:00
Daira Emma Hopwood dd246587a3 Fix bit-rotted code in miner tests.
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2023-03-29 00:05:51 +01:00
Greg Pfeil 7bf5f598ee
Update src/wallet/rpcwallet.cpp
Co-authored-by: Kris Nuttycombe <kris@nutty.land>
2023-03-28 16:30:47 -06:00
Greg Pfeil af2526d755
Improve taddr no-memo check
Do the check deeper, preventing test_bitcoin from being able to bypass it. This
also moves it out of z_sendmany-specific code, which will be helpful when we add
other operations, like sendfromaccount.
2023-03-28 16:28:16 -06:00
Greg Pfeil effbc33276
Remove CWallet member from WalletTxBuilder
This resolves a conflict where most usage is `const`, but some modifies the
wallet. Previously it held a const member and then used `pwalletMain` directly
for the mutating calls. This now passes `CWallet` explicitly where necessary,
using `const` when possible.

This also benefits a follow-up PR (#6408) that introduces locking, which also
mutates the wallet.
2023-03-28 16:24:08 -06:00
Jack Grigg 4a94975268 Use `RandomInvalidOutputDescription()` everywhere it makes sense
As a pre-check inside `z_sendmany` we estimate the size of the
transaction that would be created, to confirm it won't exceed any
limits. We do this by creating a fake transaction with fake outputs and
measuring its size. In the case of Sapling recipients, we'd push an
empty `OutputDescription`.

In zcash/zcash#6459 we pulled in changes that improved type safety in
the Rust types. One of these changes was that the `cv` field in a
Sapling Output Description is now enforced at parsing time to be not
small order (where previously we enforced this at proof verification
time).

The two above paragraphs collide because when measuring the size of the
fake transaction, we convert a `CMutableTransaction` into a
`CTransaction`; this calls `UpdateHash` to pin its txid, and that causes
the transaction to be serialized and then parsed across the FFI. This
causes the null `OutputDescription` to reach the Rust parser which
treats it as invalid.

There are two solutions to this, which are used in various contexts:

- Avoid pushing a null `OutputDescription` into a `CMutableTransaction`.
  This is the fix implemented in this PR for `z_sendmany`: we now call
  `RandomInvalidOutputDescription()` which gives us a consensus-invalid
  but parser-valid `OutputDescription`, suitable for estimating tx size.

- Use `UNSAFE_CTransaction` to avoid having `UpdateHash` be called on
  construction. This type is used in tests where we explicitly want to
  construct an invalid type in C++, for consensus checking purposes. One
  of the `OutputDescription()` uses was in a test, but didn't trigger
  the issue because the test was checking a different part of the
  transaction being invalid. Technically no change is needed here;
  however we now also call `RandomInvalidOutputDescription()` here for
  uniformity.

Part of zcash/zcash#6509.
2023-03-27 22:33:45 +00:00
Greg Pfeil 666a8d1b37
Merge pull request #6377 from sellout/wallet_tx_builder/z_sendmany
Extract common transaction logic from z_sendmany
2023-03-22 11:24:33 -06:00
Greg Pfeil 10a1beb7c5
Have GetRecipientPools return a copy
Previously returned a const reference to a non-const object, which could then be
modified under the caller’s feet.
2023-03-21 11:07:18 -06:00
Greg Pfeil 8ebb22c67f
Simplify SelectOVKs
This inverts the structure, dispatching on the selector pattern first, then only checking
`SpendableInputs` if the selector is multi-pool. This shortens the code, eliminates some failure
cases, and caught a bug where `SaplingExtendedFullViewingKey` selectors were not
supported (previously hidden by `match { ..., [](const auto&) … }`).
2023-03-20 18:22:53 -06:00
Greg Pfeil 5236f447c7
Apply suggestions for WalletTxBuilder from code review
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2023-03-20 16:20:50 -06:00
Greg Pfeil af2c7e7e49
Address WalletTxBuilder review feedback 2023-03-20 14:23:18 -06:00
Greg Pfeil 1f72b42b81
Additional z_sendmany test cases
Also improve error messages.
2023-03-20 11:24:50 -06:00
Greg Pfeil 62ae44a131
Ensure that a WalletTxBuilder tx balances
This also removes the code that stops adding spends if they ever go
`>= targetAmount`. The included note limiting and change calculation should
ensure that it’s always `==` at the end, and we don’t want paper over a mistake
in those earlier calculations.

There are existing tests that fail if either
- the newly-added Orchard increment is missing or
- the assertion is applied when there’s Sprout change.
2023-03-20 09:40:42 -06:00
Greg Pfeil 5081a8e8fd
Address WalletTxBuilder PR feedback 2023-03-17 16:11:40 -06:00
str4d 0e7d61d6dc
Adjust documentation
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2023-03-17 17:16:33 +00:00
Daira Emma Hopwood 1da8a545d8 Adjust indentation to be consistent without changing existing code.
Signed-off-by: Daira Emma Hopwood <daira@jacaranda.org>
2023-03-17 16:55:51 +00:00
Greg Pfeil 77a26692bb
Don’t permit user-provided “internal” payments
The `Payment` type had an `isInternal` field, but it is (and should always be) `false`.
`ResolvedPayment` is the corresponding type internal to the transaction builder that can be either
internal (for change) or external (for user-requested payments).
2023-03-16 19:49:38 -06:00
Jack Grigg 7f35a0da5c Migrate to `zcash_primitives 0.10`
Closes zcash/zcash#6398.
2023-03-17 00:09:45 +00:00
str4d e9e160c7e2
Merge pull request #6474 from str4d/wallet-zcash_note_encryption
Migrate in-wallet Sapling output decryption to `zcash_note_encryption`
2023-03-16 23:19:27 +00:00
Greg Pfeil d90ca22be7
Clarify `AddressResolutionError`
- document and rename the enum cases,
- rewrite some of the exception messages, and
- restructure the UA recipient case.
2023-03-16 17:18:47 -06:00
Greg Pfeil 9f84ce2858
Update WalletTxBuilder based on review
Some of the more significant changes are
- remove release note entry for already-released feature;
- rephrase some error messages and comments;
- add a missing case to `EstimateTxSize`;
- don’t return a selector when we don’t have a UFVK for a UA, which allows some
  simplifications (and elimination of a failure case) to happen; and
- remove a redundant `InsufficientFundsError`.
2023-03-16 13:57:57 -06:00
str4d 207c88474f
Improvements to code comments
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2023-03-15 23:52:09 +00:00
Kris Nuttycombe b1240282d6 Explicitly provide CChainParams to `EnforceNodeDeprecation`
This is another step in the long process of removing access to global
state.
2023-03-14 16:15:30 -06:00
Kris Nuttycombe da0a9c1313 Improve const-ness of CChainParams retrieval by network ID
This change ensures that we do not return non-const CChainParams
references.
2023-03-14 16:15:30 -06:00
Jack Grigg d154cd760c wallet: Remove recipient-side `SaplingNotePlaintext::decrypt`
All recipient-side decryption now relies on `zcash_note_encryption`.
2023-03-14 21:50:31 +00:00
Jack Grigg f5ed454f87 wallet: Use `zcash_note_encryption` in `CWalletTx::RecoverSaplingNote` 2023-03-14 21:50:31 +00:00
Jack Grigg 2fd287e73b wallet: Use `zcash_note_encryption` in `CWallet::FindMySaplingNotes`
This method is only used in tests (as the main wallet scanning logic
already uses `zcash_note_encryption` via the batch scanner).
2023-03-14 21:50:31 +00:00
Jack Grigg f622549929 wallet: Use `CWalletTx::DecryptSaplingNote` in more places 2023-03-14 21:50:31 +00:00
Jack Grigg 95157cd97c wallet: Use `zcash_note_encryption` in `CWalletTx::DecryptSaplingNote` 2023-03-14 21:50:31 +00:00
Jack Grigg db600d5863 wallet: Consolidate `CWalletTx` Sapling output decryption methods
`CWalletTx::DecryptSaplingNote` and `CWalletTx::RecoverSaplingNote` were
previously unused, and the variants that skipped the plaintext version
check were only used by `z_viewtransaction` to inspect details about
transactions that had already been added to the wallet.

We now merge the two back together, and use the activation height of the
Canopy NU as the checked height. This re-checks the plaintext version in
`z_viewtransaction` but permits either valid version.
2023-03-14 21:45:19 +00:00
Jack Grigg a95cd3db09 Add `CChainParams::RustNetwork`
The `zcashd` impl of `consensus::Parameters` is moved into a new
`params` module. It still uses the `cxx::bridge` in `wallet_scanner`
because `cxx` doesn't support Rust type aliases yet.
2023-03-14 21:42:54 +00:00
Kris Nuttycombe 659030aa46
Merge pull request #6460 from daira/generalize-weighted-map
Refactoring to split the weighted tx tree out of mempool_limit.{cpp,h} and make it more reusable
2023-03-14 13:47:48 -06:00