Commit Graph

68 Commits

Author SHA1 Message Date
Jack Grigg 54aeb2c408 Migrate Equihash Rust FFI to `cxx`
This integrates `cxxbridge` into the build system, adding its generated
source files to `libzcash`. We currently need to manually specify each
Rust file containing a bridge description.
2022-05-27 20:15:05 +00:00
Kris Nuttycombe 28040f9ce4 scripted-diff: Add 2016-2022 copyright headers for files added/modified in 2016
-BEGIN VERIFY SCRIPT-
grep -l "Copyright" $(grep -L "The Zcash developers" $(git diff --name-only --diff-filter=ACM bitcoin-v0.11.2..94f427a211bb337200c29a1e19be0f5ad2f171b0 -- src/ test/ zcutil/ qa/)) | xargs -I {} sed -i"" -e "s#\(\(.*\)Copyright (c) .* The Bitcoin Core developers\)#\1\n\2Copyright (c) 2016-2022 The Zcash developers#" {}
-END VERIFY SCRIPT-
2022-05-11 17:23:09 -06:00
Jack Grigg d8d0918951 scripted-diff: Migrate from boost::optional to std::optional
-BEGIN VERIFY SCRIPT-
sed -i 's/boost::none/std::nullopt/g' ./src/*.h ./src/*.cpp ./src/*/*.h* ./src/*/*.cpp ./src/*/*/*.h* ./src/*/*/*.cpp ;
sed -i 's/boost::optional/std::optional/g' ./src/*.h ./src/*.cpp ./src/*/*.h* ./src/*/*.cpp ./src/*/*/*.h* ./src/*/*/*.cpp ;
sed -i 's/std::optional<\(.*\)&>/std::optional<std::reference_wrapper<\1>>/' ./src/*/*.h ./src/*/*.cpp ;
sed -i 's/is_initialized()/has_value()/' ./src/*.cpp ./src/*/*.cpp ;
sed -i ':a;N;$!ba;s/#include <boost\/optional.hpp>\n//' ./src/*.h ./src/*.cpp ./src/*/*.h* ./src/*/*.cpp ./src/*/*/*.h ./src/*/*/*.cpp ;
sed -i ':a;N;$!ba;s/#include "boost\/optional.hpp"\n//' ./src/*.h ;
-END VERIFY SCRIPT-
2020-12-16 22:59:35 +00:00
Jack Grigg d9928926f3 Migrate from boost::optional::get to boost::optional::value
std::optional only has std::optional::value.
2020-12-16 22:59:34 +00:00
Eric Lombrozo 03f1d38e04 Added fPowNoRetargeting field to Consensus::Params that disables nBits recalculation.
Zcash: Moved conditional into GetNextWorkRequired(), as we had rewritten
CalculateNextWorkRequired() to not have the necessary information. This
means that CalculateNextWorkRequired() will in unit tests calculate what
regtest would use were the new field not set; this is irrelevant, as only
GetNextWorkRequired() is used directly in consensus rules.
2020-11-17 18:48:32 +00:00
Daira Hopwood 4d16bfd181 GetNextWorkRequired: clarify why this computation is equivalent to that in the protocol spec.
refs https://github.com/zcash/zips/pull/418

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2020-11-12 10:52:49 +00:00
Dimitris Tsapakidis b892fe13f8 Fixed multiple typos
A few "a->an" and "an->a".
"Shows, if the supplied default SOCKS5 proxy" -> "Shows if the supplied default SOCKS5 proxy". Change made on 3 occurrences.
"without fully understanding the ramification of a command" -> "without fully understanding the ramifications of a command".
Removed duplicate words such as "the the".

Zcash: Only the changes to files and code that we have.
2020-09-23 00:07:48 +01:00
teor 5919464919
Fix a comment typo in pow.cpp 2020-08-06 19:03:52 +10:00
Jack Grigg 3611f68811 Revert "Pass the block height through to CheckEquihashSolution()"
This reverts commit 49f9584613.

Now that we are depending unconditionally on the Rust Equihash
validator, CheckEquihashSolution() can revert to being a non-contextual
check.

This also fixes a segfault that would occur during reindexing if the
consensus rules were altered such that a previously-valid block would
become invalid, and the node's block files contained blocks in a
specific order. It was encountered while testing the Canopy NU on
testnet (due to a bug in the implementation of ZIP 212 that was
separately fixed in zcash/zcash#4604).
2020-07-15 16:16:40 +12:00
Jack Grigg 79846ac1f3 Use Rust Equihash validator unconditionally
It correctly validates all blocks prior to Heartwood activation.
2020-07-15 13:59:32 +12: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
Alfredo Garcia 0eec096843 Consensus: Decouple pow.cpp from util.h 2019-10-22 14:16:53 -03:00
Homu 2528af69ff Auto merge of #4025 - bitcartel:shorter_block_target_interval_zip208, r=daira
Implement ZIP 208: Shorter Block Target Spacing

Closes #3690.
2019-08-09 02:35:30 -07:00
Eirik Ogilvie-Wigley c192e3a75d Update pow_tests for shorter block times 2019-07-26 10:34:23 -06:00
Eirik Ogilvie-Wigley 7421272712 Make nextHeight required in CalculateNextWorkRequired 2019-07-18 14:57:13 -06:00
Daira Hopwood bc909a7a7f Replace http with https: in links to the MIT license.
Also change MIT/X11 to just MIT, since no distinction was intended.

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2019-07-18 15:26:01 +01:00
Simon b30ff0d367 Update PoW function calls to pass in height. 2019-07-11 13:46:29 -06:00
Jack Grigg cea06a4fd3
Move Equihash parameters into consensus params 2019-05-23 17:48:13 +01:00
Jack Grigg 4c90270469
Explicitly check the min-difficulty flag against boost::none
It isn't clear how a boost::optional that holds 0 (which is the case for
regtest) is coerced to a boolean, unless you pore over the Boost
documentation. An explicit check is clearer.
2018-10-04 23:29:11 +01:00
Jack Grigg 1f7ee4af70
Rename min-difficulty flag to remove off-by-one in the name 2018-10-04 23:26:05 +01:00
Jack Grigg b86dc98047
Only enable min-difficulty blocks on testnet from a particular height
The min-difficulty change is a bilateral consensus rule change, and so
must be conditionally enabled in order for the earlier section of the
chain to synchronise.

Technically this could be implemented as a network upgrade, but as this will
never be deployed to mainnet, a targeted fork will suffice.
2018-10-04 14:05:27 +01:00
Jack Grigg 1702a86455
Allow minimum-difficulty blocks on testnet and regtest
A block may be mined with nBits set to the minimum difficulty if its
nTime is set more than six block intervals (15 minutes) after its parent
block.

This is a consensus rule change on testnet that will result in a chain
split (as desired).
2018-10-03 17:50:17 +01:00
Jack Grigg 639e46b4d7
Revert "Remove testnet-only difficulty rules"
This reverts commit 333ea3c426.
2018-10-03 16:15:03 +01:00
Simon 10a7d55a03 Remove now redundant Rust call to librustzcash_xor. 2018-06-06 23:24:21 -07:00
Jack Grigg d9cd254e5e
Make Rust compilation mandatory
The temporary integration check in CheckEquihashSolution() remains, until we
have "real" Rust code to integrate.

Closes #2688.
2018-03-28 17:55:45 +02:00
Sean Bowe 802ea76b3a Allow Rust-language related assets to be disabled with `--disable-rust`. 2017-03-18 07:47:40 -06:00
Sean Bowe 6a0c7ceae9 Introduce librustzcash and Rust to depends system. 2017-03-17 11:46:41 -06:00
Jack Grigg 4b37cfd5b8 Remove unnecessary method 2016-09-08 12:22:08 +12:00
Jack Grigg 7b173bd80f Simplify difficulty averaging code 2016-09-06 23:03:36 +12:00
Jack Grigg 333ea3c426 Remove testnet-only difficulty rules
The min-difficulty blocks are incompatible with difficulty averaging.

Network difficulty is also now defined as the difficulty the network is
currently working to solve, rather than the last non-min-difficulty block
difficulty.
2016-09-05 23:13:25 +12:00
Jack Grigg 29842505cc Adjust from average difficulty instead of previous difficulty 2016-09-05 22:25:11 +12:00
Jack Grigg 488e61e852 Undo debugging change from 5be6abbf84
This was unintentionally committed, and caused Equihash verification of blocks
without parents to be skipped. This only affects the genesis block on the test
network, but also causes the "time verifyequihash" benchmark to incorrectly
appear instantaneous.
2016-08-26 14:09:25 +12:00
Jack Grigg 5be6abbf84 Store the Equihash solution in minimal representation in the block header
The genesis blocks and miner tests have been regenerated, because changing the
block header serialisation format changes the block hash, and thus validity.

The Equihash solutions have been removed from the bloom test inputs for
simplicity (block validity is not checked there; only a valid serialisation is
necessary).
2016-08-16 16:02:39 +12:00
Jack Grigg 9e0713f47f Remove hardfork from special testnet difficulty rules
Closes #1131
2016-07-29 21:46:27 +12:00
Jack Grigg 9e6adb124f Hardfork to the previous testnet difficulty adjustment behaviour at block 43400
This hardfork will be removed the next time the testnet blockchain is reset.
2016-07-22 14:17:46 +12:00
Jack Grigg e99731b4a4 Reinstate previous testnet adjustment behaviour
When the difficulty adjustment algorithm was altered, the special testnet
min-difficulty case was maintained, but the difficulty adjustment for the
following block then adjusted from min-difficulty instead of from the last
non-min-difficulty block. This caused the difficulty on the testnet to sawtooth
instead of stabilising. The intended behaviour is restored here.
2016-07-21 20:50:05 +12:00
Jack Grigg f2c48e15e5 Implement new difficulty algorithm (#931)
The algorithm is based on DigiShield v3/v4.
2016-06-15 09:48:42 +12:00
Jack Grigg e95747288a Use template parameters to statically initialise Equihash 2016-05-24 23:16:50 +12:00
Jack Grigg aa86873afd Fix pow_tests to work with Equihash
Changing the order of difficulty calculation operations to divide first doesn't
affect the result significantly, but ensures we never overflow the arith_uint256
during multiplication and get an artificial jump in difficulty.
2016-04-08 23:19:03 +12:00
Jack Grigg fdda3c5085 Use Equihash for Proof-of-Work
The main and test networks are configured to use parameters that are currently
low-memory but usable with the basic solver; they will be increased once the
solver is optimised. The regtest network is configured to have extremely low
memory usage for speed.

Note that Bitcoin's double-hasher is used for the difficulty check. This does
not match the paper, but is simpler than changing the block header
serialization. Single hashing is kept for the EquiHash solver because there is
no requirement on execution time there, only on memory usage.
2016-04-08 13:56:00 +12:00
Pieter Wuille f7303f9793 Use equivalent PoW for non-main-chain requests 2015-04-22 03:53:25 -07:00
Cory Fields fd311996e8 consensus: don't use arith_uint256 in consensus.h
Requiring arith_uint256 at such a base level is not good for modularity.
2015-04-10 15:33:37 -04:00
Pieter Wuille 1cc0e96e9c Trivial optimization: use GetAncestor to compute new target 2015-03-26 11:06:27 -07:00
Jorge Timón d698ef690f Consensus: Refactor: Decouple pow.o from chainparams.o 2015-03-26 00:47:51 +01:00
Wladimir J. van der Laan 3aa0130b96 test: remove fSkipProofOfWork
Not used, and REGTEST already allows creating blocks at
the lowerst possible difficulty.
2015-03-09 16:09:54 +01:00
Ross Nicoll 34e5015cd2
Add unit tests for next difficulty calculations
Split GetNextWorkRequired() into two functions to allow the difficulty calculations to
be tested without requiring a full blockchain.
Add unit tests to cover basic difficulty calculation, plus each of the min/max actual
time, and maximum difficulty target conditions.
2015-02-21 13:14:19 +00:00
Shaul Kfir e5ece053da Rename Interval() to DifficultyAdjustmentInterval() 2015-02-17 08:46:51 -05:00
Pavel Janík 5262fde0ec Remove whitespaces before double colon in errors and logs 2015-01-31 17:38:28 -05:00
Wladimir J. van der Laan 734f85c4f0 Use arith_uint256 where necessary
Also add conversion from/to uint256 where needed.
2015-01-05 15:45:35 +01:00