fix: Apply object reserve for Vault pseudo-account (#5954)

This commit is contained in:
Bronek Kozicki
2025-11-14 17:30:56 +00:00
committed by GitHub
parent 7025e92080
commit 362ecbd1cb
5 changed files with 47 additions and 21 deletions

View File

@@ -79,13 +79,6 @@ VaultCreate::preflight(PreflightContext const& ctx)
return tesSUCCESS;
}
XRPAmount
VaultCreate::calculateBaseFee(ReadView const& view, STTx const& tx)
{
// One reserve increment is typically much greater than one base fee.
return calculateOwnerReserveFee(view, tx);
}
TER
VaultCreate::preclaim(PreclaimContext const& ctx)
{
@@ -142,8 +135,9 @@ VaultCreate::doApply()
if (auto ter = dirLink(view(), account_, vault))
return ter;
adjustOwnerCount(view(), owner, 1, j_);
auto ownerCount = owner->at(sfOwnerCount);
// We will create Vault and PseudoAccount, hence increase OwnerCount by 2
adjustOwnerCount(view(), owner, 2, j_);
auto const ownerCount = owner->at(sfOwnerCount);
if (mPriorBalance < view().fees().accountReserve(ownerCount))
return tecINSUFFICIENT_RESERVE;

View File

@@ -23,9 +23,6 @@ public:
static NotTEC
preflight(PreflightContext const& ctx);
static XRPAmount
calculateBaseFee(ReadView const& view, STTx const& tx);
static TER
preclaim(PreclaimContext const& ctx);

View File

@@ -146,7 +146,35 @@ VaultDelete::doApply()
return tecHAS_OBLIGATIONS; // LCOV_EXCL_LINE
// Destroy the pseudo-account.
view().erase(view().peek(keylet::account(pseudoID)));
auto vaultPseudoSLE = view().peek(keylet::account(pseudoID));
if (!vaultPseudoSLE || vaultPseudoSLE->at(~sfVaultID) != vault->key())
return tefBAD_LEDGER; // LCOV_EXCL_LINE
// Making the payment and removing the empty holding should have deleted any
// obligations associated with the vault or vault pseudo-account.
if (*vaultPseudoSLE->at(sfBalance))
{
// LCOV_EXCL_START
JLOG(j_.error()) << "VaultDelete: pseudo-account has a balance";
return tecHAS_OBLIGATIONS;
// LCOV_EXCL_STOP
}
if (vaultPseudoSLE->at(sfOwnerCount) != 0)
{
// LCOV_EXCL_START
JLOG(j_.error()) << "VaultDelete: pseudo-account still owns objects";
return tecHAS_OBLIGATIONS;
// LCOV_EXCL_STOP
}
if (view().exists(keylet::ownerDir(pseudoID)))
{
// LCOV_EXCL_START
JLOG(j_.error()) << "VaultDelete: pseudo-account has a directory";
return tecHAS_OBLIGATIONS;
// LCOV_EXCL_STOP
}
view().erase(vaultPseudoSLE);
// Remove the vault from its owner's directory.
auto const ownerID = vault->at(sfOwner);
@@ -170,7 +198,9 @@ VaultDelete::doApply()
return tefBAD_LEDGER;
// LCOV_EXCL_STOP
}
adjustOwnerCount(view(), owner, -1, j_);
// We are destroying Vault and PseudoAccount, hence decrease by 2
adjustOwnerCount(view(), owner, -2, j_);
// Destroy the vault.
view().erase(vault);