prevent trustlines being spent below spendable balance

This commit is contained in:
Richard Holland
2022-03-25 13:47:39 +00:00
parent 384b224d64
commit 4726ab823d

View File

@@ -247,6 +247,29 @@ accountHolds(
// Put balance in account terms.
amount.negate();
}
// If tokens can be escrowed then they can be locked in the trustline
// which means we must never spend them until the escrow is released.
if (view.rules().enabled(featurePaychanAndEscrowForTokens)
&& sle->isFieldPresent(sfLockedBalance))
{
STAmount lockedBalance = sle->getFieldAmount(sfLockedBalance);
STAmount spendableBalance = amount -
(account > issuer ? -lockedBalance : lockedBalance);
// RH NOTE: this is defensively programmed, it should never fire
// if something bad does happen the trustline acts as a frozen line.
if (spendableBalance < beast::zero || spendableBalance > amount)
{
JLOG(j.error())
<< "SpendableBalance has illegal value in accountHolds "
<< spendableBalance;
amount.clear(Issue{currency, issuer});
}
else
amount = spendableBalance;
}
amount.setIssuer(issuer);
}
JLOG(j.trace()) << "accountHolds:"