From dbbe0dfc317b821a692974bf6f53818ed118559c Mon Sep 17 00:00:00 2001 From: miketout Date: Tue, 3 May 2022 23:24:39 -0700 Subject: [PATCH] Only check for reserve transfer imports if PBaaS upgrade is active --- src/main.cpp | 64 ++++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 489eb318db2..e0a5e7cd727 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3828,6 +3828,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin std::map exportTransferCount; std::map currencyExportTransferCount; std::map identityExportTransferCount; + bool isPBaaS = CConstVerusSolutionVector::GetVersionByHeight(nHeight) >= CActivationHeight::ACTIVATE_PBAAS; std::vector txdata; txdata.reserve(block.vtx.size()); // Required so that pointers to individual PrecomputedTransactionData don't get invalidated @@ -3846,44 +3847,47 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin return false; // Failure reason has been set in validation state object } - for (auto &oneOut : tx.vout) + if (isPBaaS) { - COptCCParams p; - CReserveTransfer rt; - if (oneOut.scriptPubKey.IsPayToCryptoCondition(p) && - p.IsValid() && - p.evalCode == EVAL_RESERVE_TRANSFER) + for (auto &oneOut : tx.vout) { - if (p.version >= p.VERSION_V3 && - p.vData.size() && - (rt = CReserveTransfer(p.vData[0])).IsValid()) + COptCCParams p; + CReserveTransfer rt; + if (oneOut.scriptPubKey.IsPayToCryptoCondition(p) && + p.IsValid() && + p.evalCode == EVAL_RESERVE_TRANSFER) { - uint160 destCurrencyID = rt.GetImportCurrency(); - CCurrencyDefinition destCurrency = ConnectedChains.GetCachedCurrency(destCurrencyID); - // ETH protocol has limits on number of valid reserve transfers of each type in a block - CCurrencyDefinition destSystem = ConnectedChains.GetCachedCurrency(destCurrency.SystemOrGatewayID()); - - if (!destSystem.IsValid()) - { - return state.DoS(10, error("%s: unable to retrieve system destination for export to %s", __func__, EncodeDestination(CIdentityID(destCurrencyID)).c_str()), REJECT_INVALID, "bad-txns-invalid-system"); - } - if (++exportTransferCount[destCurrencyID] > destSystem.MaxTransferExportCount()) - { - return state.DoS(10, error("%s: attempt to submit block with too many transfers exporting to %s", __func__, EncodeDestination(CIdentityID(destCurrencyID)).c_str()), REJECT_INVALID, "bad-txns-too-many-transfers"); - } - if (rt.IsCurrencyExport() && ++currencyExportTransferCount[destCurrencyID] > destSystem.MaxCurrencyDefinitionExportCount()) + if (p.version >= p.VERSION_V3 && + p.vData.size() && + (rt = CReserveTransfer(p.vData[0])).IsValid()) { - return state.DoS(10, error("%s: attempt to submit block with too many currency definition transfers exporting to %s", __func__, EncodeDestination(CIdentityID(destCurrencyID)).c_str()), REJECT_INVALID, "bad-txns-too-many-currency-transfers"); + uint160 destCurrencyID = rt.GetImportCurrency(); + CCurrencyDefinition destCurrency = ConnectedChains.GetCachedCurrency(destCurrencyID); + // ETH protocol has limits on number of valid reserve transfers of each type in a block + CCurrencyDefinition destSystem = ConnectedChains.GetCachedCurrency(destCurrency.SystemOrGatewayID()); + + if (!destSystem.IsValid()) + { + return state.DoS(10, error("%s: unable to retrieve system destination for export to %s", __func__, EncodeDestination(CIdentityID(destCurrencyID)).c_str()), REJECT_INVALID, "bad-txns-invalid-system"); + } + if (++exportTransferCount[destCurrencyID] > destSystem.MaxTransferExportCount()) + { + return state.DoS(10, error("%s: attempt to submit block with too many transfers exporting to %s", __func__, EncodeDestination(CIdentityID(destCurrencyID)).c_str()), REJECT_INVALID, "bad-txns-too-many-transfers"); + } + if (rt.IsCurrencyExport() && ++currencyExportTransferCount[destCurrencyID] > destSystem.MaxCurrencyDefinitionExportCount()) + { + return state.DoS(10, error("%s: attempt to submit block with too many currency definition transfers exporting to %s", __func__, EncodeDestination(CIdentityID(destCurrencyID)).c_str()), REJECT_INVALID, "bad-txns-too-many-currency-transfers"); + } + if (rt.IsIdentityExport() && ++identityExportTransferCount[destCurrencyID] > destSystem.MaxIdentityDefinitionExportCount()) + { + return state.DoS(10, error("%s: attempt to submit block with too many identity definition transfers exporting to %s", __func__, EncodeDestination(CIdentityID(destCurrencyID)).c_str()), REJECT_INVALID, "bad-txns-too-many-identity-transfers"); + } } - if (rt.IsIdentityExport() && ++identityExportTransferCount[destCurrencyID] > destSystem.MaxIdentityDefinitionExportCount()) + else { - return state.DoS(10, error("%s: attempt to submit block with too many identity definition transfers exporting to %s", __func__, EncodeDestination(CIdentityID(destCurrencyID)).c_str()), REJECT_INVALID, "bad-txns-too-many-identity-transfers"); + return state.DoS(10, error("%s: invalid reserve transfer", __func__), REJECT_INVALID, "bad-txns-reserve-transfer"); } } - else - { - return state.DoS(10, error("%s: invalid reserve transfer", __func__), REJECT_INVALID, "bad-txns-reserve-transfer"); - } } }