Commit Graph

72 Commits

Author SHA1 Message Date
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
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
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
Daira Hopwood 089acd75f7 Add Prometheus metrics so we have more visibility into what is going
on with the Equihash solution trimming:

* (counter) `zcashd.debug.memory.allocated_equihash_solutions` -
  the number of Equihash solutions that have ever been allocated;
* (counter) `zcashd.debug.memory.trimmed_equihash_solutions` -
  the number of Equihash solutions that were trimmed;
* (counter) `zcashd.debug.blocktree.trimmed_equihash_read_dbindex` -
  the number of times a block index entry needed to be reread to
  construct a block header because a solution had been trimmed;
* (counter) `zcashd.debug.blocktree.write_batch` -
  the number of block tree batch write operations (calls to
  `CBlockTreeDB::WriteBatchSync`);
* (counter) `zcashd.debug.blocktree.write_batch_read_dbindex` -
  the number of times a block index entry needed to be reread
  before being written during a block tree batch write operation.

These metrics are specific to `zcashd`; they are primarily intended
for performance debugging of this feature and should not be considered
stable.

Co-authored-by: Jack Grigg <thestr4d@gmail.com>
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2022-11-21 18:24:45 +00:00
Daira Hopwood aee8d5c0ec Avoid storing the Equihash solution in a CBlockIndex object once it has been written
to the leveldb database.

Co-authored-by: Jack Grigg <thestr4d@gmail.com>
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2022-11-21 18:24:45 +00:00
Daira Hopwood 2ee172fe15 Error reporting improvements.
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2022-11-13 18:46:30 +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
str4d 86ac3e12f0
Minor fixes to documentation and formatting
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-06-21 17:08:22 +01:00
Jack Grigg 509e7c7d79 Implement Orchard pool value tracking
The ZIP 209 rules preventing the Sprout and Sapling pool values from
going negative, are extended to the Orchard pool.
2021-06-21 01:40:49 +01:00
Jack Grigg bd4c0a8515 ZIP 244 hashBlockCommitments implementation
We will start storing two new hashes in the block index from v4.5.0:
- hashAuthDataRoot
- hashFinalOrchardRoot
2021-06-18 01:05:04 +01:00
Jack Grigg 4da2347e96 Rename hashLightClientRoot to hashBlockCommitments in block header 2021-06-18 01:05:04 +01: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 521eb81a95 Add <optional> header to files that will need it 2020-12-16 22:59:34 +00:00
Daira Hopwood 75f9f8f95b Make some conversions explicit to reduce sanitizer warnings.
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2020-08-27 23:57:28 +01: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
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
Jack Grigg 2ad84e8564 Comment tweaks and cleanups
Co-Authored-By: Daira Hopwood <daira@jacaranda.org>
2020-04-10 09:53:30 +12:00
Jack Grigg cf480fe402 Add ZIP 221 logic to block index
CBlockHeader.hashFinalSaplingRoot has been renamed to hashLightClient.

CBlockIndex now stores:
- hashLightClient as from the block header
- hashFinalSaplingRoot, which is accurate for all blocks prior to
  Heartwood activation, and all blocks from Heartwood activation onward
  that are connected at some point to the main chain in ConnectBlock().
- hashChainHistoryRoot, which is null prior to Heartwood activation, and
  set per ZIP 221 from Heartwood activation.

