Compare commits

..

26 Commits

Author SHA1 Message Date
Ed Hennis
9b40cdb4d9 Merge branch 'develop' into ximinez/test.net.diagnostic 2026-01-15 13:16:42 -04:00
Ed Hennis
32324f2580 Merge branch 'develop' into ximinez/test.net.diagnostic 2026-01-15 12:06:33 -04:00
Ed Hennis
ca3bd64baa Merge branch 'develop' into ximinez/test.net.diagnostic 2026-01-13 19:23:12 -04:00
Ed Hennis
528248cf03 Merge branch 'develop' into ximinez/test.net.diagnostic 2026-01-13 15:35:40 -04:00
Ed Hennis
8b493b13e0 Merge branch 'develop' into ximinez/test.net.diagnostic 2026-01-12 14:52:50 -04:00
Ed Hennis
22d98a6bb4 Merge branch 'develop' into ximinez/test.net.diagnostic 2026-01-11 00:55:50 -04:00
Ed Hennis
12bcec125c Merge branch 'develop' into ximinez/test.net.diagnostic 2026-01-08 17:07:28 -04:00
Ed Hennis
9f844f07af Merge branch 'develop' into ximinez/test.net.diagnostic 2026-01-08 13:05:47 -04:00
Ed Hennis
326fd8d2b7 Merge branch 'develop' into ximinez/test.net.diagnostic 2026-01-06 14:03:01 -05:00
Ed Hennis
2a74accef3 Merge branch 'develop' into ximinez/test.net.diagnostic 2025-12-22 17:51:46 -05:00
Ed Hennis
e726e0d053 Merge branch 'develop' into ximinez/test.net.diagnostic 2025-12-18 20:00:32 -05:00
Ed Hennis
ebda3167b5 Merge branch 'develop' into ximinez/test.net.diagnostic 2025-12-12 20:39:51 -05:00
Ed Hennis
38fa83ac9d Merge branch 'develop' into ximinez/test.net.diagnostic 2025-12-11 16:14:53 -05:00
Ed Hennis
14c2ceb1f9 Merge branch 'develop' into ximinez/test.net.diagnostic 2025-12-05 21:13:51 -05:00
Ed Hennis
8941f7f3cf Merge branch 'develop' into ximinez/test.net.diagnostic 2025-12-02 19:07:01 -05:00
Ed Hennis
eb8f2e6279 Merge branch 'develop' into ximinez/test.net.diagnostic 2025-12-01 14:41:27 -05:00
Ed Hennis
a0f044f69d Merge branch 'develop' into ximinez/test.net.diagnostic 2025-11-28 15:53:07 -05:00
Ed Hennis
d7f0653f77 Merge branch 'develop' into ximinez/test.net.diagnostic 2025-11-26 00:26:00 -05:00
Ed Hennis
f2d4de23f1 Merge branch 'develop' into ximinez/test.net.diagnostic 2025-11-24 21:49:51 -05:00
Ed Hennis
1c52385243 Merge branch 'develop' into ximinez/test.net.diagnostic 2025-11-24 21:43:13 -05:00
Ed Hennis
603ec19038 Merge branch 'develop' into ximinez/test.net.diagnostic 2025-11-21 14:38:50 -05:00
Ed Hennis
0aab9ce44c Merge branch 'develop' into ximinez/test.net.diagnostic 2025-11-18 22:51:44 -05:00
Ed Hennis
e4b18fd92b Merge branch 'develop' into ximinez/test.net.diagnostic 2025-11-15 03:13:03 -05:00
Ed Hennis
2bf218344b Merge branch 'develop' into ximinez/test.net.diagnostic 2025-11-13 12:21:16 -05:00
Ed Hennis
88e7ceef6a Merge branch 'develop' into ximinez/test.net.diagnostic 2025-11-12 14:17:27 -05:00
Ed Hennis
0e6b981a56 Add logs of what's going on - Simple RIAA activity tracer 2025-11-10 19:54:39 -05:00
2 changed files with 201 additions and 246 deletions

View File

