Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #410 from VerusCoin/dev
Dev
  • Loading branch information
Asherda committed May 4, 2022
2 parents d8b79a2 + bba15c7 commit 34c2fb5
Showing 1 changed file with 34 additions and 30 deletions.
64 changes: 34 additions & 30 deletions src/main.cpp
Expand Up @@ -3828,6 +3828,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
std::map<uint160, int32_t> exportTransferCount;
std::map<uint160, int32_t> currencyExportTransferCount;
std::map<uint160, int32_t> identityExportTransferCount;
bool isPBaaS = CConstVerusSolutionVector::GetVersionByHeight(nHeight) >= CActivationHeight::ACTIVATE_PBAAS;

std::vector<PrecomputedTransactionData> txdata;
txdata.reserve(block.vtx.size()); // Required so that pointers to individual PrecomputedTransactionData don't get invalidated
Expand All @@ -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");
}
}
}

Expand Down

0 comments on commit 34c2fb5

Please sign in to comment.