The new block index fields are only written to disk for client version
2.1.2 and above, which will be the first Heartwood-aware clients (even
if Heartwood doesn't have an activation height).
2020-04-08 08:49:01 +12:00
Daira Hopwood 7fa7225509 Update GetAdjustedTime() to GetTime().
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2020-02-25 16:57:22 +00:00
Daira Hopwood ca8d32070a Add string argument to static_asserts to satisfy C++11.
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2020-02-06 23:35:56 +00:00
Daira Hopwood 7704ab4846 Soft fork: restrict block timestamps to be no more than 90 minutes after the MTP of the previous block.
Note that the MTP of a block is the median timestamp of the preceding 11 blocks, i.e. it is
typically (with no or only moderate timestamp manipulation) expected to be 6 block intervals
behind that block's timestamp, which *on average* is 450 seconds behind (after Blossom activation).
So the effective limit on future dating of timestamps is ~82.5 minutes. This makes it
exceptionally unlikely --even taking into account feasible timestamp manipulation of this
and previous blocks-- that the chain will stall because no block is found before the limit.
(This may rely on assumptions that do not hold for testnet.)

If an adversary were to have a sufficient fraction of mining power to engineer this situation
then there would be something seriously wrong, and arguably the chain should stall in that
case, pending manual intervention.

Co-authored-by: Jack Grigg <jack@z.cash>
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2020-02-04 21:34:05 +00:00
Daira Hopwood a3bb1966eb Add constant for how far a block timestamp can be ahead of adjusted time.
Loosely based on e57a1fd899

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2020-02-04 19:46:48 +00: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
Wladimir J. van der Laan 3647f0a7b1
Break circular dependency main ↔ txdb
Break the circular dependency between main and txdb by:

- Moving `CBlockFileInfo` from `main.h` to `chain.h`. I think this makes
  sense, as the other block-file stuff is there too.

- Moving `CDiskTxPos` from `main.h` to `txdb.h`. This type seems
  specific to txdb.

- Pass a functor `insertBlockIndex` to `LoadBlockIndexGuts`. This leaves
  it up to the caller how to insert block indices.

Zcash: This does not actually break the circular dependency for us yet, as we
still need to pull in bitcoin/bitcoin#7756 and bitcoin/bitcoin#7904.
2019-05-23 17:48:24 +01:00
Jack Grigg 51df195f5e
Comment in CDiskBlockIndex that LoadBlockIndexGuts also needs updating 2018-11-16 15:13:17 +00:00
Jack Grigg ae97177c86
Track net value entering and exiting the Sapling circuit 2018-05-09 16:02:23 -04:00
Sean Bowe 1f8be05b63 Add consensus support for Sapling merkle trees. 2018-05-07 14:37:46 -06:00
Sean Bowe e814be60fe Rename hashSproutAnchorEnd to hashFinalSproutRoot to be consistent. 2018-05-07 14:37:46 -06:00
Sean Bowe f2c6d214e5 Rename hashSaplingAnchorEnd to hashFinalSaplingRoot to match spec. 2018-05-07 14:37:46 -06:00
Sean Bowe 30325eebf5 Add primitive implementation of GetSaplingAnchorEnd. 2018-05-07 13:46:06 -06:00
Sean Bowe 691a3fa2e9 Rename hashReserved to hashSaplingAnchorEnd. 2018-05-07 13:46:06 -06:00
Sean Bowe 08f0728884 Rename hashAnchor to hashSproutAnchor. 2018-05-07 13:46:06 -06:00
Jack Grigg 68a1a592ca
Remove nType and nVersion from Zcash-specific code 2018-04-17 13:09:47 +01:00
Pieter Wuille 242f1421db
Get rid of nType and nVersion
Remove the nType and nVersion as parameters to all serialization methods
and functions. There is only one place where it's read and has an impact
(in CAddress), and even there it does not impact any of the recursively
invoked serializers.

Instead, the few places that need nType or nVersion are changed to read
it directly from the stream object, through GetType() and GetVersion()
methods which are added to all stream classes.
2018-04-17 13:09:28 +01:00
Jack Grigg 828940b163
Use a boost::optional for nCachedBranchId
This enables us to distinguish between it being unset vs. being set to zero.
2018-02-06 22:42:18 +00:00
Jack Grigg 9e851450ab
Adjust rewind logic to use the network upgrade mechanism 2018-02-04 22:58:42 +00:00
Pieter Wuille 89f20450c2
Add rewind logic to deal with post-fork software updates
Includes logic for dealing with pruning by Suhas Daftuar.
2018-02-04 22:58:42 +00:00
Jack Grigg e365ca1c53
Remove nSproutValue TODO from CDiskBlockIndex
Block indices are flushed to disk when they are marked as dirty, and this
happens via enough distinct pathways that it would be sufficiently complex to
update nSproutValue via all of them. Thus it is necessary to be able to
serialize "no value" for writes by upgraded clients.
2017-12-16 10:01:26 +00:00
Jack Grigg 9d0c70e9e7
Clarify operator precedence in serialization of nSproutValue 2017-12-15 18:36:05 +00:00
Jack Grigg ad6a36ad02
Track net value entering and exiting the Sprout circuit
Delta values will be stored for new blocks; old blocks can be filled in by
re-indexing. The net value currently in the Sprout circuit is only calculated
when delta values for all previous blocks are present.
2017-12-14 22:06:11 +00:00
Wladimir J. van der Laan 0e2b1ae259
chain: define enum used as bit field as uint32_t
Bitwise logic combined with `<` with undefined signedness will
potentially results in undefined behavior. Fix this by defining the type
as a c++11 typed enum.

Fixes #6017.
2017-03-24 09:03:59 +13:00
Jack Grigg 0bc1e2c431
Add anchor to output of getblock
Closes #2164.
2017-03-10 20:09:40 +13:00
Jack Grigg d9d59f5176
Remove the RC 1 block index error message
Reverts 85457ddec1

Closes #1548
2016-10-18 17:19:54 -05:00
Jack Grigg 85457ddec1
Add clear error message for upgrading users 2016-10-17 09:55:02 -05:00
Jack Grigg b6961fc112
Increment witnesses for new transactions on rescan
Closes #1400
2016-10-17 09:55:02 -05: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 a8d384aeda Add a 256-bit reserved field to the block header
This field has no defined semantics. While it was added as a result of
discussions about merged mining in #724, this field will not necessarily ever be
used for that purpose.
2016-06-07 16:06:25 +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