Skip to content

Commit f91e4df

Browse files
committed
[Refactoring] Skip expensive ContainsZerocoins/HasZerocoinSpendInputs
...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.
1 parent dd784bb commit f91e4df

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/validation.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,12 +1549,9 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
15491549
return state.DoS(100, error("%s : shielded transactions are currently in maintenance mode", __func__));
15501550
}
15511551

1552-
// If v5 is active, bye bye zerocoin
1553-
if (isV5UpgradeEnforced && tx.ContainsZerocoins()) {
1554-
return state.DoS(100, error("%s : v5 upgrade enforced, zerocoin disabled", __func__));
1555-
}
1556-
1557-
if (tx.HasZerocoinSpendInputs()) {
1552+
// When v5 is enforced CheckBlock rejects zerocoin transactions.
1553+
// Therefore no need to call HasZerocoinSpendInputs after the enforcement.
1554+
if (!isV5UpgradeEnforced && tx.HasZerocoinSpendInputs()) {
15581555
auto opCoinSpendValues = ParseAndValidateZerocoinSpends(consensus, tx, pindex->nHeight, state);
15591556
if (!opCoinSpendValues) {
15601557
return false; // Invalidity/DoS is handled by ParseAndValidateZerocoinSpends.

0 commit comments

Comments
 (0)