From 2d6e33f0b6d2d5b44b903ed561e1314ff83bdf85 Mon Sep 17 00:00:00 2001 From: jed Date: Thu, 28 Feb 2013 13:57:06 -0800 Subject: [PATCH 1/8] ? --- src/cpp/ripple/RippleCalc.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cpp/ripple/RippleCalc.cpp b/src/cpp/ripple/RippleCalc.cpp index 5bf438bbbe..ddeba3080a 100644 --- a/src/cpp/ripple/RippleCalc.cpp +++ b/src/cpp/ripple/RippleCalc.cpp @@ -536,8 +536,7 @@ void PathState::setCanonical( } else { - // Node 1 must be an account - + // Node 1 must be an account } } else From 9d990b82fa22a3a08ad8ca3b5698514368f44286 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 8 Mar 2013 10:23:11 -0800 Subject: [PATCH 2/8] Some cleanups. --- src/cpp/ripple/SHAMap.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/cpp/ripple/SHAMap.h b/src/cpp/ripple/SHAMap.h index 4adf29b631..30ad9e52d7 100644 --- a/src/cpp/ripple/SHAMap.h +++ b/src/cpp/ripple/SHAMap.h @@ -37,6 +37,9 @@ private: void setHash() const; +protected: + SHAMapNode(int depth, const uint256& id, bool) : mNodeID(id), mDepth(depth), mHash(0) { ; } + public: static const int rootDepth = 0; @@ -63,13 +66,14 @@ public: bool operator<(const SHAMapNode&) const; bool operator>(const SHAMapNode&) const; - bool operator==(const SHAMapNode&) const; - bool operator==(const uint256&) const; - bool operator!=(const SHAMapNode&) const; - bool operator!=(const uint256&) const; bool operator<=(const SHAMapNode&) const; bool operator>=(const SHAMapNode&) const; + bool operator==(const SHAMapNode& n) const { return (mDepth == n.mDepth) && (mNodeID == n.mNodeID); } + bool operator==(const uint256& n) const { return n == mNodeID; } + bool operator!=(const SHAMapNode& n) const { return (mDepth != n.mDepth) || (mNodeID != n.mNodeID); } + bool operator!=(const uint256& n) const { return n != mNodeID; } + virtual std::string getString() const; void dump() const; From 142280c2fc0962970e60847f77ca5262df3ec84e Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 8 Mar 2013 11:01:54 -0800 Subject: [PATCH 3/8] Missing from previous commit. --- src/cpp/ripple/SHAMapNodes.cpp | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/src/cpp/ripple/SHAMapNodes.cpp b/src/cpp/ripple/SHAMapNodes.cpp index f02c2eda0c..31dc4441eb 100644 --- a/src/cpp/ripple/SHAMapNodes.cpp +++ b/src/cpp/ripple/SHAMapNodes.cpp @@ -60,26 +60,6 @@ bool SHAMapNode::operator>=(const SHAMapNode &s) const return mNodeID >= s.mNodeID; } -bool SHAMapNode::operator==(const SHAMapNode &s) const -{ - return (s.mDepth == mDepth) && (s.mNodeID == mNodeID); -} - -bool SHAMapNode::operator!=(const SHAMapNode &s) const -{ - return (s.mDepth != mDepth) || (s.mNodeID != mNodeID); -} - -bool SHAMapNode::operator==(const uint256 &s) const -{ - return s == mNodeID; -} - -bool SHAMapNode::operator!=(const uint256 &s) const -{ - return s != mNodeID; -} - bool SMN_j = SHAMapNode::ClassInit(); bool SHAMapNode::ClassInit() @@ -102,9 +82,10 @@ uint256 SHAMapNode::getNodeID(int depth, const uint256& hash) return hash & smMasks[depth]; } -SHAMapNode::SHAMapNode(int depth, const uint256 &hash) : mNodeID(getNodeID(depth,hash)), mDepth(depth), mHash(0) +SHAMapNode::SHAMapNode(int depth, const uint256 &hash) : mNodeID(hash), mDepth(depth), mHash(0) { // canonicalize the hash to a node ID for this depth assert((depth >= 0) && (depth < 65)); + mNodeID &= smMasks[depth]; } SHAMapNode::SHAMapNode(const void *ptr, int len) : mHash(0) @@ -136,10 +117,9 @@ SHAMapNode SHAMapNode::getChildNodeID(int m) const assert((m >= 0) && (m < 16)); uint256 child(mNodeID); + child.begin()[mDepth/2] |= (mDepth & 1) ? m : (m << 4); - child.begin()[mDepth/2] |= (mDepth & 1) ? m : m << 4; - - return SHAMapNode(mDepth + 1, child); + return SHAMapNode(mDepth + 1, child, true); } int SHAMapNode::selectBranch(const uint256& hash) const From 52b7a9e54928895b7791b32e426f90d2215a3296 Mon Sep 17 00:00:00 2001 From: jed Date: Fri, 8 Mar 2013 11:35:19 -0800 Subject: [PATCH 4/8] windows --- newcoin.vcxproj | 1 - newcoin.vcxproj.filters | 3 --- src/js/sjcl | 2 +- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/newcoin.vcxproj b/newcoin.vcxproj index bf9067b2a4..21c419eb19 100644 --- a/newcoin.vcxproj +++ b/newcoin.vcxproj @@ -188,7 +188,6 @@ - diff --git a/newcoin.vcxproj.filters b/newcoin.vcxproj.filters index 98c8ac4639..e828b851f2 100644 --- a/newcoin.vcxproj.filters +++ b/newcoin.vcxproj.filters @@ -354,9 +354,6 @@ Source Files - - Source Files - Source Files diff --git a/src/js/sjcl b/src/js/sjcl index d04d0bdccd..dbdef434e7 160000 --- a/src/js/sjcl +++ b/src/js/sjcl @@ -1 +1 @@ -Subproject commit d04d0bdccd986e434b98fe393e1e01286c10fc36 +Subproject commit dbdef434e76c3f16835f3126a7ff1c717b1ce8af From fa895e0d92743fd125f0ceb4f4e391d3f86a9b20 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 8 Mar 2013 13:37:46 -0800 Subject: [PATCH 5/8] Improve WAL logging. --- src/cpp/database/SqliteDatabase.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cpp/database/SqliteDatabase.cpp b/src/cpp/database/SqliteDatabase.cpp index 7db0a623f6..aa3195daf8 100644 --- a/src/cpp/database/SqliteDatabase.cpp +++ b/src/cpp/database/SqliteDatabase.cpp @@ -239,25 +239,25 @@ void SqliteDatabase::runWal() { { boost::mutex::scoped_lock sl(walMutex); - walDBs.swap(walSet); - if (walSet.empty()) + if (walDBs.empty()) { walRunning = false; return; } + walDBs.swap(walSet); } BOOST_FOREACH(const std::string& db, walSet) { - int log, ckpt; + int log = 0, ckpt = 0; int ret = sqlite3_wal_checkpoint_v2(mConnection, db.c_str(), SQLITE_CHECKPOINT_PASSIVE, &log, &ckpt); if (ret != SQLITE_OK) { - cLog((ret == SQLITE_LOCKED) ? lsTRACE : lsWARNING) << "WAL " << mHost << ":" + cLog((ret == SQLITE_LOCKED) ? lsTRACE : lsWARNING) << "WAL " << name << ":" << db << " error " << ret; } else - cLog(lsTRACE) << "WAL(" << mHost << "): pass=" << pass << ", frames=" << log << ", written=" << ckpt; + cLog(lsTRACE) << "WAL(" << name << "): pass=" << pass << ", frames=" << log << ", written=" << ckpt; } walSet.clear(); ++pass; From 51aa48d622d790899164b0cbc9475d9815d4e2c4 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 8 Mar 2013 13:37:54 -0800 Subject: [PATCH 6/8] Lok TOO_BUSY errors. --- src/cpp/ripple/RPCHandler.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index 76d135017a..03106fcc70 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -1163,6 +1163,7 @@ Json::Value RPCHandler::doRipplePathFind(Json::Value jvRequest, int& cost) if (theApp->getJobQueue().getJobCountGE(jtCLIENT) > 200) { + cLog(lsDEBUG) << "Too busy for RPF"; jvResult = rpcError(rpcTOO_BUSY); } else if (!jvRequest.isMember("source_account")) @@ -2892,7 +2893,10 @@ Json::Value RPCHandler::doCommand(const Json::Value& jvRequest, int iRole, int & if (cost == 0) cost = rpcCOST_DEFAULT; if ((iRole != ADMIN) && (theApp->getJobQueue().getJobCountGE(jtCLIENT) > 500)) + { + cLog(lsDEBUG) << "Too busy for command"; return rpcError(rpcTOO_BUSY); + } if (!jvRequest.isMember("command")) return rpcError(rpcCOMMAND_MISSING); From b71f16b8b81f76c996929a9ce9d9165ddd04f32f Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 8 Mar 2013 13:44:12 -0800 Subject: [PATCH 7/8] Better logging of rpcTOO_BUSY returns. --- src/cpp/ripple/RPCHandler.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index 03106fcc70..6277a88932 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -1152,6 +1152,13 @@ Json::Value RPCHandler::doRandom(Json::Value jvRequest, int& cost) // - From a trusted server, allows clients to use path without manipulation. Json::Value RPCHandler::doRipplePathFind(Json::Value jvRequest, int& cost) { + int jc = theApp->getJobQueue().getJobCountGE(jtCLIENT); + if (jc > 200) + { + cLog(lsDEBUG) << "Too busy for RPF: " << jc; + return rpcError(rpcTOO_BUSY); + } + RippleAddress raSrc; RippleAddress raDst; STAmount saDstAmount; @@ -1161,12 +1168,7 @@ Json::Value RPCHandler::doRipplePathFind(Json::Value jvRequest, int& cost) if (!lpLedger) return jvResult; - if (theApp->getJobQueue().getJobCountGE(jtCLIENT) > 200) - { - cLog(lsDEBUG) << "Too busy for RPF"; - jvResult = rpcError(rpcTOO_BUSY); - } - else if (!jvRequest.isMember("source_account")) + if (!jvRequest.isMember("source_account")) { jvResult = rpcError(rpcSRC_ACT_MISSING); } @@ -2892,10 +2894,14 @@ Json::Value RPCHandler::doCommand(const Json::Value& jvRequest, int iRole, int & { if (cost == 0) cost = rpcCOST_DEFAULT; - if ((iRole != ADMIN) && (theApp->getJobQueue().getJobCountGE(jtCLIENT) > 500)) + if (iRole != ADMIN) { - cLog(lsDEBUG) << "Too busy for command"; - return rpcError(rpcTOO_BUSY); + int jc = theApp->getJobQueue().getJobCountGE(jtCLIENT); + if (jc > 500) + { + cLog(lsDEBUG) << "Too busy for command: " << jc; + return rpcError(rpcTOO_BUSY); + } } if (!jvRequest.isMember("command")) From b10a2c7a180ea12c45172826bdda5ce477e54211 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 8 Mar 2013 13:45:43 -0800 Subject: [PATCH 8/8] Distinguish between excess server load and excessive connection work. --- src/cpp/ripple/RPCErr.cpp | 1 + src/cpp/ripple/RPCErr.h | 1 + src/cpp/ripple/WSConnection.h | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cpp/ripple/RPCErr.cpp b/src/cpp/ripple/RPCErr.cpp index 4696300604..de0216f2cb 100644 --- a/src/cpp/ripple/RPCErr.cpp +++ b/src/cpp/ripple/RPCErr.cpp @@ -72,6 +72,7 @@ Json::Value rpcError(int iError, Json::Value jvResult) { rpcUNKNOWN_COMMAND, "unknownCmd", "Unknown method." }, { rpcWRONG_SEED, "wrongSeed", "The regular key does not point as the master key." }, { rpcTOO_BUSY, "tooBusy", "The server is too busy to help you now." }, + { rpcSLOW_DOWN, "slowDown", "You are placing too much load on the server." }, }; int i; diff --git a/src/cpp/ripple/RPCErr.h b/src/cpp/ripple/RPCErr.h index 0da8f82be1..67ad2de4ae 100644 --- a/src/cpp/ripple/RPCErr.h +++ b/src/cpp/ripple/RPCErr.h @@ -18,6 +18,7 @@ enum { rpcNO_EVENTS, rpcNOT_STANDALONE, rpcTOO_BUSY, + rpcSLOW_DOWN, // Networking rpcNO_CLOSED, diff --git a/src/cpp/ripple/WSConnection.h b/src/cpp/ripple/WSConnection.h index 25a7fcfe3e..10b8be406b 100644 --- a/src/cpp/ripple/WSConnection.h +++ b/src/cpp/ripple/WSConnection.h @@ -93,7 +93,7 @@ public: connection_ptr ptr = mConnection.lock(); if (ptr) ptr->close(websocketpp::close::status::PROTOCOL_ERROR, "overload"); - return rpcError(rpcTOO_BUSY); + return rpcError(rpcSLOW_DOWN); } if (!jvRequest.isMember("command"))