Commit Graph

11430 Commits

Author SHA1 Message Date
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
Kris Nuttycombe 98391a3a92
Merge pull request #6478 from zcash/fix/distclean_rust_gen
Fix `make distclean` to recursively remove `rust/gen`
2023-03-13 17:02:33 -06:00
str4d 8c26d91b28
Merge pull request #6476 from nuttycom/fix/build_warnings
Fix a couple of longstanding zcashd build warnings
2023-03-13 17:51:38 +00:00
Kris Nuttycombe 245f35e034 Fix `make distclean` to recursively remove `rust/gen`
`make distclean` currently fails with:

```
rm -f rust/gen
rm: cannot remove 'rust/gen': Is a directory
make[2]: *** [Makefile:10025: clean-local] Error 1
```
2023-03-13 10:12:01 -06:00
Kris Nuttycombe 228ba99150 Fix a longstanding zcashd build warning
Fixes zcash/zcash#2348
2023-03-13 10:11:26 -06:00
Evan Klitzke 4966b7a221 Fix automake warnings when running autogen.sh
(cherry picked from commit f8c66972ddc2a70f5015497436870e2af6833ecc)
2023-03-13 10:11:26 -06:00
Jack Grigg ce73341951 `s/string/std::string` in `init.cpp`
This was breaking with `--disable-wallet`, likely due to some PR
removing a `using namespace std;` line from a header file that this code
was implicitly depending on.
2023-03-13 15:47:55 +00:00
Jack Grigg f8b3e9489a Move `fEnableAddrTypeField` outside `ENABLE_WALLET`
The deprecated feature was originally only applied to wallet code, but
in zcash/zcash#6282 it was extended to a missing case in non-wallet
code.
2023-03-13 15:46:05 +00:00
Kris Nuttycombe ec88817b72 zcashd release 5.4.2
Notable changes
 ===============
 
 This hotfix remediates memory exhaustion vulnerabilities that zcashd inherited
 as a fork of bitcoind. These bugs could allow an attacker to use peer-to-peer
 messages to fill the memory of a node, resulting in a crash.
 -----BEGIN PGP SIGNATURE-----
 
 iQGzBAABCgAdFiEEX8Nd8pnYcf0pobEL9FXpuSAjoYsFAmP1DKQACgkQ9FXpuSAj
 oYt2jQv+IurleLqEbtBW2ajDYDIkcMu+asEtHCk3B6GELykKaFMgHYTffFBmuyJ+
 5GdoX685Rn6r8BxK6K1u129A9ztY7K0JpVeDA75tN5WLBj9twLdNaODfCLg5EjlZ
 UtxTNnynQ0MX5Uv7pt1DAM+++OKYujUHypaajgZ9ttqpSHZl3Z2ye0/HFEc4023p
 VH13CvU/3R4JLkFENi49rbS49LFfVuQrhAQoOPlCf3xoWbUYIdmWWZa/HOJV3g0e
 3mqC+rhz97GVylLI4LJrm3v0tLeEUIuu+fdAziWfuWrBlB4jQ5p4L5trDHiQoqWB
 5Qt5tjJKHHLnHHSyLcFFaes12tjPfrn9PBxYDPyfFAHIGf0WEiy36+6G5P7jpjYj
 OXLAmBPBIRBgZf9LJIHrgvqQynfGe9vaWgCArWWgSC8wZ2hWlM7pZRhCe+uw35R1
 e5AfZjvbXj6gR+1631Mhl84e6xkGXe24szzuZDrUCqLBJpTb1JNLRh1OtT8zDN0t
 MfKtnE3W
 =AXAQ
 -----END PGP SIGNATURE-----

Merge tag 'v5.4.2' into hotfix-v5.4.2

zcashd release 5.4.2

Notable changes
===============

