Skip to content

Commit

Permalink
Merge remote-tracking branch 'mike/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Asherda committed Jun 4, 2023
2 parents 209e473 + 82e46f3 commit d28f835
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/pbaas/crosschainrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
25 changes: 22 additions & 3 deletions src/pbaas/pbaas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
52 changes: 35 additions & 17 deletions src/pbaas/reserves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand All @@ -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
Expand Down

0 comments on commit d28f835

Please sign in to comment.