From bc211391987f7bf32756cad25b883d6309eef503 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 27 Feb 2013 14:18:07 -0800 Subject: [PATCH] If we don't have a ledger we should have, make sure we mark it missing so the fetch engine will work on it. --- src/cpp/ripple/LedgerMaster.h | 8 +++++++- src/cpp/ripple/NetworkOPs.cpp | 33 ++++++++++++++++++++++++--------- src/cpp/ripple/NetworkOPs.h | 2 +- src/cpp/ripple/RPCHandler.cpp | 4 ++-- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/cpp/ripple/LedgerMaster.h b/src/cpp/ripple/LedgerMaster.h index 700f8f280..d14ab11e4 100644 --- a/src/cpp/ripple/LedgerMaster.h +++ b/src/cpp/ripple/LedgerMaster.h @@ -107,7 +107,13 @@ public: return mCurrentLedger; if (mFinalizedLedger && (mFinalizedLedger->getLedgerSeq() == index)) return mFinalizedLedger; - return mLedgerHistory.getLedgerBySeq(index); + Ledger::pointer ret = mLedgerHistory.getLedgerBySeq(index); + if (ret) + return ret; + + boost::recursive_mutex::scoped_lock ml(mLock); + mCompleteLedgers.clearValue(index); + return ret; } Ledger::pointer getLedgerByHash(const uint256& hash) diff --git a/src/cpp/ripple/NetworkOPs.cpp b/src/cpp/ripple/NetworkOPs.cpp index 7eca6eaf3..a0965e035 100644 --- a/src/cpp/ripple/NetworkOPs.cpp +++ b/src/cpp/ripple/NetworkOPs.cpp @@ -107,6 +107,23 @@ uint32 NetworkOPs::getLedgerID(const uint256& hash) return lrLedger ? lrLedger->getLedgerSeq() : 0; } +Ledger::pointer NetworkOPs::getLedgerBySeq(const uint32 seq) +{ + Ledger::pointer ret; + + ret = mLedgerMaster->getLedgerBySeq(seq); + if (ret) + return ret; + + if (!haveLedger(seq)) + return ret; + + // We should have this ledger but we don't + cLog(lsWARNING) << "We should have ledger " << seq; + + return ret; +} + uint32 NetworkOPs::getCurrentLedgerID() { return mLedgerMaster->getCurrentLedger()->getLedgerSeq(); @@ -683,7 +700,8 @@ bool NetworkOPs::checkLastClosedLedger(const std::vector& peerLis cLog(lsTRACE) << "NetworkOPs::checkLastClosedLedger"; Ledger::pointer ourClosed = mLedgerMaster->getClosedLedger(); - if(!ourClosed) return(false); + if(!ourClosed) + return false; uint256 closedLedger = ourClosed->getHash(); uint256 prevClosedLedger = ourClosed->getParentHash(); @@ -714,11 +732,7 @@ bool NetworkOPs::checkLastClosedLedger(const std::vector& peerLis BOOST_FOREACH(Peer::ref it, peerList) { - if (!it) - { - cLog(lsDEBUG) << "NOP::CS Dead pointer in peer list"; - } - else if (it->isConnected()) + if (it && it->isConnected()) { uint256 peerLedger = it->getClosedLedgerHash(); if (peerLedger.isNonZero()) @@ -738,13 +752,14 @@ bool NetworkOPs::checkLastClosedLedger(const std::vector& peerLis for (boost::unordered_map::iterator it = ledgers.begin(), end = ledgers.end(); it != end; ++it) { - cLog(lsTRACE) << "L: " << it->first << " t=" << it->second.trustedValidations << + cLog(lsDEBUG) << "L: " << it->first << " t=" << it->second.trustedValidations << ", n=" << it->second.nodesUsing; // Temporary logging to make sure tiebreaking isn't broken if (it->second.trustedValidations > 0) cLog(lsTRACE) << " TieBreakTV: " << it->second.highValidation; - else tLog(it->second.nodesUsing > 0, lsTRACE) << " TieBreakNU: " << it->second.highNodeUsing; + else + tLog(it->second.nodesUsing > 0, lsTRACE) << " TieBreakNU: " << it->second.highNodeUsing; if (it->second > bestVC) { @@ -775,7 +790,7 @@ bool NetworkOPs::checkLastClosedLedger(const std::vector& peerLis } cLog(lsWARNING) << "We are not running on the consensus ledger"; - cLog(lsINFO) << "Our LCL " << ourClosed->getHash(); + cLog(lsINFO) << "Our LCL: " << ourClosed->getJson(0); cLog(lsINFO) << "Net LCL " << closedLedger; if ((mMode == omTRACKING) || (mMode == omFULL)) setMode(omCONNECTED); diff --git a/src/cpp/ripple/NetworkOPs.h b/src/cpp/ripple/NetworkOPs.h index 8f418bb42..8270d2efd 100644 --- a/src/cpp/ripple/NetworkOPs.h +++ b/src/cpp/ripple/NetworkOPs.h @@ -164,7 +164,7 @@ public: Ledger::ref getValidatedLedger() { return mLedgerMaster->getValidatedLedger(); } Ledger::ref getCurrentLedger() { return mLedgerMaster->getCurrentLedger(); } Ledger::pointer getLedgerByHash(const uint256& hash) { return mLedgerMaster->getLedgerByHash(hash); } - Ledger::pointer getLedgerBySeq(const uint32 seq) { return mLedgerMaster->getLedgerBySeq(seq); } + Ledger::pointer getLedgerBySeq(const uint32 seq); uint256 getClosedLedgerHash() { return mLedgerMaster->getClosedLedger()->getHash(); } diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index 3ce0749c4..f63fa88f1 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -1453,7 +1453,7 @@ Json::Value RPCHandler::doTx(Json::Value jvRequest) if (txn->getLedger() != 0) { - Ledger::pointer lgr = theApp->getLedgerMaster().getLedgerBySeq(txn->getLedger()); + Ledger::pointer lgr = theApp->getOPs().getLedgerBySeq(txn->getLedger()); if (lgr) { bool okay = false; @@ -1538,7 +1538,7 @@ Json::Value RPCHandler::doLedger(Json::Value jvRequest) else if (strLedger.size() > 12) ledger = theApp->getLedgerMaster().getLedgerByHash(uint256(strLedger)); else - ledger = theApp->getLedgerMaster().getLedgerBySeq(jvRequest["ledger"].asUInt()); + ledger = theApp->getOPs().getLedgerBySeq(jvRequest["ledger"].asUInt()); if (!ledger) return rpcError(rpcLGR_NOT_FOUND);