Commit Graph

9167 Commits

Author SHA1 Message Date
Kris Nuttycombe 92cec200ee Minor fixes for ZIP-207 review comments. 2020-06-29 16:13:08 -06:00
Kris Nuttycombe 074d054e84
Trivial error message fix.
Co-authored-by: str4d <thestr4d@gmail.com>
2020-06-29 15:54:07 -06:00
Kris Nuttycombe 665b8c647b
Use for..: rather than BOOST_FOREACH
Co-authored-by: str4d <thestr4d@gmail.com>
2020-06-29 15:53:41 -06:00
Kris Nuttycombe 1c00a0b541
Identify `-fundingstream` parameter as being regtest-only
Co-authored-by: str4d <thestr4d@gmail.com>
2020-06-29 15:42:45 -06:00
Sean Bowe e9c065df5b
Cargo fmt 2020-06-29 09:40:35 -06:00
Sean Bowe 8918eca876
Add more exhaustive tests for ZIP 215 compatibility. 2020-06-29 09:40:34 -06:00
Sean Bowe 58250b4801
Turn return values for libsodium-like API into constants for clarity. 2020-06-29 09:36:54 -06:00
Jack Grigg efd04b920b Implement zip-207 and zip-214.
Add funding streams to consensus parameters.

Add funding stream payments to coinbase txns generated by the miner.
* Reduce valueBalance for shielded outputs to funding streams.
* Ensure we produce binding signatures in any case where shielded
  outputs go to either a funding stream or the miner.
2020-06-25 16:15:50 -06:00
Larry Ruane 73fae6bf0a review, cleanup: eliminate uninitialized variable 2020-06-25 09:32:36 -06:00
therealyingtong 7a1d119170 Add gtests for v2 plaintexts 2020-06-25 09:12:24 +08:00
therealyingtong 6402c589c6 Refactor SaplingNotePlaintext::decrypt
Break up plaintext decryption into height-dependent and non-height-dependent parts.
2020-06-25 09:12:24 +08:00
therealyingtong 3c8e970358 Check epk vs esk whenever caller has esk 2020-06-25 09:12:24 +08:00
therealyingtong e060d59890 Reject v1 plaintexts after grace period
SaplingNotePlaintext::decrypt() now has to be aware of consensus params and blockheight. Its callers in wallet, rpcwallet, and tests are updated accordingly.

TransactionBuilder is also modified to reject invalid leadBytes.

Co-authored by Daira Hopwood (daira@jacaranda.org)
2020-06-25 09:12:21 +08:00
Sean Bowe 56d4ef8333 Make transaction builder take the next block height into account for use of v2 note plaintexts. 2020-06-25 09:11:43 +08:00
Sean Bowe 4af761121d Require that shielded coinbase output note plaintexts are version 2 if Canopy is active.
Co-authored by Ying Tong (yingtong@electriccoin.co)
2020-06-25 09:11:31 +08:00
Homu ab2b7c0969 Auto merge of #4566 - gtank:new_seeders, r=ebfull
Add Foundation's and gtank's DNS seeders

This adds our new DNS seeders to the list. They're running [CoreDNS](https://coredns.io) with a [Zcash crawler plugin](https://github.com/ZcashFoundation/dnsseeder), the result of a Zcash Foundation in-house development effort to replace zcash-seeder with something memory safe and easier to maintain.

