Change the "Legacy" variables to amendment checks in visitNodes

- Having parallel variables is error prone in case of any future
  developments. It could also explode if another fix needs to be made
  later.
This commit is contained in:
Ed Hennis
2026-04-09 13:54:26 -04:00
parent f86acbf127
commit d01cfb63ff
2 changed files with 24 additions and 34 deletions

View File

@@ -228,7 +228,6 @@ public:
class NoXRPTrustLines
{
bool xrpTrustLine_ = false;
bool xrpTrustLineLegacy_ = false;
public:
void
@@ -248,7 +247,6 @@ public:
class NoDeepFreezeTrustLinesWithoutFreeze
{
bool deepFreezeWithoutFreeze_ = false;
bool deepFreezeWithoutFreezeLegacy_ = false;
public:
void
@@ -284,7 +282,6 @@ public:
class NoZeroEscrow
{
bool bad_ = false;
bool badLegacy_ = false;
public:
void

View File

@@ -312,27 +312,18 @@ NoZeroEscrow::visitEntry(
};
if (before && before->getType() == ltESCROW)
{
auto const b = isBad((*before)[sfAmount]);
bad_ |= b;
badLegacy_ |= b;
}
bad_ |= isBad((*before)[sfAmount]);
if (after && after->getType() == ltESCROW)
{
auto const b = isBad((*after)[sfAmount]);
bad_ |= b;
badLegacy_ |= b;
}
bad_ |= isBad((*after)[sfAmount]);
auto checkAmount = [this](std::int64_t amount) {
if (amount > maxMPTokenAmount || amount < 0)
{
bad_ = true;
badLegacy_ = true;
}
};
bool const overwriteFixEnabled = isFeatureEnabled(fixSecurity3_1_3);
if (after && after->getType() == ltMPTOKEN_ISSUANCE)
{
auto const outstanding = (*after)[sfOutstandingAmount];
@@ -340,8 +331,11 @@ NoZeroEscrow::visitEntry(
if (auto const locked = (*after)[~sfLockedAmount])
{
checkAmount(*locked);
bad_ |= outstanding < *locked;
badLegacy_ = outstanding < *locked;
bool const isBad = outstanding < *locked;
if (overwriteFixEnabled)
bad_ |= isBad;
else
bad_ = isBad;
}
}
@@ -364,9 +358,7 @@ NoZeroEscrow::finalize(
ReadView const& rv,
beast::Journal const& j) const
{
bool const effectiveBad = rv.rules().enabled(fixSecurity3_1_3) ? bad_ : badLegacy_;
if (effectiveBad)
if (bad_)
{
JLOG(j.fatal()) << "Invariant failed: escrow specifies invalid amount";
return false;
@@ -613,6 +605,8 @@ NoXRPTrustLines::visitEntry(
std::shared_ptr<SLE const> const&,
std::shared_ptr<SLE const> const& after)
{
bool const overwriteFixEnabled = isFeatureEnabled(fixSecurity3_1_3);
if (after && after->getType() == ltRIPPLE_STATE)
{
// checking the issue directly here instead of
@@ -620,8 +614,10 @@ NoXRPTrustLines::visitEntry(
// were systematically incorrect
bool const isXrp = after->getFieldAmount(sfLowLimit).asset() == xrpIssue() ||
after->getFieldAmount(sfHighLimit).asset() == xrpIssue();
xrpTrustLine_ |= isXrp;
xrpTrustLineLegacy_ = isXrp;
if (overwriteFixEnabled)
xrpTrustLine_ |= isXrp;
else
xrpTrustLine_ = isXrp;
}
}
@@ -633,10 +629,7 @@ NoXRPTrustLines::finalize(
ReadView const& rv,
beast::Journal const& j) const
{
bool const effectiveXrpTrustLine =
rv.rules().enabled(fixSecurity3_1_3) ? xrpTrustLine_ : xrpTrustLineLegacy_;
if (!effectiveXrpTrustLine)
if (!xrpTrustLine_)
return true;
JLOG(j.fatal()) << "Invariant failed: an XRP trust line was created";
@@ -653,6 +646,8 @@ NoDeepFreezeTrustLinesWithoutFreeze::visitEntry(
{
if (after && after->getType() == ltRIPPLE_STATE)
{
bool const overwriteFixEnabled = isFeatureEnabled(fixSecurity3_1_3);
std::uint32_t const uFlags = after->getFieldU32(sfFlags);
bool const lowFreeze = (uFlags & lsfLowFreeze) != 0u;
bool const lowDeepFreeze = (uFlags & lsfLowDeepFreeze) != 0u;
@@ -661,8 +656,10 @@ NoDeepFreezeTrustLinesWithoutFreeze::visitEntry(
bool const highDeepFreeze = (uFlags & lsfHighDeepFreeze) != 0u;
bool const bad = (lowDeepFreeze && !lowFreeze) || (highDeepFreeze && !highFreeze);
deepFreezeWithoutFreeze_ |= bad;
deepFreezeWithoutFreezeLegacy_ = bad;
if (overwriteFixEnabled)
deepFreezeWithoutFreeze_ |= bad;
else
deepFreezeWithoutFreeze_ = bad;
}
}
@@ -674,11 +671,7 @@ NoDeepFreezeTrustLinesWithoutFreeze::finalize(
ReadView const& rv,
beast::Journal const& j) const
{
bool const effectiveDeepFreezeWithoutFreeze = rv.rules().enabled(fixSecurity3_1_3)
? deepFreezeWithoutFreeze_
: deepFreezeWithoutFreezeLegacy_;
if (!effectiveDeepFreezeWithoutFreeze)
if (!deepFreezeWithoutFreeze_)
return true;
JLOG(j.fatal()) << "Invariant failed: a trust line with deep freeze flag "