From 780380da7e306deeef7eec1a43bbb5ccc4ca07ea Mon Sep 17 00:00:00 2001 From: Olek <115580134+oleks-rip@users.noreply.github.com> Date: Tue, 10 Mar 2026 11:37:12 -0400 Subject: [PATCH] Modularization fixes (#6488) --- include/xrpl/core/ServiceRegistry.h | 4 ++++ src/libxrpl/tx/transactors/Escrow.cpp | 19 ++++++++++--------- src/test/app/EscrowSmart_test.cpp | 7 +++---- src/test/app/Wasm_test.cpp | 6 +++--- src/xrpld/app/main/Application.cpp | 18 ++++++++++++++++++ 5 files changed, 38 insertions(+), 16 deletions(-) diff --git a/include/xrpl/core/ServiceRegistry.h b/include/xrpl/core/ServiceRegistry.h index 1a2e33d5ee..7b43051f71 100644 --- a/include/xrpl/core/ServiceRegistry.h +++ b/include/xrpl/core/ServiceRegistry.h @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -225,6 +226,9 @@ public: virtual DatabaseCon& getWalletDB() = 0; + virtual Fees + getFees() const = 0; + // Temporary: Get the underlying Application for functions that haven't // been migrated yet. This should be removed once all code is migrated. virtual Application& diff --git a/src/libxrpl/tx/transactors/Escrow.cpp b/src/libxrpl/tx/transactors/Escrow.cpp index 055d3d786d..71a2b9837a 100644 --- a/src/libxrpl/tx/transactors/Escrow.cpp +++ b/src/libxrpl/tx/transactors/Escrow.cpp @@ -198,15 +198,15 @@ EscrowCreate::preflight(PreflightContext const& ctx) if (ctx.tx.isFieldPresent(sfFinishFunction)) { - if (ctx.registry.config().FEES.extension_size_limit == 0 || - ctx.registry.config().FEES.extension_compute_limit == 0) + auto const fees(ctx.registry.getFees()); + if (fees.extensionSizeLimit == 0 || fees.extensionComputeLimit == 0) { JLOG(ctx.j.debug()) << "WASM runtime deactivated by fee voting"; return temTEMP_DISABLED; } auto const code = ctx.tx.getFieldVL(sfFinishFunction); - if (code.size() == 0 || code.size() > ctx.registry.config().FEES.extension_size_limit) + if (code.size() == 0 || code.size() > fees.extensionSizeLimit) { JLOG(ctx.j.debug()) << "EscrowCreate.FinishFunction bad size " << code.size(); return temMALFORMED; @@ -654,7 +654,8 @@ EscrowFinish::preflight(PreflightContext const& ctx) if (auto const allowance = ctx.tx[~sfComputationAllowance]; allowance) { - if (ctx.registry.config().FEES.extension_compute_limit == 0) + auto const fees(ctx.registry.getFees()); + if (fees.extensionComputeLimit == 0) { JLOG(ctx.j.debug()) << "WASM runtime deactivated by fee voting"; return temTEMP_DISABLED; @@ -663,7 +664,7 @@ EscrowFinish::preflight(PreflightContext const& ctx) { return temBAD_LIMIT; } - if (*allowance > ctx.registry.config().FEES.extension_compute_limit) + if (*allowance > fees.extensionComputeLimit) { JLOG(ctx.j.debug()) << "ComputationAllowance too large: " << *allowance; return temBAD_LIMIT; @@ -1178,8 +1179,8 @@ EscrowFinish::doApply() // already checked above, this check is just in case return tecINTERNAL; } - std::uint32_t allowance = ctx_.tx[sfComputationAllowance]; - auto re = runEscrowWasm(wasm, ledgerDataProvider, allowance, ESCROW_FUNCTION_NAME, {}); + std::uint32_t const allowance = ctx_.tx[sfComputationAllowance]; + auto re = runEscrowWasm(wasm, ledgerDataProvider, allowance, ESCROW_FUNCTION_NAME); JLOG(j_.trace()) << "Escrow WASM ran"; if (auto const& data = ledgerDataProvider.getData(); data.has_value()) @@ -1195,8 +1196,8 @@ EscrowFinish::doApply() if (re.has_value()) { - auto reValue = re.value().result; - auto reCost = re.value().cost; + auto const reValue = re.value().result; + auto const reCost = re.value().cost; JLOG(j_.debug()) << "WASM Success: " + std::to_string(reValue) << ", cost: " << reCost; ctx_.setWasmReturnCode(reValue); diff --git a/src/test/app/EscrowSmart_test.cpp b/src/test/app/EscrowSmart_test.cpp index 1ac9addfb6..ee8e30f2f3 100644 --- a/src/test/app/EscrowSmart_test.cpp +++ b/src/test/app/EscrowSmart_test.cpp @@ -1,14 +1,13 @@ #include #include -#include -#include - #include #include #include #include #include +#include +#include #include #include @@ -177,7 +176,7 @@ struct EscrowSmart_test : public beast::unit_test::suite Env env( *this, envconfig([](std::unique_ptr cfg) { - cfg->START_UP = Config::FRESH; + cfg->START_UP = StartUpType::FRESH; return cfg; }), features); diff --git a/src/test/app/Wasm_test.cpp b/src/test/app/Wasm_test.cpp index 608445691d..d4e21fa177 100644 --- a/src/test/app/Wasm_test.cpp +++ b/src/test/app/Wasm_test.cpp @@ -292,7 +292,7 @@ struct Wasm_test : public beast::unit_test::suite { TestHostFunctions hfs(env, 0); auto re = runEscrowWasm(allHFWasm, hfs, 100'000, ESCROW_FUNCTION_NAME, {}); - checkResult(re, 1, 66'340); + checkResult(re, 1, 65'840); } { @@ -316,7 +316,7 @@ struct Wasm_test : public beast::unit_test::suite TestHostFunctions hfs(env, 0); auto re = runEscrowWasm( allHFWasm, hfs, std::numeric_limits::max(), ESCROW_FUNCTION_NAME, {}); - checkResult(re, 1, 66'340); + checkResult(re, 1, 65'840); } { // fail because trying to access nonexistent field @@ -482,7 +482,7 @@ struct Wasm_test : public beast::unit_test::suite auto const codecovWasm = hexToBytes(codecovTestsWasmHex); TestHostFunctions hfs(env, 0); - auto const allowance = 339'303; + auto const allowance = 340'524; auto re = runEscrowWasm(codecovWasm, hfs, allowance, ESCROW_FUNCTION_NAME, {}); checkResult(re, 1, allowance); diff --git a/src/xrpld/app/main/Application.cpp b/src/xrpld/app/main/Application.cpp index 3e3d87dcd5..32603bf5ac 100644 --- a/src/xrpld/app/main/Application.cpp +++ b/src/xrpld/app/main/Application.cpp @@ -787,6 +787,24 @@ public: return *mWalletDB; } + virtual Fees + getFees() const override + { + XRPL_ASSERT(config_, "xrpl::ApplicationImp::getFees : non-null config"); + + auto const& f1(config_->FEES); + + Fees f2; + f2.base = f1.reference_fee; + f2.reserve = f1.account_reserve; + f2.increment = f1.owner_reserve; + f2.extensionComputeLimit = f1.extension_compute_limit; + f2.extensionSizeLimit = f1.extension_size_limit; + f2.gasPrice = f1.gas_price; + + return f2; + } + bool serverOkay(std::string& reason) override;