From 6aa725768a69567d4c000ab37b6929aba2250536 Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Sun, 19 Aug 2012 01:41:07 -0700 Subject: [PATCH 01/12] Cosmetic. --- src/TransactionEngine.cpp | 141 +++++++++++++++++++------------------- 1 file changed, 71 insertions(+), 70 deletions(-) diff --git a/src/TransactionEngine.cpp b/src/TransactionEngine.cpp index ad1c4c63d7..65e9cda809 100644 --- a/src/TransactionEngine.cpp +++ b/src/TransactionEngine.cpp @@ -1903,17 +1903,17 @@ bool TransactionEngine::calcNodeOfferRev( { bool bSuccess = false; - paymentNode& prvPN = pspCur->vpnNodes[uIndex-1]; - paymentNode& curPN = pspCur->vpnNodes[uIndex]; - paymentNode& nxtPN = pspCur->vpnNodes[uIndex+1]; + paymentNode& pnPrv = pspCur->vpnNodes[uIndex-1]; + paymentNode& pnCur = pspCur->vpnNodes[uIndex]; + paymentNode& pnNxt = pspCur->vpnNodes[uIndex+1]; - uint160& uPrvCurrencyID = prvPN.uCurrencyID; - uint160& uPrvIssuerID = prvPN.uIssuerID; - uint160& uCurCurrencyID = curPN.uCurrencyID; - uint160& uCurIssuerID = curPN.uIssuerID; - uint160& uNxtCurrencyID = nxtPN.uCurrencyID; - uint160& uNxtIssuerID = nxtPN.uIssuerID; - uint160& uNxtAccountID = nxtPN.uAccountID; + uint160& uPrvCurrencyID = pnPrv.uCurrencyID; + uint160& uPrvIssuerID = pnPrv.uIssuerID; + uint160& uCurCurrencyID = pnCur.uCurrencyID; + uint160& uCurIssuerID = pnCur.uIssuerID; + uint160& uNxtCurrencyID = pnNxt.uCurrencyID; + uint160& uNxtIssuerID = pnNxt.uIssuerID; + uint160& uNxtAccountID = pnNxt.uAccountID; STAmount saTransferRate = STAmount(CURRENCY_ONE, rippleTransferRate(uCurIssuerID), -9); @@ -1921,10 +1921,10 @@ bool TransactionEngine::calcNodeOfferRev( uint256 uDirectEnd = Ledger::getQualityNext(uDirectTip); bool bAdvance = !entryCache(ltDIR_NODE, uDirectTip); - STAmount& saPrvDlvReq = prvPN.saRevDeliver; // To be adjusted. + STAmount& saPrvDlvReq = pnPrv.saRevDeliver; // To be adjusted. STAmount saPrvDlvAct; - const STAmount& saCurDlvReq = curPN.saRevDeliver; // Reverse driver. + const STAmount& saCurDlvReq = pnCur.saRevDeliver; // Reverse driver. STAmount saCurDlvAct; while (!!uDirectTip // Have a quality. @@ -1944,6 +1944,7 @@ bool TransactionEngine::calcNodeOfferRev( { // Do a directory. // - Drive on computing saCurDlvAct to derive saPrvDlvAct. + // XXX Behave well, if entry type is wrong (someone beat us to using the hash) SLE::pointer sleDirectDir = entryCache(ltDIR_NODE, uDirectTip); STAmount saOfrRate = STAmount::setRate(Ledger::getQuality(uDirectTip), uCurCurrencyID); // For correct ratio unsigned int uEntry = 0; @@ -2095,28 +2096,28 @@ bool TransactionEngine::calcNodeOfferFwd( { bool bSuccess = false; - paymentNode& prvPN = pspCur->vpnNodes[uIndex-1]; - paymentNode& curPN = pspCur->vpnNodes[uIndex]; - paymentNode& nxtPN = pspCur->vpnNodes[uIndex+1]; + paymentNode& pnPrv = pspCur->vpnNodes[uIndex-1]; + paymentNode& pnCur = pspCur->vpnNodes[uIndex]; + paymentNode& pnNxt = pspCur->vpnNodes[uIndex+1]; - uint160& uPrvCurrencyID = prvPN.uCurrencyID; - uint160& uPrvIssuerID = prvPN.uIssuerID; - uint160& uCurCurrencyID = curPN.uCurrencyID; - uint160& uCurIssuerID = curPN.uIssuerID; - uint160& uNxtCurrencyID = nxtPN.uCurrencyID; - uint160& uNxtIssuerID = nxtPN.uIssuerID; + uint160& uPrvCurrencyID = pnPrv.uCurrencyID; + uint160& uPrvIssuerID = pnPrv.uIssuerID; + uint160& uCurCurrencyID = pnCur.uCurrencyID; + uint160& uCurIssuerID = pnCur.uIssuerID; + uint160& uNxtCurrencyID = pnNxt.uCurrencyID; + uint160& uNxtIssuerID = pnNxt.uIssuerID; - uint160& uNxtAccountID = nxtPN.uAccountID; + uint160& uNxtAccountID = pnNxt.uAccountID; STAmount saTransferRate = STAmount(CURRENCY_ONE, rippleTransferRate(uCurIssuerID), -9); uint256 uDirectTip = Ledger::getBookBase(uPrvCurrencyID, uPrvIssuerID, uCurCurrencyID, uCurIssuerID); uint256 uDirectEnd = Ledger::getQualityNext(uDirectTip); bool bAdvance = !entryCache(ltDIR_NODE, uDirectTip); - STAmount& saPrvDlvReq = prvPN.saFwdDeliver; // Forward driver. + STAmount& saPrvDlvReq = pnPrv.saFwdDeliver; // Forward driver. STAmount saPrvDlvAct; - STAmount& saCurDlvReq = curPN.saFwdDeliver; + STAmount& saCurDlvReq = pnCur.saFwdDeliver; STAmount saCurDlvAct; while (!!uDirectTip // Have a quality. @@ -2589,22 +2590,22 @@ bool TransactionEngine::calcNodeAccountRev(unsigned int uIndex, PathState::point bool bSuccess = true; unsigned int uLast = pspCur->vpnNodes.size() - 1; - paymentNode& prvPN = pspCur->vpnNodes[uIndex ? uIndex-1 : 0]; - paymentNode& curPN = pspCur->vpnNodes[uIndex]; - paymentNode& nxtPN = pspCur->vpnNodes[uIndex == uLast ? uLast : uIndex+1]; + paymentNode& pnPrv = pspCur->vpnNodes[uIndex ? uIndex-1 : 0]; + paymentNode& pnCur = pspCur->vpnNodes[uIndex]; + paymentNode& pnNxt = pspCur->vpnNodes[uIndex == uLast ? uLast : uIndex+1]; - bool bRedeem = !!(curPN.uFlags & STPathElement::typeRedeem); - bool bPrvRedeem = !!(prvPN.uFlags & STPathElement::typeRedeem); - bool bIssue = !!(curPN.uFlags & STPathElement::typeIssue); - bool bPrvIssue = !!(prvPN.uFlags & STPathElement::typeIssue); - bool bPrvAccount = !uIndex || !!(prvPN.uFlags & STPathElement::typeAccount); - bool bNxtAccount = uIndex == uLast || !!(nxtPN.uFlags & STPathElement::typeAccount); + bool bRedeem = !!(pnCur.uFlags & STPathElement::typeRedeem); + bool bPrvRedeem = !!(pnPrv.uFlags & STPathElement::typeRedeem); + bool bIssue = !!(pnCur.uFlags & STPathElement::typeIssue); + bool bPrvIssue = !!(pnPrv.uFlags & STPathElement::typeIssue); + bool bPrvAccount = !uIndex || !!(pnPrv.uFlags & STPathElement::typeAccount); + bool bNxtAccount = uIndex == uLast || !!(pnNxt.uFlags & STPathElement::typeAccount); - const uint160& uPrvAccountID = prvPN.uAccountID; - const uint160& uCurAccountID = curPN.uAccountID; - const uint160& uNxtAccountID = bNxtAccount ? nxtPN.uAccountID : uCurAccountID; // Offers are always issue. + const uint160& uPrvAccountID = pnPrv.uAccountID; + const uint160& uCurAccountID = pnCur.uAccountID; + const uint160& uNxtAccountID = bNxtAccount ? pnNxt.uAccountID : uCurAccountID; // Offers are always issue. - const uint160& uCurrencyID = curPN.uCurrencyID; + const uint160& uCurrencyID = pnCur.uCurrencyID; const uint32 uQualityIn = uIndex ? rippleQualityIn(uCurAccountID, uPrvAccountID, uCurrencyID) : 1; const uint32 uQualityOut = uIndex != uLast ? rippleQualityOut(uCurAccountID, uNxtAccountID, uCurrencyID) : 1; @@ -2614,24 +2615,24 @@ bool TransactionEngine::calcNodeAccountRev(unsigned int uIndex, PathState::point const STAmount saPrvLimit = uIndex && bPrvAccount ? rippleLimit(uCurAccountID, uPrvAccountID, uCurrencyID) : STAmount(uCurrencyID); const STAmount saPrvRedeemReq = bPrvRedeem && saPrvBalance.isNegative() ? -saPrvBalance : STAmount(uCurrencyID, 0); - STAmount& saPrvRedeemAct = prvPN.saRevRedeem; + STAmount& saPrvRedeemAct = pnPrv.saRevRedeem; const STAmount saPrvIssueReq = bPrvIssue ? saPrvLimit - saPrvBalance : STAmount(uCurrencyID); - STAmount& saPrvIssueAct = prvPN.saRevIssue; + STAmount& saPrvIssueAct = pnPrv.saRevIssue; // For !bPrvAccount const STAmount saPrvDeliverReq = STAmount(uCurrencyID, -1); // Unlimited. - STAmount& saPrvDeliverAct = prvPN.saRevDeliver; + STAmount& saPrvDeliverAct = pnPrv.saRevDeliver; // For bNxtAccount - const STAmount& saCurRedeemReq = curPN.saRevRedeem; + const STAmount& saCurRedeemReq = pnCur.saRevRedeem; STAmount saCurRedeemAct(saCurRedeemReq.getCurrency()); - const STAmount& saCurIssueReq = curPN.saRevIssue; + const STAmount& saCurIssueReq = pnCur.saRevIssue; STAmount saCurIssueAct(saCurIssueReq.getCurrency()); // Track progress. // For !bNxtAccount - const STAmount& saCurDeliverReq = curPN.saRevDeliver; + const STAmount& saCurDeliverReq = pnCur.saRevDeliver; STAmount saCurDeliverAct(saCurDeliverReq.getCurrency()); // For uIndex == uLast @@ -2883,45 +2884,45 @@ bool TransactionEngine::calcNodeAccountFwd(unsigned int uIndex, PathState::point bool bSuccess = true; unsigned int uLast = pspCur->vpnNodes.size() - 1; - paymentNode& prvPN = pspCur->vpnNodes[uIndex ? uIndex-1 : 0]; - paymentNode& curPN = pspCur->vpnNodes[uIndex]; - paymentNode& nxtPN = pspCur->vpnNodes[uIndex == uLast ? uLast : uIndex+1]; + paymentNode& pnPrv = pspCur->vpnNodes[uIndex ? uIndex-1 : 0]; + paymentNode& pnCur = pspCur->vpnNodes[uIndex]; + paymentNode& pnNxt = pspCur->vpnNodes[uIndex == uLast ? uLast : uIndex+1]; - bool bRedeem = !!(curPN.uFlags & STPathElement::typeRedeem); - bool bIssue = !!(curPN.uFlags & STPathElement::typeIssue); - bool bPrvAccount = !!(prvPN.uFlags & STPathElement::typeAccount); - bool bNxtAccount = !!(nxtPN.uFlags & STPathElement::typeAccount); + bool bRedeem = !!(pnCur.uFlags & STPathElement::typeRedeem); + bool bIssue = !!(pnCur.uFlags & STPathElement::typeIssue); + bool bPrvAccount = !!(pnPrv.uFlags & STPathElement::typeAccount); + bool bNxtAccount = !!(pnNxt.uFlags & STPathElement::typeAccount); - uint160& uPrvAccountID = prvPN.uAccountID; - uint160& uCurAccountID = curPN.uAccountID; - uint160& uNxtAccountID = bNxtAccount ? nxtPN.uAccountID : uCurAccountID; // Offers are always issue. + uint160& uPrvAccountID = pnPrv.uAccountID; + uint160& uCurAccountID = pnCur.uAccountID; + uint160& uNxtAccountID = bNxtAccount ? pnNxt.uAccountID : uCurAccountID; // Offers are always issue. - uint160& uCurrencyID = curPN.uCurrencyID; + uint160& uCurrencyID = pnCur.uCurrencyID; uint32 uQualityIn = rippleQualityIn(uCurAccountID, uPrvAccountID, uCurrencyID); uint32 uQualityOut = rippleQualityOut(uCurAccountID, uNxtAccountID, uCurrencyID); // For bNxtAccount - const STAmount& saPrvRedeemReq = prvPN.saFwdRedeem; + const STAmount& saPrvRedeemReq = pnPrv.saFwdRedeem; STAmount saPrvRedeemAct(saPrvRedeemReq.getCurrency()); - const STAmount& saPrvIssueReq = prvPN.saFwdIssue; + const STAmount& saPrvIssueReq = pnPrv.saFwdIssue; STAmount saPrvIssueAct(saPrvIssueReq.getCurrency()); // For !bPrvAccount - const STAmount& saPrvDeliverReq = prvPN.saRevDeliver; + const STAmount& saPrvDeliverReq = pnPrv.saRevDeliver; STAmount saPrvDeliverAct(saPrvDeliverReq.getCurrency()); // For bNxtAccount - const STAmount& saCurRedeemReq = curPN.saRevRedeem; - STAmount& saCurRedeemAct = curPN.saFwdRedeem; + const STAmount& saCurRedeemReq = pnCur.saRevRedeem; + STAmount& saCurRedeemAct = pnCur.saFwdRedeem; - const STAmount& saCurIssueReq = curPN.saRevIssue; - STAmount& saCurIssueAct = curPN.saFwdIssue; + const STAmount& saCurIssueReq = pnCur.saRevIssue; + STAmount& saCurIssueAct = pnCur.saFwdIssue; // For !bNxtAccount - const STAmount& saCurDeliverReq = curPN.saRevDeliver; - STAmount& saCurDeliverAct = curPN.saFwdDeliver; + const STAmount& saCurDeliverReq = pnCur.saRevDeliver; + STAmount& saCurDeliverAct = pnCur.saFwdDeliver; STAmount& saCurReceive = pspCur->saOutAct; @@ -2945,12 +2946,12 @@ bool TransactionEngine::calcNodeAccountFwd(unsigned int uIndex, PathState::point // First node, calculate amount to send. // XXX Use stamp/ripple balance - paymentNode& curPN = pspCur->vpnNodes[uIndex]; + paymentNode& pnCur = pspCur->vpnNodes[uIndex]; - STAmount& saCurRedeemReq = curPN.saRevRedeem; - STAmount& saCurRedeemAct = curPN.saFwdRedeem; - STAmount& saCurIssueReq = curPN.saRevIssue; - STAmount& saCurIssueAct = curPN.saFwdIssue; + STAmount& saCurRedeemReq = pnCur.saRevRedeem; + STAmount& saCurRedeemAct = pnCur.saFwdRedeem; + STAmount& saCurIssueReq = pnCur.saRevIssue; + STAmount& saCurIssueAct = pnCur.saFwdIssue; STAmount& saCurSendMaxReq = pspCur->saInReq; // Negative for no limit, doing a calculation. STAmount& saCurSendMaxAct = pspCur->saInAct; // Report to user how much this sends. @@ -3512,8 +3513,8 @@ Json::Value PathState::getJson() const // XXX Disallow looping. bool TransactionEngine::calcNode(unsigned int uIndex, PathState::pointer pspCur, bool bMultiQuality) { - paymentNode& curPN = pspCur->vpnNodes[uIndex]; - bool bCurAccount = !!(curPN.uFlags & STPathElement::typeAccount); + paymentNode& pnCur = pspCur->vpnNodes[uIndex]; + bool bCurAccount = !!(pnCur.uFlags & STPathElement::typeAccount); bool bValid; // Do current node reverse. From 053e030e70e9cf7b5e69377849f507c99a1e169a Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Sun, 19 Aug 2012 02:32:09 -0700 Subject: [PATCH 02/12] Constify TransactionEngine. --- src/TransactionEngine.cpp | 289 +++++++++++++++++++------------------- 1 file changed, 144 insertions(+), 145 deletions(-) diff --git a/src/TransactionEngine.cpp b/src/TransactionEngine.cpp index 65e9cda809..af7f9a53a2 100644 --- a/src/TransactionEngine.cpp +++ b/src/TransactionEngine.cpp @@ -366,8 +366,8 @@ void TransactionEngine::rippleCredit(const uint160& uSenderID, const uint160& uR // <-- saActual: Amount actually sent. Sender pay's fees. STAmount TransactionEngine::rippleSend(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount) { - STAmount saActual; - uint160 uIssuerID = saAmount.getIssuer(); + STAmount saActual; + const uint160 uIssuerID = saAmount.getIssuer(); if (uSenderID == uIssuerID || uReceiverID == uIssuerID) { @@ -1504,15 +1504,14 @@ TransactionEngineResult TransactionEngine::doCreditSet(const SerializedTransacti return terNO_DST; } - bool bFlipped = mTxnAccountID > uDstAccountID; // true, iff current is not lowest. - bool bLimitAmount = txn.getITFieldPresent(sfLimitAmount); - STAmount saLimitAmount = bLimitAmount ? txn.getITFieldAmount(sfLimitAmount) : STAmount(); - bool bQualityIn = txn.getITFieldPresent(sfQualityIn); - uint32 uQualityIn = bQualityIn ? txn.getITFieldU32(sfQualityIn) : 0; - bool bQualityOut = txn.getITFieldPresent(sfQualityOut); - uint32 uQualityOut = bQualityIn ? txn.getITFieldU32(sfQualityOut) : 0; - uint160 uCurrencyID = saLimitAmount.getCurrency(); - STAmount saBalance(uCurrencyID); + const bool bFlipped = mTxnAccountID > uDstAccountID; // true, iff current is not lowest. + const bool bLimitAmount = txn.getITFieldPresent(sfLimitAmount); + const STAmount saLimitAmount = bLimitAmount ? txn.getITFieldAmount(sfLimitAmount) : STAmount(); + const bool bQualityIn = txn.getITFieldPresent(sfQualityIn); + const uint32 uQualityIn = bQualityIn ? txn.getITFieldU32(sfQualityIn) : 0; + const bool bQualityOut = txn.getITFieldPresent(sfQualityOut); + const uint32 uQualityOut = bQualityIn ? txn.getITFieldU32(sfQualityOut) : 0; + const uint160 uCurrencyID = saLimitAmount.getCurrency(); bool bDelIndex = false; SLE::pointer sleRippleState = entryCache(ltRIPPLE_STATE, Ledger::getRippleStateIndex(mTxnAccountID, uDstAccountID, uCurrencyID)); @@ -1620,9 +1619,9 @@ TransactionEngineResult TransactionEngine::doNicknameSet(const SerializedTransac { std::cerr << "doNicknameSet>" << std::endl; - uint256 uNickname = txn.getITFieldH256(sfNickname); - bool bMinOffer = txn.getITFieldPresent(sfMinimumOffer); - STAmount saMinOffer = bMinOffer ? txn.getITFieldAmount(sfAmount) : STAmount(); + const uint256 uNickname = txn.getITFieldH256(sfNickname); + const bool bMinOffer = txn.getITFieldPresent(sfMinimumOffer); + const STAmount saMinOffer = bMinOffer ? txn.getITFieldAmount(sfAmount) : STAmount(); SLE::pointer sleNickname = entryCache(ltNICKNAME, uNickname); @@ -1631,7 +1630,7 @@ TransactionEngineResult TransactionEngine::doNicknameSet(const SerializedTransac // Edit old entry. sleNickname->setIFieldAccount(sfAccount, mTxnAccountID); - if (bMinOffer && !saMinOffer.isZero()) + if (bMinOffer && !!saMinOffer) { sleNickname->setIFieldAmount(sfMinimumOffer, saMinOffer); } @@ -1653,7 +1652,7 @@ TransactionEngineResult TransactionEngine::doNicknameSet(const SerializedTransac sleNickname->setIFieldAccount(sfAccount, mTxnAccountID); - if (bMinOffer && !saMinOffer.isZero()) + if (bMinOffer && !!saMinOffer) sleNickname->setIFieldAmount(sfMinimumOffer, saMinOffer); } @@ -1666,7 +1665,7 @@ TransactionEngineResult TransactionEngine::doPasswordFund(const SerializedTransa { std::cerr << "doPasswordFund>" << std::endl; - uint160 uDstAccountID = txn.getITFieldAccount(sfDestination); + const uint160 uDstAccountID = txn.getITFieldAccount(sfDestination); SLE::pointer sleDst = mTxnAccountID == uDstAccountID ? mTxnAccount : entryCache(ltACCOUNT_ROOT, Ledger::getAccountRootIndex(uDstAccountID)); @@ -1907,18 +1906,18 @@ bool TransactionEngine::calcNodeOfferRev( paymentNode& pnCur = pspCur->vpnNodes[uIndex]; paymentNode& pnNxt = pspCur->vpnNodes[uIndex+1]; - uint160& uPrvCurrencyID = pnPrv.uCurrencyID; - uint160& uPrvIssuerID = pnPrv.uIssuerID; - uint160& uCurCurrencyID = pnCur.uCurrencyID; - uint160& uCurIssuerID = pnCur.uIssuerID; - uint160& uNxtCurrencyID = pnNxt.uCurrencyID; - uint160& uNxtIssuerID = pnNxt.uIssuerID; - uint160& uNxtAccountID = pnNxt.uAccountID; + const uint160& uPrvCurrencyID = pnPrv.uCurrencyID; + const uint160& uPrvIssuerID = pnPrv.uIssuerID; + const uint160& uCurCurrencyID = pnCur.uCurrencyID; + const uint160& uCurIssuerID = pnCur.uIssuerID; + const uint160& uNxtCurrencyID = pnNxt.uCurrencyID; + const uint160& uNxtIssuerID = pnNxt.uIssuerID; + const uint160& uNxtAccountID = pnNxt.uAccountID; - STAmount saTransferRate = STAmount(CURRENCY_ONE, rippleTransferRate(uCurIssuerID), -9); + const STAmount saTransferRate = STAmount(CURRENCY_ONE, rippleTransferRate(uCurIssuerID), -9); uint256 uDirectTip = Ledger::getBookBase(uPrvCurrencyID, uPrvIssuerID, uCurCurrencyID, uCurIssuerID); - uint256 uDirectEnd = Ledger::getQualityNext(uDirectTip); + const uint256 uDirectEnd = Ledger::getQualityNext(uDirectTip); bool bAdvance = !entryCache(ltDIR_NODE, uDirectTip); STAmount& saPrvDlvReq = pnPrv.saRevDeliver; // To be adjusted. @@ -2100,21 +2099,21 @@ bool TransactionEngine::calcNodeOfferFwd( paymentNode& pnCur = pspCur->vpnNodes[uIndex]; paymentNode& pnNxt = pspCur->vpnNodes[uIndex+1]; - uint160& uPrvCurrencyID = pnPrv.uCurrencyID; - uint160& uPrvIssuerID = pnPrv.uIssuerID; - uint160& uCurCurrencyID = pnCur.uCurrencyID; - uint160& uCurIssuerID = pnCur.uIssuerID; - uint160& uNxtCurrencyID = pnNxt.uCurrencyID; - uint160& uNxtIssuerID = pnNxt.uIssuerID; + const uint160& uPrvCurrencyID = pnPrv.uCurrencyID; + const uint160& uPrvIssuerID = pnPrv.uIssuerID; + const uint160& uCurCurrencyID = pnCur.uCurrencyID; + const uint160& uCurIssuerID = pnCur.uIssuerID; + const uint160& uNxtCurrencyID = pnNxt.uCurrencyID; + const uint160& uNxtIssuerID = pnNxt.uIssuerID; - uint160& uNxtAccountID = pnNxt.uAccountID; - STAmount saTransferRate = STAmount(CURRENCY_ONE, rippleTransferRate(uCurIssuerID), -9); + const uint160& uNxtAccountID = pnNxt.uAccountID; + const STAmount saTransferRate = STAmount(CURRENCY_ONE, rippleTransferRate(uCurIssuerID), -9); uint256 uDirectTip = Ledger::getBookBase(uPrvCurrencyID, uPrvIssuerID, uCurCurrencyID, uCurIssuerID); - uint256 uDirectEnd = Ledger::getQualityNext(uDirectTip); + const uint256 uDirectEnd = Ledger::getQualityNext(uDirectTip); bool bAdvance = !entryCache(ltDIR_NODE, uDirectTip); - STAmount& saPrvDlvReq = pnPrv.saFwdDeliver; // Forward driver. + const STAmount& saPrvDlvReq = pnPrv.saFwdDeliver; // Forward driver. STAmount saPrvDlvAct; STAmount& saCurDlvReq = pnCur.saFwdDeliver; @@ -2164,22 +2163,22 @@ bool TransactionEngine::calcNodeOfferFwd( { // Next is an account. - STAmount saFeeRate = uCurOfrAccountID == uCurIssuerID || uNxtAccountID == uCurIssuerID - ? saOne - : saTransferRate; - bool bFee = saFeeRate != saOne; + const STAmount saFeeRate = uCurOfrAccountID == uCurIssuerID || uNxtAccountID == uCurIssuerID + ? saOne + : saTransferRate; + const bool bFee = saFeeRate != saOne; - STAmount saOutPass = STAmount::divide(saCurOfrInReq, saOfrRate, uCurCurrencyID); - STAmount saOutBase = MIN(saCurOfrOutReq, saOutPass); // Limit offer out by needed. - STAmount saOutCost = MIN( - bFee - ? STAmount::multiply(saOutBase, saFeeRate, uCurCurrencyID) - : saOutBase, - saCurOfrFunds); // Limit cost by fees & funds. - STAmount saOutDlvAct = bFee - ? STAmount::divide(saOutCost, saFeeRate, uCurCurrencyID) - : saOutCost; // Out amount after fees. - STAmount saInDlvAct = STAmount::multiply(saOutDlvAct, saOfrRate, uCurCurrencyID); // Compute input w/o fees required. + const STAmount saOutPass = STAmount::divide(saCurOfrInReq, saOfrRate, uCurCurrencyID); + const STAmount saOutBase = MIN(saCurOfrOutReq, saOutPass); // Limit offer out by needed. + const STAmount saOutCost = MIN( + bFee + ? STAmount::multiply(saOutBase, saFeeRate, uCurCurrencyID) + : saOutBase, + saCurOfrFunds); // Limit cost by fees & funds. + const STAmount saOutDlvAct = bFee + ? STAmount::divide(saOutCost, saFeeRate, uCurCurrencyID) + : saOutCost; // Out amount after fees. + const STAmount saInDlvAct = STAmount::multiply(saOutDlvAct, saOfrRate, uCurCurrencyID); // Compute input w/o fees required. saCurDlvAct += saOutDlvAct; // Portion of driver served. saPrvDlvAct += saInDlvAct; // Portion needed in previous. @@ -2189,7 +2188,7 @@ bool TransactionEngine::calcNodeOfferFwd( // Next is an offer. uint256 uNxtTip = Ledger::getBookBase(uCurCurrencyID, uCurIssuerID, uNxtCurrencyID, uNxtIssuerID); - uint256 uNxtEnd = Ledger::getQualityNext(uNxtTip); + const uint256 uNxtEnd = Ledger::getQualityNext(uNxtTip); bool bNxtAdvance = !entryCache(ltDIR_NODE, uNxtTip); while (!!uNxtTip // Have a quality. @@ -2218,30 +2217,30 @@ bool TransactionEngine::calcNodeOfferFwd( { // YYY This could combine offers with the same fee before doing math. SLE::pointer sleNxtOfr = entryCache(ltOFFER, uNxtIndex); - uint160 uNxtOfrAccountID = sleNxtOfr->getIValueFieldAccount(sfAccount).getAccountID(); + const uint160 uNxtOfrAccountID = sleNxtOfr->getIValueFieldAccount(sfAccount).getAccountID(); STAmount saNxtOfrIn = sleNxtOfr->getIValueFieldAmount(sfTakerPays); // XXX Move issuer into STAmount if (sleNxtOfr->getIFieldPresent(sfPaysIssuer)) saNxtOfrIn.setIssuer(sleCurOfr->getIValueFieldAccount(sfPaysIssuer).getAccountID()); - STAmount saFeeRate = uCurOfrAccountID == uCurIssuerID || uNxtOfrAccountID == uCurIssuerID - ? saOne - : saTransferRate; - bool bFee = saFeeRate != saOne; + const STAmount saFeeRate = uCurOfrAccountID == uCurIssuerID || uNxtOfrAccountID == uCurIssuerID + ? saOne + : saTransferRate; + const bool bFee = saFeeRate != saOne; - STAmount saInBase = saCurOfrInReq-saCurOfrInAct; - STAmount saOutPass = STAmount::divide(saInBase, saOfrRate, uCurCurrencyID); - STAmount saOutBase = MIN(saCurOfrOutReq, saOutPass); // Limit offer out by needed. - saOutBase = MIN(saOutBase, saNxtOfrIn); // Limit offer out by supplying offer. - STAmount saOutCost = MIN( + const STAmount saInBase = saCurOfrInReq-saCurOfrInAct; + const STAmount saOutPass = STAmount::divide(saInBase, saOfrRate, uCurCurrencyID); + STAmount saOutBase = MIN(saCurOfrOutReq, saOutPass); // Limit offer out by needed. + saOutBase = MIN(saOutBase, saNxtOfrIn); // Limit offer out by supplying offer. + const STAmount saOutCost = MIN( bFee ? STAmount::multiply(saOutBase, saFeeRate, uCurCurrencyID) : saOutBase, saCurOfrFunds); // Limit cost by fees & funds. - STAmount saOutDlvAct = bFee + const STAmount saOutDlvAct = bFee ? STAmount::divide(saOutCost, saFeeRate, uCurCurrencyID) : saOutCost; // Out amount after fees. - STAmount saInDlvAct = STAmount::multiply(saOutDlvAct, saOfrRate, uPrvCurrencyID); // Compute input w/o fees required. + const STAmount saInDlvAct = STAmount::multiply(saOutDlvAct, saOfrRate, uPrvCurrencyID); // Compute input w/o fees required. saCurOfrInAct += saOutDlvAct; // Portion of driver served. saPrvDlvAct += saOutDlvAct; // Portion needed in previous. @@ -2526,9 +2525,9 @@ void TransactionEngine::calcNodeRipple( assert(saPrvReq.getCurrency() == saCurReq.getCurrency()); - bool bPrvUnlimited = saPrvReq.isNegative(); - STAmount saPrv = bPrvUnlimited ? STAmount(saPrvReq) : saPrvReq-saPrvAct; - STAmount saCur = saCurReq-saCurAct; + const bool bPrvUnlimited = saPrvReq.isNegative(); + const STAmount saPrv = bPrvUnlimited ? STAmount(saPrvReq) : saPrvReq-saPrvAct; + const STAmount saCur = saCurReq-saCurAct; #if 0 Log(lsINFO) << str(boost::format("calcNodeRipple: bPrvUnlimited=%d saPrv=%s saCur=%s") @@ -2588,18 +2587,18 @@ Log(lsINFO) << str(boost::format("calcNodeRipple:4: saCurReq=%s") % saCurReq.get bool TransactionEngine::calcNodeAccountRev(unsigned int uIndex, PathState::pointer pspCur, bool bMultiQuality) { bool bSuccess = true; - unsigned int uLast = pspCur->vpnNodes.size() - 1; + const unsigned int uLast = pspCur->vpnNodes.size() - 1; paymentNode& pnPrv = pspCur->vpnNodes[uIndex ? uIndex-1 : 0]; paymentNode& pnCur = pspCur->vpnNodes[uIndex]; paymentNode& pnNxt = pspCur->vpnNodes[uIndex == uLast ? uLast : uIndex+1]; - bool bRedeem = !!(pnCur.uFlags & STPathElement::typeRedeem); - bool bPrvRedeem = !!(pnPrv.uFlags & STPathElement::typeRedeem); - bool bIssue = !!(pnCur.uFlags & STPathElement::typeIssue); - bool bPrvIssue = !!(pnPrv.uFlags & STPathElement::typeIssue); - bool bPrvAccount = !uIndex || !!(pnPrv.uFlags & STPathElement::typeAccount); - bool bNxtAccount = uIndex == uLast || !!(pnNxt.uFlags & STPathElement::typeAccount); + const bool bRedeem = !!(pnCur.uFlags & STPathElement::typeRedeem); + const bool bPrvRedeem = !!(pnPrv.uFlags & STPathElement::typeRedeem); + const bool bIssue = !!(pnCur.uFlags & STPathElement::typeIssue); + const bool bPrvIssue = !!(pnPrv.uFlags & STPathElement::typeIssue); + const bool bPrvAccount = !uIndex || !!(pnPrv.uFlags & STPathElement::typeAccount); + const bool bNxtAccount = uIndex == uLast || !!(pnNxt.uFlags & STPathElement::typeAccount); const uint160& uPrvAccountID = pnPrv.uAccountID; const uint160& uCurAccountID = pnCur.uAccountID; @@ -2882,22 +2881,22 @@ bool TransactionEngine::calcNodeAccountRev(unsigned int uIndex, PathState::point bool TransactionEngine::calcNodeAccountFwd(unsigned int uIndex, PathState::pointer pspCur, bool bMultiQuality) { bool bSuccess = true; - unsigned int uLast = pspCur->vpnNodes.size() - 1; + const unsigned int uLast = pspCur->vpnNodes.size() - 1; paymentNode& pnPrv = pspCur->vpnNodes[uIndex ? uIndex-1 : 0]; paymentNode& pnCur = pspCur->vpnNodes[uIndex]; paymentNode& pnNxt = pspCur->vpnNodes[uIndex == uLast ? uLast : uIndex+1]; - bool bRedeem = !!(pnCur.uFlags & STPathElement::typeRedeem); - bool bIssue = !!(pnCur.uFlags & STPathElement::typeIssue); - bool bPrvAccount = !!(pnPrv.uFlags & STPathElement::typeAccount); - bool bNxtAccount = !!(pnNxt.uFlags & STPathElement::typeAccount); + const bool bRedeem = !!(pnCur.uFlags & STPathElement::typeRedeem); + const bool bIssue = !!(pnCur.uFlags & STPathElement::typeIssue); + const bool bPrvAccount = !!(pnPrv.uFlags & STPathElement::typeAccount); + const bool bNxtAccount = !!(pnNxt.uFlags & STPathElement::typeAccount); - uint160& uPrvAccountID = pnPrv.uAccountID; - uint160& uCurAccountID = pnCur.uAccountID; - uint160& uNxtAccountID = bNxtAccount ? pnNxt.uAccountID : uCurAccountID; // Offers are always issue. + const uint160& uPrvAccountID = pnPrv.uAccountID; + const uint160& uCurAccountID = pnCur.uAccountID; + const uint160& uNxtAccountID = bNxtAccount ? pnNxt.uAccountID : uCurAccountID; // Offers are always issue. - uint160& uCurrencyID = pnCur.uCurrencyID; + const uint160& uCurrencyID = pnCur.uCurrencyID; uint32 uQualityIn = rippleQualityIn(uCurAccountID, uPrvAccountID, uCurrencyID); uint32 uQualityOut = rippleQualityOut(uCurAccountID, uNxtAccountID, uCurrencyID); @@ -2948,12 +2947,12 @@ bool TransactionEngine::calcNodeAccountFwd(unsigned int uIndex, PathState::point // XXX Use stamp/ripple balance paymentNode& pnCur = pspCur->vpnNodes[uIndex]; - STAmount& saCurRedeemReq = pnCur.saRevRedeem; + const STAmount& saCurRedeemReq = pnCur.saRevRedeem; STAmount& saCurRedeemAct = pnCur.saFwdRedeem; - STAmount& saCurIssueReq = pnCur.saRevIssue; + const STAmount& saCurIssueReq = pnCur.saRevIssue; STAmount& saCurIssueAct = pnCur.saFwdIssue; - STAmount& saCurSendMaxReq = pspCur->saInReq; // Negative for no limit, doing a calculation. + const STAmount& saCurSendMaxReq = pspCur->saInReq; // Negative for no limit, doing a calculation. STAmount& saCurSendMaxAct = pspCur->saInAct; // Report to user how much this sends. if (saCurRedeemReq) @@ -3224,20 +3223,20 @@ bool PathState::pushNode(int iType, uint160 uAccountID, uint160 uCurrencyID, uin << NewcoinAddress::createHumanAccountID(uAccountID) << " " << STAmount::createHumanCurrency(uCurrencyID) << " " << NewcoinAddress::createHumanAccountID(uIssuerID); - paymentNode pnCur; - bool bFirst = vpnNodes.empty(); - const paymentNode& pnPrv = bFirst ? paymentNode() : vpnNodes.back(); - // true, iff node is a ripple account. false, iff node is an offer node. - bool bAccount = !!(iType & STPathElement::typeAccount); - // true, iff currency supplied. - // Currency is specified for the output of the current node. - bool bCurrency = !!(iType & STPathElement::typeCurrency); - // Issuer is specified for the output of the current node. - bool bIssuer = !!(iType & STPathElement::typeIssuer); - // true, iff account is allowed to redeem it's IOUs to next node. - bool bRedeem = !!(iType & STPathElement::typeRedeem); - bool bIssue = !!(iType & STPathElement::typeIssue); - bool bValid = true; + paymentNode pnCur; + const bool bFirst = vpnNodes.empty(); + const paymentNode& pnPrv = bFirst ? paymentNode() : vpnNodes.back(); + // true, iff node is a ripple account. false, iff node is an offer node. + const bool bAccount = !!(iType & STPathElement::typeAccount); + // true, iff currency supplied. + // Currency is specified for the output of the current node. + const bool bCurrency = !!(iType & STPathElement::typeCurrency); + // Issuer is specified for the output of the current node. + const bool bIssuer = !!(iType & STPathElement::typeIssuer); + // true, iff account is allowed to redeem it's IOUs to next node. + const bool bRedeem = !!(iType & STPathElement::typeRedeem); + const bool bIssue = !!(iType & STPathElement::typeIssue); + bool bValid = true; pnCur.uFlags = iType; @@ -3380,10 +3379,10 @@ PathState::PathState( ) : mLedger(lpLedger), mIndex(iIndex), uQuality(0) { - uint160 uInCurrencyID = saSendMax.getCurrency(); - uint160 uOutCurrencyID = saSend.getCurrency(); - uint160 uInIssuerID = !!uInCurrencyID ? uSenderID : ACCOUNT_XNS; - uint160 uOutIssuerID = !!uOutCurrencyID ? uReceiverID : ACCOUNT_XNS; + const uint160 uInCurrencyID = saSendMax.getCurrency(); + const uint160 uOutCurrencyID = saSend.getCurrency(); + const uint160 uInIssuerID = !!uInCurrencyID ? uSenderID : ACCOUNT_XNS; + const uint160 uOutIssuerID = !!uOutCurrencyID ? uReceiverID : ACCOUNT_XNS; lesEntries = lesSource.duplicate(); @@ -3513,9 +3512,9 @@ Json::Value PathState::getJson() const // XXX Disallow looping. bool TransactionEngine::calcNode(unsigned int uIndex, PathState::pointer pspCur, bool bMultiQuality) { - paymentNode& pnCur = pspCur->vpnNodes[uIndex]; - bool bCurAccount = !!(pnCur.uFlags & STPathElement::typeAccount); - bool bValid; + const paymentNode& pnCur = pspCur->vpnNodes[uIndex]; + const bool bCurAccount = !!(pnCur.uFlags & STPathElement::typeAccount); + bool bValid; // Do current node reverse. bValid = bCurAccount @@ -3571,17 +3570,17 @@ void TransactionEngine::pathNext(PathState::pointer pspCur, int iPaths) TransactionEngineResult TransactionEngine::doPayment(const SerializedTransaction& txn) { // Ripple if source or destination is non-native or if there are paths. - uint32 uTxFlags = txn.getFlags(); - bool bCreate = !!(uTxFlags & tfCreateAccount); - bool bNoRippleDirect = !!(uTxFlags & tfNoRippleDirect); - bool bPartialPayment = !!(uTxFlags & tfPartialPayment); - bool bPaths = txn.getITFieldPresent(sfPaths); - bool bMax = txn.getITFieldPresent(sfSendMax); - uint160 uDstAccountID = txn.getITFieldAccount(sfDestination); - STAmount saDstAmount = txn.getITFieldAmount(sfAmount); - STAmount saMaxAmount = bMax ? txn.getITFieldAmount(sfSendMax) : saDstAmount; - uint160 uSrcCurrency = saMaxAmount.getCurrency(); - uint160 uDstCurrency = saDstAmount.getCurrency(); + const uint32 uTxFlags = txn.getFlags(); + const bool bCreate = !!(uTxFlags & tfCreateAccount); + const bool bNoRippleDirect = !!(uTxFlags & tfNoRippleDirect); + const bool bPartialPayment = !!(uTxFlags & tfPartialPayment); + const bool bPaths = txn.getITFieldPresent(sfPaths); + const bool bMax = txn.getITFieldPresent(sfSendMax); + const uint160 uDstAccountID = txn.getITFieldAccount(sfDestination); + const STAmount saDstAmount = txn.getITFieldAmount(sfAmount); + const STAmount saMaxAmount = bMax ? txn.getITFieldAmount(sfSendMax) : saDstAmount; + const uint160 uSrcCurrency = saMaxAmount.getCurrency(); + const uint160 uDstCurrency = saDstAmount.getCurrency(); if (!uDstAccountID) { @@ -3878,11 +3877,11 @@ TransactionEngineResult TransactionEngine::doWalletAdd(const SerializedTransacti { std::cerr << "WalletAdd>" << std::endl; - std::vector vucPubKey = txn.getITFieldVL(sfPubKey); - std::vector vucSignature = txn.getITFieldVL(sfSignature); - uint160 uAuthKeyID = txn.getITFieldAccount(sfAuthorizedKey); - NewcoinAddress naMasterPubKey = NewcoinAddress::createAccountPublic(vucPubKey); - uint160 uDstAccountID = naMasterPubKey.getAccountID(); + const std::vector vucPubKey = txn.getITFieldVL(sfPubKey); + const std::vector vucSignature = txn.getITFieldVL(sfSignature); + const uint160 uAuthKeyID = txn.getITFieldAccount(sfAuthorizedKey); + const NewcoinAddress naMasterPubKey = NewcoinAddress::createAccountPublic(vucPubKey); + const uint160 uDstAccountID = naMasterPubKey.getAccountID(); if (!naMasterPubKey.accountPublicVerify(Serializer::getSHA512Half(uAuthKeyID.begin(), uAuthKeyID.size()), vucSignature)) { @@ -3958,12 +3957,12 @@ TransactionEngineResult TransactionEngine::takeOffers( Log(lsINFO) << "takeOffers: against book: " << uBookBase.ToString(); uint256 uTipIndex = uBookBase; - uint256 uBookEnd = Ledger::getQualityNext(uBookBase); - uint64 uTakeQuality = STAmount::getRate(saTakerGets, saTakerPays); - uint160 uTakerPaysAccountID = saTakerPays.getIssuer(); - uint160 uTakerPaysCurrency = saTakerPays.getCurrency(); - uint160 uTakerGetsAccountID = saTakerGets.getIssuer(); - uint160 uTakerGetsCurrency = saTakerGets.getCurrency(); + const uint256 uBookEnd = Ledger::getQualityNext(uBookBase); + const uint64 uTakeQuality = STAmount::getRate(saTakerGets, saTakerPays); + const uint160 uTakerPaysAccountID = saTakerPays.getIssuer(); + const uint160 uTakerPaysCurrency = saTakerPays.getCurrency(); + const uint160 uTakerGetsAccountID = saTakerGets.getIssuer(); + const uint160 uTakerGetsCurrency = saTakerGets.getCurrency(); TransactionEngineResult terResult = tenUNKNOWN; saTakerPaid = 0; @@ -4018,7 +4017,7 @@ TransactionEngineResult TransactionEngine::takeOffers( Log(lsINFO) << "takeOffers: considering offer : " << sleOffer->getJson(0); - uint160 uOfferOwnerID = sleOffer->getIValueFieldAccount(sfAccount).getAccountID(); + const uint160 uOfferOwnerID = sleOffer->getIValueFieldAccount(sfAccount).getAccountID(); STAmount saOfferPays = sleOffer->getIValueFieldAmount(sfTakerGets); STAmount saOfferGets = sleOffer->getIValueFieldAmount(sfTakerPays); @@ -4139,28 +4138,28 @@ TransactionEngineResult TransactionEngine::takeOffers( TransactionEngineResult TransactionEngine::doOfferCreate(const SerializedTransaction& txn) { Log(lsWARNING) << "doOfferCreate> " << txn.getJson(0); - uint32 txFlags = txn.getFlags(); - bool bPassive = !!(txFlags & tfPassive); - uint160 uPaysIssuerID = txn.getITFieldAccount(sfPaysIssuer); - uint160 uGetsIssuerID = txn.getITFieldAccount(sfGetsIssuer); - STAmount saTakerPays = txn.getITFieldAmount(sfTakerPays); + const uint32 txFlags = txn.getFlags(); + const bool bPassive = !!(txFlags & tfPassive); + const uint160 uPaysIssuerID = txn.getITFieldAccount(sfPaysIssuer); + const uint160 uGetsIssuerID = txn.getITFieldAccount(sfGetsIssuer); + STAmount saTakerPays = txn.getITFieldAmount(sfTakerPays); saTakerPays.setIssuer(uPaysIssuerID); Log(lsWARNING) << "doOfferCreate: saTakerPays=" << saTakerPays.getFullText(); STAmount saTakerGets = txn.getITFieldAmount(sfTakerGets); saTakerGets.setIssuer(uGetsIssuerID); Log(lsWARNING) << "doOfferCreate: saTakerGets=" << saTakerGets.getFullText(); - uint32 uExpiration = txn.getITFieldU32(sfExpiration); - bool bHaveExpiration = txn.getITFieldPresent(sfExpiration); - uint32 uSequence = txn.getSequence(); + const uint32 uExpiration = txn.getITFieldU32(sfExpiration); + const bool bHaveExpiration = txn.getITFieldPresent(sfExpiration); + const uint32 uSequence = txn.getSequence(); - uint256 uLedgerIndex = Ledger::getOfferIndex(mTxnAccountID, uSequence); + const uint256 uLedgerIndex = Ledger::getOfferIndex(mTxnAccountID, uSequence); SLE::pointer sleOffer = entryCreate(ltOFFER, uLedgerIndex); Log(lsINFO) << "doOfferCreate: Creating offer node: " << uLedgerIndex.ToString() << " uSequence=" << uSequence; - uint160 uPaysCurrency = saTakerPays.getCurrency(); - uint160 uGetsCurrency = saTakerGets.getCurrency(); - uint64 uRate = STAmount::getRate(saTakerGets, saTakerPays); + const uint160 uPaysCurrency = saTakerPays.getCurrency(); + const uint160 uGetsCurrency = saTakerGets.getCurrency(); + const uint64 uRate = STAmount::getRate(saTakerGets, saTakerPays); TransactionEngineResult terResult = terSUCCESS; uint256 uDirectory; // Delete hints. @@ -4226,7 +4225,7 @@ Log(lsWARNING) << "doOfferCreate: saTakerGets=" << saTakerGets.getFullText(); { STAmount saOfferPaid; STAmount saOfferGot; - uint256 uTakeBookBase = Ledger::getBookBase(uGetsCurrency, uGetsIssuerID, uPaysCurrency, uPaysIssuerID); + const uint256 uTakeBookBase = Ledger::getBookBase(uGetsCurrency, uGetsIssuerID, uPaysCurrency, uPaysIssuerID); Log(lsINFO) << str(boost::format("doOfferCreate: take against book: %s : %s/%s -> %s/%s") % uTakeBookBase.ToString() @@ -4333,8 +4332,8 @@ Log(lsWARNING) << "doOfferCreate: saTakerGets=" << saTakerGets.getFullText(); TransactionEngineResult TransactionEngine::doOfferCancel(const SerializedTransaction& txn) { TransactionEngineResult terResult; - uint32 uSequence = txn.getITFieldU32(sfOfferSequence); - uint256 uOfferIndex = Ledger::getOfferIndex(mTxnAccountID, uSequence); + const uint32 uSequence = txn.getITFieldU32(sfOfferSequence); + const uint256 uOfferIndex = Ledger::getOfferIndex(mTxnAccountID, uSequence); SLE::pointer sleOffer = entryCache(ltOFFER, uOfferIndex); if (sleOffer) From fbd67bda89ab8966e94d5bbbbb00229f8aea0455 Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Sun, 19 Aug 2012 18:54:26 -0700 Subject: [PATCH 03/12] Let issuer be defaulted for RPC ripple command. --- src/RPCServer.cpp | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/RPCServer.cpp b/src/RPCServer.cpp index 93d800c3f1..11545daf7e 100644 --- a/src/RPCServer.cpp +++ b/src/RPCServer.cpp @@ -1315,9 +1315,9 @@ Json::Value RPCServer::doPeers(const Json::Value& params) } // ripple -// [noredeem] [noissue] +// [] // XXX [noredeem] [noissue] // + -// full|partial +// full|partial [] // // path: // path + @@ -1331,6 +1331,7 @@ Json::Value RPCServer::doRipple(const Json::Value ¶ms) STAmount saSrcAmountMax; uint160 uSrcCurrencyID; NewcoinAddress naSrcAccountID; + NewcoinAddress naSrcIssuerID; bool bSrcRedeem = true; bool bSrcIssue = true; bool bPartial; @@ -1338,11 +1339,12 @@ Json::Value RPCServer::doRipple(const Json::Value ¶ms) NewcoinAddress naDstAccountID; STAmount saDstAmount; uint160 uDstCurrencyID; - NewcoinAddress naDstIssuerID; std::vector vpnPath; STPathSet spsPaths; + naSrcIssuerID.setAccountID(params[4u].asString()); // + if (!naSeed.setSeedGeneric(params[0u].asString())) // { return RPCError(rpcBAD_SEED); @@ -1351,13 +1353,18 @@ Json::Value RPCServer::doRipple(const Json::Value ¶ms) { return RPCError(rpcSRC_ACT_MALFORMED); } - // - else if (!saSrcAmountMax.setFullValue(params[2u].asString(), params[3u].asString(), params[4u].asString())) + // [] + else if (!saSrcAmountMax.setFullValue(params[2u].asString(), params[3u].asString(), params[naSrcIssuerID.isValid() ? 4u : 1u].asString())) { + // Log(lsINFO) << "naSrcIssuerID.isValid(): " << naSrcIssuerID.isValid(); + // Log(lsINFO) << "source_max: " << params[2u].asString(); + // Log(lsINFO) << "source_currency: " << params[3u].asString(); + // Log(lsINFO) << "source_issuer: " << params[naSrcIssuerID.isValid() ? 4u : 2u].asString(); + return RPCError(rpcSRC_AMT_MALFORMED); } - int iArg = 5; + int iArg = 4 + naSrcIssuerID.isValid(); if (params[iArg].asString() == "noredeem") // [noredeem] { @@ -1483,14 +1490,21 @@ Json::Value RPCServer::doRipple(const Json::Value ¶ms) { return RPCError(rpcDST_ACT_MALFORMED); } + + const unsigned int uDstIssuer = params.size() == iArg + 3 ? iArg+2 : iArg-1; + // - else if (params.size() != iArg + 3 || !saDstAmount.setFullValue(params[iArg].asString(), params[iArg+1].asString(), params[iArg+2].asString())) + if (params.size() != iArg + 2 && params.size() != iArg + 3) { - Log(lsINFO) << "params.size(): " << params.size(); - Log(lsINFO) << " iArg: " << iArg; - Log(lsINFO) << " Amount: " << params[iArg].asString(); - Log(lsINFO) << "Currency: " << params[iArg+1].asString(); - Log(lsINFO) << " Issuer: " << params[iArg+2].asString(); + // Log(lsINFO) << "params.size(): " << params.size(); + + return RPCError(rpcDST_AMT_MALFORMED); + } + else if (!saDstAmount.setFullValue(params[iArg].asString(), params[iArg+1].asString(), params[uDstIssuer].asString())) + { + // Log(lsINFO) << " Amount: " << params[iArg].asString(); + // Log(lsINFO) << "Currency: " << params[iArg+1].asString(); + // Log(lsINFO) << " Issuer: " << params[uDstIssuer].asString(); return RPCError(rpcDST_AMT_MALFORMED); } @@ -1515,6 +1529,8 @@ Json::Value RPCServer::doRipple(const Json::Value ¶ms) // YYY Limit paths length and count. if (!asDst) { + Log(lsINFO) << "naDstAccountID: " << naDstAccountID.humanAccountID(); + return RPCError(rpcDST_ACT_MISSING); } @@ -2526,7 +2542,7 @@ Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params { "password_fund", &RPCServer::doPasswordFund, 2, 3, false, optCurrent }, { "password_set", &RPCServer::doPasswordSet, 2, 3, false, optNetwork }, { "peers", &RPCServer::doPeers, 0, 0, true }, - { "ripple", &RPCServer::doRipple, 10, -1, false, optCurrent|optClosed }, + { "ripple", &RPCServer::doRipple, 8, -1, false, optCurrent|optClosed }, { "ripple_lines_get", &RPCServer::doRippleLinesGet, 1, 2, false, optCurrent }, { "ripple_line_set", &RPCServer::doRippleLineSet, 4, 7, false, optCurrent }, { "send", &RPCServer::doSend, 3, 7, false, optCurrent }, From e825db5db98bb588f7ad2a41836fb7d4e600b627 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Sun, 19 Aug 2012 19:03:33 -0700 Subject: [PATCH 04/12] Don't report a failure if we got a fat root. --- src/SHAMapSync.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SHAMapSync.cpp b/src/SHAMapSync.cpp index ed76558906..ee3bb0e1d5 100644 --- a/src/SHAMapSync.cpp +++ b/src/SHAMapSync.cpp @@ -450,7 +450,7 @@ BOOST_AUTO_TEST_CASE( SHAMapSync_test ) Log(lsFATAL) << "GetNodeFat(root) fails"; BOOST_FAIL("GetNodeFat"); } - if (gotNodes.size() != 1) + if (gotNodes.size() < 1) { Log(lsFATAL) << "Didn't get root node " << gotNodes.size(); BOOST_FAIL("NodeSize"); From 84ee39b1474ec21009ddc3b6a1d5257f2734ba45 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Sun, 19 Aug 2012 19:04:18 -0700 Subject: [PATCH 05/12] Fix a few more cases where we create a new shared pointer just to immediately throw it away, resulting in a wasted allocate/increment/decrement/free. --- src/CanonicalTXSet.cpp | 2 +- src/CanonicalTXSet.h | 2 +- src/ConnectionPool.cpp | 11 ++++++----- src/ConnectionPool.h | 15 +++++---------- src/Ledger.cpp | 4 ++-- src/Ledger.h | 6 +++--- src/LedgerNode.cpp | 2 +- src/SHAMap.cpp | 4 ++-- src/SHAMap.h | 10 +++++----- src/SHAMapDiff.cpp | 2 +- src/SHAMapNodes.cpp | 4 ++-- src/Transaction.cpp | 4 ++-- src/Transaction.h | 4 ++-- 13 files changed, 33 insertions(+), 37 deletions(-) diff --git a/src/CanonicalTXSet.cpp b/src/CanonicalTXSet.cpp index c46c089374..e3af1e4870 100644 --- a/src/CanonicalTXSet.cpp +++ b/src/CanonicalTXSet.cpp @@ -37,7 +37,7 @@ bool CanonicalTXKey::operator>=(const CanonicalTXKey& key)const return mTXid >= key.mTXid; } -void CanonicalTXSet::push_back(SerializedTransaction::pointer txn) +void CanonicalTXSet::push_back(const SerializedTransaction::pointer& txn) { uint256 effectiveAccount = mSetHash; effectiveAccount ^= txn->getSourceAccount().getAccountID().to256(); diff --git a/src/CanonicalTXSet.h b/src/CanonicalTXSet.h index 6978859af7..3315625a3e 100644 --- a/src/CanonicalTXSet.h +++ b/src/CanonicalTXSet.h @@ -38,7 +38,7 @@ protected: public: CanonicalTXSet(const uint256& lclHash) : mSetHash(lclHash) { ; } - void push_back(SerializedTransaction::pointer txn); + void push_back(const SerializedTransaction::pointer& txn); iterator erase(const iterator& it); iterator begin() { return mMap.begin(); } diff --git a/src/ConnectionPool.cpp b/src/ConnectionPool.cpp index 3d79fbc2ad..14e5604841 100644 --- a/src/ConnectionPool.cpp +++ b/src/ConnectionPool.cpp @@ -226,7 +226,7 @@ void ConnectionPool::policyHandler(const boost::system::error_code& ecResult) // YYY: Should probably do this in the background. // YYY: Might end up sending to disconnected peer? -void ConnectionPool::relayMessage(Peer* fromPeer, PackedMessage::pointer msg) +void ConnectionPool::relayMessage(Peer* fromPeer, const PackedMessage::pointer& msg) { boost::mutex::scoped_lock sl(mPeerLock); @@ -339,7 +339,8 @@ std::vector ConnectionPool::getPeerVector() // Now know peer's node public key. Determine if we want to stay connected. // <-- bNew: false = redundant -bool ConnectionPool::peerConnected(Peer::pointer peer, const NewcoinAddress& naPeer, const std::string& strIP, int iPort) +bool ConnectionPool::peerConnected(const Peer::pointer& peer, const NewcoinAddress& naPeer, + const std::string& strIP, int iPort) { bool bNew = false; @@ -397,7 +398,7 @@ bool ConnectionPool::peerConnected(Peer::pointer peer, const NewcoinAddress& naP } // We maintain a map of public key to peer for connected and verified peers. Maintain it. -void ConnectionPool::peerDisconnected(Peer::pointer peer, const NewcoinAddress& naPeer) +void ConnectionPool::peerDisconnected(const Peer::pointer& peer, const NewcoinAddress& naPeer) { if (naPeer.isValid()) { @@ -484,7 +485,7 @@ bool ConnectionPool::peerScanSet(const std::string& strIp, int iPort) } // --> strIp: not empty -void ConnectionPool::peerClosed(Peer::pointer peer, const std::string& strIp, int iPort) +void ConnectionPool::peerClosed(const Peer::pointer& peer, const std::string& strIp, int iPort) { ipPort ipPeer = make_pair(strIp, iPort); bool bScanRefresh = false; @@ -539,7 +540,7 @@ void ConnectionPool::peerClosed(Peer::pointer peer, const std::string& strIp, in scanRefresh(); } -void ConnectionPool::peerVerified(Peer::pointer peer) +void ConnectionPool::peerVerified(const Peer::pointer& peer) { if (mScanning && mScanning == peer) { diff --git a/src/ConnectionPool.h b/src/ConnectionPool.h index c71c59fef6..b7983b751b 100644 --- a/src/ConnectionPool.h +++ b/src/ConnectionPool.h @@ -58,7 +58,7 @@ public: void start(); // Send message to network. - void relayMessage(Peer* fromPeer, PackedMessage::pointer msg); + void relayMessage(Peer* fromPeer, const PackedMessage::pointer& msg); // Manual connection request. // Queue for immediate scanning. @@ -72,16 +72,16 @@ public: // We know peers node public key. // <-- bool: false=reject - bool peerConnected(Peer::pointer peer, const NewcoinAddress& naPeer, const std::string& strIP, int iPort); + bool peerConnected(const Peer::pointer& peer, const NewcoinAddress& naPeer, const std::string& strIP, int iPort); // No longer connected. - void peerDisconnected(Peer::pointer peer, const NewcoinAddress& naPeer); + void peerDisconnected(const Peer::pointer& peer, const NewcoinAddress& naPeer); // As client accepted. - void peerVerified(Peer::pointer peer); + void peerVerified(const Peer::pointer& peer); // As client failed connect and be accepted. - void peerClosed(Peer::pointer peer, const std::string& strIp, int iPort); + void peerClosed(const Peer::pointer& peer, const std::string& strIp, int iPort); Json::Value getPeersJson(); std::vector getPeerVector(); @@ -98,11 +98,6 @@ public: void policyLowWater(); void policyEnforce(); -#if 0 - //std::vector > mBroadcastMessages; - - bool isMessageKnown(PackedMessage::pointer msg); -#endif }; extern void splitIpPort(const std::string& strIpPort, std::string& strIp, int& iPort); diff --git a/src/Ledger.cpp b/src/Ledger.cpp index 0cd6e2346d..7b150d69c7 100644 --- a/src/Ledger.cpp +++ b/src/Ledger.cpp @@ -210,7 +210,7 @@ RippleState::pointer Ledger::accessRippleState(const uint256& uNode) return boost::make_shared(sle); } -bool Ledger::addTransaction(Transaction::pointer trans) +bool Ledger::addTransaction(const Transaction::pointer& trans) { // low-level - just add to table assert(!mAccepted); assert(trans->getID().isNonZero()); @@ -257,7 +257,7 @@ uint256 Ledger::getHash() return(mHash); } -void Ledger::saveAcceptedLedger(Ledger::pointer ledger) +void Ledger::saveAcceptedLedger(const Ledger::pointer& ledger) { static boost::format ledgerExists("SELECT LedgerSeq FROM Ledgers where LedgerSeq = %d;"); static boost::format deleteLedger("DELETE FROM Ledgers WHERE LedgerSeq = %d;"); diff --git a/src/Ledger.h b/src/Ledger.h index 53dbe4dfbb..7f60fcbc8f 100644 --- a/src/Ledger.h +++ b/src/Ledger.h @@ -81,7 +81,7 @@ private: protected: - bool addTransaction(Transaction::pointer); + bool addTransaction(const Transaction::pointer&); bool addTransaction(const uint256& id, const Serializer& txn); static Ledger::pointer getSQL(const std::string& sqlStatement); @@ -156,12 +156,12 @@ public: // high-level functions AccountState::pointer getAccountState(const NewcoinAddress& acctID); - LedgerStateParms writeBack(LedgerStateParms parms, SLE::pointer); + LedgerStateParms writeBack(LedgerStateParms parms, const SLE::pointer&); SLE::pointer getAccountRoot(const uint160& accountID); SLE::pointer getAccountRoot(const NewcoinAddress& naAccountID); // database functions - static void saveAcceptedLedger(Ledger::pointer); + static void saveAcceptedLedger(const Ledger::pointer&); static Ledger::pointer loadByIndex(uint32 ledgerIndex); static Ledger::pointer loadByHash(const uint256& ledgerHash); diff --git a/src/LedgerNode.cpp b/src/LedgerNode.cpp index bbb4b7e969..24bfc58d77 100644 --- a/src/LedgerNode.cpp +++ b/src/LedgerNode.cpp @@ -8,7 +8,7 @@ // XXX Use shared locks where possible? -LedgerStateParms Ledger::writeBack(LedgerStateParms parms, SLE::pointer entry) +LedgerStateParms Ledger::writeBack(LedgerStateParms parms, const SLE::pointer& entry) { ScopedLock l(mAccountStateMap->Lock()); bool create = false; diff --git a/src/SHAMap.cpp b/src/SHAMap.cpp index b360908f2d..2a9b48520b 100644 --- a/src/SHAMap.cpp +++ b/src/SHAMap.cpp @@ -498,7 +498,7 @@ bool SHAMap::delItem(const uint256& id) return true; } -bool SHAMap::addGiveItem(SHAMapItem::pointer item, bool isTransaction, bool hasMeta) +bool SHAMap::addGiveItem(const SHAMapItem::pointer& item, bool isTransaction, bool hasMeta) { // add the specified item, does not update #ifdef ST_DEBUG std::cerr << "aGI " << item->getTag().GetHex() << std::endl; @@ -596,7 +596,7 @@ bool SHAMap::addItem(const SHAMapItem& i, bool isTransaction, bool hasMetaData) return addGiveItem(boost::make_shared(i), isTransaction, hasMetaData); } -bool SHAMap::updateGiveItem(SHAMapItem::pointer item, bool isTransaction, bool hasMeta) +bool SHAMap::updateGiveItem(const SHAMapItem::pointer& item, bool isTransaction, bool hasMeta) { // can't change the tag but can change the hash uint256 tag = item->getTag(); diff --git a/src/SHAMap.h b/src/SHAMap.h index 2f9e73d529..2e5c0ccbc8 100644 --- a/src/SHAMap.h +++ b/src/SHAMap.h @@ -160,7 +160,7 @@ private: public: SHAMapTreeNode(uint32 seq, const SHAMapNode& nodeID); // empty node SHAMapTreeNode(const SHAMapTreeNode& node, uint32 seq); // copy node from older tree - SHAMapTreeNode(const SHAMapNode& nodeID, SHAMapItem::pointer item, TNType type, uint32 seq); + SHAMapTreeNode(const SHAMapNode& nodeID, const SHAMapItem::pointer& item, TNType type, uint32 seq); // raw node functions SHAMapTreeNode(const SHAMapNode& id, const std::vector& data, uint32 seq, SHANodeFormat format); @@ -199,7 +199,7 @@ public: bool hasItem() const { return !!mItem; } SHAMapItem::pointer peekItem() { return mItem; } SHAMapItem::pointer getItem() const; - bool setItem(SHAMapItem::pointer& i, TNType type); + bool setItem(const SHAMapItem::pointer& i, TNType type); const uint256& getTag() const { return mItem->getTag(); } const std::vector& peekData() { return mItem->peekData(); } std::vector getData() const { return mItem->getData(); } @@ -311,8 +311,8 @@ public: uint256 getHash() { return root->getNodeHash(); } // save a copy if you have a temporary anyway - bool updateGiveItem(SHAMapItem::pointer, bool isTransaction, bool hasMeta); - bool addGiveItem(SHAMapItem::pointer, bool isTransaction, bool hasMeta); + bool updateGiveItem(const SHAMapItem::pointer&, bool isTransaction, bool hasMeta); + bool addGiveItem(const SHAMapItem::pointer&, bool isTransaction, bool hasMeta); // save a copy if you only need a temporary SHAMapItem::pointer peekItem(const uint256& id); @@ -345,7 +345,7 @@ public: // caution: otherMap must be accessed only by this function // return value: true=successfully completed, false=too different - bool compare(SHAMap::pointer otherMap, SHAMapDiff& differences, int maxCount); + bool compare(const SHAMap::pointer& otherMap, SHAMapDiff& differences, int maxCount); void armDirty(); int flushDirty(int maxNodes, HashedObjectType t, uint32 seq); diff --git a/src/SHAMapDiff.cpp b/src/SHAMapDiff.cpp index d1f3a32145..4bef1f73d1 100644 --- a/src/SHAMapDiff.cpp +++ b/src/SHAMapDiff.cpp @@ -91,7 +91,7 @@ bool SHAMap::walkBranch(SHAMapTreeNode* node, SHAMapItem::pointer otherMapItem, return true; } -bool SHAMap::compare(SHAMap::pointer otherMap, SHAMapDiff& differences, int maxCount) +bool SHAMap::compare(const SHAMap::pointer& otherMap, SHAMapDiff& differences, int maxCount) { // compare two hash trees, add up to maxCount differences to the difference table // return value: true=complete table of differences given, false=too many differences // throws on corrupt tables or missing nodes diff --git a/src/SHAMapNodes.cpp b/src/SHAMapNodes.cpp index 689745995c..144ccaf993 100644 --- a/src/SHAMapNodes.cpp +++ b/src/SHAMapNodes.cpp @@ -182,7 +182,7 @@ SHAMapTreeNode::SHAMapTreeNode(const SHAMapTreeNode& node, uint32 seq) : SHAMapN memcpy(mHashes, node.mHashes, sizeof(mHashes)); } -SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& node, SHAMapItem::pointer item, TNType type, uint32 seq) : +SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& node, const SHAMapItem::pointer& item, TNType type, uint32 seq) : SHAMapNode(node), mItem(item), mSeq(seq), mType(type), mFullBelow(true) { assert(item->peekData().size() >= 12); @@ -429,7 +429,7 @@ void SHAMapTreeNode::addRaw(Serializer& s, SHANodeFormat format) assert(false); } -bool SHAMapTreeNode::setItem(SHAMapItem::pointer& i, TNType type) +bool SHAMapTreeNode::setItem(const SHAMapItem::pointer& i, TNType type) { uint256 hash = getNodeHash(); mType = type; diff --git a/src/Transaction.cpp b/src/Transaction.cpp index 3f01d43f0f..bf692f6cff 100644 --- a/src/Transaction.cpp +++ b/src/Transaction.cpp @@ -13,7 +13,7 @@ #include "SerializedTransaction.h" #include "Log.h" -Transaction::Transaction(const SerializedTransaction::pointer sit, bool bValidate) +Transaction::Transaction(const SerializedTransaction::pointer& sit, bool bValidate) : mInLedger(0), mStatus(INVALID), mTransaction(sit) { try @@ -584,7 +584,7 @@ void Transaction::setStatus(TransStatus ts, uint32 lseq) mInLedger = lseq; } -void Transaction::saveTransaction(Transaction::pointer txn) +void Transaction::saveTransaction(const Transaction::pointer& txn) { txn->save(); } diff --git a/src/Transaction.h b/src/Transaction.h index 745dce6d93..15ae32dff5 100644 --- a/src/Transaction.h +++ b/src/Transaction.h @@ -126,7 +126,7 @@ private: const std::vector& vucSignature); public: - Transaction(const SerializedTransaction::pointer st, bool bValidate); + Transaction(const SerializedTransaction::pointer& st, bool bValidate); static Transaction::pointer sharedTransaction(const std::vector&vucTransaction, bool bValidate); @@ -288,7 +288,7 @@ public: void setLedger(uint32 ledger) { mInLedger = ledger; } // database functions - static void saveTransaction(Transaction::pointer); + static void saveTransaction(const Transaction::pointer&); bool save(); static Transaction::pointer load(const uint256& id); static Transaction::pointer findFrom(const NewcoinAddress& fromID, uint32 seq); From 420ee918774da63724fb5e1f08af7cc60e195afd Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Sun, 19 Aug 2012 19:23:10 -0700 Subject: [PATCH 06/12] Remove more wasteful allocate/increment/decrement/free cycles. --- src/AccountState.cpp | 3 ++- src/AccountState.h | 4 ++-- src/LedgerAcquire.cpp | 2 +- src/LedgerAcquire.h | 2 +- src/LedgerConsensus.cpp | 28 ++++++++++++++-------------- src/LedgerConsensus.h | 30 +++++++++++++++--------------- src/LedgerHistory.cpp | 3 ++- src/LedgerMaster.cpp | 10 +++++----- src/LedgerMaster.h | 14 +++++++------- src/NetworkOPs.cpp | 2 +- src/NetworkOPs.h | 2 +- 11 files changed, 51 insertions(+), 49 deletions(-) diff --git a/src/AccountState.cpp b/src/AccountState.cpp index 1f84c9dce9..e9804926c2 100644 --- a/src/AccountState.cpp +++ b/src/AccountState.cpp @@ -19,7 +19,8 @@ AccountState::AccountState(const NewcoinAddress& id) : mValid(false) mValid = true; } -AccountState::AccountState(SerializedLedgerEntry::pointer ledgerEntry) : mLedgerEntry(ledgerEntry), mValid(false) +AccountState::AccountState(const SerializedLedgerEntry::pointer& ledgerEntry) : + mLedgerEntry(ledgerEntry), mValid(false) { if (!mLedgerEntry) return; if (mLedgerEntry->getType() != ltACCOUNT_ROOT) return; diff --git a/src/AccountState.h b/src/AccountState.h index b2e5a0c95a..9069f375b0 100644 --- a/src/AccountState.h +++ b/src/AccountState.h @@ -27,8 +27,8 @@ private: bool mValid; public: - AccountState(const NewcoinAddress& AccountID); // For new accounts - AccountState(SerializedLedgerEntry::pointer ledgerEntry); // For accounts in a ledger + AccountState(const NewcoinAddress& AccountID); // For new accounts + AccountState(const SerializedLedgerEntry::pointer& ledgerEntry); // For accounts in a ledger bool bHaveAuthorizedKey() { diff --git a/src/LedgerAcquire.cpp b/src/LedgerAcquire.cpp index d2189e693f..949cc7e851 100644 --- a/src/LedgerAcquire.cpp +++ b/src/LedgerAcquire.cpp @@ -257,7 +257,7 @@ void LedgerAcquire::trigger(const Peer::pointer& peer, bool timer) resetTimer(); } -void PeerSet::sendRequest(const newcoin::TMGetLedger& tmGL, Peer::pointer peer) +void PeerSet::sendRequest(const newcoin::TMGetLedger& tmGL, const Peer::pointer& peer) { if (!peer) sendRequest(tmGL); diff --git a/src/LedgerAcquire.h b/src/LedgerAcquire.h index 3ea334bd10..ff92ad4ef8 100644 --- a/src/LedgerAcquire.h +++ b/src/LedgerAcquire.h @@ -31,7 +31,7 @@ protected: virtual ~PeerSet() { ; } void sendRequest(const newcoin::TMGetLedger& message); - void sendRequest(const newcoin::TMGetLedger& message, Peer::pointer peer); + void sendRequest(const newcoin::TMGetLedger& message, const Peer::pointer& peer); public: const uint256& getHash() const { return mHash; } diff --git a/src/LedgerConsensus.cpp b/src/LedgerConsensus.cpp index 2b45f3b8c4..52e4173c1c 100644 --- a/src/LedgerConsensus.cpp +++ b/src/LedgerConsensus.cpp @@ -83,7 +83,7 @@ void TransactionAcquire::trigger(const Peer::pointer& peer, bool timer) } bool TransactionAcquire::takeNodes(const std::list& nodeIDs, - const std::list< std::vector >& data, Peer::pointer peer) + const std::list< std::vector >& data, const Peer::pointer& peer) { if (mComplete) return true; @@ -191,7 +191,7 @@ bool LCTransaction::updatePosition(int percentTime, bool proposing) return true; } -LedgerConsensus::LedgerConsensus(const uint256& prevLCLHash, Ledger::pointer previousLedger, uint32 closeTime) +LedgerConsensus::LedgerConsensus(const uint256& prevLCLHash, const Ledger::pointer& previousLedger, uint32 closeTime) : mState(lcsPRE_CLOSE), mCloseTime(closeTime), mPrevLedgerHash(prevLCLHash), mPreviousLedger(previousLedger), mCurrentMSeconds(0), mClosePercent(0), mHaveCloseTimeConsensus(false) { @@ -297,7 +297,7 @@ void LedgerConsensus::takeInitialPosition(Ledger& initialLedger) propose(std::vector(), std::vector()); } -void LedgerConsensus::createDisputes(SHAMap::pointer m1, SHAMap::pointer m2) +void LedgerConsensus::createDisputes(const SHAMap::pointer& m1, const SHAMap::pointer& m2) { SHAMap::SHAMapDiff differences; m1->compare(m2, differences, 16384); @@ -317,7 +317,7 @@ void LedgerConsensus::createDisputes(SHAMap::pointer m1, SHAMap::pointer m2) } } -void LedgerConsensus::mapComplete(const uint256& hash, SHAMap::pointer map, bool acquired) +void LedgerConsensus::mapComplete(const uint256& hash, const SHAMap::pointer& map, bool acquired) { if (acquired) Log(lsINFO) << "We have acquired TXS " << hash.GetHex(); @@ -370,7 +370,7 @@ void LedgerConsensus::sendHaveTxSet(const uint256& hash, bool direct) theApp->getConnectionPool().relayMessage(NULL, packet); } -void LedgerConsensus::adjustCount(SHAMap::pointer map, const std::vector& peers) +void LedgerConsensus::adjustCount(const SHAMap::pointer& map, const std::vector& peers) { // Adjust the counts on all disputed transactions based on the set of peers taking this position for (boost::unordered_map::iterator it = mDisputes.begin(), end = mDisputes.end(); it != end; ++it) @@ -645,7 +645,7 @@ SHAMap::pointer LedgerConsensus::getTransactionTree(const uint256& hash, bool do return it->second; } -void LedgerConsensus::startAcquiring(TransactionAcquire::pointer acquire) +void LedgerConsensus::startAcquiring(const TransactionAcquire::pointer& acquire) { boost::unordered_map< uint256, std::vector< boost::weak_ptr > >::iterator it = mPeerData.find(acquire->getHash()); @@ -713,7 +713,7 @@ void LedgerConsensus::addDisputedTransaction(const uint256& txID, const std::vec } } -bool LedgerConsensus::peerPosition(LedgerProposal::pointer newPosition) +bool LedgerConsensus::peerPosition(const LedgerProposal::pointer& newPosition) { LedgerProposal::pointer& currentPosition = mPeerPositions[newPosition->getPeerID()]; @@ -746,7 +746,7 @@ bool LedgerConsensus::peerPosition(LedgerProposal::pointer newPosition) return true; } -bool LedgerConsensus::peerHasSet(Peer::pointer peer, const uint256& hashSet, newcoin::TxSetStatus status) +bool LedgerConsensus::peerHasSet(const Peer::pointer& peer, const uint256& hashSet, newcoin::TxSetStatus status) { if (status != newcoin::tsHAVE) // Indirect requests are for future support return true; @@ -763,7 +763,7 @@ bool LedgerConsensus::peerHasSet(Peer::pointer peer, const uint256& hashSet, new return true; } -bool LedgerConsensus::peerGaveNodes(Peer::pointer peer, const uint256& setHash, +bool LedgerConsensus::peerGaveNodes(const Peer::pointer& peer, const uint256& setHash, const std::list& nodeIDs, const std::list< std::vector >& nodeData) { boost::unordered_map::iterator acq = mAcquiring.find(setHash); @@ -791,8 +791,8 @@ void LedgerConsensus::Saccept(boost::shared_ptr This, SHAMap::p This->accept(txSet); } -void LedgerConsensus::applyTransaction(TransactionEngine& engine, SerializedTransaction::pointer txn, - Ledger::pointer ledger, CanonicalTXSet& failedTransactions, bool final) +void LedgerConsensus::applyTransaction(TransactionEngine& engine, const SerializedTransaction::pointer& txn, + const Ledger::pointer& ledger, CanonicalTXSet& failedTransactions, bool final) { TransactionEngineParams parms = final ? (tepNO_CHECK_FEE | tepUPDATE_TOTAL | tepMETADATA) : tepNONE; #ifndef TRUST_NETWORK @@ -824,8 +824,8 @@ void LedgerConsensus::applyTransaction(TransactionEngine& engine, SerializedTran #endif } -void LedgerConsensus::applyTransactions(SHAMap::pointer set, Ledger::pointer applyLedger, Ledger::pointer checkLedger, - CanonicalTXSet& failedTransactions, bool final) +void LedgerConsensus::applyTransactions(const SHAMap::pointer& set, const Ledger::pointer& applyLedger, + const Ledger::pointer& checkLedger, CanonicalTXSet& failedTransactions, bool final) { TransactionEngineParams parms = final ? (tepNO_CHECK_FEE | tepUPDATE_TOTAL) : tepNONE; TransactionEngine engine(applyLedger); @@ -881,7 +881,7 @@ void LedgerConsensus::applyTransactions(SHAMap::pointer set, Ledger::pointer app } while (successes > 0); } -void LedgerConsensus::accept(SHAMap::pointer set) +void LedgerConsensus::accept(const SHAMap::pointer& set) { assert(set->getHash() == mOurPosition->getCurrentHash()); diff --git a/src/LedgerConsensus.h b/src/LedgerConsensus.h index cadfb23acd..e95ed6328a 100644 --- a/src/LedgerConsensus.h +++ b/src/LedgerConsensus.h @@ -41,7 +41,7 @@ public: SHAMap::pointer getMap() { return mMap; } bool takeNodes(const std::list& IDs, const std::list< std::vector >& data, - Peer::pointer); + const Peer::pointer&); }; class LCTransaction @@ -113,24 +113,24 @@ protected: // final accept logic static void Saccept(boost::shared_ptr This, SHAMap::pointer txSet); - void accept(SHAMap::pointer txSet); + void accept(const SHAMap::pointer& txSet); - void weHave(const uint256& id, Peer::pointer avoidPeer); - void startAcquiring(TransactionAcquire::pointer); + void weHave(const uint256& id, const Peer::pointer& avoidPeer); + void startAcquiring(const TransactionAcquire::pointer&); SHAMap::pointer find(const uint256& hash); - void createDisputes(SHAMap::pointer, SHAMap::pointer); + void createDisputes(const SHAMap::pointer&, const SHAMap::pointer&); void addDisputedTransaction(const uint256&, const std::vector& transaction); - void adjustCount(SHAMap::pointer map, const std::vector& peers); + void adjustCount(const SHAMap::pointer& map, const std::vector& peers); void propose(const std::vector& addedTx, const std::vector& removedTx); void addPosition(LedgerProposal&, bool ours); void removePosition(LedgerProposal&, bool ours); void sendHaveTxSet(const uint256& set, bool direct); - void applyTransactions(SHAMap::pointer transactionSet, Ledger::pointer targetLedger, Ledger::pointer checkLedger, - CanonicalTXSet& failedTransactions, bool final); - void applyTransaction(TransactionEngine& engine, SerializedTransaction::pointer txn, Ledger::pointer targetLedger, - CanonicalTXSet& failedTransactions, bool final); + void applyTransactions(const SHAMap::pointer& transactionSet, const Ledger::pointer& targetLedger, + const Ledger::pointer& checkLedger, CanonicalTXSet& failedTransactions, bool final); + void applyTransaction(TransactionEngine& engine, const SerializedTransaction::pointer& txn, + const Ledger::pointer& targetLedger, CanonicalTXSet& failedTransactions, bool final); // manipulating our own position void statusChange(newcoin::NodeEvent, Ledger& ledger); @@ -141,7 +141,7 @@ protected: void endConsensus(); public: - LedgerConsensus(const uint256& prevLCLHash, Ledger::pointer previousLedger, uint32 closeTime); + LedgerConsensus(const uint256& prevLCLHash, const Ledger::pointer& previousLedger, uint32 closeTime); int startup(); Json::Value getJson(); @@ -151,7 +151,7 @@ public: SHAMap::pointer getTransactionTree(const uint256& hash, bool doAcquire); TransactionAcquire::pointer getAcquiring(const uint256& hash); - void mapComplete(const uint256& hash, SHAMap::pointer map, bool acquired); + void mapComplete(const uint256& hash, const SHAMap::pointer& map, bool acquired); void checkLCL(); void timerEntry(); @@ -165,11 +165,11 @@ public: bool haveConsensus(); - bool peerPosition(LedgerProposal::pointer); + bool peerPosition(const LedgerProposal::pointer&); - bool peerHasSet(Peer::pointer peer, const uint256& set, newcoin::TxSetStatus status); + bool peerHasSet(const Peer::pointer& peer, const uint256& set, newcoin::TxSetStatus status); - bool peerGaveNodes(Peer::pointer peer, const uint256& setHash, + bool peerGaveNodes(const Peer::pointer& peer, const uint256& setHash, const std::list& nodeIDs, const std::list< std::vector >& nodeData); }; diff --git a/src/LedgerHistory.cpp b/src/LedgerHistory.cpp index 0445b268d5..6dd3a9c4a3 100644 --- a/src/LedgerHistory.cpp +++ b/src/LedgerHistory.cpp @@ -90,7 +90,8 @@ Ledger::pointer LedgerHistory::canonicalizeLedger(Ledger::pointer ledger, bool s if (!save) { // return input ledger if not in map, otherwise, return corresponding map ledger Ledger::pointer ret = mLedgersByHash.fetch(h); - if (ret) return ret; + if (ret) + return ret; return ledger; } diff --git a/src/LedgerMaster.cpp b/src/LedgerMaster.cpp index 7350b85349..e7b571f361 100644 --- a/src/LedgerMaster.cpp +++ b/src/LedgerMaster.cpp @@ -13,13 +13,13 @@ uint32 LedgerMaster::getCurrentLedgerIndex() return mCurrentLedger->getLedgerSeq(); } -bool LedgerMaster::addHeldTransaction(Transaction::pointer transaction) +bool LedgerMaster::addHeldTransaction(const Transaction::pointer& transaction) { // returns true if transaction was added boost::recursive_mutex::scoped_lock ml(mLock); return mHeldTransactionsByID.insert(std::make_pair(transaction->getID(), transaction)).second; } -void LedgerMaster::pushLedger(Ledger::pointer newLedger) +void LedgerMaster::pushLedger(const Ledger::pointer& newLedger) { // Caller should already have properly assembled this ledger into "ready-to-close" form -- // all candidate transactions must already be appled @@ -35,7 +35,7 @@ void LedgerMaster::pushLedger(Ledger::pointer newLedger) mEngine.setLedger(newLedger); } -void LedgerMaster::pushLedger(Ledger::pointer newLCL, Ledger::pointer newOL) +void LedgerMaster::pushLedger(const Ledger::pointer& newLCL, const Ledger::pointer& newOL) { assert(newLCL->isClosed() && newLCL->isAccepted()); assert(!newOL->isClosed() && !newOL->isAccepted()); @@ -54,7 +54,7 @@ void LedgerMaster::pushLedger(Ledger::pointer newLCL, Ledger::pointer newOL) mEngine.setLedger(newOL); } -void LedgerMaster::switchLedgers(Ledger::pointer lastClosed, Ledger::pointer current) +void LedgerMaster::switchLedgers(const Ledger::pointer& lastClosed, const Ledger::pointer& current) { assert(lastClosed && current); mFinalizedLedger = lastClosed; @@ -66,7 +66,7 @@ void LedgerMaster::switchLedgers(Ledger::pointer lastClosed, Ledger::pointer cur mEngine.setLedger(mCurrentLedger); } -void LedgerMaster::storeLedger(Ledger::pointer ledger) +void LedgerMaster::storeLedger(const Ledger::pointer& ledger) { mLedgerHistory.addLedger(ledger); } diff --git a/src/LedgerMaster.h b/src/LedgerMaster.h index 187aaeec13..dd51333283 100644 --- a/src/LedgerMaster.h +++ b/src/LedgerMaster.h @@ -26,8 +26,8 @@ class LedgerMaster std::map mHeldTransactionsByID; void applyFutureTransactions(uint32 ledgerIndex); - bool isValidTransaction(Transaction::pointer trans); - bool isTransactionOnFutureList(Transaction::pointer trans); + bool isValidTransaction(const Transaction::pointer& trans); + bool isTransactionOnFutureList(const Transaction::pointer& trans); public: @@ -48,11 +48,11 @@ public: TransactionEngineResult doTransaction(const SerializedTransaction& txn, uint32 targetLedger, TransactionEngineParams params); - void pushLedger(Ledger::pointer newLedger); - void pushLedger(Ledger::pointer newLCL, Ledger::pointer newOL); - void storeLedger(Ledger::pointer); + void pushLedger(const Ledger::pointer& newLedger); + void pushLedger(const Ledger::pointer& newLCL, const Ledger::pointer& newOL); + void storeLedger(const Ledger::pointer&); - void switchLedgers(Ledger::pointer lastClosed, Ledger::pointer newCurrent); + void switchLedgers(const Ledger::pointer& lastClosed, const Ledger::pointer& newCurrent); Ledger::pointer closeLedger(); @@ -74,7 +74,7 @@ public: return mLedgerHistory.getLedgerByHash(hash); } - bool addHeldTransaction(Transaction::pointer trans); + bool addHeldTransaction(const Transaction::pointer& trans); }; #endif diff --git a/src/NetworkOPs.cpp b/src/NetworkOPs.cpp index a0e7811425..4d3fd7aee2 100644 --- a/src/NetworkOPs.cpp +++ b/src/NetworkOPs.cpp @@ -52,7 +52,7 @@ uint32 NetworkOPs::getCurrentLedgerID() } // Sterilize transaction through serialization. -Transaction::pointer NetworkOPs::submitTransaction(Transaction::pointer tpTrans) +Transaction::pointer NetworkOPs::submitTransaction(const Transaction::pointer& tpTrans) { Serializer s; diff --git a/src/NetworkOPs.h b/src/NetworkOPs.h index 52e1329f8d..79dc6ae138 100644 --- a/src/NetworkOPs.h +++ b/src/NetworkOPs.h @@ -108,7 +108,7 @@ public: // // Transaction operations // - Transaction::pointer submitTransaction(Transaction::pointer tpTrans); + Transaction::pointer submitTransaction(const Transaction::pointer& tpTrans); Transaction::pointer processTransaction(Transaction::pointer transaction, uint32 targetLedger = 0, Peer* source = NULL); From c036188c3cb8fe3cc318d4e4258d056512fd2a1d Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Sun, 19 Aug 2012 21:01:36 -0700 Subject: [PATCH 07/12] Some more cleanups. --- src/Ledger.h | 6 ------ src/NetworkOPs.cpp | 8 ++++---- src/NetworkOPs.h | 8 ++++---- src/PubKeyCache.cpp | 12 ++++++------ src/PubKeyCache.h | 2 +- src/TransactionEngine.h | 4 ++-- 6 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/Ledger.h b/src/Ledger.h index 7f60fcbc8f..53b7980794 100644 --- a/src/Ledger.h +++ b/src/Ledger.h @@ -281,12 +281,6 @@ public: SLE::pointer getRippleState(const uint160& uiA, const uint160& uiB, const uint160& uCurrency) { return getRippleState(getRippleStateIndex(NewcoinAddress::createAccountID(uiA), NewcoinAddress::createAccountID(uiB), uCurrency)); } - // - // Misc - // - bool isCompatible(boost::shared_ptr other); -// bool signLedger(std::vector &signature, const LocalHanko &hanko); - void addJson(Json::Value&, int options); static bool unitTest(); diff --git a/src/NetworkOPs.cpp b/src/NetworkOPs.cpp index 4d3fd7aee2..75b12a813b 100644 --- a/src/NetworkOPs.cpp +++ b/src/NetworkOPs.cpp @@ -650,7 +650,7 @@ SHAMap::pointer NetworkOPs::getTXMap(const uint256& hash) return mConsensus->getTransactionTree(hash, false); } -bool NetworkOPs::gotTXData(boost::shared_ptr peer, const uint256& hash, +bool NetworkOPs::gotTXData(const boost::shared_ptr& peer, const uint256& hash, const std::list& nodeIDs, const std::list< std::vector >& nodeData) { if (!mConsensus) @@ -658,14 +658,14 @@ bool NetworkOPs::gotTXData(boost::shared_ptr peer, const uint256& hash, return mConsensus->peerGaveNodes(peer, hash, nodeIDs, nodeData); } -bool NetworkOPs::hasTXSet(boost::shared_ptr peer, const uint256& set, newcoin::TxSetStatus status) +bool NetworkOPs::hasTXSet(const boost::shared_ptr& peer, const uint256& set, newcoin::TxSetStatus status) { if (!mConsensus) return false; return mConsensus->peerHasSet(peer, set, status); } -void NetworkOPs::mapComplete(const uint256& hash, SHAMap::pointer map) +void NetworkOPs::mapComplete(const uint256& hash, const SHAMap::pointer& map) { if (mConsensus) mConsensus->mapComplete(hash, map, true); @@ -746,7 +746,7 @@ std::vector return accounts; } -bool NetworkOPs::recvValidation(SerializedValidation::pointer val) +bool NetworkOPs::recvValidation(const SerializedValidation::pointer& val) { Log(lsINFO) << "recvValidation " << val->getLedgerHash().GetHex(); return theApp->getValidations().addValidation(val); diff --git a/src/NetworkOPs.h b/src/NetworkOPs.h index 79dc6ae138..91ac722a05 100644 --- a/src/NetworkOPs.h +++ b/src/NetworkOPs.h @@ -161,12 +161,12 @@ public: // ledger proposal/close functions bool recvPropose(uint32 proposeSeq, const uint256& proposeHash, uint32 closeTime, const std::string& pubKey, const std::string& signature); - bool gotTXData(boost::shared_ptr peer, const uint256& hash, + bool gotTXData(const boost::shared_ptr& peer, const uint256& hash, const std::list& nodeIDs, const std::list< std::vector >& nodeData); - bool recvValidation(SerializedValidation::pointer val); + bool recvValidation(const SerializedValidation::pointer& val); SHAMap::pointer getTXMap(const uint256& hash); - bool hasTXSet(boost::shared_ptr peer, const uint256& set, newcoin::TxSetStatus status); - void mapComplete(const uint256& hash, SHAMap::pointer map); + bool hasTXSet(const boost::shared_ptr& peer, const uint256& set, newcoin::TxSetStatus status); + void mapComplete(const uint256& hash, const SHAMap::pointer& map); // network state machine void checkState(const boost::system::error_code& result); diff --git a/src/PubKeyCache.cpp b/src/PubKeyCache.cpp index f6a4096d38..503fefc3d1 100644 --- a/src/PubKeyCache.cpp +++ b/src/PubKeyCache.cpp @@ -42,7 +42,7 @@ CKey::pointer PubKeyCache::locate(const NewcoinAddress& id) return ckp; } -CKey::pointer PubKeyCache::store(const NewcoinAddress& id, CKey::pointer key) +CKey::pointer PubKeyCache::store(const NewcoinAddress& id, const CKey::pointer& key) { // stored if needed, returns cached copy (possibly the original) { boost::mutex::scoped_lock sl(mLock); @@ -51,14 +51,14 @@ CKey::pointer PubKeyCache::store(const NewcoinAddress& id, CKey::pointer key) return pit.first->second; } - std::vector pk=key->GetPubKey(); + std::vector pk = key->GetPubKey(); std::string encodedPK; theApp->getTxnDB()->getDB()->escape(&(pk.front()), pk.size(), encodedPK); - std::string sql="INSERT INTO PubKeys (ID,PubKey) VALUES ('"; - sql+=id.humanAccountID(); - sql+="',"; - sql+=encodedPK; + std::string sql = "INSERT INTO PubKeys (ID,PubKey) VALUES ('"; + sql += id.humanAccountID(); + sql += "',"; + sql += encodedPK; sql.append(");"); ScopedLock dbl(theApp->getTxnDB()->getDBLock()); diff --git a/src/PubKeyCache.h b/src/PubKeyCache.h index bf6995875c..69c19b2be6 100644 --- a/src/PubKeyCache.h +++ b/src/PubKeyCache.h @@ -18,7 +18,7 @@ public: PubKeyCache() { ; } CKey::pointer locate(const NewcoinAddress& id); - CKey::pointer store(const NewcoinAddress& id, CKey::pointer key); + CKey::pointer store(const NewcoinAddress& id, const CKey::pointer& key); void clear(); }; diff --git a/src/TransactionEngine.h b/src/TransactionEngine.h index 5df286d743..1960bde680 100644 --- a/src/TransactionEngine.h +++ b/src/TransactionEngine.h @@ -268,10 +268,10 @@ protected: public: TransactionEngine() { ; } - TransactionEngine(Ledger::pointer ledger) : mLedger(ledger) { ; } + TransactionEngine(const Ledger::pointer& ledger) : mLedger(ledger) { ; } Ledger::pointer getLedger() { return mLedger; } - void setLedger(Ledger::pointer ledger) { assert(ledger); mLedger = ledger; } + void setLedger(const Ledger::pointer& ledger) { assert(ledger); mLedger = ledger; } TransactionEngineResult applyTransaction(const SerializedTransaction&, TransactionEngineParams); }; From 7e30db94b4a9e37d5910938aeca9245d86edad2b Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Sun, 19 Aug 2012 21:36:25 -0700 Subject: [PATCH 08/12] Work on ripple paths. --- src/SerializedTypes.cpp | 13 ++++++++++--- src/TransactionEngine.cpp | 27 ++++++++++++++++++--------- src/TransactionEngine.h | 6 +++++- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/SerializedTypes.cpp b/src/SerializedTypes.cpp index cd759e1ee2..6e50c61fdb 100644 --- a/src/SerializedTypes.cpp +++ b/src/SerializedTypes.cpp @@ -5,6 +5,7 @@ #include "SerializedTypes.h" #include "SerializedObject.h" #include "TransactionFormats.h" +#include "Log.h" #include "NewcoinAddress.h" #include "utils.h" @@ -308,7 +309,11 @@ STPathSet* STPathSet::construct(SerializerIterator& s, const char *name) if (iType == STPathElement::typeEnd || iType == STPathElement::typeBoundary) { if (path.empty()) + { + Log(lsINFO) << "STPathSet: Empty path."; + throw std::runtime_error("empty path"); + } paths.push_back(path); path.clear(); @@ -320,13 +325,15 @@ STPathSet* STPathSet::construct(SerializerIterator& s, const char *name) } else if (iType & ~STPathElement::typeValidBits) { + Log(lsINFO) << "STPathSet: Bad path element: " << iType; + throw std::runtime_error("bad path element"); } else { - bool bAccount = !!(iType & STPathElement::typeAccount); - bool bCurrency = !!(iType & STPathElement::typeCurrency); - bool bIssuer = !!(iType & STPathElement::typeIssuer); + const bool bAccount = !!(iType & STPathElement::typeAccount); + const bool bCurrency = !!(iType & STPathElement::typeCurrency); + const bool bIssuer = !!(iType & STPathElement::typeIssuer); uint160 uAccountID; uint160 uCurrency; diff --git a/src/TransactionEngine.cpp b/src/TransactionEngine.cpp index af7f9a53a2..c322b289de 100644 --- a/src/TransactionEngine.cpp +++ b/src/TransactionEngine.cpp @@ -1969,14 +1969,14 @@ bool TransactionEngine::calcNodeOfferRev( if (!saCurOfrFunds) { // Offer is unfunded. - Log(lsINFO) << "calcNodeOffer: encountered unfunded offer"; + Log(lsINFO) << "calcNodeOfferRev: encountered unfunded offer"; // XXX Mark unfunded. } else if (sleCurOfr->getIFieldPresent(sfExpiration) && sleCurOfr->getIFieldU32(sfExpiration) <= mLedger->getParentCloseTimeNC()) { // Offer is expired. - Log(lsINFO) << "calcNodeOffer: encountered expired offer"; + Log(lsINFO) << "calcNodeOfferRev: encountered expired offer"; // XXX Mark unfunded. } @@ -3774,8 +3774,10 @@ TransactionEngineResult TransactionEngine::doPayment(const SerializedTransaction if (!bNoRippleDirect) { // Direct path. + // XXX Might also make a stamp bridge by default. Log(lsINFO) << "doPayment: Build direct:"; - vpsPaths.push_back(PathState::createPathState( + + PathState::pointer pspDirect = PathState::createPathState( mLedger, vpsPaths.size(), mNodes, @@ -3784,14 +3786,19 @@ TransactionEngineResult TransactionEngine::doPayment(const SerializedTransaction mTxnAccountID, saDstAmount, saMaxAmount, - bPartialPayment - )); + bPartialPayment); + + if (pspDirect) + vpsPaths.push_back(pspDirect); } + Log(lsINFO) << "doPayment: Paths: " << spsPaths.getPathCount(); + BOOST_FOREACH(const STPath& spPath, spsPaths) { Log(lsINFO) << "doPayment: Build path:"; - vpsPaths.push_back(PathState::createPathState( + + PathState::pointer pspExpanded = PathState::createPathState( mLedger, vpsPaths.size(), mNodes, @@ -3800,8 +3807,10 @@ TransactionEngineResult TransactionEngine::doPayment(const SerializedTransaction mTxnAccountID, saDstAmount, saMaxAmount, - bPartialPayment - )); + bPartialPayment); + + if (pspExpanded) + vpsPaths.push_back(pspExpanded); } TransactionEngineResult terResult; @@ -3885,7 +3894,7 @@ TransactionEngineResult TransactionEngine::doWalletAdd(const SerializedTransacti if (!naMasterPubKey.accountPublicVerify(Serializer::getSHA512Half(uAuthKeyID.begin(), uAuthKeyID.size()), vucSignature)) { - std::cerr << "WalletAdd: unauthorized: bad signature " << std::endl; + std::cerr << "WalletAdd: unauthorized: bad signature " << std::endl; return tenBAD_ADD_AUTH; } diff --git a/src/TransactionEngine.h b/src/TransactionEngine.h index 5df286d743..ecc1a4a722 100644 --- a/src/TransactionEngine.h +++ b/src/TransactionEngine.h @@ -169,7 +169,11 @@ public: STAmount saSendMax, bool bPartialPayment ) - { return boost::make_shared(lpLedger, iIndex, lesSource, spSourcePath, uReceiverID, uSenderID, saSend, saSendMax, bPartialPayment); }; + { + PathState::pointer pspNew = boost::make_shared(lpLedger, iIndex, lesSource, spSourcePath, uReceiverID, uSenderID, saSend, saSendMax, bPartialPayment); + + return pspNew && pspNew->bValid ? pspNew : PathState::pointer(); + } static bool lessPriority(const PathState::pointer& lhs, const PathState::pointer& rhs); }; From a251a1ae4e2d1ecfeecb016c125dece497e2e78d Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Sun, 19 Aug 2012 22:20:58 -0700 Subject: [PATCH 09/12] Fix STPathSet deserialization. --- src/SerializedTypes.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/SerializedTypes.cpp b/src/SerializedTypes.cpp index 6e50c61fdb..2a6b0f978e 100644 --- a/src/SerializedTypes.cpp +++ b/src/SerializedTypes.cpp @@ -332,6 +332,8 @@ STPathSet* STPathSet::construct(SerializerIterator& s, const char *name) else { const bool bAccount = !!(iType & STPathElement::typeAccount); + const bool bRedeem = !!(iType & STPathElement::typeRedeem); + const bool bIssue = !!(iType & STPathElement::typeIssue); const bool bCurrency = !!(iType & STPathElement::typeCurrency); const bool bIssuer = !!(iType & STPathElement::typeIssuer); @@ -348,7 +350,7 @@ STPathSet* STPathSet::construct(SerializerIterator& s, const char *name) if (bIssuer) uIssuerID = s.get160(); - path.push_back(STPathElement(uAccountID, uCurrency, uIssuerID)); + path.push_back(STPathElement(uAccountID, uCurrency, uIssuerID, bRedeem, bIssue)); } } while(1); } @@ -361,6 +363,8 @@ bool STPathSet::isEquivalent(const SerializedType& t) const int STPathSet::getLength() const { + // XXX This code is broken? + assert(false); int ret = 0; for (std::vector::const_iterator it = value.begin(), end = value.end(); it != end; ++it) From 6f5eb015bfe6a165ea2609e3d1f0002827f2362d Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Sun, 19 Aug 2012 22:41:30 -0700 Subject: [PATCH 10/12] Fix the bug causing 'Paths' not to have a name. The implicit 'operator=' function obliterated the name. --- src/SerializedTypes.cpp | 8 ++++++++ src/SerializedTypes.h | 1 + 2 files changed, 9 insertions(+) diff --git a/src/SerializedTypes.cpp b/src/SerializedTypes.cpp index 2a6b0f978e..da96fa5373 100644 --- a/src/SerializedTypes.cpp +++ b/src/SerializedTypes.cpp @@ -463,6 +463,14 @@ std::string STPathSet::getText() const } #endif +STPathSet& STPathSet::operator=(const STPathSet& p) +{ + if (name == NULL) + name = p.name; + value = p.value; + return *this; +} + void STPathSet::add(Serializer& s) const { bool bFirst = true; diff --git a/src/SerializedTypes.h b/src/SerializedTypes.h index 1ba0793ad3..7b7aa562b9 100644 --- a/src/SerializedTypes.h +++ b/src/SerializedTypes.h @@ -668,6 +668,7 @@ public: void addPath(const STPath& e) { value.push_back(e); } virtual bool isEquivalent(const SerializedType& t) const; + STPathSet& operator=(const STPathSet&); std::vector::iterator begin() { return value.begin(); } std::vector::iterator end() { return value.end(); } From aa1f923306ef7699c474691d76bf5e5e22109a94 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Sun, 19 Aug 2012 22:47:59 -0700 Subject: [PATCH 11/12] A better fix so that every type doesn't have to have its own operator=. This fixes it in one place and allows many such helpers to be removed. --- src/Amount.cpp | 12 ------------ src/SerializedTypes.cpp | 8 -------- src/SerializedTypes.h | 13 ++----------- 3 files changed, 2 insertions(+), 31 deletions(-) diff --git a/src/Amount.cpp b/src/Amount.cpp index e6616a9c35..966eea15b6 100644 --- a/src/Amount.cpp +++ b/src/Amount.cpp @@ -491,18 +491,6 @@ STAmount STAmount::operator-(void) const return STAmount(name, mCurrency, mValue, mOffset, mIsNative, !mIsNegative); } -STAmount& STAmount::operator=(const STAmount& a) -{ - mValue = a.mValue; - mOffset = a.mOffset; - mIssuer = a.mIssuer; - mCurrency = a.mCurrency; - mIsNative = a.mIsNative; - mIsNegative = a.mIsNegative; - - return *this; -} - STAmount& STAmount::operator=(uint64 v) { // does not copy name, does not change currency type mOffset = 0; diff --git a/src/SerializedTypes.cpp b/src/SerializedTypes.cpp index da96fa5373..2a6b0f978e 100644 --- a/src/SerializedTypes.cpp +++ b/src/SerializedTypes.cpp @@ -463,14 +463,6 @@ std::string STPathSet::getText() const } #endif -STPathSet& STPathSet::operator=(const STPathSet& p) -{ - if (name == NULL) - name = p.name; - value = p.value; - return *this; -} - void STPathSet::add(Serializer& s) const { bool bFirst = true; diff --git a/src/SerializedTypes.h b/src/SerializedTypes.h index 7b7aa562b9..2c877b8bd1 100644 --- a/src/SerializedTypes.h +++ b/src/SerializedTypes.h @@ -91,6 +91,8 @@ public: virtual bool isEquivalent(const SerializedType& t) const { assert(getSType() == STI_NOTPRESENT); return t.getSType() == STI_NOTPRESENT; } + SerializedType& operator=(const SerializedType& t) + { name = (name == NULL) ? t.name : name; return *this; } bool operator==(const SerializedType& t) const { return (getSType() == t.getSType()) && isEquivalent(t); } bool operator!=(const SerializedType& t) const @@ -124,7 +126,6 @@ public: void setValue(unsigned char v) { value=v; } operator unsigned char() const { return value; } - STUInt8& operator=(unsigned char v) { value=v; return *this; } virtual bool isEquivalent(const SerializedType& t) const; }; @@ -152,7 +153,6 @@ public: void setValue(uint16 v) { value=v; } operator uint16() const { return value; } - STUInt16& operator=(uint16 v) { value=v; return *this; } virtual bool isEquivalent(const SerializedType& t) const; }; @@ -180,7 +180,6 @@ public: void setValue(uint32 v) { value=v; } operator uint32() const { return value; } - STUInt32& operator=(uint32 v) { value=v; return *this; } virtual bool isEquivalent(const SerializedType& t) const; }; @@ -208,7 +207,6 @@ public: void setValue(uint64 v) { value=v; } operator uint64() const { return value; } - STUInt64& operator=(uint64 v) { value=v; return *this; } virtual bool isEquivalent(const SerializedType& t) const; }; @@ -334,7 +332,6 @@ public: STAmount& operator+=(const STAmount&); STAmount& operator-=(const STAmount&); - STAmount& operator=(const STAmount&); STAmount& operator+=(uint64); STAmount& operator-=(uint64); STAmount& operator=(uint64); @@ -401,7 +398,6 @@ public: void setValue(const uint128& v) { value=v; } operator uint128() const { return value; } - STHash128& operator=(const uint128& v) { value=v; return *this; } virtual bool isEquivalent(const SerializedType& t) const; }; @@ -431,7 +427,6 @@ public: void setValue(const uint160& v) { value=v; } operator uint160() const { return value; } - STHash160& operator=(const uint160& v) { value=v; return *this; } virtual bool isEquivalent(const SerializedType& t) const; }; @@ -461,7 +456,6 @@ public: void setValue(const uint256& v) { value=v; } operator uint256() const { return value; } - STHash256& operator=(const uint256& v) { value=v; return *this; } virtual bool isEquivalent(const SerializedType& t) const; }; @@ -494,7 +488,6 @@ public: void setValue(const std::vector& v) { value=v; } operator std::vector() const { return value; } - STVariableLength& operator=(const std::vector& v) { value=v; return *this; } virtual bool isEquivalent(const SerializedType& t) const; }; @@ -668,7 +661,6 @@ public: void addPath(const STPath& e) { value.push_back(e); } virtual bool isEquivalent(const SerializedType& t) const; - STPathSet& operator=(const STPathSet&); std::vector::iterator begin() { return value.begin(); } std::vector::iterator end() { return value.end(); } @@ -747,7 +739,6 @@ public: void addItem(const TaggedListItem& v) { value.push_back(v); } operator std::vector() const { return value; } - STTaggedList& operator=(const std::vector& v) { value=v; return *this; } virtual bool isEquivalent(const SerializedType& t) const; }; From 532db8be357c881b3627dec36a9d39bd60cc007b Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Sun, 19 Aug 2012 22:52:14 -0700 Subject: [PATCH 12/12] assert if the sanitized transaction differs materially from the submitted transaction. --- src/NetworkOPs.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/NetworkOPs.cpp b/src/NetworkOPs.cpp index 75b12a813b..adc8a3c7b9 100644 --- a/src/NetworkOPs.cpp +++ b/src/NetworkOPs.cpp @@ -65,6 +65,7 @@ Transaction::pointer NetworkOPs::submitTransaction(const Transaction::pointer& t Transaction::pointer tpTransNew = Transaction::sharedTransaction(s.getData(), true); assert(tpTransNew); + assert(tpTransNew->getSTransaction()->isEquivalent(*tpTrans->getSTransaction())); (void) NetworkOPs::processTransaction(tpTransNew);