Browse Source

Hardening and correct launchsystemid for sub-ids

pull/451/head
miketout 2 years ago
parent
commit
d502658a4f
  1. 4
      src/pbaas/notarization.cpp
  2. 41
      src/pbaas/pbaas.cpp
  3. 3
      src/pbaas/reserves.cpp
  4. 4
      src/rpc/pbaasrpc.cpp

4
src/pbaas/notarization.cpp

@ -4590,7 +4590,8 @@ std::vector<uint256> CPBaaSNotarization::SubmitFinalizedNotarizations(const CRPC
*/
bool ValidateAcceptedNotarization(struct CCcontract_info *cp, Eval* eval, const CTransaction &tx, uint32_t nIn, bool fulfilled)
{
// TODO: this validates the spending transaction
// TODO: HARDENING
// the spending transaction must be a notarization in the same thread of notarizations
// check the following things:
// 1. It represents a valid PoS or merge mined block on the other chain, and contains the header in the opret
// 2. The MMR and proof provided for the currently asserted block can prove the provided header. The provided
@ -5117,6 +5118,7 @@ bool IsAcceptedNotarizationInput(const CScript &scriptSig)
bool ValidateEarnedNotarization(struct CCcontract_info *cp, Eval* eval, const CTransaction &tx, uint32_t nIn, bool fulfilled)
{
// TODO: HARDENING ensure that earned notarization UTXOs are spent appropriately
// the spending transaction must be a finalization that either confirms or invalidates this notarization
return true;
}

41
src/pbaas/pbaas.cpp

@ -584,8 +584,8 @@ bool PrecheckCrossChainImport(const CTransaction &tx, int32_t outNum, CValidatio
return state.Error(strprintf("%s: Invalid currency import", __func__));
}
// TODO: HARDENING - imported currencies do need to conform to type constraints in order
// to benefit from reduced import fees
// imported currencies do need to conform to type constraints in order
// to benefit from reduced import fees. this happens on the precheck for currency definition
if ((oneTransfer.HasNextLeg() && oneTransfer.destination.gatewayID != ASSETCHAINS_CHAINID ?
nextLegFeeEquiv :
@ -4589,20 +4589,19 @@ bool CConnectedChains::CreateLatestImports(const CCurrencyDefinition &sourceSyst
newLocalDepositsRequired.valueMap[destCurID] -= newPrimaryCurrency;
}
/*printf("%s: newNotarization:\n%s\n", __func__, newNotarization.ToUniValue().write(1,2).c_str());
printf("%s: ccx.totalAmounts: %s\ngatewayDepositsUsed: %s\nimportedCurrency: %s\nspentCurrencyOut: %s\n",
LogPrint("crosschainimports", "%s: newNotarization:\n%s\n", __func__, newNotarization.ToUniValue().write(1,2).c_str());
LogPrint("crosschainimports", "%s: ccx.totalAmounts: %s\ngatewayDepositsUsed: %s\nimportedCurrency: %s\nspentCurrencyOut: %s\n",
__func__,
ccx.totalAmounts.ToUniValue().write(1,2).c_str(),
gatewayDepositsUsed.ToUniValue().write(1,2).c_str(),
importedCurrency.ToUniValue().write(1,2).c_str(),
spentCurrencyOut.ToUniValue().write(1,2).c_str());
printf("%s: incomingCurrency: %s\ncurrencyChange: %s\nnewLocalDepositsRequired: %s\n",
LogPrint("crosschainimports", "%s: incomingCurrency: %s\ncurrencyChange: %s\nnewLocalDepositsRequired: %s\n",
__func__,
incomingCurrency.ToUniValue().write(1,2).c_str(),
newLocalReserveDeposits.ToUniValue().write(1,2).c_str(),
newLocalDepositsRequired.ToUniValue().write(1,2).c_str());
//*/
// create the import
CCrossChainImport cci = CCrossChainImport(sourceSystemID,
@ -4825,9 +4824,8 @@ bool CConnectedChains::CreateLatestImports(const CCurrencyDefinition &sourceSyst
gatewayChange = (totalDepositsInput - gatewayDepositsUsed).CanonicalMap();
/*printf("%s: gatewayDepositsUsed: %s\n", __func__, gatewayDepositsUsed.ToUniValue().write(1,2).c_str());
printf("%s: gatewayChange: %s\n", __func__, gatewayChange.ToUniValue().write(1,2).c_str());
//*/
LogPrint("crosschainimports", "%s: gatewayDepositsUsed: %s\n", __func__, gatewayDepositsUsed.ToUniValue().write(1,2).c_str());
LogPrint("crosschainimports", "%s: gatewayChange: %s\n", __func__, gatewayChange.ToUniValue().write(1,2).c_str());
// we should always be able to fulfill
// gateway despoit requirements, or this is an error
@ -4867,15 +4865,14 @@ bool CConnectedChains::CreateLatestImports(const CCurrencyDefinition &sourceSyst
}
}
/* printf("%s: newNotarization.currencyState: %s\n", __func__, newNotarization.currencyState.ToUniValue().write(1,2).c_str());
printf("%s: cci: %s\n", __func__, cci.ToUniValue().write(1,2).c_str());
printf("%s: spentcurrencyout: %s\n", __func__, spentCurrencyOut.ToUniValue().write(1,2).c_str());
printf("%s: newcurrencyin: %s\n", __func__, incomingCurrency.ToUniValue().write(1,2).c_str());
printf("%s: importedCurrency: %s\n", __func__, importedCurrency.ToUniValue().write(1,2).c_str());
printf("%s: localdepositrequirements: %s\n", __func__, newLocalDepositsRequired.ToUniValue().write(1,2).c_str());
printf("%s: checkImportedCurrency: %s\n", __func__, checkImportedCurrency.ToUniValue().write(1,2).c_str());
printf("%s: checkRequiredDeposits: %s\n", __func__, checkRequiredDeposits.ToUniValue().write(1,2).c_str());
//*/
LogPrint("crosschainimports", "%s: newNotarization.currencyState: %s\n", __func__, newNotarization.currencyState.ToUniValue().write(1,2).c_str());
LogPrint("crosschainimports", "%s: cci: %s\n", __func__, cci.ToUniValue().write(1,2).c_str());
LogPrint("crosschainimports", "%s: spentcurrencyout: %s\n", __func__, spentCurrencyOut.ToUniValue().write(1,2).c_str());
LogPrint("crosschainimports", "%s: newcurrencyin: %s\n", __func__, incomingCurrency.ToUniValue().write(1,2).c_str());
LogPrint("crosschainimports", "%s: importedCurrency: %s\n", __func__, importedCurrency.ToUniValue().write(1,2).c_str());
LogPrint("crosschainimports", "%s: localdepositrequirements: %s\n", __func__, newLocalDepositsRequired.ToUniValue().write(1,2).c_str());
LogPrint("crosschainimports", "%s: checkImportedCurrency: %s\n", __func__, checkImportedCurrency.ToUniValue().write(1,2).c_str());
LogPrint("crosschainimports", "%s: checkRequiredDeposits: %s\n", __func__, checkRequiredDeposits.ToUniValue().write(1,2).c_str());
// add local reserve deposit inputs and determine change
if (newLocalDepositsRequired.valueMap.size() ||
@ -4901,7 +4898,7 @@ bool CConnectedChains::CreateLatestImports(const CCurrencyDefinition &sourceSyst
newLocalReserveDeposits = ((totalDepositsInput + incomingCurrency) - spentCurrencyOut).CanonicalMap();
/* printf("%s: totalDepositsInput: %s\nincomingPlusDepositsMinusSpent: %s\n",
LogPrint("crosschainimports", "%s: totalDepositsInput: %s\nincomingPlusDepositsMinusSpent: %s\n",
__func__,
totalDepositsInput.ToUniValue().write(1,2).c_str(),
newLocalReserveDeposits.ToUniValue().write(1,2).c_str()); //*/
@ -4974,12 +4971,12 @@ bool CConnectedChains::CreateLatestImports(const CCurrencyDefinition &sourceSyst
// ins and outs are correct. now calculate the fee correctly here and set the transaction builder accordingly
// to prevent an automatic change output. we could just let it go and have a setting to stop creation of a change output,
// but this is a nice doublecheck requirement
/*printf("%s: reserveInMap:\n%s\nspentCurrencyOut:\n%s\nccx.totalAmounts:\n%s\nccx.totalFees:\n%s\n",
LogPrint("crosschainimports", "%s: reserveInMap:\n%s\nspentCurrencyOut:\n%s\nccx.totalAmounts:\n%s\nccx.totalFees:\n%s\n",
__func__,
reserveInMap.ToUniValue().write(1,2).c_str(),
spentCurrencyOut.ToUniValue().write(1,2).c_str(),
ccx.totalAmounts.ToUniValue().write(1,2).c_str(),
ccx.totalFees.ToUniValue().write(1,2).c_str()); //*/
ccx.totalFees.ToUniValue().write(1,2).c_str());
// pay the fee out to the miner
CReserveTransactionDescriptor rtxd(tb.mtx, view, nHeight + 1);
@ -4990,7 +4987,7 @@ bool CConnectedChains::CreateLatestImports(const CCurrencyDefinition &sourceSyst
tb.SetReserveFee(reserveFees);
}
if (LogAcceptCategory("imports"))
if (LogAcceptCategory("crosschainimports"))
{
UniValue jsonTx(UniValue::VOBJ);
uint256 hashBlk;

3
src/pbaas/reserves.cpp

@ -2502,6 +2502,9 @@ CReserveTransactionDescriptor::CReserveTransactionDescriptor(const CTransaction
checkState.SetLaunchCompleteMarker(false);
}
// TODO: HARDENING - ensure that we match notarization state to account for burns and
// transactions that affect state without outputs
if (!rtxd.AddReserveTransferImportOutputs(sourceSystemDef,
ConnectedChains.thisChain,
importCurrencyDef,

4
src/rpc/pbaasrpc.cpp

@ -8252,6 +8252,10 @@ extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue&
CCurrencyDefinition ValidateNewUnivalueCurrencyDefinition(const UniValue &uniObj, uint32_t height, const uint160 systemID, std::map<uint160, std::string> &requiredDefinitions, bool checkMempool)
{
CCurrencyDefinition newCurrency(uniObj);
if (find_value(uniObj, "launchsystemid").isNull() && newCurrency.GetID() != ASSETCHAINS_CHAINID && newCurrency.parent != ASSETCHAINS_CHAINID)
{
newCurrency.launchSystemID = systemID;
}
if (!newCurrency.IsValid())
{

Loading…
Cancel
Save