Skip to content

Commit

Permalink
always retain buckets referenced by last closed ledger
Browse files Browse the repository at this point in the history
the in memory state (tracked by BucketManager) may change as merges happen,
this may cause buckets referenced by the LCL HAS to not be the same
  • Loading branch information
MonsieurNicolas committed Dec 9, 2018
1 parent f1a0cac commit f4b6572
Showing 1 changed file with 38 additions and 10 deletions.
48 changes: 38 additions & 10 deletions src/bucket/BucketManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "bucket/BucketList.h"
#include "crypto/Hex.h"
#include "history/HistoryManager.h"
#include "ledger/LedgerManager.h"
#include "main/Application.h"
#include "main/Config.h"
#include "overlay/StellarXDR.h"
Expand Down Expand Up @@ -237,28 +238,55 @@ BucketManagerImpl::getBucketByHash(uint256 const& hash)
std::set<Hash>
BucketManagerImpl::getReferencedBuckets() const
{
auto referenced = std::set<Hash>{};
std::set<Hash> referenced;
// retain current bucket list
for (uint32_t i = 0; i < BucketList::kNumLevels; ++i)
{
auto const& level = mBucketList.getLevel(i);
referenced.insert(level.getCurr()->getHash());
referenced.insert(level.getSnap()->getHash());
auto rit = referenced.insert(level.getCurr()->getHash());
if (rit.second)
{
CLOG(TRACE, "Bucket")
<< binToHex(*rit.first) << " referenced by bucket list";
}
rit = referenced.insert(level.getSnap()->getHash());
if (rit.second)
{
CLOG(TRACE, "Bucket")
<< binToHex(*rit.first) << " referenced by bucket list";
}
for (auto const& h : level.getNext().getHashes())
{
referenced.insert(hexToBin256(h));
rit = referenced.insert(hexToBin256(h));
if (rit.second)
{
CLOG(TRACE, "Bucket") << h << " referenced by bucket list";
}
}
}
// retain any bucket referenced by the last closed ledger as recorded in the
// database (as merge complete, the bucket list drifts from that state)
auto lclHas = mApp.getLedgerManager().getLastClosedLedgerHAS();
auto lclBuckets = lclHas.allBuckets();
for (auto const& h : lclBuckets)
{
auto rit = referenced.insert(hexToBin256(h));
if (rit.second)
{
CLOG(TRACE, "Bucket") << h << " referenced by LCL";
}
}

// Implicitly retain any buckets that are referenced by a state in
// the publish queue.
// retain buckets that are referenced by a state in the publish queue.
auto pub = mApp.getHistoryManager().getBucketsReferencedByPublishQueue();
{
for (auto const& h : pub)
{
CLOG(DEBUG, "Bucket")
<< "BucketManager::forgetUnreferencedBuckets: " << h
<< " referenced by publish queue";
referenced.insert(hexToBin256(h));
auto rit = referenced.insert(hexToBin256(h));
if (rit.second)
{
CLOG(TRACE, "Bucket") << h << " referenced by publish queue";
}
}
}

Expand Down

5 comments on commit f4b6572

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from vogel
at MonsieurNicolas@f4b6572

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging MonsieurNicolas/stellar-core/preserveHAS = f4b6572 into auto

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MonsieurNicolas/stellar-core/preserveHAS = f4b6572 merged ok, testing candidate = 1fe2e8a

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 1fe2e8a

Please sign in to comment.