These are validly operated seeders per the existing policy (https://zcash.readthedocs.io/en/latest/rtd_pages/dnsseed_policy.html):

> A DNS seed operating organization or person is expected to follow good host security practices, maintain control of applicable infrastructure, and not sell or transfer control of the DNS seed. Any hosting services contracted by the operator are equally expected to uphold these expectations.

In both cases the code is running on well-operated public cloud infrastructure in either a container or the most sandboxing appropriate to the environment. The DNS records pointing to the seeders are controlled by reputable third-party DNS providers under accounts with 2FA enabled.

> The DNS seed results must consist exclusively of fairly selected and functioning Zcash nodes from the public network to the best of the operator’s understanding and capability.

The crawler attempts to connect to all discoverable Zcash peers and ensures their continued uptime on a regular basis. The results are always a uniformly randomized subset of all known live peers.

> For the avoidance of doubt, the results may be randomized but must not single out any group of hosts to receive different results unless due to an urgent technical necessity and disclosed.

See above. However, we reserve the right to begin offering [NU-targeted results](https://github.com/ZcashFoundation/dnsseeder/issues/3) based on opt-in client queries.

> The results may not be served with a DNS TTL of less than one minute.

Mainnet results are served with a TTL of 600 seconds, and Testnet results with a TTL of 300 seconds to account for greater flux on that network.

> Any logging of DNS queries should be only that which is necessary for the operation of the service or urgent health of the Zcash network and must not be retained longer than necessary nor disclosed to any third party.

There is no logging of DNS queries in either production configuration, which can be somewhat confirmed by examining the Corefile(s) [[1]](https://github.com/ZcashFoundation/coredns-zcash/blob/master/coredns/Corefile)[[2]](https://github.com/ZcashFoundation/coredns-zcash/blob/master/scripts/gcp-start.sh#L9-L27) we use.

> Information gathered as a result of the operators node-spidering (not from DNS queries) may be freely published or retained, but only if this data was not made more complete by biasing node connectivity (a violation of expectation (1)).

The seeder currently has no persistence outside of its static config file, so this data is neither retained nor shared by the operators.

> Operators are encouraged, but not required, to publicly document the details of their operating practices.

Our deployments are described in detail by the [coredns-zcash](https://github.com/ZcashFoundation/coredns-zcash) repo. Reader, you could run one too!

> A reachable email contact address must be published for inquiries related to the DNS seed operation.

For general questions related to either seeder, contact george@zfnd.org or mention @gtank in the Foundation's Discord. For bug reports, open an issue on the [dnsseeder](https://github.com/ZcashFoundation/dnsseeder) repo.
2020-06-25 00:44:33 +00:00
Larry Ruane 0219a97139 flush witness cache correctly
Rather than flushing the witness cache from FlushStateToDisk(), called
by ActivateBestChain() called by ProcessNewBlock(), do so from
ThreadNotifyWallets() after the wallet has updated the in-memory witness
data according to the new block, so it's always consistent on disk.
2020-06-24 16:49:59 -06:00
Sean Bowe f29c731915
Minor adjustments to librustzcash and tests. 2020-06-23 16:35:19 -06:00
Sean Bowe ba04450945
Remove unused curve25519-dalek dev-dependency. 2020-06-23 16:29:51 -06:00
Sean Bowe 14bdf7e811
Remove bincode crate. 2020-06-23 15:38:59 -06:00
Sean Bowe 2a3527bfe8
Add test that a weird signature successfully validates. 2020-06-23 14:31:41 -06:00
Sean Bowe 3251bea45a
Enforce ZIP 215 rules upon activation of Canopy. 2020-06-23 13:17:29 -06:00
Daira Hopwood 76c416d2df Remove an unused CCriticalSection.
The code that used this was removed in 5f84491d82.

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2020-06-23 19:38:29 +01:00
Sean Bowe 3688f508d8
Make ed25519-zebra available via librustzcash. 2020-06-22 15:58:26 -06:00
Sean Bowe bf9baf2cb6 Change transaction builder and miner to use v2 Sapling note plaintexts after Canopy activates.
Co-authored by Ying Tong (yingtong@electriccoin.co)
2020-06-18 15:51:34 +08:00
Sean Bowe 8770a5c532 Add support for receiving v2 Sapling note plaintexts.
Co-authored by Ying Tong (yingtong@electriccoin.co)
2020-06-18 15:02:50 +08:00
Sean Bowe e71d2fba9d
Add a getter method to obtain rcm from a Sapling note plaintext. 2020-06-17 13:18:20 -06:00
Sean Bowe 1c2c6be872
Remove bare SaplingNote constructor. 2020-06-17 11:36:35 -06:00
Sean Bowe 6581970d59
Add implementations of PRF_expand calls that obtain esk and rcm. 2020-06-17 10:59:48 -06:00
George Tankersley 27b8a616de Add ZF and gtank's DNS seeders 2020-06-10 21:10:43 -04:00
Homu 4ffccda774 Auto merge of #4322 - oxarbitrage:issue3740, r=str4d
Add -debuglogfile option

Cherry-picked from https://github.com/bitcoin/bitcoin/pull/11781.
Closes https://github.com/zcash/zcash/issues/3740.
2020-06-04 00:40:45 +00:00
Homu e9a6d7926b Auto merge of #4282 - oxarbitrage:issue2375, r=daira
Add a flag to get amount results as integer

Closes https://github.com/zcash/zcash/issues/2375
2020-06-03 11:26:00 +00:00
Alfredo Garcia 916351be04
fix/improve docs
Co-authored-by: str4d <thestr4d@gmail.com>
2020-06-02 09:14:50 -03:00
Homu 7275bc7f3f Auto merge of #4545 - str4d:metrics-ibd-progress-bar, r=str4d
metrics: Add a progress bar when in Initial Block Download mode

The progress bar shows both headers (in green) and blocks (in white / inverse of background colour). It is only printed for TTY output.

Additionally, the "not mining" message is no longer shown on mainnet, as the built-in CPU miner is not effective at the current network difficulty.
2020-06-02 03:01:51 +00:00
Jack Grigg 12e169d09f metrics: Only print IBD progress bar on TTY
Now that it is created from space characters, it is meaningless to print
it to a log file.
2020-06-02 14:23:03 +12:00
Jack Grigg a79337c3ee metrics: Switch to ANSI colour codes for progress bar
We already assume that ANSI colour codes work for the metrics art,
whereas the block characters have inconsistent support in fonts.
2020-06-02 14:20:55 +12:00
Alfredo Garcia 74039434a8
initialize size_t 2020-06-01 09:47:02 -03:00
Alfredo Garcia 93afebeef4 add new parameters to rpc client and fix some bugs 2020-05-30 12:18:43 -03:00
Alfredo Garcia e7c829aa0e update docs 2020-05-30 10:34:03 -03:00
Alfredo Garcia 3b9bd2da2f fix sort of options 2020-05-28 10:58:04 -03:00
Wladimir J. van der Laan 540cdb34e2 Add `-debuglogfile` option
This patch adds an option to configure the name and/or directory of the
debug log.

The user can specify either a relative path, in which case the path
is relative to the data directory. They can also specify an absolute
path to put the log anywhere else in the file system.
2020-05-28 10:53:58 -03:00
Daira Hopwood c1227ae67c Rename NU4 to Canopy in constant and function names.
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2020-05-28 13:11:48 +01:00
Jack Grigg 96681695c9 metrics: Don't show "not mining" text for mainnet
Mining with the zcashd built-in CPU miner is not useful work on mainnet
at the current network difficulty.
2020-05-28 22:21:40 +12:00
Jack Grigg eb4ada98d2 metrics: Draw IBD progress bar showing headers and blocks 2020-05-28 22:21:40 +12:00
Jack Grigg 3a1b1a2fa2 metrics: Fix indents 2020-05-28 22:21:40 +12:00
Homu 68d25c9259 Auto merge of #3936 - solardiz:report-headers-download, r=str4d
Report headers download

With current compile-time defaults, a Zcash node prefetches up to 160 block headers per request without a limit on how far it can prefetch, but only up to 16 full blocks at a time. For this and other reasons, it can get very far ahead in headers prefetch (and PoW verification on those, so it's quite some processing too) over full blocks fetch (such as 10x ahead) during initial blocks download. Let's report to the user on how many headers the node has fetched, and let's also use this information as additional input on estimating the total number of blocks to fetch: it can't be less than the number of headers already fetched.

While at it, also fix typos in related code.
2020-05-28 09:08:44 +00:00
Solar Designer fad004114a During initial blocks download, also report the number of headers 2020-05-28 20:34:31 +12:00
Solar Designer ed3b473ec6 Fix typos in ProcessMessage() "headers" 2020-05-28 20:26:00 +12:00
Homu 804125cc20 Auto merge of #4543 - defuse:fix-invalid-argument, r=str4d
Add missing <stdexcept> header for std::invalid_argument

Closes #1703.
2020-05-28 08:06:06 +00:00
Homu 9bf8443c16 Auto merge of #4504 - str4d:disconnectblock-fixes, r=str4d
Use the cached consensusBranchId in DisconnectBlock

If a node is started with a set of network upgrades that don't match the
serialized chain (such as when we implement NU rollbacks on testnet),
RewindBlockIndex will disconnect each block in the chain until it
reaches the most recent block that agrees with the node's set of network
upgrades. However, the blocks themselves should be disconnected using
the consensus branch ID that they were connected with, which is
persisted alongside the chain and reconstructed in LoadBlockIndex.
2020-05-28 02:51:34 +00:00
Homu 4907a31302 Auto merge of #4242 - oxarbitrage:issue3726, r=str4d
Add estimatedheight to rpc getblockchaininfo response

Fixes https://github.com/zcash/zcash/issues/3726

Ported from https://github.com/zcash/zcash/pull/3727 with comments addressed.
2020-05-28 00:49:49 +00:00
Homu 72edd11bd9 Auto merge of #4486 - defuse:fix-undefined-behavior-in-gtest, r=daira
Fix undefined behavior in gtest tests
2020-05-27 23:47:58 +00:00
Jack Grigg 27b2ce3468 Use the cached consensusBranchId in DisconnectBlock
If a node is started with a set of network upgrades that don't match the
serialized chain (such as when we implement NU rollbacks on testnet),
RewindBlockIndex will disconnect each block in the chain until it
reaches the most recent block that agrees with the node's set of network
upgrades. However, the blocks themselves should be disconnected using
the consensus branch ID that they were connected with, which is
persisted alongside the chain and reconstructed in LoadBlockIndex.
2020-05-28 09:50:08 +12:00
Homu 8c778c9c0d Auto merge of #4527 - dannywillems:librustzcash/c-header-compatibility, r=str4d
librustzcash: make the header C compatible

The `librustzcash.h` file is compatible with both languages. However, only C++ is supported at the moment. By relying on the preprocessor to include or not the `extern "C"` piece, the interface becomes compatible with both.
2020-05-27 21:23:08 +00:00
Taylor Hornby 08662fa09a Add missing <stdexcept> header for std::invalid_argument 2020-05-24 16:49:13 -06:00
Sean Bowe 306a336a0a
make-release.py: Versioning changes for 3.0.0. 2020-05-22 11:46:19 -06:00
Sean Bowe 61aee9ec9c
Set deprecation of 3.0.0 to target EOS halt mid-September. 2020-05-21 07:35:09 -06:00
Sean Bowe 7000f452fa
make-release.py: Versioning changes for 3.0.0-rc1. 2020-05-21 07:32:25 -06:00
Homu 3860e7cae7 Auto merge of #4533 - ebfull:heartwood-activation, r=ebfull
Enable Heartwood activation on mainnet

This sets the Heartwood activation height to `903000`, which follows the deprecation height of `v2.1.2-3` (which is set to deprecate on block `901475`, roughly 31 hours earlier, sometime mid-July).
2020-05-20 21:36:27 +00:00
Homu bfb1bfd9d6 Auto merge of #4534 - ebfull:fix-chainwork, r=daira
Update minimum chain work on testnet to reflect Heartwood activation.
2020-05-20 06:45:44 +00:00
Sean Bowe 5a955674a5
Bump the protocol version, as this node supports Heartwood on mainnet. 2020-05-19 14:38:53 -06:00
Sean Bowe d0c96683bf
Set the Heartwood activation height to 903000. 2020-05-19 14:38:49 -06:00
Homu ed9537f9dd Auto merge of #4529 - daira:fix-abort-on-reindex, r=daira
Fix a null pointer dereference that occurs when formatting an error message

This fixes a bug in the error message printout for the case when we have sufficient chain work, but an expected network upgrade has not activated.
2020-05-19 19:33:31 +00:00
Daira Hopwood cb7c90522d Explicitly assert that chainActive[upgrade.nActivationHeight] is non-null at this point.
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2020-05-19 20:13:37 +01:00
Alfredo Garcia 1805466d5c add MINOR_CURRENCY_UNIT 2020-05-18 16:53:01 -03:00
Alfredo Garcia 507e1623f9 simplify inzat balances logic
Co-Authored-By: Daira Hopwood <daira@jacaranda.org>
2020-05-18 16:53:01 -03:00
Alfredo Garcia 25f48c21dd add amountZat field to z_listreceivedbyaddress 2020-05-18 16:53:01 -03:00
Alfredo Garcia 76e7f21d4a add amountZat field to listunspent 2020-05-18 16:52:04 -03:00
Alfredo Garcia 9a55c8b238 add amountZat field to listtransactions, gettransaction and listsinceblock 2020-05-18 16:51:24 -03:00
Alfredo Garcia 2ec9ac3c81 add amountZat field to listreceivedbyaddress and listreceivedbyaccount 2020-05-18 16:49:39 -03:00
Alfredo Garcia 306270911e add boolean inZat to z_getbalance 2020-05-18 16:47:17 -03:00
Alfredo Garcia 50372cab62 add boolean inZat to getbalance 2020-05-18 16:47:17 -03:00
Alfredo Garcia d2c26b33e0 add boolean inZat to getreceivedbyaccount 2020-05-18 16:47:17 -03:00
Alfredo Garcia 4155db0325 change argument name 2020-05-18 16:47:17 -03:00
Alfredo Garcia aba1d94673 add documentation to flag 2020-05-18 16:47:17 -03:00
Alfredo Garcia 4b61aede28 add bool argument to get balance in satoshis to rpc getreceivedbyaddress 2020-05-18 16:47:17 -03:00
Sean Bowe ecafe6913c
Update minimum chain work on testnet to reflect Heartwood activation. 2020-05-18 09:59:34 -06:00
Homu 1eff1f98b6 Auto merge of #4526 - defuse:update-univalue, r=daira
Add univalue to updatecheck.py and update it to v1.1.1
2020-05-17 18:12:13 +00:00
Daira Hopwood a76e568800 Fix a null pointer dereference that occurs when formatting an error message, if we haven't activated an upgrade as expected.
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2020-05-16 00:26:44 +01:00
Taylor Hornby fc4a70e812 Avoid names starting with __.
These are reserved for all uses (including member function names) in C++,
and their use is technically undefined behaviour:
https://stackoverflow.com/a/228797/393146

Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2020-05-15 16:27:34 -06:00
Danny Willems 332ce1a800
Use preprocessor for ENTRY_SERIALIZED_LENGTH 2020-05-15 19:50:57 +02:00
Danny Willems e465731e69
Use assert.h instead of define manually static_assert 2020-05-15 19:47:49 +02:00
Danny Willems 80fe96a04e
librustzcash: make the header C compatible 2020-05-15 19:38:41 +02:00
Taylor Hornby e0ab57ee36 Add univalue to updatecheck.py and update univalue, removing calls to deprecated methods 2020-05-14 12:42:19 -06:00
therealyingtong 79657a8e3a Fix off-by-one error in CreateNewBlock()
When calling GetHistoryRoot, use prevConsensusBranchId instead of consensusBranchId for compatibility with NU4 and future upgrades.

Co-authored by Jack Grigg (jack@electriccoin.co)
2020-05-14 21:29:47 +08:00
Homu d52003861c Auto merge of #4508 - oxarbitrage:remove_fhelp_from_impls, r=str4d
Remove unused fHelp parameters from internal functions

- dumpwallet_impl
- importwallet_impl
2020-05-12 12:42:58 +00:00
Homu d0b533aacb Auto merge of #4304 - oxarbitrage:issue3893, r=str4d
Add status to transactions in RPC calls

Closes https://github.com/zcash/zcash/issues/3893.
2020-05-12 03:05:37 +00:00
Homu eab938b829 Auto merge of #4513 - zcash:hotfix-v2.1.2-3, r=str4d
Merge in hotfix v2.1.2-3
2020-05-12 00:27:26 +00:00
Homu c82b3f9450 Auto merge of #4510 - zcash:hotfix-v2.1.2-2, r=nuttycom
Merge in 2.1.2-2 hotfix
2020-05-11 19:11:56 +00:00
Sean Bowe 1e945ee82a
Set the deprecation height manually to roughly July 14th. 2020-05-08 13:28:55 -06:00
Sean Bowe f9d4405c09
make-release.py: Versioning changes for 2.1.2-3. 2020-05-08 12:39:13 -06:00
Sean Bowe bdb2df182b
make-release.py: Versioning changes for 2.1.2-2. 2020-05-08 11:41:47 -06:00
Alfredo Garcia 3995fb634b remove not needed help parameters to dump and import impl 2020-05-08 10:54:36 -03:00
Daira Hopwood 58d49ac61b
txdb: log additional debug information.
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2020-05-07 16:22:25 -06:00
Jack Grigg daabcd6d22
txdb: More complete fix for the Heartwood chain consistency check issue.
#4499 was an insufficient fix, because it did not consider the case where
a post-Heartwood node wrote a block index object for a header from a
non-upgraded peer. In that case the version in the block index entry is
`>= CHAIN_HISTORY_ROOT_VERSION`, and so the fix in #4499 has no effect.
In addition, we should skip the consistency check when the index object
validity is not BLOCK_VALID_CONSENSUS.

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2020-05-07 16:22:09 -06:00
Homu 38885ee9a8 Auto merge of #4501 - zcash:hotfix-v2.1.2-1, r=ebfull
Merge in hotfix v2.1.2-1

This PR brings our `v2.1.2-1` hotfix into master.

**Please don't try/r+ this yet.**
2020-05-06 23:01:09 +00:00
ebfull 84a703b3b1
Merge branch 'master' into hotfix-v2.1.2-1 2020-05-06 16:36:01 -06:00
Homu eb06b0a8d4 Auto merge of #4447 - nuttycom:bug/4119-rewind_detection, r=str4d
Reproduce and fix off-by-one error in reorg logic (#4119)

This attempts to reproduce #4119 using a simple chain split.It currently seems to trigger a different issue, an assertion failure in `CheckBlockIndex` when restarting
2020-05-06 21:50:03 +00:00
Sean Bowe 5d24937e5f
make-release.py: Versioning changes for 2.1.2-1. 2020-05-06 10:50:43 -06:00
Sean Bowe c3018904c3
Don't throw exception in PopHistoryNode when popping from empty tree.
If we are doing an expected rollback that changes the consensus
branch ID for some upgrade (or introduces one that wasn't present
at the equivalent height) this will occur because
`SelectHistoryCache` selects the tree for the new consensus
branch ID, not the one that existed on the chain being rolled
back.
2020-05-05 17:25:56 -06:00
Jack Grigg d946b69cf8 txdb/chain: Restrict Heartwood chain consistency check to block index objects that were created by Heartwood-unaware clients.
In the vicinity of a network upgrade, a zcashd node may receive headers
for a non-upgrading chain from its non-upgraded peers (e.g. if the block
at the NU activation height is found more quickly by the non-upgrading
chain). In this situation, the node will end up with two headers at the
NU activation height (and possibly for subsequent block heights).

In the case of Heartwood, the block headers from the non-upgrading chain
do not satisfy the Heartwood header consistency check in
CBlockTreeDB::LoadBlockIndexGuts. In this commit, we restrict the
Heartwood consistency checks to block index objects that were created by
clients that are CHAIN_HISTORY_ROOT_VERSION or better.
2020-05-06 10:41:30 +12:00
Sean Bowe 8dcb533226
Add the intended testnet activation block of Heartwood to our intended rewind logic. 2020-05-05 14:47:29 -06:00
Homu 68fd808e0f Auto merge of #4444 - oxarbitrage:issue4375, r=str4d
Fix advertised version

Closes https://github.com/zcash/zcash/issues/4375 by adding the `-` character to the list of safe ones.

Now i can see stuff like the following in the logs:

```
...
2020-04-13 14:19:37 receive version message: /MagicBean:2.1.1-1/: version 170009, blocks=795400, us=[2800:a4:316b:8e00:ceb:c7b4:3481:197f]:59754, peer=2
...
```

API call `getpeerinfo` will also gets fixed.
2020-05-05 00:29:32 +00:00
Kris Nuttycombe 1508345a20 Merge remote-tracking branch 'upstream/master' into bug/4119-rewind_detection 2020-05-01 17:33:53 -06:00
Homu 1abdc883ac Auto merge of #4487 - str4d:nu4-activation-logic, r=str4d
Add NU4 to upgrade list

Once NU4 has been named, we will rename the constants and functions.

Closes #4472.
2020-05-01 13:41:28 +00:00
Jack Grigg febfaef44e Update URLs for prior network upgrades 2020-05-01 11:40:13 +12:00
Jack Grigg 7e684120d3 Add NU4 test helpers 2020-05-01 11:38:32 +12:00
Jack Grigg 99d387fc51 Add NU4 to upgrade list
Once NU4 has a name, we will rename the constants.
2020-05-01 11:38:03 +12:00
Taylor Hornby 39ca21845a Fix undefined behavior in gtest tests 2020-04-30 17:16:53 -06:00
Homu 7a0fe273d8 Auto merge of #4482 - str4d:memory_cleanse-backports, r=str4d
memory_cleanse backports

Cherry-picked from the following upstream PRs:
- bitcoin/bitcoin#10308
- bitcoin/bitcoin#11196
- bitcoin/bitcoin#11558
  - Only the changes that did not conflict.
- bitcoin/bitcoin#16158

Part of #145.
2020-04-30 23:03:44 +00:00
Jack Grigg 8ea2f467cd Improve memory_cleanse documentation
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2020-05-01 11:00:49 +12:00
Jack Grigg 6a4ff45e8a Use BOOST_SCOPE_EXIT_TPL to clean and free datValue in CDB::Read 2020-05-01 10:57:24 +12:00
Tim Ruffing 1ccdb5734d Improve documentation of memory_cleanse()
So far, the documentation of memory_cleanse() is a verbatim copy of
the commit message in BoringSSL, where this code was originally
written. However, our code evolved since then, and the commit message
is not particularly helpful in the code but is rather of historical
interested in BoringSSL only.

This commit improves improves the comments around memory_cleanse()
and gives a better rationale for the method that we use. This commit
touches only comments.
2020-04-30 17:40:26 +12:00
Tim Ruffing f27ff314e6 Clean up logic in memory_cleanse() for MSVC
Commit fbf327b13868861c2877c5754caf5a9816f2603c ("Minimal code
changes to allow msvc compilation.") was indeed minimal in terms
of lines touched. But as a result of that minimalism it changed the
logic in memory_cleanse() to first call std::memset() and then
additionally the MSVC-specific SecureZeroMemory() function, and it
also moved a comment to the wrong location.

This commit removes the superfluous call to std::memset() on MSVC
and ensures that the comment is in the right position again.
2020-04-30 17:40:26 +12:00
Aaron Clauson 2fcc466273 Minimal code changes to allow msvc compilation.
Zcash: Only changes that did not conflict.
2020-04-30 17:40:26 +12:00
Adam Langley c502acc7c4 Switch memory_cleanse implementation to BoringSSL's to ensure memory clearing even with link-time optimization.
The implementation we currently use from OpenSSL prevents the compiler from optimizing away clensing operations on blocks of memory that are about to be released, but this protection is not extended to link-time optimization. This commit copies the solution cooked up by Google compiler engineers which uses inline assembly directives to instruct the compiler not to optimize out the call under any circumstances. As the code is in-lined, this has the added advantage of removing one more OpenSSL dependency.

Regarding license compatibility, Google's contributions to BoringSSL library, including this code, is made available under the ISC license, which is MIT compatible.

BoringSSL git commit: ad1907fe73334d6c696c8539646c21b11178f20f
2020-04-30 17:40:26 +12:00
Thomas Snider 0a2d4756e1 [wallet] Securely erase potentially sensitive keys/values 2020-04-30 17:40:26 +12:00
Homu 0dbb2d05d3 Auto merge of #4465 - oxarbitrage:issue4463, r=str4d
Add z_getnotescount API

Implement new API call to count notes in wallet.

Closes https://github.com/zcash/zcash/issues/4463
2020-04-30 01:35:59 +00:00
Homu 9e86cc2d82 Auto merge of #4427 - nuttycom:simplify_connect_tip, r=daira
Remove option to load new blocks from ConnectTip

A minor refactoring to move file IO out of ConnectTip, which has only a single caller.
2020-04-25 19:06:55 +00:00
Alfredo Garcia 4c40f9f514 implement z_getnotescount api call 2020-04-25 11:17:20 -03:00
Homu 0ad52ca9b1 Auto merge of #4249 - oxarbitrage:issue_3724, r=str4d
Add confirmations, blockheight, blockindex and blocktime to z_listreceivedbyaddress

Fixes https://github.com/zcash/zcash/issues/3724

1- There was a PR to add confirmations to this call at https://github.com/zcash/zcash/pull/3836
I ported the commit from there and fixed test case by incrementing the confirmations as suggested at: https://github.com/zcash/zcash/pull/3836#issuecomment-499927807

2- Then added `blockheight`, `blockindex` and `blocktime`. To avoid some duplicated code (Sprout/Sapling) created a structure `trxblock`.

3- Original issue requests only time and blockindex however i think height is also important; if `blockindex` is the position of the transaction in the block then you are going to need also `height` to find it.
2020-04-25 05:28:16 +00:00
Kris Nuttycombe 5a8f6f8058 Merge remote-tracking branch 'upstream/master' into bug/4119-rewind_detection 2020-04-22 14:58:11 -06:00
Kris Nuttycombe 368a7c5a9d Ensure that we don't pass a null block pointer to ConnectTip. 2020-04-22 13:17:05 -06:00
Kris Nuttycombe db65d92df4 Make condition closer to original, Fix incorrect comment. 2020-04-22 13:17:05 -06:00
Kris Nuttycombe 2013b35e3e Remove option to load new blocks from ConnectTip 2020-04-22 13:17:05 -06:00
Sean Bowe 9eadd525a5
make-release.py: Versioning changes for 2.1.2. 2020-04-22 10:43:50 -06:00
Daira Hopwood f7208c19c5 Clarify definition of NETWORK_UPGRADE_PEER_PREFERENCE_BLOCK_PERIOD.
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2020-04-22 01:15:06 +01:00
Sean Bowe b42af16553
Set Heartwood activation height for testnet to 903800. 2020-04-21 16:13:33 -06:00
Sean Bowe 08e6ed154c
Add test_random.h to distribution tarball. 2020-04-20 14:53:48 -06:00
Sean Bowe 37fa94e01d
Add Rust resources to distribution tarball. 2020-04-20 13:44:06 -06:00
Alfredo Garcia 766e0b8f09 add a test case 2020-04-19 09:52:38 -03:00
Jack Grigg 51af936f19 Set hashFinalSaplingRoot and hashChainHistoryRoot in AddToBlockIndex
- hashFinalSaplingRoot is now always set to hashLightClientRoot before
  Heartwood activation (regardless of whether or not that is the correct
  Sapling root), and set to the Sapling root after Heartwood activation
  only for blocks that have been passed to ConnectBlock() at least once.

- hashChainHistoryRoot is now always set "correctly" (either null, or
  identical to hashLightClientRoot).

We rely on the fact that block headers are downloaded in order, and we
therefore always know the height of a block header, in order to check
whether Heartwood is active for a particular header.
2020-04-16 20:48:20 +12:00
Sean Bowe 2386046941
make-release.py: Versioning changes for 2.1.2-rc1. 2020-04-15 17:45:34 -06:00
Homu 215c74ec3f Auto merge of #4454 - defuse:cscriptnum-serialization-fix, r=daira
Fix undefined behavior in CScriptNum

Fixes #4432
2020-04-15 22:36:33 +00:00
Kris Nuttycombe 9fc94cc372 The last valid height condition reads better flipped. 2020-04-15 14:33:41 -06:00
Kris Nuttycombe 40b5d5e3ea Fix #4119. 2020-04-15 14:19:09 -06:00
Homu 4fad49d802 Auto merge of #4416 - daira:sa_restart, r=daira
Use SA_RESTART in sa_flags when setting up signal handlers

Explanation: if a signal interrupts certain syscalls such as `open`, `read`, or `write`,
then the library function will by default fail with `errno` `EINTR`. But we [almost](https://github.com/zcash/zcash/search?q=WSAEINTR) [never](https://github.com/zcash/zcash/search?q=EINTR)
check for `EINTR`, so this is likely to cause spurious errors. We want to restart the syscall
instead, which is what `SA_RESTART` is intended to do. Since our signal handlers (defined
in init.cpp) only set a flag, restarting the syscall is safe and is always the Right Thing.

See <https://www.gnu.org/software/libc/manual/html_node/Flags-for-Sigaction.html> and
<https://www.gnu.org/software/libc/manual/html_node/Interrupted-Primitives.html> for
further information.

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2020-04-15 19:23:14 +00:00
Homu 1f5de9cae2 Auto merge of #4306 - oxarbitrage:issue4224, r=daira
Compute more structures in CTxMemPool::DynamicMemoryUsage()

Closes https://github.com/zcash/zcash/issues/4224

Added more structures to the computation of the mempool memory size as indicated in the issue. RPC call `getmempoolinfo` is the only place where this is used to get the `usage` result.
2020-04-15 17:03:31 +00:00
Taylor Hornby 418ef7002a Fix undefined behavior in CScriptNum 2020-04-15 09:19:00 -06:00
Homu 344a2325ef Auto merge of #4431 - oxarbitrage:issue4389, r=daira
Lock with cs_main inside gtests that request chain state

Fix https://github.com/zcash/zcash/issues/4389

- Used the lock from boost tests where `chainActive.Height()` is being called: https://github.com/zcash/zcash/blob/master/src/wallet/test/rpc_wallet_tests.cpp#L1323

- I found no other place in the gtests where `chainActive` is used apart from just the same tests `chainActive.Height()` is called. It seems chain state is only used when we fake mine transactions and these are all inside `test_wallet.cpp`.

I might be missing some other patterns to look at, please let me know if so.
2020-04-15 11:03:48 +00:00
Jack Grigg 655f0c9802 consensus: From Heartwood activation, use Rust Equihash validator
The C++ and Rust Equihash validators are intended to have an identical
set of valid Equihash solutions, so this should merely be an
implementation detail. However, deploying the Rust validator at the same
time as a network upgrade reduces the risk of an unintentional consensus
divergence due to undocumented behaviour in either implementation.

Once Heartwood has activated on mainnet, we can verify that all
pre-Heartwood blocks satisfy the Rust validator, and then remove the C++
validator and make Equihash-checking non-contextual again.
2020-04-15 11:53:28 +12:00
Jack Grigg 49f9584613 Pass the block height through to CheckEquihashSolution()
This requires moving CheckEquihashSolution() to
ContextualCheckBlockHeader() for all but the genesis block, which has no
effect on consensus; it just means that an invalid Equihash solution is
rejected slightly later in the block validation process.
2020-04-15 11:51:21 +12:00
Jack Grigg f4fe77ad1e test: Run Equihash test vectors on both C++ and Rust validators 2020-04-15 11:31:10 +12:00
Homu 084303d8c2 Auto merge of #4264 - NikVolf:mmr, r=str4d
[ZIP 221] FlyClient - Consensus-Layer Changes

Implements https://zips.z.cash/zip-0221
2020-04-14 20:09:34 +00:00
Alfredo Garcia 6f3ad1c496 compute more structures in mempool DynamicMemoryUsage 2020-04-14 10:22:27 -03:00
Alfredo Garcia 8ed97dd9cc Add a new safe chars rule for node version string 2020-04-14 09:08:51 -03:00
Jack Grigg f4194a3fd7 test: Add a second Sapling note to WalletTests.ClearNoteWitnessCache
Quoting the documentation for `std::vector::operator[]`:

    Portable programs should never call this function with an argument
    n that is out of range, since this causes undefined behavior.

This test was doing just that: performing checks on a non-existent
second Sapling witness (duplicating the Sprout logic that checked two
notes, one of which was in the wallet). The test was instead reading
arbitrary memory after the witness that did exist; in most cases, this
memory was interpreted as a `boost::none` as expected, but in some cases
the memory was interpreted as a "real" witness.

Closes zcash/zcash#4445.

Co-authored-by: Ying Tong <yingtong@ethereum.org>
2020-04-14 20:57:59 +12:00
Jack Grigg 31e5f9cde2 Make peak_pos zero-indexed in CCoinsViewCache::PreloadHistoryTree 2020-04-11 11:52:56 +12:00
Jack Grigg 21d8e5be15 Comment clarifications and fixes 2020-04-11 11:39:00 +12:00
Jack Grigg bc30c57cdb Truncate HistoryCache.appends correctly for zero-indexed entries 2020-04-10 19:56:13 +12:00