mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-05 16:57:56 +00:00
Use trusted validators median fee
Conflicts: src/ripple/app/misc/Validations.cpp
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include <ripple/basics/RangeSet.h>
|
||||
#include <ripple/app/ledger/LedgerMaster.h>
|
||||
#include <ripple/validators/Manager.h>
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <beast/cxx14/memory.h> // <memory>
|
||||
|
||||
@@ -772,15 +773,25 @@ public:
|
||||
getApp().getOrderBookDB().setup(ledger);
|
||||
}
|
||||
|
||||
std::uint64_t 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);
|
||||
std::uint64_t const base = getApp().getFeeTrack().getLoadBase();
|
||||
auto fees = getApp().getValidations().fees (ledger->getHash(), base);
|
||||
{
|
||||
auto fees2 = getApp().getValidations().fees (ledger->getParentHash(), base);
|
||||
fees.reserve (fees.size() + fees2.size());
|
||||
std::copy (fees2.begin(), fees2.end(), std::back_inserter(fees));
|
||||
}
|
||||
std::uint64_t fee;
|
||||
if (! fees.empty())
|
||||
{
|
||||
std::sort (fees.begin(), fees.end());
|
||||
fee = fees[fees.size() / 2]; // median
|
||||
}
|
||||
else
|
||||
getApp().getFeeTrack().setRemoteFee(((fee * count) + (fee2 * count2)) / (count + count2));
|
||||
{
|
||||
fee = base;
|
||||
}
|
||||
|
||||
getApp().getFeeTrack().setRemoteFee(fee);
|
||||
|
||||
tryAdvance ();
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include <ripple/basics/StringUtilities.h>
|
||||
#include <beast/cxx14/memory.h> // <memory>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
namespace ripple {
|
||||
@@ -26,10 +27,10 @@ namespace ripple {
|
||||
class ValidationsImp : public Validations
|
||||
{
|
||||
private:
|
||||
typedef RippleMutex LockType;
|
||||
using LockType = std::mutex;
|
||||
typedef std::lock_guard <LockType> ScopedLockType;
|
||||
typedef beast::GenericScopedUnlock <LockType> ScopedUnlockType;
|
||||
LockType mLock;
|
||||
std::mutex mutable mLock;
|
||||
|
||||
TaggedCache<uint256, ValidationSet> mValidations;
|
||||
ValidationSet mCurrentValidations;
|
||||
@@ -233,34 +234,27 @@ private:
|
||||
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;
|
||||
fee = 0;
|
||||
|
||||
ScopedLockType sl (mLock);
|
||||
auto set = findSet (ledger);
|
||||
|
||||
std::vector <std::uint64_t> result;
|
||||
std::lock_guard <std::mutex> lock (mLock);
|
||||
auto const set = findSet (ledger);
|
||||
if (set)
|
||||
{
|
||||
for (auto& it: *set)
|
||||
for (auto const& v : *set)
|
||||
{
|
||||
if (it.second->isTrusted ())
|
||||
if (v.second->isTrusted())
|
||||
{
|
||||
++trusted;
|
||||
if (it.second->isFieldPresent(sfLoadFee))
|
||||
fee += it.second->getFieldU32(sfLoadFee);
|
||||
if (v.second->isFieldPresent(sfLoadFee))
|
||||
result.push_back(v.second->getFieldU32(sfLoadFee));
|
||||
else
|
||||
fee += ref;
|
||||
result.push_back(base);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (trusted == 0)
|
||||
fee = ref;
|
||||
else
|
||||
fee /= trusted;
|
||||
return trusted;
|
||||
return result;
|
||||
}
|
||||
|
||||
int getNodesAfter (uint256 const& ledger)
|
||||
|
||||
@@ -51,8 +51,10 @@ public:
|
||||
|
||||
virtual int getTrustedValidationCount (uint256 const& ledger) = 0;
|
||||
|
||||
virtual int getFeeAverage(
|
||||
uint256 const& ledger, std::uint64_t ref, std::uint64_t& fee) = 0;
|
||||
/** Returns fees reported by trusted validators in the given ledger. */
|
||||
virtual
|
||||
std::vector <std::uint64_t>
|
||||
fees (uint256 const& ledger, std::uint64_t base) = 0;
|
||||
|
||||
virtual int getNodesAfter (uint256 const& ledger) = 0;
|
||||
virtual int getLoadRatio (bool overLoaded) = 0;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include <ripple/http/impl/Door.h>
|
||||
#include <ripple/http/impl/Peer.h>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <beast/asio/placeholders.h>
|
||||
#include <boost/logic/tribool.hpp>
|
||||
#include <functional>
|
||||
@@ -53,7 +54,7 @@ detect_ssl (Socket& socket, StreamBuf& buf, Yield yield)
|
||||
for(;;)
|
||||
{
|
||||
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 (
|
||||
boost::asio::buffer(data), buf.data());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user