20 #include <ripple/app/ledger/LedgerMaster.h>
21 #include <ripple/app/ledger/OrderBookDB.h>
22 #include <ripple/app/main/Application.h>
23 #include <ripple/app/misc/AMMUtils.h>
24 #include <ripple/app/misc/NetworkOPs.h>
25 #include <ripple/basics/Log.h>
26 #include <ripple/core/Config.h>
27 #include <ripple/core/JobQueue.h>
28 #include <ripple/protocol/Indexes.h>
33 : app_(app), seq_(0), j_(app.journal(
"OrderBookDB"))
42 JLOG(
j_.
warn()) <<
"Eliding full order book update: no ledger";
50 if ((seq > ledger->seq()) && ((ledger->seq() - seq) < 25600))
53 if ((ledger->seq() <= seq) && ((seq - ledger->seq()) < 16))
60 JLOG(
j_.
debug()) <<
"Full order book update: " << seq <<
" to "
71 [
this, ledger]() { update(ledger); });
82 if (
auto const seq =
seq_.
load(); seq > ledger->seq())
84 JLOG(
j_.
debug()) <<
"Eliding update for " << ledger->seq()
85 <<
" because of pending update to later " << seq;
95 JLOG(
j_.
debug()) <<
"Beginning update (" << ledger->seq() <<
")";
102 for (
auto& sle : ledger->sles)
107 <<
"Update halted because the process is stopping";
123 allBooks[book.
in].insert(book.
out);
126 xrpBooks.insert(book.
in);
130 else if (sle->getType() ==
ltAMM)
132 auto const issue1 = (*sle)[
sfAsset];
133 auto const issue2 = (*sle)[
sfAsset2];
135 allBooks[
in].insert(
out);
142 addBook(issue1, issue2);
143 addBook(issue2, issue1);
149 JLOG(
j_.
info()) <<
"Missing node in " << ledger->seq()
150 <<
" during update: " << mn.
what();
155 JLOG(
j_.
debug()) <<
"Update completed (" << ledger->seq() <<
"): " << cnt
191 ret.
reserve(it->second.size());
193 for (
auto const& gets : it->second)
206 return static_cast<int>(it->second.size());
225 ret = std::make_shared<BookListeners>();
270 auto process = [&,
this](
SField const& field) {
271 if (
auto data =
dynamic_cast<STObject const*
>(
272 node.peekAtPField(field));
280 listeners->publish(jvObj, havePublished);
297 <<
"processTxn: field not found (" << ex.
what() <<
")";
const SF_UINT256 sfRootIndex
A currency issued by an account.
std::recursive_mutex mLock
const SF_UINT160 sfTakerPaysCurrency
const SField sfFinalFields
std::atomic< std::uint32_t > seq_
virtual bool isStopping() const =0
bool addJob(JobType type, std::string const &name, JobHandler &&jobHandler)
Adds a job to the JobQueue.
void update(std::shared_ptr< ReadView const > const &ledger)
const SF_UINT160 sfTakerGetsCurrency
const SField sfDeletedNode
hash_set< Issue > xrpBooks_
virtual NetworkOPs & getOPs()=0
@ ltDIR_NODE
A ledger object which contains a list of object identifiers.
bool isBookToXRP(Issue const &)
const SF_UINT160 sfTakerGetsIssuer
const SF_AMOUNT sfTakerPays
@ ltOFFER
A ledger object which describes an offer on the DEX.
int getBookSize(Issue const &)
virtual bool isNeedNetworkLedger()=0
virtual LedgerMaster & getLedgerMaster()=0
virtual Config & config()=0
virtual JobQueue & getJobQueue()=0
A transaction that is in a closed ledger.
const SField sfModifiedNode
const SF_AMOUNT sfTakerGets
void setup(std::shared_ptr< ReadView const > const &ledger)
bool isXRP(AccountID const &c)
const SF_UINT64 sfExchangeRate
BookListeners::pointer makeBookListeners(Book const &)
hardened_hash_map< Issue, hardened_hash_set< Issue > > allBooks_
BookToListenersMap mListeners
const SField sfPreviousFields
BookListeners::pointer getBookListeners(Book const &)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
const SF_UINT16 sfLedgerEntryType
void processTxn(std::shared_ptr< ReadView const > const &ledger, const AcceptedLedgerTx &alTx, MultiApiJson const &jvObj)
TxMeta const & getMeta() const
const SF_UINT160 sfTakerPaysIssuer
const SField sfCreatedNode
OrderBookDB(Application &app)
std::vector< Book > getBooksByTakerPays(Issue const &)
@ ltAMM
The ledger object which tracks the AMM.
void addOrderBook(Book const &)