Work toward ripple loop detection and offer deletion.

This commit is contained in:
Arthur Britto
2012-08-28 13:27:54 -07:00
parent 0d8ad928f6
commit 354c33f71a
2 changed files with 117 additions and 43 deletions

View File

@@ -1,6 +1,7 @@
#ifndef __TRANSACTIONENGINE__
#define __TRANSACTIONENGINE__
#include <boost/tuple/tuple.hpp>
#include <boost/unordered_set.hpp>
#include <boost/unordered_map.hpp>
@@ -97,8 +98,8 @@ enum TransactionEngineParams
typedef struct {
uint16 uFlags; // --> From path.
uint160 uAccountID; // --> Recieving/sending account.
uint160 uCurrencyID; // --> Accounts: receive and send, Offers: send.
uint160 uAccountID; // --> Accounts: Recieving/sending account.
uint160 uCurrencyID; // --> Accounts: Receive and send, Offers: send.
// --- For offer's next has currency out.
uint160 uIssuerID; // --> Currency's issuer
@@ -115,6 +116,13 @@ typedef struct {
STAmount saFwdDeliver; // <-- Amount to deliver to next regardless of fee.
} paymentNode;
// account id, currency id, issuer id :: node
typedef boost::tuple<uint160, uint160, uint160> aciSource;
typedef boost::unordered_map<aciSource, unsigned int> curIssuerNode; // Map of currency, issuer to node index.
typedef boost::unordered_map<aciSource, unsigned int>::const_iterator curIssuerNodeConstIterator;
extern std::size_t hash_value(const aciSource& asValue);
// Hold a path state under incremental application.
class PathState
{
@@ -133,8 +141,12 @@ public:
// When processing, don't want to complicate directory walking with deletion.
std::vector<uint256> vUnfundedBecame; // Offers that became unfunded.
// First time working in reverse a funding source was mentioned. Source may only be used there.
boost::unordered_map<std::pair<uint160, uint160>, int> umSource; // Map of currency, issuer to node index.
// First time working foward a funding source was mentioned for accounts. Source may only be used there.
curIssuerNode umForward; // Map of currency, issuer to node index.
// First time working in reverse a funding source was used.
// Source may only be used there if not mentioned by an account.
curIssuerNode umReverse; // Map of currency, issuer to node index.
LedgerEntrySet lesEntries;
@@ -221,7 +233,7 @@ protected:
SLE::pointer mTxnAccount;
// First time working in reverse a funding source was mentioned. Source may only be used there.
boost::unordered_map<std::pair<uint160, uint160>, int> mumSource; // Map of currency, issuer to node index.
curIssuerNode mumSource; // Map of currency, issuer to node index.
// When processing, don't want to complicate directory walking with deletion.
std::vector<uint256> mvUnfundedBecame; // Offers that became unfunded.
@@ -254,12 +266,12 @@ protected:
STAmount accountFunds(const uint160& uAccountID, const STAmount& saDefault);
PathState::pointer pathCreate(const STPath& spPath);
void pathNext(PathState::pointer pspCur, int iPaths);
bool calcNode(unsigned int uIndex, PathState::pointer pspCur, bool bMultiQuality);
bool calcNodeOfferRev(unsigned int uIndex, PathState::pointer pspCur, bool bMultiQuality);
bool calcNodeOfferFwd(unsigned int uIndex, PathState::pointer pspCur, bool bMultiQuality);
bool calcNodeAccountRev(unsigned int uIndex, PathState::pointer pspCur, bool bMultiQuality);
bool calcNodeAccountFwd(unsigned int uIndex, PathState::pointer pspCur, bool bMultiQuality);
void pathNext(const PathState::pointer& pspCur, const int iPaths);
bool calcNode(const unsigned int uIndex, const PathState::pointer& pspCur, const bool bMultiQuality);
bool calcNodeOfferRev(const unsigned int uIndex, const PathState::pointer& pspCur, const bool bMultiQuality);
bool calcNodeOfferFwd(const unsigned int uIndex, const PathState::pointer& pspCur, const bool bMultiQuality);
bool calcNodeAccountRev(const unsigned int uIndex, const PathState::pointer& pspCur, const bool bMultiQuality);
bool calcNodeAccountFwd(const unsigned int uIndex, const PathState::pointer& pspCur, const bool bMultiQuality);
void calcNodeRipple(const uint32 uQualityIn, const uint32 uQualityOut,
const STAmount& saPrvReq, const STAmount& saCurReq,
STAmount& saPrvAct, STAmount& saCurAct);