mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-27 22:45:52 +00:00
Compute validated ledger age from signing time
This commit is contained in:
committed by
Nik Bougalis
parent
18299c3f7a
commit
d0b28a6700
@@ -41,6 +41,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <beast/cxx14/memory.h> // <memory>
|
#include <beast/cxx14/memory.h> // <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace ripple {
|
namespace ripple {
|
||||||
|
|
||||||
@@ -91,7 +92,7 @@ public:
|
|||||||
|
|
||||||
std::atomic <std::uint32_t> mPubLedgerClose;
|
std::atomic <std::uint32_t> mPubLedgerClose;
|
||||||
std::atomic <std::uint32_t> mPubLedgerSeq;
|
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> mValidLedgerSeq;
|
||||||
std::atomic <std::uint32_t> mBuildingLedgerSeq;
|
std::atomic <std::uint32_t> mBuildingLedgerSeq;
|
||||||
|
|
||||||
@@ -125,7 +126,7 @@ public:
|
|||||||
, mPathFindNewRequest (false)
|
, mPathFindNewRequest (false)
|
||||||
, mPubLedgerClose (0)
|
, mPubLedgerClose (0)
|
||||||
, mPubLedgerSeq (0)
|
, mPubLedgerSeq (0)
|
||||||
, mValidLedgerClose (0)
|
, mValidLedgerSign (0)
|
||||||
, mValidLedgerSeq (0)
|
, mValidLedgerSeq (0)
|
||||||
, mBuildingLedgerSeq (0)
|
, mBuildingLedgerSeq (0)
|
||||||
, standalone_ (config.RUN_STANDALONE)
|
, standalone_ (config.RUN_STANDALONE)
|
||||||
@@ -168,7 +169,7 @@ public:
|
|||||||
|
|
||||||
int getValidatedLedgerAge ()
|
int getValidatedLedgerAge ()
|
||||||
{
|
{
|
||||||
std::uint32_t valClose = mValidLedgerClose.load();
|
std::uint32_t valClose = mValidLedgerSign.load();
|
||||||
if (!valClose)
|
if (!valClose)
|
||||||
{
|
{
|
||||||
WriteLog (lsDEBUG, LedgerMaster) << "No validated ledger";
|
WriteLog (lsDEBUG, LedgerMaster) << "No validated ledger";
|
||||||
@@ -190,7 +191,7 @@ public:
|
|||||||
reason = "No recently-published ledger";
|
reason = "No recently-published ledger";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
std::uint32_t validClose = mValidLedgerClose.load();
|
std::uint32_t validClose = mValidLedgerSign.load();
|
||||||
std::uint32_t pubClose = mPubLedgerClose.load();
|
std::uint32_t pubClose = mPubLedgerClose.load();
|
||||||
if (!validClose || !pubClose)
|
if (!validClose || !pubClose)
|
||||||
{
|
{
|
||||||
@@ -207,8 +208,25 @@ public:
|
|||||||
|
|
||||||
void setValidLedger(Ledger::ref l)
|
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);
|
mValidLedger.set (l);
|
||||||
mValidLedgerClose = l->getCloseTimeNC();
|
mValidLedgerSign = signTime;
|
||||||
mValidLedgerSeq = l->getLedgerSeq();
|
mValidLedgerSeq = l->getLedgerSeq();
|
||||||
getApp().getOPs().updateLocalTx (l);
|
getApp().getOPs().updateLocalTx (l);
|
||||||
getApp().getSHAMapStore().onLedgerClosed (getValidatedLedger());
|
getApp().getSHAMapStore().onLedgerClosed (getValidatedLedger());
|
||||||
|
|||||||
@@ -387,6 +387,18 @@ private:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<uint32_t>
|
||||||
|
getValidationTimes (uint256 const& hash)
|
||||||
|
{
|
||||||
|
std::vector <std::uint32_t> times;
|
||||||
|
ScopedLockType sl (mLock);
|
||||||
|
if (auto j = findSet (hash))
|
||||||
|
for (auto& it : *j)
|
||||||
|
if (it.second->isTrusted())
|
||||||
|
times.push_back (it.second->getSignTime());
|
||||||
|
return times;
|
||||||
|
}
|
||||||
|
|
||||||
void flush ()
|
void flush ()
|
||||||
{
|
{
|
||||||
bool anyNew = false;
|
bool anyNew = false;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include <ripple/protocol/STValidation.h>
|
#include <ripple/protocol/STValidation.h>
|
||||||
#include <beast/cxx14/memory.h> // <memory>
|
#include <beast/cxx14/memory.h> // <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace ripple {
|
namespace ripple {
|
||||||
|
|
||||||
@@ -64,6 +65,10 @@ public:
|
|||||||
virtual LedgerToValidationCounter getCurrentValidations (
|
virtual LedgerToValidationCounter getCurrentValidations (
|
||||||
uint256 currentLedger, uint256 previousLedger) = 0;
|
uint256 currentLedger, uint256 previousLedger) = 0;
|
||||||
|
|
||||||
|
/** Return the times of all validations for a particular ledger hash. */
|
||||||
|
virtual std::vector<std::uint32_t> getValidationTimes (
|
||||||
|
uint256 const& ledger) = 0;
|
||||||
|
|
||||||
virtual std::list <STValidation::pointer>
|
virtual std::list <STValidation::pointer>
|
||||||
getCurrentTrustedValidations () = 0;
|
getCurrentTrustedValidations () = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user