From 4e7d1cb390ab64e1e9627d2eb41abbd19ee67543 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 4 Jun 2012 19:10:30 -0700 Subject: [PATCH 1/7] Add an STAmount::operator bool() const --- src/SerializedTypes.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SerializedTypes.h b/src/SerializedTypes.h index ec0987c12b..ceadb90e52 100644 --- a/src/SerializedTypes.h +++ b/src/SerializedTypes.h @@ -274,6 +274,7 @@ public: bool isNegative() const { return mIsNegative && !isZero(); } bool isPositive() const { return !mIsNegative && !isZero(); } bool isGEZero() const { return !mIsNegative; } + operator bool() const { return !isZero(); } void changeSign() { if (!isZero()) mIsNegative = !mIsNegative; } void zero() { mOffset = mIsNative ? -100 : 0; mValue = 0; mIsNegative = false; } From 73b579aef8fe29ccb1ac7290b85c69a55101f457 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 4 Jun 2012 19:10:44 -0700 Subject: [PATCH 2/7] Cleanups and fixes. --- src/TransactionEngine.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/TransactionEngine.cpp b/src/TransactionEngine.cpp index 39691b3d3d..4bbf2774f5 100644 --- a/src/TransactionEngine.cpp +++ b/src/TransactionEngine.cpp @@ -394,7 +394,7 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran if (terSUCCESS == result && (params & tepNO_CHECK_FEE) == tepNONE) { - if (saCost) + if (!saCost.isZero()) { if (saPaid < saCost) { @@ -532,8 +532,8 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran { std::cerr << str(boost::format("applyTransaction: Delay transaction: insufficent balance: balance=%s paid=%s") - % saSrcBalance - % saPaid) + % saSrcBalance.getText() + % saPaid.getText()) << std::endl; result = terINSUF_FEE_B; @@ -548,7 +548,7 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran { nothing(); } - else if (saCost) + else if (!saCost.isZero()) { uint32 a_seq = sleSrc->getIFieldU32(sfSequence); @@ -1173,8 +1173,8 @@ TransactionEngineResult TransactionEngine::doWalletAdd(const SerializedTransacti { std::cerr << str(boost::format("WalletAdd: Delay transaction: insufficent balance: balance=%s amount=%s") - % saSrcBalance - % saAmount) + % saSrcBalance.getText() + % saAmount.getText()) << std::endl; return terUNFUNDED; From 7d2d698296ef6f0819cd898d75160c46175b5e21 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 4 Jun 2012 19:18:19 -0700 Subject: [PATCH 3/7] If we set the account sequence number to the transaction sequence, the transaction is forever repeatable! --- src/TransactionEngine.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/TransactionEngine.cpp b/src/TransactionEngine.cpp index 4bbf2774f5..979bd7d467 100644 --- a/src/TransactionEngine.cpp +++ b/src/TransactionEngine.cpp @@ -551,7 +551,7 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran else if (!saCost.isZero()) { uint32 a_seq = sleSrc->getIFieldU32(sfSequence); - + Log(lsINFO) << "Aseq=" << a_seq << ", Tseq=" << t_seq; if (t_seq != a_seq) { // WRITEME: Special case code for changing transaction key @@ -576,11 +576,12 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran } else { - sleSrc->setIFieldU32(sfSequence, t_seq); + sleSrc->setIFieldU32(sfSequence, t_seq + 1); } } else { + Log(lsINFO) << "Zero cost transaction"; if (t_seq) { std::cerr << "applyTransaction: bad sequence for pre-paid transaction" << std::endl; From e84c7924a4124276f646c140aaf0796458edff47 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 4 Jun 2012 21:37:04 -0700 Subject: [PATCH 4/7] Extra debug --- src/Ledger.cpp | 18 +++++++++++++++++- src/Ledger.h | 5 ++++- src/LedgerConsensus.cpp | 42 +++++++++++++++++++++++++++++++++++++++++ src/RPCServer.cpp | 4 ++-- 4 files changed, 65 insertions(+), 4 deletions(-) diff --git a/src/Ledger.cpp b/src/Ledger.cpp index 1fda2ca217..5a7e6e2338 100644 --- a/src/Ledger.cpp +++ b/src/Ledger.cpp @@ -302,7 +302,7 @@ Ledger::pointer Ledger::loadByHash(const uint256& ledgerHash) return getSQL(sql); } -void Ledger::addJson(Json::Value& ret) +void Ledger::addJson(Json::Value& ret, int options) { Json::Value ledger(Json::objectValue); @@ -321,6 +321,22 @@ void Ledger::addJson(Json::Value& ret) else ledger["Closed"] = false; if (mCloseTime != 0) ledger["CloseTime"] = boost::posix_time::to_simple_string(ptFromSeconds(mCloseTime)); + if ((options & LEDGER_JSON_DUMP_TXNS) != 0) + { + Json::Value txns(Json::arrayValue); + for (SHAMapItem::pointer item = mTransactionMap->peekFirstItem(); !!item; + item = mTransactionMap->peekNextItem(item->getTag())) + txns.append(item->getTag().GetHex()); + ledger["Transactions"] = txns; + } + if ((options & LEDGER_JSON_DUMP_STATE) != 0) + { + Json::Value state(Json::arrayValue); + for (SHAMapItem::pointer item = mAccountStateMap->peekFirstItem(); !!item; + item = mAccountStateMap->peekNextItem(item->getTag())) + state.append(item->getTag().GetHex()); + ledger["AccounState"] = state; + } ret[boost::lexical_cast(mLedgerSeq)] = ledger; } diff --git a/src/Ledger.h b/src/Ledger.h index d4fe92f460..00750ea9c2 100644 --- a/src/Ledger.h +++ b/src/Ledger.h @@ -32,6 +32,9 @@ enum LedgerStateParms lepERROR = 32, // error }; +#define LEDGER_JSON_DUMP_TXNS 0x10000000 +#define LEDGER_JSON_DUMP_STATE 0x20000000 + class Ledger : public boost::enable_shared_from_this { // The basic Ledger structure, can be opened, closed, or synching friend class TransactionEngine; @@ -206,7 +209,7 @@ public: bool isCompatible(boost::shared_ptr other); // bool signLedger(std::vector &signature, const LocalHanko &hanko); - void addJson(Json::Value&); + void addJson(Json::Value&, int options); static bool unitTest(); }; diff --git a/src/LedgerConsensus.cpp b/src/LedgerConsensus.cpp index d1bae73334..91a393a05c 100644 --- a/src/LedgerConsensus.cpp +++ b/src/LedgerConsensus.cpp @@ -3,6 +3,8 @@ #include #include +#include "../json/writer.h" + #include "Application.h" #include "NetworkOPs.h" #include "LedgerTiming.h" @@ -661,6 +663,17 @@ void LedgerConsensus::accept(SHAMap::pointer set) Ledger::pointer newLCL = boost::make_shared(false, boost::ref(*mPreviousLedger)); +#ifdef DEBUG + Json::StyledStreamWriter ssw; + if (1) + { + Log(lsTRACE) << "newLCL before transactions"; + Json::Value p; + newLCL->addJson(p, LEDGER_JSON_DUMP_TXNS | LEDGER_JSON_DUMP_STATE); + ssw.write(std::cerr, p); + } +#endif + std::deque failedTransactions; applyTransactions(set, newLCL, failedTransactions); newLCL->setClosed(); @@ -668,8 +681,27 @@ void LedgerConsensus::accept(SHAMap::pointer set) newLCL->updateHash(); uint256 newLCLHash = newLCL->getHash(); +#ifdef DEBUG + if (1) + { + Log(lsTRACE) << "newLCL after transactions"; + Json::Value p; + newLCL->addJson(p, LEDGER_JSON_DUMP_TXNS | LEDGER_JSON_DUMP_STATE); + ssw.write(std::cerr, p); + } +#endif + Ledger::pointer newOL = boost::make_shared(true, boost::ref(*newLCL)); +#ifdef DEBUG + if (1) + { + Log(lsTRACE) << "newOL before transactions"; + Json::Value p; + newOL->addJson(p, LEDGER_JSON_DUMP_TXNS | LEDGER_JSON_DUMP_STATE); + ssw.write(std::cerr, p); + } +#endif ScopedLock sl = theApp->getMasterLedger().getLock(); applyTransactions(theApp->getMasterLedger().getCurrentLedger()->peekTransactionMap(), @@ -677,6 +709,16 @@ void LedgerConsensus::accept(SHAMap::pointer set) theApp->getMasterLedger().pushLedger(newLCL, newOL); mState = lcsACCEPTED; +#ifdef DEBUG + if (1) + { + Log(lsTRACE) << "newOL after transactions"; + Json::Value p; + newOL->addJson(p, LEDGER_JSON_DUMP_TXNS | LEDGER_JSON_DUMP_STATE); + ssw.write(std::cerr, p); + } +#endif + sl.unlock(); SerializedValidation v(newLCLHash, mOurPosition->peekKey(), true); diff --git a/src/RPCServer.cpp b/src/RPCServer.cpp index 1460767f1b..0a2f4a87a3 100644 --- a/src/RPCServer.cpp +++ b/src/RPCServer.cpp @@ -1206,8 +1206,8 @@ Json::Value RPCServer::doLedger(Json::Value& params) if (getParamCount(params)== 0) { Json::Value ret(Json::objectValue), current(Json::objectValue), closed(Json::objectValue); - theApp->getMasterLedger().getCurrentLedger()->addJson(current); - theApp->getMasterLedger().getClosedLedger()->addJson(closed); + theApp->getMasterLedger().getCurrentLedger()->addJson(current, 0); + theApp->getMasterLedger().getClosedLedger()->addJson(closed, 0); ret["open"] = current; ret["closed"] = closed; return ret; From d8ad2fcbb5fa4303b4ed2b6394b2cdb419b01899 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 4 Jun 2012 21:45:59 -0700 Subject: [PATCH 5/7] Typo. --- src/Ledger.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ledger.cpp b/src/Ledger.cpp index 5a7e6e2338..1c5a8b7f21 100644 --- a/src/Ledger.cpp +++ b/src/Ledger.cpp @@ -335,7 +335,7 @@ void Ledger::addJson(Json::Value& ret, int options) for (SHAMapItem::pointer item = mAccountStateMap->peekFirstItem(); !!item; item = mAccountStateMap->peekNextItem(item->getTag())) state.append(item->getTag().GetHex()); - ledger["AccounState"] = state; + ledger["AccountState"] = state; } ret[boost::lexical_cast(mLedgerSeq)] = ledger; } From e685b8678c44c14109260ece826dd700a55add99 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 4 Jun 2012 21:47:04 -0700 Subject: [PATCH 6/7] Typo. --- src/TransactionEngine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TransactionEngine.cpp b/src/TransactionEngine.cpp index 979bd7d467..5126bbd4fa 100644 --- a/src/TransactionEngine.cpp +++ b/src/TransactionEngine.cpp @@ -471,7 +471,7 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran default: if (!sleSrc->getIFieldPresent(sfAuthorizedKey)) { - std::cerr << "applyTransaction: Souce is an unclaimed account." << std::endl; + std::cerr << "applyTransaction: Source is an unclaimed account." << std::endl; result = tenUNCLAIMED; } From a9876135954a93e85bcbc53893ddb40b90b2091d Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Mon, 4 Jun 2012 23:28:34 -0700 Subject: [PATCH 7/7] Fix some errors to be temporary. --- src/TransactionEngine.cpp | 7 +++---- src/TransactionEngine.h | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/TransactionEngine.cpp b/src/TransactionEngine.cpp index 5126bbd4fa..e9e71b2192 100644 --- a/src/TransactionEngine.cpp +++ b/src/TransactionEngine.cpp @@ -473,7 +473,7 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran { std::cerr << "applyTransaction: Source is an unclaimed account." << std::endl; - result = tenUNCLAIMED; + result = terUNCLAIMED; } break; } @@ -514,9 +514,9 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran // Verify the transaction's signing public key is the key authorized for signing. if (naSigningPubKey.getAccountID() != sleSrc->getIValueFieldAccount(sfAuthorizedKey).getAccountID()) { - std::cerr << "applyTransaction: Not authorized to use account." << std::endl; + std::cerr << "applyTransaction: Delay: Not authorized to use account." << std::endl; - result = tenBAD_AUTH; + result = terBAD_AUTH; } break; } @@ -651,7 +651,6 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran if (terSUCCESS == result) { // Write back the account states and add the transaction to the ledger - // WRITEME: Special case code for changing transaction key for (std::vector::iterator it = accounts.begin(), end = accounts.end(); it != end; ++it) { diff --git a/src/TransactionEngine.h b/src/TransactionEngine.h index 75b79aca07..87aec83de0 100644 --- a/src/TransactionEngine.h +++ b/src/TransactionEngine.h @@ -24,9 +24,7 @@ enum TransactionEngineResult tenBAD_SET_ID, // Malformed. // Invalid: Ledger won't allow. - tenUNCLAIMED = -200, // Can not use an unclaimed account. - tenCLAIMED, // Can not claim a previously claimed account. - tenBAD_AUTH, // Transaction's public key is not authorized. + tenCLAIMED = -200, // Can not claim a previously claimed account. tenCREATED, // Can't add an already created account. tenMSG_SET, // Can't change a message key. @@ -60,6 +58,8 @@ enum TransactionEngineResult terNO_LINE_NO_ZERO, // Can't zero non-existant line, destination might make it. terSET_MISSING_DST, // Can't set password, destination missing. terFUNDS_SPENT, // Can't set password, password set funds already spent. + terUNCLAIMED, // Can not use an unclaimed account. + terBAD_AUTH, // Transaction's public key is not authorized. }; enum TransactionEngineParams