Skip to content

Conversation

@random-zebra
Copy link

#2425 introduced two bugs which are preventing a successful chain sync from scratch on master:

  1. It abstracted a piece of code in ParseAndValidateZerocoinSpend, which is only parsing/validating a single zerocoin spend per tx, while a transaction could contain multiple spends. Fix it by returning an optional list of CoinSpendValue, instead of a singleton.

  2. It re-introduced in the validation the (unused-at-the-time) function CheckPublicCoinSpendVersion, which is now failing at the first block with (version 3) public spends.
    As all spork-based checks, this was supposed to be skipped when fInitialBlockDownload.
    Zerocoin transactions are no longer accepted (in both nets) in the mempool, as well as inside blocks (after v5 enforcement), so we can just remove this obsolete function.

The third commit fixes a very old bug: a zerocoin spend tx nValueIn is counted twice in ConnectBlock (first directly, after the coinspend parsing/validation, and then via CCoinsViewCache::GetValueIn).

Then, since we are at it, we can deprecate SPORK_16_ZEROCOIN_MAINTENANCE_MODE and SPORK_18_ZEROCOIN_PUBLICSPEND_V4, which are now unused/unneeded.

The last three commits are performance optimizations to avoid multiple calls to ContainsZerocoins()/HasZerocoinSpendInputs() in ConnectBlock, when possible.

considering that a tx can contain multiple spends
as this was meant to be checked only if IsBlockChainSynced.
As zerocoin public spends are no longer accepted (both in
main-net/testnet) we can just remove it.
Zerocoin spends values are already returned by GetValueIn below
SPORK_16 value is still checked in:
- AcceptToMemoryPool (but there's a static check at lines 418-421)
- ConnectBlock (but there's a height-based check at lines 1562-1564, and
an additional height-based check inside CheckBlock)
...calls in ConnectBlock when possible.

The check at line 2798 in CheckBlock ensures that no zc tx (either mint
or spend) is accepted in the chain after v5 activation.
`ContainsZerocoins`/`HasZerocoinSpendInputs` are expensive functions,
especially when they return `false` (as they need to go through all
inputs and outputs).
Therefore avoid the duplicated check in ConnectBlock, and, instead, use
the shortcut operator to skip HasZerocoinSpendInputs call after v5
enforcement.
as we already checking it via ContextualCheckBlock -->
ContextualCheckTransaction --> ContextualCheckZerocoinTx
@random-zebra random-zebra force-pushed the 202107_fix_zerocoin-connectblock branch from 810d589 to f7a93cd Compare July 25, 2021 18:33
Copy link

@furszy furszy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK f7a93cd.
Going to try a fresh sync now.

Copy link
Collaborator

@Fuzzbawls Fuzzbawls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK a5a20e8

Full sync on mainnet confirmed

Copy link

@furszy furszy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK a5a20e8
Took a while to sync on a small VPS (and had a disk space abortion that ended up on a chain reindex..).

@furszy furszy merged commit c49c4c1 into PIVX-Project:master Jul 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants