diff --git a/src/cpp/ripple/LedgerMaster.cpp b/src/cpp/ripple/LedgerMaster.cpp index df3f3b15c9..7ba2dcd22f 100644 --- a/src/cpp/ripple/LedgerMaster.cpp +++ b/src/cpp/ripple/LedgerMaster.cpp @@ -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(mValidLedger->getCloseTimeNC()); + ret = std::max(0LL, ret); + + cLog(lsINFO) << "Validated ledger age is " << ret; + return static_cast(ret); +} + void LedgerMaster::addHeldTransaction(Transaction::ref transaction) { // returns true if transaction was added boost::recursive_mutex::scoped_lock ml(mLock); diff --git a/src/cpp/ripple/LedgerMaster.h b/src/cpp/ripple/LedgerMaster.h index 33b6344934..37c3a9630c 100644 --- a/src/cpp/ripple/LedgerMaster.h +++ b/src/cpp/ripple/LedgerMaster.h @@ -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); diff --git a/src/cpp/ripple/NetworkOPs.cpp b/src/cpp/ripple/NetworkOPs.cpp index 0e206bd724..a5adad261e 100644 --- a/src/cpp/ripple/NetworkOPs.cpp +++ b/src/cpp/ripple/NetworkOPs.cpp @@ -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); diff --git a/src/cpp/ripple/NetworkOPs.h b/src/cpp/ripple/NetworkOPs.h index 45499c08e7..76a6cd9393 100644 --- a/src/cpp/ripple/NetworkOPs.h +++ b/src/cpp/ripple/NetworkOPs.h @@ -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 subMapType; diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index 525aeb6a2f..a350ae65c7 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -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();