mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-27 22:45:52 +00:00
Cleanup and optimize order book DB generation.
This commit is contained in:
@@ -1,13 +1,6 @@
|
|||||||
#include "OrderBook.h"
|
#include "OrderBook.h"
|
||||||
#include "Ledger.h"
|
#include "Ledger.h"
|
||||||
|
|
||||||
OrderBook::pointer OrderBook::newOrderBook(SerializedLedgerEntry::ref ledgerEntry)
|
|
||||||
{
|
|
||||||
if(ledgerEntry->getType() != ltOFFER) return( OrderBook::pointer());
|
|
||||||
|
|
||||||
return( OrderBook::pointer(new OrderBook(ledgerEntry)));
|
|
||||||
}
|
|
||||||
|
|
||||||
OrderBook::OrderBook(SerializedLedgerEntry::ref ledgerEntry)
|
OrderBook::OrderBook(SerializedLedgerEntry::ref ledgerEntry)
|
||||||
{
|
{
|
||||||
const STAmount saTakerGets = ledgerEntry->getFieldAmount(sfTakerGets);
|
const STAmount saTakerGets = ledgerEntry->getFieldAmount(sfTakerGets);
|
||||||
|
|||||||
@@ -27,11 +27,12 @@ public:
|
|||||||
typedef const boost::shared_ptr<OrderBook>& ref;
|
typedef const boost::shared_ptr<OrderBook>& ref;
|
||||||
|
|
||||||
OrderBook(const uint256& index, const uint160& ci, const uint160& co, const uint160& ii, const uint160& io) :
|
OrderBook(const uint256& index, const uint160& ci, const uint160& co, const uint160& ii, const uint160& io) :
|
||||||
mBookBase(index), mCurrencyIn(ci), mCurrencyOut(co), mIssuerIn(ii), mIssuerOut(io) { ; }
|
mBookBase(index),
|
||||||
|
mCurrencyIn(ci),
|
||||||
// returns NULL if ledgerEntry doesn't point to an order
|
mCurrencyOut(co),
|
||||||
// if ledgerEntry is an Order it creates the OrderBook this order would live in
|
mIssuerIn(ii),
|
||||||
static OrderBook::pointer newOrderBook(SerializedLedgerEntry::ref ledgerEntry);
|
mIssuerOut(io)
|
||||||
|
{ ; }
|
||||||
|
|
||||||
uint256& getBookBase(){ return(mBookBase); }
|
uint256& getBookBase(){ return(mBookBase); }
|
||||||
uint160& getCurrencyIn(){ return(mCurrencyIn); }
|
uint160& getCurrencyIn(){ return(mCurrencyIn); }
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ void OrderBookDB::invalidate()
|
|||||||
// TODO: this would be way faster if we could just look under the order dirs
|
// TODO: this would be way faster if we could just look under the order dirs
|
||||||
void OrderBookDB::setup(Ledger::ref ledger)
|
void OrderBookDB::setup(Ledger::ref ledger)
|
||||||
{
|
{
|
||||||
|
boost::unordered_set<uint256> mSeen;
|
||||||
|
|
||||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||||
|
|
||||||
if (ledger->getLedgerSeq() == mSeq)
|
if (ledger->getLedgerSeq() == mSeq)
|
||||||
@@ -30,7 +32,6 @@ void OrderBookDB::setup(Ledger::ref ledger)
|
|||||||
|
|
||||||
mXRPOrders.clear();
|
mXRPOrders.clear();
|
||||||
mIssuerMap.clear();
|
mIssuerMap.clear();
|
||||||
mKnownMap.clear();
|
|
||||||
|
|
||||||
// walk through the entire ledger looking for orderbook entries
|
// walk through the entire ledger looking for orderbook entries
|
||||||
uint256 currentIndex = ledger->getFirstLedgerIndex();
|
uint256 currentIndex = ledger->getFirstLedgerIndex();
|
||||||
@@ -40,19 +41,19 @@ void OrderBookDB::setup(Ledger::ref ledger)
|
|||||||
while (currentIndex.isNonZero())
|
while (currentIndex.isNonZero())
|
||||||
{
|
{
|
||||||
SLE::pointer entry = ledger->getSLEi(currentIndex);
|
SLE::pointer entry = ledger->getSLEi(currentIndex);
|
||||||
OrderBook::pointer book = OrderBook::newOrderBook(entry);
|
if ((entry->getType() == ltDIR_NODE) && (entry->isFieldPresent(sfExchangeRate)) &&
|
||||||
if (book)
|
(entry->getFieldH256(sfRootIndex) == currentIndex))
|
||||||
{
|
{
|
||||||
cLog(lsTRACE) << "OrderBookDB: found book";
|
const uint160& ci = entry->getFieldH160(sfTakerPaysCurrency);
|
||||||
|
const uint160& co = entry->getFieldH160(sfTakerGetsCurrency);
|
||||||
|
const uint160& ii = entry->getFieldH160(sfTakerPaysIssuer);
|
||||||
|
const uint160& io = entry->getFieldH160(sfTakerGetsIssuer);
|
||||||
|
|
||||||
if (mKnownMap.find(book->getBookBase()) == mKnownMap.end())
|
uint256 index = Ledger::getBookBase(ci, ii, co, io);
|
||||||
|
if (mSeen.insert(index).second)
|
||||||
{
|
{
|
||||||
mKnownMap[book->getBookBase()] = true;
|
OrderBook::pointer book = boost::make_shared<OrderBook>(boost::cref(index),
|
||||||
|
boost::cref(ci), boost::cref(co), boost::cref(ii), boost::cref(io));
|
||||||
cLog(lsTRACE) << "OrderBookDB: unknown book in: "
|
|
||||||
<< STAmount::createHumanCurrency(book->getCurrencyIn())
|
|
||||||
<< " -> "
|
|
||||||
<< STAmount::createHumanCurrency(book->getCurrencyOut());
|
|
||||||
|
|
||||||
if (!book->getCurrencyIn()) // XRP
|
if (!book->getCurrencyIn()) // XRP
|
||||||
mXRPOrders.push_back(book);
|
mXRPOrders.push_back(book);
|
||||||
|
|||||||
@@ -38,8 +38,6 @@ class OrderBookDB
|
|||||||
// issuerIn, issuerOut, currencyIn, currencyOut
|
// issuerIn, issuerOut, currencyIn, currencyOut
|
||||||
std::map<uint160, std::map<uint160, std::map<uint160, std::map<uint160, BookListeners::pointer> > > > mListeners;
|
std::map<uint160, std::map<uint160, std::map<uint160, std::map<uint160, BookListeners::pointer> > > > mListeners;
|
||||||
|
|
||||||
std::map<uint256, bool > mKnownMap;
|
|
||||||
|
|
||||||
uint32 mSeq;
|
uint32 mSeq;
|
||||||
boost::recursive_mutex mLock;
|
boost::recursive_mutex mLock;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user