Compute validated ledger age from signing time

This commit is contained in:
David Schwartz
2015-05-01 13:10:14 -07:00
committed by Nik Bougalis
parent 18299c3f7a
commit d0b28a6700
3 changed files with 40 additions and 5 deletions

View File

@@ -41,6 +41,7 @@
#include <algorithm>
#include <cassert>
#include <beast/cxx14/memory.h> // <memory>
#include <vector>
namespace ripple {
@@ -91,7 +92,7 @@ public:
std::atomic <std::uint32_t> mPubLedgerClose;
std::atomic <std::uint32_t> mPubLedgerSeq;
std::atomic <std::uint32_t> mValidLedgerClose;
std::atomic <std::uint32_t> mValidLedgerSign;
std::atomic <std::uint32_t> mValidLedgerSeq;
std::atomic <std::uint32_t> mBuildingLedgerSeq;
@@ -125,7 +126,7 @@ public:
, mPathFindNewRequest (false)
, mPubLedgerClose (0)
, mPubLedgerSeq (0)
, mValidLedgerClose (0)
, mValidLedgerSign (0)
, mValidLedgerSeq (0)
, mBuildingLedgerSeq (0)
, standalone_ (config.RUN_STANDALONE)
@@ -168,7 +169,7 @@ public:
int getValidatedLedgerAge ()
{
std::uint32_t valClose = mValidLedgerClose.load();
std::uint32_t valClose = mValidLedgerSign.load();
if (!valClose)
{
WriteLog (lsDEBUG, LedgerMaster) << "No validated ledger";
@@ -190,7 +191,7 @@ public:
reason = "No recently-published ledger";
return false;
}
std::uint32_t validClose = mValidLedgerClose.load();
std::uint32_t validClose = mValidLedgerSign.load();
std::uint32_t pubClose = mPubLedgerClose.load();
if (!validClose || !pubClose)
{
@@ -207,8 +208,25 @@ public:
void setValidLedger(Ledger::ref l)
{
std::vector <std::uint32_t> times;
std::uint32_t signTime;
if (! getConfig().RUN_STANDALONE)
times = getApp().getValidations().getValidationTimes(
l->getHash());
if (! times.empty () && times.size() >= mMinValidations)
{
// Calculate the sample median
std::sort (times.begin (), times.end ());
signTime = (times[times.size() / 2] +
times[(times.size() - 1) / 2]) / 2;
}
else
{
signTime = l->getCloseTimeNC();
}
mValidLedger.set (l);
mValidLedgerClose = l->getCloseTimeNC();
mValidLedgerSign = signTime;
mValidLedgerSeq = l->getLedgerSeq();
getApp().getOPs().updateLocalTx (l);
getApp().getSHAMapStore().onLedgerClosed (getValidatedLedger());