mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Clean up LedgerEntrySet and TransactionEngine:
* Reduce public interfaces * Remove wrapper functions * Remove freeze timed cutover code * Return results directly instead of via ref parameters
This commit is contained in:
committed by
Tom Ritchford
parent
5ce3ed3555
commit
67c666b033
@@ -2060,12 +2060,6 @@
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\ripple\app\tx\TransactionAcquire.h">
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\ripple\app\tx\TransactionCheck.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
|
||||
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='debug.classic|x64'">..\..\src\soci\src\core;..\..\src\sqlite;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='release.classic|x64'">..\..\src\soci\src\core;..\..\src\sqlite;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\ripple\app\tx\TransactionEngine.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
|
||||
@@ -4518,8 +4512,6 @@
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\soci\src\core\values.h">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\soci\src\core\version.h">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\sqlite\sqlite.h">
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\sqlite\sqlite.unity.c">
|
||||
|
||||
@@ -2613,9 +2613,6 @@
|
||||
<ClInclude Include="..\..\src\ripple\app\tx\TransactionAcquire.h">
|
||||
<Filter>ripple\app\tx</Filter>
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\ripple\app\tx\TransactionCheck.cpp">
|
||||
<Filter>ripple\app\tx</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\ripple\app\tx\TransactionEngine.cpp">
|
||||
<Filter>ripple\app\tx</Filter>
|
||||
</ClCompile>
|
||||
@@ -5289,9 +5286,6 @@
|
||||
<ClInclude Include="..\..\src\soci\src\core\values.h">
|
||||
<Filter>soci\src\core</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\soci\src\core\version.h">
|
||||
<Filter>soci\src\core</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\sqlite\sqlite.h">
|
||||
<Filter>sqlite</Filter>
|
||||
</ClInclude>
|
||||
|
||||
@@ -1852,27 +1852,26 @@ int applyTransaction (TransactionEngine& engine
|
||||
|
||||
try
|
||||
{
|
||||
bool didApply;
|
||||
TER result = engine.applyTransaction (*txn, parms, didApply);
|
||||
auto result = engine.applyTransaction (*txn, parms);
|
||||
|
||||
if (didApply)
|
||||
if (result.second)
|
||||
{
|
||||
WriteLog (lsDEBUG, LedgerConsensus)
|
||||
<< "Transaction success: " << transHuman (result);
|
||||
<< "Transaction applied: " << transHuman (result.first);
|
||||
return LedgerConsensusImp::resultSuccess;
|
||||
}
|
||||
|
||||
if (isTefFailure (result) || isTemMalformed (result) ||
|
||||
isTelLocal (result))
|
||||
if (isTefFailure (result.first) || isTemMalformed (result.first) ||
|
||||
isTelLocal (result.first))
|
||||
{
|
||||
// failure
|
||||
WriteLog (lsDEBUG, LedgerConsensus)
|
||||
<< "Transaction failure: " << transHuman (result);
|
||||
<< "Transaction failure: " << transHuman (result.first);
|
||||
return LedgerConsensusImp::resultFail;
|
||||
}
|
||||
|
||||
WriteLog (lsDEBUG, LedgerConsensus)
|
||||
<< "Transaction retry: " << transHuman (result);
|
||||
<< "Transaction retry: " << transHuman (result.first);
|
||||
return LedgerConsensusImp::resultRetry;
|
||||
}
|
||||
catch (...)
|
||||
|
||||
@@ -261,30 +261,6 @@ Ledger::~Ledger ()
|
||||
}
|
||||
}
|
||||
|
||||
bool Ledger::enforceFreeze () const
|
||||
{
|
||||
|
||||
// Temporarily, the freze code can run in either
|
||||
// enforcing mode or non-enforcing mode. In
|
||||
// non-enforcing mode, freeze flags can be
|
||||
// manipulated, but freezing is not actually
|
||||
// enforced. Once freeze enforcing has been
|
||||
// enabled, this function can be removed
|
||||
|
||||
// Let freeze enforcement be tested
|
||||
// If you wish to test non-enforcing mode,
|
||||
// you must remove this line
|
||||
if (getConfig().RUN_STANDALONE)
|
||||
return true;
|
||||
|
||||
// Freeze enforcing date is September 15, 2014
|
||||
static std::uint32_t const enforceDate =
|
||||
iToSeconds (boost::posix_time::ptime (
|
||||
boost::gregorian::date (2014, boost::gregorian::Sep, 15)));
|
||||
|
||||
return mParentCloseTime >= enforceDate;
|
||||
}
|
||||
|
||||
void Ledger::setImmutable ()
|
||||
{
|
||||
// Updates the hash and marks the ledger and its maps immutable
|
||||
|
||||
@@ -181,8 +181,6 @@ public:
|
||||
mAccountStateMap->setLedgerSeq (mLedgerSeq);
|
||||
}
|
||||
|
||||
bool enforceFreeze () const;
|
||||
|
||||
// ledger signature operations
|
||||
void addRaw (Serializer & s) const;
|
||||
void setRaw (Serializer & s, bool hasPrefix);
|
||||
|
||||
@@ -122,16 +122,6 @@ SLE::pointer LedgerEntrySet::entryCache (LedgerEntryType letType, uint256 const&
|
||||
return sleEntry;
|
||||
}
|
||||
|
||||
LedgerEntryAction LedgerEntrySet::hasEntry (uint256 const& index) const
|
||||
{
|
||||
std::map<uint256, LedgerEntrySetEntry>::const_iterator it = mEntries.find (index);
|
||||
|
||||
if (it == mEntries.end ())
|
||||
return taaNONE;
|
||||
|
||||
return it->second.mAction;
|
||||
}
|
||||
|
||||
void LedgerEntrySet::entryCache (SLE::ref sle)
|
||||
{
|
||||
assert (mLedger);
|
||||
@@ -1187,7 +1177,7 @@ STAmount LedgerEntrySet::accountHolds (
|
||||
|
||||
bool LedgerEntrySet::isGlobalFrozen (Account const& issuer)
|
||||
{
|
||||
if (!enforceFreeze () || isXRP (issuer))
|
||||
if (isXRP (issuer))
|
||||
return false;
|
||||
|
||||
SLE::pointer sle = entryCache (ltACCOUNT_ROOT, getAccountRootIndex (issuer));
|
||||
@@ -1204,7 +1194,7 @@ bool LedgerEntrySet::isFrozen(
|
||||
Currency const& currency,
|
||||
Account const& issuer)
|
||||
{
|
||||
if (!enforceFreeze () || isXRP (currency))
|
||||
if (isXRP (currency))
|
||||
return false;
|
||||
|
||||
SLE::pointer sle = entryCache (ltACCOUNT_ROOT, getAccountRootIndex (issuer));
|
||||
|
||||
@@ -126,11 +126,6 @@ public:
|
||||
return mSeq;
|
||||
}
|
||||
|
||||
TransactionEngineParams getParams () const
|
||||
{
|
||||
return mParams;
|
||||
}
|
||||
|
||||
void bumpSeq ()
|
||||
{
|
||||
++mSeq;
|
||||
@@ -146,14 +141,9 @@ public:
|
||||
return mLedger;
|
||||
}
|
||||
|
||||
bool enforceFreeze () const
|
||||
{
|
||||
return mLedger->enforceFreeze ();
|
||||
}
|
||||
|
||||
// basic entry functions
|
||||
SLE::pointer getEntry (uint256 const& index, LedgerEntryAction&);
|
||||
LedgerEntryAction hasEntry (uint256 const& index) const;
|
||||
|
||||
void entryCache (SLE::ref); // Add this entry to the cache
|
||||
void entryCreate (SLE::ref); // This entry will be created
|
||||
void entryDelete (SLE::ref); // This entry will be deleted
|
||||
|
||||
@@ -344,10 +344,9 @@ public:
|
||||
if (getApp().getHashRouter ().addSuppressionFlags (it.first.getTXID (), SF_SIGGOOD))
|
||||
tepFlags = static_cast<TransactionEngineParams> (tepFlags | tapNO_CHECK_SIGN);
|
||||
|
||||
bool didApply;
|
||||
engine.applyTransaction (*it.second, tepFlags, didApply);
|
||||
auto ret = engine.applyTransaction (*it.second, tepFlags);
|
||||
|
||||
if (didApply)
|
||||
if (ret.second)
|
||||
++recovers;
|
||||
|
||||
// If a transaction is recovered but hasn't been relayed,
|
||||
@@ -390,7 +389,7 @@ public:
|
||||
ScopedLockType sl (m_mutex);
|
||||
ledger = mCurrentLedger.getMutable ();
|
||||
engine.setLedger (ledger);
|
||||
result = engine.applyTransaction (*txn, params, didApply);
|
||||
std::tie(result, didApply) = engine.applyTransaction (*txn, params);
|
||||
}
|
||||
if (didApply)
|
||||
{
|
||||
|
||||
@@ -1045,7 +1045,6 @@ Transaction::pointer NetworkOPsImp::processTransactionCb (
|
||||
if (callback)
|
||||
callback (trans, r);
|
||||
|
||||
|
||||
if (r == tefFAILURE)
|
||||
throw Fault (IO_ERROR);
|
||||
|
||||
|
||||
@@ -710,8 +710,7 @@ int Pathfinder::getPathsOut (
|
||||
|
||||
int aFlags = sleAccount->getFieldU32 (sfFlags);
|
||||
bool const bAuthRequired = (aFlags & lsfRequireAuth) != 0;
|
||||
bool const bFrozen = ((aFlags & lsfGlobalFreeze) != 0)
|
||||
&& mLedger->enforceFreeze ();
|
||||
bool const bFrozen = ((aFlags & lsfGlobalFreeze) != 0);
|
||||
|
||||
int count = 0;
|
||||
|
||||
@@ -741,7 +740,7 @@ int Pathfinder::getPathsOut (
|
||||
{
|
||||
// This probably isn't a useful path out
|
||||
}
|
||||
else if (rspEntry->getFreezePeer () && mLedger->enforceFreeze ())
|
||||
else if (rspEntry->getFreezePeer ())
|
||||
{
|
||||
// Not a useful path out
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ bool RippleCalc::addPathState(STPath const& path, TER& resultCode)
|
||||
if (pathState->status() == tesSUCCESS)
|
||||
pathState->checkNoRipple (uDstAccountID_, uSrcAccountID_);
|
||||
|
||||
if (pathState->status() == tesSUCCESS && mActiveLedger.enforceFreeze ())
|
||||
if (pathState->status() == tesSUCCESS)
|
||||
pathState->checkFreeze ();
|
||||
|
||||
pathState->setIndex (pathStateList_.size ());
|
||||
|
||||
@@ -128,15 +128,12 @@ void
|
||||
applyTransaction(Ledger::pointer const& ledger, STTx const& tx, bool check)
|
||||
{
|
||||
TransactionEngine engine(ledger);
|
||||
bool didApply = false;
|
||||
auto r = engine.applyTransaction(tx, tapOPEN_LEDGER | (check ? tapNONE : tapNO_CHECK_SIGN),
|
||||
didApply);
|
||||
if (r != tesSUCCESS)
|
||||
throw std::runtime_error(
|
||||
"r != tesSUCCESS");
|
||||
if (!didApply)
|
||||
throw std::runtime_error(
|
||||
"didApply");
|
||||
auto r = engine.applyTransaction(tx,
|
||||
tapOPEN_LEDGER | (check ? tapNONE : tapNO_CHECK_SIGN));
|
||||
if (r.first != tesSUCCESS)
|
||||
throw std::runtime_error("r != tesSUCCESS");
|
||||
if (!r.second)
|
||||
throw std::runtime_error("didApply");
|
||||
}
|
||||
|
||||
// Create genesis ledger from a start amount in drops, and the public
|
||||
|
||||
@@ -78,7 +78,7 @@ public:
|
||||
|
||||
uint256 const offerIndex (getOfferIndex (mTxnAccountID, uOfferSequence));
|
||||
|
||||
SLE::pointer sleOffer (mEngine->entryCache (ltOFFER,
|
||||
SLE::pointer sleOffer (mEngine->view().entryCache (ltOFFER,
|
||||
offerIndex));
|
||||
|
||||
if (sleOffer)
|
||||
|
||||
@@ -119,10 +119,10 @@ private:
|
||||
|
||||
auto const index = getLedgerAmendmentIndex ();
|
||||
|
||||
SLE::pointer amendmentObject (mEngine->entryCache (ltAMENDMENTS, index));
|
||||
SLE::pointer amendmentObject (mEngine->view().entryCache (ltAMENDMENTS, index));
|
||||
|
||||
if (!amendmentObject)
|
||||
amendmentObject = mEngine->entryCreate(ltAMENDMENTS, index);
|
||||
amendmentObject = mEngine->view().entryCreate(ltAMENDMENTS, index);
|
||||
|
||||
STVector256 amendments (amendmentObject->getFieldV256 (sfAmendments));
|
||||
|
||||
@@ -134,7 +134,7 @@ private:
|
||||
|
||||
amendments.push_back (amendment);
|
||||
amendmentObject->setFieldV256 (sfAmendments, amendments);
|
||||
mEngine->entryModify (amendmentObject);
|
||||
mEngine->view().entryModify (amendmentObject);
|
||||
|
||||
getApp().getAmendmentTable ().enable (amendment);
|
||||
|
||||
@@ -148,10 +148,10 @@ private:
|
||||
{
|
||||
auto const index = getLedgerFeeIndex ();
|
||||
|
||||
SLE::pointer feeObject = mEngine->entryCache (ltFEE_SETTINGS, index);
|
||||
SLE::pointer feeObject = mEngine->view().entryCache (ltFEE_SETTINGS, index);
|
||||
|
||||
if (!feeObject)
|
||||
feeObject = mEngine->entryCreate (ltFEE_SETTINGS, index);
|
||||
feeObject = mEngine->view().entryCreate (ltFEE_SETTINGS, index);
|
||||
|
||||
// VFALCO-FIXME this generates errors
|
||||
// m_journal.trace <<
|
||||
@@ -166,7 +166,7 @@ private:
|
||||
feeObject->setFieldU32 (
|
||||
sfReserveIncrement, mTxn.getFieldU32 (sfReserveIncrement));
|
||||
|
||||
mEngine->entryModify (feeObject);
|
||||
mEngine->view().entryModify (feeObject);
|
||||
|
||||
// VFALCO-FIXME this generates errors
|
||||
// m_journal.trace <<
|
||||
|
||||
@@ -49,7 +49,7 @@ private:
|
||||
// Only valid for custom currencies
|
||||
assert (!isXRP (issue.currency));
|
||||
|
||||
SLE::pointer const issuerAccount = mEngine->entryCache (
|
||||
SLE::pointer const issuerAccount = mEngine->view().entryCache (
|
||||
ltACCOUNT_ROOT, getAccountRootIndex (issue.account));
|
||||
|
||||
if (!issuerAccount)
|
||||
@@ -65,7 +65,7 @@ private:
|
||||
|
||||
if (issuerAccount->getFieldU32 (sfFlags) & lsfRequireAuth)
|
||||
{
|
||||
SLE::pointer const trustLine (mEngine->entryCache (
|
||||
SLE::pointer const trustLine (mEngine->view().entryCache (
|
||||
ltRIPPLE_STATE, getRippleStateIndex (
|
||||
mTxnAccountID, issue.account, issue.currency)));
|
||||
|
||||
@@ -604,7 +604,7 @@ public:
|
||||
|
||||
view.bumpSeq (); // Begin ledger variance.
|
||||
|
||||
SLE::pointer sleCreator = mEngine->entryCache (
|
||||
SLE::pointer sleCreator = mEngine->view().entryCache (
|
||||
ltACCOUNT_ROOT, getAccountRootIndex (mTxnAccountID));
|
||||
|
||||
if (view.isGlobalFrozen (uPaysIssuerID) || view.isGlobalFrozen (uGetsIssuerID))
|
||||
@@ -642,7 +642,7 @@ public:
|
||||
// Process a cancellation request that's passed along with an offer.
|
||||
if (bHaveCancel)
|
||||
{
|
||||
SLE::pointer sleCancel = mEngine->entryCache (ltOFFER,
|
||||
SLE::pointer sleCancel = mEngine->view().entryCache (ltOFFER,
|
||||
getOfferIndex (mTxnAccountID, uCancelSequence));
|
||||
|
||||
// It's not an error to not find the offer to cancel: it might have
|
||||
@@ -831,7 +831,7 @@ public:
|
||||
|
||||
if (result == tesSUCCESS)
|
||||
{
|
||||
SLE::pointer sleOffer (mEngine->entryCreate (ltOFFER, offer_index));
|
||||
SLE::pointer sleOffer (mEngine->view().entryCreate (ltOFFER, offer_index));
|
||||
|
||||
sleOffer->setFieldAccount (sfAccount, mTxnAccountID);
|
||||
sleOffer->setFieldU32 (sfSequence, uSequence);
|
||||
|
||||
@@ -80,7 +80,7 @@ public:
|
||||
return tesSUCCESS;
|
||||
}
|
||||
|
||||
SLE::pointer sleTicket = mEngine->entryCreate (ltTICKET,
|
||||
SLE::pointer sleTicket = mEngine->view().entryCreate (ltTICKET,
|
||||
getTicketIndex (mTxnAccountID, mTxn.getSequence ()));
|
||||
|
||||
sleTicket->setFieldAccount (sfAccount, mTxnAccountID);
|
||||
@@ -93,7 +93,7 @@ public:
|
||||
{
|
||||
Account const target_account (mTxn.getFieldAccount160 (sfTarget));
|
||||
|
||||
SLE::pointer sleTarget = mEngine->entryCache (ltACCOUNT_ROOT,
|
||||
SLE::pointer sleTarget = mEngine->view().entryCache (ltACCOUNT_ROOT,
|
||||
getAccountRootIndex (target_account));
|
||||
|
||||
// Destination account does not exist.
|
||||
|
||||
@@ -192,7 +192,7 @@ public:
|
||||
|
||||
// Open a ledger for editing.
|
||||
auto const index = getAccountRootIndex (uDstAccountID);
|
||||
SLE::pointer sleDst (mEngine->entryCache (ltACCOUNT_ROOT, index));
|
||||
SLE::pointer sleDst (mEngine->view().entryCache (ltACCOUNT_ROOT, index));
|
||||
|
||||
if (!sleDst)
|
||||
{
|
||||
@@ -234,7 +234,7 @@ public:
|
||||
|
||||
// Create the account.
|
||||
auto const newIndex = getAccountRootIndex (uDstAccountID);
|
||||
sleDst = mEngine->entryCreate (ltACCOUNT_ROOT, newIndex);
|
||||
sleDst = mEngine->view().entryCreate (ltACCOUNT_ROOT, newIndex);
|
||||
sleDst->setFieldAccount (sfAccount, uDstAccountID);
|
||||
sleDst->setFieldU32 (sfSequence, 1);
|
||||
}
|
||||
@@ -255,7 +255,7 @@ public:
|
||||
// Tell the engine that we are intending to change the the destination
|
||||
// account. The source account gets always charged a fee so it's always
|
||||
// marked as modified.
|
||||
mEngine->entryModify (sleDst);
|
||||
mEngine->view().entryModify (sleDst);
|
||||
}
|
||||
|
||||
TER terResult;
|
||||
|
||||
@@ -153,7 +153,7 @@ public:
|
||||
// lines exist now, why not remove this code and simply
|
||||
// return an error?
|
||||
SLE::pointer selDelete (
|
||||
mEngine->entryCache (ltRIPPLE_STATE,
|
||||
mEngine->view().entryCache (ltRIPPLE_STATE,
|
||||
getRippleStateIndex (
|
||||
mTxnAccountID, uDstAccountID, currency)));
|
||||
|
||||
@@ -173,7 +173,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
SLE::pointer sleDst (mEngine->entryCache (
|
||||
SLE::pointer sleDst (mEngine->view().entryCache (
|
||||
ltACCOUNT_ROOT, getAccountRootIndex (uDstAccountID)));
|
||||
|
||||
if (!sleDst)
|
||||
@@ -186,7 +186,7 @@ public:
|
||||
STAmount saLimitAllow = saLimitAmount;
|
||||
saLimitAllow.setIssuer (mTxnAccountID);
|
||||
|
||||
SLE::pointer sleRippleState (mEngine->entryCache (ltRIPPLE_STATE,
|
||||
SLE::pointer sleRippleState (mEngine->view().entryCache (ltRIPPLE_STATE,
|
||||
getRippleStateIndex (mTxnAccountID, uDstAccountID, currency)));
|
||||
|
||||
if (sleRippleState)
|
||||
@@ -391,7 +391,7 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
mEngine->entryModify (sleRippleState);
|
||||
mEngine->view().entryModify (sleRippleState);
|
||||
|
||||
m_journal.trace << "Modify ripple line";
|
||||
}
|
||||
|
||||
@@ -266,7 +266,7 @@ TER Transactor::apply ()
|
||||
return terResult;
|
||||
|
||||
// Find source account
|
||||
mTxnAccount = mEngine->entryCache (ltACCOUNT_ROOT,
|
||||
mTxnAccount = mEngine->view().entryCache (ltACCOUNT_ROOT,
|
||||
getAccountRootIndex (mTxnAccountID));
|
||||
|
||||
calculateFee ();
|
||||
@@ -303,7 +303,7 @@ TER Transactor::apply ()
|
||||
if (terResult != tesSUCCESS) return (terResult);
|
||||
|
||||
if (mTxnAccount)
|
||||
mEngine->entryModify (mTxnAccount);
|
||||
mEngine->view().entryModify (mTxnAccount);
|
||||
|
||||
return doApply ();
|
||||
}
|
||||
|
||||
@@ -156,9 +156,7 @@ public:
|
||||
{
|
||||
try
|
||||
{
|
||||
TransactionEngineParams parms = tapOPEN_LEDGER;
|
||||
bool didApply;
|
||||
engine.applyTransaction (*it.second, parms, didApply);
|
||||
engine.applyTransaction (*it.second, tapOPEN_LEDGER);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of rippled: https://github.com/ripple/rippled
|
||||
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <BeastConfig.h>
|
||||
#include <ripple/app/tx/TransactionEngine.h>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
// VFALCO TODO move this into TransactionEngine.cpp
|
||||
|
||||
// Double check a transaction's metadata to make sure no system invariants were broken
|
||||
|
||||
bool TransactionEngine::checkInvariants (TER result, const STTx& txn, TransactionEngineParams params)
|
||||
{
|
||||
// VFALCO I deleted a bunch of code that was wrapped in #if 0.
|
||||
// If you need it, check the commit log.
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // ripple
|
||||
@@ -80,15 +80,25 @@ void TransactionEngine::txnWrite ()
|
||||
}
|
||||
}
|
||||
|
||||
TER TransactionEngine::applyTransaction (
|
||||
std::pair<TER, bool>
|
||||
TransactionEngine::applyTransaction (
|
||||
STTx const& txn,
|
||||
TransactionEngineParams params,
|
||||
bool& didApply)
|
||||
TransactionEngineParams params)
|
||||
{
|
||||
WriteLog (lsTRACE, TransactionEngine) << "applyTransaction>";
|
||||
didApply = false;
|
||||
assert (mLedger);
|
||||
mNodes.init (mLedger, txn.getTransactionID (), mLedger->getLedgerSeq (), params);
|
||||
|
||||
WriteLog (lsTRACE, TransactionEngine) << "applyTransaction>";
|
||||
|
||||
uint256 const& txID = txn.getTransactionID ();
|
||||
|
||||
if (!txID)
|
||||
{
|
||||
WriteLog (lsWARNING, TransactionEngine) <<
|
||||
"applyTransaction: invalid transaction id";
|
||||
return std::make_pair(temINVALID_FLAG, false);
|
||||
}
|
||||
|
||||
mNodes.init (mLedger, txID, mLedger->getLedgerSeq (), params);
|
||||
|
||||
#ifdef BEAST_DEBUG
|
||||
if (1)
|
||||
@@ -109,22 +119,13 @@ TER TransactionEngine::applyTransaction (
|
||||
}
|
||||
#endif
|
||||
|
||||
uint256 const& txID = txn.getTransactionID ();
|
||||
|
||||
if (!txID)
|
||||
{
|
||||
WriteLog (lsWARNING, TransactionEngine) <<
|
||||
"applyTransaction: invalid transaction id";
|
||||
return temINVALID;
|
||||
}
|
||||
|
||||
TER terResult = Transactor::transact (txn, params, this);
|
||||
|
||||
if (terResult == temUNKNOWN)
|
||||
{
|
||||
WriteLog (lsWARNING, TransactionEngine) <<
|
||||
"applyTransaction: Invalid transaction: unknown transaction type";
|
||||
return temUNKNOWN;
|
||||
return std::make_pair(temUNKNOWN, false);
|
||||
}
|
||||
|
||||
if (ShouldLog (lsDEBUG, TransactionEngine))
|
||||
@@ -140,15 +141,16 @@ TER TransactionEngine::applyTransaction (
|
||||
" : " << strHuman;
|
||||
}
|
||||
|
||||
if (isTesSuccess (terResult))
|
||||
didApply = true;
|
||||
else if (isTecClaim (terResult) && !(params & tapRETRY))
|
||||
bool didApply = isTesSuccess (terResult);
|
||||
|
||||
if (isTecClaim (terResult) && !(params & tapRETRY))
|
||||
{
|
||||
// only claim the transaction fee
|
||||
WriteLog (lsDEBUG, TransactionEngine) << "Reprocessing to only claim fee";
|
||||
WriteLog (lsDEBUG, TransactionEngine) <<
|
||||
"Reprocessing tx " << txID << " to only claim fee";
|
||||
mNodes.clear ();
|
||||
|
||||
SLE::pointer txnAcct = entryCache (ltACCOUNT_ROOT,
|
||||
SLE::pointer txnAcct = mNodes.entryCache (ltACCOUNT_ROOT,
|
||||
getAccountRootIndex (txn.getSourceAccount ()));
|
||||
|
||||
if (!txnAcct)
|
||||
@@ -182,18 +184,18 @@ TER TransactionEngine::applyTransaction (
|
||||
fee = balance;
|
||||
txnAcct->setFieldAmount (sfBalance, balance - fee);
|
||||
txnAcct->setFieldU32 (sfSequence, t_seq + 1);
|
||||
entryModify (txnAcct);
|
||||
mNodes.entryModify (txnAcct);
|
||||
didApply = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
WriteLog (lsDEBUG, TransactionEngine) << "Not applying transaction " << txID;
|
||||
|
||||
if (didApply)
|
||||
else if (!didApply)
|
||||
{
|
||||
if (!checkInvariants (terResult, txn, params))
|
||||
WriteLog (lsDEBUG, TransactionEngine) << "Not applying transaction " << txID;
|
||||
}
|
||||
|
||||
if (didApply && !checkInvariants (terResult, txn, params))
|
||||
{
|
||||
WriteLog (lsFATAL, TransactionEngine) <<
|
||||
"Transaction violates invariants";
|
||||
@@ -206,7 +208,8 @@ TER TransactionEngine::applyTransaction (
|
||||
didApply = false;
|
||||
terResult = tefINTERNAL;
|
||||
}
|
||||
else
|
||||
|
||||
if (didApply)
|
||||
{
|
||||
// Transaction succeeded fully or (retries are not allowed and the
|
||||
// transaction could claim a fee)
|
||||
@@ -223,7 +226,7 @@ TER TransactionEngine::applyTransaction (
|
||||
if (!mLedger->addTransaction (txID, s))
|
||||
{
|
||||
WriteLog (lsFATAL, TransactionEngine) <<
|
||||
"Tried to add transaction to open ledger that already had it";
|
||||
"Duplicate transaction applied";
|
||||
assert (false);
|
||||
throw std::runtime_error ("Duplicate transaction applied");
|
||||
}
|
||||
@@ -233,7 +236,7 @@ TER TransactionEngine::applyTransaction (
|
||||
if (!mLedger->addTransaction (txID, s, m))
|
||||
{
|
||||
WriteLog (lsFATAL, TransactionEngine) <<
|
||||
"Tried to add transaction to ledger that already had it";
|
||||
"Duplicate transaction applied to closed ledger";
|
||||
assert (false);
|
||||
throw std::runtime_error ("Duplicate transaction applied to closed ledger");
|
||||
}
|
||||
@@ -243,9 +246,7 @@ TER TransactionEngine::applyTransaction (
|
||||
mLedger->destroyCoins (saPaid.getNValue ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mTxnAccount.reset ();
|
||||
mNodes.clear ();
|
||||
|
||||
if (!(params & tapOPEN_LEDGER) && isTemMalformed (terResult))
|
||||
@@ -253,7 +254,19 @@ TER TransactionEngine::applyTransaction (
|
||||
// XXX Malformed or failed transaction in closed ledger must bow out.
|
||||
}
|
||||
|
||||
return terResult;
|
||||
return { terResult, didApply };
|
||||
}
|
||||
|
||||
bool
|
||||
TransactionEngine::checkInvariants (
|
||||
TER result,
|
||||
STTx const& txn,
|
||||
TransactionEngineParams params)
|
||||
{
|
||||
// VFALCO I deleted a bunch of code that was wrapped in #if 0.
|
||||
// If you need it, check the commit log.
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // ripple
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include <ripple/app/ledger/Ledger.h>
|
||||
#include <ripple/app/ledger/LedgerEntrySet.h>
|
||||
#include <utility>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
@@ -39,67 +40,45 @@ public:
|
||||
private:
|
||||
LedgerEntrySet mNodes;
|
||||
|
||||
TER setAuthorized (const STTx & txn, bool bMustSetGenerator);
|
||||
TER checkSig (const STTx & txn);
|
||||
void txnWrite ();
|
||||
|
||||
protected:
|
||||
Ledger::pointer mLedger;
|
||||
int mTxnSeq;
|
||||
|
||||
Account mTxnAccountID;
|
||||
SLE::pointer mTxnAccount;
|
||||
|
||||
void txnWrite ();
|
||||
int mTxnSeq = 0;
|
||||
|
||||
public:
|
||||
typedef std::shared_ptr<TransactionEngine> pointer;
|
||||
TransactionEngine () = default;
|
||||
|
||||
TransactionEngine () : mTxnSeq (0)
|
||||
{
|
||||
;
|
||||
}
|
||||
TransactionEngine (Ledger::ref ledger) : mLedger (ledger), mTxnSeq (0)
|
||||
TransactionEngine (Ledger::ref ledger)
|
||||
: mLedger (ledger)
|
||||
{
|
||||
assert (mLedger);
|
||||
}
|
||||
|
||||
LedgerEntrySet& view ()
|
||||
LedgerEntrySet&
|
||||
view ()
|
||||
{
|
||||
return mNodes;
|
||||
}
|
||||
Ledger::ref getLedger ()
|
||||
|
||||
Ledger::ref
|
||||
getLedger ()
|
||||
{
|
||||
return mLedger;
|
||||
}
|
||||
void setLedger (Ledger::ref ledger)
|
||||
|
||||
void
|
||||
setLedger (Ledger::ref ledger)
|
||||
{
|
||||
assert (ledger);
|
||||
mLedger = ledger;
|
||||
}
|
||||
|
||||
// VFALCO TODO Remove these pointless wrappers
|
||||
SLE::pointer entryCreate (LedgerEntryType type, uint256 const& index)
|
||||
{
|
||||
return mNodes.entryCreate (type, index);
|
||||
}
|
||||
std::pair<TER, bool>
|
||||
applyTransaction (STTx const&, TransactionEngineParams);
|
||||
|
||||
SLE::pointer entryCache (LedgerEntryType type, uint256 const& index)
|
||||
{
|
||||
return mNodes.entryCache (type, index);
|
||||
}
|
||||
|
||||
void entryDelete (SLE::ref sleEntry)
|
||||
{
|
||||
mNodes.entryDelete (sleEntry);
|
||||
}
|
||||
|
||||
void entryModify (SLE::ref sleEntry)
|
||||
{
|
||||
mNodes.entryModify (sleEntry);
|
||||
}
|
||||
|
||||
TER applyTransaction (const STTx&, TransactionEngineParams, bool & didApply);
|
||||
bool checkInvariants (TER result, const STTx & txn, TransactionEngineParams params);
|
||||
bool
|
||||
checkInvariants (TER result, STTx const& txn, TransactionEngineParams params);
|
||||
};
|
||||
|
||||
inline TransactionEngineParams operator| (const TransactionEngineParams& l1, const TransactionEngineParams& l2)
|
||||
|
||||
@@ -39,7 +39,7 @@ CreateOffer::checkAcceptAsset(IssueRef issue) const
|
||||
/* Only valid for custom currencies */
|
||||
assert (!isXRP (issue.currency));
|
||||
|
||||
SLE::pointer const issuerAccount = mEngine->entryCache (
|
||||
SLE::pointer const issuerAccount = mEngine->view().entryCache (
|
||||
ltACCOUNT_ROOT, getAccountRootIndex (issue.account));
|
||||
|
||||
if (!issuerAccount)
|
||||
@@ -55,7 +55,7 @@ CreateOffer::checkAcceptAsset(IssueRef issue) const
|
||||
|
||||
if (issuerAccount->getFieldU32 (sfFlags) & lsfRequireAuth)
|
||||
{
|
||||
SLE::pointer const trustLine (mEngine->entryCache (
|
||||
SLE::pointer const trustLine (mEngine->view().entryCache (
|
||||
ltRIPPLE_STATE, getRippleStateIndex (
|
||||
mTxnAccountID, issue.account, issue.currency)));
|
||||
|
||||
@@ -236,7 +236,7 @@ CreateOffer::doApply()
|
||||
|
||||
view.bumpSeq (); // Begin ledger variance.
|
||||
|
||||
SLE::pointer sleCreator = mEngine->entryCache (
|
||||
SLE::pointer sleCreator = mEngine->view().entryCache (
|
||||
ltACCOUNT_ROOT, getAccountRootIndex (mTxnAccountID));
|
||||
|
||||
if (uTxFlags & tfOfferCreateMask)
|
||||
@@ -336,7 +336,7 @@ CreateOffer::doApply()
|
||||
{
|
||||
uint256 const uCancelIndex (
|
||||
getOfferIndex (mTxnAccountID, uCancelSequence));
|
||||
SLE::pointer sleCancel = mEngine->entryCache (ltOFFER, uCancelIndex);
|
||||
SLE::pointer sleCancel = mEngine->view().entryCache (ltOFFER, uCancelIndex);
|
||||
|
||||
// It's not an error to not find the offer to cancel: it might have
|
||||
// been consumed or removed as we are processing.
|
||||
@@ -571,7 +571,7 @@ CreateOffer::doApply()
|
||||
saTakerGets.getHumanCurrency ();
|
||||
}
|
||||
|
||||
SLE::pointer sleOffer (mEngine->entryCreate (ltOFFER, uLedgerIndex));
|
||||
SLE::pointer sleOffer (mEngine->view().entryCreate (ltOFFER, uLedgerIndex));
|
||||
|
||||
sleOffer->setFieldAccount (sfAccount, mTxnAccountID);
|
||||
sleOffer->setFieldU32 (sfSequence, uSequence);
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include <ripple/app/paths/RippleState.cpp>
|
||||
#include <ripple/app/peers/UniqueNodeList.cpp>
|
||||
#include <ripple/app/transactors/Transactor.h>
|
||||
#include <ripple/app/tx/TransactionCheck.cpp>
|
||||
#include <ripple/app/tx/TransactionMaster.cpp>
|
||||
#include <ripple/app/tx/Transaction.cpp>
|
||||
#include <ripple/app/tx/TransactionEngine.cpp>
|
||||
|
||||
Reference in New Issue
Block a user