Simplify InboundLedger expiration (RIPD-873)

Let sweep logic remove obsolete ledger requests.
Touch inbound ledgers to prevent sweeping on requests.
Update sequence number if possible.
This commit is contained in:
David Schwartz
2015-05-01 10:54:53 -07:00
committed by Nik Bougalis
parent 4244e1070d
commit 45f092488a
3 changed files with 19 additions and 36 deletions

View File

@@ -67,6 +67,20 @@ InboundLedger::InboundLedger (uint256 const& hash, std::uint32_t seq, fcReason r
"Acquiring ledger " << mHash;
}
void InboundLedger::update (std::uint32_t seq)
{
ScopedLockType sl (mLock);
if ((seq != 0) && (mSeq == 0))
{
// If we didn't know the sequence number, but now do, save it
mSeq = seq;
}
// Prevent this from being swept
touch ();
}
bool InboundLedger::checkLocal ()
{
ScopedLockType sl (mLock);

View File

@@ -55,6 +55,9 @@ public:
~InboundLedger ();
// Called when another attempt is made to fetch this same ledger
void update (std::uint32_t seq);
bool isHeader () const
{
return mHaveHeader;

View File

@@ -54,47 +54,16 @@ public:
assert (hash.isNonZero ());
InboundLedger::pointer ret;
// Ensure that any previous IL is destroyed outside the lock
InboundLedger::pointer oldLedger;
{
ScopedLockType sl (mLock);
if (! isStopping ())
{
if (reason == InboundLedger::fcCONSENSUS)
{
if (mConsensusLedger.isNonZero() && (mValidationLedger != mConsensusLedger) && (hash != mConsensusLedger))
{
hash_map<uint256, InboundLedger::pointer>::iterator it = mLedgers.find (mConsensusLedger);
if (it != mLedgers.end ())
{
oldLedger = it->second;
mLedgers.erase (it);
}
}
mConsensusLedger = hash;
}
else if (reason == InboundLedger::fcVALIDATION)
{
if (mValidationLedger.isNonZero() && (mValidationLedger != mConsensusLedger) && (hash != mValidationLedger))
{
hash_map<uint256, InboundLedger::pointer>::iterator it = mLedgers.find (mValidationLedger);
if (it != mLedgers.end ())
{
oldLedger = it->second;
mLedgers.erase (it);
}
}
mValidationLedger = hash;
}
hash_map<uint256, InboundLedger::pointer>::iterator it = mLedgers.find (hash);
auto it = mLedgers.find (hash);
if (it != mLedgers.end ())
{
ret = it->second;
// FIXME: Should set the sequence if it's not set
ret->update (seq);
}
else
{
@@ -393,9 +362,6 @@ private:
MapType mLedgers;
KeyCache <uint256> mRecentFailures;
uint256 mConsensusLedger;
uint256 mValidationLedger;
beast::insight::Counter mCounter;
};