Use block hash comparison for consistency check when loading block index
The Equihash check caused block index loading to take around 38x longer.
However, we don't need to check it directly, as the only paths to writing a
block header to disk already go through a proof-of-work check (e.g. receiving a
block over the network). By forcing the block header inside the CBlockIndex to
be re-serialized, we retain the benefits of the consistency check without the
overhead at startup.
The Equihash check caused block index loading to take around 38x longer.
However, we don't need to check it directly, as the only paths to writing a
block header to disk already go through a proof-of-work check (e.g. receiving a
block over the network). By forcing the block header inside the CBlockIndex to
be re-serialized, we retain the benefits of the consistency check without the
overhead at startup.
Co-authored-by: Brad Miller <brad@z.cash>
Check Equihash solution when loading block index
An additional consistency check, which also ensures that the in-memory representation
matches the stored index.
read hashReserved from disk
This fixes a bug where the hashReserved field of the block header is not properly read back into CBlockIndex when loaded from disk. This happens to cause no issues currently because hashReserved has always been its default value (== 0), but if a block were ever mined where this was not the case, headers read back from disk would appear to have an invalid solution
Overwinter SignatureHash
Implements ZIP 143.
Includes code cherry-picked from the following upstream PRs:
- bitcoin/bitcoin#7276
- bitcoin/bitcoin#7976
- bitcoin/bitcoin#8118
- bitcoin/bitcoin#8149
- Only amount validation and SignatureHash commits.
- bitcoin/bitcoin#8346
- bitcoin/bitcoin#8524
Part of #2074 and #2254. Closes#1408 and #2584.
We do not need to be able to calculate multiple SignatureHash versions for a
single transaction format; instead, we use the transaction format to determine
the SigVersion.
The consensus branch ID *does* need to be passed in from the outside, as only
the caller knows the context in which the SignatureHash is being calculated
(ie. mempool acceptance vs. block validation).
JoinSplit signature verification has been moved into ContextualCheckTransaction,
where the consensus branch ID can be obtained.
The argument to the sign command for zcash-tx has been modified to take a height
in addition to the optional sigtype flags.