mirror of
https://github.com/Xahau/xahaud.git
synced 2026-06-03 00:36:37 +00:00
chore: remove dead post-sync wiring helpers from InboundLedger
After dropping primeInboundLedgerForUse from init() and done(), the helper chain (findBestFullyWiredBase, chooseCloserBase, the local sameChainDistance copy, wireCompleteSHAMap, primeInboundLedgerForUse) became unused and produced -Wunused-function warnings. Remove them. Keeps isRWDBNullMode() — still used by init() and done() to gate the setFullyWired() call. The other sameChainDistance copy in InboundLedgers.cpp remains in use by getClosestFullyWiredLedger.
This commit is contained in:
@@ -56,146 +56,6 @@ isRWDBNullMode()
|
||||
return v;
|
||||
}
|
||||
|
||||
template <class Map>
|
||||
std::size_t
|
||||
wireCompleteSHAMap(Map const& map)
|
||||
{
|
||||
std::size_t leaves = 0;
|
||||
for (auto const& item : map)
|
||||
{
|
||||
(void)item;
|
||||
++leaves;
|
||||
}
|
||||
return leaves;
|
||||
}
|
||||
|
||||
std::optional<std::uint32_t>
|
||||
sameChainDistance(
|
||||
std::shared_ptr<Ledger const> const& targetLedger,
|
||||
std::shared_ptr<Ledger const> const& candidate,
|
||||
beast::Journal journal)
|
||||
{
|
||||
if (!targetLedger || !candidate || !candidate->isFullyWired())
|
||||
return std::nullopt;
|
||||
|
||||
if (candidate->info().hash == targetLedger->info().hash)
|
||||
return std::nullopt;
|
||||
|
||||
bool sameChain = false;
|
||||
try
|
||||
{
|
||||
if (candidate->info().seq < targetLedger->info().seq)
|
||||
{
|
||||
if (auto const hash =
|
||||
hashOfSeq(*targetLedger, candidate->info().seq, journal);
|
||||
hash && *hash == candidate->info().hash)
|
||||
{
|
||||
sameChain = true;
|
||||
}
|
||||
}
|
||||
else if (candidate->info().seq > targetLedger->info().seq)
|
||||
{
|
||||
if (auto const hash =
|
||||
hashOfSeq(*candidate, targetLedger->info().seq, journal);
|
||||
hash && *hash == targetLedger->info().hash)
|
||||
{
|
||||
sameChain = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (std::exception const&)
|
||||
{
|
||||
sameChain = false;
|
||||
}
|
||||
|
||||
if (!sameChain)
|
||||
return std::nullopt;
|
||||
|
||||
return candidate->info().seq < targetLedger->info().seq
|
||||
? targetLedger->info().seq - candidate->info().seq
|
||||
: candidate->info().seq - targetLedger->info().seq;
|
||||
}
|
||||
|
||||
std::shared_ptr<Ledger const>
|
||||
chooseCloserBase(
|
||||
std::shared_ptr<Ledger const> const& targetLedger,
|
||||
std::shared_ptr<Ledger const> const& first,
|
||||
std::shared_ptr<Ledger const> const& second,
|
||||
beast::Journal journal)
|
||||
{
|
||||
auto const firstDistance = sameChainDistance(targetLedger, first, journal);
|
||||
auto const secondDistance =
|
||||
sameChainDistance(targetLedger, second, journal);
|
||||
|
||||
if (firstDistance && secondDistance)
|
||||
return *firstDistance <= *secondDistance ? first : second;
|
||||
if (firstDistance)
|
||||
return first;
|
||||
if (secondDistance)
|
||||
return second;
|
||||
return {};
|
||||
}
|
||||
|
||||
std::shared_ptr<Ledger const>
|
||||
findBestFullyWiredBase(
|
||||
Application& app,
|
||||
std::shared_ptr<Ledger const> const& targetLedger,
|
||||
beast::Journal journal)
|
||||
{
|
||||
auto const ledgerMasterBase =
|
||||
app.getLedgerMaster().getClosestFullyWiredLedger(targetLedger);
|
||||
auto const inboundBase =
|
||||
app.getInboundLedgers().getClosestFullyWiredLedger(targetLedger);
|
||||
return chooseCloserBase(
|
||||
targetLedger, inboundBase, ledgerMasterBase, journal);
|
||||
}
|
||||
|
||||
bool
|
||||
primeInboundLedgerForUse(
|
||||
std::shared_ptr<Ledger> const& ledger,
|
||||
std::shared_ptr<Ledger const> const& baseLedger,
|
||||
beast::Journal journal,
|
||||
char const* context)
|
||||
{
|
||||
if (!isRWDBNullMode())
|
||||
return true;
|
||||
|
||||
if (ledger->isFullyWired())
|
||||
return true;
|
||||
|
||||
if (!baseLedger || !baseLedger->isFullyWired())
|
||||
{
|
||||
return ledger->fullWireForUse(journal, context);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
std::size_t stateNodes = 0;
|
||||
// By the time an inbound ledger is marked complete, sync has already
|
||||
// descended the current tree; this delta walk avoids rewalking
|
||||
// unchanged state subtrees that are known-good via a fully wired
|
||||
// same-chain base ledger.
|
||||
ledger->stateMap().visitDifferences(
|
||||
&baseLedger->stateMap(), [&stateNodes](SHAMapTreeNode const&) {
|
||||
++stateNodes;
|
||||
return true;
|
||||
});
|
||||
auto const txLeaves = wireCompleteSHAMap(ledger->txMap());
|
||||
ledger->setFullyWired();
|
||||
JLOG(journal.info())
|
||||
<< context << ": fully wired ledger " << ledger->info().seq << " ("
|
||||
<< stateNodes << " changed state nodes vs base ledger "
|
||||
<< baseLedger->info().seq << ", " << txLeaves << " tx leaves)";
|
||||
return true;
|
||||
}
|
||||
catch (SHAMapMissingNode const& e)
|
||||
{
|
||||
JLOG(journal.warn()) << context << ": incomplete ledger "
|
||||
<< ledger->info().seq << ": " << e.what();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
enum {
|
||||
|
||||
Reference in New Issue
Block a user