diff --git a/modules/ripple_core/functional/ripple_ILoadFeeTrack.h b/modules/ripple_core/functional/ripple_ILoadFeeTrack.h index 9662aaa89..f7fa1b2ab 100644 --- a/modules/ripple_core/functional/ripple_ILoadFeeTrack.h +++ b/modules/ripple_core/functional/ripple_ILoadFeeTrack.h @@ -32,9 +32,7 @@ public: // Scale using load as well as base rate virtual uint64 scaleFeeLoad (uint64 fee, uint64 baseFee, uint32 referenceFeeUnits, bool bAdmin) = 0; - // VFALCO NOTE This appears to be unused, so I'm hiding the declaration. - // - //virtual void setRemoteFee (uint32) = 0; + virtual void setRemoteFee (uint32) = 0; virtual uint32 getRemoteFee () = 0; virtual uint32 getLocalFee () = 0; diff --git a/src/cpp/ripple/LedgerMaster.cpp b/src/cpp/ripple/LedgerMaster.cpp index 8b8cb7d8b..cd52f306d 100644 --- a/src/cpp/ripple/LedgerMaster.cpp +++ b/src/cpp/ripple/LedgerMaster.cpp @@ -73,6 +73,7 @@ void LedgerMaster::pushLedger (Ledger::pointer newLedger) // Caller should already have properly assembled this ledger into "ready-to-close" form -- // all candidate transactions must already be applied WriteLog (lsINFO, LedgerMaster) << "PushLedger: " << newLedger->getHash (); + boost::recursive_mutex::scoped_lock ml (mLock); if (!mPubLedger) @@ -662,6 +663,16 @@ void LedgerMaster::checkAccept (uint256 const& hash, uint32 seq) mValidLedger = ledger; + uint64 fee, fee2, ref; + ref = getApp().getFeeTrack().getLoadBase(); + int count = getApp().getValidations().getFeeAverage(ledger->getHash(), ref, fee); + int count2 = getApp().getValidations().getFeeAverage(ledger->getParentHash(), ref, fee2); + + if ((count + count2) == 0) + getApp().getFeeTrack().setRemoteFee(ref); + else + getApp().getFeeTrack().setRemoteFee(((fee * count) + (fee2 * count2)) / (count + count2)); + tryPublish (); } diff --git a/src/cpp/ripple/ripple_IValidations.h b/src/cpp/ripple/ripple_IValidations.h index 566c8d180..38e338776 100644 --- a/src/cpp/ripple/ripple_IValidations.h +++ b/src/cpp/ripple/ripple_IValidations.h @@ -27,6 +27,8 @@ public: virtual int getTrustedValidationCount (uint256 const& ledger) = 0; + virtual int getFeeAverage(uint256 const& ledger, uint64 ref, uint64& fee) = 0; + virtual int getNodesAfter (uint256 const& ledger) = 0; virtual int getLoadRatio (bool overLoaded) = 0; diff --git a/src/cpp/ripple/ripple_Validations.cpp b/src/cpp/ripple/ripple_Validations.cpp index bfe464242..9d3455b95 100644 --- a/src/cpp/ripple/ripple_Validations.cpp +++ b/src/cpp/ripple/ripple_Validations.cpp @@ -205,6 +205,36 @@ private: return trusted; } + int getFeeAverage (uint256 const& ledger, uint64 ref, uint64& fee) + { + int trusted = 0; + fee = 0; + + boost::mutex::scoped_lock sl (mValidationLock); + VSpointer set = findSet (ledger); + + if (set) + { + BOOST_FOREACH (u160_val_pair & it, *set) + { + if (it.second->isTrusted ()) + { + ++trusted; + if (it.second->isFieldPresent(sfLoadFee)) + fee += it.second->getFieldU64(sfLoadFee); + else + fee += ref; + } + } + } + + if (trusted == 0) + fee = ref; + else + fee /= trusted; + return trusted; + } + int getNodesAfter (uint256 const& ledger) { // Number of trusted nodes that have moved past this ledger