Skip to content

Commit b39a1b4

Browse files
committed
Distinguish ledger requests needed for preferred ledger analysis
1 parent a3616f3 commit b39a1b4

File tree

4 files changed

+41
-26
lines changed

4 files changed

+41
-26
lines changed

src/xrpld/app/consensus/RCLValidations.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ RCLValidationsAdaptor::acquire(LedgerHash const& hash)
146146
JLOG(j_.debug())
147147
<< "JOB advanceLedger getConsensusLedger2 started";
148148
pApp->getInboundLedgers().acquireAsync(
149-
hash, 0, InboundLedger::Reason::CONSENSUS);
149+
hash, 0, InboundLedger::Reason::PREFERRED);
150150
});
151151
return std::nullopt;
152152
}

src/xrpld/app/ledger/InboundLedger.h

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ class InboundLedger final : public TimeoutCounter,
4343

4444
// These are the reasons we might acquire a ledger
4545
enum class Reason {
46-
HISTORY, // Acquiring past ledger
47-
GENERIC, // Generic other reasons
48-
CONSENSUS // We believe the consensus round requires this ledger
46+
HISTORY, // Acquiring past ledger
47+
GENERIC, // Generic other reasons
48+
CONSENSUS, // We believe the consensus round requires this ledger
49+
PREFERRED // We need this ledger for preferred ledger analysis
4950
};
5051

5152
InboundLedger(
@@ -200,24 +201,8 @@ class InboundLedger final : public TimeoutCounter,
200201
std::unique_ptr<PeerSet> mPeerSet;
201202
};
202203

203-
inline std::string
204-
to_string(InboundLedger::Reason reason)
205-
{
206-
using enum InboundLedger::Reason;
207-
switch (reason)
208-
{
209-
case HISTORY:
210-
return "HISTORY";
211-
case GENERIC:
212-
return "GENERIC";
213-
case CONSENSUS:
214-
return "CONSENSUS";
215-
default:
216-
UNREACHABLE(
217-
"ripple::to_string(InboundLedger::Reason) : unknown value");
218-
return "unknown";
219-
}
220-
}
204+
std::string
205+
to_string(InboundLedger::Reason reason);
221206

222207
} // namespace ripple
223208

src/xrpld/app/ledger/detail/InboundLedger.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,27 @@ enum {
7373
// millisecond for each ledger timeout
7474
auto constexpr ledgerAcquireTimeout = 3000ms;
7575

76+
std::string
77+
to_string(InboundLedger::Reason reason)
78+
{
79+
using enum InboundLedger::Reason;
80+
switch (reason)
81+
{
82+
case HISTORY:
83+
return "HISTORY";
84+
case GENERIC:
85+
return "GENERIC";
86+
case CONSENSUS:
87+
return "CONSENSUS";
88+
case PREFERRED:
89+
return "PREFERRED";
90+
default:
91+
UNREACHABLE(
92+
"ripple::to_string(InboundLedger::Reason) : unknown value");
93+
return "unknown";
94+
}
95+
}
96+
7697
InboundLedger::InboundLedger(
7798
Application& app,
7899
uint256 const& hash,
@@ -142,7 +163,7 @@ InboundLedger::init(ScopedLockType& collectionLock, bool broadcast)
142163
app_.getLedgerMaster().storeLedger(mLedger);
143164

144165
// Check if this could be a newer fully-validated ledger
145-
if (mReason == Reason::CONSENSUS)
166+
if (mReason >= Reason::CONSENSUS)
146167
app_.getLedgerMaster().checkAccept(mLedger);
147168
}
148169

src/xrpld/app/ledger/detail/InboundLedgers.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class InboundLedgersImp : public InboundLedgers
8484
return true;
8585
if (reason == InboundLedger::Reason::GENERIC)
8686
return true;
87-
if (reason == InboundLedger::Reason::CONSENSUS)
87+
if (reason >= InboundLedger::Reason::CONSENSUS)
8888
return true;
8989
return false;
9090
}();
@@ -119,6 +119,11 @@ class InboundLedgersImp : public InboundLedgers
119119
// ledger interval has passed, so the node is beginning to
120120
// fall behind.
121121
bool const fallingBehind = app_.getOPs().isFallingBehind();
122+
// If the ledger is needed for preferred ledger analysis and we
123+
// don't have it, chances are we're not going to build it,
124+
// because someone else has built it, so download it.
125+
bool const preferred =
126+
reason == InboundLedger::Reason::PREFERRED;
122127
// If everything else is ok, don't try to acquire the ledger
123128
// if the requested seq is in the near future relative to
124129
// the validated ledger. Because validations lag behind
@@ -139,8 +144,9 @@ class InboundLedgersImp : public InboundLedgers
139144
ss << " Evaluating whether to broadcast requests to peers"
140145
<< ". full: " << (isFull ? "true" : "false")
141146
<< ". falling behind: " << (fallingBehind ? "true" : "false")
142-
<< ". ledger sequence " << seq
143-
<< ". Valid sequence: " << validSeq
147+
<< ". needed for preferred ledger analysis: "
148+
<< (preferred ? "true" : "false") << ". ledger sequence "
149+
<< seq << ". Valid sequence: " << validSeq
144150
<< ". Lag leeway: " << lagLeeway
145151
<< ". request for near future ledger: "
146152
<< (nearFuture ? "true" : "false")
@@ -152,6 +158,9 @@ class InboundLedgersImp : public InboundLedgers
152158
// If the node is falling behind, send requests.
153159
if (fallingBehind)
154160
return true;
161+
// If needed for preferred analysis, send requests.
162+
if (preferred)
163+
return true;
155164
// If the ledger is in the near future, do NOT send requests.
156165
// This node is probably about to build it.
157166
if (nearFuture)

0 commit comments

Comments
 (0)