Skip to content

Commit

Permalink
Merge pull request KomodoPlatform#516 from VerusCoin/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Asherda authored Jun 3, 2023
2 parents e6991df + 0124403 commit bf40024
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/pbaas/crosschainrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ CCurrencyDefinition::CCurrencyDefinition(const UniValue &obj) :
}
}

if (nVersion != PBAAS_VERSION_INVALID && IsFractional())
if (nVersion != PBAAS_VERSION_INVALID)
{
if (minPreconvertArr.isArray() && minPreconvertArr.size() && minPreconvertArr.size() != currencyArr.size())
{
Expand Down
18 changes: 15 additions & 3 deletions src/pbaas/notarization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1319,8 +1319,10 @@ bool CPBaaSNotarization::NextNotarizationInfo(const CCurrencyDefinition &sourceS
minPreMap = CCurrencyValueMap(destCurrency.currencies, destCurrency.minPreconvert).CanonicalMap();
}

bool improvedMinCheck = ConnectedChains.CheckZeroViaOnlyPostLaunch(currentHeight);
if (forcedRefund ||
(minPreMap.valueMap.size() && preConvertedMap < minPreMap) ||
(minPreMap.valueMap.size() &&
((!improvedMinCheck && preConvertedMap < minPreMap) || (improvedMinCheck && (preConvertedMap - minPreMap).HasNegative()))) ||
(destCurrency.IsFractional() &&
(CCurrencyValueMap(destCurrency.currencies, newNotarization.currencyState.reserveIn) +
newPreConversionReservesIn).CanonicalMap().valueMap.size() != destCurrency.currencies.size()))
Expand Down Expand Up @@ -10236,8 +10238,9 @@ bool PreCheckFinalizeNotarization(const CTransaction &tx, int32_t outNum, CValid
CTransaction finalizedTx;
uint256 txBlockHash;
CPBaaSNotarization notarization;
BlockMap::iterator notaTxBlockIt;

if (!(currentFinalization.GetOutputTransaction(tx, finalizedTx, txBlockHash) &&
if (!(currentFinalization.GetOutputTransaction(tx, finalizedTx, txBlockHash, false) &&
finalizedTx.vout[currentFinalization.output.n].scriptPubKey.IsPayToCryptoCondition(p) &&
p.IsValid() &&
(p.evalCode == EVAL_ACCEPTEDNOTARIZATION || p.evalCode == EVAL_EARNEDNOTARIZATION) &&
Expand All @@ -10251,6 +10254,14 @@ bool PreCheckFinalizeNotarization(const CTransaction &tx, int32_t outNum, CValid
return state.Error("Invalid notarization output for finalization");
}

if (!(!txBlockHash.IsNull() &&
(notaTxBlockIt = mapBlockIndex.find(txBlockHash)) != mapBlockIndex.end() &&
chainActive.Contains(notaTxBlockIt->second)) &&
(!PBAAS_TESTMODE || chainActive[height - 1]->nTime >= PBAAS_TESTFORK4_TIME))
{
return state.Error("Uncommitted notarization output is invalid for finalization");
}

for (int i = outNum + 1; i < tx.vout.size(); i++)
{
if (i == currentFinalization.output.n)
Expand Down Expand Up @@ -10520,6 +10531,7 @@ bool PreCheckFinalizeNotarization(const CTransaction &tx, int32_t outNum, CValid
!proofDescr.challengeOutputs[0].GetOutputTransaction(tipTx, tipBlockHash, false) ||
tipBlockHash.IsNull() ||
(tipTxBlockIt = mapBlockIndex.find(tipBlockHash)) == mapBlockIndex.end() ||
!chainActive.Contains(tipTxBlockIt->second) ||
tipTxBlockIt->second->GetHeight() > (height - 1) ||
tipTxBlockIt->second->GetHeight() < pCurNotarizationBlkIndex->GetHeight() ||
tipTx.vout.size() <= proofDescr.challengeOutputs[0].n ||
Expand All @@ -10534,7 +10546,7 @@ bool PreCheckFinalizeNotarization(const CTransaction &tx, int32_t outNum, CValid
continue;
}
LogPrint("notarization", "%s: notarization finalization tip transaction not in prior chain at height %u\n", __func__, height);
if (confirmNeedsEvidence && (!PBAAS_TESTMODE || chainActive[height - 1]->nTime >= PBAAS_TESTFORK3_TIME))
if (confirmNeedsEvidence && (!PBAAS_TESTMODE || chainActive[height - 1]->nTime >= PBAAS_TESTFORK4_TIME))
{
return state.Error("Invalid confirmation evidence 1");
}
Expand Down
15 changes: 9 additions & 6 deletions src/pbaas/reserves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4332,7 +4332,10 @@ bool CReserveTransactionDescriptor::AddReserveTransferImportOutputs(const CCurre
std::vector<int64_t>({curTransfer.FirstValue() - CReserveTransactionDescriptor::CalculateConversionFee(curTransfer.FirstValue())}));
CCurrencyValueMap newTotalReserves = CCurrencyValueMap(importCurrencyState.currencies, updatedPostLaunch ? importCurrencyState.reserveIn : importCurrencyState.primaryCurrencyIn) + newReserveIn + preConvertedReserves;

if (newTotalReserves > CCurrencyValueMap(importCurrencyDef.currencies, importCurrencyDef.maxPreconvert))
if ((!updatedPostLaunch &&
newTotalReserves > CCurrencyValueMap(importCurrencyDef.currencies, importCurrencyDef.maxPreconvert)) ||
(updatedPostLaunch &&
(CCurrencyValueMap(importCurrencyDef.currencies, importCurrencyDef.maxPreconvert) - newTotalReserves).HasNegative()))
{
LogPrint("defi", "%s: refunding pre-conversion over maximum: %s\n", __func__, curTransfer.ToUniValue().write(1,2).c_str());
curTransfer = curTransfer.GetRefundTransfer();
Expand Down Expand Up @@ -4676,21 +4679,21 @@ bool CReserveTransactionDescriptor::AddReserveTransferImportOutputs(const CCurre
return false;
}

uint160 convertFromID = curTransfer.FirstCurrency();
uint160 convertFromCur = curTransfer.FirstCurrency();

// source currency must be in definition
auto currencyMap = importCurrencyDef.GetCurrenciesMap();
if (((!isFractional && convertFromID != importCurrencyDef.launchSystemID) ||
(isFractional && !currencyMap.count(convertFromID)))&&
!(updatedPostLaunch && currencyMap.count(convertFromID)))
if (!(updatedPostLaunch && currencyMap.count(convertFromCur)) &&
((!isFractional && convertFromCur != importCurrencyDef.launchSystemID) ||
(isFractional && !currencyMap.count(convertFromCur))))
{
printf("%s: Invalid conversion %s. Source currency must be included in definition currencies\n", __func__, curTransfer.ToUniValue().write().c_str());
LogPrintf("%s: Invalid conversion %s. Source currency must be included in definition currencies\n", __func__, curTransfer.ToUniValue().write().c_str());
return false;
}

// get currency index
auto curIndexIt = currencyIndexMap.find(convertFromID);
auto curIndexIt = currencyIndexMap.find(convertFromCur);
if (curIndexIt == currencyIndexMap.end())
{
printf("%s: Invalid currency for conversion %s\n", __func__, curTransfer.ToUniValue().write().c_str());
Expand Down

0 comments on commit bf40024

Please sign in to comment.