1#include <xrpld/app/ledger/BuildLedger.h>
2#include <xrpld/app/ledger/InboundLedger.h>
3#include <xrpld/app/ledger/LedgerReplay.h>
4#include <xrpld/app/ledger/LedgerReplayer.h>
5#include <xrpld/app/ledger/detail/LedgerDeltaAcquire.h>
6#include <xrpld/app/main/Application.h>
7#include <xrpld/overlay/PeerSet.h>
9#include <xrpl/core/JobQueue.h>
22 LedgerReplayParameters::SUB_TASK_TIMEOUT,
26 app.journal(
"LedgerReplayDelta"))
27 , inboundLedgers_(inboundLedgers)
28 , ledgerSeq_(ledgerSeq)
29 , peerSet_(std::move(peerSet))
31 JLOG(journal_.trace()) <<
"Create " << hash_ <<
" Seq " << ledgerSeq;
74 <<
"Add a peer " << peer->id() <<
" for " <<
hash_;
75 protocol::TMReplayDeltaRequest request;
77 peerSet_->sendRequest(request, peer);
147 <<
"failed to create a (info only) ledger from verified data " <<
hash_;
168 <<
"task added to a finished LedgerDeltaAcquire " <<
hash_;
186 "xrpl::LedgerDeltaAcquire::tryBuild : parent sequence match");
188 parent->header().hash ==
replayTemp_->header().parentHash,
189 "xrpl::LedgerDeltaAcquire::tryBuild : parent hash match");
204 << parent->header().hash;
205 Throw<std::runtime_error>(
"Cannot replay ledger");
215 << (reason ?
" for a new reason" :
"");
219 bool firstTime =
true;
223 reasons.push_back(*reason);
230 for (
auto reason : reasons)
235 app.getLedgerMaster().storeLedger(ledger);
244 app.getLedgerMaster().tryAdvance();
251 XRPL_ASSERT(
isDone(),
"xrpl::LedgerDeltaAcquire::notify : is done");
257 for (
auto& cb : toCall)
Stream trace() const
Severity stream access functions.
virtual Config & config()=0
virtual LedgerMaster & getLedgerMaster()=0
virtual Family & getNodeFamily()=0
virtual JobQueue & getJobQueue()=0
Manages the lifetime of inbound ledgers.
virtual std::shared_ptr< Ledger const > acquire(uint256 const &hash, std::uint32_t seq, InboundLedger::Reason)=0
bool addJob(JobType type, std::string const &name, JobHandler &&jobHandler)
Adds a job to the JobQueue.
std::uint32_t const ledgerSeq_
std::uint32_t noFeaturePeerCount
void trigger(std::size_t limit, ScopedLockType &sl)
Trigger another round.
void init(int numPeers)
Start the LedgerDeltaAcquire task.
std::shared_ptr< Ledger const > fullLedger_
void onLedgerBuilt(ScopedLockType &sl, std::optional< InboundLedger::Reason > reason={})
Process a newly built ledger, such as store it.
LedgerDeltaAcquire(Application &app, InboundLedgers &inboundLedgers, uint256 const &ledgerHash, std::uint32_t ledgerSeq, std::unique_ptr< PeerSet > peerSet)
Constructor.
InboundLedgers & inboundLedgers_
std::vector< OnDeltaDataCB > dataReadyCallbacks_
~LedgerDeltaAcquire() override
void processData(LedgerHeader const &info, std::map< std::uint32_t, std::shared_ptr< STTx const > > &&orderedTxns)
Process the data extracted from a peer's reply.
std::unique_ptr< PeerSet > peerSet_
std::set< InboundLedger::Reason > reasons_
void notify(ScopedLockType &sl)
Call the OnDeltaDataCB callbacks.
std::shared_ptr< Ledger const > replayTemp_
void onTimer(bool progress, ScopedLockType &peerSetLock) override
Hook called from invokeOnTimer().
std::weak_ptr< TimeoutCounter > pmDowncast() override
Return a weak pointer to this.
std::shared_ptr< Ledger const > tryBuild(std::shared_ptr< Ledger const > const &parent)
Try to build the ledger if not already.
std::map< std::uint32_t, std::shared_ptr< STTx const > > orderedTxns_
void addDataCallback(InboundLedger::Reason reason, OnDeltaDataCB &&cb)
Add a reason and a callback to the LedgerDeltaAcquire subtask.
std::shared_ptr< Ledger const > getLedgerByHash(uint256 const &hash)
This class is an "active" object.
std::recursive_mutex mtx_
uint256 const hash_
The hash of the object (in practice, always a ledger) we are trying to fetch.
void setTimer(ScopedLockType &)
Schedule a call to queueJob() after mTimerInterval.
std::chrono::milliseconds timerInterval_
The minimum time to wait between calls to execute().
static constexpr std::size_t size()
auto constexpr SUB_TASK_FALLBACK_TIMEOUT
auto constexpr MAX_NO_FEATURE_PEER_COUNT
std::uint32_t constexpr MAX_QUEUED_TASKS
std::uint32_t constexpr SUB_TASK_MAX_TIMEOUTS
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::shared_ptr< Ledger > buildLedger(std::shared_ptr< Ledger const > const &parent, NetClock::time_point closeTime, bool const closeTimeCorrect, NetClock::duration closeResolution, Application &app, CanonicalTXSet &txns, std::set< TxID > &failedTxs, beast::Journal j)
Build a new ledger by applying consensus transactions.
T shared_from_this(T... args)