From 31ad073f8aa6e24a4b7838d717de3ec533663ba4 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 22 Jun 2012 17:57:02 -0700 Subject: [PATCH] Track timeouts in ledgers and transaction sets we're acquiring. --- src/LedgerAcquire.cpp | 14 +++++++++++--- src/LedgerAcquire.h | 7 +++++-- src/LedgerConsensus.cpp | 1 + 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/LedgerAcquire.cpp b/src/LedgerAcquire.cpp index e440a77945..960fa1632d 100644 --- a/src/LedgerAcquire.cpp +++ b/src/LedgerAcquire.cpp @@ -11,8 +11,8 @@ #define LA_DEBUG #define LEDGER_ACQUIRE_TIMEOUT 2 -PeerSet::PeerSet(const uint256& hash, int interval) : mHash(hash), mTimerInterval(interval), - mComplete(false), mFailed(false), mTimer(theApp->getIOService()) +PeerSet::PeerSet(const uint256& hash, int interval) : mHash(hash), mTimerInterval(interval), mTimeouts(0), + mComplete(false), mFailed(false), mProgress(true), mTimer(theApp->getIOService()) { ; } void PeerSet::peerHas(Peer::pointer ptr) @@ -65,7 +65,12 @@ void PeerSet::TimerEntry(boost::weak_ptr wptr, const boost::system::err { if (result == boost::asio::error::operation_aborted) return; boost::shared_ptr ptr = wptr.lock(); - if (!!ptr) ptr->onTimer(); + if (!ptr) return; + if (!ptr->mProgress) + ++ptr->mTimeouts; + else + ptr->mProgress = false; + ptr->onTimer(); } LedgerAcquire::LedgerAcquire(const uint256& hash) : PeerSet(hash, LEDGER_ACQUIRE_TIMEOUT), @@ -284,6 +289,7 @@ bool LedgerAcquire::takeBase(const std::string& data, Peer::pointer peer) return false; } mHaveBase = true; + progress(); if (!mLedger->getTransHash()) mHaveTransactions = true; if (!mLedger->getAccountHash()) mHaveState = true; mLedger->setAcquiring(); @@ -315,6 +321,7 @@ bool LedgerAcquire::takeTxNode(const std::list& nodeIDs, if (mHaveState) mComplete = true; } trigger(peer); + progress(); return true; } @@ -345,6 +352,7 @@ bool LedgerAcquire::takeAsNode(const std::list& nodeIDs, if (mHaveTransactions) mComplete = true; } trigger(peer); + progress(); return true; } diff --git a/src/LedgerAcquire.h b/src/LedgerAcquire.h index 681d4bd0e0..01a0c3de06 100644 --- a/src/LedgerAcquire.h +++ b/src/LedgerAcquire.h @@ -20,8 +20,8 @@ class PeerSet { protected: uint256 mHash; - int mTimerInterval; - bool mComplete, mFailed; + int mTimerInterval, mTimeouts; + bool mComplete, mFailed, mProgress; boost::recursive_mutex mLock; boost::asio::deadline_timer mTimer; @@ -37,6 +37,9 @@ public: const uint256& getHash() const { return mHash; } bool isComplete() const { return mComplete; } bool isFailed() const { return mFailed; } + int getTimeouts() const { return mTimeouts; } + + void progress() { mProgress = true; } void peerHas(Peer::pointer); void badPeer(Peer::pointer); diff --git a/src/LedgerConsensus.cpp b/src/LedgerConsensus.cpp index 5f547a821b..bc142ef2ef 100644 --- a/src/LedgerConsensus.cpp +++ b/src/LedgerConsensus.cpp @@ -110,6 +110,7 @@ bool TransactionAcquire::takeNodes(const std::list& nodeIDs, ++nodeDatait; } trigger(peer); + progress(); return true; } catch (...)