Shed load if the ledger publication engine is falling behind.

This commit is contained in:
JoelKatz
2013-07-03 13:20:27 -07:00
parent bc5781e05d
commit d303e7dba8
4 changed files with 28 additions and 0 deletions

View File

@@ -25,6 +25,7 @@ Ledger::ref LedgerMaster::getCurrentSnapshot ()
int LedgerMaster::getValidatedLedgerAge () int LedgerMaster::getValidatedLedgerAge ()
{ {
boost::recursive_mutex::scoped_lock ml (mLock);
if (!mValidLedger) if (!mValidLedger)
{ {
WriteLog (lsDEBUG, LedgerMaster) << "No validated ledger"; WriteLog (lsDEBUG, LedgerMaster) << "No validated ledger";
@@ -39,6 +40,27 @@ int LedgerMaster::getValidatedLedgerAge ()
return static_cast<int> (ret); return static_cast<int> (ret);
} }
bool LedgerMaster::isCaughtUp(std::string& reason)
{
if (getValidatedLedgerAge() > 180)
{
reason = "No recently-validated ledger";
return false;
}
boost::recursive_mutex::scoped_lock ml (mLock);
if (!mValidLedger || !mPubLedger)
{
reason = "No published ledger";
return false;
}
if (mValidLedger->getLedgerSeq() > (mPubLedger->getLedgerSeq() + 3))
{
reason = "Published ledger lags validated ledger";
return false;
}
return true;
}
void LedgerMaster::addHeldTransaction (Transaction::ref transaction) void LedgerMaster::addHeldTransaction (Transaction::ref transaction)
{ {
// returns true if transaction was added // returns true if transaction was added

View File

@@ -60,6 +60,7 @@ public:
return mPubLedger; return mPubLedger;
} }
int getValidatedLedgerAge (); int getValidatedLedgerAge ();
bool isCaughtUp(std::string& reason);
TER doTransaction (SerializedTransaction::ref txn, TransactionEngineParams params, bool& didApply); TER doTransaction (SerializedTransaction::ref txn, TransactionEngineParams params, bool& didApply);

View File

@@ -829,6 +829,9 @@ bool serverOkay (std::string& reason)
return false; return false;
} }
if (!theApp->getLedgerMaster().isCaughtUp(reason))
return false;
if (theApp->getFeeTrack ().isLoaded ()) if (theApp->getFeeTrack ().isLoaded ())
{ {
reason = "Too much load"; reason = "Too much load";

View File

@@ -201,6 +201,8 @@ private:
// We do it this way in case we want to add exponential decay later // We do it this way in case we want to add exponential decay later
int now = UptimeTimer::getInstance ().getElapsedSeconds (); int now = UptimeTimer::getInstance ().getElapsedSeconds ();
boost::mutex::scoped_lock sl (mLock);
canonicalize (source, now); canonicalize (source, now);
source.mBalance += credits; source.mBalance += credits;