diff --git a/.github/scripts/levelization/results/ordering.txt b/.github/scripts/levelization/results/ordering.txt index 1de6f803f3..5f8812c49b 100644 --- a/.github/scripts/levelization/results/ordering.txt +++ b/.github/scripts/levelization/results/ordering.txt @@ -1,4 +1,6 @@ libxrpl.basics > xrpl.basics +libxrpl.conditions > xrpl.basics +libxrpl.conditions > xrpl.conditions libxrpl.core > xrpl.basics libxrpl.core > xrpl.core libxrpl.crypto > xrpl.basics @@ -56,7 +58,7 @@ test.basics > xrpl.json test.basics > xrpl.protocol test.beast > xrpl.basics test.conditions > xrpl.basics -test.conditions > xrpld.conditions +test.conditions > xrpl.conditions test.consensus > test.csf test.consensus > test.toplevel test.consensus > test.unit_test @@ -158,6 +160,8 @@ test.unit_test > xrpl.basics tests.libxrpl > xrpl.basics tests.libxrpl > xrpl.json tests.libxrpl > xrpl.net +xrpl.conditions > xrpl.basics +xrpl.conditions > xrpl.protocol xrpl.core > xrpl.basics xrpl.core > xrpl.json xrpl.core > xrpl.ledger @@ -165,6 +169,7 @@ xrpl.core > xrpl.protocol xrpl.json > xrpl.basics xrpl.ledger > xrpl.basics xrpl.ledger > xrpl.protocol +xrpl.ledger > xrpl.server xrpl.net > xrpl.basics xrpl.nodestore > xrpl.basics xrpl.nodestore > xrpl.protocol @@ -179,7 +184,6 @@ xrpl.resource > xrpl.protocol xrpl.server > xrpl.basics xrpl.server > xrpl.core xrpl.server > xrpl.json -xrpl.server > xrpl.ledger xrpl.server > xrpl.protocol xrpl.server > xrpl.rdb xrpl.server > xrpl.resource @@ -189,8 +193,8 @@ xrpl.shamap > xrpl.nodestore xrpl.shamap > xrpl.protocol xrpld.app > test.unit_test xrpld.app > xrpl.basics +xrpld.app > xrpl.conditions xrpld.app > xrpl.core -xrpld.app > xrpld.conditions xrpld.app > xrpld.consensus xrpld.app > xrpld.core xrpld.app > xrpl.json @@ -202,8 +206,6 @@ xrpld.app > xrpl.rdb xrpld.app > xrpl.resource xrpld.app > xrpl.server xrpld.app > xrpl.shamap -xrpld.conditions > xrpl.basics -xrpld.conditions > xrpl.protocol xrpld.consensus > xrpl.basics xrpld.consensus > xrpl.json xrpld.consensus > xrpl.protocol diff --git a/cmake/XrplCore.cmake b/cmake/XrplCore.cmake index ba14899bd9..3380ca85cd 100644 --- a/cmake/XrplCore.cmake +++ b/cmake/XrplCore.cmake @@ -98,9 +98,18 @@ add_module(xrpl server) target_link_libraries(xrpl.libxrpl.server PUBLIC xrpl.libxrpl.protocol xrpl.libxrpl.core xrpl.libxrpl.rdb xrpl.libxrpl.resource) +add_module(xrpl conditions) +target_link_libraries(xrpl.libxrpl.conditions PUBLIC xrpl.libxrpl.server) + add_module(xrpl ledger) -target_link_libraries(xrpl.libxrpl.ledger PUBLIC xrpl.libxrpl.basics xrpl.libxrpl.json xrpl.libxrpl.protocol - xrpl.libxrpl.rdb) +target_link_libraries( + xrpl.libxrpl.ledger + PUBLIC xrpl.libxrpl.basics + xrpl.libxrpl.json + xrpl.libxrpl.protocol + xrpl.libxrpl.rdb + xrpl.libxrpl.server + xrpl.libxrpl.conditions) add_library(xrpl.libxrpl) set_target_properties(xrpl.libxrpl PROPERTIES OUTPUT_NAME xrpl) @@ -115,6 +124,7 @@ target_link_modules( PUBLIC basics beast + conditions core crypto json diff --git a/cmake/XrplInstall.cmake b/cmake/XrplInstall.cmake index 340dca553b..d2fef5d488 100644 --- a/cmake/XrplInstall.cmake +++ b/cmake/XrplInstall.cmake @@ -20,6 +20,7 @@ install(TARGETS common xrpl.libxrpl xrpl.libxrpl.basics xrpl.libxrpl.beast + xrpl.libxrpl.conditions xrpl.libxrpl.core xrpl.libxrpl.crypto xrpl.libxrpl.json diff --git a/src/xrpld/conditions/Condition.h b/include/xrpl/conditions/Condition.h similarity index 98% rename from src/xrpld/conditions/Condition.h rename to include/xrpl/conditions/Condition.h index 50872e75ef..6b306a3982 100644 --- a/src/xrpld/conditions/Condition.h +++ b/include/xrpl/conditions/Condition.h @@ -1,9 +1,8 @@ #pragma once -#include - #include #include +#include #include #include diff --git a/src/xrpld/conditions/Fulfillment.h b/include/xrpl/conditions/Fulfillment.h similarity index 98% rename from src/xrpld/conditions/Fulfillment.h rename to include/xrpl/conditions/Fulfillment.h index 840e9f9993..04d0b2aa1e 100644 --- a/src/xrpld/conditions/Fulfillment.h +++ b/include/xrpl/conditions/Fulfillment.h @@ -1,9 +1,8 @@ #pragma once -#include - #include #include +#include namespace xrpl { namespace cryptoconditions { diff --git a/src/xrpld/conditions/detail/PreimageSha256.h b/include/xrpl/conditions/detail/PreimageSha256.h similarity index 95% rename from src/xrpld/conditions/detail/PreimageSha256.h rename to include/xrpl/conditions/detail/PreimageSha256.h index f3ce1a03e0..8726473c2d 100644 --- a/src/xrpld/conditions/detail/PreimageSha256.h +++ b/include/xrpl/conditions/detail/PreimageSha256.h @@ -1,11 +1,10 @@ #pragma once -#include -#include -#include - #include #include +#include +#include +#include #include #include diff --git a/src/xrpld/conditions/detail/error.h b/include/xrpl/conditions/detail/error.h similarity index 100% rename from src/xrpld/conditions/detail/error.h rename to include/xrpl/conditions/detail/error.h diff --git a/src/xrpld/conditions/detail/utils.h b/include/xrpl/conditions/detail/utils.h similarity index 98% rename from src/xrpld/conditions/detail/utils.h rename to include/xrpl/conditions/detail/utils.h index 2a4187718b..17d93d43b5 100644 --- a/src/xrpld/conditions/detail/utils.h +++ b/include/xrpl/conditions/detail/utils.h @@ -1,9 +1,8 @@ #pragma once -#include - #include #include +#include #include diff --git a/src/xrpld/app/misc/HashRouter.h b/include/xrpl/core/HashRouter.h similarity index 99% rename from src/xrpld/app/misc/HashRouter.h rename to include/xrpl/core/HashRouter.h index ad6da520bd..dfc57081ee 100644 --- a/src/xrpld/app/misc/HashRouter.h +++ b/include/xrpl/core/HashRouter.h @@ -251,7 +251,4 @@ private: beast::aged_unordered_map> suppressionMap_; }; -HashRouter::Setup -setup_HashRouter(Config const&); - } // namespace xrpl diff --git a/include/xrpl/core/ServiceRegistry.h b/include/xrpl/core/ServiceRegistry.h index 86591a815f..fabf61f9e4 100644 --- a/include/xrpl/core/ServiceRegistry.h +++ b/include/xrpl/core/ServiceRegistry.h @@ -214,6 +214,13 @@ public: virtual Logs& logs() = 0; + virtual std::optional const& + trapTxID() const = 0; + + /** Retrieve the "wallet database" */ + virtual DatabaseCon& + getWalletDB() = 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/xrpld/app/ledger/AcceptedLedgerTx.h b/include/xrpl/ledger/AcceptedLedgerTx.h similarity index 92% rename from src/xrpld/app/ledger/AcceptedLedgerTx.h rename to include/xrpl/ledger/AcceptedLedgerTx.h index 6c936bbcf2..d07016b860 100644 --- a/src/xrpld/app/ledger/AcceptedLedgerTx.h +++ b/include/xrpl/ledger/AcceptedLedgerTx.h @@ -1,15 +1,15 @@ #pragma once -#include - +#include +#include #include +#include +#include #include namespace xrpl { -class Logs; - /** A transaction that is in a closed ledger. diff --git a/src/xrpld/app/ledger/BookListeners.h b/include/xrpl/ledger/BookListeners.h similarity index 100% rename from src/xrpld/app/ledger/BookListeners.h rename to include/xrpl/ledger/BookListeners.h diff --git a/include/xrpl/ledger/OrderBookDB.h b/include/xrpl/ledger/OrderBookDB.h new file mode 100644 index 0000000000..3d689607bf --- /dev/null +++ b/include/xrpl/ledger/OrderBookDB.h @@ -0,0 +1,93 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace xrpl { + +/** Tracks order books in the ledger. + + This interface provides access to order book information, including: + - Which order books exist in the ledger + - Querying order books by issue + - Managing order book subscriptions + + The order book database is updated as ledgers are accepted and provides + efficient lookup of order book information for pathfinding and client + subscriptions. +*/ +class OrderBookDB +{ +public: + virtual ~OrderBookDB() = default; + + /** Initialize or update the order book database with a new ledger. + + This method should be called when a new ledger is accepted to update + the order book database with the current state of all order books. + + @param ledger The ledger to scan for order books + */ + virtual void + setup(std::shared_ptr const& ledger) = 0; + + /** Add an order book to track. + + @param book The order book to add + */ + virtual void + addOrderBook(Book const& book) = 0; + + /** Get all order books that want a specific issue. + + Returns a list of all order books where the taker pays the specified + issue. This is useful for pathfinding to find all possible next hops + from a given currency. + + @param issue The issue to search for + @param domain Optional domain restriction for the order book + @return Vector of books that want this issue + */ + virtual std::vector + getBooksByTakerPays(Issue const& issue, std::optional const& domain = std::nullopt) = 0; + + /** Get the count of order books that want a specific issue. + + @param issue The issue to search for + @param domain Optional domain restriction for the order book + @return Number of books that want this issue + */ + virtual int + getBookSize(Issue const& issue, std::optional const& domain = std::nullopt) = 0; + + /** Check if an order book to XRP exists for the given issue. + + @param issue The issue to check + @param domain Optional domain restriction for the order book + @return true if a book from this issue to XRP exists + */ + virtual bool + isBookToXRP(Issue const& issue, std::optional domain = std::nullopt) = 0; + + virtual void + processTxn( + std::shared_ptr const& ledger, + AcceptedLedgerTx const& alTx, + MultiApiJson const& jvObj) = 0; + + virtual BookListeners::pointer + getBookListeners(Book const&) = 0; + virtual BookListeners::pointer + makeBookListeners(Book const&) = 0; +}; + +} // namespace xrpl diff --git a/include/xrpl/server/NetworkOPs.h b/include/xrpl/server/NetworkOPs.h index cfe0021c07..ce55f667f7 100644 --- a/include/xrpl/server/NetworkOPs.h +++ b/include/xrpl/server/NetworkOPs.h @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -19,6 +18,8 @@ namespace xrpl { // Master operational handler, server sequencer, network tracker class Peer; +class STTx; +class ReadView; class LedgerMaster; class Transaction; class ValidatorKeys; diff --git a/src/xrpld/conditions/detail/Condition.cpp b/src/libxrpl/conditions/Condition.cpp similarity index 97% rename from src/xrpld/conditions/detail/Condition.cpp rename to src/libxrpl/conditions/Condition.cpp index 9cac75121d..30beba3402 100644 --- a/src/xrpld/conditions/detail/Condition.cpp +++ b/src/libxrpl/conditions/Condition.cpp @@ -1,6 +1,6 @@ -#include -#include -#include +#include +#include +#include namespace xrpl { namespace cryptoconditions { diff --git a/src/xrpld/conditions/detail/Fulfillment.cpp b/src/libxrpl/conditions/Fulfillment.cpp similarity index 94% rename from src/xrpld/conditions/detail/Fulfillment.cpp rename to src/libxrpl/conditions/Fulfillment.cpp index 9ecaa44ab8..11581a8705 100644 --- a/src/xrpld/conditions/detail/Fulfillment.cpp +++ b/src/libxrpl/conditions/Fulfillment.cpp @@ -1,9 +1,8 @@ -#include -#include -#include -#include - #include +#include +#include +#include +#include namespace xrpl { namespace cryptoconditions { diff --git a/src/xrpld/conditions/detail/error.cpp b/src/libxrpl/conditions/error.cpp similarity index 98% rename from src/xrpld/conditions/detail/error.cpp rename to src/libxrpl/conditions/error.cpp index 04c8d03fbb..3124be6fdd 100644 --- a/src/xrpld/conditions/detail/error.cpp +++ b/src/libxrpl/conditions/error.cpp @@ -1,6 +1,5 @@ -#include - #include +#include #include diff --git a/src/xrpld/app/misc/HashRouter.cpp b/src/libxrpl/core/HashRouter.cpp similarity index 69% rename from src/xrpld/app/misc/HashRouter.cpp rename to src/libxrpl/core/HashRouter.cpp index eca46c9872..dff1394f77 100644 --- a/src/xrpld/app/misc/HashRouter.cpp +++ b/src/libxrpl/core/HashRouter.cpp @@ -1,5 +1,4 @@ -#include -#include +#include namespace xrpl { @@ -108,38 +107,4 @@ HashRouter::shouldRelay(uint256 const& key) -> std::optional( - "HashRouter hold time must be at least 12 seconds (the " - "approximate validation time for three ledgers)."); - setup.holdTime = seconds(tmp); - } - if (set(tmp, "relay_time", section)) - { - if (tmp < 8) - Throw( - "HashRouter relay time must be at least 8 seconds (the " - "approximate validation time for two ledgers)."); - setup.relayTime = seconds(tmp); - } - if (setup.relayTime > setup.holdTime) - { - Throw("HashRouter relay time must be less than or equal to hold time"); - } - - return setup; -} - } // namespace xrpl diff --git a/src/xrpld/app/ledger/AcceptedLedgerTx.cpp b/src/libxrpl/ledger/AcceptedLedgerTx.cpp similarity index 96% rename from src/xrpld/app/ledger/AcceptedLedgerTx.cpp rename to src/libxrpl/ledger/AcceptedLedgerTx.cpp index 2ef05e511d..3f35f7cbc2 100644 --- a/src/xrpld/app/ledger/AcceptedLedgerTx.cpp +++ b/src/libxrpl/ledger/AcceptedLedgerTx.cpp @@ -1,7 +1,7 @@ -#include - #include #include +#include +#include #include #include diff --git a/src/xrpld/app/ledger/BookListeners.cpp b/src/libxrpl/ledger/BookListeners.cpp similarity index 95% rename from src/xrpld/app/ledger/BookListeners.cpp rename to src/libxrpl/ledger/BookListeners.cpp index 4d72c6f3b3..9ba25b783a 100644 --- a/src/xrpld/app/ledger/BookListeners.cpp +++ b/src/libxrpl/ledger/BookListeners.cpp @@ -1,4 +1,4 @@ -#include +#include namespace xrpl { diff --git a/src/test/app/Batch_test.cpp b/src/test/app/Batch_test.cpp index 133f10cd28..a4e00f26db 100644 --- a/src/test/app/Batch_test.cpp +++ b/src/test/app/Batch_test.cpp @@ -2,11 +2,11 @@ #include #include -#include #include #include #include +#include #include #include #include diff --git a/src/test/app/HashRouter_test.cpp b/src/test/app/HashRouter_test.cpp index 03bb28e35a..753922a67d 100644 --- a/src/test/app/HashRouter_test.cpp +++ b/src/test/app/HashRouter_test.cpp @@ -1,8 +1,9 @@ -#include +#include #include #include #include +#include namespace xrpl { namespace test { diff --git a/src/test/app/NetworkOPs_test.cpp b/src/test/app/NetworkOPs_test.cpp index ffca1ed79d..a4bdae9101 100644 --- a/src/test/app/NetworkOPs_test.cpp +++ b/src/test/app/NetworkOPs_test.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include namespace xrpl { namespace test { diff --git a/src/test/conditions/PreimageSha256_test.cpp b/src/test/conditions/PreimageSha256_test.cpp index 71ba526be3..c3508758a7 100644 --- a/src/test/conditions/PreimageSha256_test.cpp +++ b/src/test/conditions/PreimageSha256_test.cpp @@ -1,12 +1,11 @@ -#include -#include -#include - #include #include #include #include #include +#include +#include +#include #include #include diff --git a/src/xrpld/app/consensus/RCLConsensus.cpp b/src/xrpld/app/consensus/RCLConsensus.cpp index 4ebd1a502f..ad581585b1 100644 --- a/src/xrpld/app/consensus/RCLConsensus.cpp +++ b/src/xrpld/app/consensus/RCLConsensus.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -21,6 +20,7 @@ #include #include #include +#include #include #include #include diff --git a/src/xrpld/app/ledger/AcceptedLedger.cpp b/src/xrpld/app/ledger/AcceptedLedger.cpp index 89806c2337..7ad43b2d81 100644 --- a/src/xrpld/app/ledger/AcceptedLedger.cpp +++ b/src/xrpld/app/ledger/AcceptedLedger.cpp @@ -4,7 +4,7 @@ namespace xrpl { -AcceptedLedger::AcceptedLedger(std::shared_ptr const& ledger, Application& app) : mLedger(ledger) +AcceptedLedger::AcceptedLedger(std::shared_ptr const& ledger) : mLedger(ledger) { transactions_.reserve(256); diff --git a/src/xrpld/app/ledger/AcceptedLedger.h b/src/xrpld/app/ledger/AcceptedLedger.h index c0f186c781..23cee6ce35 100644 --- a/src/xrpld/app/ledger/AcceptedLedger.h +++ b/src/xrpld/app/ledger/AcceptedLedger.h @@ -1,6 +1,8 @@ #pragma once -#include +#include +#include +#include namespace xrpl { @@ -23,7 +25,7 @@ namespace xrpl { class AcceptedLedger : public CountedObject { public: - AcceptedLedger(std::shared_ptr const& ledger, Application& app); + AcceptedLedger(std::shared_ptr const& ledger); std::shared_ptr const& getLedger() const diff --git a/src/xrpld/app/ledger/Ledger.cpp b/src/xrpld/app/ledger/Ledger.cpp index 0f44601679..d75e4dd22e 100644 --- a/src/xrpld/app/ledger/Ledger.cpp +++ b/src/xrpld/app/ledger/Ledger.cpp @@ -3,13 +3,13 @@ #include #include #include -#include #include #include #include #include #include +#include #include #include #include diff --git a/src/xrpld/app/ledger/OrderBookDB.h b/src/xrpld/app/ledger/OrderBookDB.h deleted file mode 100644 index da604d7e22..0000000000 --- a/src/xrpld/app/ledger/OrderBookDB.h +++ /dev/null @@ -1,75 +0,0 @@ -#pragma once - -#include -#include -#include - -#include -#include - -#include -#include - -namespace xrpl { - -class OrderBookDB -{ -public: - explicit OrderBookDB(Application& app); - - void - setup(std::shared_ptr const& ledger); - void - update(std::shared_ptr const& ledger); - - void - addOrderBook(Book const&); - - /** @return a list of all orderbooks that want this issuerID and currencyID. - */ - std::vector - getBooksByTakerPays(Issue const&, std::optional const& domain = std::nullopt); - - /** @return a count of all orderbooks that want this issuerID and - currencyID. */ - int - getBookSize(Issue const&, std::optional const& domain = std::nullopt); - - bool - isBookToXRP(Issue const&, std::optional domain = std::nullopt); - - BookListeners::pointer - getBookListeners(Book const&); - BookListeners::pointer - makeBookListeners(Book const&); - - // see if this txn effects any orderbook - void - processTxn(std::shared_ptr const& ledger, AcceptedLedgerTx const& alTx, MultiApiJson const& jvObj); - -private: - Application& app_; - - // Maps order books by "issue in" to "issue out": - hardened_hash_map> allBooks_; - - hardened_hash_map, hardened_hash_set> domainBooks_; - - // does an order book to XRP exist - hash_set xrpBooks_; - - // does an order book to XRP exist - hash_set> xrpDomainBooks_; - - std::recursive_mutex mLock; - - using BookToListenersMap = hash_map; - - BookToListenersMap mListeners; - - std::atomic seq_; - - beast::Journal const j_; -}; - -} // namespace xrpl diff --git a/src/xrpld/app/ledger/OrderBookDB.cpp b/src/xrpld/app/ledger/OrderBookDBImpl.cpp similarity index 84% rename from src/xrpld/app/ledger/OrderBookDB.cpp rename to src/xrpld/app/ledger/OrderBookDBImpl.cpp index 6450544f92..62c03fb7ca 100644 --- a/src/xrpld/app/ledger/OrderBookDB.cpp +++ b/src/xrpld/app/ledger/OrderBookDBImpl.cpp @@ -1,6 +1,5 @@ #include -#include -#include +#include #include #include @@ -11,14 +10,25 @@ namespace xrpl { -OrderBookDB::OrderBookDB(Application& app) : app_(app), seq_(0), j_(app.journal("OrderBookDB")) +OrderBookDBImpl::OrderBookDBImpl(ServiceRegistry& registry, OrderBookDBConfig const& config) + : registry_(registry) + , pathSearchMax_(config.pathSearchMax) + , standalone_(config.standalone) + , seq_(0) + , j_(registry.journal("OrderBookDB")) { } -void -OrderBookDB::setup(std::shared_ptr const& ledger) +std::unique_ptr +make_OrderBookDB(ServiceRegistry& registry, OrderBookDBConfig const& config) { - if (!app_.config().standalone() && app_.getOPs().isNeedNetworkLedger()) + return std::make_unique(registry, config); +} + +void +OrderBookDBImpl::setup(std::shared_ptr const& ledger) +{ + if (!standalone_ && registry_.getOPs().isNeedNetworkLedger()) { JLOG(j_.warn()) << "Eliding full order book update: no ledger"; return; @@ -40,19 +50,20 @@ OrderBookDB::setup(std::shared_ptr const& ledger) JLOG(j_.debug()) << "Full order book update: " << seq << " to " << ledger->seq(); - if (app_.config().PATH_SEARCH_MAX != 0) + if (pathSearchMax_ != 0) { - if (app_.config().standalone()) + if (standalone_) update(ledger); else - app_.getJobQueue().addJob(jtUPDATE_PF, "OrderBookUpd", [this, ledger]() { update(ledger); }); + registry_.getJobQueue().addJob( + jtUPDATE_PF, "OrderBookUpd" + std::to_string(ledger->seq()), [this, ledger]() { update(ledger); }); } } void -OrderBookDB::update(std::shared_ptr const& ledger) +OrderBookDBImpl::update(std::shared_ptr const& ledger) { - if (app_.config().PATH_SEARCH_MAX == 0) + if (pathSearchMax_ == 0) return; // pathfinding has been disabled // A newer full update job is pending @@ -79,7 +90,7 @@ OrderBookDB::update(std::shared_ptr const& ledger) { for (auto& sle : ledger->sles) { - if (app_.isStopping()) + if (registry_.isStopping()) { JLOG(j_.info()) << "Update halted because the process is stopping"; seq_.store(0); @@ -143,11 +154,11 @@ OrderBookDB::update(std::shared_ptr const& ledger) xrpDomainBooks_.swap(xrpDomainBooks); } - app_.getLedgerMaster().newOrderBookDB(); + registry_.getLedgerMaster().newOrderBookDB(); } void -OrderBookDB::addOrderBook(Book const& book) +OrderBookDBImpl::addOrderBook(Book const& book) { bool toXRP = isXRP(book.out); @@ -166,7 +177,7 @@ OrderBookDB::addOrderBook(Book const& book) // return list of all orderbooks that want this issuerID and currencyID std::vector -OrderBookDB::getBooksByTakerPays(Issue const& issue, std::optional const& domain) +OrderBookDBImpl::getBooksByTakerPays(Issue const& issue, std::optional const& domain) { std::vector ret; @@ -194,7 +205,7 @@ OrderBookDB::getBooksByTakerPays(Issue const& issue, std::optional cons } int -OrderBookDB::getBookSize(Issue const& issue, std::optional const& domain) +OrderBookDBImpl::getBookSize(Issue const& issue, std::optional const& domain) { std::lock_guard sl(mLock); @@ -213,7 +224,7 @@ OrderBookDB::getBookSize(Issue const& issue, std::optional const& domai } bool -OrderBookDB::isBookToXRP(Issue const& issue, std::optional domain) +OrderBookDBImpl::isBookToXRP(Issue const& issue, std::optional domain) { std::lock_guard sl(mLock); if (domain) @@ -222,7 +233,7 @@ OrderBookDB::isBookToXRP(Issue const& issue, std::optional domain) } BookListeners::pointer -OrderBookDB::makeBookListeners(Book const& book) +OrderBookDBImpl::makeBookListeners(Book const& book) { std::lock_guard sl(mLock); auto ret = getBookListeners(book); @@ -242,7 +253,7 @@ OrderBookDB::makeBookListeners(Book const& book) } BookListeners::pointer -OrderBookDB::getBookListeners(Book const& book) +OrderBookDBImpl::getBookListeners(Book const& book) { BookListeners::pointer ret; std::lock_guard sl(mLock); @@ -257,7 +268,7 @@ OrderBookDB::getBookListeners(Book const& book) // Based on the meta, send the meta to the streams that are listening. // We need to determine which streams a given meta effects. void -OrderBookDB::processTxn( +OrderBookDBImpl::processTxn( std::shared_ptr const& ledger, AcceptedLedgerTx const& alTx, MultiApiJson const& jvObj) diff --git a/src/xrpld/app/ledger/OrderBookDBImpl.h b/src/xrpld/app/ledger/OrderBookDBImpl.h new file mode 100644 index 0000000000..69739451c4 --- /dev/null +++ b/src/xrpld/app/ledger/OrderBookDBImpl.h @@ -0,0 +1,93 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace xrpl { + +/** Configuration for OrderBookDB */ +struct OrderBookDBConfig +{ + int pathSearchMax; + bool standalone; +}; + +/** Create an OrderBookDB instance. + + @param registry Service registry for accessing other services + @param config Configuration parameters + @return A new OrderBookDB instance +*/ +std::unique_ptr +make_OrderBookDB(ServiceRegistry& registry, OrderBookDBConfig const& config); + +class OrderBookDBImpl final : public OrderBookDB +{ +public: + OrderBookDBImpl(ServiceRegistry& registry, OrderBookDBConfig const& config); + + // OrderBookDB interface implementation + void + setup(std::shared_ptr const& ledger) override; + + void + addOrderBook(Book const& book) override; + + std::vector + getBooksByTakerPays(Issue const& issue, std::optional const& domain = std::nullopt) override; + + int + getBookSize(Issue const& issue, std::optional const& domain = std::nullopt) override; + + bool + isBookToXRP(Issue const& issue, std::optional domain = std::nullopt) override; + + // OrderBookDBImpl-specific methods + void + update(std::shared_ptr const& ledger); + + // see if this txn effects any orderbook + void + processTxn(std::shared_ptr const& ledger, AcceptedLedgerTx const& alTx, MultiApiJson const& jvObj) + override; + + BookListeners::pointer + getBookListeners(Book const&) override; + BookListeners::pointer + makeBookListeners(Book const&) override; + +private: + ServiceRegistry& registry_; + int const pathSearchMax_; + bool const standalone_; + + // Maps order books by "issue in" to "issue out": + hardened_hash_map> allBooks_; + + hardened_hash_map, hardened_hash_set> domainBooks_; + + // does an order book to XRP exist + hash_set xrpBooks_; + + // does an order book to XRP exist + hash_set> xrpDomainBooks_; + + std::recursive_mutex mLock; + + using BookToListenersMap = hash_map; + + BookToListenersMap mListeners; + + std::atomic seq_; + + beast::Journal const j_; +}; + +} // namespace xrpl diff --git a/src/xrpld/app/ledger/detail/LedgerMaster.cpp b/src/xrpld/app/ledger/detail/LedgerMaster.cpp index f8ef91a83f..5538ebcb96 100644 --- a/src/xrpld/app/ledger/detail/LedgerMaster.cpp +++ b/src/xrpld/app/ledger/detail/LedgerMaster.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -24,6 +23,7 @@ #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 698862d4da..d621285619 100644 --- a/src/xrpld/app/ledger/detail/OpenLedger.cpp +++ b/src/xrpld/app/ledger/detail/OpenLedger.cpp @@ -1,11 +1,11 @@ #include #include -#include #include #include #include #include +#include #include #include diff --git a/src/xrpld/app/main/Application.cpp b/src/xrpld/app/main/Application.cpp index 3f7b6c5596..4612479b78 100644 --- a/src/xrpld/app/main/Application.cpp +++ b/src/xrpld/app/main/Application.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include @@ -16,13 +16,13 @@ #include #include #include -#include #include #include #include #include #include #include +#include #include #include #include @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -164,8 +165,7 @@ public: std::unique_ptr m_nodeStore; NodeFamily nodeFamily_; - // VFALCO TODO Make OrderBookDB abstract - OrderBookDB m_orderBookDB; + std::unique_ptr m_orderBookDB; std::unique_ptr m_pathRequests; std::unique_ptr m_ledgerMaster; std::unique_ptr ledgerCleaner_; @@ -296,7 +296,7 @@ public: , nodeFamily_(*this, *m_collectorManager) - , m_orderBookDB(*this) + , m_orderBookDB(make_OrderBookDB(*this, {config_->PATH_SEARCH_MAX, config_->standalone()})) , m_pathRequests( std::make_unique(*this, logs_->journal("PathRequest"), m_collectorManager->collector())) @@ -613,7 +613,7 @@ public: OrderBookDB& getOrderBookDB() override { - return m_orderBookDB; + return *m_orderBookDB; } PathRequests& @@ -1170,7 +1170,7 @@ ApplicationImp::setup(boost::program_options::variables_map const& cmdline) m_ledgerMaster->setLedgerRangePresent(forcedRange->first, forcedRange->second); } - m_orderBookDB.setup(getLedgerMaster().getCurrentLedger()); + m_orderBookDB->setup(getLedgerMaster().getCurrentLedger()); nodeIdentity_ = getNodeIdentity(*this, cmdline); diff --git a/src/xrpld/app/main/Application.h b/src/xrpld/app/main/Application.h index 5ecc84c11c..a0fea69171 100644 --- a/src/xrpld/app/main/Application.h +++ b/src/xrpld/app/main/Application.h @@ -153,17 +153,10 @@ public: virtual int fdRequired() const = 0; - /** Retrieve the "wallet database" */ - virtual DatabaseCon& - getWalletDB() = 0; - /** Ensure that a newly-started validator does not sign proposals older * than the last ledger it persisted. */ virtual LedgerIndex getMaxDisallowedLedger() = 0; - - virtual std::optional const& - trapTxID() const = 0; }; std::unique_ptr diff --git a/src/xrpld/app/misc/AmendmentTable.h b/src/xrpld/app/misc/AmendmentTable.h index 94ac9608a7..bfef818b0a 100644 --- a/src/xrpld/app/misc/AmendmentTable.h +++ b/src/xrpld/app/misc/AmendmentTable.h @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -163,7 +164,7 @@ public: std::unique_ptr make_AmendmentTable( - Application& app, + ServiceRegistry& registry, std::chrono::seconds majorityTime, std::vector const& supported, Section const& enabled, diff --git a/src/xrpld/app/misc/NetworkOPs.cpp b/src/xrpld/app/misc/NetworkOPs.cpp index 9e60a8bdc0..8732f9610d 100644 --- a/src/xrpld/app/misc/NetworkOPs.cpp +++ b/src/xrpld/app/misc/NetworkOPs.cpp @@ -7,13 +7,11 @@ #include #include #include -#include #include #include #include #include #include -#include #include #include #include @@ -39,9 +37,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -2824,7 +2824,7 @@ NetworkOPsImp::pubLedger(std::shared_ptr const& lpAccepted) std::shared_ptr alpAccepted = registry_.getAcceptedLedgerCache().fetch(lpAccepted->header().hash); if (!alpAccepted) { - alpAccepted = std::make_shared(lpAccepted, registry_.app()); + alpAccepted = std::make_shared(lpAccepted); registry_.getAcceptedLedgerCache().canonicalize_replace_client(lpAccepted->header().hash, alpAccepted); } diff --git a/src/xrpld/app/misc/detail/AmendmentTable.cpp b/src/xrpld/app/misc/detail/AmendmentTable.cpp index 3addfd2235..767a3d87f9 100644 --- a/src/xrpld/app/misc/detail/AmendmentTable.cpp +++ b/src/xrpld/app/misc/detail/AmendmentTable.cpp @@ -1,7 +1,7 @@ -#include #include #include +#include #include #include #include @@ -400,7 +400,7 @@ private: public: AmendmentTableImpl( - Application& app, + ServiceRegistry& registry, std::chrono::seconds majorityTime, std::vector const& supported, Section const& enabled, @@ -461,13 +461,17 @@ public: //------------------------------------------------------------------------------ AmendmentTableImpl::AmendmentTableImpl( - Application& app, + ServiceRegistry& registry, std::chrono::seconds majorityTime, std::vector const& supported, Section const& enabled, Section const& vetoed, beast::Journal journal) - : lastUpdateSeq_(0), majorityTime_(majorityTime), unsupportedEnabled_(false), j_(journal), db_(app.getWalletDB()) + : lastUpdateSeq_(0) + , majorityTime_(majorityTime) + , unsupportedEnabled_(false) + , j_(journal) + , db_(registry.getWalletDB()) { std::lock_guard lock(mutex_); @@ -957,14 +961,14 @@ AmendmentTableImpl::getJson(uint256 const& amendmentID, bool isAdmin) const std::unique_ptr make_AmendmentTable( - Application& app, + ServiceRegistry& registry, std::chrono::seconds majorityTime, std::vector const& supported, Section const& enabled, Section const& vetoed, beast::Journal journal) { - return std::make_unique(app, majorityTime, supported, enabled, vetoed, journal); + return std::make_unique(registry, majorityTime, supported, enabled, vetoed, journal); } } // namespace xrpl diff --git a/src/xrpld/app/misc/detail/Transaction.cpp b/src/xrpld/app/misc/detail/Transaction.cpp index 8ffbc47b08..d45c49c3c4 100644 --- a/src/xrpld/app/misc/detail/Transaction.cpp +++ b/src/xrpld/app/misc/detail/Transaction.cpp @@ -1,11 +1,11 @@ #include #include -#include #include #include #include #include +#include #include #include #include diff --git a/src/xrpld/app/misc/detail/ValidatorList.cpp b/src/xrpld/app/misc/detail/ValidatorList.cpp index 3a46d2baa1..4730df4983 100644 --- a/src/xrpld/app/misc/detail/ValidatorList.cpp +++ b/src/xrpld/app/misc/detail/ValidatorList.cpp @@ -1,4 +1,3 @@ -#include #include #include @@ -6,6 +5,7 @@ #include #include #include +#include #include #include #include diff --git a/src/xrpld/app/misc/detail/setup_HashRouter.cpp b/src/xrpld/app/misc/detail/setup_HashRouter.cpp new file mode 100644 index 0000000000..a0e63dd67e --- /dev/null +++ b/src/xrpld/app/misc/detail/setup_HashRouter.cpp @@ -0,0 +1,42 @@ +#include +#include + +#include + +namespace xrpl { + +HashRouter::Setup +setup_HashRouter(Config const& config) +{ + using namespace std::chrono; + + HashRouter::Setup setup; + auto const& section = config.section("hashrouter"); + + std::int32_t tmp{}; + + if (set(tmp, "hold_time", section)) + { + if (tmp < 12) + Throw( + "HashRouter hold time must be at least 12 seconds (the " + "approximate validation time for three ledgers)."); + setup.holdTime = seconds(tmp); + } + if (set(tmp, "relay_time", section)) + { + if (tmp < 8) + Throw( + "HashRouter relay time must be at least 8 seconds (the " + "approximate validation time for two ledgers)."); + setup.relayTime = seconds(tmp); + } + if (setup.relayTime > setup.holdTime) + { + Throw("HashRouter relay time must be less than or equal to hold time"); + } + + return setup; +} + +} // namespace xrpl diff --git a/src/xrpld/app/misc/setup_HashRouter.h b/src/xrpld/app/misc/setup_HashRouter.h new file mode 100644 index 0000000000..3054233b89 --- /dev/null +++ b/src/xrpld/app/misc/setup_HashRouter.h @@ -0,0 +1,17 @@ +#ifndef XRPLD_APP_MISC_SETUP_HASHROUTER_H_INCLUDED +#define XRPLD_APP_MISC_SETUP_HASHROUTER_H_INCLUDED + +#include + +namespace xrpl { + +// Forward declaration +class Config; + +/** Create HashRouter setup from configuration */ +HashRouter::Setup +setup_HashRouter(Config const& config); + +} // namespace xrpl + +#endif diff --git a/src/xrpld/app/paths/Pathfinder.cpp b/src/xrpld/app/paths/Pathfinder.cpp index b64ce0cc20..ea4fa2013a 100644 --- a/src/xrpld/app/paths/Pathfinder.cpp +++ b/src/xrpld/app/paths/Pathfinder.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -9,6 +8,7 @@ #include #include #include +#include #include #include diff --git a/src/xrpld/app/rdb/backend/detail/Node.cpp b/src/xrpld/app/rdb/backend/detail/Node.cpp index 328d07c0ab..01e036731c 100644 --- a/src/xrpld/app/rdb/backend/detail/Node.cpp +++ b/src/xrpld/app/rdb/backend/detail/Node.cpp @@ -203,7 +203,7 @@ saveValidatedLedger( aLedger = app.getAcceptedLedgerCache().fetch(ledger->header().hash); if (!aLedger) { - aLedger = std::make_shared(ledger, app); + aLedger = std::make_shared(ledger); app.getAcceptedLedgerCache().canonicalize_replace_client(ledger->header().hash, aLedger); } } diff --git a/src/xrpld/app/tx/detail/AMMCreate.cpp b/src/xrpld/app/tx/detail/AMMCreate.cpp index 4634ac79e0..aa75a18e30 100644 --- a/src/xrpld/app/tx/detail/AMMCreate.cpp +++ b/src/xrpld/app/tx/detail/AMMCreate.cpp @@ -1,8 +1,8 @@ -#include #include #include #include +#include #include #include #include diff --git a/src/xrpld/app/tx/detail/Batch.cpp b/src/xrpld/app/tx/detail/Batch.cpp index 34b08beb2f..81f39193cb 100644 --- a/src/xrpld/app/tx/detail/Batch.cpp +++ b/src/xrpld/app/tx/detail/Batch.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include diff --git a/src/xrpld/app/tx/detail/Batch.h b/src/xrpld/app/tx/detail/Batch.h index 8af8b2e020..17abec38c3 100644 --- a/src/xrpld/app/tx/detail/Batch.h +++ b/src/xrpld/app/tx/detail/Batch.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include diff --git a/src/xrpld/app/tx/detail/CancelCheck.cpp b/src/xrpld/app/tx/detail/CancelCheck.cpp index 4ac04e9ffb..086a126eb4 100644 --- a/src/xrpld/app/tx/detail/CancelCheck.cpp +++ b/src/xrpld/app/tx/detail/CancelCheck.cpp @@ -1,8 +1,8 @@ -#include #include #include #include +#include #include #include #include diff --git a/src/xrpld/app/tx/detail/CashCheck.cpp b/src/xrpld/app/tx/detail/CashCheck.cpp index 9deee006d9..2cc25924a1 100644 --- a/src/xrpld/app/tx/detail/CashCheck.cpp +++ b/src/xrpld/app/tx/detail/CashCheck.cpp @@ -1,9 +1,9 @@ -#include #include #include #include #include +#include #include #include #include diff --git a/src/xrpld/app/tx/detail/CreateOffer.cpp b/src/xrpld/app/tx/detail/CreateOffer.cpp index fab406189b..666023233d 100644 --- a/src/xrpld/app/tx/detail/CreateOffer.cpp +++ b/src/xrpld/app/tx/detail/CreateOffer.cpp @@ -1,10 +1,10 @@ -#include #include #include #include #include #include +#include #include #include #include diff --git a/src/xrpld/app/tx/detail/CreateTicket.cpp b/src/xrpld/app/tx/detail/CreateTicket.cpp index e6965ca1cf..eb42904a0b 100644 --- a/src/xrpld/app/tx/detail/CreateTicket.cpp +++ b/src/xrpld/app/tx/detail/CreateTicket.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include #include diff --git a/src/xrpld/app/tx/detail/CreateTicket.h b/src/xrpld/app/tx/detail/CreateTicket.h index 2a6e1bb8cc..dd424e3756 100644 --- a/src/xrpld/app/tx/detail/CreateTicket.h +++ b/src/xrpld/app/tx/detail/CreateTicket.h @@ -1,6 +1,5 @@ #pragma once -#include #include namespace xrpl { diff --git a/src/xrpld/app/tx/detail/Escrow.cpp b/src/xrpld/app/tx/detail/Escrow.cpp index 80d1f6c9da..dea9d3aa2b 100644 --- a/src/xrpld/app/tx/detail/Escrow.cpp +++ b/src/xrpld/app/tx/detail/Escrow.cpp @@ -1,11 +1,11 @@ -#include #include #include -#include -#include #include #include +#include +#include +#include #include #include #include diff --git a/src/xrpld/app/tx/detail/SetAccount.cpp b/src/xrpld/app/tx/detail/SetAccount.cpp index beca60c06b..41804c9211 100644 --- a/src/xrpld/app/tx/detail/SetAccount.cpp +++ b/src/xrpld/app/tx/detail/SetAccount.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include diff --git a/src/xrpld/app/tx/detail/Transactor.cpp b/src/xrpld/app/tx/detail/Transactor.cpp index b3b5d8b9bc..a7bb7992fb 100644 --- a/src/xrpld/app/tx/detail/Transactor.cpp +++ b/src/xrpld/app/tx/detail/Transactor.cpp @@ -1,11 +1,9 @@ -#include #include #include #include #include #include #include -#include #include #include @@ -15,6 +13,7 @@ #include #include #include +#include #include #include diff --git a/src/xrpld/app/tx/detail/apply.cpp b/src/xrpld/app/tx/detail/apply.cpp index 7babc415d5..1c7a509007 100644 --- a/src/xrpld/app/tx/detail/apply.cpp +++ b/src/xrpld/app/tx/detail/apply.cpp @@ -1,8 +1,9 @@ -#include #include #include #include +#include +#include #include #include diff --git a/src/xrpld/overlay/detail/OverlayImpl.cpp b/src/xrpld/overlay/detail/OverlayImpl.cpp index ceefab24f1..5b9f142001 100644 --- a/src/xrpld/overlay/detail/OverlayImpl.cpp +++ b/src/xrpld/overlay/detail/OverlayImpl.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -15,6 +14,7 @@ #include #include #include +#include #include #include #include diff --git a/src/xrpld/overlay/detail/PeerImp.cpp b/src/xrpld/overlay/detail/PeerImp.cpp index d66a57bae6..ec641487a8 100644 --- a/src/xrpld/overlay/detail/PeerImp.cpp +++ b/src/xrpld/overlay/detail/PeerImp.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -16,6 +15,7 @@ #include #include #include +#include #include #include #include diff --git a/src/xrpld/overlay/detail/PeerImp.h b/src/xrpld/overlay/detail/PeerImp.h index 65a6112159..d88314a9a5 100644 --- a/src/xrpld/overlay/detail/PeerImp.h +++ b/src/xrpld/overlay/detail/PeerImp.h @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -11,6 +10,7 @@ #include #include #include +#include #include #include #include diff --git a/src/xrpld/rpc/handlers/Simulate.cpp b/src/xrpld/rpc/handlers/Simulate.cpp index f44fc57261..58b40e2048 100644 --- a/src/xrpld/rpc/handlers/Simulate.cpp +++ b/src/xrpld/rpc/handlers/Simulate.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -10,6 +9,7 @@ #include #include +#include #include #include #include