Skip to content

Commit a241e2f

Browse files
committed
refactor: acquireAsync will dispatch the job, not the other way around
1 parent 021c10d commit a241e2f

File tree

5 files changed

+40
-32
lines changed

5 files changed

+40
-32
lines changed

src/test/app/LedgerReplay_test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ class MagicInboundLedgers : public InboundLedgers
108108

109109
virtual void
110110
acquireAsync(
111+
JobType type,
112+
std::string const& name,
111113
uint256 const& hash,
112114
std::uint32_t seq,
113115
InboundLedger::Reason reason) override

src/xrpld/app/consensus/RCLConsensus.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,12 @@ RCLConsensus::Adaptor::acquireLedger(LedgerHash const& hash)
136136
// Tell the ledger acquire system that we need the consensus ledger
137137
acquiringLedger_ = hash;
138138

139-
app_.getJobQueue().addJob(
139+
app_.getInboundLedgers().acquireAsync(
140140
jtADVANCE,
141141
"getConsensusLedger1",
142-
[id = hash, &app = app_, this]() {
143-
JLOG(j_.debug())
144-
<< "JOB advanceLedger getConsensusLedger1 started";
145-
app.getInboundLedgers().acquireAsync(
146-
id, 0, InboundLedger::Reason::CONSENSUS);
147-
});
142+
hash,
143+
0,
144+
InboundLedger::Reason::CONSENSUS);
148145
}
149146
return std::nullopt;
150147
}

src/xrpld/app/consensus/RCLValidations.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,12 @@ RCLValidationsAdaptor::acquire(LedgerHash const& hash)
142142
JLOG(j_.debug())
143143
<< "Need validated ledger for preferred ledger analysis " << hash;
144144

145-
Application* pApp = &app_;
146-
147-
app_.getJobQueue().addJob(
148-
jtADVANCE, "getConsensusLedger2", [pApp, hash, this]() {
149-
JLOG(j_.debug())
150-
<< "JOB advanceLedger getConsensusLedger2 started";
151-
pApp->getInboundLedgers().acquireAsync(
152-
hash, 0, InboundLedger::Reason::CONSENSUS);
153-
});
145+
app_.getInboundLedgers().acquireAsync(
146+
jtADVANCE,
147+
"getConsensusLedger2",
148+
hash,
149+
0,
150+
InboundLedger::Reason::CONSENSUS);
154151
return std::nullopt;
155152
}
156153

src/xrpld/app/ledger/InboundLedgers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class InboundLedgers
4848
// instead. Inbound ledger acquisition is asynchronous anyway.
4949
virtual void
5050
acquireAsync(
51+
JobType type,
52+
std::string const& name,
5153
uint256 const& hash,
5254
std::uint32_t seq,
5355
InboundLedger::Reason reason) = 0;

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

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -214,28 +214,38 @@ class InboundLedgersImp : public InboundLedgers
214214

215215
void
216216
acquireAsync(
217+
JobType type,
218+
std::string const& name,
217219
uint256 const& hash,
218220
std::uint32_t seq,
219221
InboundLedger::Reason reason) override
220222
{
221223
if (CanProcess const check{acquiresMutex_, pendingAcquires_, hash})
222224
{
223-
try
224-
{
225-
acquire(hash, seq, reason);
226-
}
227-
catch (std::exception const& e)
228-
{
229-
JLOG(j_.warn())
230-
<< "Exception thrown for acquiring new inbound ledger "
231-
<< hash << ": " << e.what();
232-
}
233-
catch (...)
234-
{
235-
JLOG(j_.warn()) << "Unknown exception thrown for acquiring new "
236-
"inbound ledger "
237-
<< hash;
238-
}
225+
app_.getJobQueue().addJob(
226+
type,
227+
name,
228+
[check = std::move(check), name, hash, seq, reason, this]() {
229+
JLOG(j_.debug())
230+
<< "JOB acquireAsync " << name << " started ";
231+
try
232+
{
233+
acquire(hash, seq, reason);
234+
}
235+
catch (std::exception const& e)
236+
{
237+
JLOG(j_.warn()) << "Exception thrown for acquiring new "
238+
"inbound ledger "
239+
<< hash << ": " << e.what();
240+
}
241+
catch (...)
242+
{
243+
JLOG(j_.warn())
244+
<< "Unknown exception thrown for acquiring new "
245+
"inbound ledger "
246+
<< hash;
247+
}
248+
});
239249
}
240250
}
241251

0 commit comments

Comments
 (0)