From fbfb150cff4ff27a1fe91a85367ef7c875403873 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Sun, 11 Aug 2013 22:57:57 -0700 Subject: [PATCH] Some cleanups. --- modules/ripple_app/ledger/LedgerMaster.cpp | 7 +++++-- modules/ripple_app/ledger/ripple_InboundLedger.cpp | 4 ++-- modules/ripple_app/ledger/ripple_InboundLedgers.h | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/ripple_app/ledger/LedgerMaster.cpp b/modules/ripple_app/ledger/LedgerMaster.cpp index ffc3ea79d..b91ccc339 100644 --- a/modules/ripple_app/ledger/LedgerMaster.cpp +++ b/modules/ripple_app/ledger/LedgerMaster.cpp @@ -557,16 +557,19 @@ void LedgerMaster::advanceThread() Ledger::pointer ledger = getLedgerByHash(nextLedger->getParentHash()); if (!ledger) { - if (getApp().getOPs().shouldFetchPack(missing) && (missing > 40000)) - getFetchPack(nextLedger); if (!getApp().getInboundLedgers().isFailure(nextLedger->getParentHash())) { sl.unlock(); + + if (getApp().getOPs().shouldFetchPack(missing) && (missing > 40000)) + getFetchPack(nextLedger); + InboundLedger::pointer acq = getApp().getInboundLedgers().findCreate(nextLedger->getParentHash(), nextLedger->getLedgerSeq() - 1); if (acq && acq->isComplete() && !acq->isFailed()) ledger = acq->getLedger(); + sl.lock(); if (mValidLedger->getLedgerSeq() != mPubLedger->getLedgerSeq()) progress = true; diff --git a/modules/ripple_app/ledger/ripple_InboundLedger.cpp b/modules/ripple_app/ledger/ripple_InboundLedger.cpp index 2b88800a5..ec4ffc574 100644 --- a/modules/ripple_app/ledger/ripple_InboundLedger.cpp +++ b/modules/ripple_app/ledger/ripple_InboundLedger.cpp @@ -210,7 +210,7 @@ void InboundLedger::addPeers () return; // We traverse the peer list in random order so as not to favor any particular peer - int firstPeer = rand () & vSize; + int firstPeer = rand () % vSize; int found = 0; @@ -228,7 +228,7 @@ void InboundLedger::addPeers () } if (!found) - for (int i = 0; i < vSize; ++i) + for (int i = 0; i < ((vSize > 3) ? 3 : vSize); ++i) peerHas (peerList[ (i + firstPeer) % vSize]); } diff --git a/modules/ripple_app/ledger/ripple_InboundLedgers.h b/modules/ripple_app/ledger/ripple_InboundLedgers.h index 1794595c9..5eb9dcf7c 100644 --- a/modules/ripple_app/ledger/ripple_InboundLedgers.h +++ b/modules/ripple_app/ledger/ripple_InboundLedgers.h @@ -17,7 +17,7 @@ class InboundLedgers : LeakChecked { public: // How long before we try again to acquire the same ledger - static const int kReacquireIntervalSeconds = 600; + static const int kReacquireIntervalSeconds = 300; InboundLedgers () : mRecentFailures ("LedgerAcquireRecentFailures", 0, kReacquireIntervalSeconds)