Skip to content

Commit 0efb318

Browse files
committed
Include context on calls to InboundLedgers::acquire
1 parent ca07176 commit 0efb318

11 files changed

+72
-27
lines changed

src/test/app/LedgerReplay_test.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,11 @@ class MagicInboundLedgers : public InboundLedgers
9292
virtual ~MagicInboundLedgers() = default;
9393

9494
virtual std::shared_ptr<Ledger const>
95-
acquire(uint256 const& hash, std::uint32_t seq, InboundLedger::Reason)
96-
override
95+
acquire(
96+
uint256 const& hash,
97+
std::uint32_t seq,
98+
InboundLedger::Reason,
99+
const char*) override
97100
{
98101
if (bhvr == InboundLedgersBehavior::DropAll)
99102
return {};

src/xrpld/app/ledger/InboundLedgers.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ class InboundLedgers
4141
// Callers should use this if they possibly need an authoritative
4242
// response immediately.
4343
virtual std::shared_ptr<Ledger const>
44-
acquire(uint256 const& hash, std::uint32_t seq, InboundLedger::Reason) = 0;
44+
acquire(
45+
uint256 const& hash,
46+
std::uint32_t seq,
47+
InboundLedger::Reason,
48+
const char* context) = 0;
4549

4650
// Callers should use this if they are known to be executing on the Job
4751
// Queue. TODO review whether all callers of acquire() can use this

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ class InboundLedgersImp : public InboundLedgers
7070
acquire(
7171
uint256 const& hash,
7272
std::uint32_t seq,
73-
InboundLedger::Reason reason) override
73+
InboundLedger::Reason reason,
74+
const char* context) override
7475
{
7576
auto doAcquire = [&, seq, reason]() -> std::shared_ptr<Ledger const> {
7677
XRPL_ASSERT(
@@ -92,7 +93,7 @@ class InboundLedgersImp : public InboundLedgers
9293
ss << "InboundLedger::acquire: "
9394
<< "Request: " << to_string(hash) << ", " << seq
9495
<< " NeedNetworkLedger: " << (needNetworkLedger ? "yes" : "no")
95-
<< " Reason: " << to_string(reason)
96+
<< " Reason: " << to_string(reason) << " Context: " << context
9697
<< " Should acquire: " << (shouldAcquire ? "true." : "false.");
9798

9899
/* Acquiring ledgers is somewhat expensive. It requires lots of
@@ -222,7 +223,7 @@ class InboundLedgersImp : public InboundLedgers
222223
{
223224
try
224225
{
225-
acquire(hash, seq, reason);
226+
acquire(hash, seq, reason, "acquireAsync");
226227
}
227228
catch (std::exception const& e)
228229
{

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

+18-5
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ class LedgerCleanerImp : public LedgerCleaner
255255
app_.getInboundLedgers().acquire(
256256
ledger->info().hash,
257257
ledger->info().seq,
258-
InboundLedger::Reason::GENERIC);
258+
InboundLedger::Reason::GENERIC,
259+
"getLedgerHash");
259260
}
260261
return hash ? *hash : beast::zero; // kludge
261262
}
@@ -275,13 +276,19 @@ class LedgerCleanerImp : public LedgerCleaner
275276
bool doTxns)
276277
{
277278
auto nodeLedger = app_.getInboundLedgers().acquire(
278-
ledgerHash, ledgerIndex, InboundLedger::Reason::GENERIC);
279+
ledgerHash,
280+
ledgerIndex,
281+
InboundLedger::Reason::GENERIC,
282+
"doLedger");
279283
if (!nodeLedger)
280284
{
281285
JLOG(j_.debug()) << "Ledger " << ledgerIndex << " not available";
282286
app_.getLedgerMaster().clearLedger(ledgerIndex);
283287
app_.getInboundLedgers().acquire(
284-
ledgerHash, ledgerIndex, InboundLedger::Reason::GENERIC);
288+
ledgerHash,
289+
ledgerIndex,
290+
InboundLedger::Reason::GENERIC,
291+
"doLedger not available");
285292
return false;
286293
}
287294

@@ -307,7 +314,10 @@ class LedgerCleanerImp : public LedgerCleaner
307314
JLOG(j_.debug()) << "Ledger " << ledgerIndex << " is missing nodes";
308315
app_.getLedgerMaster().clearLedger(ledgerIndex);
309316
app_.getInboundLedgers().acquire(
310-
ledgerHash, ledgerIndex, InboundLedger::Reason::GENERIC);
317+
ledgerHash,
318+
ledgerIndex,
319+
InboundLedger::Reason::GENERIC,
320+
"doLedger missing nodes");
311321
return false;
312322
}
313323

@@ -363,7 +373,10 @@ class LedgerCleanerImp : public LedgerCleaner
363373
// We found the hash and sequence of a better reference
364374
// ledger.
365375
referenceLedger = app_.getInboundLedgers().acquire(
366-
refHash, refIndex, InboundLedger::Reason::GENERIC);
376+
refHash,
377+
refIndex,
378+
InboundLedger::Reason::GENERIC,
379+
"getHash");
367380
if (referenceLedger)
368381
ledgerHash =
369382
getLedgerHash(referenceLedger, ledgerIndex);

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ LedgerDeltaAcquire::trigger(std::size_t limit, ScopedLockType& sl)
110110

111111
if (fallBack_)
112112
inboundLedgers_.acquire(
113-
hash_, ledgerSeq_, InboundLedger::Reason::GENERIC);
113+
hash_,
114+
ledgerSeq_,
115+
InboundLedger::Reason::GENERIC,
116+
"LedgerDeltaAcquire::trigger");
114117
}
115118

116119
void

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

+16-9
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,8 @@ void
879879
LedgerMaster::failedSave(std::uint32_t seq, uint256 const& hash)
880880
{
881881
clearLedger(seq);
882-
app_.getInboundLedgers().acquire(hash, seq, InboundLedger::Reason::GENERIC);
882+
app_.getInboundLedgers().acquire(
883+
hash, seq, InboundLedger::Reason::GENERIC, "failedSave");
883884
}
884885

885886
// Check if the specified ledger can become the new last fully-validated
@@ -927,7 +928,7 @@ LedgerMaster::checkAccept(uint256 const& hash, std::uint32_t seq)
927928
// FIXME: We may not want to fetch a ledger with just one
928929
// trusted validation
929930
ledger = app_.getInboundLedgers().acquire(
930-
hash, seq, InboundLedger::Reason::GENERIC);
931+
hash, seq, InboundLedger::Reason::GENERIC, "checkAccept");
931932
}
932933

933934
if (ledger)
@@ -1302,7 +1303,10 @@ LedgerMaster::findNewLedgersToPublish(
13021303
// Can we try to acquire the ledger we need?
13031304
if (!ledger && (++acqCount < ledger_fetch_size_))
13041305
ledger = app_.getInboundLedgers().acquire(
1305-
*hash, seq, InboundLedger::Reason::GENERIC);
1306+
*hash,
1307+
seq,
1308+
InboundLedger::Reason::GENERIC,
1309+
"findNewLedgersToPublish");
13061310
}
13071311

13081312
// Did we acquire the next ledger we need to publish?
@@ -1493,15 +1497,17 @@ LedgerMaster::updatePaths()
14931497
app_.getInboundLedgers().acquire(
14941498
lastLedger->info().parentHash,
14951499
lastLedger->info().seq - 1,
1496-
InboundLedger::Reason::GENERIC);
1500+
InboundLedger::Reason::GENERIC,
1501+
"updatePaths open");
14971502
}
14981503
else
14991504
{
15001505
// this ledger is the problem
15011506
app_.getInboundLedgers().acquire(
15021507
lastLedger->info().hash,
15031508
lastLedger->info().seq,
1504-
InboundLedger::Reason::GENERIC);
1509+
InboundLedger::Reason::GENERIC,
1510+
"updatePaths closed");
15051511
}
15061512
}
15071513
}
@@ -1702,7 +1708,7 @@ LedgerMaster::walkHashBySeq(
17021708
if (!ledger)
17031709
{
17041710
if (auto const l = app_.getInboundLedgers().acquire(
1705-
*refHash, refIndex, reason))
1711+
*refHash, refIndex, reason, "walkHashBySeq"))
17061712
{
17071713
ledgerHash = hashOfSeq(*l, index, m_journal);
17081714
XRPL_ASSERT(
@@ -1828,8 +1834,8 @@ LedgerMaster::fetchForHistory(
18281834
{
18291835
if (!app_.getInboundLedgers().isFailure(*hash))
18301836
{
1831-
ledger =
1832-
app_.getInboundLedgers().acquire(*hash, missing, reason);
1837+
ledger = app_.getInboundLedgers().acquire(
1838+
*hash, missing, reason, "fetchForHistory");
18331839
if (!ledger && missing != fetch_seq_ &&
18341840
missing > app_.getNodeStore().earliestLedgerSeq())
18351841
{
@@ -1896,7 +1902,8 @@ LedgerMaster::fetchForHistory(
18961902
h->isNonZero(),
18971903
"ripple::LedgerMaster::fetchForHistory : "
18981904
"prefetched ledger");
1899-
app_.getInboundLedgers().acquire(*h, seq, reason);
1905+
app_.getInboundLedgers().acquire(
1906+
*h, seq, reason, "fetchForHistory no ledger");
19001907
}
19011908
}
19021909
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ LedgerReplayTask::trigger(ScopedLockType& sl)
162162
parent_ = inboundLedgers_.acquire(
163163
parameter_.startHash_,
164164
parameter_.startSeq_,
165-
InboundLedger::Reason::GENERIC);
165+
InboundLedger::Reason::GENERIC,
166+
"LedgerReplayTask::trigger");
166167
}
167168
if (parent_)
168169
{

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ SkipListAcquire::trigger(std::size_t limit, ScopedLockType& sl)
109109
}
110110

111111
if (fallBack_)
112-
inboundLedgers_.acquire(hash_, 0, InboundLedger::Reason::GENERIC);
112+
inboundLedgers_.acquire(
113+
hash_,
114+
0,
115+
InboundLedger::Reason::GENERIC,
116+
"SkipListAcquire::trigger");
113117
}
114118

115119
void

src/xrpld/app/misc/NetworkOPs.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1728,7 +1728,10 @@ NetworkOPsImp::checkLastClosedLedger(
17281728

17291729
if (!consensus)
17301730
consensus = app_.getInboundLedgers().acquire(
1731-
closedLedger, 0, InboundLedger::Reason::CONSENSUS);
1731+
closedLedger,
1732+
0,
1733+
InboundLedger::Reason::CONSENSUS,
1734+
"checkLastClosedLedger");
17321735

17331736
if (consensus &&
17341737
(!m_ledgerMaster.canBeCurrent(consensus) ||

src/xrpld/rpc/detail/RPCHelpers.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,10 @@ getLedgerByContext(RPC::JsonContext& context)
10871087
// ledger they want. Try to get it.
10881088

10891089
if (auto il = context.app.getInboundLedgers().acquire(
1090-
*refHash, refIndex, InboundLedger::Reason::GENERIC))
1090+
*refHash,
1091+
refIndex,
1092+
InboundLedger::Reason::GENERIC,
1093+
"getLedgerByContext no hash"))
10911094
{
10921095
Json::Value jvResult = RPC::make_error(
10931096
rpcLGR_NOT_FOUND,
@@ -1121,7 +1124,10 @@ getLedgerByContext(RPC::JsonContext& context)
11211124
// Try to get the desired ledger
11221125
// Verify all nodes even if we think we have it
11231126
auto ledger = context.app.getInboundLedgers().acquire(
1124-
ledgerHash, ledgerIndex, InboundLedger::Reason::GENERIC);
1127+
ledgerHash,
1128+
ledgerIndex,
1129+
InboundLedger::Reason::GENERIC,
1130+
"getLedgerByContext");
11251131

11261132
// In standalone mode, accept the ledger from the ledger cache
11271133
if (!ledger && context.app.config().standalone())

src/xrpld/shamap/detail/NodeFamily.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ NodeFamily::acquire(uint256 const& hash, std::uint32_t seq)
102102
JLOG(j_.error()) << "Missing node in " << to_string(hash);
103103

104104
app_.getInboundLedgers().acquire(
105-
hash, seq, InboundLedger::Reason::GENERIC);
105+
hash, seq, InboundLedger::Reason::GENERIC, "NodeFamily::acquire");
106106
}
107107
}
108108

0 commit comments

Comments
 (0)