From 08f271443d4e17efd180dd135deecda7aa1316b5 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 19 Nov 2012 15:33:49 -0800 Subject: [PATCH 01/10] Start to hook this stuff up. --- src/cpp/ripple/JobQueue.cpp | 39 ++++++++++++++++++++++- src/cpp/ripple/JobQueue.h | 57 +++++++++++++++++++++------------- src/cpp/ripple/LoadMonitor.cpp | 34 +++++++++++++++----- src/cpp/ripple/LoadMonitor.h | 16 +++++----- src/cpp/ripple/NetworkOPs.cpp | 17 +--------- 5 files changed, 109 insertions(+), 54 deletions(-) diff --git a/src/cpp/ripple/JobQueue.cpp b/src/cpp/ripple/JobQueue.cpp index cbb2bee83..cdf126e23 100644 --- a/src/cpp/ripple/JobQueue.cpp +++ b/src/cpp/ripple/JobQueue.cpp @@ -68,7 +68,7 @@ void JobQueue::addJob(JobType type, const boost::function& jobFunc) boost::mutex::scoped_lock sl(mJobLock); assert(mThreadCount != 0); // do not add jobs to a queue with no threads - mJobSet.insert(Job(type, ++mLastJob, jobFunc)); + mJobSet.insert(Job(type, ++mLastJob, mJobLoads[type], jobFunc)); ++mJobCounts[type]; mJobCond.notify_one(); } @@ -108,6 +108,43 @@ std::vector< std::pair > JobQueue::getJobCounts() return ret; } +Json::Value JobQueue::getJson(int) +{ + Json::Value ret(Json::objectValue); + boost::mutex::scoped_lock sl(mJobLock); + + ret["threads"] = mThreadCount; + + Json::Value priorities = Json::arrayValue; + for (int i = 0; i < NUM_JOB_TYPES; ++i) + { + uint64 count, latencyAvg, latencyPeak, jobCount; + mJobLoads[i].getCountAndLatency(count, latencyAvg, latencyPeak); + std::map::iterator it = mJobCounts.find(static_cast(i)); + if (it == mJobCounts.end()) + jobCount = 0; + else + jobCount = it->second; + if ((count != 0) || (jobCount != 0) || (latencyPeak != 0)) + { + Json::Value pri(Json::objectValue); + pri["priority_level"] = Job::toString(static_cast(i)); + if (count != 0) + pri["waiting"] = static_cast(jobCount); + if (jobCount != 0) + pri["per_second"] = static_cast(count); + if (latencyPeak != 0) + pri["peak_latency"] = static_cast(latencyPeak); + if (latencyAvg != 0) + pri["avg_latency"] = static_cast(latencyAvg); + priorities.append(pri); + } + } + ret["priorities"] = priorities; + + return ret; +} + void JobQueue::shutdown() { // shut down the job queue without completing pending jobs cLog(lsINFO) << "Job queue shutting down"; diff --git a/src/cpp/ripple/JobQueue.h b/src/cpp/ripple/JobQueue.h index bdd23bc69..060c9f1da 100644 --- a/src/cpp/ripple/JobQueue.h +++ b/src/cpp/ripple/JobQueue.h @@ -8,26 +8,31 @@ #include #include #include +#include + +#include "../json/value.h" #include "types.h" +#include "LoadMonitor.h" // Note that this queue should only be used for CPU-bound jobs // It is primarily intended for signature checking enum JobType { // must be in priority order, low to high - jtINVALID, - jtVALIDATION_ut, // A validation from an untrusted source - jtCLIENTOP_ut, // A client operation from a non-local/untrusted source - jtTRANSACTION, // A transaction received from the network - jtPROPOSAL_ut, // A proposal from an untrusted source - jtCLIENTOP_t, // A client operation from a trusted source - jtVALIDATION_t, // A validation from a trusted source - jtTRANSACTION_l, // A local transaction - jtPROPOSAL_t, // A proposal from a trusted source - jtADMIN, // An administrative operation - jtDEATH, // job of death, used internally + jtINVALID = -1, + jtVALIDATION_ut = 0, // A validation from an untrusted source + jtCLIENTOP_ut = 1, // A client operation from a non-local/untrusted source + jtTRANSACTION = 2, // A transaction received from the network + jtPROPOSAL_ut = 3, // A proposal from an untrusted source + jtCLIENTOP_t = 4, // A client operation from a trusted source + jtVALIDATION_t = 5, // A validation from a trusted source + jtTRANSACTION_l = 6, // A local transaction + jtPROPOSAL_t = 7, // A proposal from a trusted source + jtADMIN = 8, // An administrative operation + jtDEATH = 9, // job of death, used internally }; +#define NUM_JOB_TYPES 10 class Job { @@ -35,13 +40,18 @@ protected: JobType mType; uint64 mJobIndex; boost::function mJob; + LoadEvent::pointer mLoadMonitor; public: - Job() : mType(jtINVALID), mJobIndex(0) { ; } - Job(JobType type, uint64 index) : mType(type), mJobIndex(index) { ; } - Job(JobType type, uint64 index, const boost::function& job) - : mType(type), mJobIndex(index), mJob(job) { ; } + Job() : mType(jtINVALID), mJobIndex(0) { ; } + + Job(JobType type, uint64 index) : mType(type), mJobIndex(index) + { ; } + + Job(JobType type, uint64 index, LoadMonitor& lm, const boost::function& job) + : mType(type), mJobIndex(index), mJob(job) + { mLoadMonitor = boost::make_shared(boost::ref(lm), true, 1); } JobType getType() const { return mType; } void doJob(void) { mJob(*this); } @@ -57,14 +67,15 @@ public: class JobQueue { protected: - boost::mutex mJobLock; - boost::condition_variable mJobCond; + boost::mutex mJobLock; + boost::condition_variable mJobCond; - uint64 mLastJob; - std::set mJobSet; - std::map mJobCounts; - int mThreadCount; - bool mShuttingDown; + uint64 mLastJob; + std::set mJobSet; + std::map mJobCounts; + LoadMonitor mJobLoads[NUM_JOB_TYPES]; + int mThreadCount; + bool mShuttingDown; void threadEntry(void); @@ -81,6 +92,8 @@ public: void shutdown(); void setThreadCount(int c = 0); + + Json::Value getJson(int c = 0); }; #endif diff --git a/src/cpp/ripple/LoadMonitor.cpp b/src/cpp/ripple/LoadMonitor.cpp index 76e23ccf4..55470eab7 100644 --- a/src/cpp/ripple/LoadMonitor.cpp +++ b/src/cpp/ripple/LoadMonitor.cpp @@ -11,7 +11,8 @@ void LoadMonitor::LoadMonitor::update() { // way out of date mCounts = 0; mLatencyEvents = 0; - mLatencyMS = 0; + mLatencyMSAvg = 0; + mLatencyMSPeak = 0; mLastUpdate = now; return; } @@ -21,7 +22,8 @@ void LoadMonitor::LoadMonitor::update() ++mLastUpdate; mCounts -= (mCounts / 4); mLatencyEvents -= (mLatencyEvents / 4); - mLatencyMS -= (mLatencyMS / 4); + mLatencyMSAvg -= (mLatencyMSAvg / 4); + mLatencyMSPeak -= (mLatencyMSPeak / 4); } while (mLastUpdate < now); } @@ -38,8 +40,14 @@ void LoadMonitor::addLatency(int latency) boost::mutex::scoped_lock sl(mLock); update(); + ++mLatencyEvents; - mLatencyMS += latency; + mLatencyMSAvg += latency; + mLatencyMSPeak += latency; + + int lp = mLatencyEvents * latency * 4; + if (mLatencyMSPeak < lp) + mLatencyMSPeak = lp; } void LoadMonitor::addCountAndLatency(int counts, int latency) @@ -49,10 +57,15 @@ void LoadMonitor::addCountAndLatency(int counts, int latency) update(); mCounts += counts; ++mLatencyEvents; - mLatencyMS += latency; + mLatencyMSAvg += latency; + mLatencyMSPeak += latency; + + int lp = mLatencyEvents * latency * 4; + if (mLatencyMSPeak < lp) + mLatencyMSPeak = lp; } -void LoadMonitor::getCountAndLatency(uint64& count, uint64& latency) +void LoadMonitor::getCountAndLatency(uint64& count, uint64& latencyAvg, uint64& latencyPeak) { boost::mutex::scoped_lock sl(mLock); @@ -61,6 +74,13 @@ void LoadMonitor::getCountAndLatency(uint64& count, uint64& latency) count = mCounts / 4; if (mLatencyEvents == 0) - latency = 0; - else latency = mLatencyMS / (mLatencyEvents * 4); + { + latencyAvg = 0; + latencyPeak = 0; + } + else + { + latencyAvg = mLatencyMSAvg / (mLatencyEvents * 4); + latencyPeak = mLatencyMSPeak / (mLatencyEvents * 4); + } } diff --git a/src/cpp/ripple/LoadMonitor.h b/src/cpp/ripple/LoadMonitor.h index 17d7cf8a5..08c2afbf2 100644 --- a/src/cpp/ripple/LoadMonitor.h +++ b/src/cpp/ripple/LoadMonitor.h @@ -4,6 +4,7 @@ #include #include +#include #include "types.h" @@ -12,32 +13,31 @@ class LoadMonitor { protected: - std::string mName; uint64 mCounts; uint64 mLatencyEvents; - uint64 mLatencyMS; + uint64 mLatencyMSAvg; + uint64 mLatencyMSPeak; time_t mLastUpdate; boost::mutex mLock; void update(); public: - LoadMonitor(const std::string& n) : mName(n), mCounts(0), mLatencyEvents(0), mLatencyMS(0) + LoadMonitor() : mCounts(0), mLatencyEvents(0), mLatencyMSAvg(0), mLatencyMSPeak(0) { mLastUpdate = time(NULL); } - void setName(const std::string& n) { mName = n; } - - const std::string& getName() const { return mName; } - void addCount(int counts); void addLatency(int latency); void addCountAndLatency(int counts, int latency); - void getCountAndLatency(uint64& count, uint64& latency); + void getCountAndLatency(uint64& count, uint64& latencyAvg, uint64& latencyPeak); }; class LoadEvent { +public: + typedef boost::shared_ptr pointer; + protected: LoadMonitor& mMonitor; bool mRunning; diff --git a/src/cpp/ripple/NetworkOPs.cpp b/src/cpp/ripple/NetworkOPs.cpp index 89a5d77e7..546e75909 100644 --- a/src/cpp/ripple/NetworkOPs.cpp +++ b/src/cpp/ripple/NetworkOPs.cpp @@ -957,22 +957,7 @@ Json::Value NetworkOPs::getServerInfo() if (mConsensus) info["consensus"] = mConsensus->getJson(); - typedef std::pair jt_int_pair; - bool anyJobs = false; - Json::Value jobs = Json::arrayValue; - std::vector< std::pair > jobCounts = theApp->getJobQueue().getJobCounts(); - BOOST_FOREACH(jt_int_pair& it, jobCounts) - { - if (it.second != 0) - { - Json::Value o = Json::objectValue; - o[Job::toString(it.first)] = it.second; - jobs.append(o); - anyJobs = true; - } - } - if (anyJobs) - info["jobs"] = jobs; + info["jobs"] = theApp->getJobQueue().getJson(); return info; } From 19d73bd4779094b65e1492140276b1c5b3ee0ac3 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 19 Nov 2012 15:41:45 -0800 Subject: [PATCH 02/10] More tie ins. --- src/cpp/ripple/JobQueue.cpp | 3 ++- src/cpp/ripple/JobQueue.h | 9 ++++++++- src/cpp/ripple/Peer.cpp | 5 ++++- src/cpp/ripple/WSHandler.h | 5 ++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/cpp/ripple/JobQueue.cpp b/src/cpp/ripple/JobQueue.cpp index cdf126e23..d0e32610c 100644 --- a/src/cpp/ripple/JobQueue.cpp +++ b/src/cpp/ripple/JobQueue.cpp @@ -1,6 +1,5 @@ #include "JobQueue.h" -#include #include #include #include @@ -21,6 +20,8 @@ const char* Job::toString(JobType t) case jtPROPOSAL_t: return "trustedProposal"; case jtADMIN: return "administration"; case jtDEATH: return "jobOfDeath"; + case jtCLIENT: return "clientCommand"; + case jtPEER: return "peerCommand"; default: assert(false); return "unknown"; } } diff --git a/src/cpp/ripple/JobQueue.h b/src/cpp/ripple/JobQueue.h index 060c9f1da..33694c255 100644 --- a/src/cpp/ripple/JobQueue.h +++ b/src/cpp/ripple/JobQueue.h @@ -31,8 +31,12 @@ enum JobType jtPROPOSAL_t = 7, // A proposal from a trusted source jtADMIN = 8, // An administrative operation jtDEATH = 9, // job of death, used internally + +// special types not dispatched by the job pool + jtCLIENT = 10, + jtPEER = 11, }; -#define NUM_JOB_TYPES 10 +#define NUM_JOB_TYPES 16 class Job { @@ -93,6 +97,9 @@ public: void shutdown(); void setThreadCount(int c = 0); + LoadEvent::pointer getLoadEvent(JobType t) + { return boost::make_shared(boost::ref(mJobLoads[t]), true, 1); } + Json::Value getJson(int c = 0); }; diff --git a/src/cpp/ripple/Peer.cpp b/src/cpp/ripple/Peer.cpp index f364df838..76e396b3e 100644 --- a/src/cpp/ripple/Peer.cpp +++ b/src/cpp/ripple/Peer.cpp @@ -373,8 +373,11 @@ void Peer::processReadBuffer() // std::cerr << "Peer::processReadBuffer: " << mIpPort.first << " " << mIpPort.second << std::endl; - // If connected and get a mtHELLO or if not connected and get a non-mtHELLO, wrong message was sent. + LoadEvent::pointer event = theApp->getJobQueue().getLoadEvent(jtPEER); + boost::recursive_mutex::scoped_lock sl(theApp->getMasterLock()); + + // If connected and get a mtHELLO or if not connected and get a non-mtHELLO, wrong message was sent. if (mHelloed == (type == ripple::mtHELLO)) { cLog(lsWARNING) << "Wrong message type: " << type; diff --git a/src/cpp/ripple/WSHandler.h b/src/cpp/ripple/WSHandler.h index 43c9a9ce6..306647c5c 100644 --- a/src/cpp/ripple/WSHandler.h +++ b/src/cpp/ripple/WSHandler.h @@ -1,6 +1,8 @@ #ifndef __WSHANDLER__ #define __WSHANDLER__ +#include "Application.h" + class WSConnection; // A single instance of this object is made. @@ -87,10 +89,11 @@ public: void on_message(connection_ptr cpClient, message_ptr mpMessage) { + LoadEvent::pointer event = theApp->getJobQueue().getLoadEvent(jtCLIENT); Json::Value jvRequest; Json::Reader jrReader; - cLog(lsDEBUG) << "Ws:: Receiving '" << mpMessage->get_payload() << "'"; + cLog(lsDEBUG) << "Ws:: Receiving '" << mpMessage->get_payload() << "'"; if (mpMessage->get_opcode() != websocketpp::frame::opcode::TEXT) { From cec3aaf4b33b156d5c90d5df75bbe812f2631ba0 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 19 Nov 2012 15:43:55 -0800 Subject: [PATCH 03/10] Bugfixes. --- src/cpp/ripple/JobQueue.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cpp/ripple/JobQueue.cpp b/src/cpp/ripple/JobQueue.cpp index d0e32610c..3c6329576 100644 --- a/src/cpp/ripple/JobQueue.cpp +++ b/src/cpp/ripple/JobQueue.cpp @@ -130,9 +130,9 @@ Json::Value JobQueue::getJson(int) { Json::Value pri(Json::objectValue); pri["priority_level"] = Job::toString(static_cast(i)); - if (count != 0) - pri["waiting"] = static_cast(jobCount); if (jobCount != 0) + pri["waiting"] = static_cast(jobCount); + if (count != 0) pri["per_second"] = static_cast(count); if (latencyPeak != 0) pri["peak_latency"] = static_cast(latencyPeak); From 82c4d81b0e2346df5d0fd1eaf3685481af8ff277 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 19 Nov 2012 15:44:54 -0800 Subject: [PATCH 04/10] Better naming. --- src/cpp/ripple/JobQueue.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cpp/ripple/JobQueue.cpp b/src/cpp/ripple/JobQueue.cpp index 3c6329576..a371875dd 100644 --- a/src/cpp/ripple/JobQueue.cpp +++ b/src/cpp/ripple/JobQueue.cpp @@ -129,7 +129,7 @@ Json::Value JobQueue::getJson(int) if ((count != 0) || (jobCount != 0) || (latencyPeak != 0)) { Json::Value pri(Json::objectValue); - pri["priority_level"] = Job::toString(static_cast(i)); + pri["job_type"] = Job::toString(static_cast(i)); if (jobCount != 0) pri["waiting"] = static_cast(jobCount); if (count != 0) @@ -141,7 +141,7 @@ Json::Value JobQueue::getJson(int) priorities.append(pri); } } - ret["priorities"] = priorities; + ret["job_types"] = priorities; return ret; } From b79a927c28878aae1d1a17fdbe526738b40459b4 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 19 Nov 2012 15:45:35 -0800 Subject: [PATCH 05/10] Tweak. --- src/cpp/ripple/NetworkOPs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp/ripple/NetworkOPs.cpp b/src/cpp/ripple/NetworkOPs.cpp index 546e75909..ed4847f9b 100644 --- a/src/cpp/ripple/NetworkOPs.cpp +++ b/src/cpp/ripple/NetworkOPs.cpp @@ -957,7 +957,7 @@ Json::Value NetworkOPs::getServerInfo() if (mConsensus) info["consensus"] = mConsensus->getJson(); - info["jobs"] = theApp->getJobQueue().getJson(); + info["load"] = theApp->getJobQueue().getJson(); return info; } From 11088937a485da46b99c92473323e73d78548515 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 19 Nov 2012 17:08:58 -0800 Subject: [PATCH 06/10] Track special disk accesses. --- src/cpp/ripple/HashedObject.cpp | 1 + src/cpp/ripple/JobQueue.cpp | 1 + src/cpp/ripple/JobQueue.h | 1 + src/cpp/ripple/Ledger.cpp | 1 + src/cpp/ripple/ValidationCollection.cpp | 1 + 5 files changed, 5 insertions(+) diff --git a/src/cpp/ripple/HashedObject.cpp b/src/cpp/ripple/HashedObject.cpp index aa5dc5661..7505a4c24 100644 --- a/src/cpp/ripple/HashedObject.cpp +++ b/src/cpp/ripple/HashedObject.cpp @@ -60,6 +60,7 @@ void HashedObjectStore::waitWrite() void HashedObjectStore::bulkWrite() { + LoadEvent::pointer event = theApp->getJobQueue().getLoadEvent(jtDISK); while (1) { std::vector< boost::shared_ptr > set; diff --git a/src/cpp/ripple/JobQueue.cpp b/src/cpp/ripple/JobQueue.cpp index a371875dd..a72e8ddae 100644 --- a/src/cpp/ripple/JobQueue.cpp +++ b/src/cpp/ripple/JobQueue.cpp @@ -22,6 +22,7 @@ const char* Job::toString(JobType t) case jtDEATH: return "jobOfDeath"; case jtCLIENT: return "clientCommand"; case jtPEER: return "peerCommand"; + case jtDISK: return "diskAccess"; default: assert(false); return "unknown"; } } diff --git a/src/cpp/ripple/JobQueue.h b/src/cpp/ripple/JobQueue.h index 33694c255..339804d20 100644 --- a/src/cpp/ripple/JobQueue.h +++ b/src/cpp/ripple/JobQueue.h @@ -35,6 +35,7 @@ enum JobType // special types not dispatched by the job pool jtCLIENT = 10, jtPEER = 11, + jtDISK = 12, }; #define NUM_JOB_TYPES 16 diff --git a/src/cpp/ripple/Ledger.cpp b/src/cpp/ripple/Ledger.cpp index 03e0a48d1..8f6d87e79 100644 --- a/src/cpp/ripple/Ledger.cpp +++ b/src/cpp/ripple/Ledger.cpp @@ -341,6 +341,7 @@ uint256 Ledger::getHash() void Ledger::saveAcceptedLedger(bool fromConsensus) { // can be called in a different thread + LoadEvent::pointer event = theApp->getJobQueue().getLoadEvent(jtDISK); cLog(lsTRACE) << "saveAcceptedLedger " << (fromConsensus ? "fromConsensus " : "fromAcquire ") << getLedgerSeq(); static boost::format ledgerExists("SELECT LedgerSeq FROM Ledgers where LedgerSeq = %d;"); static boost::format deleteLedger("DELETE FROM Ledgers WHERE LedgerSeq = %d;"); diff --git a/src/cpp/ripple/ValidationCollection.cpp b/src/cpp/ripple/ValidationCollection.cpp index acb6c2c4b..cab64a950 100644 --- a/src/cpp/ripple/ValidationCollection.cpp +++ b/src/cpp/ripple/ValidationCollection.cpp @@ -289,6 +289,7 @@ void ValidationCollection::condWrite() void ValidationCollection::doWrite() { + LoadEvent::pointer event = theApp->getJobQueue().getLoadEvent(jtDISK); static boost::format insVal("INSERT INTO LedgerValidations " "(LedgerHash,NodePubKey,Flags,SignTime,Signature) VALUES ('%s','%s','%u','%u',%s);"); From 145a7d8df0eafb81f659c7850dd013b61d8af8b5 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 19 Nov 2012 21:01:37 -0800 Subject: [PATCH 07/10] Keep 1's from getting stuck in the load monitor stats. --- src/cpp/ripple/LoadMonitor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cpp/ripple/LoadMonitor.cpp b/src/cpp/ripple/LoadMonitor.cpp index 55470eab7..2b4ab5dfb 100644 --- a/src/cpp/ripple/LoadMonitor.cpp +++ b/src/cpp/ripple/LoadMonitor.cpp @@ -20,8 +20,8 @@ void LoadMonitor::LoadMonitor::update() do { // do exponential decay ++mLastUpdate; - mCounts -= (mCounts / 4); - mLatencyEvents -= (mLatencyEvents / 4); + mCounts -= ((mCounts + 3) / 4); + mLatencyEvents -= ((mLatencyEvents + 3) / 4); mLatencyMSAvg -= (mLatencyMSAvg / 4); mLatencyMSPeak -= (mLatencyMSPeak / 4); } while (mLastUpdate < now); From e837988481898e18103c45b2fb7b0f5b086d3419 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 19 Nov 2012 21:33:19 -0800 Subject: [PATCH 08/10] Cosmetic fix. --- src/cpp/ripple/LoadMonitor.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cpp/ripple/LoadMonitor.cpp b/src/cpp/ripple/LoadMonitor.cpp index 2b4ab5dfb..958fe2108 100644 --- a/src/cpp/ripple/LoadMonitor.cpp +++ b/src/cpp/ripple/LoadMonitor.cpp @@ -37,6 +37,8 @@ void LoadMonitor::addCount(int counts) void LoadMonitor::addLatency(int latency) { + if (latency == 1) + latency = 0; boost::mutex::scoped_lock sl(mLock); update(); @@ -52,6 +54,8 @@ void LoadMonitor::addLatency(int latency) void LoadMonitor::addCountAndLatency(int counts, int latency) { + if (latency == 1) + latency = 0; boost::mutex::scoped_lock sl(mLock); update(); From 280f832c14db5277227d7cb1386d60b6797c3062 Mon Sep 17 00:00:00 2001 From: jed Date: Tue, 20 Nov 2012 06:31:58 -0800 Subject: [PATCH 09/10] regular key set fee --- ripple2010.vcxproj | 1 + ripple2010.vcxproj.filters | 3 ++ src/cpp/ripple/LoadMonitor.cpp | 2 +- src/cpp/ripple/PaymentTransactor.cpp | 9 +++++- src/cpp/ripple/RegularKeySetTransactor.cpp | 35 +++++++--------------- src/cpp/ripple/RegularKeySetTransactor.h | 1 - 6 files changed, 24 insertions(+), 27 deletions(-) diff --git a/ripple2010.vcxproj b/ripple2010.vcxproj index 374a65bd6..7867ca8f9 100644 --- a/ripple2010.vcxproj +++ b/ripple2010.vcxproj @@ -122,6 +122,7 @@ + diff --git a/ripple2010.vcxproj.filters b/ripple2010.vcxproj.filters index 9e03588ae..5650c2763 100644 --- a/ripple2010.vcxproj.filters +++ b/ripple2010.vcxproj.filters @@ -345,6 +345,9 @@ Source Files + + Source Files + diff --git a/src/cpp/ripple/LoadMonitor.cpp b/src/cpp/ripple/LoadMonitor.cpp index 958fe2108..2011035ae 100644 --- a/src/cpp/ripple/LoadMonitor.cpp +++ b/src/cpp/ripple/LoadMonitor.cpp @@ -1,6 +1,6 @@ #include "LoadMonitor.h" -void LoadMonitor::LoadMonitor::update() +void LoadMonitor::update() { // call with the mutex time_t now = time(NULL); diff --git a/src/cpp/ripple/PaymentTransactor.cpp b/src/cpp/ripple/PaymentTransactor.cpp index 7577341cb..b8421d10e 100644 --- a/src/cpp/ripple/PaymentTransactor.cpp +++ b/src/cpp/ripple/PaymentTransactor.cpp @@ -9,6 +9,7 @@ void PaymentTransactor::calculateFee() { if (mTxn.getFlags() & tfCreateAccount) { + mFeeDue = theConfig.FEE_ACCOUNT_CREATE; }else Transactor::calculateFee(); } @@ -146,7 +147,13 @@ TER PaymentTransactor::doApply() else { mTxnAccount->setFieldAmount(sfBalance, saSrcXRPBalance - saDstAmount); - sleDst->setFieldAmount(sfBalance, sleDst->getFieldAmount(sfBalance) + saDstAmount); + // re-arm the password change fee if we can and need to + if ( (sleDst->getFlags() & lsfPasswordSpent) && + (saDstAmount > theConfig.FEE_DEFAULT) ) + { + sleDst->setFieldAmount(sfBalance, sleDst->getFieldAmount(sfBalance) + saDstAmount-theConfig.FEE_DEFAULT); + sleDst->clearFlag(lsfPasswordSpent); + }else sleDst->setFieldAmount(sfBalance, sleDst->getFieldAmount(sfBalance) + saDstAmount); terResult = tesSUCCESS; } diff --git a/src/cpp/ripple/RegularKeySetTransactor.cpp b/src/cpp/ripple/RegularKeySetTransactor.cpp index eb89bed28..f74b8f5a9 100644 --- a/src/cpp/ripple/RegularKeySetTransactor.cpp +++ b/src/cpp/ripple/RegularKeySetTransactor.cpp @@ -4,43 +4,30 @@ SETUP_LOG(); -// TODO: -TER RegularKeySetTransactor::checkSig() -{ - // Transaction's signing public key must be for the source account. - // To prove the master private key made this transaction. - if (mSigningPubKey.getAccountID() != mTxnAccountID) - { - // Signing Pub Key must be for Source Account ID. - cLog(lsWARNING) << "sourceAccountID: " << mSigningPubKey.humanAccountID(); - cLog(lsWARNING) << "txn accountID: " << mTxn.getSourceAccount().humanAccountID(); - return temBAD_SET_ID; - } - return tesSUCCESS; -} - -// TODO: this should be default fee if flag isn't set void RegularKeySetTransactor::calculateFee() { - mFeeDue = 0; + Transactor::calculateFee(); + + if ( !(mTxnAccount->getFlags() & lsfPasswordSpent) && + (mSigningPubKey.getAccountID() == mTxnAccountID)) + { // flag is armed and they signed with the right account + + mSourceBalance = mTxnAccount->getFieldAmount(sfBalance); + if(mSourceBalance < mFeeDue) mFeeDue = 0; + } } -// TODO: change to take a fee if there is one there TER RegularKeySetTransactor::doApply() { std::cerr << "doRegularKeySet>" << std::endl; - if (mTxnAccount->getFlags() & lsfPasswordSpent) + if(mFeeDue.isZero()) { - std::cerr << "doRegularKeySet: Delay transaction: Funds already spent." << std::endl; - - return terFUNDS_SPENT; + mTxnAccount->setFlag(lsfPasswordSpent); } - mTxnAccount->setFlag(lsfPasswordSpent); - uint160 uAuthKeyID=mTxn.getFieldAccount160(sfRegularKey); mTxnAccount->setFieldAccount(sfRegularKey, uAuthKeyID); diff --git a/src/cpp/ripple/RegularKeySetTransactor.h b/src/cpp/ripple/RegularKeySetTransactor.h index a6df0b356..35d744c8f 100644 --- a/src/cpp/ripple/RegularKeySetTransactor.h +++ b/src/cpp/ripple/RegularKeySetTransactor.h @@ -6,6 +6,5 @@ class RegularKeySetTransactor : public Transactor public: RegularKeySetTransactor(const SerializedTransaction& txn,TransactionEngineParams params, TransactionEngine* engine) : Transactor(txn,params,engine) {} TER checkFee(); - TER checkSig(); TER doApply(); }; From 9d83ce6bf2900fd05b6ba26bc55b0fef5c039e0e Mon Sep 17 00:00:00 2001 From: jed Date: Tue, 20 Nov 2012 08:22:53 -0800 Subject: [PATCH 10/10] . --- src/cpp/ripple/PaymentTransactor.cpp | 8 +++++--- test/send-test.js | 11 ++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/cpp/ripple/PaymentTransactor.cpp b/src/cpp/ripple/PaymentTransactor.cpp index b8421d10e..e2e6bceed 100644 --- a/src/cpp/ripple/PaymentTransactor.cpp +++ b/src/cpp/ripple/PaymentTransactor.cpp @@ -4,13 +4,15 @@ #define RIPPLE_PATHS_MAX 3 -// TODO: only have the higher fee if the account doesn't in fact exist +// only have the higher fee if the account doesn't in fact exist void PaymentTransactor::calculateFee() { if (mTxn.getFlags() & tfCreateAccount) { - - mFeeDue = theConfig.FEE_ACCOUNT_CREATE; + const uint160 uDstAccountID = mTxn.getFieldAccount160(sfDestination); + SLE::pointer sleDst = mEngine->entryCache(ltACCOUNT_ROOT, Ledger::getAccountRootIndex(uDstAccountID)); + if(!sleDst) mFeeDue = theConfig.FEE_ACCOUNT_CREATE; + else Transactor::calculateFee(); }else Transactor::calculateFee(); } diff --git a/test/send-test.js b/test/send-test.js index 043855714..21d261c7a 100644 --- a/test/send-test.js +++ b/test/send-test.js @@ -15,13 +15,14 @@ var serverDelay = 1500; buster.testRunner.timeout = 5000; + /* -buster.testCase("Simple", { +buster.testCase("Fee Changes", { 'setUp' : testutils.build_setup({no_server: true}), // 'tearDown' : testutils.build_teardown(), - "simple." : - function (done) { buster.assert(1); + "varying the fee for Payment" : + function (done) { this.remote.transaction() .payment('root', 'alice', "10000") @@ -36,8 +37,8 @@ buster.testCase("Simple", { }).submit(); } - }); */ - + }); + */ buster.testCase("Sending", { 'setUp' : testutils.build_setup(), 'tearDown' : testutils.build_teardown(),