From d0e85ff4b4b60c344c2e7e24ed54f77629cc4cf1 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 11 Feb 2013 14:50:15 -0800 Subject: [PATCH] Make sure all fee schedule changes are reported to clients. --- src/cpp/ripple/LoadManager.cpp | 23 +++++++++++++++-------- src/cpp/ripple/LoadManager.h | 4 ++-- src/cpp/ripple/NetworkOPs.cpp | 16 +++++++++++++--- src/cpp/ripple/NetworkOPs.h | 4 ++++ 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/cpp/ripple/LoadManager.cpp b/src/cpp/ripple/LoadManager.cpp index 54c70bd98c..d596ddcf61 100644 --- a/src/cpp/ripple/LoadManager.cpp +++ b/src/cpp/ripple/LoadManager.cpp @@ -242,7 +242,7 @@ void LoadFeeTrack::setRemoteFee(uint32 f) mRemoteTxnLoadFee = f; } -void LoadFeeTrack::raiseLocalFee() +bool LoadFeeTrack::raiseLocalFee() { boost::mutex::scoped_lock sl(mLock); uint32 origFee = mLocalTxnLoadFee; @@ -255,11 +255,13 @@ void LoadFeeTrack::raiseLocalFee() if (mLocalTxnLoadFee > lftFeeMax) mLocalTxnLoadFee = lftFeeMax; - tLog(origFee != mLocalTxnLoadFee, lsDEBUG) << - "Local load fee raised from " << origFee << " to " << mLocalTxnLoadFee; + if (origFee == mLocalTxnLoadFee) + return false; + cLog(lsDEBUG) << "Local load fee raised from " << origFee << " to " << mLocalTxnLoadFee; + return true; } -void LoadFeeTrack::lowerLocalFee() +bool LoadFeeTrack::lowerLocalFee() { boost::mutex::scoped_lock sl(mLock); uint32 origFee = mLocalTxnLoadFee; @@ -269,8 +271,10 @@ void LoadFeeTrack::lowerLocalFee() if (mLocalTxnLoadFee < lftNormalFee) mLocalTxnLoadFee = lftNormalFee; - tLog(origFee != mLocalTxnLoadFee, lsDEBUG) << - "Local load fee lowered from " << origFee << " to " << mLocalTxnLoadFee; + if (origFee == mLocalTxnLoadFee) + return false; + cLog(lsDEBUG) << "Local load fee lowered from " << origFee << " to " << mLocalTxnLoadFee; + return true; } Json::Value LoadFeeTrack::getJson(uint64 baseFee, uint32 referenceFeeUnits) @@ -312,10 +316,13 @@ void LoadManager::threadEntry() ++mUptime; } + bool change; if (theApp->getJobQueue().isOverloaded()) - theApp->getFeeTrack().raiseLocalFee(); + change = theApp->getFeeTrack().raiseLocalFee(); else - theApp->getFeeTrack().lowerLocalFee(); + change = theApp->getFeeTrack().lowerLocalFee(); + if (change) + theApp->getOPs().reportFeeChange(); t += boost::posix_time::seconds(1); boost::posix_time::time_duration when = t - boost::posix_time::microsec_clock::universal_time(); diff --git a/src/cpp/ripple/LoadManager.h b/src/cpp/ripple/LoadManager.h index b64394298f..825e8f7605 100644 --- a/src/cpp/ripple/LoadManager.h +++ b/src/cpp/ripple/LoadManager.h @@ -164,8 +164,8 @@ public: Json::Value getJson(uint64 baseFee, uint32 referenceFeeUnits); void setRemoteFee(uint32); - void raiseLocalFee(); - void lowerLocalFee(); + bool raiseLocalFee(); + bool lowerLocalFee(); }; diff --git a/src/cpp/ripple/NetworkOPs.cpp b/src/cpp/ripple/NetworkOPs.cpp index 7891b8dc98..4940215d9c 100644 --- a/src/cpp/ripple/NetworkOPs.cpp +++ b/src/cpp/ripple/NetworkOPs.cpp @@ -35,7 +35,8 @@ void InfoSub::onSendEmpty() NetworkOPs::NetworkOPs(boost::asio::io_service& io_service, LedgerMaster* pLedgerMaster) : mMode(omDISCONNECTED), mNeedNetworkLedger(false), mProposing(false), mValidating(false), mNetTimer(io_service), mLedgerMaster(pLedgerMaster), mCloseTimeOffset(0), mLastCloseProposers(0), - mLastCloseConvergeTime(1000 * LEDGER_IDLE_INTERVAL), mLastValidationTime(0) + mLastCloseConvergeTime(1000 * LEDGER_IDLE_INTERVAL), mLastValidationTime(0), + mLastLoadBase(256), mLastLoadFactor(256) { } @@ -1020,8 +1021,8 @@ void NetworkOPs::pubServer() jvObj["type"] = "serverStatus"; jvObj["server_status"] = strOperatingMode(); - jvObj["load_base"] = theApp->getFeeTrack().getLoadBase(); - jvObj["load_factor"] = theApp->getFeeTrack().getLoadFactor(); + jvObj["load_base"] = (mLastLoadBase = theApp->getFeeTrack().getLoadBase()); + jvObj["load_factor"] = (mLastLoadFactor = theApp->getFeeTrack().getLoadFactor()); BOOST_FOREACH(InfoSub* ispListener, mSubServer) { @@ -1285,6 +1286,15 @@ void NetworkOPs::pubLedger(Ledger::ref lpAccepted) } } +void NetworkOPs::reportFeeChange() +{ + if ((theApp->getFeeTrack().getLoadBase() == mLastLoadBase) && + (theApp->getFeeTrack().getLoadFactor() == mLastLoadFactor)) + return; + + theApp->getJobQueue().addJob(jtCLIENT, boost::bind(&NetworkOPs::pubServer, this)); +} + Json::Value NetworkOPs::transJson(const SerializedTransaction& stTxn, TER terResult, bool bAccepted, Ledger::ref lpCurrent, const std::string& strType) { Json::Value jvObj(Json::objectValue); diff --git a/src/cpp/ripple/NetworkOPs.h b/src/cpp/ripple/NetworkOPs.h index 918ea4ccfb..1adefd0347 100644 --- a/src/cpp/ripple/NetworkOPs.h +++ b/src/cpp/ripple/NetworkOPs.h @@ -116,6 +116,9 @@ protected: boost::recursive_mutex mWantedHashLock; boost::unordered_set mWantedHashes; + uint32 mLastLoadBase; + uint32 mLastLoadFactor; + void setMode(OperatingMode); Json::Value transJson(const SerializedTransaction& stTxn, TER terResult, bool bAccepted, Ledger::ref lpCurrent, const std::string& strType); @@ -257,6 +260,7 @@ public: std::list >& peekStoredProposals() { return mStoredProposals; } void storeProposal(LedgerProposal::ref proposal, const RippleAddress& peerPublic); uint256 getConsensusLCL(); + void reportFeeChange(); bool addWantedHash(const uint256& h); bool isWantedHash(const uint256& h, bool remove);