diff --git a/src/AccountState.cpp b/src/AccountState.cpp index 5e56bd996..1f84c9dce 100644 --- a/src/AccountState.cpp +++ b/src/AccountState.cpp @@ -10,12 +10,12 @@ #include "Ledger.h" #include "Serializer.h" -AccountState::AccountState(const NewcoinAddress& id) : mAccountID(id), mValid(false) +AccountState::AccountState(const NewcoinAddress& id) : mValid(false) { if (!id.isValid()) return; mLedgerEntry = boost::make_shared(ltACCOUNT_ROOT); mLedgerEntry->setIndex(Ledger::getAccountRootIndex(id)); - mLedgerEntry->setIFieldAccount(sfAccount, id); + mValid = true; } @@ -23,9 +23,8 @@ AccountState::AccountState(SerializedLedgerEntry::pointer ledgerEntry) : mLedger { if (!mLedgerEntry) return; if (mLedgerEntry->getType() != ltACCOUNT_ROOT) return; - mAccountID = mLedgerEntry->getIValueFieldAccount(sfAccount); - if (mAccountID.isValid()) - mValid = true; + + mValid = true; } std::string AccountState::createGravatarUrl(uint128 uEmailHash) diff --git a/src/AccountState.h b/src/AccountState.h index d51898e5d..b2e5a0c95 100644 --- a/src/AccountState.h +++ b/src/AccountState.h @@ -21,7 +21,6 @@ public: typedef boost::shared_ptr pointer; private: - NewcoinAddress mAccountID; NewcoinAddress mAuthorizedKey; SerializedLedgerEntry::pointer mLedgerEntry; @@ -41,7 +40,6 @@ public: return mLedgerEntry->getIValueFieldAccount(sfAuthorizedKey); } - const NewcoinAddress& getAccountID() const { return mAccountID; } STAmount getBalance() const { return mLedgerEntry->getIValueFieldAmount(sfBalance); } uint32 getSeq() const { return mLedgerEntry->getIFieldU32(sfSequence); } diff --git a/src/LedgerEntrySet.cpp b/src/LedgerEntrySet.cpp index a43ea72bf..9dc3bb157 100644 --- a/src/LedgerEntrySet.cpp +++ b/src/LedgerEntrySet.cpp @@ -20,7 +20,7 @@ LedgerEntrySet LedgerEntrySet::duplicate() const return LedgerEntrySet(mEntries, mSet, mSeq + 1); } -void LedgerEntrySet::setTo(LedgerEntrySet& e) +void LedgerEntrySet::setTo(const LedgerEntrySet& e) { mEntries = e.mEntries; mSet = e.mSet; diff --git a/src/LedgerEntrySet.h b/src/LedgerEntrySet.h index a6784d946..02c09c559 100644 --- a/src/LedgerEntrySet.h +++ b/src/LedgerEntrySet.h @@ -42,7 +42,7 @@ public: // set functions LedgerEntrySet duplicate() const; // Make a duplicate of this set - void setTo(LedgerEntrySet&); // Set this set to have the same contents as another + void setTo(const LedgerEntrySet&); // Set this set to have the same contents as another void swapWith(LedgerEntrySet&); // Swap the contents of two sets int getSeq() const { return mSeq; } diff --git a/src/SerializedTypes.h b/src/SerializedTypes.h index 41bcafc33..63977102c 100644 --- a/src/SerializedTypes.h +++ b/src/SerializedTypes.h @@ -342,6 +342,7 @@ public: static STAmount multiply(const STAmount& v1, const STAmount& v2, const uint160& currencyOut); // Someone is offering X for Y, what is the rate? + // Rate: smaller is better, the taker wants the most out: in/out static uint64 getRate(const STAmount& offerOut, const STAmount& offerIn); static STAmount setRate(uint64 rate, const uint160& currencyOut); diff --git a/src/TransactionEngine.cpp b/src/TransactionEngine.cpp index ae32693fe..5cb0f5a4f 100644 --- a/src/TransactionEngine.cpp +++ b/src/TransactionEngine.cpp @@ -3221,6 +3221,8 @@ bool TransactionEngine::calcNode(unsigned int uIndex, PathState::pointer pspCur, } // Calculate the next increment of a path. +// The increment is what can satisfy a portion or all of the requested output at the best quality. +// <-- pspCur->uQuality void TransactionEngine::pathNext(PathState::pointer pspCur, int iPaths) { // The next state is what is available in preference order. @@ -3228,20 +3230,18 @@ void TransactionEngine::pathNext(PathState::pointer pspCur, int iPaths) unsigned int uLast = pspCur->vpnNodes.size() - 1; - pspCur->lesEntries = mNodes.duplicate(); // Checkpoint state? - - if (!calcNode(uLast, pspCur, iPaths == 1)) + if (calcNode(uLast, pspCur, iPaths == 1)) + { + // Calculate relative quality. + pspCur->uQuality = STAmount::getRate(pspCur->saOutAct, pspCur->saInAct); + } + else { // Mark path as inactive. pspCur->uQuality = 0; } } -// Apply an increment of the path, then calculate the next increment. -void TransactionEngine::pathApply(PathState::pointer pspCur) -{ -} - // XXX Need to audit for things like setting accountID not having memory. TransactionEngineResult TransactionEngine::doPayment(const SerializedTransaction& txn) { @@ -3484,23 +3484,28 @@ TransactionEngineResult TransactionEngine::doPayment(const SerializedTransaction while (tenUNKNOWN == terResult) { PathState::pointer pspBest; + LedgerEntrySet lesCheckpoint; + + mNodes.swapWith(lesCheckpoint); // Checkpoint ledger prior to path application. // Find the best path. BOOST_FOREACH(PathState::pointer pspCur, vpsPaths) { + mNodes.setTo(lesCheckpoint.duplicate()); // Vary ledger from checkpoint. + pathNext(pspCur, vpsPaths.size()); // Compute increment + mNodes.swapWith(pspCur->lesEntries); // For the path, save ledger state. + if (!pspBest || (pspCur->uQuality && PathState::lessPriority(pspBest, pspCur))) pspBest = pspCur; } - if (!pspBest) + if (pspBest) { - // - // Apply path. - // + // Apply best path. - // Install changes for path. + // Install ledger for best past. mNodes.swapWith(pspBest->lesEntries); // Figure out if done. @@ -3518,8 +3523,7 @@ TransactionEngineResult TransactionEngine::doPayment(const SerializedTransaction else if (saPaid.isZero()) { // Nothing claimed. - terResult = terPATH_EMPTY; // XXX No effect except unfundeds and charge fee. - // XXX + terResult = terPATH_EMPTY; // XXX No effect except unfundeds and charge fee. } else { diff --git a/src/TransactionEngine.h b/src/TransactionEngine.h index 5e1d76c76..16e105b57 100644 --- a/src/TransactionEngine.h +++ b/src/TransactionEngine.h @@ -239,7 +239,6 @@ protected: STAmount accountFunds(const uint160& uAccountID, const STAmount& saDefault); PathState::pointer pathCreate(const STPath& spPath); - void pathApply(PathState::pointer pspCur); 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);