Adjust our remote load fee based on validations.

This commit is contained in:
JoelKatz
2013-07-10 17:10:00 -07:00
parent e87cefd979
commit ac4843bc00
4 changed files with 44 additions and 3 deletions

View File

@@ -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 ();
}

View File

@@ -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;

View File

@@ -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