diff --git a/include/xrpl/core/NetworkIDService.h b/include/xrpl/core/NetworkIDService.h new file mode 100644 index 0000000000..bd34046757 --- /dev/null +++ b/include/xrpl/core/NetworkIDService.h @@ -0,0 +1,36 @@ +#ifndef XRPL_CORE_NETWORKIDSERVICE_H_INCLUDED +#define XRPL_CORE_NETWORKIDSERVICE_H_INCLUDED + +#include + +namespace xrpl { + +/** Service that provides access to the network ID. + + This service provides read-only access to the network ID configured + for this server. The network ID identifies which network (mainnet, + testnet, devnet, or custom network) this server is configured to + connect to. + + Well-known network IDs: + - 0: Mainnet + - 1: Testnet + - 2: Devnet + - 1025+: Custom networks (require NetworkID field in transactions) +*/ +class NetworkIDService +{ +public: + virtual ~NetworkIDService() = default; + + /** Get the configured network ID + * + * @return The network ID this server is configured for + */ + virtual std::uint32_t + getNetworkID() const = 0; +}; + +} // namespace xrpl + +#endif diff --git a/include/xrpl/core/ServiceRegistry.h b/include/xrpl/core/ServiceRegistry.h index c7c82bb496..5ae561dafe 100644 --- a/include/xrpl/core/ServiceRegistry.h +++ b/include/xrpl/core/ServiceRegistry.h @@ -4,10 +4,11 @@ #include #include #include +#include #include #include -#include +#include #include #include @@ -30,6 +31,7 @@ class AmendmentTable; class Application; class Cluster; class CollectorManager; +class Config; class DatabaseCon; class Family; class HashRouter; @@ -43,6 +45,7 @@ class LoadFeeTrack; class LoadManager; class ManifestCache; class NetworkOPs; +class NetworkIDService; class OpenLedger; class OrderBookDB; class Overlay; @@ -102,6 +105,9 @@ public: virtual CachedSLEs& cachedSLEs() = 0; + virtual NetworkIDService& + getNetworkIDService() = 0; + // Protocol and validation services virtual AmendmentTable& getAmendmentTable() = 0; @@ -217,6 +223,9 @@ public: virtual Logs& logs() = 0; + virtual std::optional const& + trapTxID() 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/test/app/AMM_test.cpp b/src/test/app/AMM_test.cpp index 55bf4aa0a3..3e7487600d 100644 --- a/src/test/app/AMM_test.cpp +++ b/src/test/app/AMM_test.cpp @@ -3563,7 +3563,7 @@ private: auto jtx = env.jt(tx, seq(1), fee(baseFee)); env.app().config().features.erase(featureAMM); PreflightContext pfCtx( - env.app(), + env.app().getServiceRegistry(), *jtx.stx, env.current()->rules(), tapNONE, @@ -3578,7 +3578,7 @@ private: jtx.jv["TxnSignature"] = "deadbeef"; jtx.stx = env.ust(jtx); PreflightContext pfCtx( - env.app(), + env.app().getServiceRegistry(), *jtx.stx, env.current()->rules(), tapNONE, @@ -3593,7 +3593,7 @@ private: jtx.jv["Asset2"].removeMember("issuer"); jtx.stx = env.ust(jtx); PreflightContext pfCtx( - env.app(), + env.app().getServiceRegistry(), *jtx.stx, env.current()->rules(), tapNONE, diff --git a/src/test/app/Batch_test.cpp b/src/test/app/Batch_test.cpp index e1322d151a..4c1467ef0b 100644 --- a/src/test/app/Batch_test.cpp +++ b/src/test/app/Batch_test.cpp @@ -1416,7 +1416,7 @@ class Batch_test : public beast::unit_test::suite env.app().openLedger().modify([&](OpenView& view, beast::Journal j) { auto const result = xrpl::apply( - env.app(), view, *jt.stx, tapNONE, j); + env.app().getServiceRegistry(), view, *jt.stx, tapNONE, j); BEAST_EXPECT( !result.applied && result.ter == temARRAY_TOO_LARGE); return result.applied; @@ -1462,7 +1462,7 @@ class Batch_test : public beast::unit_test::suite env.app().openLedger().modify([&](OpenView& view, beast::Journal j) { auto const result = xrpl::apply( - env.app(), view, *jt.stx, tapNONE, j); + env.app().getServiceRegistry(), view, *jt.stx, tapNONE, j); BEAST_EXPECT( !result.applied && result.ter == temARRAY_TOO_LARGE); return result.applied; @@ -3737,7 +3737,7 @@ class Batch_test : public beast::unit_test::suite BEAST_EXPECT(reason == "Cannot submit pseudo transactions."); env.app().openLedger().modify([&](OpenView& view, beast::Journal j) { auto const result = xrpl::apply( - env.app(), view, stx, tapNONE, j); + env.app().getServiceRegistry(), view, stx, tapNONE, j); BEAST_EXPECT(!result.applied && result.ter == temINVALID_FLAG); return result.applied; }); diff --git a/src/test/app/Escrow_test.cpp b/src/test/app/Escrow_test.cpp index 2b7297009a..11f8d1f051 100644 --- a/src/test/app/Escrow_test.cpp +++ b/src/test/app/Escrow_test.cpp @@ -1314,7 +1314,7 @@ struct Escrow_test : public beast::unit_test::suite seq(1), fee(baseFee)); auto const pf = preflight( - env.app(), + env.app().getServiceRegistry(), env.current()->rules(), *jtx.stx, tapNONE, @@ -1329,7 +1329,7 @@ struct Escrow_test : public beast::unit_test::suite auto const jtx = env.jt(escrow::cancel("bob", "alice", 3), seq(1), fee(baseFee)); auto const pf = preflight( - env.app(), + env.app().getServiceRegistry(), env.current()->rules(), *jtx.stx, tapNONE, @@ -1344,7 +1344,7 @@ struct Escrow_test : public beast::unit_test::suite auto const jtx = env.jt(escrow::finish("bob", "alice", 3), seq(1), fee(baseFee)); auto const pf = preflight( - env.app(), + env.app().getServiceRegistry(), env.current()->rules(), *jtx.stx, tapNONE, diff --git a/src/test/app/FeeVote_test.cpp b/src/test/app/FeeVote_test.cpp index c7f33544f9..6ce34119da 100644 --- a/src/test/app/FeeVote_test.cpp +++ b/src/test/app/FeeVote_test.cpp @@ -122,8 +122,12 @@ createInvalidFeeTx( bool applyFeeAndTestResult(jtx::Env& env, OpenView& view, STTx const& tx) { - auto const res = - apply(env.app(), view, tx, ApplyFlags::tapNONE, env.journal); + auto const res = apply( + env.app().getServiceRegistry(), + view, + tx, + ApplyFlags::tapNONE, + env.journal); return res.ter == tesSUCCESS; } diff --git a/src/test/app/Invariants_test.cpp b/src/test/app/Invariants_test.cpp index 9f70538778..589674ecf7 100644 --- a/src/test/app/Invariants_test.cpp +++ b/src/test/app/Invariants_test.cpp @@ -89,7 +89,7 @@ class Invariants_test : public beast::unit_test::suite tx.setAccountID( sfAccount, setTxAccount == TxAccount::A1 ? A1.id() : A2.id()); ApplyContext ac{ - env.app(), + env.app().getServiceRegistry(), ov, tx, tesSUCCESS, diff --git a/src/test/app/LedgerHistory_test.cpp b/src/test/app/LedgerHistory_test.cpp index b69203f1e0..5d21f8bada 100644 --- a/src/test/app/LedgerHistory_test.cpp +++ b/src/test/app/LedgerHistory_test.cpp @@ -49,7 +49,12 @@ public: { OpenView accum(&*res); applyTransaction( - env.app(), accum, *stx, false, tapNONE, env.journal); + env.app().getServiceRegistry(), + accum, + *stx, + false, + tapNONE, + env.journal); accum.apply(*res); } res->updateSkipList(); diff --git a/src/test/app/LoanBroker_test.cpp b/src/test/app/LoanBroker_test.cpp index 769ed40321..4c3a9f3043 100644 --- a/src/test/app/LoanBroker_test.cpp +++ b/src/test/app/LoanBroker_test.cpp @@ -1323,7 +1323,7 @@ class LoanBroker_test : public beast::unit_test::suite test::StreamSink sink{beast::severities::kWarning}; beast::Journal jlog{sink}; ApplyContext ac{ - env.app(), + env.app().getServiceRegistry(), ov, tx, tesSUCCESS, @@ -1344,7 +1344,12 @@ class LoanBroker_test : public beast::unit_test::suite // Invoke preclaim against the mutated (ApplyView) view; triggers // nullptr deref PreclaimContext pctx{ - env.app(), ac.view(), tesSUCCESS, tx, tapNONE, jlog}; + env.app().getServiceRegistry(), + ac.view(), + tesSUCCESS, + tx, + tapNONE, + jlog}; (void)LoanBrokerCoverDeposit::preclaim(pctx); } diff --git a/src/test/app/NFTokenBurn_test.cpp b/src/test/app/NFTokenBurn_test.cpp index a1c6ffb6de..d004fa9ae8 100644 --- a/src/test/app/NFTokenBurn_test.cpp +++ b/src/test/app/NFTokenBurn_test.cpp @@ -780,7 +780,7 @@ class NFTokenBurn_test : public beast::unit_test::suite test::StreamSink sink{beast::severities::kWarning}; beast::Journal jlog{sink}; ApplyContext ac{ - env.app(), + env.app().getServiceRegistry(), ov, tx, tesSUCCESS, @@ -824,7 +824,7 @@ class NFTokenBurn_test : public beast::unit_test::suite test::StreamSink sink{beast::severities::kWarning}; beast::Journal jlog{sink}; ApplyContext ac{ - env.app(), + env.app().getServiceRegistry(), ov, tx, tesSUCCESS, diff --git a/src/test/app/PseudoTx_test.cpp b/src/test/app/PseudoTx_test.cpp index f01ba616c8..1435c493a2 100644 --- a/src/test/app/PseudoTx_test.cpp +++ b/src/test/app/PseudoTx_test.cpp @@ -75,8 +75,8 @@ struct PseudoTx_test : public beast::unit_test::suite BEAST_EXPECT(reason == "Cannot submit pseudo transactions."); env.app().openLedger().modify( [&](OpenView& view, beast::Journal j) { - auto const result = - xrpl::apply(env.app(), view, stx, tapNONE, j); + auto const result = xrpl::apply( + env.app().getServiceRegistry(), view, stx, tapNONE, j); BEAST_EXPECT(!result.applied && result.ter == temINVALID); return result.applied; }); diff --git a/src/test/app/Regression_test.cpp b/src/test/app/Regression_test.cpp index 56f0de9e07..2806d351a2 100644 --- a/src/test/app/Regression_test.cpp +++ b/src/test/app/Regression_test.cpp @@ -62,8 +62,12 @@ struct Regression_test : public beast::unit_test::suite auto const jt = env.jt(pay(env.master, "alice", aliceAmount)); OpenView accum(&*next); - auto const result = - xrpl::apply(env.app(), accum, *jt.stx, tapNONE, env.journal); + auto const result = xrpl::apply( + env.app().getServiceRegistry(), + accum, + *jt.stx, + tapNONE, + env.journal); BEAST_EXPECT(result.ter == tesSUCCESS); BEAST_EXPECT(result.applied); @@ -86,8 +90,12 @@ struct Regression_test : public beast::unit_test::suite OpenView accum(&*next); - auto const result = - xrpl::apply(env.app(), accum, *jt.stx, tapNONE, env.journal); + auto const result = xrpl::apply( + env.app().getServiceRegistry(), + accum, + *jt.stx, + tapNONE, + env.journal); BEAST_EXPECT(result.ter == tecINSUFF_FEE); BEAST_EXPECT(result.applied); diff --git a/src/test/app/TxQ_test.cpp b/src/test/app/TxQ_test.cpp index 9489bb7f04..652a7d6a46 100644 --- a/src/test/app/TxQ_test.cpp +++ b/src/test/app/TxQ_test.cpp @@ -977,13 +977,17 @@ public: Env::ParsedResult parsed; - env.app().openLedger().modify([&](OpenView& view, - beast::Journal j) { - auto const result = - xrpl::apply(env.app(), view, *jt.stx, tapNONE, env.journal); - parsed.ter = result.ter; - return result.applied; - }); + env.app().openLedger().modify( + [&](OpenView& view, beast::Journal j) { + auto const result = xrpl::apply( + env.app().getServiceRegistry(), + view, + *jt.stx, + tapNONE, + env.journal); + parsed.ter = result.ter; + return result.applied; + }); env.postconditions(jt, parsed); } checkMetrics(*this, env, 1, std::nullopt, 4, 2); @@ -2428,7 +2432,7 @@ public: { auto const jtx = env.jt(offer_cancel(alice, 3), seq(5), fee(10)); auto const pf = preflight( - env.app(), + env.app().getServiceRegistry(), env.current()->rules(), *jtx.stx, tapNONE, @@ -2445,7 +2449,7 @@ public: auto const jtx = env.jt(trust("carol", USD(50000000)), seq(1), fee(10)); auto const pf = preflight( - env.app(), + env.app().getServiceRegistry(), env.current()->rules(), *jtx.stx, tapNONE, @@ -2459,7 +2463,7 @@ public: { auto const jtx = env.jt(ticket::create(alice, 1), seq(1), fee(10)); auto const pf = preflight( - env.app(), + env.app().getServiceRegistry(), env.current()->rules(), *jtx.stx, tapNONE, @@ -4190,8 +4194,8 @@ public: env.app().openLedger().modify([&](OpenView& view, beast::Journal j) { auto const tx = env.jt(noop(alice), seq(aliceSeq), fee(openLedgerCost(env))); - auto const result = - xrpl::apply(env.app(), view, *tx.stx, tapUNLIMITED, j); + auto const result = xrpl::apply( + env.app().getServiceRegistry(), view, *tx.stx, tapUNLIMITED, j); BEAST_EXPECT(result.ter == tesSUCCESS && result.applied); return result.applied; }); @@ -4262,8 +4266,8 @@ public: noop(alice), ticket::use(tktSeq0 + 1), fee(openLedgerCost(env))); - auto const result = - xrpl::apply(env.app(), view, *tx.stx, tapUNLIMITED, j); + auto const result = xrpl::apply( + env.app().getServiceRegistry(), view, *tx.stx, tapUNLIMITED, j); BEAST_EXPECT(result.ter == tesSUCCESS && result.applied); return result.applied; }); diff --git a/src/test/app/tx/apply_test.cpp b/src/test/app/tx/apply_test.cpp index 6f9473ce69..eaa1924542 100644 --- a/src/test/app/tx/apply_test.cpp +++ b/src/test/app/tx/apply_test.cpp @@ -42,8 +42,7 @@ public: Validity valid = checkValidity( fully_canonical.app().getHashRouter(), tx, - fully_canonical.current()->rules(), - fully_canonical.app().config()) + fully_canonical.current()->rules()) .first; if (valid == Validity::Valid) fail("Non-Fully canonical signature was permitted"); diff --git a/src/test/consensus/NegativeUNL_test.cpp b/src/test/consensus/NegativeUNL_test.cpp index 535aec03bf..644536071d 100644 --- a/src/test/consensus/NegativeUNL_test.cpp +++ b/src/test/consensus/NegativeUNL_test.cpp @@ -1863,8 +1863,12 @@ negUnlSizeTest( bool applyAndTestResult(jtx::Env& env, OpenView& view, STTx const& tx, bool pass) { - auto const res = - apply(env.app(), view, tx, ApplyFlags::tapNONE, env.journal); + auto const res = apply( + env.app().getServiceRegistry(), + view, + tx, + ApplyFlags::tapNONE, + env.journal); if (pass) return res.ter == tesSUCCESS; else diff --git a/src/test/rpc/AccountSet_test.cpp b/src/test/rpc/AccountSet_test.cpp index 40ef4acba7..9bcf5ded7b 100644 --- a/src/test/rpc/AccountSet_test.cpp +++ b/src/test/rpc/AccountSet_test.cpp @@ -565,7 +565,8 @@ public: stx->at(sfSigningPubKey) = makeSlice(std::string("badkey")); env.app().openLedger().modify([&](OpenView& view, beast::Journal j) { - auto const result = xrpl::apply(env.app(), view, *stx, tapNONE, j); + auto const result = xrpl::apply( + env.app().getServiceRegistry(), view, *stx, tapNONE, j); BEAST_EXPECT(result.ter == temBAD_SIGNATURE); BEAST_EXPECT(!result.applied); return result.applied; diff --git a/src/xrpld/app/ledger/ConsensusTransSetSF.cpp b/src/xrpld/app/ledger/ConsensusTransSetSF.cpp index 892fb98f63..213cf926d0 100644 --- a/src/xrpld/app/ledger/ConsensusTransSetSF.cpp +++ b/src/xrpld/app/ledger/ConsensusTransSetSF.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include @@ -8,6 +7,7 @@ #include #include #include +#include namespace xrpl { diff --git a/src/xrpld/app/ledger/LedgerHistory.cpp b/src/xrpld/app/ledger/LedgerHistory.cpp index 447c51274f..2654e25d7b 100644 --- a/src/xrpld/app/ledger/LedgerHistory.cpp +++ b/src/xrpld/app/ledger/LedgerHistory.cpp @@ -1,4 +1,5 @@ #include +#include #include #include diff --git a/src/xrpld/app/ledger/OrderBookDB.cpp b/src/xrpld/app/ledger/OrderBookDB.cpp index 73685215e7..310bab8785 100644 --- a/src/xrpld/app/ledger/OrderBookDB.cpp +++ b/src/xrpld/app/ledger/OrderBookDB.cpp @@ -2,12 +2,12 @@ #include #include #include -#include #include #include #include #include +#include namespace xrpl { diff --git a/src/xrpld/app/ledger/detail/BuildLedger.cpp b/src/xrpld/app/ledger/detail/BuildLedger.cpp index a716375f6b..172c2c2b4c 100644 --- a/src/xrpld/app/ledger/detail/BuildLedger.cpp +++ b/src/xrpld/app/ledger/detail/BuildLedger.cpp @@ -110,7 +110,12 @@ applyTransactions( } switch (applyTransaction( - app, view, *it->second, certainRetry, tapNONE, j)) + app.getServiceRegistry(), + view, + *it->second, + certainRetry, + tapNONE, + j)) { case ApplyTransactionResult::Success: it = txns.erase(it); @@ -224,7 +229,13 @@ buildLedger( j, [&](OpenView& accum, std::shared_ptr const& built) { for (auto& tx : replayData.orderedTxns()) - applyTransaction(app, accum, *tx.second, false, applyFlags, j); + applyTransaction( + app.getServiceRegistry(), + accum, + *tx.second, + false, + applyFlags, + j); }); } diff --git a/src/xrpld/app/ledger/detail/InboundTransactions.cpp b/src/xrpld/app/ledger/detail/InboundTransactions.cpp index 350b96dd75..52c69224c9 100644 --- a/src/xrpld/app/ledger/detail/InboundTransactions.cpp +++ b/src/xrpld/app/ledger/detail/InboundTransactions.cpp @@ -2,12 +2,12 @@ #include #include #include -#include #include #include #include #include +#include #include #include diff --git a/src/xrpld/app/ledger/detail/OpenLedger.cpp b/src/xrpld/app/ledger/detail/OpenLedger.cpp index 35f4b75157..16a7563d70 100644 --- a/src/xrpld/app/ledger/detail/OpenLedger.cpp +++ b/src/xrpld/app/ledger/detail/OpenLedger.cpp @@ -163,7 +163,8 @@ OpenLedger::apply_one( if (retry) flags = flags | tapRETRY; // If it's in anybody's proposed set, try to keep it in the ledger - auto const result = xrpl::apply(app, view, *tx, flags, j); + auto const result = + xrpl::apply(app.getServiceRegistry(), view, *tx, flags, j); if (result.applied || result.ter == terQUEUED) return Result::success; if (isTefFailure(result.ter) || isTemMalformed(result.ter) || diff --git a/src/xrpld/app/ledger/detail/TransactionAcquire.cpp b/src/xrpld/app/ledger/detail/TransactionAcquire.cpp index e32ddc7b56..f6b63a37a3 100644 --- a/src/xrpld/app/ledger/detail/TransactionAcquire.cpp +++ b/src/xrpld/app/ledger/detail/TransactionAcquire.cpp @@ -3,6 +3,7 @@ #include #include #include + #include #include diff --git a/src/xrpld/app/main/Application.cpp b/src/xrpld/app/main/Application.cpp index b55f55395c..8268e333ff 100644 --- a/src/xrpld/app/main/Application.cpp +++ b/src/xrpld/app/main/Application.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -166,6 +167,7 @@ public: NodeCache m_tempNodeCache; CachedSLEs cachedSLEs_; + std::unique_ptr networkIDService_; std::optional> nodeIdentity_; ValidatorKeys const validatorKeys_; @@ -328,6 +330,8 @@ public: stopwatch(), logs_->journal("CachedSLEs")) + , networkIDService_(std::make_unique(*config_)) + , validatorKeys_(*config_, m_journal) , m_resourceManager(Resource::make_Manager( @@ -695,6 +699,12 @@ public: return cachedSLEs_; } + NetworkIDService& + getNetworkIDService() override + { + return *networkIDService_; + } + AmendmentTable& getAmendmentTable() override { diff --git a/src/xrpld/app/main/Application.h b/src/xrpld/app/main/Application.h index 9b6fb56198..42de255fdd 100644 --- a/src/xrpld/app/main/Application.h +++ b/src/xrpld/app/main/Application.h @@ -159,6 +159,8 @@ public: getTempNodeCache() = 0; virtual CachedSLEs& cachedSLEs() = 0; + virtual NetworkIDService& + getNetworkIDService() = 0; virtual AmendmentTable& getAmendmentTable() = 0; virtual HashRouter& diff --git a/src/xrpld/app/misc/NetworkOPs.cpp b/src/xrpld/app/misc/NetworkOPs.cpp index c072a1c496..6e66d4a122 100644 --- a/src/xrpld/app/misc/NetworkOPs.cpp +++ b/src/xrpld/app/misc/NetworkOPs.cpp @@ -1202,10 +1202,7 @@ NetworkOPsImp::submitTransaction(std::shared_ptr const& iTrans) try { auto const [validity, reason] = checkValidity( - app_.getHashRouter(), - *trans, - m_ledgerMaster.getValidatedRules(), - app_.config()); + app_.getHashRouter(), *trans, m_ledgerMaster.getValidatedRules()); if (validity != Validity::Valid) { @@ -1265,7 +1262,7 @@ NetworkOPsImp::preProcessTransaction(std::shared_ptr& transaction) // but I'm not 100% sure yet. // If so, only cost is looking up HashRouter flags. auto const [validity, reason] = - checkValidity(app_.getHashRouter(), sttx, view->rules(), app_.config()); + checkValidity(app_.getHashRouter(), sttx, view->rules()); XRPL_ASSERT( validity == Validity::Valid, "xrpl::NetworkOPsImp::processTransaction : valid validity"); diff --git a/src/xrpld/app/misc/detail/TxQ.cpp b/src/xrpld/app/misc/detail/TxQ.cpp index 01abcc9c7d..eac92ed2cb 100644 --- a/src/xrpld/app/misc/detail/TxQ.cpp +++ b/src/xrpld/app/misc/detail/TxQ.cpp @@ -290,13 +290,17 @@ TxQ::MaybeTx::apply(Application& app, OpenView& view, beast::Journal j) << " rules or flags have changed. Flags from " << pfResult->flags << " to " << flags; - pfResult.emplace( - preflight(app, view.rules(), pfResult->tx, flags, pfResult->j)); + pfResult.emplace(preflight( + app.getServiceRegistry(), + view.rules(), + pfResult->tx, + flags, + pfResult->j)); } - auto pcresult = preclaim(*pfResult, app, view); + auto pcresult = preclaim(*pfResult, app.getServiceRegistry(), view); - return doApply(pcresult, app, view); + return doApply(pcresult, app.getServiceRegistry(), view); } TxQ::TxQAccount::TxQAccount(std::shared_ptr const& txn) @@ -578,7 +582,10 @@ TxQ::tryClearAccountQueueUpThruTx( } // Apply the current tx. Because the state of the view has been changed // by the queued txs, we also need to preclaim again. - auto const txResult = doApply(preclaim(pfResult, app, view), app, view); + auto const txResult = doApply( + preclaim(pfResult, app.getServiceRegistry(), view), + app.getServiceRegistry(), + view); if (txResult.applied) { @@ -720,7 +727,8 @@ TxQ::apply( // See if the transaction is valid, properly formed, // etc. before doing potentially expensive queue // replace and multi-transaction operations. - auto const pfResult = preflight(app, view.rules(), *tx, flags, j); + auto const pfResult = + preflight(app.getServiceRegistry(), view.rules(), *tx, flags, j); if (pfResult.ter != tesSUCCESS) return {pfResult.ter, false}; @@ -1143,8 +1151,10 @@ TxQ::apply( // Note that earlier code has already verified that the sequence/ticket // is valid. So we use a special entry point that runs all of the // preclaim checks with the exception of the sequence check. - auto const pcresult = - preclaim(pfResult, app, multiTxn ? multiTxn->openView : view); + auto const pcresult = preclaim( + pfResult, + app.getServiceRegistry(), + multiTxn ? multiTxn->openView : view); if (!pcresult.likelyToClaimFee) return {pcresult.ter, false}; @@ -1694,7 +1704,7 @@ TxQ::tryDirectApply( << " to open ledger."; auto const [txnResult, didApply, metadata] = - xrpl::apply(app, view, *tx, flags, j); + xrpl::apply(app.getServiceRegistry(), view, *tx, flags, j); JLOG(j_.trace()) << "New transaction " << transactionID << (didApply ? " applied successfully with " diff --git a/src/xrpld/app/paths/PathRequest.cpp b/src/xrpld/app/paths/PathRequest.cpp index 9556f8d4aa..9c2278f2ee 100644 --- a/src/xrpld/app/paths/PathRequest.cpp +++ b/src/xrpld/app/paths/PathRequest.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -14,6 +13,7 @@ #include #include #include +#include #include #include diff --git a/src/xrpld/app/tx/apply.h b/src/xrpld/app/tx/apply.h index d578334c31..f5342fd239 100644 --- a/src/xrpld/app/tx/apply.h +++ b/src/xrpld/app/tx/apply.h @@ -12,8 +12,8 @@ namespace xrpl { -class Application; class HashRouter; +class ServiceRegistry; /** Describes the pre-processing validity of a transaction. @@ -42,11 +42,7 @@ enum class Validity { @see Validity */ std::pair -checkValidity( - HashRouter& router, - STTx const& tx, - Rules const& rules, - Config const& config); +checkValidity(HashRouter& router, STTx const& tx, Rules const& rules); /** Sets the validity of a given transaction in the cache. @@ -103,7 +99,7 @@ forceValidity(HashRouter& router, uint256 const& txid, Validity validity); */ ApplyResult apply( - Application& app, + ServiceRegistry& registry, OpenView& view, STTx const& tx, ApplyFlags flags, @@ -131,7 +127,7 @@ enum class ApplyTransactionResult { */ ApplyTransactionResult applyTransaction( - Application& app, + ServiceRegistry& registry, OpenView& view, STTx const& tx, bool retryAssured, diff --git a/src/xrpld/app/tx/applySteps.h b/src/xrpld/app/tx/applySteps.h index 0ae3d8790e..dba5c6e6c8 100644 --- a/src/xrpld/app/tx/applySteps.h +++ b/src/xrpld/app/tx/applySteps.h @@ -6,7 +6,7 @@ namespace xrpl { -class Application; +class ServiceRegistry; class STTx; class TxQ; @@ -245,7 +245,7 @@ public: /** @{ */ PreflightResult preflight( - Application& app, + ServiceRegistry& registry, Rules const& rules, STTx const& tx, ApplyFlags flags, @@ -253,7 +253,7 @@ preflight( PreflightResult preflight( - Application& app, + ServiceRegistry& registry, Rules const& rules, uint256 const& parentBatchId, STTx const& tx, @@ -292,7 +292,7 @@ preflight( PreclaimResult preclaim( PreflightResult const& preflightResult, - Application& app, + ServiceRegistry& registry, OpenView const& view); /** Compute only the expected base fee for a transaction. @@ -335,7 +335,7 @@ calculateDefaultBaseFee(ReadView const& view, STTx const& tx); @param preclaimResult The result of a previous call to `preclaim` for the transaction. - @param app The current running `Application`. + @param registry The service registry. @param view The open ledger that the transaction will attempt to be applied to. @@ -345,7 +345,10 @@ calculateDefaultBaseFee(ReadView const& view, STTx const& tx); whether or not the transaction was applied. */ ApplyResult -doApply(PreclaimResult const& preclaimResult, Application& app, OpenView& view); +doApply( + PreclaimResult const& preclaimResult, + ServiceRegistry& registry, + OpenView& view); } // namespace xrpl diff --git a/src/xrpld/app/tx/detail/AMMCreate.cpp b/src/xrpld/app/tx/detail/AMMCreate.cpp index 3a3ce4b1e1..26e66830ac 100644 --- a/src/xrpld/app/tx/detail/AMMCreate.cpp +++ b/src/xrpld/app/tx/detail/AMMCreate.cpp @@ -308,7 +308,7 @@ applyCreate( auto const dir = keylet::quality(keylet::book(book), uRate); if (auto const bookExisted = static_cast(sb.read(dir)); !bookExisted) - ctx_.app.getOrderBookDB().addOrderBook(book); + ctx_.registry.getOrderBookDB().addOrderBook(book); }; addOrderBook(amount.issue(), amount2.issue(), getRate(amount2, amount)); addOrderBook(amount2.issue(), amount.issue(), getRate(amount, amount2)); diff --git a/src/xrpld/app/tx/detail/ApplyContext.cpp b/src/xrpld/app/tx/detail/ApplyContext.cpp index d364950b44..46398c3d10 100644 --- a/src/xrpld/app/tx/detail/ApplyContext.cpp +++ b/src/xrpld/app/tx/detail/ApplyContext.cpp @@ -8,7 +8,7 @@ namespace xrpl { ApplyContext::ApplyContext( - Application& app_, + ServiceRegistry& registry_, OpenView& base, std::optional const& parentBatchId, STTx const& tx_, @@ -16,7 +16,7 @@ ApplyContext::ApplyContext( XRPAmount baseFee_, ApplyFlags flags, beast::Journal journal_) - : app(app_) + : registry(registry_) , tx(tx_) , preclaimResult(preclaimResult_) , baseFee(baseFee_) diff --git a/src/xrpld/app/tx/detail/ApplyContext.h b/src/xrpld/app/tx/detail/ApplyContext.h index 4ae2f11a85..3cb2d439a0 100644 --- a/src/xrpld/app/tx/detail/ApplyContext.h +++ b/src/xrpld/app/tx/detail/ApplyContext.h @@ -1,10 +1,8 @@ #ifndef XRPL_TX_APPLYCONTEXT_H_INCLUDED #define XRPL_TX_APPLYCONTEXT_H_INCLUDED -#include -#include - #include +#include #include #include #include @@ -18,7 +16,7 @@ class ApplyContext { public: explicit ApplyContext( - Application& app, + ServiceRegistry& registry, OpenView& base, std::optional const& parentBatchId, STTx const& tx, @@ -28,7 +26,7 @@ public: beast::Journal journal = beast::Journal{beast::Journal::getNullSink()}); explicit ApplyContext( - Application& app, + ServiceRegistry& registry, OpenView& base, STTx const& tx, TER preclaimResult, @@ -36,7 +34,7 @@ public: ApplyFlags flags, beast::Journal journal = beast::Journal{beast::Journal::getNullSink()}) : ApplyContext( - app, + registry, base, std::nullopt, tx, @@ -49,7 +47,7 @@ public: (flags & tapBATCH) == 0, "Batch apply flag should not be set"); } - Application& app; + ServiceRegistry& registry; STTx const& tx; TER const preclaimResult; XRPAmount const baseFee; diff --git a/src/xrpld/app/tx/detail/Batch.cpp b/src/xrpld/app/tx/detail/Batch.cpp index a26bc52880..9f5cb4d548 100644 --- a/src/xrpld/app/tx/detail/Batch.cpp +++ b/src/xrpld/app/tx/detail/Batch.cpp @@ -317,7 +317,7 @@ Batch::preflight(PreflightContext const& ctx) auto const innerAccount = stx.getAccountID(sfAccount); if (auto const preflightResult = xrpl::preflight( - ctx.app, ctx.rules, parentBatchId, stx, tapBATCH, ctx.j); + ctx.registry, ctx.rules, parentBatchId, stx, tapBATCH, ctx.j); preflightResult.ter != tesSUCCESS) { JLOG(ctx.j.debug()) << "BatchTrace[" << parentBatchId << "]: " diff --git a/src/xrpld/app/tx/detail/CancelCheck.cpp b/src/xrpld/app/tx/detail/CancelCheck.cpp index b673784655..39277c7cf8 100644 --- a/src/xrpld/app/tx/detail/CancelCheck.cpp +++ b/src/xrpld/app/tx/detail/CancelCheck.cpp @@ -64,7 +64,7 @@ CancelCheck::doApply() AccountID const srcId{sleCheck->getAccountID(sfAccount)}; AccountID const dstId{sleCheck->getAccountID(sfDestination)}; - auto viewJ = ctx_.app.journal("View"); + auto viewJ = ctx_.registry.journal("View"); // If the check is not written to self (and it shouldn't be), remove the // check from the destination account root. diff --git a/src/xrpld/app/tx/detail/CancelOffer.cpp b/src/xrpld/app/tx/detail/CancelOffer.cpp index 1dc9ad0bde..3b690cb730 100644 --- a/src/xrpld/app/tx/detail/CancelOffer.cpp +++ b/src/xrpld/app/tx/detail/CancelOffer.cpp @@ -54,7 +54,7 @@ CancelOffer::doApply() if (auto sleOffer = view().peek(keylet::offer(account_, offerSequence))) { JLOG(j_.debug()) << "Trying to cancel offer #" << offerSequence; - return offerDelete(view(), sleOffer, ctx_.app.journal("View")); + return offerDelete(view(), sleOffer, ctx_.registry.journal("View")); } JLOG(j_.debug()) << "Offer #" << offerSequence << " can't be found."; diff --git a/src/xrpld/app/tx/detail/CashCheck.cpp b/src/xrpld/app/tx/detail/CashCheck.cpp index c32b7dfe4e..eb9b52f0eb 100644 --- a/src/xrpld/app/tx/detail/CashCheck.cpp +++ b/src/xrpld/app/tx/detail/CashCheck.cpp @@ -247,7 +247,7 @@ CashCheck::doApply() // // If it is not a check to self (as should be the case), then there's // work to do... - auto viewJ = ctx_.app.journal("View"); + auto viewJ = ctx_.registry.journal("View"); auto const optDeliverMin = ctx_.tx[~sfDeliverMin]; if (srcId != account_) diff --git a/src/xrpld/app/tx/detail/Change.cpp b/src/xrpld/app/tx/detail/Change.cpp index f501595e2f..b0bcc1a870 100644 --- a/src/xrpld/app/tx/detail/Change.cpp +++ b/src/xrpld/app/tx/detail/Change.cpp @@ -1,5 +1,3 @@ -#include -#include #include #include @@ -208,7 +206,7 @@ Change::applyAmendment() entry[sfCloseTime] = view().parentCloseTime().time_since_epoch().count(); - if (!ctx_.app.getAmendmentTable().isSupported(amendment)) + if (!ctx_.registry.getAmendmentTable().isSupported(amendment)) { JLOG(j_.warn()) << "Unsupported amendment " << amendment << " received a majority."; @@ -220,13 +218,13 @@ Change::applyAmendment() amendments.push_back(amendment); amendmentObject->setFieldV256(sfAmendments, amendments); - ctx_.app.getAmendmentTable().enable(amendment); + ctx_.registry.getAmendmentTable().enable(amendment); - if (!ctx_.app.getAmendmentTable().isSupported(amendment)) + if (!ctx_.registry.getAmendmentTable().isSupported(amendment)) { JLOG(j_.error()) << "Unsupported amendment " << amendment << " activated: server blocked."; - ctx_.app.getOPs().setAmendmentBlocked(); + ctx_.registry.getOPs().setAmendmentBlocked(); } } diff --git a/src/xrpld/app/tx/detail/CreateCheck.cpp b/src/xrpld/app/tx/detail/CreateCheck.cpp index 11613a5855..a9d7cb950b 100644 --- a/src/xrpld/app/tx/detail/CreateCheck.cpp +++ b/src/xrpld/app/tx/detail/CreateCheck.cpp @@ -174,7 +174,7 @@ CreateCheck::doApply() view().insert(sleCheck); - auto viewJ = ctx_.app.journal("View"); + auto viewJ = ctx_.registry.journal("View"); // If it's not a self-send (and it shouldn't be), add Check to the // destination's owner directory. if (dstAccountId != account_) diff --git a/src/xrpld/app/tx/detail/CreateOffer.cpp b/src/xrpld/app/tx/detail/CreateOffer.cpp index 848599943a..241fb4f649 100644 --- a/src/xrpld/app/tx/detail/CreateOffer.cpp +++ b/src/xrpld/app/tx/detail/CreateOffer.cpp @@ -147,7 +147,7 @@ CreateOffer::preclaim(PreclaimContext const& ctx) std::uint32_t const uAccountSequence = sleCreator->getFieldU32(sfSequence); - auto viewJ = ctx.app.journal("View"); + auto viewJ = ctx.registry.journal("View"); if (isGlobalFrozen(ctx.view, uPaysIssuerID) || isGlobalFrozen(ctx.view, uGetsIssuerID)) @@ -530,7 +530,7 @@ CreateOffer::applyHybrid( bookArr.push_back(std::move(bookInfo)); if (!bookExists) - ctx_.app.getOrderBookDB().addOrderBook(book); + ctx_.registry.getOrderBookDB().addOrderBook(book); sleOffer->setFieldArray(sfAdditionalBooks, bookArr); return tesSUCCESS; @@ -564,7 +564,7 @@ CreateOffer::applyGuts(Sandbox& sb, Sandbox& sbCancel) // end up on the books. auto uRate = getRate(saTakerGets, saTakerPays); - auto viewJ = ctx_.app.journal("View"); + auto viewJ = ctx_.registry.journal("View"); TER result = tesSUCCESS; @@ -880,7 +880,7 @@ CreateOffer::applyGuts(Sandbox& sb, Sandbox& sbCancel) sb.insert(sleOffer); if (!bookExisted) - ctx_.app.getOrderBookDB().addOrderBook(book); + ctx_.registry.getOrderBookDB().addOrderBook(book); JLOG(j_.debug()) << "final result: success"; diff --git a/src/xrpld/app/tx/detail/CreateTicket.cpp b/src/xrpld/app/tx/detail/CreateTicket.cpp index 6432d1b3d5..aa01d22f7c 100644 --- a/src/xrpld/app/tx/detail/CreateTicket.cpp +++ b/src/xrpld/app/tx/detail/CreateTicket.cpp @@ -71,7 +71,7 @@ CreateTicket::doApply() return tecINSUFFICIENT_RESERVE; } - beast::Journal viewJ{ctx_.app.journal("View")}; + beast::Journal viewJ{ctx_.registry.journal("View")}; // The starting ticket sequence is the same as the current account // root sequence. Before we got here to doApply(), the transaction diff --git a/src/xrpld/app/tx/detail/DeleteAccount.cpp b/src/xrpld/app/tx/detail/DeleteAccount.cpp index 422ed37e2f..37c7785cf5 100644 --- a/src/xrpld/app/tx/detail/DeleteAccount.cpp +++ b/src/xrpld/app/tx/detail/DeleteAccount.cpp @@ -53,7 +53,7 @@ DeleteAccount::calculateBaseFee(ReadView const& view, STTx const& tx) namespace { // Define a function pointer type that can be used to delete ledger node types. using DeleterFuncPtr = TER (*)( - Application& app, + ServiceRegistry& registry, ApplyView& view, AccountID const& account, uint256 const& delIndex, @@ -63,7 +63,7 @@ using DeleterFuncPtr = TER (*)( // Local function definitions that provides signature compatibility. TER offerDelete( - Application& app, + ServiceRegistry&, ApplyView& view, AccountID const& account, uint256 const& delIndex, @@ -75,19 +75,19 @@ offerDelete( TER removeSignersFromLedger( - Application& app, + ServiceRegistry& registry, ApplyView& view, AccountID const& account, uint256 const& delIndex, std::shared_ptr const& sleDel, beast::Journal j) { - return SetSignerList::removeFromLedger(app, view, account, j); + return SetSignerList::removeFromLedger(registry, view, account, j); } TER removeTicketFromLedger( - Application&, + ServiceRegistry&, ApplyView& view, AccountID const& account, uint256 const& delIndex, @@ -99,7 +99,7 @@ removeTicketFromLedger( TER removeDepositPreauthFromLedger( - Application&, + ServiceRegistry&, ApplyView& view, AccountID const&, uint256 const& delIndex, @@ -111,7 +111,7 @@ removeDepositPreauthFromLedger( TER removeNFTokenOfferFromLedger( - Application& app, + ServiceRegistry&, ApplyView& view, AccountID const& account, uint256 const& delIndex, @@ -126,7 +126,7 @@ removeNFTokenOfferFromLedger( TER removeDIDFromLedger( - Application& app, + ServiceRegistry&, ApplyView& view, AccountID const& account, uint256 const& delIndex, @@ -138,7 +138,7 @@ removeDIDFromLedger( TER removeOracleFromLedger( - Application&, + ServiceRegistry&, ApplyView& view, AccountID const& account, uint256 const&, @@ -150,7 +150,7 @@ removeOracleFromLedger( TER removeCredentialFromLedger( - Application&, + ServiceRegistry&, ApplyView& view, AccountID const&, uint256 const&, @@ -162,7 +162,7 @@ removeCredentialFromLedger( TER removeDelegateFromLedger( - Application& app, + ServiceRegistry&, ApplyView& view, AccountID const& account, uint256 const& delIndex, @@ -364,8 +364,8 @@ DeleteAccount::doApply() std::shared_ptr& sleItem) -> std::pair { if (auto deleter = nonObligationDeleter(nodeType)) { - TER const result{ - deleter(ctx_.app, view(), account_, dirEntry, sleItem, j_)}; + TER const result{deleter( + ctx_.registry, view(), account_, dirEntry, sleItem, j_)}; return {result, SkipEntry::No}; } diff --git a/src/xrpld/app/tx/detail/Escrow.cpp b/src/xrpld/app/tx/detail/Escrow.cpp index 4e5f41a427..2370930ea5 100644 --- a/src/xrpld/app/tx/detail/Escrow.cpp +++ b/src/xrpld/app/tx/detail/Escrow.cpp @@ -590,7 +590,7 @@ EscrowFinish::preflightSigValidated(PreflightContext const& ctx) if (cb && fb) { - auto& router = ctx.app.getHashRouter(); + auto& router = ctx.registry.getHashRouter(); auto const id = ctx.tx.getTransactionID(); auto const flags = router.getFlags(id); @@ -977,7 +977,7 @@ EscrowFinish::doApply() // Check cryptocondition fulfillment { auto const id = ctx_.tx.getTransactionID(); - auto flags = ctx_.app.getHashRouter().getFlags(id); + auto flags = ctx_.registry.getHashRouter().getFlags(id); auto const cb = ctx_.tx[~sfCondition]; @@ -997,7 +997,7 @@ EscrowFinish::doApply() else flags = SF_CF_INVALID; - ctx_.app.getHashRouter().setFlags(id, flags); + ctx_.registry.getHashRouter().setFlags(id, flags); // LCOV_EXCL_STOP } diff --git a/src/xrpld/app/tx/detail/PayChan.cpp b/src/xrpld/app/tx/detail/PayChan.cpp index 163ea802a8..3356f5d4f2 100644 --- a/src/xrpld/app/tx/detail/PayChan.cpp +++ b/src/xrpld/app/tx/detail/PayChan.cpp @@ -328,7 +328,7 @@ PayChanFund::doApply() if ((cancelAfter && closeTime >= *cancelAfter) || (expiration && closeTime >= *expiration)) return closeChannel( - slep, ctx_.view(), k.key, ctx_.app.journal("View")); + slep, ctx_.view(), k.key, ctx_.registry.journal("View")); } if (src != txAccount) @@ -485,7 +485,7 @@ PayChanClaim::doApply() if ((cancelAfter && closeTime >= *cancelAfter) || (curExpiration && closeTime >= *curExpiration)) return closeChannel( - slep, ctx_.view(), k.key, ctx_.app.journal("View")); + slep, ctx_.view(), k.key, ctx_.registry.journal("View")); } if (txAccount != src && txAccount != dst) @@ -546,7 +546,7 @@ PayChanClaim::doApply() // Channel will close immediately if dry or the receiver closes if (dst == txAccount || (*slep)[sfBalance] == (*slep)[sfAmount]) return closeChannel( - slep, ctx_.view(), k.key, ctx_.app.journal("View")); + slep, ctx_.view(), k.key, ctx_.registry.journal("View")); auto const settleExpiration = ctx_.view().header().parentCloseTime.time_since_epoch().count() + diff --git a/src/xrpld/app/tx/detail/Payment.cpp b/src/xrpld/app/tx/detail/Payment.cpp index 59c7431f4c..9f985c631b 100644 --- a/src/xrpld/app/tx/detail/Payment.cpp +++ b/src/xrpld/app/tx/detail/Payment.cpp @@ -455,7 +455,7 @@ Payment::doApply() account_, ctx_.tx.getFieldPathSet(sfPaths), ctx_.tx[~sfDomainID], - ctx_.app.logs(), + ctx_.registry.logs(), &rcInput); // VFALCO NOTE We might not need to apply, depending // on the TER. But always applying *should* diff --git a/src/xrpld/app/tx/detail/SetRegularKey.cpp b/src/xrpld/app/tx/detail/SetRegularKey.cpp index ff1dbdf769..c349ee8ec3 100644 --- a/src/xrpld/app/tx/detail/SetRegularKey.cpp +++ b/src/xrpld/app/tx/detail/SetRegularKey.cpp @@ -48,7 +48,7 @@ SetRegularKey::doApply() if (!sle) return tefINTERNAL; // LCOV_EXCL_LINE - if (!minimumFee(ctx_.app, ctx_.baseFee, view().fees(), view().flags())) + if (!minimumFee(ctx_.registry, ctx_.baseFee, view().fees(), view().flags())) sle->setFlag(lsfPasswordSpent); if (ctx_.tx.isFieldPresent(sfRegularKey)) diff --git a/src/xrpld/app/tx/detail/SetSignerList.cpp b/src/xrpld/app/tx/detail/SetSignerList.cpp index f65c17e303..17d81baf43 100644 --- a/src/xrpld/app/tx/detail/SetSignerList.cpp +++ b/src/xrpld/app/tx/detail/SetSignerList.cpp @@ -1,8 +1,8 @@ -#include #include #include #include +#include #include #include #include @@ -171,7 +171,7 @@ signerCountBasedOwnerCountDelta(std::size_t entryCount, Rules const& rules) static TER removeSignersFromLedger( - Application& app, + ServiceRegistry& registry, ApplyView& view, Keylet const& accountKeylet, Keylet const& ownerDirKeylet, @@ -213,7 +213,7 @@ removeSignersFromLedger( view, view.peek(accountKeylet), removeFromOwnerCount, - app.journal("View")); + registry.journal("View")); view.erase(signers); @@ -222,7 +222,7 @@ removeSignersFromLedger( TER SetSignerList::removeFromLedger( - Application& app, + ServiceRegistry& registry, ApplyView& view, AccountID const& account, beast::Journal j) @@ -232,7 +232,7 @@ SetSignerList::removeFromLedger( auto const signerListKeylet = keylet::signers(account); return removeSignersFromLedger( - app, view, accountKeylet, ownerDirKeylet, signerListKeylet, j); + registry, view, accountKeylet, ownerDirKeylet, signerListKeylet, j); } NotTEC @@ -306,7 +306,7 @@ SetSignerList::replaceSignerList() // old signer list. May reduce the reserve, so this is done before // checking the reserve. if (TER const ter = removeSignersFromLedger( - ctx_.app, + ctx_.registry, view(), accountKeylet, ownerDirKeylet, @@ -338,7 +338,7 @@ SetSignerList::replaceSignerList() view().insert(signerList); writeSignersToSLE(signerList, flags); - auto viewJ = ctx_.app.journal("View"); + auto viewJ = ctx_.registry.journal("View"); // Add the signer list to the account's directory. auto const page = ctx_.view().dirInsert( ownerDirKeylet, signerListKeylet, describeOwnerDir(account_)); @@ -374,7 +374,12 @@ SetSignerList::destroySignerList() auto const ownerDirKeylet = keylet::ownerDir(account_); auto const signerListKeylet = keylet::signers(account_); return removeSignersFromLedger( - ctx_.app, view(), accountKeylet, ownerDirKeylet, signerListKeylet, j_); + ctx_.registry, + view(), + accountKeylet, + ownerDirKeylet, + signerListKeylet, + j_); } void diff --git a/src/xrpld/app/tx/detail/SetSignerList.h b/src/xrpld/app/tx/detail/SetSignerList.h index f6f63d2b7d..971565e987 100644 --- a/src/xrpld/app/tx/detail/SetSignerList.h +++ b/src/xrpld/app/tx/detail/SetSignerList.h @@ -46,7 +46,7 @@ public: // Interface used by DeleteAccount static TER removeFromLedger( - Application& app, + ServiceRegistry& registry, ApplyView& view, AccountID const& account, beast::Journal j); diff --git a/src/xrpld/app/tx/detail/SetTrust.cpp b/src/xrpld/app/tx/detail/SetTrust.cpp index 77d7e6d9b5..be0c5cc3d0 100644 --- a/src/xrpld/app/tx/detail/SetTrust.cpp +++ b/src/xrpld/app/tx/detail/SetTrust.cpp @@ -376,7 +376,7 @@ SetTrust::doApply() bool const bSetDeepFreeze = (uTxFlags & tfSetDeepFreeze); bool const bClearDeepFreeze = (uTxFlags & tfClearDeepFreeze); - auto viewJ = ctx_.app.journal("View"); + auto viewJ = ctx_.registry.journal("View"); SLE::pointer sleDst = view().peek(keylet::account(uDstAccountID)); diff --git a/src/xrpld/app/tx/detail/Transactor.cpp b/src/xrpld/app/tx/detail/Transactor.cpp index 691443ed93..f28626c85a 100644 --- a/src/xrpld/app/tx/detail/Transactor.cpp +++ b/src/xrpld/app/tx/detail/Transactor.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -33,7 +34,7 @@ preflight0(PreflightContext const& ctx, std::uint32_t flagMask) if (!isPseudoTx(ctx.tx) || ctx.tx.isFieldPresent(sfNetworkID)) { - uint32_t nodeNID = ctx.app.config().NETWORK_ID; + uint32_t nodeNID = ctx.registry.getNetworkIDService().getNetworkID(); std::optional txNID = ctx.tx[~sfNetworkID]; if (nodeNID <= 1024) @@ -216,8 +217,8 @@ Transactor::preflight2(PreflightContext const& ctx) // Do not add any checks after this point that are relevant for // batch inner transactions. They will be skipped. - auto const sigValid = checkValidity( - ctx.app.getHashRouter(), ctx.tx, ctx.rules, ctx.app.config()); + auto const sigValid = + checkValidity(ctx.registry.getHashRouter(), ctx.tx, ctx.rules); if (sigValid.first == Validity::SigBad) { // LCOV_EXCL_START JLOG(ctx.j.debug()) << "preflight2: bad signature. " << sigValid.second; @@ -320,12 +321,13 @@ Transactor::calculateOwnerReserveFee(ReadView const& view, STTx const& tx) XRPAmount Transactor::minimumFee( - Application& app, + ServiceRegistry& registry, XRPAmount baseFee, Fees const& fees, ApplyFlags flags) { - return scaleFeeLoad(baseFee, app.getFeeTrack(), fees, flags & tapUNLIMITED); + return scaleFeeLoad( + baseFee, registry.getFeeTrack(), fees, flags & tapUNLIMITED); } TER @@ -352,7 +354,7 @@ Transactor::checkFee(PreclaimContext const& ctx, XRPAmount baseFee) if (ctx.view.open()) { auto const feeDue = - minimumFee(ctx.app, baseFee, ctx.view.fees(), ctx.flags); + minimumFee(ctx.registry, baseFee, ctx.view.fees(), ctx.flags); if (feePaid < feeDue) { @@ -1165,7 +1167,7 @@ Transactor::operator()() } #endif - if (auto const& trap = ctx_.app.trapTxID(); + if (auto const& trap = ctx_.registry.trapTxID(); trap && *trap == ctx_.tx.getTransactionID()) { trapTransaction(*trap); @@ -1277,19 +1279,19 @@ Transactor::operator()() // If necessary, remove any offers found unfunded during processing if ((result == tecOVERSIZE) || (result == tecKILLED)) removeUnfundedOffers( - view(), removedOffers, ctx_.app.journal("View")); + view(), removedOffers, ctx_.registry.journal("View")); if (result == tecEXPIRED) removeExpiredNFTokenOffers( - view(), expiredNFTokenOffers, ctx_.app.journal("View")); + view(), expiredNFTokenOffers, ctx_.registry.journal("View")); if (result == tecINCOMPLETE) removeDeletedTrustLines( - view(), removedTrustLines, ctx_.app.journal("View")); + view(), removedTrustLines, ctx_.registry.journal("View")); if (result == tecEXPIRED) removeExpiredCredentials( - view(), expiredCredentials, ctx_.app.journal("View")); + view(), expiredCredentials, ctx_.registry.journal("View")); applied = isTecClaim(result); } diff --git a/src/xrpld/app/tx/detail/Transactor.h b/src/xrpld/app/tx/detail/Transactor.h index 7d24df0a3b..5a82f62c0e 100644 --- a/src/xrpld/app/tx/detail/Transactor.h +++ b/src/xrpld/app/tx/detail/Transactor.h @@ -15,7 +15,7 @@ namespace xrpl { struct PreflightContext { public: - Application& app; + ServiceRegistry& registry; STTx const& tx; Rules const rules; ApplyFlags flags; @@ -23,13 +23,13 @@ public: beast::Journal const j; PreflightContext( - Application& app_, + ServiceRegistry& registry_, STTx const& tx_, uint256 parentBatchId_, Rules const& rules_, ApplyFlags flags_, beast::Journal j_ = beast::Journal{beast::Journal::getNullSink()}) - : app(app_) + : registry(registry_) , tx(tx_) , rules(rules_) , flags(flags_) @@ -41,12 +41,12 @@ public: } PreflightContext( - Application& app_, + ServiceRegistry& registry_, STTx const& tx_, Rules const& rules_, ApplyFlags flags_, beast::Journal j_ = beast::Journal{beast::Journal::getNullSink()}) - : app(app_), tx(tx_), rules(rules_), flags(flags_), j(j_) + : registry(registry_), tx(tx_), rules(rules_), flags(flags_), j(j_) { XRPL_ASSERT( (flags_ & tapBATCH) == 0, "Batch apply flag should not be set"); @@ -60,7 +60,7 @@ public: struct PreclaimContext { public: - Application& app; + ServiceRegistry& registry; ReadView const& view; TER preflightResult; ApplyFlags flags; @@ -69,14 +69,14 @@ public: beast::Journal const j; PreclaimContext( - Application& app_, + ServiceRegistry& registry_, ReadView const& view_, TER preflightResult_, STTx const& tx_, ApplyFlags flags_, std::optional parentBatchId_, beast::Journal j_ = beast::Journal{beast::Journal::getNullSink()}) - : app(app_) + : registry(registry_) , view(view_) , preflightResult(preflightResult_) , flags(flags_) @@ -90,14 +90,14 @@ public: } PreclaimContext( - Application& app_, + ServiceRegistry& registry_, ReadView const& view_, TER preflightResult_, STTx const& tx_, ApplyFlags flags_, beast::Journal j_ = beast::Journal{beast::Journal::getNullSink()}) : PreclaimContext( - app_, + registry_, view_, preflightResult_, tx_, @@ -245,7 +245,7 @@ protected: /** Compute the minimum fee required to process a transaction with a given baseFee based on the current server load. - @param app The application hosting the server + @param registry The service registry. @param baseFee The base fee of a candidate transaction @see xrpl::calculateBaseFee @param fees Fee settings from the current ledger @@ -253,7 +253,7 @@ protected: */ static XRPAmount minimumFee( - Application& app, + ServiceRegistry& registry, XRPAmount baseFee, Fees const& fees, ApplyFlags flags); diff --git a/src/xrpld/app/tx/detail/apply.cpp b/src/xrpld/app/tx/detail/apply.cpp index a75f0cc967..a98088b77f 100644 --- a/src/xrpld/app/tx/detail/apply.cpp +++ b/src/xrpld/app/tx/detail/apply.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -22,11 +23,7 @@ constexpr HashRouterFlags SF_LOCALGOOD = //------------------------------------------------------------------------------ std::pair -checkValidity( - HashRouter& router, - STTx const& tx, - Rules const& rules, - Config const& config) +checkValidity(HashRouter& router, STTx const& tx, Rules const& rules) { auto const id = tx.getTransactionID(); auto const flags = router.getFlags(id); @@ -118,42 +115,45 @@ forceValidity(HashRouter& router, uint256 const& txid, Validity validity) template ApplyResult -apply(Application& app, OpenView& view, PreflightChecks&& preflightChecks) +apply( + ServiceRegistry& registry, + OpenView& view, + PreflightChecks&& preflightChecks) { NumberSO stNumberSO{view.rules().enabled(fixUniversalNumber)}; - return doApply(preclaim(preflightChecks(), app, view), app, view); + return doApply(preclaim(preflightChecks(), registry, view), registry, view); } ApplyResult apply( - Application& app, + ServiceRegistry& registry, OpenView& view, STTx const& tx, ApplyFlags flags, beast::Journal j) { - return apply(app, view, [&]() mutable { - return preflight(app, view.rules(), tx, flags, j); + return apply(registry, view, [&]() mutable { + return preflight(registry, view.rules(), tx, flags, j); }); } ApplyResult apply( - Application& app, + ServiceRegistry& registry, OpenView& view, uint256 const& parentBatchId, STTx const& tx, ApplyFlags flags, beast::Journal j) { - return apply(app, view, [&]() mutable { - return preflight(app, view.rules(), parentBatchId, tx, flags, j); + return apply(registry, view, [&]() mutable { + return preflight(registry, view.rules(), parentBatchId, tx, flags, j); }); } static bool applyBatchTransactions( - Application& app, + ServiceRegistry& registry, OpenView& batchView, STTx const& batchTxn, beast::Journal j) @@ -167,11 +167,11 @@ applyBatchTransactions( auto const mode = batchTxn.getFlags(); auto applyOneTransaction = - [&app, &j, &parentBatchId, &batchView](STTx&& tx) { + [®istry, &j, &parentBatchId, &batchView](STTx&& tx) { OpenView perTxBatchView(batch_view, batchView); auto const ret = - apply(app, perTxBatchView, parentBatchId, tx, tapBATCH, j); + apply(registry, perTxBatchView, parentBatchId, tx, tapBATCH, j); XRPL_ASSERT( ret.applied == (isTesSuccess(ret.ter) || isTecClaim(ret.ter)), "Inner transaction should not be applied"); @@ -219,7 +219,7 @@ applyBatchTransactions( ApplyTransactionResult applyTransaction( - Application& app, + ServiceRegistry& registry, OpenView& view, STTx const& txn, bool retryAssured, @@ -235,7 +235,7 @@ applyTransaction( try { - auto const result = apply(app, view, txn, flags, j); + auto const result = apply(registry, view, txn, flags, j); if (result.applied) { @@ -248,7 +248,7 @@ applyTransaction( { OpenView wholeBatchView(batch_view, view); - if (applyBatchTransactions(app, wholeBatchView, txn, j)) + if (applyBatchTransactions(registry, wholeBatchView, txn, j)) wholeBatchView.apply(view); } diff --git a/src/xrpld/app/tx/detail/applySteps.cpp b/src/xrpld/app/tx/detail/applySteps.cpp index 0fae1a15e0..5a831a2eb2 100644 --- a/src/xrpld/app/tx/detail/applySteps.cpp +++ b/src/xrpld/app/tx/detail/applySteps.cpp @@ -14,6 +14,7 @@ // DO NOT INCLUDE TRANSACTOR HEADER FILES HERE. // See the instructions at the top of transactions.macro instead. +#include #include #include @@ -314,13 +315,13 @@ invoke_apply(ApplyContext& ctx) PreflightResult preflight( - Application& app, + ServiceRegistry& registry, Rules const& rules, STTx const& tx, ApplyFlags flags, beast::Journal j) { - PreflightContext const pfCtx(app, tx, rules, flags, j); + PreflightContext const pfCtx(registry, tx, rules, flags, j); try { return {pfCtx, invoke_preflight(pfCtx)}; @@ -334,14 +335,14 @@ preflight( PreflightResult preflight( - Application& app, + ServiceRegistry& registry, Rules const& rules, uint256 const& parentBatchId, STTx const& tx, ApplyFlags flags, beast::Journal j) { - PreflightContext const pfCtx(app, tx, parentBatchId, rules, flags, j); + PreflightContext const pfCtx(registry, tx, parentBatchId, rules, flags, j); try { return {pfCtx, invoke_preflight(pfCtx)}; @@ -356,7 +357,7 @@ preflight( PreclaimResult preclaim( PreflightResult const& preflightResult, - Application& app, + ServiceRegistry& registry, OpenView const& view) { std::optional ctx; @@ -365,7 +366,7 @@ preclaim( auto secondFlight = [&]() { if (preflightResult.parentBatchId) return preflight( - app, + registry, view.rules(), preflightResult.parentBatchId.value(), preflightResult.tx, @@ -373,7 +374,7 @@ preclaim( preflightResult.j); return preflight( - app, + registry, view.rules(), preflightResult.tx, preflightResult.flags, @@ -381,7 +382,7 @@ preclaim( }(); ctx.emplace( - app, + registry, view, secondFlight.ter, secondFlight.tx, @@ -392,7 +393,7 @@ preclaim( else { ctx.emplace( - app, + registry, view, preflightResult.ter, preflightResult.tx, @@ -427,7 +428,10 @@ calculateDefaultBaseFee(ReadView const& view, STTx const& tx) } ApplyResult -doApply(PreclaimResult const& preclaimResult, Application& app, OpenView& view) +doApply( + PreclaimResult const& preclaimResult, + ServiceRegistry& registry, + OpenView& view) { if (preclaimResult.view.seq() != view.seq()) { @@ -440,7 +444,7 @@ doApply(PreclaimResult const& preclaimResult, Application& app, OpenView& view) if (!preclaimResult.likelyToClaimFee) return {preclaimResult.ter, false}; ApplyContext ctx( - app, + registry, view, preclaimResult.parentBatchId, preclaimResult.tx, diff --git a/src/xrpld/core/NetworkIDServiceImpl.h b/src/xrpld/core/NetworkIDServiceImpl.h new file mode 100644 index 0000000000..6161d86fad --- /dev/null +++ b/src/xrpld/core/NetworkIDServiceImpl.h @@ -0,0 +1,35 @@ +#ifndef XRPLD_CORE_NETWORK_ID_SERVICE_IMPL_H_INCLUDED +#define XRPLD_CORE_NETWORK_ID_SERVICE_IMPL_H_INCLUDED + +#include + +#include + +namespace xrpl { + +// Forward declaration +class Config; + +/** Implementation of NetworkIDService that reads from Config. + + This class provides a NetworkIDService interface that wraps + the network ID from the application Config. It caches the + network ID at construction time. +*/ +class NetworkIDServiceImpl : public NetworkIDService +{ +public: + explicit NetworkIDServiceImpl(Config const& config); + + ~NetworkIDServiceImpl() override = default; + + std::uint32_t + getNetworkID() const override; + +private: + std::uint32_t networkID_; +}; + +} // namespace xrpl + +#endif diff --git a/src/xrpld/core/ServiceRegistryImpl.h b/src/xrpld/core/ServiceRegistryImpl.h index 3f29edccf0..1172c8480c 100644 --- a/src/xrpld/core/ServiceRegistryImpl.h +++ b/src/xrpld/core/ServiceRegistryImpl.h @@ -46,6 +46,9 @@ public: CachedSLEs& cachedSLEs() override; + NetworkIDService& + getNetworkIDService() override; + // Protocol and validation services AmendmentTable& getAmendmentTable() override; @@ -161,6 +164,9 @@ public: Logs& logs() override; + std::optional const& + trapTxID() const override; + // Temporary: Get the underlying Application Application& app() override; diff --git a/src/xrpld/core/detail/NetworkIDServiceImpl.cpp b/src/xrpld/core/detail/NetworkIDServiceImpl.cpp new file mode 100644 index 0000000000..a9eb48d766 --- /dev/null +++ b/src/xrpld/core/detail/NetworkIDServiceImpl.cpp @@ -0,0 +1,17 @@ +#include +#include + +namespace xrpl { + +NetworkIDServiceImpl::NetworkIDServiceImpl(Config const& config) + : networkID_(config.NETWORK_ID) +{ +} + +std::uint32_t +NetworkIDServiceImpl::getNetworkID() const +{ + return networkID_; +} + +} // namespace xrpl diff --git a/src/xrpld/core/detail/ServiceRegistryImpl.cpp b/src/xrpld/core/detail/ServiceRegistryImpl.cpp index b49f79188a..e116fc4847 100644 --- a/src/xrpld/core/detail/ServiceRegistryImpl.cpp +++ b/src/xrpld/core/detail/ServiceRegistryImpl.cpp @@ -1,4 +1,5 @@ #include +#include #include namespace xrpl { @@ -44,6 +45,12 @@ ServiceRegistryImpl::cachedSLEs() return app_.cachedSLEs(); } +NetworkIDService& +ServiceRegistryImpl::getNetworkIDService() +{ + return app_.getNetworkIDService(); +} + // Protocol and validation services AmendmentTable& ServiceRegistryImpl::getAmendmentTable() @@ -267,6 +274,12 @@ ServiceRegistryImpl::logs() return app_.logs(); } +std::optional const& +ServiceRegistryImpl::trapTxID() const +{ + return app_.trapTxID(); +} + Application& ServiceRegistryImpl::app() { diff --git a/src/xrpld/overlay/detail/PeerImp.cpp b/src/xrpld/overlay/detail/PeerImp.cpp index 6cf98b53ee..126b4566bd 100644 --- a/src/xrpld/overlay/detail/PeerImp.cpp +++ b/src/xrpld/overlay/detail/PeerImp.cpp @@ -3022,8 +3022,7 @@ PeerImp::checkTransaction( if (auto [valid, validReason] = checkValidity( app_.getHashRouter(), *stx, - app_.getLedgerMaster().getValidatedRules(), - app_.config()); + app_.getLedgerMaster().getValidatedRules()); valid != Validity::Valid) { if (!validReason.empty()) diff --git a/src/xrpld/rpc/detail/TransactionSign.cpp b/src/xrpld/rpc/detail/TransactionSign.cpp index 485765c133..ff95017aa3 100644 --- a/src/xrpld/rpc/detail/TransactionSign.cpp +++ b/src/xrpld/rpc/detail/TransactionSign.cpp @@ -705,9 +705,8 @@ transactionConstructImpl( app.getHashRouter(), sttxNew->getTransactionID(), Validity::SigGoodOnly); - if (checkValidity( - app.getHashRouter(), *sttxNew, rules, app.config()) - .first != Validity::Valid) + if (checkValidity(app.getHashRouter(), *sttxNew, rules).first != + Validity::Valid) { ret.first = RPC::make_error(rpcINTERNAL, "Invalid signature."); return ret; diff --git a/src/xrpld/rpc/detail/TransactionSign.h b/src/xrpld/rpc/detail/TransactionSign.h index c1480a44d0..aa5b706858 100644 --- a/src/xrpld/rpc/detail/TransactionSign.h +++ b/src/xrpld/rpc/detail/TransactionSign.h @@ -2,10 +2,11 @@ #define XRPL_RPC_TRANSACTIONSIGN_H_INCLUDED #include -#include #include #include +#include + namespace xrpl { // Forward declarations diff --git a/src/xrpld/rpc/handlers/Submit.cpp b/src/xrpld/rpc/handlers/Submit.cpp index e3888187ae..025461af43 100644 --- a/src/xrpld/rpc/handlers/Submit.cpp +++ b/src/xrpld/rpc/handlers/Submit.cpp @@ -85,8 +85,7 @@ doSubmit(RPC::JsonContext& context) auto [validity, reason] = checkValidity( context.app.getHashRouter(), *stTx, - context.ledgerMaster.getCurrentLedger()->rules(), - context.app.config()); + context.ledgerMaster.getCurrentLedger()->rules()); if (validity != Validity::Valid) { jvResult[jss::error] = "invalidTransaction";