This hotfix remediates memory exhaustion vulnerabilities that zcashd inherited
as a fork of bitcoind. These bugs could allow an attacker to use peer-to-peer
messages to fill the memory of a node, resulting in a crash.
2023-03-13 06:19:46 -06:00
Kris Nuttycombe 1b2d994a39 zcashd release v5.3.3
Notable changes
 ===============
 
 This hotfix remediates memory exhaustion vulnerabilities that zcashd inherited
 as a fork of bitcoind. These bugs could allow an attacker to use peer-to-peer
 messages to fill the memory of a node, resulting in a crash.
 -----BEGIN PGP SIGNATURE-----
 
 iQGzBAABCgAdFiEEX8Nd8pnYcf0pobEL9FXpuSAjoYsFAmP1CD8ACgkQ9FXpuSAj
 oYvGXQwAqaa1l5qC3VY/60jkH4xmWoSUEzeCOPUG7lYJrIEyzgXj8Ko0Cjr308jm
 ISXDDTOxKb2hfnCbeqbZqRyFbzGzG5L6AkjHAvmQMiZwx2JlbH2k+jd5fggOZSMv
 shL5KbxWN2YRftc8r+fDraJMbGULbKBWQooKaFyQmupT+bVsRf1Nh+lFIVG4FUwA
 oWZot36wB6Y99Y57wlyN2m22+j1glyk5mKv2ttXYbdwSRTFB5W5L1US6Z8uxXQPb
 Qa7sVO90QtzkHr+GPtMiTn513VuLFr+KArGn+qidU/PvblJI/vXuBf54g7JZw4Ot
 gkKziatgaN3pO30I4rTij78LCgKJZ/WImLE7nwTl/bG2Ki1WfyolNLjS+1pXpcPL
 xlXso5ioKlSIGhnlPouXwoxlaqTpDwRKLp0azNJl5hG/tXEHupToK2M61woi9LlP
 4RB+a75OptFi9NMp/Sx0T8zNRn7OB8iP+3BgRP0+mzcLC1AHfjJk/IRo9CQh5jRZ
 MMe98OrC
 =6QYn
 -----END PGP SIGNATURE-----

Merge tag 'v5.3.3' into hotfix-v5.4.2

zcashd release v5.3.3

Notable changes
===============

