From f95ed4c3f502d189efa470b86f3328188a5e370d Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Sun, 23 Dec 2012 15:09:10 -0800 Subject: [PATCH 1/2] Properly handle tec return codes. This won't compile until isTecClaim exists. --- src/cpp/ripple/TransactionEngine.cpp | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/cpp/ripple/TransactionEngine.cpp b/src/cpp/ripple/TransactionEngine.cpp index e4cadfb99..825ddabb3 100644 --- a/src/cpp/ripple/TransactionEngine.cpp +++ b/src/cpp/ripple/TransactionEngine.cpp @@ -110,13 +110,31 @@ TER TransactionEngine::applyTransaction(const SerializedTransaction& txn, Transa cLog(lsINFO) << "applyTransaction: terResult=" << strToken << " : " << terResult << " : " << strHuman; - if (isTepPartial(terResult) && isSetBit(params, tapRETRY)) - { - // Partial result and allowed to retry, reclassify as a retry. - terResult = terRETRY; + bool applyTransaction = false; + + if (terResult == tesSUCCESS) + applyTransaction = true; + else if (isTepPartial(terResult) && !isSetBit(params, tapRETRY)) + applyTransaction = true; + else if (isTecClaim(terResult) && !isSetBit(params, tapRETRY)) + { // only claim the transaction fee + mNodes.clear(); + + SLE::pointer txnAcct = entryCache(ltACCOUNT_ROOT, Ledger::getAccountRootIndex(txn.getSourceAccount())); + STAmount fee = txn.getTransactionFee(); + STAmount balance = txnAcct->getFieldAmount(sfBalance); + + if (balance < fee) + terResult = terINSUF_FEE_B; + else + { + txnAcct->setFieldAmount(sfBalance, balance - fee); + applyTransaction = true; + entryModify(txnAcct); + } } - if ((tesSUCCESS == terResult) || isTepPartial(terResult)) + if (applyTransaction) { // Transaction succeeded fully or (retries are not allowed and the transaction succeeded partially). Serializer m; From f89eda7efd4f2cc809dc2f05fcfca44ec3ce46c8 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Sun, 23 Dec 2012 15:15:21 -0800 Subject: [PATCH 2/2] Fix a bug. We mishandle the sequence. --- src/cpp/ripple/TransactionEngine.cpp | 35 +++++++++++++++++++++------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/cpp/ripple/TransactionEngine.cpp b/src/cpp/ripple/TransactionEngine.cpp index 825ddabb3..1d9b33cc7 100644 --- a/src/cpp/ripple/TransactionEngine.cpp +++ b/src/cpp/ripple/TransactionEngine.cpp @@ -121,16 +121,35 @@ TER TransactionEngine::applyTransaction(const SerializedTransaction& txn, Transa mNodes.clear(); SLE::pointer txnAcct = entryCache(ltACCOUNT_ROOT, Ledger::getAccountRootIndex(txn.getSourceAccount())); - STAmount fee = txn.getTransactionFee(); - STAmount balance = txnAcct->getFieldAmount(sfBalance); - - if (balance < fee) - terResult = terINSUF_FEE_B; + if (!txnAcct) + terResult = terNO_ACCOUNT; else { - txnAcct->setFieldAmount(sfBalance, balance - fee); - applyTransaction = true; - entryModify(txnAcct); + uint32 t_seq = txn.getSequence(); + uint32 a_seq = txnAcct->getFieldU32(sfSequence); + + if (t_seq != a_seq) + { + if (a_seq < t_seq) + terResult = terPRE_SEQ; + else + terResult = tefPAST_SEQ; + } + else + { + STAmount fee = txn.getTransactionFee(); + STAmount balance = txnAcct->getFieldAmount(sfBalance); + + if (balance < fee) + terResult = terINSUF_FEE_B; + else + { + txnAcct->setFieldAmount(sfBalance, balance - fee); + txnAcct->setFieldU32(sfSequence, t_seq + 1); + applyTransaction = true; + entryModify(txnAcct); + } + } } }