Skip to content

Commit

Permalink
Fixed comments #1
Browse files Browse the repository at this point in the history
  • Loading branch information
vvysokikh1 committed Nov 18, 2024
1 parent 306a112 commit f5efa31
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 41 deletions.
2 changes: 2 additions & 0 deletions src/xrpld/app/paths/detail/StepChecks.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ checkFreeze(
}
if (view.rules().enabled(featureDeepFreeze))
{
// Unline normal freeze, a deep frozen trust line acts the same
// regardless of which side froze it
if (sle->isFlag(lsfHighDeepFreeze) || sle->isFlag(lsfLowDeepFreeze))
{
return terNO_LINE;
Expand Down
4 changes: 3 additions & 1 deletion src/xrpld/app/tx/detail/CreateOffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,9 @@ CreateOffer::checkAcceptAsset(

if (view.rules().enabled(featureDeepFreeze))
{
// An issuer can always accept its own issuance.
// An account can not create a trustline to itself, so no line can exist
// to be frozen. Additionally, an issuer can always accept its own
// issuance.
if (issue.account == id)
{
return tesSUCCESS;
Expand Down
47 changes: 28 additions & 19 deletions src/xrpld/app/tx/detail/SetTrust.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ SetTrust::preflight(PreflightContext const& ctx)
return temINVALID_FLAG;
}

if (!ctx.rules.enabled(featureDeepFreeze))
{
// Even though the deep freeze flags are included in the
// `tfTrustSetMask`, they are not valid if the amendment is not enabled.
if (uTxFlags & (tfSetDeepFreeze | tfClearDeepFreeze))
{
return temINVALID_FLAG;
}
}

STAmount const saLimitAmount(tx.getFieldAmount(sfLimitAmount));

if (!isLegalNet(saLimitAmount))
Expand Down Expand Up @@ -242,11 +252,8 @@ SetTrust::doApply()
bool const bClearNoRipple = (uTxFlags & tfClearNoRipple);
bool const bSetFreeze = (uTxFlags & tfSetFreeze);
bool const bClearFreeze = (uTxFlags & tfClearFreeze);
bool const bDeepFreezeEnabled = view().rules().enabled(featureDeepFreeze);
bool const bSetDeepFreeze =
bDeepFreezeEnabled && (uTxFlags & tfSetDeepFreeze);
bool const bClearDeepFreeze =
bDeepFreezeEnabled && (uTxFlags & tfClearDeepFreeze);
bool const bSetDeepFreeze = (uTxFlags & tfSetDeepFreeze);
bool const bClearDeepFreeze = (uTxFlags & tfClearDeepFreeze);

auto viewJ = ctx_.app.journal("View");

Expand Down Expand Up @@ -413,33 +420,35 @@ SetTrust::doApply()
uFlagsOut &= ~(bHigh ? lsfHighNoRipple : lsfLowNoRipple);
}

bool willSetFreeze = false;
if (bSetFreeze && !bClearFreeze && !sle->isFlag(lsfNoFreeze))
{
uFlagsOut |= (bHigh ? lsfHighFreeze : lsfLowFreeze);
willSetFreeze = true;
}
else if (bClearFreeze && !bSetFreeze)
{
uFlagsOut &= ~(bHigh ? lsfHighFreeze : lsfLowFreeze);
}

bool const alreadyFrozen =
bHigh ? sle->isFlag(lsfHighFreeze) : sle->isFlag(lsfLowFreeze);
if (bSetDeepFreeze && !bClearDeepFreeze &&
(willSetFreeze || alreadyFrozen))
if (bSetDeepFreeze && !bClearDeepFreeze && !sle->isFlag(lsfNoFreeze))
{
if (ctx_.view().rules().enabled(featureDeepFreeze))
uFlagsOut |= (bHigh ? lsfHighDeepFreeze : lsfLowDeepFreeze);
else
return temMALFORMED;
uFlagsOut |= (bHigh ? lsfHighDeepFreeze : lsfLowDeepFreeze);
}
else if (bClearDeepFreeze && !bSetDeepFreeze)
{
if (ctx_.view().rules().enabled(featureDeepFreeze))
uFlagsOut &= ~(bHigh ? lsfHighDeepFreeze : lsfLowDeepFreeze);
else
return temMALFORMED;
uFlagsOut &= ~(bHigh ? lsfHighDeepFreeze : lsfLowDeepFreeze);
}

// Checking freeze invariants
auto const frozen = uFlagsOut & (bHigh ? lsfHighFreeze : lsfLowFreeze);
auto const deepFrozen =
uFlagsOut & (bHigh ? lsfHighDeepFreeze : lsfLowDeepFreeze);

// Trying to set deep freeze on not already frozen trust line must fail
// This also checks that clearing normal freeze while deep frozen must
// not work
if (deepFrozen && !frozen)
{
return tecNO_PERMISSION;
}

if (QUALITY_ONE == uLowQualityOut)
Expand Down
58 changes: 37 additions & 21 deletions src/xrpld/ledger/detail/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,20 +273,24 @@ isDeepFrozen(
AccountID const& issuer)
{
if (!view.rules().enabled(featureDeepFreeze))
{
return false;
}

if (isXRP(currency))
{
return false;
if (issuer != account)
}

if (issuer == account)
{
// Check if the issuer deep froze the line
auto sle = view.read(keylet::line(account, issuer, currency));
if (sle)
{
if (sle->isFlag(lsfHighDeepFreeze) || sle->isFlag(lsfLowDeepFreeze))
return true;
}
return false;
}
return false;

// Check if the line is deep frozen
auto const sle = view.read(keylet::line(account, issuer, currency));
return sle &&
(sle->isFlag(lsfHighDeepFreeze) || sle->isFlag(lsfLowDeepFreeze));
}

STAmount
Expand All @@ -306,18 +310,25 @@ accountHolds(

// IOU: Return balance on trust line modulo freeze
auto const sle = view.read(keylet::line(account, issuer, currency));
if (!sle)
{
amount.clear(Issue{currency, issuer});
}
else if (
((zeroIfFrozen == fhZERO_IF_FROZEN) &&
isFrozen(view, account, currency, issuer)) ||
isDeepFrozen(view, account, currency, issuer))
{
amount.clear(Issue{currency, issuer});
}
else
auto const allowBalance = [&]() {
if (!sle)
{
return false;
}

if (zeroIfFrozen == fhZERO_IF_FROZEN)
{
if (isFrozen(view, account, currency, issuer) ||
isDeepFrozen(view, account, currency, issuer))
{
return false;
}
}

return true;
}();

if (allowBalance)
{
amount = sle->getFieldAmount(sfBalance);
if (account > issuer)
Expand All @@ -327,6 +338,11 @@ accountHolds(
}
amount.setIssuer(issuer);
}
else
{
amount.clear(Issue{currency, issuer});
}

JLOG(j.trace()) << "accountHolds:" << " account=" << to_string(account)
<< " amount=" << amount.getFullText();

Expand Down

0 comments on commit f5efa31

Please sign in to comment.