This hotfix remediates memory exhaustion vulnerabilities that zcashd inherited
as a fork of bitcoind. These bugs could allow an attacker to use peer-to-peer
messages to fill the memory of a node, resulting in a crash.
2023-03-13 06:18:00 -06:00
Daira Emma Hopwood 9d368ba29b Remove unnecessary #include.
Signed-off-by: Daira Emma Hopwood <daira@jacaranda.org>
2023-03-11 00:34:41 +00:00
Daira Hopwood efda29a05d
Another minor optimization
Co-authored-by: Kris Nuttycombe <kris@electriccoin.co>
2023-03-10 23:46:43 +00:00
Daira Hopwood 99d5cdd3fc
This PR doesn't bring in any ZIP 317 changes yet
The new comment text matches the wording in https://zips.z.cash/zip-0401#specification .
2023-03-10 21:47:07 +00:00
Daira Hopwood 7b52813c61
Minor optimization to weighted_map::remove
Co-authored-by: str4d <thestr4d@gmail.com>
2023-03-10 21:45:46 +00:00
Greg Pfeil 37ca96e747
Address comments on WalletTxBuilder introduction 2023-03-09 16:29:15 -07:00
Greg Pfeil 4bf618937e
Don’t pass PrivacyPolicy to selector constructor
This reverts to the `bool` that was used previously. The independent change to use
`TransparentCoinbasePolicy as a parameter type eliminates some of the motivation for this, and there
is a better approach to solving the remaining issues in #6457.
2023-03-09 16:29:15 -07:00
Greg Pfeil fd07935259
Assert that we get a change addr for any selector 2023-03-09 16:29:05 -07:00
Greg Pfeil d44facfa41
Improve GetRequiredPrivacyPolicy
- invert the order of the checks, fold them into a single conditional
- add documentation
- improve an error message
2023-03-09 13:04:17 -07:00
Greg Pfeil a420dd20f9
Remove changes that aren’t needed by z_sendmany
These changes will be applied in later PRs.
2023-03-09 13:04:17 -07:00
Greg Pfeil 96ac6e763e
Rename `Get*Balance` to `Get*Total` 2023-03-09 13:04:17 -07:00
Greg Pfeil 820af47019
Unify requireTransparentCoinbase handling
Eliminates SelectsTransparentCoinbase in favor of a Disallow/Allow/Require ternary. Also asserts if
a selector requires transparent coinbase but doesn’t select transparent.
2023-03-09 13:04:17 -07:00
Greg Pfeil d2d0378943
Apply suggestions from code review
Co-authored-by: Kris Nuttycombe <kris@nutty.land>
Co-authored-by: str4d <thestr4d@gmail.com>
2023-03-09 13:04:17 -07:00
Greg Pfeil 71c0dad1a1
Fix some overly-strict privacy policies in btest
These were introduced earlier in this PR, but they were incorrect.
2023-03-09 13:04:17 -07:00
Greg Pfeil 47f15811d8
Fix weakened privacy policy for transparent change 2023-03-09 13:04:17 -07:00
Greg Pfeil 11721906fd
Ensure we don’t make Orchard change pre-NU5
Co-authored-by: Kris Nuttycombe <kris@nutty.land>
2023-03-09 13:04:17 -07:00
Greg Pfeil c8fed15f19
Refactoring InsufficientFundsError 2023-03-09 13:04:17 -07:00
Greg Pfeil fd6194abe6
Return anchorHeight from ResolveInputsAndPayments 2023-03-09 13:04:17 -07:00
Greg Pfeil c2281f5425
Some orchard fixes for wallet_tx_builder 2023-03-09 13:04:17 -07:00
Greg Pfeil 708c5354b2
Limit UTXOs
Also, don’t get a change addr if there’s no change.
2023-03-09 13:04:17 -07:00
Kris Nuttycombe 010141426d
Allow selectors to require transparent coinbase 2023-03-09 13:04:17 -07:00
Kris Nuttycombe 2bc8713925
Use WalletTxBuilder for z_sendmany 2023-03-09 13:04:16 -07:00
Kris Nuttycombe 78e76f1332
Add a wallet-aware transaction builder.
This factors several pieces out from asyncrpcoperation_sendmany
to form the foundation of a new two-stage transaction construction
process.
2023-03-09 13:03:48 -07:00
Kris Nuttycombe 90e347905e
Merge pull request #6425 from nuttycom/feature/deprecation_info
Add information about deprecated features to `deprecationinfo` results.
2023-03-09 12:56:00 -07:00
Kris Nuttycombe 9b17b45da5 Apply suggestions from code review
Co-authored-by: str4d <thestr4d@gmail.com>
2023-03-09 10:39:13 -07:00
Kris Nuttycombe 0d8118b1ed Add information about deprecated features to `deprecationinfo` results.
Fixes #6422
2023-03-09 10:33:29 -07:00
Greg Pfeil ad42a6e7aa
Merge pull request #6463 from sellout/ufvk-simplification
Simplify diversifier_index_t handling
2023-03-09 10:08:50 -07:00
Greg Pfeil 45c4568a7e
Simplify diversifier_index_t handling
- Remove `std::optional` from a number of uses,
- simplify `GetUFVKMetadataForAddress` to `GetUFVKIdForAddress`, and
- add a new `GetUFVKMetadataForAddress` as a wrapper around
  `GetUFVKMetadataForReceiver`.
2023-03-08 18:14:08 -07:00
Daira Hopwood 16099d66b6 Refactoring to split the weighted tx tree out of mempool_limit.{cpp,h}
and make it more reusable.

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2023-03-08 16:03:34 +00:00
Greg Pfeil 8c41fbcc85
Make pool selection order more flexible
Previously, all pools had to be listed in the selection order. This had a few problems
- if a pool was missing from selection, we’d `assert`
- a logic error could result in note selection from pools that we thought were not needed for
  selection (and thus might subvert our strategy re: hiding sender, fewer pools, opportunistic
  shielding, etc.)

Now, we only include pools that are intended to be part of the selection order, and all notes from
other pools are cleared before we do any selection.
2023-03-07 18:31:59 -07:00
Marius Kjærstad cdfa020658
Update estimated number of transactions due to Blossom NU
Update estimated number of transactions due to Blossom NU

Co-authored-by: str4d <thestr4d@gmail.com>
2023-03-07 19:47:17 +01:00
Marius Kjærstad 9419a9bde8
New checkpoint at block 2000000 for mainnet
New checkpoint at block 2000000 for mainnet
2023-02-28 17:57:35 +01:00
str4d 5829feed10
Merge pull request #6434 from softminus/better-errors
Give better error messages if proof parameters aren't loaded
2023-02-22 15:36:39 +00:00
Kris Nuttycombe cf33607665 make-release.py: Versioning changes for 5.4.2. 2023-02-20 19:55:37 -07:00
Kris Nuttycombe 10ba5f12ff Merge commit '1478dc1e7f1ccd89bac76fc738650877fbfd1422' into hotfix-5.4.2 2023-02-20 19:52:21 -07:00
Kris Nuttycombe 6fe1b5e595 make-release.py: Versioning changes for 5.3.3. 2023-02-20 19:43:45 -07:00
Kris Nuttycombe 2c85dd9598 Merge remote-tracking branch '22387-backport' into hotfix-5.3.3 2023-02-20 19:33:18 -07:00
Kris Nuttycombe 169e890f1e Merge remote-tracking branch 'trim-cnode' into hotfix-5.3.3 2023-02-20 19:30:48 -07:00
Daira Hopwood 074e633798 Improve the encapsulation of `CNode::filterInventoryKnown`.
Co-authored-by: Jack Grigg <jack@z.cash>
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2023-02-20 23:39:20 +00:00
Daira Hopwood c5b8807ce7 Ensure that CNode::{addrKnown, filterInventoryKnown} immediately take
little memory when we disconnect the node.

Co-authored-by: Kris Nuttycombe <kris@nutty.land>
Co-authored-by: Jack Grigg <str4d@z.cash>
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2023-02-20 20:14:55 +00:00
Daira Hopwood 0a39cc6727 Enable a CRollingBloomFilter to be reset to a state where it takes little memory.
Co-authored-by: Jack Grigg <jack@z.cash>
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2023-02-20 18:32:46 +00:00
Jon Atack 9555b5e8a4 p2p, rpc, test: address rate-limiting follow-ups
(cherry picked from commit bitcoin/bitcoin@d930c7f5b0)
2023-02-17 17:54:39 -07:00
Pieter Wuille 1dddc1337c Add logging and addr rate limiting statistics
Includes logging improvements by Vasil Dimov and John Newbery.

(cherry picked from commit bitcoin/bitcoin@f424d601e1)
2023-02-17 16:47:47 -07:00
Pieter Wuille c8cdfcffd0 Randomize the order of addr processing
(cherry picked from commit bitcoin/bitcoin@5648138f59)
2023-02-17 16:47:37 -07:00
Greg Pfeil 2c48eddfa5
Remove `ResetRequestCount`
There is no longer any `mapRequestCount` to reset.

This also removes the `BlockFound` signal, as its only purpose was to call
`ResetRequestCount`.
2023-02-17 15:45:29 -07:00
Pieter Wuille 7c739e2b20 Rate limit the processing of incoming addr messages
While limitations on the influence of attackers on addrman already
exist (affected buckets are restricted to a subset based on incoming
IP / network group), there is no reason to permit them to let them
feed us addresses at more than a multiple of the normal network
rate.

This commit introduces a "token bucket" rate limiter for the
processing of addresses in incoming ADDR and ADDRV2 messages.
Every connection gets an associated token bucket. Processing an
address in an ADDR or ADDRV2 message from non-whitelisted peers
consumes a token from the bucket. If the bucket is empty, the
address is ignored (it is not forwarded or processed). The token
counter increases at a rate of 0.1 tokens per second, and will
accrue up to a maximum of 1000 tokens (the maximum we accept in a
single ADDR or ADDRV2). When a GETADDR is sent to a peer, it
immediately gets 1000 additional tokens, as we actively desire many
addresses from such peers (this may temporarily cause the token
count to exceed 1000).

The rate limit of 0.1 addr/s was chosen based on observation of
honest nodes on the network. Activity in general from most nodes
is either 0, or up to a maximum around 0.025 addr/s for recent
Bitcoin Core nodes. A few (self-identified, through subver) crawler
nodes occasionally exceed 0.1 addr/s.

(cherry-picked from commit bitcoin/bitcoin@0d64b8f709)
2023-02-17 14:36:25 -07:00
Matt Corallo aa88e23f6b
Remove useless mapRequest tracking that just effects Qt display.
I thought we had removed this a long time ago, TBH, its really
confusing feedback to users that we display whether a tx was
broadcast to immediate neighbor nodes, given that has little
indication of whether the tx propagated very far.
2023-02-17 14:04:37 -07:00
sasha 0d2d64ee43 Better error messages if proof parameters aren't loaded 2023-02-16 13:51:27 -08:00
Jack Grigg d3a88bc332 Fix 1.67.1 clippy lints 2023-02-16 16:10:13 +00:00
Kris Nuttycombe b92c6de29f Remove `FakeCoinsViewDB` as it is identical to `CCoinsViewDummy` 2023-02-15 15:05:03 -07:00
Kris Nuttycombe cc2fd60617 Make all CCoinsView methods pure-virtual. 2023-02-15 13:58:46 -07:00
Kris Nuttycombe 0b9f76c36c
Merge pull request #6430 from zcash/hotfix-v5.4.1
Back-merge of hotfix-v5.4.1
2023-02-13 16:24:30 -07:00
Jack Grigg fc6ddfa605 make-release.py: Versioning changes for 5.4.1. 2023-02-13 18:06:28 +00:00
Kris Nuttycombe 97aa2b9442
Merge pull request #6423 from str4d/6420-allowdeprecated-in-config-file
Load `-allowdeprecated` settings after reading the config file
2023-02-10 17:53:20 -07:00
Kris Nuttycombe cb22267fa3
Merge pull request #6399 from str4d/6396-retroactive-zip-216
Retroactively enable ZIP 216 before NU5 activation
2023-02-10 17:36:11 -07:00
Kris Nuttycombe 8707a8e9f5
Merge pull request #6424 from str4d/sideport-reindex-lock-contention-fix-5.4.1
Sleep for 200µs before each `ActivateBestChainStep` call
2023-02-10 15:40:51 -07:00
Jack Grigg b814336aec Load `-allowdeprecated` settings after reading the config file
We need to load these early so that it's possible for other
initialization steps to respect them. However, we were loading them
slightly too early, before the config file had been read, which meant
that only CLI arguments were being used.

We now load the `-allowdeprecated` settings just after the config file
is parsed and the chain parameters are prepared; neither of these are
features we would ever consider deprecating (at least while `zcashd`
exists in its Bitcoin Core-derived form).

Closes zcash/zcash#6420.
2023-02-10 22:14:10 +00:00
Kris Nuttycombe af4994c1ae
Merge pull request #6414 from zcash/version-5.4.0 2023-02-08 15:28:18 -07:00
Jack Grigg 4cb8973c22 make-release.py: Versioning changes for 5.4.0. 2023-02-08 17:07:58 +00:00
str4d 8b8fcddffa
Merge pull request #6406 from str4d/lower-reindex-lock-contention
Sleep for 200µs before each ActivateBestChainStep call
2023-02-07 20:36:17 +00:00
str4d 048af2d7a3
Adjust documentation of 200µs sleep
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2023-02-07 19:08:59 +00:00
Jack Grigg e2cd1b761f Sleep for 200us before each ActivateBestChainStep call
This should lower the main thread's likelihood to immediately reacquire
cs_main after dropping it, which should help ThreadNotifyWallets and the
RPC methods to acquire cs_main more quickly.

Co-authored-by: Daira Hopwood <daira@jacaranda.org>
Co-authored-by: Kris Nuttycombe <kris@nutty.land>
2023-02-03 23:12:28 +00:00
Jack Grigg 9ce6753909 Retroactively enable ZIP 216 before NU5 activation
This completes the work started in zcash/zcash#6000.

Closes zcash/zcash#6396.
2023-02-02 22:48:00 +00:00
Charlie O'Keefe 251432966f
Merge pull request #6401 from nuttycom/version-5.4.0-back_merge
Back-merge version-5.4.0 changes to `master`.
2023-02-02 15:36:12 -07:00
Charlie O'Keefe b7d613b6ca
Merge pull request #6313 from str4d/6309-backport-blockassembler
Backport `BlockAssembler` class
2023-02-02 15:33:45 -07:00
Jack Grigg f789229a33 CreateNewBlock: Leave more space for Orchard shielded coinbase 2023-02-02 21:47:16 +00:00
Kris Nuttycombe 6ae749d4d9 make-release.py: Versioning changes for 5.4.0-rc4. 2023-02-01 17:35:05 -07:00
Kris Nuttycombe db0d0deef8
Merge pull request #6385 from rex4539/typos
Fix typo
2023-02-01 07:02:58 -07:00
Kris Nuttycombe 192804a081 Merge branch 'version-5.4.0' into 'master' 2023-01-30 21:19:54 -07:00
Jack Grigg 204950191c Reset Orchard wallet state in `CWallet::ClearNoteWitnessCache`
The general invariant in the wallet is that `CWallet::ChainTip` is only
called with sequential (either connecting or disconnecting) blocks. The
one exception to this is when starting `zcashd` with `-reindex`, which
creates a discontinuity: the node jumps back to the genesis block, and
`ThreadNotifyWallets` will similarly start notifying the wallet of the
entire chain again.

In Bitcoin Core, this behaviour was fine: there was no persistent cached
state that couldn't just be overwritten during the re-notification. For
Zcash however, wallets need to additionally maintain witnesses for notes
that are spendable, and these witnesses can generally only be amended by
sequential blocks.

For Sprout and Sapling, the discontinuity was handled by checking if a
reindex was occurring during `CWallet::InitLoadWallet`, and clearing the
witness caches in `CWallet::ClearNoteWitnessCache` if so. The witnesses
would then be rebuilt as the reindexed chain was re-connected during
`ActivateBestChain`.

The Orchard wallet stores its witnesses in a different structure on the
Rust side, so it wasn't being cleared at the same time. This meant that
when a full reindex was performed in one go, the sequentiality invariant
would be broken once `ThreadNotifyWallets` reached NU5 activation, and
the node would crash with a failed assertion (the issue at hand).

However, reindexing Zcash takes a long time, and has been historically
buggy for various reasons (e.g. crashing due to OOM). And due to a quirk
of how the `-rescan` behaviour is implemented, if a reindexing node is
restarted during its `ActivateBestChain` phase, on restart the node will
almost always trigger a rescan due to the wallet chain locator not
containing any hashes that match the on-start chain tip. And the first
thing that the rescan logic does is check whether the start of the
rescan is before NU5 activation, and reset the Orchard wallet if so.

We now reset the Orchard wallet unconditionally at the same time as we
clear the Sprout and Sapling witness caches. This additionally clears
spentness information that the Orchard wallet is storing, but that is
rebuilt during the reindex.

Closes zcash/zcash#5736.
Closes zcash/zcash#6004.
2023-01-31 00:28:30 +00:00
Jack Grigg 0d1e1ad438 Fix return type of `orchard_wallet_reset`
Part of zcash/zcash#6386.
2023-01-31 00:28:30 +00:00
Dimitris Apostolou 4464f81061
Fix typo 2023-01-31 00:26:47 +02:00
Alex Morcos 05a1c41aac FIX: correctly measure size of priority block
(cherry picked from commit bitcoin/bitcoin@c2dd5a3c39)
2023-01-30 21:59:42 +00:00
Alex Morcos 43ce65399c FIX: Account for txs already added to block in addPriorityTxs
(cherry picked from commit bitcoin/bitcoin@a278764748)
2023-01-30 21:59:42 +00:00
Alex Morcos e6d4027888 Refactor CreateNewBlock to be a method of the BlockAssembler class
(cherry picked from commit bitcoin/bitcoin@4dc94d1036)

Zcash: Adapted to include our miner changes.
2023-01-30 21:59:42 +00:00
Kris Nuttycombe c9d6230e88 Defer z_getbalance and z_gettotalbalance disablement.
These disable-by-default changes need to be deferred until we
have a better replacement that provides a single source for
summary balance information.
2023-01-30 11:00:09 -07:00
Kris Nuttycombe 6e8404e9b3 make-release.py: Versioning changes for 5.4.0-rc3. 2023-01-27 15:03:29 -07:00
Daira Hopwood 88a57f3617
Merge pull request #6368 from nuttycom/bug/slow_wallet_shutdown
Fetch recently conflicted transactions incrementally in ThreadNotifyWallet
2023-01-27 21:23:47 +00:00
Kris Nuttycombe 29e65bf536 Tolerate missing cached conflict data in ThreadNotifyWallets 2023-01-26 16:51:23 -07:00
Kris Nuttycombe 887b2688df Remove unused DEFAULT_BATCHSCANNERMEMLIMIT constant. 2023-01-26 12:33:55 -07:00
Kris Nuttycombe aab58d308f Bound wallet batch scanner size to 1000 blocks instead of 100 MiB
1000 blocks was selected as a balance between limiting the likely
maximum memory usage of the batch scanner, and avoiding
artificially restricting scanning throughput of small/fast blocks
due to the second-boundary lock synchronization point.

This also removes the `zcashd.wallet.batchscanner.usage.bytes` gague
value that was previously made available when `-prometheusport` was
specified.

Co-authored-by: Jack Grigg <jack@z.cash>
2023-01-26 12:26:31 -07:00
Kris Nuttycombe ce694802d9 Fetch recently conflicted transactions incrementally in ThreadNotifyWallet.
We no longer fetch updates from the mempool unless we have fetched all
updates from the chain, as we would otherwise notify the wallet of
mempool changes for which they have not observed parent transactions
in the chain.

Co-authored-by: Jack Grigg <jack@z.cash>
2023-01-26 12:26:31 -07:00
Kris Nuttycombe 3b17b77f3d Allow rescan to exit in the case that Ctrl-C is pressed.
Wallet rescanning that happens on node startup was previously not
respecting Ctrl-C. We use an explicit check of `ShutdownRequested()`
instead of a `boost::interruption_point` because wallet startup does
not run in a separate thread.

Co-authored-by: Jack Grigg <jack@z.cash>
2023-01-26 11:43:54 -07:00
Kris Nuttycombe 25c62d804a Fixes an error in `zcash-cli help` following the removal of `dumpwallet`. 2023-01-25 16:57:29 -07:00
Jack Grigg 817276c02f rust: Migrate `OrchardMerkleFrontier` to `cxx`
Closes zcash/zcash#6333.
2023-01-24 21:04:48 +00:00
Jack Grigg 908675b5b9 rust: Add `cxx` version of `RustStream` 2023-01-24 04:15:09 +00:00
Jack Grigg ae7c2c742d make-release.py: Versioning changes for 5.4.0-rc2. 2023-01-24 02:13:05 +00:00
Jack Grigg 5b74dbfddd metrics: Update `zcash.pool.value.zatoshis` gauge for transparent pool 2023-01-24 02:13:05 +00:00
str4d d6e2fada84
Merge pull request #6362 from nuttycom/issue2921-fix-copyright-headers
Replace fix-copyright-headers.py with a script that creates a scripted-diff git commit.
2023-01-23 22:13:05 +00:00
str4d 0e931a9397
Merge pull request #4470 from oxarbitrage/issue4294
Add transparent value pool to RPC calls
2023-01-23 21:55:00 +00:00
Kris Nuttycombe 0f886c32fe Apply suggestions from code review
Co-authored-by: str4d <thestr4d@gmail.com>
2023-01-23 13:23:20 -07:00
Kris Nuttycombe 3cec519ce4 scripted-diff: Update Zcash copyrights to 2023
-BEGIN VERIFY SCRIPT-
for party in "The Zcash developers" "The Bitcoin Core developers" "Bitcoin Developers"; do
  sed -i"" -e "s#Copyright (c) \([0-9]\{4\}\)\(-[0-9]\{4\}\)\? $party#Copyright (c) \1-2023 $party#" COPYING
  sed -i"" -e "s#\(.*\)\([0-9]\{4\}\)\(-[0-9]\{4\}\)\, $party#\1\2-2023, $party#" contrib/debian/copyright
done

sed -i"" -e "s/define(_COPYRIGHT_YEAR, [0-9]\{4\})/define(_COPYRIGHT_YEAR, 2023)/" configure.ac
sed -i"" -e "s/#define COPYRIGHT_YEAR [0-9]\{4\}/#define COPYRIGHT_YEAR 2023/" src/clientversion.h

git grep "^// Copyright (c) .* The Zcash developers" \
  | awk -F ':' '{print $1}' \
  | xargs -I {} sed -i"" -e "s#// Copyright (c) \([0-9]\{4\}\)\(-[0-9]\{4\}\)\? The Zcash developers#// Copyright (c) \1-2023 The Zcash developers#" {}
-END VERIFY SCRIPT-
2023-01-23 11:31:54 -07:00
Kris Nuttycombe 193b22b754 Apply suggestions from code review
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2023-01-22 11:33:23 -07:00
Kris Nuttycombe 2fd52ada51 Apply suggestions from code review
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2023-01-22 09:10:03 -07:00
Kris Nuttycombe aa78fc0878 Verify sum of pool balances against chain total supply.
Co-authored-by: Jack Grigg <jack@z.cash>
2023-01-22 09:10:03 -07:00
Alfredo Garcia 486817498f Add chain supply and transparent value to block index.
Co-authored-by: Jack Grigg <jack@z.cash>
Co-authored-by: Kris Nuttycombe <kris@nutty.land>
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2023-01-22 09:10:03 -07:00
Jack Grigg 072fc26e3e make-release.py: Versioning changes for 5.4.0-rc1. 2023-01-19 22:50:16 +00:00
instagibbs 4bb399a8f5 Corrected values
(cherry picked from commit bitcoin/bitcoin@f8536a62c3)
2023-01-19 21:49:14 +00:00
instagibbs bbf4f8b6e9 Gave miner test values constants for less error-prone values.
(cherry picked from commit bitcoin/bitcoin@617deeb06e)

Zcash: Adapted to mining slow start.
2023-01-19 21:49:13 +00:00
Suhas Daftuar 9d04148414 Add tags to mempool's mapTx indices
(cherry picked from commit bitcoin/bitcoin@086da92ea7)
2023-01-19 21:49:13 +00:00
str4d 9e1efad2d1
Merge pull request #6312 from str4d/6308-backport-6898
Backport `CreateNewBlock` rewrite
2023-01-19 21:47:20 +00:00
str4d 6ec042dd51
Merge pull request #6343 from rex4539/typos
Fix typos
2023-01-18 23:22:44 +00:00
str4d 8bc5740003
Merge pull request #6348 from str4d/update-deps-5.4.0
Update dependencies for 5.4.0 and fix some help messages
2023-01-13 16:18:10 +00:00
Jack Grigg 7e42041772 Document -clockoffset option 2023-01-13 00:43:46 +00:00