From 8ae19d1dce23a31f67636682a28d2cbfbb3f934b Mon Sep 17 00:00:00 2001 From: Nicholas Dudfield Date: Tue, 14 Apr 2026 14:39:16 +0700 Subject: [PATCH] chore: remove dead post-sync wiring helpers from InboundLedger MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/xrpld/app/ledger/detail/InboundLedger.cpp | 140 ------------------ 1 file changed, 140 deletions(-) diff --git a/src/xrpld/app/ledger/detail/InboundLedger.cpp b/src/xrpld/app/ledger/detail/InboundLedger.cpp index d4d2a45be..1bfcef055 100644 --- a/src/xrpld/app/ledger/detail/InboundLedger.cpp +++ b/src/xrpld/app/ledger/detail/InboundLedger.cpp @@ -56,146 +56,6 @@ isRWDBNullMode() return v; } -template -std::size_t -wireCompleteSHAMap(Map const& map) -{ - std::size_t leaves = 0; - for (auto const& item : map) - { - (void)item; - ++leaves; - } - return leaves; -} - -std::optional -sameChainDistance( - std::shared_ptr const& targetLedger, - std::shared_ptr 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 -chooseCloserBase( - std::shared_ptr const& targetLedger, - std::shared_ptr const& first, - std::shared_ptr 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 -findBestFullyWiredBase( - Application& app, - std::shared_ptr 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 const& ledger, - std::shared_ptr 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 {