Rename to PathRequest, begin include dependency analysis in ripple_client

This commit is contained in:
Vinnie Falco
2013-06-10 16:52:19 -07:00
parent e2c92ee8a4
commit c23b088755
14 changed files with 141 additions and 108 deletions

View File

@@ -1,24 +1,6 @@
#ifndef __APPLICATION__
#define __APPLICATION__
#include "leveldb/db.h"
#include <boost/asio.hpp>
#include "../database/database.h"
#include "LedgerMaster.h"
#include "TransactionMaster.h"
#include "Wallet.h"
#include "WSDoor.h"
#include "SNTPClient.h"
#include "RPCHandler.h"
#include "LoadManager.h"
#include "TransactionQueue.h"
#include "OrderBookDB.h"
#include "ripple_DatabaseCon.h"
// VFALCO TODO Fix forward declares required for header dependency loops
class IFeatures;
class IFeeVote;

View File

@@ -39,7 +39,14 @@ public:
LedgerEntrySetEntry(SLE::ref e, LedgerEntryAction a, int s) : mEntry(e), mAction(a), mSeq(s) { ; }
};
/** An LES is a LedgerEntrySet.
It's a view into a ledger used while a transaction is processing.
The transaction manipulates the LES rather than the ledger
(because it's cheaper, can be checkpointed, and so on). When the
transaction finishes, the LES is committed into the ledger to make
the modifications. The transaction metadata is built from the LES too.
*/
class LedgerEntrySet : private IS_INSTANCE(LedgerEntrySet)
{
public:

View File

@@ -726,12 +726,13 @@ void LedgerMaster::updatePaths()
mPathFindNewRequest = false;
}
PFRequest::updateAll(lastLedger, newOnly);
// VFALCO TODO Fix this global variable
PathRequest::updateAll (lastLedger, newOnly);
} while(1);
}
void LedgerMaster::newPFRequest()
void LedgerMaster::newPathRequest()
{
boost::recursive_mutex::scoped_lock ml(mLock);
mPathFindNewRequest = true;

View File

@@ -11,7 +11,7 @@
class LedgerMaster
{
public:
typedef FUNCTION_TYPE<void(Ledger::ref)> callback;
typedef FUNCTION_TYPE <void(Ledger::ref)> callback;
public:
LedgerMaster ()
@@ -125,7 +125,7 @@ public:
void checkAccept(uint256 const& hash);
void checkAccept(uint256 const& hash, uint32 seq);
void tryPublish();
void newPFRequest();
void newPathRequest();
static bool shouldAcquire(uint32 currentLedgerID, uint32 ledgerHistory, uint32 targetLedger);

View File

@@ -19,7 +19,6 @@
#include "AccountState.h"
#include "NicknameState.h"
#include "Offer.h"
#include "PFRequest.h"
SETUP_LOG (RPCHandler)
@@ -1325,29 +1324,29 @@ Json::Value RPCHandler::doPathFind(Json::Value jvRequest, int& cost, ScopedLock&
if (sSubCommand == "create")
{
mInfoSub->clearPFRequest();
PFRequest::pointer request = boost::make_shared<PFRequest>(mInfoSub);
mInfoSub->clearPathRequest();
PathRequest::pointer request = boost::make_shared<PathRequest>(mInfoSub);
Json::Value result = request->doCreate(mNetOps->getClosedLedger(), jvRequest);
if (request->isValid())
{
mInfoSub->setPFRequest(request);
theApp->getLedgerMaster().newPFRequest();
mInfoSub->setPathRequest(request);
theApp->getLedgerMaster().newPathRequest();
}
return result;
}
if (sSubCommand == "close")
{
PFRequest::pointer request = mInfoSub->getPFRequest();
PathRequest::pointer request = mInfoSub->getPathRequest();
if (!request)
return rpcError(rpcNO_PF_REQUEST);
mInfoSub->clearPFRequest();
mInfoSub->clearPathRequest();
return request->doClose(jvRequest);
}
if (sSubCommand == "status")
{
PFRequest::pointer request = mInfoSub->getPFRequest();
PathRequest::pointer request = mInfoSub->getPathRequest();
if (!request)
return rpcNO_PF_REQUEST;
return request->doStatus(jvRequest);

View File

@@ -10,7 +10,7 @@
// code assumes this node is synched (and will continue to do so until
// there's a functional network.
DECLARE_INSTANCE(InfoSub);
DECLARE_INSTANCE (InfoSub);
// VFALCO TODO Figure out how to clean up these globals
uint64 InfoSub::sSeq = 0;
@@ -54,17 +54,17 @@ void InfoSub::insertSubAccountInfo (RippleAddress addr, uint32 uLedgerIndex)
mSubAccountInfo.insert(addr);
}
void InfoSub::clearPFRequest()
void InfoSub::clearPathRequest()
{
mPFRequest.reset();
mPathRequest.reset();
}
void InfoSub::setPFRequest(const boost::shared_ptr<PFRequest>& req)
void InfoSub::setPathRequest(const boost::shared_ptr<PathRequest>& req)
{
mPFRequest = req;
mPathRequest = req;
}
const boost::shared_ptr<PFRequest>& InfoSub::getPFRequest()
const boost::shared_ptr<PathRequest>& InfoSub::getPathRequest()
{
return mPFRequest;
return mPathRequest;
}

View File

@@ -4,11 +4,10 @@
// Operations that clients may wish to perform against the network
// Master operational handler, server sequencer, network tracker
class PFRequest;
class PathRequest;
DEFINE_INSTANCE(InfoSub);
// VFALCO TODO Move InfoSub to a separate file
class InfoSub : public IS_INSTANCE(InfoSub)
{
public:
@@ -35,23 +34,24 @@ public:
void insertSubAccountInfo (RippleAddress addr, uint32 uLedgerIndex);
void clearPFRequest();
void clearPathRequest();
void setPFRequest (const boost::shared_ptr<PFRequest>& req);
void setPathRequest (const boost::shared_ptr<PathRequest>& req);
boost::shared_ptr <PFRequest> const& getPFRequest ();
boost::shared_ptr <PathRequest> const& getPathRequest ();
protected:
// VFALCO TODO make accessor for this member
boost::mutex mLockInfo;
private:
// VFALCO TODO Move these globals to class instance
static uint64 sSeq;
static boost::mutex sSeqLock;
boost::unordered_set<RippleAddress> mSubAccountInfo;
boost::unordered_set<RippleAddress> mSubAccountTransaction;
boost::shared_ptr <PFRequest> mPFRequest;
boost::unordered_set <RippleAddress> mSubAccountInfo;
boost::unordered_set <RippleAddress> mSubAccountTransaction;
boost::shared_ptr <PathRequest> mPathRequest;
uint64 mSeq;
};

View File

@@ -1,35 +1,30 @@
#include "PFRequest.h"
SETUP_LOG (PathRequest)
#include "RPCErr.h"
#include "Ledger.h"
#include "Application.h"
#include "Pathfinder.h"
#include "RippleCalc.h"
// VFALCO TODO Move these globals into a PathRequests collection inteface
boost::recursive_mutex PathRequest::sLock;
std::set <PathRequest::wptr> PathRequest::sRequests;
SETUP_LOG (PFRequest)
boost::recursive_mutex PFRequest::sLock;
std::set<PFRequest::wptr> PFRequest::sRequests;
PFRequest::PFRequest(const boost::shared_ptr<InfoSub>& subscriber) :
wpSubscriber(subscriber), jvStatus(Json::objectValue), bValid(false), bNew(true)
PathRequest::PathRequest (const boost::shared_ptr<InfoSub>& subscriber)
: wpSubscriber (subscriber)
, jvStatus (Json::objectValue)
, bValid (false)
, bNew (true)
{
;
}
bool PFRequest::isValid()
bool PathRequest::isValid()
{
boost::recursive_mutex::scoped_lock sl(mLock);
return bValid;
}
bool PFRequest::isNew()
bool PathRequest::isNew()
{
boost::recursive_mutex::scoped_lock sl(mLock);
return bNew;
}
bool PFRequest::isValid(Ledger::ref lrLedger)
bool PathRequest::isValid(Ledger::ref lrLedger)
{
boost::recursive_mutex::scoped_lock sl(mLock);
bValid = raSrcAccount.isSet() && raDstAccount.isSet() && saDstAmount.isPositive();
@@ -74,7 +69,7 @@ bool PFRequest::isValid(Ledger::ref lrLedger)
return bValid;
}
Json::Value PFRequest::doCreate(Ledger::ref lrLedger, const Json::Value& value)
Json::Value PathRequest::doCreate(Ledger::ref lrLedger, const Json::Value& value)
{
assert(lrLedger->isClosed());
@@ -98,9 +93,9 @@ Json::Value PFRequest::doCreate(Ledger::ref lrLedger, const Json::Value& value)
if (mValid)
{
WriteLog (lsINFO, PFRequest) << "Request created: " << raSrcAccount.humanAccountID() <<
WriteLog (lsINFO, PathRequest) << "Request created: " << raSrcAccount.humanAccountID() <<
" -> " << raDstAccount.humanAccountID();
WriteLog (lsINFO, PFRequest) << "Deliver: " << saDstAmount.getFullText();
WriteLog (lsINFO, PathRequest) << "Deliver: " << saDstAmount.getFullText();
boost::recursive_mutex::scoped_lock sl(sLock);
sRequests.insert(shared_from_this());
@@ -109,7 +104,7 @@ Json::Value PFRequest::doCreate(Ledger::ref lrLedger, const Json::Value& value)
return jvStatus;
}
int PFRequest::parseJson(const Json::Value& jvParams, bool complete)
int PathRequest::parseJson(const Json::Value& jvParams, bool complete)
{
int ret = PFR_PJ_NOCHANGE;
@@ -194,19 +189,19 @@ int PFRequest::parseJson(const Json::Value& jvParams, bool complete)
return ret;
}
Json::Value PFRequest::doClose(const Json::Value&)
Json::Value PathRequest::doClose(const Json::Value&)
{
boost::recursive_mutex::scoped_lock sl(mLock);
return jvStatus;
}
Json::Value PFRequest::doStatus(const Json::Value&)
Json::Value PathRequest::doStatus(const Json::Value&)
{
boost::recursive_mutex::scoped_lock sl(mLock);
return jvStatus;
}
bool PFRequest::doUpdate(RLCache::ref cache, bool fast)
bool PathRequest::doUpdate(RLCache::ref cache, bool fast)
{
boost::recursive_mutex::scoped_lock sl(mLock);
jvStatus = Json::objectValue;
@@ -246,13 +241,13 @@ bool PFRequest::doUpdate(RLCache::ref cache, bool fast)
{
{
STAmount test(currIssuer.first, currIssuer.second, 1);
WriteLog (lsDEBUG, PFRequest) << "Trying to find paths: " << test.getFullText();
WriteLog (lsDEBUG, PathRequest) << "Trying to find paths: " << test.getFullText();
}
bool valid;
STPathSet spsPaths;
Pathfinder pf(cache, raSrcAccount, raDstAccount,
currIssuer.first, currIssuer.second, saDstAmount, valid);
CondLog (!valid, lsINFO, PFRequest) << "PF request not valid";
CondLog (!valid, lsINFO, PathRequest) << "PF request not valid";
if (valid && pf.findPaths(theConfig.PATH_SEARCH_SIZE - (fast ? 0 : 1), 3, spsPaths))
{
LedgerEntrySet lesSandbox(cache->getLedger(), tapNONE);
@@ -263,7 +258,7 @@ bool PFRequest::doUpdate(RLCache::ref cache, bool fast)
currIssuer.second.isNonZero() ? currIssuer.second :
(currIssuer.first.isZero() ? ACCOUNT_XRP : raSrcAccount.getAccountID()), 1);
saMaxAmount.negate();
WriteLog (lsDEBUG, PFRequest) << "Paths found, calling rippleCalc";
WriteLog (lsDEBUG, PathRequest) << "Paths found, calling rippleCalc";
TER terResult = RippleCalc::rippleCalc(lesSandbox, saMaxAmountAct, saDstAmountAct,
vpsExpanded, saMaxAmount, saDstAmount, raDstAccount.getAccountID(), raSrcAccount.getAccountID(),
spsPaths, false, false, false, true);
@@ -276,19 +271,19 @@ bool PFRequest::doUpdate(RLCache::ref cache, bool fast)
}
else
{
WriteLog (lsINFO, PFRequest) << "rippleCalc returns " << transHuman(terResult);
WriteLog (lsINFO, PathRequest) << "rippleCalc returns " << transHuman(terResult);
}
}
else
{
WriteLog (lsINFO, PFRequest) << "No paths found";
WriteLog (lsINFO, PathRequest) << "No paths found";
}
}
jvStatus["alternatives"] = jvArray;
return true;
}
void PFRequest::updateAll(Ledger::ref ledger, bool newOnly)
void PathRequest::updateAll(Ledger::ref ledger, bool newOnly)
{
std::set<wptr> requests;
@@ -305,7 +300,7 @@ void PFRequest::updateAll(Ledger::ref ledger, bool newOnly)
BOOST_FOREACH(wref wRequest, requests)
{
bool remove = true;
PFRequest::pointer pRequest = wRequest.lock();
PathRequest::pointer pRequest = wRequest.lock();
if (pRequest && (!newOnly || pRequest->isNew()))
{
InfoSub::pointer ipSub = pRequest->wpSubscriber.lock();

View File

@@ -14,7 +14,6 @@
// A pathfinding request submitted by a client
// The request issuer must maintain a strong pointer
class Ledger;
class InfoSub;
class STAmount;
class RLCache;
@@ -24,17 +23,18 @@ class RLCache;
#define PFR_PJ_NOCHANGE 0
#define PFR_PJ_CHANGE 1
class PFRequest : public boost::enable_shared_from_this<PFRequest>
class PathRequest : public boost::enable_shared_from_this<PathRequest>
{
public:
typedef boost::weak_ptr<PFRequest> wptr;
typedef boost::shared_ptr<PFRequest> pointer;
typedef boost::weak_ptr<PathRequest> wptr;
typedef boost::shared_ptr<PathRequest> pointer;
typedef const pointer& ref;
typedef const wptr& wref;
typedef std::pair<uint160, uint160> currIssuer_t;
public:
PFRequest(const boost::shared_ptr<InfoSub>& subscriber);
// VFALCO TODO Break the cyclic dependency on InfoSub
explicit PathRequest (boost::shared_ptr <InfoSub> const& subscriber);
bool isValid(const boost::shared_ptr<Ledger>&);
bool isValid();