From 6e0d6bdba4878e87dc5116b4187e3ef685ee90d1 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Sun, 18 Aug 2013 19:29:55 -0700 Subject: [PATCH] Make sure checkAccept is called, unless we know we don't need to, when findCreate completed immediately --- .../ripple_app/consensus/ripple_LedgerConsensus.cpp | 2 +- modules/ripple_app/ledger/LedgerMaster.cpp | 12 ++++++------ modules/ripple_app/ledger/ripple_InboundLedgers.cpp | 4 +++- modules/ripple_app/ledger/ripple_InboundLedgers.h | 2 +- modules/ripple_app/misc/NetworkOPs.cpp | 4 ++-- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/modules/ripple_app/consensus/ripple_LedgerConsensus.cpp b/modules/ripple_app/consensus/ripple_LedgerConsensus.cpp index e2845c508..0cc301283 100644 --- a/modules/ripple_app/consensus/ripple_LedgerConsensus.cpp +++ b/modules/ripple_app/consensus/ripple_LedgerConsensus.cpp @@ -209,7 +209,7 @@ void LedgerConsensus::handleLCL (uint256 const& lclHash) if (mAcquiringLedger) getApp().getInboundLedgers ().dropLedger (mAcquiringLedger->getHash ()); - mAcquiringLedger = getApp().getInboundLedgers ().findCreate (mPrevLedgerHash, 0); + mAcquiringLedger = getApp().getInboundLedgers ().findCreate (mPrevLedgerHash, 0, true); mHaveCorrectLCL = false; return; } diff --git a/modules/ripple_app/ledger/LedgerMaster.cpp b/modules/ripple_app/ledger/LedgerMaster.cpp index 1e998e307..fefe20136 100644 --- a/modules/ripple_app/ledger/LedgerMaster.cpp +++ b/modules/ripple_app/ledger/LedgerMaster.cpp @@ -480,7 +480,7 @@ void LedgerMaster::checkAccept (uint256 const& hash) if (!ledger) { - InboundLedger::pointer l = getApp().getInboundLedgers().findCreate(hash, 0); + InboundLedger::pointer l = getApp().getInboundLedgers().findCreate(hash, 0, false); if (l->isComplete() && !l->isFailed()) ledger = l->getLedger(); } @@ -526,7 +526,7 @@ void LedgerMaster::checkAccept (uint256 const& hash, uint32 seq) if (!ledger) { - InboundLedger::pointer i = getApp().getInboundLedgers ().findCreate (hash, seq); + InboundLedger::pointer i = getApp().getInboundLedgers ().findCreate (hash, seq, false); if (!i->isDone() || !i->isComplete() || i->isFailed()) return; ledger = i->getLedger(); @@ -598,7 +598,7 @@ void LedgerMaster::advanceThread() { InboundLedger::pointer acq = getApp().getInboundLedgers().findCreate(nextLedger->getParentHash(), - nextLedger->getLedgerSeq() - 1); + nextLedger->getLedgerSeq() - 1, false); if (acq->isComplete() && !acq->isFailed()) ledger = acq->getLedger(); else if ((missing > 40000) && getApp().getOPs().shouldFetchPack(missing)) @@ -633,7 +633,7 @@ void LedgerMaster::advanceThread() uint32 seq = missing - i; uint256 hash = nextLedger->getLedgerHash(seq); if (hash.isNonZero()) - getApp().getInboundLedgers().findCreate(hash, seq); + getApp().getInboundLedgers().findCreate(hash, seq, false); } } } @@ -735,7 +735,7 @@ std::list LedgerMaster::findNewLedgersToPublish(boost::recursiv if (!ledger && (++acqCount < 4)) { // We can try to acquire the ledger we need - InboundLedger::pointer acq = getApp().getInboundLedgers ().findCreate (hash, seq); + InboundLedger::pointer acq = getApp().getInboundLedgers ().findCreate (hash, seq, false); if (!acq->isDone ()) { @@ -749,7 +749,7 @@ std::list LedgerMaster::findNewLedgersToPublish(boost::recursiv { WriteLog (lsWARNING, LedgerMaster) << "Failed to acquire a published ledger"; getApp().getInboundLedgers().dropLedger(hash); - acq = getApp().getInboundLedgers().findCreate(hash, seq); + acq = getApp().getInboundLedgers().findCreate(hash, seq, false); if (acq->isComplete()) { if (acq->isFailed()) diff --git a/modules/ripple_app/ledger/ripple_InboundLedgers.cpp b/modules/ripple_app/ledger/ripple_InboundLedgers.cpp index a5f4c5305..f57fe4036 100644 --- a/modules/ripple_app/ledger/ripple_InboundLedgers.cpp +++ b/modules/ripple_app/ledger/ripple_InboundLedgers.cpp @@ -6,7 +6,7 @@ typedef std::pair u256_acq_pair; -InboundLedger::pointer InboundLedgers::findCreate (uint256 const& hash, uint32 seq) +InboundLedger::pointer InboundLedgers::findCreate (uint256 const& hash, uint32 seq, bool couldBeNew) { assert (hash.isNonZero ()); InboundLedger::pointer ret; @@ -39,6 +39,8 @@ InboundLedger::pointer InboundLedgers::findCreate (uint256 const& hash, uint32 s ledger->setClosed (); ledger->setImmutable (); getApp().getLedgerMaster ().storeLedger (ledger); + if (couldBeNew) + getApp().getLedgerMaster().checkAccept(ledger->getHash(), ledger->getLedgerSeq()); } } } diff --git a/modules/ripple_app/ledger/ripple_InboundLedgers.h b/modules/ripple_app/ledger/ripple_InboundLedgers.h index 12be0b103..655475c0a 100644 --- a/modules/ripple_app/ledger/ripple_InboundLedgers.h +++ b/modules/ripple_app/ledger/ripple_InboundLedgers.h @@ -26,7 +26,7 @@ public: // VFALCO TODO Should this be called findOrAdd ? // - InboundLedger::pointer findCreate (uint256 const& hash, uint32 seq); + InboundLedger::pointer findCreate (uint256 const& hash, uint32 seq, bool bCouldBeNew); InboundLedger::pointer find (uint256 const& hash); diff --git a/modules/ripple_app/misc/NetworkOPs.cpp b/modules/ripple_app/misc/NetworkOPs.cpp index 007ca1e86..c8a3c49b0 100644 --- a/modules/ripple_app/misc/NetworkOPs.cpp +++ b/modules/ripple_app/misc/NetworkOPs.cpp @@ -843,7 +843,7 @@ bool NetworkOPs::checkLastClosedLedger (const std::vector& peerLi WriteLog (lsINFO, NetworkOPs) << "Acquiring consensus ledger " << closedLedger; if (!mAcquiringLedger || (mAcquiringLedger->getHash () != closedLedger)) - mAcquiringLedger = getApp().getInboundLedgers ().findCreate (closedLedger, 0); + mAcquiringLedger = getApp().getInboundLedgers ().findCreate (closedLedger, 0, true); if (!mAcquiringLedger || mAcquiringLedger->isFailed ()) { @@ -2384,7 +2384,7 @@ void NetworkOPs::missingNodeInLedger (uint32 seq) uint256 hash = getApp().getLedgerMaster ().getHashBySeq (seq); if (hash.isNonZero ()) - getApp().getInboundLedgers ().findCreate (hash, seq); + getApp().getInboundLedgers ().findCreate (hash, seq, false); } void NetworkOPs::doClusterReport ()