mirror of
https://github.com/XRPLF/rippled.git
synced 2026-07-26 00:20:41 +00:00
fix stuff
This commit is contained in:
@@ -134,16 +134,36 @@ void
|
||||
increaseOwnerCount(
|
||||
ApplyView& view,
|
||||
ReserveContext const& reserveCtx,
|
||||
std::int32_t ownerCountAdj,
|
||||
beast::Journal j = beast::Journal{beast::Journal::getNullSink()});
|
||||
std::uint32_t count,
|
||||
beast::Journal j);
|
||||
|
||||
/** Adjust the owner counters of the account up or down. If object has sponsor adjust its counters
|
||||
* too. Used primarily just before deleting the object.
|
||||
/** Decrease owner-count fields when the caller supplies the sponsor.
|
||||
*
|
||||
* This helper does not delete a ledger object. It updates reserve accounting
|
||||
* after the caller has removed an owner-counted reserve, or for special
|
||||
* owner-count changes whose sponsor cannot be derived from an object's
|
||||
* sfSponsor field.
|
||||
*
|
||||
* @param view The apply view for making changes
|
||||
* @param accountSle The account's ledger entry
|
||||
* @param sponsorSle The sponsor's ledger entry (if applicable)
|
||||
* @param count Amount to remove from the owner count
|
||||
* @param j Journal for logging
|
||||
*/
|
||||
void
|
||||
decreaseOwnerCount(
|
||||
ApplyView& view,
|
||||
ReserveContext const& reserveCtx,
|
||||
std::uint32_t count,
|
||||
beast::Journal j);
|
||||
|
||||
/** Decrease the owner counters of the account. If the object has a sponsor,
|
||||
* adjust its counters too. Used primarily just before deleting the object.
|
||||
*
|
||||
* @param view The apply view for making changes
|
||||
* @param ownerSle The account's ledger entry
|
||||
* @param objectSle The object's ledger entry
|
||||
* @param ownerCountAdj Adjustment amount for the account count
|
||||
* @param count Positive amount to remove from the owner count
|
||||
* @param j Journal for logging (default: null sink)
|
||||
*/
|
||||
void
|
||||
@@ -151,8 +171,28 @@ decreaseOwnerCountForObject(
|
||||
ApplyView& view,
|
||||
SLE::pointer ownerSle,
|
||||
SLE::ref objectSle,
|
||||
std::int32_t ownerCountAdj,
|
||||
beast::Journal j = beast::Journal{beast::Journal::getNullSink()});
|
||||
std::uint32_t count,
|
||||
beast::Journal j);
|
||||
|
||||
/** Convenience overload that accepts AccountID instead of account SLE reference.
|
||||
*
|
||||
* @param view The apply view for making changes
|
||||
* @param account The account ID
|
||||
* @param objectSle The object's ledger entry
|
||||
* @param count Amount to remove from the owner count
|
||||
* @param j Journal for logging
|
||||
*/
|
||||
inline void
|
||||
decreaseOwnerCountForObject(
|
||||
ApplyView& view,
|
||||
AccountID const& account,
|
||||
SLE::ref objectSle,
|
||||
std::uint32_t count,
|
||||
beast::Journal j)
|
||||
{
|
||||
SLE::ref accountSle = view.peek(keylet::account(account));
|
||||
decreaseOwnerCountForObject(view, accountSle, objectSle, count, j);
|
||||
}
|
||||
|
||||
/** Returns IOU issuer transfer fee as Rate. Rate specifies
|
||||
* the fee as fractions of 1 billion. For example, 1% transfer rate
|
||||
|
||||
@@ -194,7 +194,7 @@ transferRate(ReadView const& view, AccountID const& issuer)
|
||||
}
|
||||
|
||||
static void
|
||||
adjustOwnerCountValue(
|
||||
adjustOwnerCountImpl(
|
||||
ApplyView& view,
|
||||
SLE::ref sle,
|
||||
SF_UINT32 const& sfield,
|
||||
@@ -212,63 +212,85 @@ adjustOwnerCountValue(
|
||||
view.update(sle);
|
||||
}
|
||||
|
||||
static void
|
||||
adjustOwnerCountSigned(
|
||||
ApplyView& view,
|
||||
SLE::ref accountSle,
|
||||
SLE::ref sponsorSle,
|
||||
std::int32_t adjustment,
|
||||
beast::Journal j)
|
||||
{
|
||||
XRPL_ASSERT(accountSle, "xrpl::adjustOwnerCountSigned : valid account sle");
|
||||
if (!accountSle)
|
||||
return; // LCOV_EXCL_LINE
|
||||
|
||||
auto const sleType = accountSle->getType();
|
||||
bool const validType = sponsorSle ? sleType == ltACCOUNT_ROOT
|
||||
: sleType == ltLOAN_BROKER || sleType == ltACCOUNT_ROOT;
|
||||
XRPL_ASSERT(validType, "xrpl::adjustOwnerCountSigned : valid account sle type");
|
||||
if (!validType)
|
||||
return; // LCOV_EXCL_LINE
|
||||
|
||||
XRPL_ASSERT(adjustment, "xrpl::adjustOwnerCountSigned : nonzero adjustment input");
|
||||
|
||||
auto const accountID = accountSle->getAccountID(sfAccount);
|
||||
if (sponsorSle)
|
||||
{
|
||||
bool const validSponsorType = sponsorSle->getType() == ltACCOUNT_ROOT;
|
||||
XRPL_ASSERT(validSponsorType, "xrpl::adjustOwnerCountSigned : valid sponsor sle type");
|
||||
if (!validSponsorType)
|
||||
return; // LCOV_EXCL_LINE
|
||||
auto const sponsorID = sponsorSle->getAccountID(sfAccount);
|
||||
|
||||
adjustOwnerCountImpl(view, accountSle, sfSponsoredOwnerCount, accountID, adjustment, j);
|
||||
adjustOwnerCountImpl(view, sponsorSle, sfSponsoringOwnerCount, sponsorID, adjustment, j);
|
||||
|
||||
auto sponsorshipSle = view.peek(keylet::sponsorship(sponsorID, accountID));
|
||||
if (sponsorshipSle && adjustment > 0)
|
||||
{
|
||||
// Only decrease the pre-funded ReserveCount on Sponsorship if we assign new objects.
|
||||
// Removing/reassigning ownership of the object doesn't increase RemainingOwnerCount
|
||||
// back. Don't call hook because this counter is not something that requires reserve
|
||||
// (like other sf...OwnerCounts do).
|
||||
adjustOwnerCountImpl(
|
||||
view, sponsorshipSle, sfRemainingOwnerCount, sponsorID, -adjustment, j, false);
|
||||
}
|
||||
}
|
||||
adjustOwnerCountImpl(view, accountSle, sfOwnerCount, accountID, adjustment, j);
|
||||
}
|
||||
|
||||
void
|
||||
increaseOwnerCount(
|
||||
ApplyView& view,
|
||||
ReserveContext const& reserveCtx,
|
||||
std::int32_t ownerCountAdj,
|
||||
std::uint32_t count,
|
||||
beast::Journal j)
|
||||
{
|
||||
auto& accountSle = reserveCtx.accountSle;
|
||||
if (!accountSle)
|
||||
XRPL_ASSERT(
|
||||
count != 0 && count <= std::numeric_limits<std::int32_t>::max(),
|
||||
"xrpl::increaseOwnerCount : count in signed delta range");
|
||||
if (count == 0 || count > std::numeric_limits<std::int32_t>::max())
|
||||
return; // LCOV_EXCL_LINE
|
||||
|
||||
auto const sleType = reserveCtx.accountSle->getType();
|
||||
bool const validType = reserveCtx.sponsorSle
|
||||
? sleType == ltACCOUNT_ROOT
|
||||
: sleType == ltLOAN_BROKER || sleType == ltACCOUNT_ROOT;
|
||||
if (!validType)
|
||||
adjustOwnerCountSigned(
|
||||
view, reserveCtx.accountSle, reserveCtx.sponsorSle, static_cast<std::int32_t>(count), j);
|
||||
}
|
||||
|
||||
void
|
||||
decreaseOwnerCount(
|
||||
ApplyView& view,
|
||||
ReserveContext const& reserveCtx,
|
||||
std::uint32_t count,
|
||||
beast::Journal j)
|
||||
{
|
||||
XRPL_ASSERT(
|
||||
count != 0 && count <= std::numeric_limits<std::int32_t>::max(),
|
||||
"xrpl::decreaseOwnerCount : count in signed delta range");
|
||||
if (count == 0 || count > std::numeric_limits<std::int32_t>::max())
|
||||
return; // LCOV_EXCL_LINE
|
||||
|
||||
XRPL_ASSERT(ownerCountAdj, "xrpl::adjustOwnerCountSigned : nonzero adjustment input");
|
||||
|
||||
if (reserveCtx.isSponsored())
|
||||
{
|
||||
if (reserveCtx.sponsorSle->getType() != ltACCOUNT_ROOT)
|
||||
Throw<std::logic_error>("xrpl::adjustOwnerCount : valid sponsor sle type");
|
||||
|
||||
adjustOwnerCountValue(
|
||||
view,
|
||||
reserveCtx.accountSle,
|
||||
sfSponsoredOwnerCount,
|
||||
reserveCtx.accountID(),
|
||||
ownerCountAdj,
|
||||
j);
|
||||
adjustOwnerCountValue(
|
||||
view,
|
||||
reserveCtx.sponsorSle,
|
||||
sfSponsoringOwnerCount,
|
||||
reserveCtx.sponsorID().value(),
|
||||
ownerCountAdj,
|
||||
j);
|
||||
|
||||
if (reserveCtx.sponsorshipSle && ownerCountAdj > 0)
|
||||
{
|
||||
// update the pre-funded RemainingOwnerCount on Sponsorship ledger object
|
||||
// Remaining owner count moves opposite to ownerCountAdj:
|
||||
// +ownerCountAdj => consume reserve (-),
|
||||
adjustOwnerCountValue(
|
||||
view,
|
||||
reserveCtx.sponsorshipSle,
|
||||
sfRemainingOwnerCount,
|
||||
reserveCtx.sponsorID().value(),
|
||||
-ownerCountAdj,
|
||||
j,
|
||||
false);
|
||||
}
|
||||
}
|
||||
adjustOwnerCountValue(
|
||||
view, reserveCtx.accountSle, sfOwnerCount, reserveCtx.accountID(), ownerCountAdj, j);
|
||||
adjustOwnerCountSigned(
|
||||
view, reserveCtx.accountSle, reserveCtx.sponsorSle, -static_cast<std::int32_t>(count), j);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -276,7 +298,7 @@ decreaseOwnerCountForObject(
|
||||
ApplyView& view,
|
||||
SLE::pointer ownerSle,
|
||||
SLE::ref objectSle,
|
||||
std::int32_t ownerCountAdj,
|
||||
std::int32_t count,
|
||||
beast::Journal j)
|
||||
{
|
||||
XRPL_ASSERT(objectSle, "xrpl::decreaseOwnerCountForObject : valid object sle");
|
||||
@@ -288,8 +310,7 @@ decreaseOwnerCountForObject(
|
||||
if (!validObjectType)
|
||||
return; // LCOV_EXCL_LINE
|
||||
|
||||
increaseOwnerCount(
|
||||
view, ReserveContext::makeFromObject(view, objectSle, ownerSle), ownerCountAdj, j);
|
||||
increaseOwnerCount(view, ReserveContext::makeFromObject(view, objectSle, ownerSle), -count, j);
|
||||
}
|
||||
XRPAmount
|
||||
accountReserve(ReadView const& view, SLE::const_ref sle, beast::Journal j, Adjustment adj)
|
||||
|
||||
@@ -98,7 +98,7 @@ deleteSLE(ApplyView& view, SLE::ref sleCredential, beast::Journal j)
|
||||
|
||||
if (isOwner)
|
||||
decreaseOwnerCountForObject(
|
||||
view, view.peek(keylet::account(account)), sleCredential, -1, j);
|
||||
view, view.peek(keylet::account(account)), sleCredential, 1, j);
|
||||
|
||||
return tesSUCCESS;
|
||||
};
|
||||
|
||||
@@ -185,7 +185,7 @@ authorizeMPToken(
|
||||
keylet::ownerDir(account), (*sleMpt)[sfOwnerNode], sleMpt->key(), false))
|
||||
return tecINTERNAL; // LCOV_EXCL_LINE
|
||||
|
||||
decreaseOwnerCountForObject(ctx.view, reserveCtx.accountSle, sleMpt, -1, journal);
|
||||
decreaseOwnerCountForObject(ctx.view, reserveCtx.accountSle, sleMpt, 1, journal);
|
||||
|
||||
ctx.view.erase(sleMpt);
|
||||
return tesSUCCESS;
|
||||
|
||||
@@ -56,7 +56,7 @@ offerDelete(ApplyView& view, SLE::ref sle, beast::Journal j)
|
||||
}
|
||||
|
||||
auto const ownerSle = view.peek(keylet::account(owner));
|
||||
decreaseOwnerCountForObject(view, ownerSle, sle, -1, j);
|
||||
decreaseOwnerCountForObject(view, ownerSle, sle, 1, j);
|
||||
|
||||
view.erase(sle);
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ CheckCancel::doApply()
|
||||
}
|
||||
|
||||
// If we succeeded, update the check owner's reserve.
|
||||
decreaseOwnerCountForObject(view(), view().peek(keylet::account(srcId)), sleCheck, -1, viewJ);
|
||||
decreaseOwnerCountForObject(view(), view().peek(keylet::account(srcId)), sleCheck, 1, viewJ);
|
||||
|
||||
// Remove check from ledger.
|
||||
view().erase(sleCheck);
|
||||
|
||||
@@ -392,7 +392,7 @@ EscrowFinish::doApply()
|
||||
|
||||
// Adjust source owner count
|
||||
decreaseOwnerCountForObject(
|
||||
ctx_.view(), ctx_.view().peek(keylet::account(account)), slep, -1, ctx_.journal);
|
||||
ctx_.view(), ctx_.view().peek(keylet::account(account)), slep, 1, ctx_.journal);
|
||||
|
||||
// Remove escrow from ledger
|
||||
ctx_.view().erase(slep);
|
||||
|
||||
@@ -49,7 +49,7 @@ MPTokenIssuanceDestroy::doApply()
|
||||
if (!view().dirRemove(keylet::ownerDir(accountID_), (*mpt)[sfOwnerNode], mpt->key(), false))
|
||||
return tefBAD_LEDGER; // LCOV_EXCL_LINE
|
||||
|
||||
decreaseOwnerCountForObject(view(), view().peek(keylet::account(accountID_)), mpt, -1, j_);
|
||||
decreaseOwnerCountForObject(view(), view().peek(keylet::account(accountID_)), mpt, 1, j_);
|
||||
view().erase(mpt);
|
||||
|
||||
return tesSUCCESS;
|
||||
|
||||
Reference in New Issue
Block a user