From 6282ad4a88080daa8378951f303b67716ec70dee Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 29 Aug 2012 23:02:06 -0700 Subject: [PATCH] Clean up the TransactionEngineParameter flags. Clarify the semantics for soft failure. Note that the code will not yet invoke a transaction with a retry flag, but the support is there for transcations to handle it. --- src/LedgerConsensus.cpp | 16 ++++++++-------- src/LedgerConsensus.h | 4 ++-- src/NetworkOPs.cpp | 2 +- src/TransactionEngine.cpp | 8 ++++---- src/TransactionEngine.h | 12 ++++++------ 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/LedgerConsensus.cpp b/src/LedgerConsensus.cpp index 08df045123..46cd2deb2e 100644 --- a/src/LedgerConsensus.cpp +++ b/src/LedgerConsensus.cpp @@ -799,9 +799,9 @@ void LedgerConsensus::Saccept(boost::shared_ptr This, SHAMap::p } void LedgerConsensus::applyTransaction(TransactionEngine& engine, const SerializedTransaction::pointer& txn, - const Ledger::pointer& ledger, CanonicalTXSet& failedTransactions, bool final) + const Ledger::pointer& ledger, CanonicalTXSet& failedTransactions, bool openLedger) { - TransactionEngineParams parms = final ? (tepNO_CHECK_FEE | tepUPDATE_TOTAL | tepMETADATA) : tepNONE; + TransactionEngineParams parms = openLedger ? temOPEN_LEDGER : temFINAL; #ifndef TRUST_NETWORK try { @@ -832,9 +832,9 @@ void LedgerConsensus::applyTransaction(TransactionEngine& engine, const Serializ } void LedgerConsensus::applyTransactions(const SHAMap::pointer& set, const Ledger::pointer& applyLedger, - const Ledger::pointer& checkLedger, CanonicalTXSet& failedTransactions, bool final) + const Ledger::pointer& checkLedger, CanonicalTXSet& failedTransactions, bool openLgr) { - TransactionEngineParams parms = final ? (tepNO_CHECK_FEE | tepUPDATE_TOTAL) : tepNONE; + TransactionEngineParams parms = openLgr ? temOPEN_LEDGER : temFINAL; TransactionEngine engine(applyLedger); for (SHAMapItem::pointer item = set->peekFirstItem(); !!item; item = set->peekNextItem(item->getTag())) @@ -848,7 +848,7 @@ void LedgerConsensus::applyTransactions(const SHAMap::pointer& set, const Ledger #endif SerializerIterator sit(item->peekSerializer()); SerializedTransaction::pointer txn = boost::make_shared(boost::ref(sit)); - applyTransaction(engine, txn, applyLedger, failedTransactions, final); + applyTransaction(engine, txn, applyLedger, failedTransactions, openLgr); #ifndef TRUST_NETWORK } catch (...) @@ -906,7 +906,7 @@ void LedgerConsensus::accept(const SHAMap::pointer& set) newLCL->armDirty(); CanonicalTXSet failedTransactions(set->getHash()); - applyTransactions(set, newLCL, newLCL, failedTransactions, true); + applyTransactions(set, newLCL, newLCL, failedTransactions, false); newLCL->setClosed(); bool closeTimeCorrect = true; @@ -950,7 +950,7 @@ void LedgerConsensus::accept(const SHAMap::pointer& set) Log(lsINFO) << "Test applying disputed transaction that did not get in"; SerializerIterator sit(it.second->peekTransaction()); SerializedTransaction::pointer txn = boost::make_shared(boost::ref(sit)); - applyTransaction(engine, txn, newOL, failedTransactions, false); + applyTransaction(engine, txn, newOL, failedTransactions, true); } catch (...) { @@ -961,7 +961,7 @@ void LedgerConsensus::accept(const SHAMap::pointer& set) Log(lsINFO) << "Applying transactions from current ledger"; applyTransactions(theApp->getMasterLedger().getCurrentLedger()->peekTransactionMap(), newOL, newLCL, - failedTransactions, false); + failedTransactions, true); theApp->getMasterLedger().pushLedger(newLCL, newOL); mNewLedgerHash = newLCL->getHash(); mState = lcsACCEPTED; diff --git a/src/LedgerConsensus.h b/src/LedgerConsensus.h index e95ed6328a..362c621f6e 100644 --- a/src/LedgerConsensus.h +++ b/src/LedgerConsensus.h @@ -128,9 +128,9 @@ protected: void removePosition(LedgerProposal&, bool ours); void sendHaveTxSet(const uint256& set, bool direct); void applyTransactions(const SHAMap::pointer& transactionSet, const Ledger::pointer& targetLedger, - const Ledger::pointer& checkLedger, CanonicalTXSet& failedTransactions, bool final); + const Ledger::pointer& checkLedger, CanonicalTXSet& failedTransactions, bool openLgr); void applyTransaction(TransactionEngine& engine, const SerializedTransaction::pointer& txn, - const Ledger::pointer& targetLedger, CanonicalTXSet& failedTransactions, bool final); + const Ledger::pointer& targetLedger, CanonicalTXSet& failedTransactions, bool openLgr); // manipulating our own position void statusChange(newcoin::NodeEvent, Ledger& ledger); diff --git a/src/NetworkOPs.cpp b/src/NetworkOPs.cpp index eb0aedc5c6..58bd6290c1 100644 --- a/src/NetworkOPs.cpp +++ b/src/NetworkOPs.cpp @@ -84,7 +84,7 @@ Transaction::pointer NetworkOPs::processTransaction(Transaction::pointer trans, return trans; } - TER r = mLedgerMaster->doTransaction(*trans->getSTransaction(), tgtLedger, tepNONE); + TER r = mLedgerMaster->doTransaction(*trans->getSTransaction(), tgtLedger, temOPEN_LEDGER); if (r == tefFAILURE) throw Fault(IO_ERROR); if (r == terPRE_SEQ) diff --git a/src/TransactionEngine.cpp b/src/TransactionEngine.cpp index 9411512f3b..70f57303e8 100644 --- a/src/TransactionEngine.cpp +++ b/src/TransactionEngine.cpp @@ -973,7 +973,7 @@ TER TransactionEngine::applyTransaction(const SerializedTransaction& txn, naSigningPubKey = NewcoinAddress::createAccountPublic(txn.peekSigningPubKey()); // Consistency: really signed. - if ((tesSUCCESS == terResult) && ((params & tepNO_CHECK_SIGN) == 0) && !txn.checkSign(naSigningPubKey)) + if ((tesSUCCESS == terResult) && ((params & temNO_CHECK_SIGN) == 0) && !txn.checkSign(naSigningPubKey)) { Log(lsWARNING) << "applyTransaction: Invalid transaction: bad signature"; @@ -1032,8 +1032,8 @@ TER TransactionEngine::applyTransaction(const SerializedTransaction& txn, STAmount saPaid = txn.getTransactionFee(); - if (tesSUCCESS == terResult && (params & tepNO_CHECK_FEE) == tepNONE) - { + if (tesSUCCESS == terResult && (params & temOPEN_LEDGER) != temNONE) + { // Applying to open ledger, check fee if (!!saCost) { // XXX DO NOT CHECK ON CONSENSUS PASS @@ -1322,7 +1322,7 @@ TER TransactionEngine::applyTransaction(const SerializedTransaction& txn, if (!mLedger->addTransaction(txID, s)) assert(false); - if ((params & tepUPDATE_TOTAL) != tepNONE) + if ((params & temOPEN_LEDGER) == temNONE) mLedger->destroyCoins(saPaid.getNValue()); } diff --git a/src/TransactionEngine.h b/src/TransactionEngine.h index 4c84145800..c231e33b47 100644 --- a/src/TransactionEngine.h +++ b/src/TransactionEngine.h @@ -84,7 +84,7 @@ enum TER // aka TransactionEngineResult // 100 .. P Partial success (SR) (ripple transaction with no good paths, pay to non-existent account) // Transaction can be applied, can charge fee, forwarded, but does not achieve optimal result. - tepPARITAL = 100, + tepPARTIAL = 100, tepPATH_DRY, tepPATH_PARTIAL, }; @@ -93,11 +93,11 @@ bool transResultInfo(TER terCode, std::string& strToken, std::string& strHuman); enum TransactionEngineParams { - tepNONE = 0, - tepNO_CHECK_SIGN = 1, // Signature already checked - tepNO_CHECK_FEE = 2, // It was voted into a ledger anyway - tepUPDATE_TOTAL = 4, // Update the total coins - tepMETADATA = 5, // put metadata in tree, not transaction + temNONE = 0x00, + temNO_CHECK_SIGN = 0x01, // Signature already checked + temOPEN_LEDGER = 0x10, // Transaction is running against an open ledger + temRETRY_OK = 0x20, // It was voted into a ledger anyway + temFINAL = 0x40, // This may be the transaction's last pass }; typedef struct {