diff --git a/src/pbaas/crosschainrpc.cpp b/src/pbaas/crosschainrpc.cpp index b0b0c70b1f5..53e24e45cf5 100644 --- a/src/pbaas/crosschainrpc.cpp +++ b/src/pbaas/crosschainrpc.cpp @@ -53,7 +53,7 @@ extern std::string VERUS_CHAINNAME; uint32_t PBAAS_TESTFORK2_TIME = 1684281600; uint32_t PBAAS_TESTFORK3_TIME = 1685379600; -uint32_t PBAAS_TESTFORK4_TIME = 1685901600; +uint32_t PBAAS_TESTFORK4_TIME = 1685984400; uint32_t PBAAS_MAINDEFI3_HEIGHT = 2553500; uint32_t PBAAS_ENFORCE_CORRECT_EVIDENCE_TIME = 1684359650; diff --git a/src/pbaas/pbaas.cpp b/src/pbaas/pbaas.cpp index bf35cf0bbab..298c5fa5667 100644 --- a/src/pbaas/pbaas.cpp +++ b/src/pbaas/pbaas.cpp @@ -7425,10 +7425,29 @@ bool CConnectedChains::CreateLatestImports(const CCurrencyDefinition &sourceSyst { tb.SetReserveFee(reserveFees); } - if (reserveChange > CCurrencyValueMap() && - !VERUS_NOTARYID.IsNull()) + if (reserveChange > CCurrencyValueMap()) { - tb.SendChangeTo(VERUS_NOTARYID); + CTxDestination changeDest; + if (!VERUS_NOTARYID.IsNull()) + { + changeDest = VERUS_NOTARYID; + } + else if (!VERUS_DEFAULTID.IsNull()) + { + changeDest = VERUS_DEFAULTID; + } + else if (!IsValidDestination(changeDest = DecodeDestination(GetArg("-mineraddress", "")))) + { + extern CWallet *pwalletMain; + LOCK(pwalletMain->cs_wallet); + CPubKey key; + + if (pwalletMain->GetKeyFromPool(key)) + { + changeDest = key.GetID(); + } + } + tb.SendChangeTo(changeDest); } if (LogAcceptCategory("crosschainimports")) diff --git a/src/pbaas/reserves.cpp b/src/pbaas/reserves.cpp index aa7cc1d0a59..b231e2767a6 100644 --- a/src/pbaas/reserves.cpp +++ b/src/pbaas/reserves.cpp @@ -2764,6 +2764,9 @@ CReserveTransactionDescriptor::CReserveTransactionDescriptor(const CTransaction bool isClearLaunch = (ccx.IsClearLaunch() && ccx.sourceSystemID == importCurrencyDef.launchSystemID); + CReserveTransactionDescriptor rtxd = *this; + uint256 weakEntropyHash = EntropyHashFromHeight(CBlockIndex::BlockEntropyKey(), importNotarization.notarizationHeight, importCurrencyDef.GetID()); + if (ConnectedChains.CheckZeroViaOnlyPostLaunch(nHeight) && isClearLaunch && importTransfers.size()) @@ -2798,8 +2801,27 @@ CReserveTransactionDescriptor::CReserveTransactionDescriptor(const CTransaction { checkState = priorNotar.currencyState; checkState.SetPrelaunch(false); - validNotarization = true; - break; + if (rtxd.AddReserveTransferImportOutputs(sourceSystemDef, + ConnectedChains.thisChain, + importCurrencyDef, + checkState, + importTransfers, + nHeight, + checkOutputs, + importedCurrency, + gatewayDeposits, + spentCurrencyOut, + &newState, + ccx.exporter, + importNotarization.proposer, + weakEntropyHash)) + { + checkState.conversionPrice = newState.conversionPrice; + checkState.viaConversionPrice = newState.viaConversionPrice; + validNotarization = true; + checkOutputs.clear(); + break; + } } } if (!validNotarization) @@ -2849,8 +2871,7 @@ CReserveTransactionDescriptor::CReserveTransactionDescriptor(const CTransaction checkState.SetLaunchClear(); } - CReserveTransactionDescriptor rtxd = *this; - uint256 weakEntropyHash = EntropyHashFromHeight(CBlockIndex::BlockEntropyKey(), importNotarization.notarizationHeight, importCurrencyDef.GetID()); + rtxd = *this; if (!rtxd.AddReserveTransferImportOutputs(sourceSystemDef, ConnectedChains.thisChain, @@ -4334,7 +4355,7 @@ bool CReserveTransactionDescriptor::AddReserveTransferImportOutputs(const CCurre { CCurrencyValueMap cumulativeReservesIn = importCurrencyDef.IsFractional() ? - CCurrencyValueMap(importCurrencyState.currencies, importCurrencyState.reserveIn) : + CCurrencyValueMap(importCurrencyState.currencies, importCurrencyState.primaryCurrencyIn) : importCurrencyState.NativeToReserveRaw(importCurrencyState.primaryCurrencyIn, importCurrencyState.conversionPrice); // check if it exceeds pre-conversion maximums, and refund if so @@ -6363,6 +6384,8 @@ void CCoinbaseCurrencyState::RevertReservesAndSupply(const uint160 &systemID, bo // reverse last changes auto currencyMap = GetReserveMap(); + CCurrencyValueMap negativePreReserves(currencies, reserveIn); + // revert changes in reserves and supply to pre conversion state, add reserve outs and subtract reserve ins for (auto &oneCur : currencyMap) { @@ -6379,21 +6402,16 @@ void CCoinbaseCurrencyState::RevertReservesAndSupply(const uint160 &systemID, bo { supply += primaryCurrencyIn[oneCur.second]; } - else + else if (processingPreconverts) { - CCurrencyValueMap negativePreReserves(currencies, reserveIn); - negativePreReserves = negativePreReserves * -1; - - if (!IsPrelaunch()) - { - primaryCurrencyIn = AddVectors(primaryCurrencyIn, negativePreReserves.AsCurrencyVector(currencies)); - for (auto &oneVal : reserveIn) - { - oneVal = 0; - } - } + reserveIn[oneCur.second] = 0; } } + if (processingPreconverts) + { + negativePreReserves = negativePreReserves * -1; + primaryCurrencyIn = AddVectors(primaryCurrencyIn, negativePreReserves.AsCurrencyVector(currencies)); + } } } // between prelaunch and launch complete phases of non-fractional, we have accumulation of reserves