Skip to content

Commit

Permalink
Only have 1 running job for each inbound ledger.
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrippled committed Aug 23, 2024
1 parent 8dcdc64 commit dc37b3e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/test/app/LedgerReplay_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ class MagicInboundLedgers : public InboundLedgers
virtual ~MagicInboundLedgers() = default;

virtual std::shared_ptr<Ledger const>
acquire(uint256 const& hash, std::uint32_t seq, InboundLedger::Reason)
acquire(uint256 const& hash, std::uint32_t seq, InboundLedger::Reason,
bool jq)
override
{
if (bhvr == InboundLedgersBehavior::DropAll)
Expand Down
2 changes: 1 addition & 1 deletion src/xrpld/app/consensus/RCLConsensus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ RCLConsensus::Adaptor::acquireLedger(LedgerHash const& hash)
jtADVANCE1, "getConsensusLedger1", [id = hash, &app = app_, this]() {
JLOG(j_.debug()) << "JOB advanceLedger getConsensusLedger1 started";
app.getInboundLedgers().acquire(
id, 0, InboundLedger::Reason::CONSENSUS);
id, 0, InboundLedger::Reason::CONSENSUS, true);
JLOG(j_.debug()) << "JOB advanceLedger getConsensusLedger1 finishing";
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/xrpld/app/consensus/RCLValidations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ RCLValidationsAdaptor::acquire(LedgerHash const& hash)
jtADVANCE2, "getConsensusLedger2", [pApp, hash, this]() {
JLOG(j_.debug()) << "JOB advanceLedger getConsensusLedger2 started";
pApp->getInboundLedgers().acquire(
hash, 0, InboundLedger::Reason::CONSENSUS);
hash, 0, InboundLedger::Reason::CONSENSUS, true);
JLOG(j_.debug()) << "JOB advanceLedger getConsensusLedger2 finishing";
});
return std::nullopt;
Expand Down
3 changes: 2 additions & 1 deletion src/xrpld/app/ledger/InboundLedgers.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class InboundLedgers
// VFALCO TODO Should this be called findOrAdd ?
//
virtual std::shared_ptr<Ledger const>
acquire(uint256 const& hash, std::uint32_t seq, InboundLedger::Reason) = 0;
acquire(uint256 const& hash, std::uint32_t seq, InboundLedger::Reason,
bool jq = false) = 0;

virtual std::shared_ptr<InboundLedger>
find(LedgerHash const& hash) = 0;
Expand Down
14 changes: 13 additions & 1 deletion src/xrpld/app/ledger/detail/InboundLedgers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <memory>
#include <mutex>
#include <thread>
#include <set>
#include <vector>

namespace ripple {
Expand Down Expand Up @@ -67,7 +68,8 @@ class InboundLedgersImp : public InboundLedgers
acquire(
uint256 const& hash,
std::uint32_t seq,
InboundLedger::Reason reason) override
InboundLedger::Reason reason,
bool jq) override
{
static std::size_t instance = 0;
++instance;
Expand Down Expand Up @@ -131,9 +133,17 @@ class InboundLedgersImp : public InboundLedgers

if (!isNew)
{
if (jq)
{
if (pendingJobs_.contains(*const_cast<uint256*>(&hash)))
return {};
pendingJobs_.insert(*const_cast<uint256*>(&hash));
}
JLOG(j_.debug()) << "InboundLedgers::acquire5.4 " << this << " " << std::this_thread::get_id() << " " << instance;
inbound->update(seq);
JLOG(j_.debug()) << "InboundLedgers::acquire5.5 " << this << " " << std::this_thread::get_id() << " " << instance;
if (jq)
pendingJobs_.erase(*const_cast<uint256*>(&hash));
}

if (!inbound->isComplete())
Expand Down Expand Up @@ -479,6 +489,8 @@ class InboundLedgersImp : public InboundLedgers
beast::insight::Counter mCounter;

std::unique_ptr<PeerSetBuilder> mPeerSetBuilder;

std::set<uint256> pendingJobs_;
};

//------------------------------------------------------------------------------
Expand Down

0 comments on commit dc37b3e

Please sign in to comment.