mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-29 23:45:51 +00:00
Add "syncing" state.
This commit is contained in:
@@ -26,6 +26,22 @@ Ledger::ref LedgerMaster::getCurrentSnapshot()
|
||||
return mCurrentSnapshot;
|
||||
}
|
||||
|
||||
int LedgerMaster::getValidatedLedgerAge()
|
||||
{
|
||||
if (!mValidLedger)
|
||||
{
|
||||
cLog(lsINFO) << "No validated ledger";
|
||||
return 999999;
|
||||
}
|
||||
|
||||
int64 ret = theApp->getOPs().getCloseTimeNC();
|
||||
ret -= static_cast<int64>(mValidLedger->getCloseTimeNC());
|
||||
ret = std::max(0LL, ret);
|
||||
|
||||
cLog(lsINFO) << "Validated ledger age is " << ret;
|
||||
return static_cast<int>(ret);
|
||||
}
|
||||
|
||||
void LedgerMaster::addHeldTransaction(Transaction::ref transaction)
|
||||
{ // returns true if transaction was added
|
||||
boost::recursive_mutex::scoped_lock ml(mLock);
|
||||
|
||||
@@ -83,6 +83,7 @@ public:
|
||||
|
||||
// The published ledger is the last fully validated ledger
|
||||
Ledger::ref getValidatedLedger() { return mPubLedger; }
|
||||
int getValidatedLedgerAge();
|
||||
|
||||
TER doTransaction(SerializedTransaction::ref txn, TransactionEngineParams params, bool& didApply);
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ std::string NetworkOPs::strOperatingMode()
|
||||
static const char* paStatusToken[] = {
|
||||
"disconnected",
|
||||
"connected",
|
||||
"syncing",
|
||||
"tracking",
|
||||
"full"
|
||||
};
|
||||
@@ -654,12 +655,6 @@ void NetworkOPs::tryStartConsensus()
|
||||
setMode(omFULL);
|
||||
}
|
||||
|
||||
if (mMode == omFULL)
|
||||
{
|
||||
// WRITEME
|
||||
// check if the ledger is bad enough to go to omTRACKING
|
||||
}
|
||||
|
||||
if ((!mConsensus) && (mMode != omDISCONNECTED))
|
||||
beginConsensus(networkClosed, mLedgerMaster->getCurrentLedger());
|
||||
}
|
||||
@@ -1038,6 +1033,12 @@ void NetworkOPs::setMode(OperatingMode om)
|
||||
{
|
||||
if (mMode == om) return;
|
||||
|
||||
if (om == omCONNECTED)
|
||||
{
|
||||
if (theApp->getLedgerMaster().getValidatedLedgerAge() < 60)
|
||||
om = omSYNCING;
|
||||
}
|
||||
|
||||
if ((om >= omCONNECTED) && (mMode == omDISCONNECTED))
|
||||
mConnectTime = boost::posix_time::second_clock::universal_time();
|
||||
|
||||
@@ -1398,7 +1399,7 @@ void NetworkOPs::pubLedger(Ledger::ref accepted)
|
||||
|
||||
jvObj["txn_count"] = Json::UInt(alpAccepted->getTxnCount());
|
||||
|
||||
if ((mMode == omFULL) || (mMode == omTRACKING))
|
||||
if (mMode >= omSYNCING)
|
||||
jvObj["validated_ledgers"] = theApp->getLedgerMaster().getCompleteLedgers();
|
||||
|
||||
NetworkOPs::subMapType::const_iterator it = mSubLedger.begin();
|
||||
@@ -1731,7 +1732,7 @@ bool NetworkOPs::subLedger(InfoSub::ref isrListener, Json::Value& jvResult)
|
||||
jvResult["reserve_inc"] = Json::UInt(lpClosed->getReserveInc());
|
||||
}
|
||||
|
||||
if (((mMode == omFULL) || (mMode == omTRACKING)) && !isNeedNetworkLedger())
|
||||
if ((mMode >= omSYNCING) && !isNeedNetworkLedger())
|
||||
jvResult["validated_ledgers"] = theApp->getLedgerMaster().getCompleteLedgers();
|
||||
|
||||
boost::recursive_mutex::scoped_lock sl(mMonitorLock);
|
||||
|
||||
@@ -98,8 +98,9 @@ public:
|
||||
{ // how we process transactions or account balance requests
|
||||
omDISCONNECTED = 0, // not ready to process requests
|
||||
omCONNECTED = 1, // convinced we are talking to the network
|
||||
omTRACKING = 2, // convinced we agree with the network
|
||||
omFULL = 3 // we have the ledger and can even validate
|
||||
omSYNCING = 2, // fallen slightly behind
|
||||
omTRACKING = 3, // convinced we agree with the network
|
||||
omFULL = 4 // we have the ledger and can even validate
|
||||
};
|
||||
|
||||
typedef boost::unordered_map<uint64, InfoSub::wptr> subMapType;
|
||||
|
||||
@@ -3545,9 +3545,7 @@ Json::Value RPCHandler::doCommand(const Json::Value& jvRequest, int iRole, int &
|
||||
|
||||
ScopedLock MasterLockHolder(theApp->getMasterLock());
|
||||
|
||||
if (commandsA[i].iOptions & optNetwork
|
||||
&& mNetOps->getOperatingMode() != NetworkOPs::omTRACKING
|
||||
&& mNetOps->getOperatingMode() != NetworkOPs::omFULL)
|
||||
if ((commandsA[i].iOptions & optNetwork) && (mNetOps->getOperatingMode() < NetworkOPs::omSYNCING))
|
||||
{
|
||||
cLog(lsINFO) << "Insufficient network mode for RPC: " << mNetOps->strOperatingMode();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user