Address clang-tidy findings in entry-point migration

- Suppress cppcoreguidelines-avoid-capturing-lambda-coroutines with
  NOLINT where lifetime is guaranteed: GRPCServer (thisShared keeps
  CallData alive), ServerHandler RPC/WS clients (captures by value,
  handler outlives JobQueue jobs), and PathMPT_test (test blocks on
  Gate::waitFor until the coroutine completes).
- Change ServerHandler::processRequest to take Output const& to fix
  cppcoreguidelines-rvalue-reference-param-not-moved.
- Replace std::lock_guard with std::scoped_lock in RipplePathFind.
- Remove redundant includes and default member initializer in
  Context.h, GRPCServer.h, RipplePathFind.cpp.
This commit is contained in:
Pratik Mankawde
2026-07-27 12:06:25 +01:00
parent 62839b1531
commit 072e11ecd1
7 changed files with 33 additions and 9 deletions

View File

@@ -135,6 +135,9 @@ public:
numSrc.reserve(RPC::Tuning::kMaxSrcCur);
for (std::uint8_t i = 0; i < RPC::Tuning::kMaxSrcCur; ++i)
numSrc.push_back(makeMptID(i, bob));
// Safe capture: the test blocks on g.waitFor() until the coroutine
// completes, so the captured locals outlive the coroutine.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines)
app.getJobQueue().postCoroTask(JtClient, "RPC-Client", [&](auto) -> CoroTask<void> {
context.params = xrpl::test::detail::rpf(alice, bob, usd, numSrc);
RPC::doCommand(context, result);
@@ -146,6 +149,9 @@ public:
// Test more than RPC::Tuning::max_src_cur source currencies.
numSrc.push_back(makeMptID(RPC::Tuning::kMaxSrcCur, bob));
// Safe capture: the test blocks on g.waitFor() until the coroutine
// completes, so the captured locals outlive the coroutine.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines)
app.getJobQueue().postCoroTask(JtClient, "RPC-Client", [&](auto) -> CoroTask<void> {
context.params = xrpl::test::detail::rpf(alice, bob, usd, numSrc);
RPC::doCommand(context, result);
@@ -162,6 +168,9 @@ public:
auto curm = MPTTester({.env = env, .issuer = alice, .holders = {bob}});
numSrc.push_back(curm.issuanceID());
}
// Safe capture: the test blocks on g.waitFor() until the coroutine
// completes, so the captured locals outlive the coroutine.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines)
app.getJobQueue().postCoroTask(JtClient, "RPC-Client", [&](auto) -> CoroTask<void> {
context.params = xrpl::test::detail::rpf(alice, bob, usd, {});
RPC::doCommand(context, result);
@@ -173,6 +182,9 @@ public:
// Test more than RPC::Tuning::max_auto_src_cur source currencies.
auto curm = MPTTester({.env = env, .issuer = alice, .holders = {bob}});
// Safe capture: the test blocks on g.waitFor() until the coroutine
// completes, so the captured locals outlive the coroutine.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines)
app.getJobQueue().postCoroTask(JtClient, "RPC-Client", [&](auto) -> CoroTask<void> {
context.params = xrpl::test::detail::rpf(alice, bob, usd, {});
RPC::doCommand(context, result);

View File

@@ -148,7 +148,12 @@ GRPCServerImpl::CallData<Request, Response>::process()
// is returned as a tag in handleRpcs(), after sending the response
finished_ = true;
auto runner = app_.getJobQueue().postCoroTask(
JobType::JtRpc, "gRPC-Client", [thisShared](auto) -> CoroTask<void> {
JobType::JtRpc,
"gRPC-Client",
// Safe capture: postCoroTask heap-allocates the lambda (FuncStore)
// and thisShared keeps the CallData alive until the coroutine ends.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines)
[thisShared](auto) -> CoroTask<void> {
thisShared->processRequest();
co_return;
});

View File

@@ -6,7 +6,6 @@
#include <xrpld/rpc/detail/Handler.h>
#include <xrpl/beast/utility/Journal.h>
#include <xrpl/core/JobQueue.h>
#include <xrpl/proto/org/xrpl/rpc/v1/xrp_ledger.grpc.pb.h>
#include <xrpl/resource/Charge.h>
#include <xrpl/resource/Consumer.h>

View File

@@ -8,7 +8,6 @@
#include <xrpl/resource/Consumer.h>
#include <xrpl/server/InfoSub.h>
#include <memory>
#include <string_view>
namespace xrpl {
@@ -31,7 +30,7 @@ struct Context
LedgerMaster& ledgerMaster;
Resource::Consumer& consumer;
Role role;
InfoSub::pointer infoSub{};
InfoSub::pointer infoSub;
unsigned int apiVersion;
};

View File

@@ -194,7 +194,7 @@ private:
Port const& port,
std::string const& request,
beast::IP::Endpoint const& remoteIPAddress,
Output&&,
Output const&,
std::string_view forwardedFor,
std::string_view user);

View File

@@ -319,7 +319,13 @@ ServerHandler::onRequest(Session& session)
std::shared_ptr<Session> const detachedSession = session.detach();
auto const postResult = jobQueue_.postCoroTask(
JtClientRpc, "RPC-Client", [this, detachedSession](auto) -> CoroTask<void> {
JtClientRpc,
"RPC-Client",
// Safe capture: postCoroTask heap-allocates the lambda (FuncStore),
// detachedSession is captured by value, and this (the ServerHandler)
// outlives the JobQueue jobs.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines)
[this, detachedSession](auto) -> CoroTask<void> {
try
{
processSession(detachedSession);
@@ -367,6 +373,10 @@ ServerHandler::onWSMessage(
auto const postResult = jobQueue_.postCoroTask(
JtClientWebsocket,
"WS-Client",
// Safe capture: postCoroTask heap-allocates the lambda (FuncStore),
// session and jv are captured by value, and this (the ServerHandler)
// outlives the JobQueue jobs.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-capturing-lambda-coroutines)
[this, session, jv = std::move(jv)](auto) -> CoroTask<void> {
try
{
@@ -612,7 +622,7 @@ ServerHandler::processRequest(
Port const& port,
std::string const& request,
beast::IP::Endpoint const& remoteIPAddress,
Output&& output,
Output const& output,
std::string_view forwardedFor,
std::string_view user)
{

View File

@@ -13,7 +13,6 @@
#include <xrpl/protocol/jss.h>
#include <xrpl/resource/Fees.h>
#include <chrono>
#include <condition_variable>
#include <memory>
#include <mutex>
@@ -85,7 +84,7 @@ doRipplePathFind(RPC::JsonContext& context)
request,
[state]() {
{
std::lock_guard const lk(state->mtx);
std::scoped_lock const lk(state->mtx);
state->done = true;
}
state->cv.notify_one();