@@ -2167,105 +2167,6 @@ rippleSendIOU(
return terResult;
}
template <class TAsset>
static TER
doSendMulti(
std::string const& name,
ApplyView& view,
AccountID const& senderID,
TAsset const& issue,
MultiplePaymentDestinations const& receivers,
STAmount& actual,
beast::Journal j,
WaiveTransferFee waiveFee,
// Don't pass back parameters that the caller already has
std::function<
TER(AccountID const& senderID,
AccountID const& receiverID,
STAmount const& amount,
bool checkIssuer)> doCredit,
std::function<
TER(AccountID const& issuer,
STAmount const& takeFromSender,
STAmount const& amount)> preMint = {})
{
// Use the same pattern for all the SendMulti functions to help avoid
// divergence and copy/paste errors.
auto const& issuer = issue.getIssuer();
// These values may not stay in sync
STAmount takeFromSender{issue};
actual = takeFromSender;
// Failures return immediately.
for (auto const& r : receivers)
{
auto const& receiverID = r.first;
STAmount amount{issue, r.second};
if (amount < beast::zero)
{
return tecINTERNAL; // LCOV_EXCL_LINE
}
/* If we aren't sending anything or if the sender is the same as the
* receiver then we don't need to do anything.
*/
if (!amount || (senderID == receiverID))
continue;
using namespace std::string_literals;
XRPL_ASSERT(
!isXRP(receiverID),
("xrpl::"s + name + " : receiver is not XRP").c_str());
if (senderID == issuer || receiverID == issuer || issuer == noAccount())
{
if (preMint)
{
if (auto const ter = preMint(issuer, takeFromSender, amount))
return ter;
}
// Direct send: redeeming IOUs and/or sending own IOUs.
if (auto const ter = doCredit(senderID, receiverID, amount, false))
return ter;
actual += amount;
// Do not add amount to takeFromSender, because doCredit took
// it.
continue;
}
// Sending 3rd party: transit.
// Calculate the amount to transfer accounting
// for any transfer fees if the fee is not waived:
STAmount actualSend =
(waiveFee == WaiveTransferFee::Yes || issue.native())
? amount
: multiply(amount, transferRate(view, amount));
actual += actualSend;
takeFromSender += actualSend;
JLOG(j.debug()) << name << "> " << to_string(senderID) << " - > "
<< to_string(receiverID)
<< " : deliver=" << amount.getFullText()
<< " cost=" << actualSend.getFullText();
if (TER const terResult = doCredit(issuer, receiverID, amount, true))
return terResult;
}
if (senderID != issuer && takeFromSender)
{
if (TER const terResult =
doCredit(senderID, issuer, takeFromSender, true))
return terResult;
}
return tesSUCCESS;
}
// Send regardless of limits.
// --> receivers: Amount/currency/issuer to deliver to receivers.
// <-- saActual: Amount actually cost to sender. Sender pays fees.
@@ -2279,28 +2180,72 @@ rippleSendMultiIOU(
beast::Journal j,
WaiveTransferFee waiveFee)
{
auto const& issuer = issue.getIssuer();
XRPL_ASSERT(
!isXRP(senderID), "xrpl::rippleSendMultiIOU : sender is not XRP");
auto doCredit = [&view, j](
AccountID const& senderID,
AccountID const& receiverID,
STAmount const& amount,
bool checkIssuer) {
return rippleCreditIOU(
view, senderID, receiverID, amount, checkIssuer, j);
};
// These may diverge
STAmount takeFromSender{issue};
actual = takeFromSender;
return doSendMulti(
"rippleSendMultiIOU",
view,
senderID,
issue,
receivers,
actual,
j,
waiveFee,
doCredit);
// Failures return immediately.
for (auto const& r : receivers)
{
auto const& receiverID = r.first;
STAmount amount{issue, r.second};
/* If we aren't sending anything or if the sender is the same as the
* receiver then we don't need to do anything.
*/
if (!amount || (senderID == receiverID))
continue;
XRPL_ASSERT(
!isXRP(receiverID),
"xrpl::rippleSendMultiIOU : receiver is not XRP");
if (senderID == issuer || receiverID == issuer || issuer == noAccount())
{
// Direct send: redeeming IOUs and/or sending own IOUs.
if (auto const ter = rippleCreditIOU(
view, senderID, receiverID, amount, false, j))
return ter;
actual += amount;
// Do not add amount to takeFromSender, because rippleCreditIOU took
// it.
continue;
}
// Sending 3rd party IOUs: transit.
// Calculate the amount to transfer accounting
// for any transfer fees if the fee is not waived:
STAmount actualSend = (waiveFee == WaiveTransferFee::Yes)
? amount
: multiply(amount, transferRate(view, issuer));
actual += actualSend;
takeFromSender += actualSend;
JLOG(j.debug()) << "rippleSendMultiIOU> " << to_string(senderID)
<< " - > " << to_string(receiverID)
<< " : deliver=" << amount.getFullText()
<< " cost=" << actual.getFullText();
if (TER const terResult =
rippleCreditIOU(view, issuer, receiverID, amount, true, j))
return terResult;
}
if (senderID != issuer && takeFromSender)
{
if (TER const terResult = rippleCreditIOU(
view, senderID, issuer, takeFromSender, true, j))
return terResult;
}
return tesSUCCESS;
}
static TER
@@ -2441,9 +2386,9 @@ accountSendMultiIOU(
"xrpl::accountSendMultiIOU",
"multiple recipients provided");
STAmount actual;
if (!issue.native())
{
STAmount actual;
JLOG(j.trace()) << "accountSendMultiIOU: " << to_string(senderID)
<< " sending " << receivers.size() << " IOUs";
@@ -2472,97 +2417,6 @@ accountSendMultiIOU(
<< sender_bal << ") -> " << receivers.size() << " receivers.";
}
auto doCredit = [&view, &sender, &receivers, j](
AccountID const& senderID,
AccountID const& receiverID,
STAmount const& amount,
bool /*checkIssuer*/) -> TER {
if (!senderID)
{
SLE::pointer receiver = receiverID != beast::zero
? view.peek(keylet::account(receiverID))
: SLE::pointer();
if (auto stream = j.trace())
{
std::string receiver_bal("-");
if (receiver)
receiver_bal =
receiver->getFieldAmount(sfBalance).getFullText();
stream << "accountSendMultiIOU> " << to_string(senderID)
<< " -> " << to_string(receiverID) << " ("
<< receiver_bal << ") : " << amount.getFullText();
}
if (receiver)
{
// Increment XRP balance.
auto const rcvBal = receiver->getFieldAmount(sfBalance);
receiver->setFieldAmount(sfBalance, rcvBal + amount);
view.creditHook(xrpAccount(), receiverID, amount, -rcvBal);
view.update(receiver);
}
if (auto stream = j.trace())
{
std::string receiver_bal("-");
if (receiver)
receiver_bal =
receiver->getFieldAmount(sfBalance).getFullText();
stream << "accountSendMultiIOU< " << to_string(senderID)
<< " -> " << to_string(receiverID) << " ("
<< receiver_bal << ") : " << amount.getFullText();
}
return tesSUCCESS;
}
// Sender
if (sender)
{
if (sender->getFieldAmount(sfBalance) < amount)
{
return TER{tecFAILED_PROCESSING};
}
else
{
auto const sndBal = sender->getFieldAmount(sfBalance);
view.creditHook(senderID, xrpAccount(), amount, sndBal);
// Decrement XRP balance.
sender->setFieldAmount(sfBalance, sndBal - amount);
view.update(sender);
}
}
if (auto stream = j.trace())
{
std::string sender_bal("-");
if (sender)
sender_bal = sender->getFieldAmount(sfBalance).getFullText();
stream << "accountSendMultiIOU< " << to_string(senderID) << " ("
<< sender_bal << ") -> " << receivers.size()
<< " receivers.";
}
return tesSUCCESS;
};
return doSendMulti(
"accountSendMultiIOU",
view,
senderID,
issue,
receivers,
actual,
j,
waiveFee,
doCredit);
// Failures return immediately.
STAmount takeFromSender{issue};
for (auto const& r : receivers)
@@ -2794,51 +2648,90 @@ rippleSendMultiMPT(
beast::Journal j,
WaiveTransferFee waiveFee)
{
// Safe to get MPT since rippleSendMultiMPT is only called by
// accountSendMultiMPT
auto const& issuer = mptIssue.getIssuer();
auto const sle = view.read(keylet::mptIssuance(mptIssue.getMptID()));
if (!sle)
return tecOBJECT_NOT_FOUND;
auto preMint = [&](AccountID const& issuer,
STAmount const& takeFromSender,
STAmount const& amount) -> TER {
// if sender is issuer, check that the new OutstandingAmount will
// not exceed MaximumAmount
if (senderID == issuer)
// These may diverge
STAmount takeFromSender{mptIssue};
actual = takeFromSender;
for (auto const& r : receivers)
{
auto const& receiverID = r.first;
STAmount amount{mptIssue, r.second};
if (amount < beast::zero)
{
XRPL_ASSERT_PARTS(
takeFromSender == beast::zero,
"rippler::rippleSendMultiMPT",
"sender == issuer, takeFromSender == zero");
auto const sendAmount = amount.mpt().value();
auto const maximumAmount =
sle->at(~sfMaximumAmount).value_or(maxMPTokenAmount);
if (sendAmount > maximumAmount ||
sle->getFieldU64(sfOutstandingAmount) >
maximumAmount - sendAmount)
return tecPATH_DRY;
return tecINTERNAL; // LCOV_EXCL_LINE
}
return tesSUCCESS;
};
auto doCredit = [&view, j](
AccountID const& senderID,
AccountID const& receiverID,
STAmount const& amount,
bool) {
return rippleCreditMPT(view, senderID, receiverID, amount, j);
};
/* If we aren't sending anything or if the sender is the same as the
* receiver then we don't need to do anything.
*/
if (!amount || (senderID == receiverID))
continue;
return doSendMulti(
"rippleSendMultiMPT",
view,
senderID,
mptIssue,
receivers,
actual,
j,
waiveFee,
doCredit,
preMint);
if (senderID == issuer || receiverID == issuer)
{
// if sender is issuer, check that the new OutstandingAmount will
// not exceed MaximumAmount
if (senderID == issuer)
{
XRPL_ASSERT_PARTS(
takeFromSender == beast::zero,
"rippler::rippleSendMultiMPT",
"sender == issuer, takeFromSender == zero");
auto const sendAmount = amount.mpt().value();
auto const maximumAmount =
sle->at(~sfMaximumAmount).value_or(maxMPTokenAmount);
if (sendAmount > maximumAmount ||
sle->getFieldU64(sfOutstandingAmount) >
maximumAmount - sendAmount)
return tecPATH_DRY;
}
// Direct send: redeeming MPTs and/or sending own MPTs.
if (auto const ter =
rippleCreditMPT(view, senderID, receiverID, amount, j))
return ter;
actual += amount;
// Do not add amount to takeFromSender, because rippleCreditMPT took
// it
continue;
}
// Sending 3rd party MPTs: transit.
STAmount actualSend = (waiveFee == WaiveTransferFee::Yes)
? amount
: multiply(
amount,
transferRate(view, amount.get<MPTIssue>().getMptID()));
actual += actualSend;
takeFromSender += actualSend;
JLOG(j.debug()) << "rippleSendMultiMPT> " << to_string(senderID)
<< " - > " << to_string(receiverID)
<< " : deliver=" << amount.getFullText()
<< " cost=" << actualSend.getFullText();
if (auto const terResult =
rippleCreditMPT(view, issuer, receiverID, amount, j))
return terResult;
}
if (senderID != issuer && takeFromSender)
{
if (TER const terResult =
rippleCreditMPT(view, senderID, issuer, takeFromSender, j))
return terResult;
}
return tesSUCCESS;
}
static TER

View File

@@ -10,6 +10,7 @@
#include <gtest/gtest.h>
#include <atomic>
#include <iostream>
#include <map>
#include <thread>
@@ -17,6 +18,40 @@ using namespace xrpl;
namespace {
struct logger
{
std::string name;
logger const* const parent = nullptr;
static std::size_t depth;
logger(std::string n) : name(n)
{
std::clog << indent() << name << " begin\n";
++depth;
}
logger(logger const& p, std::string n) : parent(&p), name(n)
{
std::clog << indent() << parent->name << " : " << name << " begin\n";
++depth;
}
~logger()
{
--depth;
if (parent)
std::clog << indent() << parent->name << " : " << name << " end\n";
else
std::clog << indent() << name << " end\n";
}
std::string
indent()
{
return std::string(depth, ' ');
}
};
std::size_t logger::depth = 0;
// Simple HTTP server using Beast for testing
class TestHTTPServer
{
@@ -35,6 +70,7 @@ private:
public:
TestHTTPServer() : acceptor_(ioc_), port_(0)
{
logger l("TestHTTPServer()");
// Bind to any available port
endpoint_ = {boost::asio::ip::tcp::v4(), 0};
acceptor_.open(endpoint_.protocol());
@@ -50,6 +86,7 @@ public:
~TestHTTPServer()
{
logger l("~TestHTTPServer()");
stop();
}
@@ -87,6 +124,7 @@ private:
void
stop()
{
logger l("TestHTTPServer::stop");
running_ = false;
acceptor_.close();
}
@@ -94,6 +132,7 @@ private:
void
accept()
{
logger l("TestHTTPServer::accept");
if (!running_)
return;
@@ -115,31 +154,37 @@ private:
void
handleConnection(boost::asio::ip::tcp::socket socket)
{
logger l("TestHTTPServer::handleConnection");
try
{
std::optional<logger> r(std::in_place, l, "read the http request");
// Read the HTTP request
boost::beast::flat_buffer buffer;
boost::beast::http::request<boost::beast::http::string_body> req;
boost::beast::http::read(socket, buffer, req);
// Create response
r.emplace(l, "create response");
boost::beast::http::response<boost::beast::http::string_body> res;
res.version(req.version());
res.result(status_code_);
res.set(boost::beast::http::field::server, "TestServer");
// Add custom headers
r.emplace(l, "add custom headers");
for (auto const& [name, value] : custom_headers_)
{
res.set(name, value);
}
// Set body and prepare payload first
r.emplace(l, "set body and prepare payload");
res.body() = response_body_;
res.prepare_payload();
// Override Content-Length with custom headers after prepare_payload
// This allows us to test case-insensitive header parsing
r.emplace(l, "override content-length");
for (auto const& [name, value] : custom_headers_)
{
if (boost::iequals(name, "Content-Length"))
@@ -150,19 +195,25 @@ private:
}
// Send response
r.emplace(l, "send response");
boost::beast::http::write(socket, res);
// Shutdown socket gracefully
r.emplace(l, "shutdown socket");
boost::system::error_code ec;
socket.shutdown(boost::asio::ip::tcp::socket::shutdown_send, ec);
}
catch (std::exception const&)
{
// Connection handling errors are expected
logger c(l, "catch");
}
if (running_)
{
logger r(l, "accept");
accept();
}
}
};
@@ -176,12 +227,16 @@ runHTTPTest(
std::string& result_data,
boost::system::error_code& result_error)
{
logger l("runHTTPTest");
// Create a null journal for testing
beast::Journal j{beast::Journal::getNullSink()};
std::optional<logger> r(std::in_place, l, "initializeSSLContext");
// Initialize HTTPClient SSL context
HTTPClient::initializeSSLContext("", "", false, j);
r.emplace(l, "HTTPClient::get");
HTTPClient::get(
false, // no SSL
server.ioc(),
@@ -206,6 +261,7 @@ runHTTPTest(
while (!completed &&
std::chrono::steady_clock::now() - start < std::chrono::seconds(10))
{
r.emplace(l, "ioc.run_one");
if (server.ioc().run_one() == 0)
{
break;
@@ -219,6 +275,8 @@ runHTTPTest(
TEST(HTTPClient, case_insensitive_content_length)
{
logger l("HTTPClient case insensitive Content-Length");
// Test different cases of Content-Length header
std::vector<std::string> header_cases = {
"Content-Length", // Standard case
@@ -230,6 +288,7 @@ TEST(HTTPClient, case_insensitive_content_length)
for (auto const& header_name : header_cases)
{
logger h(l, header_name);
TestHTTPServer server;
std::string test_body = "Hello World!";
server.setResponseBody(test_body);
@@ -258,6 +317,7 @@ TEST(HTTPClient, case_insensitive_content_length)
TEST(HTTPClient, basic_http_request)
{
logger l("HTTPClient basic HTTP request");
TestHTTPServer server;
std::string test_body = "Test response body";
server.setResponseBody(test_body);
@@ -279,6 +339,7 @@ TEST(HTTPClient, basic_http_request)
TEST(HTTPClient, empty_response)
{
logger l("HTTPClient empty response");
TestHTTPServer server;
server.setResponseBody(""); // Empty body
server.setHeader("Content-Length", "0");
@@ -299,6 +360,7 @@ TEST(HTTPClient, empty_response)
TEST(HTTPClient, different_status_codes)
{
logger l("HTTPClient different status codes");
std::vector<unsigned int> status_codes = {200, 404, 500};
for (auto status : status_codes)