Skip to content

Commit

Permalink
refactor: acquireAsync will dispatch the job, not the other way around
Browse files Browse the repository at this point in the history
  • Loading branch information
ximinez committed Feb 27, 2025
1 parent 15e4475 commit 0d68766
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 32 deletions.
2 changes: 2 additions & 0 deletions src/test/app/LedgerReplay_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ class MagicInboundLedgers : public InboundLedgers

virtual void
acquireAsync(
JobType type,
std::string const& name,
uint256 const& hash,
std::uint32_t seq,
InboundLedger::Reason reason) override
Expand Down
11 changes: 4 additions & 7 deletions src/xrpld/app/consensus/RCLConsensus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,12 @@ RCLConsensus::Adaptor::acquireLedger(LedgerHash const& hash)
// Tell the ledger acquire system that we need the consensus ledger
acquiringLedger_ = hash;

app_.getJobQueue().addJob(
app_.getInboundLedgers().acquireAsync(
jtADVANCE,
"getConsensusLedger1",
[id = hash, &app = app_, this]() {
JLOG(j_.debug())
<< "JOB advanceLedger getConsensusLedger1 started";
app.getInboundLedgers().acquireAsync(
id, 0, InboundLedger::Reason::CONSENSUS);
});
hash,
0,
InboundLedger::Reason::CONSENSUS);
}
return std::nullopt;
}
Expand Down
15 changes: 6 additions & 9 deletions src/xrpld/app/consensus/RCLValidations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,12 @@ RCLValidationsAdaptor::acquire(LedgerHash const& hash)
JLOG(j_.debug())
<< "Need validated ledger for preferred ledger analysis " << hash;

Application* pApp = &app_;

app_.getJobQueue().addJob(
jtADVANCE, "getConsensusLedger2", [pApp, hash, this]() {
JLOG(j_.debug())
<< "JOB advanceLedger getConsensusLedger2 started";
pApp->getInboundLedgers().acquireAsync(
hash, 0, InboundLedger::Reason::CONSENSUS);
});
app_.getInboundLedgers().acquireAsync(
jtADVANCE,
"getConsensusLedger2",
hash,
0,
InboundLedger::Reason::CONSENSUS);
return std::nullopt;
}

Expand Down
2 changes: 2 additions & 0 deletions src/xrpld/app/ledger/InboundLedgers.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class InboundLedgers
// instead. Inbound ledger acquisition is asynchronous anyway.
virtual void
acquireAsync(
JobType type,
std::string const& name,
uint256 const& hash,
std::uint32_t seq,
InboundLedger::Reason reason) = 0;
Expand Down
42 changes: 26 additions & 16 deletions src/xrpld/app/ledger/detail/InboundLedgers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,28 +214,38 @@ class InboundLedgersImp : public InboundLedgers

void
acquireAsync(
JobType type,
std::string const& name,
uint256 const& hash,
std::uint32_t seq,
InboundLedger::Reason reason) override
{
if (CanProcess const check{acquiresMutex_, pendingAcquires_, hash})
{
try
{
acquire(hash, seq, reason);
}
catch (std::exception const& e)
{
JLOG(j_.warn())
<< "Exception thrown for acquiring new inbound ledger "
<< hash << ": " << e.what();
}
catch (...)
{
JLOG(j_.warn()) << "Unknown exception thrown for acquiring new "
"inbound ledger "
<< hash;
}
app_.getJobQueue().addJob(
type,
name,
[check = std::move(check), name, hash, seq, reason, this]() {
JLOG(j_.debug())
<< "JOB acquireAsync " << name << " started ";
try
{
acquire(hash, seq, reason);
}
catch (std::exception const& e)
{
JLOG(j_.warn()) << "Exception thrown for acquiring new "
"inbound ledger "
<< hash << ": " << e.what();
}
catch (...)
{
JLOG(j_.warn())
<< "Unknown exception thrown for acquiring new "
"inbound ledger "
<< hash;
}
});
}
}

Expand Down

0 comments on commit 0d68766

Please sign in to comment.