diff --git a/src/ripple/app/tx/impl/CancelOffer.cpp b/src/ripple/app/tx/impl/CancelOffer.cpp index fe9626310f..40430445d0 100644 --- a/src/ripple/app/tx/impl/CancelOffer.cpp +++ b/src/ripple/app/tx/impl/CancelOffer.cpp @@ -54,14 +54,16 @@ CancelOffer::doApply () { std::uint32_t const uOfferSequence = mTxn.getFieldU32 (sfOfferSequence); - if (mTxnAccount->getFieldU32 (sfSequence) - 1 <= uOfferSequence) + auto const sle = view().read( + keylet::account(account_)); + if (sle->getFieldU32 (sfSequence) - 1 <= uOfferSequence) { j_.trace << "Malformed transaction: " << "Sequence " << uOfferSequence << " is invalid."; return temBAD_SEQUENCE; } - uint256 const offerIndex (getOfferIndex (mTxnAccountID, uOfferSequence)); + uint256 const offerIndex (getOfferIndex (account_, uOfferSequence)); auto sleOffer = view().peek ( keylet::offer(offerIndex)); diff --git a/src/ripple/app/tx/impl/CancelTicket.cpp b/src/ripple/app/tx/impl/CancelTicket.cpp index e7b52f3a12..8904cc8f70 100644 --- a/src/ripple/app/tx/impl/CancelTicket.cpp +++ b/src/ripple/app/tx/impl/CancelTicket.cpp @@ -37,8 +37,6 @@ CancelTicket::preCheck() TER CancelTicket::doApply () { - assert (mTxnAccount); - uint256 const ticketId = mTxn.getFieldH256 (sfTicketID); // VFALCO This is highly suspicious, we're requiring that the @@ -52,11 +50,11 @@ CancelTicket::doApply () sleTicket->getAccountID (sfAccount); bool authorized = - mTxnAccountID == ticket_owner; + account_ == ticket_owner; // The target can also always remove a ticket if (!authorized && sleTicket->isFieldPresent (sfTarget)) - authorized = (mTxnAccountID == sleTicket->getAccountID (sfTarget)); + authorized = (account_ == sleTicket->getAccountID (sfTarget)); // And finally, anyone can remove an expired ticket if (!authorized && sleTicket->isFieldPresent (sfExpiration)) diff --git a/src/ripple/app/tx/impl/Change.cpp b/src/ripple/app/tx/impl/Change.cpp index 6c7e8772af..bdf20b2af9 100644 --- a/src/ripple/app/tx/impl/Change.cpp +++ b/src/ripple/app/tx/impl/Change.cpp @@ -84,9 +84,9 @@ Change::payFee() TER Change::preCheck() { - mTxnAccountID = mTxn.getAccountID(sfAccount); + account_ = mTxn.getAccountID(sfAccount); - if (mTxnAccountID.isNonZero ()) + if (account_.isNonZero ()) { j_.warning << "Bad source id"; return temBAD_SRC_ACCOUNT; diff --git a/src/ripple/app/tx/impl/CreateOffer.cpp b/src/ripple/app/tx/impl/CreateOffer.cpp index 3c34b78c39..164c34d858 100644 --- a/src/ripple/app/tx/impl/CreateOffer.cpp +++ b/src/ripple/app/tx/impl/CreateOffer.cpp @@ -55,7 +55,7 @@ CreateOffer::checkAcceptAsset(IssueRef issue) const if (issuerAccount->getFieldU32 (sfFlags) & lsfRequireAuth) { auto const trustLine = ctx_.view().read( - keylet::line(mTxnAccountID, issue.account, issue.currency)); + keylet::line(account_, issue.account, issue.currency)); if (!trustLine) { @@ -67,7 +67,7 @@ CreateOffer::checkAcceptAsset(IssueRef issue) const // Entries have a canonical representation, determined by a // lexicographical "greater than" comparison employing strict weak // ordering. Determine which entry we need to access. - bool const canonical_gt (mTxnAccountID > issue.account); + bool const canonical_gt (account_ > issue.account); bool const is_authorized (trustLine->getFieldU32 (sfFlags) & (canonical_gt ? lsfLowAuth : lsfHighAuth)); @@ -386,7 +386,7 @@ CreateOffer::cross ( beast::WrappedSink takerSink (j_, "Taker "); - Taker taker (cross_type_, view, mTxnAccountID, taker_amount, + Taker taker (cross_type_, view, account_, taker_amount, mTxn.getFlags(), ctx_.config, beast::Journal (takerSink)); try @@ -555,7 +555,10 @@ CreateOffer::applyGuts (View& view, View& view_cancel) // sequence to determine the transaction. Why is the offer sequence // number insufficient? - std::uint32_t const uAccountSequenceNext = mTxnAccount->getFieldU32 (sfSequence); + auto const sleCreator = view.peek ( + keylet::account(account_)); + + std::uint32_t const uAccountSequenceNext = sleCreator->getFieldU32 (sfSequence); std::uint32_t const uSequence = mTxn.getSequence (); // This is the original rate of the offer, and is the rate at which @@ -568,9 +571,6 @@ CreateOffer::applyGuts (View& view, View& view_cancel) // This is the ledger view that we work against. Transactions are applied // as we go on processing transactions. - auto const sleCreator = view.peek ( - keylet::account(mTxnAccountID)); - if (isGlobalFrozen (view, uPaysIssuerID) || isGlobalFrozen (view, uGetsIssuerID)) { if (j_.warning) j_.warning << @@ -578,7 +578,7 @@ CreateOffer::applyGuts (View& view, View& view_cancel) result = tecFROZEN; } - else if (accountFunds(view, mTxnAccountID, saTakerGets, + else if (accountFunds(view, account_, saTakerGets, fhZERO_IF_FROZEN, ctx_.config) <= zero) { if (j_.debug) j_.debug << @@ -607,7 +607,7 @@ CreateOffer::applyGuts (View& view, View& view_cancel) if (bHaveCancel) { auto const sleCancel = view.peek( - keylet::offer(mTxnAccountID, uCancelSequence)); + keylet::offer(account_, uCancelSequence)); // It's not an error to not find the offer to cancel: it might have // been consumed or removed. If it is found, however, it's an error @@ -753,7 +753,7 @@ CreateOffer::applyGuts (View& view, View& view_cancel) } // We need to place the remainder of the offer into its order book. - auto const offer_index = getOfferIndex (mTxnAccountID, uSequence); + auto const offer_index = getOfferIndex (account_, uSequence); std::uint64_t uOwnerNode; std::uint64_t uBookNode; @@ -761,10 +761,10 @@ CreateOffer::applyGuts (View& view, View& view_cancel) // Add offer to owner's directory. result = dirAdd(view, uOwnerNode, - getOwnerDirIndex (mTxnAccountID), offer_index, + getOwnerDirIndex (account_), offer_index, std::bind ( &ownerDirDescriber, std::placeholders::_1, - std::placeholders::_2, mTxnAccountID)); + std::placeholders::_2, account_)); if (result == tesSUCCESS) { @@ -793,7 +793,7 @@ CreateOffer::applyGuts (View& view, View& view_cancel) if (result == tesSUCCESS) { auto sleOffer = std::make_shared(ltOFFER, offer_index); - sleOffer->setAccountID (sfAccount, mTxnAccountID); + sleOffer->setAccountID (sfAccount, account_); sleOffer->setFieldU32 (sfSequence, uSequence); sleOffer->setFieldH256 (sfBookDirectory, uDirectory); sleOffer->setFieldAmount (sfTakerPays, saTakerPays); diff --git a/src/ripple/app/tx/impl/CreateTicket.cpp b/src/ripple/app/tx/impl/CreateTicket.cpp index 070beb61c7..ef9048772d 100644 --- a/src/ripple/app/tx/impl/CreateTicket.cpp +++ b/src/ripple/app/tx/impl/CreateTicket.cpp @@ -56,12 +56,11 @@ CreateTicket::getAccountReserve (SLE::pointer account) TER CreateTicket::doApply () { - assert (mTxnAccount); - // A ticket counts against the reserve of the issuing account, but we // check the starting balance because we want to allow dipping into the // reserve to pay fees. - if (mPriorBalance < getAccountReserve (mTxnAccount)) + if (mPriorBalance < STAmount(view().fees().accountReserve( + view().read(keylet::account(account_))->getFieldU32(sfOwnerCount) + 1))) return tecINSUFFICIENT_RESERVE; std::uint32_t expiration (0); @@ -75,8 +74,8 @@ CreateTicket::doApply () } SLE::pointer sleTicket = std::make_shared(ltTICKET, - getTicketIndex (mTxnAccountID, mTxn.getSequence ())); - sleTicket->setAccountID (sfAccount, mTxnAccountID); + getTicketIndex (account_, mTxn.getSequence ())); + sleTicket->setAccountID (sfAccount, account_); sleTicket->setFieldU32 (sfSequence, mTxn.getSequence ()); if (expiration != 0) sleTicket->setFieldU32 (sfExpiration, expiration); @@ -94,7 +93,7 @@ CreateTicket::doApply () // The issuing account is the default account to which the ticket // applies so don't bother saving it if that's what's specified. - if (target_account != mTxnAccountID) + if (target_account != account_) sleTicket->setAccountID (sfTarget, target_account); } @@ -102,12 +101,12 @@ CreateTicket::doApply () auto describer = [&](SLE::pointer p, bool b) { - ownerDirDescriber(p, b, mTxnAccountID); + ownerDirDescriber(p, b, account_); }; TER result = dirAdd(view(), hint, - getOwnerDirIndex (mTxnAccountID), + getOwnerDirIndex (account_), sleTicket->getIndex (), describer); @@ -121,7 +120,8 @@ CreateTicket::doApply () sleTicket->setFieldU64(sfOwnerNode, hint); // If we succeeded, the new entry counts agains the creator's reserve. - adjustOwnerCount(view(), mTxnAccount, 1); + adjustOwnerCount(view(), view().peek( + keylet::account(account_)), 1); return result; } diff --git a/src/ripple/app/tx/impl/Payment.cpp b/src/ripple/app/tx/impl/Payment.cpp index ae2680c2dd..b4f934e42c 100644 --- a/src/ripple/app/tx/impl/Payment.cpp +++ b/src/ripple/app/tx/impl/Payment.cpp @@ -55,7 +55,7 @@ Payment::preCheck () maxSourceAmount = saDstAmount; else maxSourceAmount = STAmount ( - { saDstAmount.getCurrency (), mTxnAccountID }, + { saDstAmount.getCurrency (), account_ }, saDstAmount.mantissa(), saDstAmount.exponent (), saDstAmount < zero); @@ -94,12 +94,12 @@ Payment::preCheck () "Bad currency."; return temBAD_CURRENCY; } - if (mTxnAccountID == uDstAccountID && uSrcCurrency == uDstCurrency && !bPaths) + if (account_ == uDstAccountID && uSrcCurrency == uDstCurrency && !bPaths) { // You're signing yourself a payment. // If bPaths is true, you might be trying some arbitrage. j_.trace << "Malformed transaction: " << - "Redundant payment from " << to_string (mTxnAccountID) << + "Redundant payment from " << to_string (account_) << " to self without path for " << to_string (uDstCurrency); return temREDUNDANT; } @@ -161,7 +161,7 @@ Payment::doApply () maxSourceAmount = saDstAmount; else maxSourceAmount = STAmount ( - {saDstAmount.getCurrency (), mTxnAccountID}, + {saDstAmount.getCurrency (), account_}, saDstAmount.mantissa(), saDstAmount.exponent (), saDstAmount < zero); @@ -280,7 +280,7 @@ Payment::doApply () maxSourceAmount, saDstAmount, uDstAccountID, - mTxnAccountID, + account_, spsPaths, &rcInput); // VFALCO NOTE We might not need to apply, depending @@ -316,7 +316,8 @@ Payment::doApply () // uOwnerCount is the number of entries in this legder for this // account that require a reserve. - auto const uOwnerCount = mTxnAccount->getFieldU32 (sfOwnerCount); + auto const uOwnerCount = view().read( + keylet::account(account_))->getFieldU32 (sfOwnerCount); // This is the total reserve in drops. auto const uReserve = @@ -343,7 +344,7 @@ Payment::doApply () { // The source account does have enough money, so do the // arithmetic for the transfer and make the ledger change. - mTxnAccount->setFieldAmount (sfBalance, + view().peek(keylet::account(account_))->setFieldAmount (sfBalance, mSourceBalance - saDstAmount); sleDst->setFieldAmount (sfBalance, sleDst->getFieldAmount (sfBalance) + saDstAmount); diff --git a/src/ripple/app/tx/impl/SetAccount.cpp b/src/ripple/app/tx/impl/SetAccount.cpp index 413344212a..6b8bf2403e 100644 --- a/src/ripple/app/tx/impl/SetAccount.cpp +++ b/src/ripple/app/tx/impl/SetAccount.cpp @@ -103,7 +103,10 @@ SetAccount::doApply () { std::uint32_t const uTxFlags = mTxn.getFlags (); - std::uint32_t const uFlagsIn = mTxnAccount->getFieldU32 (sfFlags); + auto const sle = view().peek( + keylet::account(account_)); + + std::uint32_t const uFlagsIn = sle->getFieldU32 (sfFlags); std::uint32_t uFlagsOut = uFlagsIn; std::uint32_t const uSetFlag = mTxn.getFieldU32 (sfSetFlag); @@ -123,7 +126,7 @@ SetAccount::doApply () if (bSetRequireAuth && !(uFlagsIn & lsfRequireAuth)) { if (! dirIsEmpty (view(), - keylet::ownerDir(mTxnAccountID))) + keylet::ownerDir(account_))) { j_.trace << "Retry: Owner directory not empty."; return (view().flags() & tapRETRY) ? terOWNERS : tecOWNERS; @@ -180,7 +183,7 @@ SetAccount::doApply () return tecNEED_MASTER_KEY; } - if (!mTxnAccount->isFieldPresent (sfRegularKey)) + if (!sle->isFieldPresent (sfRegularKey)) return tecNO_REGULAR_KEY; j_.trace << "Set lsfDisableMaster."; @@ -240,16 +243,16 @@ SetAccount::doApply () // // Track transaction IDs signed by this account in its root // - if ((uSetFlag == asfAccountTxnID) && !mTxnAccount->isFieldPresent (sfAccountTxnID)) + if ((uSetFlag == asfAccountTxnID) && !sle->isFieldPresent (sfAccountTxnID)) { j_.trace << "Set AccountTxnID"; - mTxnAccount->makeFieldPresent (sfAccountTxnID); + sle->makeFieldPresent (sfAccountTxnID); } - if ((uClearFlag == asfAccountTxnID) && mTxnAccount->isFieldPresent (sfAccountTxnID)) + if ((uClearFlag == asfAccountTxnID) && sle->isFieldPresent (sfAccountTxnID)) { j_.trace << "Clear AccountTxnID"; - mTxnAccount->makeFieldAbsent (sfAccountTxnID); + sle->makeFieldAbsent (sfAccountTxnID); } // @@ -262,12 +265,12 @@ SetAccount::doApply () if (!uHash) { j_.trace << "unset email hash"; - mTxnAccount->makeFieldAbsent (sfEmailHash); + sle->makeFieldAbsent (sfEmailHash); } else { j_.trace << "set email hash"; - mTxnAccount->setFieldH128 (sfEmailHash, uHash); + sle->setFieldH128 (sfEmailHash, uHash); } } @@ -281,12 +284,12 @@ SetAccount::doApply () if (!uHash) { j_.trace << "unset wallet locator"; - mTxnAccount->makeFieldAbsent (sfWalletLocator); + sle->makeFieldAbsent (sfWalletLocator); } else { j_.trace << "set wallet locator"; - mTxnAccount->setFieldH256 (sfWalletLocator, uHash); + sle->setFieldH256 (sfWalletLocator, uHash); } } @@ -306,12 +309,12 @@ SetAccount::doApply () if (messageKey.empty ()) { j_.debug << "set message key"; - mTxnAccount->makeFieldAbsent (sfMessageKey); + sle->makeFieldAbsent (sfMessageKey); } else { j_.debug << "set message key"; - mTxnAccount->setFieldVL (sfMessageKey, messageKey); + sle->setFieldVL (sfMessageKey, messageKey); } } @@ -331,12 +334,12 @@ SetAccount::doApply () if (domain.empty ()) { j_.trace << "unset domain"; - mTxnAccount->makeFieldAbsent (sfDomain); + sle->makeFieldAbsent (sfDomain); } else { j_.trace << "set domain"; - mTxnAccount->setFieldVL (sfDomain, domain); + sle->setFieldVL (sfDomain, domain); } } @@ -350,17 +353,17 @@ SetAccount::doApply () if (uRate == 0 || uRate == QUALITY_ONE) { j_.trace << "unset transfer rate"; - mTxnAccount->makeFieldAbsent (sfTransferRate); + sle->makeFieldAbsent (sfTransferRate); } else if (uRate > QUALITY_ONE) { j_.trace << "set transfer rate"; - mTxnAccount->setFieldU32 (sfTransferRate, uRate); + sle->setFieldU32 (sfTransferRate, uRate); } } if (uFlagsIn != uFlagsOut) - mTxnAccount->setFieldU32 (sfFlags, uFlagsOut); + sle->setFieldU32 (sfFlags, uFlagsOut); return tesSUCCESS; } diff --git a/src/ripple/app/tx/impl/SetRegularKey.cpp b/src/ripple/app/tx/impl/SetRegularKey.cpp index 1c744b981a..89b3d3e699 100644 --- a/src/ripple/app/tx/impl/SetRegularKey.cpp +++ b/src/ripple/app/tx/impl/SetRegularKey.cpp @@ -28,9 +28,11 @@ namespace ripple { std::uint64_t SetRegularKey::calculateBaseFee () { - if ( mTxnAccount - && (! (mTxnAccount->getFlags () & lsfPasswordSpent)) - && (calcAccountID(mSigningPubKey) == mTxnAccountID)) + auto const sle = view().peek( + keylet::account(account_)); + if ( sle + && (! (sle->getFlags () & lsfPasswordSpent)) + && (calcAccountID(mSigningPubKey) == account_)) { // flag is armed and they signed with the right account return 0; @@ -58,19 +60,22 @@ SetRegularKey::preCheck () TER SetRegularKey::doApply () { + auto const sle = view().peek( + keylet::account(account_)); + if (mFeeDue == zero) - mTxnAccount->setFlag (lsfPasswordSpent); + sle->setFlag (lsfPasswordSpent); if (mTxn.isFieldPresent (sfRegularKey)) { - mTxnAccount->setAccountID (sfRegularKey, + sle->setAccountID (sfRegularKey, mTxn.getAccountID (sfRegularKey)); } else { - if (mTxnAccount->isFlag (lsfDisableMaster)) + if (sle->isFlag (lsfDisableMaster)) return tecMASTER_DISABLED; - mTxnAccount->makeFieldAbsent (sfRegularKey); + sle->makeFieldAbsent (sfRegularKey); } return tesSUCCESS; diff --git a/src/ripple/app/tx/impl/SetSignerList.cpp b/src/ripple/app/tx/impl/SetSignerList.cpp index b19f92237c..dfeb360d9a 100644 --- a/src/ripple/app/tx/impl/SetSignerList.cpp +++ b/src/ripple/app/tx/impl/SetSignerList.cpp @@ -35,11 +35,9 @@ namespace ripple { TER SetSignerList::doApply () { - assert (mTxnAccount); - // All operations require our ledger index. Compute that once and pass it // to our handlers. - uint256 const index = getSignerListIndex (mTxnAccountID); + uint256 const index = getSignerListIndex (account_); // Perform the operation preCheck() decided on. switch (do_) @@ -142,7 +140,7 @@ SetSignerList::validateQuorumAndSignerEntries ( { allSignersWeight += signer.weight; - if (signer.account == mTxnAccountID) + if (signer.account == account_) { if (j_.trace) j_.trace << "A signer may not self reference account."; @@ -170,8 +168,11 @@ SetSignerList::replaceSignerList (uint256 const& index) if (TER const ter = destroySignerList (index)) return ter; + auto const sle = view().peek( + keylet::account(account_)); + // Compute new reserve. Verify the account has funds to meet the reserve. - std::uint32_t const oldOwnerCount = mTxnAccount->getFieldU32 (sfOwnerCount); + std::uint32_t const oldOwnerCount = sle->getFieldU32 (sfOwnerCount); std::uint32_t const addedOwnerCount = ownerCountDelta (signers_.size ()); auto const newReserve = @@ -192,17 +193,17 @@ SetSignerList::replaceSignerList (uint256 const& index) // Lambda for call to dirAdd. auto describer = [&] (SLE::ref sle, bool dummy) { - ownerDirDescriber (sle, dummy, mTxnAccountID); + ownerDirDescriber (sle, dummy, account_); }; // Add the signer list to the account's directory. std::uint64_t hint; TER result = dirAdd(ctx_.view (), - hint, getOwnerDirIndex (mTxnAccountID), index, describer); + hint, getOwnerDirIndex (account_), index, describer); if (j_.trace) j_.trace << "Create signer list for account " << - mTxnAccountID << ": " << transHuman (result); + account_ << ": " << transHuman (result); if (result != tesSUCCESS) return result; @@ -211,7 +212,7 @@ SetSignerList::replaceSignerList (uint256 const& index) // If we succeeded, the new entry counts against the creator's reserve. adjustOwnerCount(view(), - mTxnAccount, addedOwnerCount); + sle, addedOwnerCount); return result; } @@ -230,7 +231,7 @@ SetSignerList::destroySignerList (uint256 const& index) // We have to examine the current SignerList so we know how much to // reduce the OwnerCount. std::uint32_t removeFromOwnerCount = 0; - auto const k = keylet::signers(mTxnAccountID); + auto const k = keylet::signers(account_); SLE::pointer accountSignersList = view().peek (k); if (accountSignersList) @@ -244,11 +245,12 @@ SetSignerList::destroySignerList (uint256 const& index) std::uint64_t const hint (signerList->getFieldU64 (sfOwnerNode)); TER const result = dirDelete(ctx_.view (), false, hint, - getOwnerDirIndex (mTxnAccountID), index, false, (hint == 0)); + getOwnerDirIndex (account_), index, false, (hint == 0)); if (result == tesSUCCESS) adjustOwnerCount(view(), - mTxnAccount, removeFromOwnerCount); + view().peek(keylet::account(account_)), + removeFromOwnerCount); ctx_.view ().erase (signerList); diff --git a/src/ripple/app/tx/impl/SetTrust.cpp b/src/ripple/app/tx/impl/SetTrust.cpp index 3cd767d8e4..3d91b2859f 100644 --- a/src/ripple/app/tx/impl/SetTrust.cpp +++ b/src/ripple/app/tx/impl/SetTrust.cpp @@ -91,9 +91,12 @@ SetTrust::doApply () AccountID uDstAccountID (saLimitAmount.getIssuer ()); // true, iff current is high account. - bool const bHigh = mTxnAccountID > uDstAccountID; + bool const bHigh = account_ > uDstAccountID; - std::uint32_t const uOwnerCount (mTxnAccount->getFieldU32 (sfOwnerCount)); + auto const sle = view().peek( + keylet::account(account_)); + + std::uint32_t const uOwnerCount = sle->getFieldU32 (sfOwnerCount); // The reserve required to create the line. Note that we allow up to // two trust lines without requiring a reserve because being able to @@ -125,21 +128,21 @@ SetTrust::doApply () bool const bSetFreeze = (uTxFlags & tfSetFreeze); bool const bClearFreeze = (uTxFlags & tfClearFreeze); - if (bSetAuth && !(mTxnAccount->getFieldU32 (sfFlags) & lsfRequireAuth)) + if (bSetAuth && !(sle->getFieldU32 (sfFlags) & lsfRequireAuth)) { j_.trace << "Retry: Auth not required."; return tefNO_AUTH_REQUIRED; } - if (mTxnAccountID == uDstAccountID) + if (account_ == uDstAccountID) { // The only purpose here is to allow a mistakenly created // trust line to oneself to be deleted. If no such trust // lines exist now, why not remove this code and simply // return an error? SLE::pointer sleDelete = view().peek ( - keylet::line(mTxnAccountID, uDstAccountID, currency)); + keylet::line(account_, uDstAccountID, currency)); if (sleDelete) { @@ -147,7 +150,7 @@ SetTrust::doApply () "Clearing redundant line."; return trustDelete (view(), - sleDelete, mTxnAccountID, uDstAccountID); + sleDelete, account_, uDstAccountID); } else { @@ -168,10 +171,10 @@ SetTrust::doApply () } STAmount saLimitAllow = saLimitAmount; - saLimitAllow.setIssuer (mTxnAccountID); + saLimitAllow.setIssuer (account_); SLE::pointer sleRippleState = view().peek ( - keylet::line(mTxnAccountID, uDstAccountID, currency)); + keylet::line(account_, uDstAccountID, currency)); if (sleRippleState) { @@ -183,10 +186,10 @@ SetTrust::doApply () std::uint32_t uLowQualityOut; std::uint32_t uHighQualityIn; std::uint32_t uHighQualityOut; - auto const& uLowAccountID = !bHigh ? mTxnAccountID : uDstAccountID; - auto const& uHighAccountID = bHigh ? mTxnAccountID : uDstAccountID; - SLE::ref sleLowAccount = !bHigh ? mTxnAccount : sleDst; - SLE::ref sleHighAccount = bHigh ? mTxnAccount : sleDst; + auto const& uLowAccountID = !bHigh ? account_ : uDstAccountID; + auto const& uHighAccountID = bHigh ? account_ : uDstAccountID; + SLE::ref sleLowAccount = !bHigh ? sle : sleDst; + SLE::ref sleHighAccount = bHigh ? sle : sleDst; // // Balances @@ -280,7 +283,7 @@ SetTrust::doApply () uFlagsOut &= ~(bHigh ? lsfHighNoRipple : lsfLowNoRipple); } - if (bSetFreeze && !bClearFreeze && !mTxnAccount->isFlag (lsfNoFreeze)) + if (bSetFreeze && !bClearFreeze && !sle->isFlag (lsfNoFreeze)) { uFlagsOut |= (bHigh ? lsfHighFreeze : lsfLowFreeze); } @@ -408,7 +411,7 @@ SetTrust::doApply () STAmount saBalance ({currency, noAccount()}); uint256 index (getRippleStateIndex ( - mTxnAccountID, uDstAccountID, currency)); + account_, uDstAccountID, currency)); j_.trace << "doTrustSet: Creating ripple line: " << @@ -417,10 +420,10 @@ SetTrust::doApply () // Create a new ripple line. terResult = trustCreate (view(), bHigh, - mTxnAccountID, + account_, uDstAccountID, index, - mTxnAccount, + sle, bSetAuth, bSetNoRipple && !bClearNoRipple, bSetFreeze && !bClearFreeze, diff --git a/src/ripple/app/tx/impl/Transactor.cpp b/src/ripple/app/tx/impl/Transactor.cpp index cd40d33bd5..cea4f4f4da 100644 --- a/src/ripple/app/tx/impl/Transactor.cpp +++ b/src/ripple/app/tx/impl/Transactor.cpp @@ -75,6 +75,9 @@ TER Transactor::payFee () if (!saPaid) return tesSUCCESS; + auto const sle = view().peek( + keylet::account(account_)); + if (mSourceBalance < saPaid) { j_.trace << "Insufficient balance:" << @@ -85,7 +88,7 @@ TER Transactor::payFee () { // Closed ledger, non-zero balance, less than fee mSourceBalance.clear (); - mTxnAccount->setFieldAmount (sfBalance, mSourceBalance); + sle->setFieldAmount (sfBalance, mSourceBalance); return tecINSUFF_FEE; } @@ -96,7 +99,7 @@ TER Transactor::payFee () // Will only write the account back, if the transaction succeeds. mSourceBalance -= saPaid; - mTxnAccount->setFieldAmount (sfBalance, mSourceBalance); + sle->setFieldAmount (sfBalance, mSourceBalance); // VFALCO Should we call view().destroyCoins() here as well? @@ -105,8 +108,11 @@ TER Transactor::payFee () TER Transactor::checkSeq () { + auto const sle = view().peek( + keylet::account(account_)); + std::uint32_t const t_seq = mTxn.getSequence (); - std::uint32_t const a_seq = mTxnAccount->getFieldU32 (sfSequence); + std::uint32_t const a_seq = sle->getFieldU32 (sfSequence); if (t_seq != a_seq) { @@ -127,17 +133,17 @@ TER Transactor::checkSeq () } if (mTxn.isFieldPresent (sfAccountTxnID) && - (mTxnAccount->getFieldH256 (sfAccountTxnID) != mTxn.getFieldH256 (sfAccountTxnID))) + (sle->getFieldH256 (sfAccountTxnID) != mTxn.getFieldH256 (sfAccountTxnID))) return tefWRONG_PRIOR; if (mTxn.isFieldPresent (sfLastLedgerSequence) && (view().seq() > mTxn.getFieldU32 (sfLastLedgerSequence))) return tefMAX_LEDGER; - mTxnAccount->setFieldU32 (sfSequence, t_seq + 1); + sle->setFieldU32 (sfSequence, t_seq + 1); - if (mTxnAccount->isFieldPresent (sfAccountTxnID)) - mTxnAccount->setFieldH256 (sfAccountTxnID, mTxn.getTransactionID ()); + if (sle->isFieldPresent (sfAccountTxnID)) + sle->setFieldH256 (sfAccountTxnID, mTxn.getTransactionID ()); return tesSUCCESS; } @@ -154,9 +160,9 @@ TER Transactor::preCheck () TER Transactor::preCheckAccount () { - mTxnAccountID = mTxn.getAccountID(sfAccount); + account_ = mTxn.getAccountID(sfAccount); - if (!mTxnAccountID) + if (!account_) { j_.warning << "applyTransaction: bad transaction source id"; return temBAD_SRC_ACCOUNT; @@ -213,13 +219,13 @@ TER Transactor::apply () return terResult; // Find source account - mTxnAccount = view().peek (keylet::account(mTxnAccountID)); + auto const sle = view().peek (keylet::account(account_)); calculateFee (); // If are only forwarding, due to resource limitations, we might verifying // only some transactions, this would be probabilistic. - if (!mTxnAccount) + if (!sle) { if (mustHaveValidAccount ()) { @@ -231,9 +237,9 @@ TER Transactor::apply () } else { - mPriorBalance = mTxnAccount->getFieldAmount (sfBalance); + mPriorBalance = sle->getFieldAmount (sfBalance); mSourceBalance = mPriorBalance; - mHasAuthKey = mTxnAccount->isFieldPresent (sfRegularKey); + mHasAuthKey = sle->isFieldPresent (sfRegularKey); } terResult = checkSeq (); @@ -248,8 +254,8 @@ TER Transactor::apply () if (terResult != tesSUCCESS) return (terResult); - if (mTxnAccount) - view().update (mTxnAccount); + if (sle) + view().update (sle); return doApply (); } @@ -274,18 +280,22 @@ TER Transactor::checkSingleSign () // VFALCO NOTE This is needlessly calculating the // AccountID multiple times. + // VFALCO What if sle is nullptr? + auto const sle = view().peek( + keylet::account(account_)); + // Consistency: Check signature // Verify the transaction's signing public key is authorized for signing. - if (calcAccountID(mSigningPubKey) == mTxnAccountID) + if (calcAccountID(mSigningPubKey) == account_) { // Authorized to continue. mSigMaster = true; - if (mTxnAccount->isFlag(lsfDisableMaster)) + if (sle->isFlag(lsfDisableMaster)) return tefMASTER_DISABLED; } else if (mHasAuthKey && (calcAccountID(mSigningPubKey) == - mTxnAccount->getAccountID (sfRegularKey))) + sle->getAccountID (sfRegularKey))) { // Authorized to continue. } @@ -495,10 +505,10 @@ checkSigningAccounts ( TER Transactor::checkMultiSign () { - // Get mTxnAccountID's SignerList and Quorum. + // Get account_'s SignerList and Quorum. using namespace TransactorDetail; GetSignerListResult const outer = - getSignerList (mTxnAccountID, view(), j_); + getSignerList (account_, view(), j_); if (outer.ter != tesSUCCESS) return outer.ter; @@ -526,7 +536,7 @@ TER Transactor::checkMultiSign () // o The signers are direct multi-signers for this account. // o The signers are signing for a multi-signer on this account. // Handle those two cases separately. - if (signingForID == mTxnAccountID) + if (signingForID == account_) { // The signers are direct multi-signers for this account. Results // from these signers directly effect the quorum. diff --git a/src/ripple/app/tx/impl/Transactor.h b/src/ripple/app/tx/impl/Transactor.h index 1bbe8b015a..7b0b951632 100644 --- a/src/ripple/app/tx/impl/Transactor.h +++ b/src/ripple/app/tx/impl/Transactor.h @@ -32,11 +32,10 @@ protected: ApplyContext& ctx_; beast::Journal j_; - AccountID mTxnAccountID; + AccountID account_; STAmount mFeeDue; STAmount mPriorBalance; // Balance before fees. STAmount mSourceBalance; // Balance after fees. - SLE::pointer mTxnAccount; bool mHasAuthKey; bool mSigMaster; RippleAddress mSigningPubKey;