Use trusted validators median fee

Conflicts:
	src/ripple/app/misc/Validations.cpp
This commit is contained in:
Vinnie Falco
2014-09-30 18:00:40 -07:00
parent 40a955e192
commit 01e52e6f9f
4 changed files with 40 additions and 32 deletions

View File

@@ -20,6 +20,7 @@
#include <ripple/basics/RangeSet.h> #include <ripple/basics/RangeSet.h>
#include <ripple/app/ledger/LedgerMaster.h> #include <ripple/app/ledger/LedgerMaster.h>
#include <ripple/validators/Manager.h> #include <ripple/validators/Manager.h>
#include <algorithm>
#include <cassert> #include <cassert>
#include <beast/cxx14/memory.h> // <memory> #include <beast/cxx14/memory.h> // <memory>
@@ -772,15 +773,25 @@ public:
getApp().getOrderBookDB().setup(ledger); getApp().getOrderBookDB().setup(ledger);
} }
std::uint64_t fee, fee2, ref; std::uint64_t const base = getApp().getFeeTrack().getLoadBase();
ref = getApp().getFeeTrack().getLoadBase(); auto fees = getApp().getValidations().fees (ledger->getHash(), base);
int count = getApp().getValidations().getFeeAverage(ledger->getHash(), ref, fee); {
int count2 = getApp().getValidations().getFeeAverage(ledger->getParentHash(), ref, fee2); auto fees2 = getApp().getValidations().fees (ledger->getParentHash(), base);
fees.reserve (fees.size() + fees2.size());
if ((count + count2) == 0) std::copy (fees2.begin(), fees2.end(), std::back_inserter(fees));
getApp().getFeeTrack().setRemoteFee(ref); }
std::uint64_t fee;
if (! fees.empty())
{
std::sort (fees.begin(), fees.end());
fee = fees[fees.size() / 2]; // median
}
else else
getApp().getFeeTrack().setRemoteFee(((fee * count) + (fee2 * count2)) / (count + count2)); {
fee = base;
}
getApp().getFeeTrack().setRemoteFee(fee);
tryAdvance (); tryAdvance ();
} }

View File

@@ -19,6 +19,7 @@
#include <ripple/basics/StringUtilities.h> #include <ripple/basics/StringUtilities.h>
#include <beast/cxx14/memory.h> // <memory> #include <beast/cxx14/memory.h> // <memory>
#include <mutex>
#include <thread> #include <thread>
namespace ripple { namespace ripple {
@@ -26,10 +27,10 @@ namespace ripple {
class ValidationsImp : public Validations class ValidationsImp : public Validations
{ {
private: private:
typedef RippleMutex LockType; using LockType = std::mutex;
typedef std::lock_guard <LockType> ScopedLockType; typedef std::lock_guard <LockType> ScopedLockType;
typedef beast::GenericScopedUnlock <LockType> ScopedUnlockType; typedef beast::GenericScopedUnlock <LockType> ScopedUnlockType;
LockType mLock; std::mutex mutable mLock;
TaggedCache<uint256, ValidationSet> mValidations; TaggedCache<uint256, ValidationSet> mValidations;
ValidationSet mCurrentValidations; ValidationSet mCurrentValidations;
@@ -233,34 +234,27 @@ private:
return trusted; return trusted;
} }
int getFeeAverage (uint256 const& ledger, std::uint64_t ref, std::uint64_t& fee) std::vector <std::uint64_t>
fees (uint256 const& ledger, std::uint64_t base) override
{ {
int trusted = 0; std::vector <std::uint64_t> result;
fee = 0; std::lock_guard <std::mutex> lock (mLock);
auto const set = findSet (ledger);
ScopedLockType sl (mLock);
auto set = findSet (ledger);
if (set) if (set)
{ {
for (auto& it: *set) for (auto const& v : *set)
{ {
if (it.second->isTrusted ()) if (v.second->isTrusted())
{ {
++trusted; if (v.second->isFieldPresent(sfLoadFee))
if (it.second->isFieldPresent(sfLoadFee)) result.push_back(v.second->getFieldU32(sfLoadFee));
fee += it.second->getFieldU32(sfLoadFee);
else else
fee += ref; result.push_back(base);
} }
} }
} }
if (trusted == 0) return result;
fee = ref;
else
fee /= trusted;
return trusted;
} }
int getNodesAfter (uint256 const& ledger) int getNodesAfter (uint256 const& ledger)

View File

@@ -51,8 +51,10 @@ public:
virtual int getTrustedValidationCount (uint256 const& ledger) = 0; virtual int getTrustedValidationCount (uint256 const& ledger) = 0;
virtual int getFeeAverage( /** Returns fees reported by trusted validators in the given ledger. */
uint256 const& ledger, std::uint64_t ref, std::uint64_t& fee) = 0; virtual
std::vector <std::uint64_t>
fees (uint256 const& ledger, std::uint64_t base) = 0;
virtual int getNodesAfter (uint256 const& ledger) = 0; virtual int getNodesAfter (uint256 const& ledger) = 0;
virtual int getLoadRatio (bool overLoaded) = 0; virtual int getLoadRatio (bool overLoaded) = 0;

View File

@@ -19,6 +19,7 @@
#include <ripple/http/impl/Door.h> #include <ripple/http/impl/Door.h>
#include <ripple/http/impl/Peer.h> #include <ripple/http/impl/Peer.h>
#include <boost/asio/buffer.hpp>
#include <beast/asio/placeholders.h> #include <beast/asio/placeholders.h>
#include <boost/logic/tribool.hpp> #include <boost/logic/tribool.hpp>
#include <functional> #include <functional>
@@ -53,7 +54,7 @@ detect_ssl (Socket& socket, StreamBuf& buf, Yield yield)
for(;;) for(;;)
{ {
std::size_t const max = 4; // the most bytes we could need std::size_t const max = 4; // the most bytes we could need
std::array <unsigned char, max> data; unsigned char data[max];
auto const bytes = boost::asio::buffer_copy ( auto const bytes = boost::asio::buffer_copy (
boost::asio::buffer(data), buf.data()); boost::asio::buffer(data), buf.data());