From ff9046a3377f3b5d5bf82d6667a89fbc975559cf Mon Sep 17 00:00:00 2001 From: Ed Hennis Date: Wed, 11 Sep 2024 16:24:53 -0400 Subject: [PATCH] Distinguish ledger requests needed for preferred ledger analysis --- src/xrpld/app/consensus/RCLValidations.cpp | 2 +- src/xrpld/app/ledger/InboundLedger.h | 26 +++++-------------- src/xrpld/app/ledger/detail/InboundLedger.cpp | 22 +++++++++++++++- .../app/ledger/detail/InboundLedgers.cpp | 15 ++++++++--- 4 files changed, 40 insertions(+), 25 deletions(-) diff --git a/src/xrpld/app/consensus/RCLValidations.cpp b/src/xrpld/app/consensus/RCLValidations.cpp index c4d9389e896..453686bf34e 100644 --- a/src/xrpld/app/consensus/RCLValidations.cpp +++ b/src/xrpld/app/consensus/RCLValidations.cpp @@ -149,7 +149,7 @@ RCLValidationsAdaptor::acquire(LedgerHash const& hash) JLOG(j_.debug()) << "JOB advanceLedger getConsensusLedger2 started"; pApp->getInboundLedgers().acquireAsync( - hash, 0, InboundLedger::Reason::CONSENSUS); + hash, 0, InboundLedger::Reason::PREFERRED); }); return std::nullopt; } diff --git a/src/xrpld/app/ledger/InboundLedger.h b/src/xrpld/app/ledger/InboundLedger.h index 85591ffc0bf..5ac056373bc 100644 --- a/src/xrpld/app/ledger/InboundLedger.h +++ b/src/xrpld/app/ledger/InboundLedger.h @@ -41,9 +41,10 @@ class InboundLedger final : public TimeoutCounter, // These are the reasons we might acquire a ledger enum class Reason { - HISTORY, // Acquiring past ledger - GENERIC, // Generic other reasons - CONSENSUS // We believe the consensus round requires this ledger + HISTORY, // Acquiring past ledger + GENERIC, // Generic other reasons + CONSENSUS, // We believe the consensus round requires this ledger + PREFERRED // We need this ledger for preferred ledger analysis }; InboundLedger( @@ -198,23 +199,8 @@ class InboundLedger final : public TimeoutCounter, std::unique_ptr mPeerSet; }; -inline std::string -to_string(InboundLedger::Reason reason) -{ - using enum InboundLedger::Reason; - switch (reason) - { - case HISTORY: - return "HISTORY"; - case GENERIC: - return "GENERIC"; - case CONSENSUS: - return "CONSENSUS"; - default: - assert(false); - return "unknown"; - } -} +std::string +to_string(InboundLedger::Reason reason); } // namespace ripple diff --git a/src/xrpld/app/ledger/detail/InboundLedger.cpp b/src/xrpld/app/ledger/detail/InboundLedger.cpp index 13a30a8c54e..47db2573df8 100644 --- a/src/xrpld/app/ledger/detail/InboundLedger.cpp +++ b/src/xrpld/app/ledger/detail/InboundLedger.cpp @@ -73,6 +73,26 @@ enum { // millisecond for each ledger timeout auto constexpr ledgerAcquireTimeout = 3000ms; +std::string +to_string(InboundLedger::Reason reason) +{ + using enum InboundLedger::Reason; + switch (reason) + { + case HISTORY: + return "HISTORY"; + case GENERIC: + return "GENERIC"; + case CONSENSUS: + return "CONSENSUS"; + case PREFERRED: + return "PREFERRED"; + default: + assert(false); + return "unknown"; + } +} + InboundLedger::InboundLedger( Application& app, uint256 const& hash, @@ -142,7 +162,7 @@ InboundLedger::init(ScopedLockType& collectionLock, bool broadcast) app_.getLedgerMaster().storeLedger(mLedger); // Check if this could be a newer fully-validated ledger - if (mReason == Reason::CONSENSUS) + if (mReason >= Reason::CONSENSUS) app_.getLedgerMaster().checkAccept(mLedger); } diff --git a/src/xrpld/app/ledger/detail/InboundLedgers.cpp b/src/xrpld/app/ledger/detail/InboundLedgers.cpp index e48ac624b21..ca1e7e3ad68 100644 --- a/src/xrpld/app/ledger/detail/InboundLedgers.cpp +++ b/src/xrpld/app/ledger/detail/InboundLedgers.cpp @@ -84,7 +84,7 @@ class InboundLedgersImp : public InboundLedgers return true; if (reason == InboundLedger::Reason::GENERIC) return true; - if (reason == InboundLedger::Reason::CONSENSUS) + if (reason >= InboundLedger::Reason::CONSENSUS) return true; return false; }(); @@ -119,6 +119,11 @@ class InboundLedgersImp : public InboundLedgers // ledger interval has passed, so the node is beginning to // fall behind. bool const fallingBehind = app_.getOPs().isFallingBehind(); + // If the ledger is needed for preferred ledger analysis and we + // don't have it, chances are we're not going to build it, + // because someone else has built it, so download it. + bool const preferred = + reason == InboundLedger::Reason::PREFERRED; // If everything else is ok, don't try to acquire the ledger // if the requested seq is in the near future relative to // the validated ledger. Because validations lag behind @@ -139,8 +144,9 @@ class InboundLedgersImp : public InboundLedgers ss << " Evaluating whether to broadcast requests to peers" << ". full: " << (isFull ? "true" : "false") << ". falling behind: " << (fallingBehind ? "true" : "false") - << ". ledger sequence " << seq - << ". Valid sequence: " << validSeq + << ". needed for preferred ledger analysis: " + << (preferred ? "true" : "false") << ". ledger sequence " + << seq << ". Valid sequence: " << validSeq << ". Lag leeway: " << lagLeeway << ". request for near future ledger: " << (nearFuture ? "true" : "false") @@ -152,6 +158,9 @@ class InboundLedgersImp : public InboundLedgers // If the node is falling behind, send requests. if (fallingBehind) return true; + // If needed for preferred analysis, send requests. + if (preferred) + return true; // If the ledger is in the near future, do NOT send requests. // This node is probably about to build it. if (nearFuture)