Compare commits

...

10 Commits

Author SHA1 Message Date
Bronek Kozicki
99935390ce Merge branch 'develop' into Bronek/Vault_calculation_error 2025-11-07 18:31:40 +00:00
Bronek Kozicki
0d102a6bb9 Improved unit test 2025-11-07 11:21:59 +00:00
Michael Legleux
c39f9c561c chore: Point xrpld symlink to rippled (#6012)
As part of renaming ripple(d) to xrpl(d), the xrpld symlink was made to point to itself instead of to the rippled binary. This change fixes the symlink.
2025-11-07 10:51:12 +00:00
Bronek Kozicki
1b2ff92c01 Merge branch 'develop' into HEAD 2025-11-06 16:51:03 +00:00
Bronek Kozicki
7c36576eac Fix unit tests 2025-11-06 16:50:06 +00:00
Bronek Kozicki
f769d2ac1f Add comments to explain test 2025-11-06 16:49:07 +00:00
Bart
173f9f7bb0 chore: Removes unnecessary creation of symlink in CMake install file (#6009) 2025-11-06 09:06:45 +00:00
Shawn Xie
28a1f90938 fix: domain order book insertion #5998 2025-11-05 23:08:10 +00:00
Bronek Kozicki
a1f25346ee Merge branch 'develop' into Bronek/Vault_calculation_error 2025-11-04 17:12:21 +00:00
Bronek Kozicki
4991aa3ffc Fix floating point representation errors in vault 2025-11-04 17:00:36 +00:00
5 changed files with 96 additions and 15 deletions

View File

@@ -74,12 +74,19 @@ if grep -q '"xrpld"' cmake/XrplCore.cmake; then
# The script has been rerun, so just restore the name of the binary.
${SED_COMMAND} -i 's/"xrpld"/"rippled"/' cmake/XrplCore.cmake
elif ! grep -q '"rippled"' cmake/XrplCore.cmake; then
ghead -n -1 cmake/XrplCore.cmake > cmake.tmp
${HEAD_COMMAND} -n -1 cmake/XrplCore.cmake > cmake.tmp
echo ' # For the time being, we will keep the name of the binary as it was.' >> cmake.tmp
echo ' set_target_properties(xrpld PROPERTIES OUTPUT_NAME "rippled")' >> cmake.tmp
tail -1 cmake/XrplCore.cmake >> cmake.tmp
mv cmake.tmp cmake/XrplCore.cmake
fi
# Restore the symlink from 'xrpld' to 'rippled'.
${SED_COMMAND} -i -E 's@create_symbolic_link\(xrpld@create_symbolic_link(rippled@' cmake/XrplInstall.cmake
# Remove the symlink that previously pointed from 'ripple' to 'xrpl' but now is
# no longer needed.
${SED_COMMAND} -z -i -E 's@install\(CODE.+CMAKE_INSTALL_INCLUDEDIR}/xrpl\)\n"\)\n+@@' cmake/XrplInstall.cmake
popd
echo "Renaming complete."

View File

@@ -37,13 +37,6 @@ install(
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
install(CODE "
set(CMAKE_MODULE_PATH \"${CMAKE_MODULE_PATH}\")
include(create_symbolic_link)
create_symbolic_link(xrpl \
\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/xrpl)
")
install (EXPORT XrplExports
FILE XrplTargets.cmake
NAMESPACE Xrpl::
@@ -74,7 +67,7 @@ if (is_root_project AND TARGET xrpld)
install(CODE "
set(CMAKE_MODULE_PATH \"${CMAKE_MODULE_PATH}\")
include(create_symbolic_link)
create_symbolic_link(xrpld${suffix} \
create_symbolic_link(rippled${suffix} \
\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/xrpld${suffix})
")
endif ()

View File

@@ -2885,7 +2885,7 @@ assetsToSharesDeposit(
.truncate()};
Number const shareTotal = issuance->at(sfOutstandingAmount);
shares = (shareTotal * (assets / assetTotal)).truncate();
shares = ((shareTotal * assets) / assetTotal).truncate();
return shares;
}
@@ -2914,7 +2914,7 @@ sharesToAssetsDeposit(
false};
Number const shareTotal = issuance->at(sfOutstandingAmount);
assets = assetTotal * (shares / shareTotal);
assets = (assetTotal * shares) / shareTotal;
return assets;
}
@@ -2940,7 +2940,7 @@ assetsToSharesWithdraw(
if (assetTotal == 0)
return shares;
Number const shareTotal = issuance->at(sfOutstandingAmount);
Number result = shareTotal * (assets / assetTotal);
Number result = (shareTotal * assets) / assetTotal;
if (truncate == TruncateShares::yes)
result = result.truncate();
shares = result;
@@ -2968,7 +2968,7 @@ sharesToAssetsWithdraw(
if (assetTotal == 0)
return assets;
Number const shareTotal = issuance->at(sfOutstandingAmount);
assets = assetTotal * (shares / shareTotal);
assets = (assetTotal * shares) / shareTotal;
return assets;
}

View File

@@ -2454,6 +2454,7 @@ class Vault_test : public beast::unit_test::suite
struct CaseArgs
{
int initialXRP = 1000;
Number initialIOU = 200;
double transferRate = 1.0;
};
@@ -2481,7 +2482,7 @@ class Vault_test : public beast::unit_test::suite
PrettyAsset const asset = issuer["IOU"];
env.trust(asset(1000), owner);
env.trust(asset(1000), charlie);
env(pay(issuer, owner, asset(200)));
env(pay(issuer, owner, asset(args.initialIOU)));
env(rate(issuer, args.transferRate));
env.close();
@@ -2859,6 +2860,86 @@ class Vault_test : public beast::unit_test::suite
env(tx1);
});
testCase(
[&, this](
Env& env,
Account const& owner,
Account const& issuer,
Account const& charlie,
auto const& vaultAccount,
Vault& vault,
PrettyAsset const& asset,
auto&&...) {
testcase("IOU calculation rounding");
auto [tx, keylet] =
vault.create({.owner = owner, .asset = asset});
tx[sfScale] = 1;
env(tx);
env.close();
auto const startingOwnerBalance = env.balance(owner, asset);
BEAST_EXPECT(
(startingOwnerBalance.value() ==
STAmount{asset, 11875, -2}));
// This operation (first deposit 100, then 3.75 x 5) is known to
// have triggered calculation rounding errors in Number
// (addition and division), causing the last deposit to be
// blocked by Vault invariants.
env(vault.deposit(
{.depositor = owner,
.id = keylet.key,
.amount = asset(100)}));
auto const tx1 = vault.deposit(
{.depositor = owner,
.id = keylet.key,
.amount = asset(Number(375, -2))});
for (auto i = 0; i < 5; ++i)
{
env(tx1);
}
env.close();
{
STAmount const xfer{asset, 1185, -1};
BEAST_EXPECT(
env.balance(owner, asset) ==
startingOwnerBalance.value() - xfer);
BEAST_EXPECT(
env.balance(vaultAccount(keylet), asset) == xfer);
auto const vault = env.le(keylet);
BEAST_EXPECT(vault->at(sfAssetsAvailable) == xfer);
BEAST_EXPECT(vault->at(sfAssetsTotal) == xfer);
}
// Total vault balance should be 118.5 IOU. Withdraw and delete
// the vault to verify this exact amount was deposited and the
// owner has matching shares
env(vault.withdraw(
{.depositor = owner,
.id = keylet.key,
.amount = asset(Number(1000 + 37 * 5, -1))}));
{
BEAST_EXPECT(
env.balance(owner, asset) ==
startingOwnerBalance.value());
BEAST_EXPECT(
env.balance(vaultAccount(keylet), asset) ==
beast::zero);
auto const vault = env.le(keylet);
BEAST_EXPECT(vault->at(sfAssetsAvailable) == beast::zero);
BEAST_EXPECT(vault->at(sfAssetsTotal) == beast::zero);
}
env(vault.del({.owner = owner, .id = keylet.key}));
env.close();
},
{.initialIOU = Number(11875, -2)});
auto const [acctReserve, incReserve] = [this]() -> std::pair<int, int> {
Env env{*this, testable_amendments()};
return {

View File

@@ -106,7 +106,7 @@ OrderBookDB::update(std::shared_ptr<ReadView const> const& ledger)
book.domain = (*sle)[~sfDomainID];
if (book.domain)
domainBooks_[{book.in, *book.domain}].insert(book.out);
domainBooks[{book.in, *book.domain}].insert(book.out);
else
allBooks[book.in].insert(book.out);