Skip to content

Commit a3b0a5d

Browse files
committed
Distinguish ledger requests needed for preferred ledger analysis
1 parent e1e0df9 commit a3b0a5d

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
@@ -127,7 +127,7 @@ RCLValidationsAdaptor::acquire(LedgerHash const& hash)
127127
JLOG(j_.debug())
128128
<< "JOB advanceLedger getConsensusLedger2 started";
129129
pApp->getInboundLedgers().acquireAsync(
130-
hash, 0, InboundLedger::Reason::CONSENSUS);
130+
hash, 0, InboundLedger::Reason::PREFERRED);
131131
});
132132
return std::nullopt;
133133
}

src/xrpld/app/ledger/InboundLedger.h

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

2525
// These are the reasons we might acquire a ledger
2626
enum class Reason {
27-
HISTORY, // Acquiring past ledger
28-
GENERIC, // Generic other reasons
29-
CONSENSUS // We believe the consensus round requires this ledger
27+
HISTORY, // Acquiring past ledger
28+
GENERIC, // Generic other reasons
29+
CONSENSUS, // We believe the consensus round requires this ledger
30+
PREFERRED // We need this ledger for preferred ledger analysis
3031
};
3132

3233
InboundLedger(
@@ -181,24 +182,8 @@ class InboundLedger final : public TimeoutCounter,
181182
std::unique_ptr<PeerSet> mPeerSet;
182183
};
183184

184-
inline std::string
185-
to_string(InboundLedger::Reason reason)
186-
{
187-
using enum InboundLedger::Reason;
188-
switch (reason)
189-
{
190-
case HISTORY:
191-
return "HISTORY";
192-
case GENERIC:
193-
return "GENERIC";
194-
case CONSENSUS:
195-
return "CONSENSUS";
196-
default:
197-
UNREACHABLE(
198-
"ripple::to_string(InboundLedger::Reason) : unknown value");
199-
return "unknown";
200-
}
201-
}
185+
std::string
186+
to_string(InboundLedger::Reason reason);
202187

203188
} // namespace ripple
204189

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

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

57+
std::string
58+
to_string(InboundLedger::Reason reason)
59+
{
60+
using enum InboundLedger::Reason;
61+
switch (reason)
62+
{
63+
case HISTORY:
64+
return "HISTORY";
65+
case GENERIC:
66+
return "GENERIC";
67+
case CONSENSUS:
68+
return "CONSENSUS";
69+
case PREFERRED:
70+
return "PREFERRED";
71+
default:
72+
UNREACHABLE(
73+
"ripple::to_string(InboundLedger::Reason) : unknown value");
74+
return "unknown";
75+
}
76+
}
77+
5778
InboundLedger::InboundLedger(
5879
Application& app,
5980
uint256 const& hash,
@@ -123,7 +144,7 @@ InboundLedger::init(ScopedLockType& collectionLock, bool broadcast)
123144
app_.getLedgerMaster().storeLedger(mLedger);
124145

125146
// Check if this could be a newer fully-validated ledger
126-
if (mReason == Reason::CONSENSUS)
147+
if (mReason >= Reason::CONSENSUS)
127148
app_.getLedgerMaster().checkAccept(mLedger);
128149
}
129150

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class InboundLedgersImp : public InboundLedgers
6565
return true;
6666
if (reason == InboundLedger::Reason::GENERIC)
6767
return true;
68-
if (reason == InboundLedger::Reason::CONSENSUS)
68+
if (reason >= InboundLedger::Reason::CONSENSUS)
6969
return true;
7070
return false;
7171
}();
@@ -100,6 +100,11 @@ class InboundLedgersImp : public InboundLedgers
100100
// ledger interval has passed, so the node is beginning to
101101
// fall behind.
102102
bool const fallingBehind = app_.getOPs().isFallingBehind();
103+
// If the ledger is needed for preferred ledger analysis and we
104+
// don't have it, chances are we're not going to build it,
105+
// because someone else has built it, so download it.
106+
bool const preferred =
107+
reason == InboundLedger::Reason::PREFERRED;
103108
// If everything else is ok, don't try to acquire the ledger
104109
// if the requested seq is in the near future relative to
105110
// the validated ledger. Because validations lag behind
@@ -120,8 +125,9 @@ class InboundLedgersImp : public InboundLedgers
120125
ss << " Evaluating whether to broadcast requests to peers"
121126
<< ". full: " << (isFull ? "true" : "false")
122127
<< ". falling behind: " << (fallingBehind ? "true" : "false")
123-
<< ". ledger sequence " << seq
124-
<< ". Valid sequence: " << validSeq
128+
<< ". needed for preferred ledger analysis: "
129+
<< (preferred ? "true" : "false") << ". ledger sequence "
130+
<< seq << ". Valid sequence: " << validSeq
125131
<< ". Lag leeway: " << lagLeeway
126132
<< ". request for near future ledger: "
127133
<< (nearFuture ? "true" : "false")
@@ -133,6 +139,9 @@ class InboundLedgersImp : public InboundLedgers
133139
// If the node is falling behind, send requests.
134140
if (fallingBehind)
135141
return true;
142+
// If needed for preferred analysis, send requests.
143+
if (preferred)
144+
return true;
136145
// If the ledger is in the near future, do NOT send requests.
137146
// This node is probably about to build it.
138147
if (nearFuture)

0 commit comments

Comments
 (0)