rippled
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
xrpl::LedgerDeltaAcquire Class Referencefinal

Manage the retrieval of a ledger delta (header and transactions) from the network. More...

#include <LedgerDeltaAcquire.h>

Inheritance diagram for xrpl::LedgerDeltaAcquire:
Inheritance graph
[legend]
Collaboration diagram for xrpl::LedgerDeltaAcquire:
Collaboration graph
[legend]

Public Types

using OnDeltaDataCB = std::function< void(bool successful, uint256 const &hash)>
 A callback used to notify that the delta's data is ready or failed.
 

Public Member Functions

 LedgerDeltaAcquire (Application &app, InboundLedgers &inboundLedgers, uint256 const &ledgerHash, std::uint32_t ledgerSeq, std::unique_ptr< PeerSet > peerSet)
 Constructor.
 
 ~LedgerDeltaAcquire () override
 
void init (int numPeers)
 Start the LedgerDeltaAcquire task.
 
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::shared_ptr< Ledger const > tryBuild (std::shared_ptr< Ledger const > const &parent)
 Try to build the ledger if not already.
 
void addDataCallback (InboundLedger::Reason reason, OnDeltaDataCB &&cb)
 Add a reason and a callback to the LedgerDeltaAcquire subtask.
 
virtual void cancel ()
 Cancel the task by marking it as failed if the task is not done.
 
shared_from_this (T... args)
 
weak_from_this (T... args)
 

Protected Types

using ScopedLockType = std::unique_lock< std::recursive_mutex >
 

Protected Member Functions

void setTimer (ScopedLockType &)
 Schedule a call to queueJob() after mTimerInterval.
 
void queueJob (ScopedLockType &)
 Queue a job to call invokeOnTimer().
 
bool isDone () const
 

Protected Attributes

Applicationapp_
 
beast::Journal journal_
 
std::recursive_mutex mtx_
 
uint256 const hash_
 The hash of the object (in practice, always a ledger) we are trying to fetch.
 
int timeouts_
 
bool complete_
 
bool failed_
 
bool progress_
 Whether forward progress has been made.
 
std::chrono::milliseconds timerInterval_
 The minimum time to wait between calls to execute().
 
QueueJobParameter queueJobParameter_
 

Private Member Functions

void onTimer (bool progress, ScopedLockType &peerSetLock) override
 Hook called from invokeOnTimer().
 
std::weak_ptr< TimeoutCounterpmDowncast () override
 Return a weak pointer to this.
 
void trigger (std::size_t limit, ScopedLockType &sl)
 Trigger another round.
 
void onLedgerBuilt (ScopedLockType &sl, std::optional< InboundLedger::Reason > reason={})
 Process a newly built ledger, such as store it.
 
void notify (ScopedLockType &sl)
 Call the OnDeltaDataCB callbacks.
 
void invokeOnTimer ()
 Calls onTimer() if in the right state.
 

Static Private Member Functions

static auto & getCounter () noexcept
 

Private Attributes

InboundLedgersinboundLedgers_
 
std::uint32_t const ledgerSeq_
 
std::unique_ptr< PeerSetpeerSet_
 
std::shared_ptr< Ledger const > replayTemp_ = {}
 
std::shared_ptr< Ledger const > fullLedger_ = {}
 
std::map< std::uint32_t, std::shared_ptr< STTx const > > orderedTxns_
 
std::vector< OnDeltaDataCBdataReadyCallbacks_
 
std::set< InboundLedger::Reasonreasons_
 
std::uint32_t noFeaturePeerCount = 0
 
bool fallBack_ = false
 
boost::asio::basic_waitable_timer< std::chrono::steady_clocktimer_
 

Friends

class LedgerReplayTask
 
class test::LedgerReplayClient
 

Detailed Description

Manage the retrieval of a ledger delta (header and transactions) from the network.

Before asking peers, always check if the local node has the ledger.

Definition at line 25 of file LedgerDeltaAcquire.h.

Member Typedef Documentation

◆ OnDeltaDataCB

using xrpl::LedgerDeltaAcquire::OnDeltaDataCB = std::function<void(bool successful, uint256 const& hash)>

A callback used to notify that the delta's data is ready or failed.

Parameters
successfulif the ledger delta data was acquired successfully
hashhash of the ledger to build

Definition at line 36 of file LedgerDeltaAcquire.h.

◆ ScopedLockType

Definition at line 64 of file TimeoutCounter.h.

Constructor & Destructor Documentation

◆ LedgerDeltaAcquire()

xrpl::LedgerDeltaAcquire::LedgerDeltaAcquire ( Application app,
InboundLedgers inboundLedgers,
uint256 const &  ledgerHash,
std::uint32_t  ledgerSeq,
std::unique_ptr< PeerSet peerSet 
)

Constructor.

Parameters
appApplication reference
inboundLedgersInboundLedgers reference
ledgerHashhash of the ledger
ledgerSeqsequence number of the ledger
peerSetmanage a set of peers that we will ask for the ledger

Definition at line 13 of file LedgerDeltaAcquire.cpp.

◆ ~LedgerDeltaAcquire()

xrpl::LedgerDeltaAcquire::~LedgerDeltaAcquire ( )
override

Definition at line 34 of file LedgerDeltaAcquire.cpp.

Member Function Documentation

◆ init()

void xrpl::LedgerDeltaAcquire::init ( int  numPeers)

Start the LedgerDeltaAcquire task.

Parameters
numPeersnumber of peers to try initially

Definition at line 40 of file LedgerDeltaAcquire.cpp.

◆ processData()

void xrpl::LedgerDeltaAcquire::processData ( LedgerHeader const &  info,
std::map< std::uint32_t, std::shared_ptr< STTx const > > &&  orderedTxns 
)

Process the data extracted from a peer's reply.

Parameters
infoinfo (header) of the ledger
orderedTxnsset of Txns of the ledger
Note
info and Txns must have been verified against the ledger hash

Definition at line 121 of file LedgerDeltaAcquire.cpp.

◆ tryBuild()

std::shared_ptr< Ledger const > xrpl::LedgerDeltaAcquire::tryBuild ( std::shared_ptr< Ledger const > const &  parent)

Try to build the ledger if not already.

Parameters
parentparent ledger
Returns
the ledger if built, nullptr otherwise (e.g. waiting for peers' replies of the ledger info (header) and Txns.)
Note
may throw runtime_error if the replay failed due to data error

Definition at line 174 of file LedgerDeltaAcquire.cpp.

◆ addDataCallback()

void xrpl::LedgerDeltaAcquire::addDataCallback ( InboundLedger::Reason  reason,
OnDeltaDataCB &&  cb 
)

Add a reason and a callback to the LedgerDeltaAcquire subtask.

The reason is used to process the ledger once it is replayed. The callback is called when the delta's data is ready or failed

Note
the callback will be called once and only once unless this object is destructed before the call.

Definition at line 152 of file LedgerDeltaAcquire.cpp.

◆ onTimer()

void xrpl::LedgerDeltaAcquire::onTimer ( bool  progress,
ScopedLockType  
)
overrideprivatevirtual

Hook called from invokeOnTimer().

Implements xrpl::TimeoutCounter.

Definition at line 99 of file LedgerDeltaAcquire.cpp.

◆ pmDowncast()

std::weak_ptr< TimeoutCounter > xrpl::LedgerDeltaAcquire::pmDowncast ( )
overrideprivatevirtual

Return a weak pointer to this.

Implements xrpl::TimeoutCounter.

Definition at line 115 of file LedgerDeltaAcquire.cpp.

◆ trigger()

void xrpl::LedgerDeltaAcquire::trigger ( std::size_t  limit,
ScopedLockType sl 
)
private

Trigger another round.

Parameters
limitnumber of new peers to send the request
sllock. this function must be called with the lock

Definition at line 51 of file LedgerDeltaAcquire.cpp.

◆ onLedgerBuilt()

void xrpl::LedgerDeltaAcquire::onLedgerBuilt ( ScopedLockType sl,
std::optional< InboundLedger::Reason reason = {} 
)
private

Process a newly built ledger, such as store it.

Parameters
sllock. this function must be called with the lock
reasonspecific new reason if any
Note
this function should be called (1) when the ledger is built the first time, and (2) when a LedgerReplayTask with a new reason is added.

Definition at line 210 of file LedgerDeltaAcquire.cpp.

◆ notify()

void xrpl::LedgerDeltaAcquire::notify ( ScopedLockType sl)
private

Call the OnDeltaDataCB callbacks.

Parameters
sllock. this function must be called with the lock

Definition at line 249 of file LedgerDeltaAcquire.cpp.

◆ cancel()

void xrpl::TimeoutCounter::cancel ( )
virtualinherited

Cancel the task by marking it as failed if the task is not done.

Note
this function does not attempt to cancel the scheduled timer or to remove the queued job if any. When the timer expires or the queued job starts, however, the code will see that the task is done and returns immediately, if it can lock the weak pointer of the task.

Definition at line 100 of file TimeoutCounter.cpp.

◆ setTimer()

void xrpl::TimeoutCounter::setTimer ( ScopedLockType sl)
protectedinherited

Schedule a call to queueJob() after mTimerInterval.

Definition at line 32 of file TimeoutCounter.cpp.

◆ queueJob()

void xrpl::TimeoutCounter::queueJob ( ScopedLockType sl)
protectedinherited

Queue a job to call invokeOnTimer().

Definition at line 51 of file TimeoutCounter.cpp.

◆ isDone()

bool xrpl::TimeoutCounter::isDone ( ) const
protectedinherited

Definition at line 99 of file TimeoutCounter.h.

◆ invokeOnTimer()

void xrpl::TimeoutCounter::invokeOnTimer ( )
privateinherited

Calls onTimer() if in the right state.

Only called by queueJob().

Definition at line 75 of file TimeoutCounter.cpp.

◆ getCounter()

static auto & xrpl::CountedObject< LedgerDeltaAcquire >::getCounter ( )
staticprivatenoexceptinherited

Definition at line 110 of file CountedObject.h.

Friends And Related Symbol Documentation

◆ LedgerReplayTask

friend class LedgerReplayTask
friend

Definition at line 141 of file LedgerDeltaAcquire.h.

◆ test::LedgerReplayClient

friend class test::LedgerReplayClient
friend

Definition at line 142 of file LedgerDeltaAcquire.h.

Member Data Documentation

◆ inboundLedgers_

InboundLedgers& xrpl::LedgerDeltaAcquire::inboundLedgers_
private

Definition at line 130 of file LedgerDeltaAcquire.h.

◆ ledgerSeq_

std::uint32_t const xrpl::LedgerDeltaAcquire::ledgerSeq_
private

Definition at line 131 of file LedgerDeltaAcquire.h.

◆ peerSet_

std::unique_ptr<PeerSet> xrpl::LedgerDeltaAcquire::peerSet_
private

Definition at line 132 of file LedgerDeltaAcquire.h.

◆ replayTemp_

std::shared_ptr<Ledger const> xrpl::LedgerDeltaAcquire::replayTemp_ = {}
private

Definition at line 133 of file LedgerDeltaAcquire.h.

◆ fullLedger_

std::shared_ptr<Ledger const> xrpl::LedgerDeltaAcquire::fullLedger_ = {}
private

Definition at line 134 of file LedgerDeltaAcquire.h.

◆ orderedTxns_

std::map<std::uint32_t, std::shared_ptr<STTx const> > xrpl::LedgerDeltaAcquire::orderedTxns_
private

Definition at line 135 of file LedgerDeltaAcquire.h.

◆ dataReadyCallbacks_

std::vector<OnDeltaDataCB> xrpl::LedgerDeltaAcquire::dataReadyCallbacks_
private

Definition at line 136 of file LedgerDeltaAcquire.h.

◆ reasons_

std::set<InboundLedger::Reason> xrpl::LedgerDeltaAcquire::reasons_
private

Definition at line 137 of file LedgerDeltaAcquire.h.

◆ noFeaturePeerCount

std::uint32_t xrpl::LedgerDeltaAcquire::noFeaturePeerCount = 0
private

Definition at line 138 of file LedgerDeltaAcquire.h.

◆ fallBack_

bool xrpl::LedgerDeltaAcquire::fallBack_ = false
private

Definition at line 139 of file LedgerDeltaAcquire.h.

◆ app_

Application& xrpl::TimeoutCounter::app_
protectedinherited

Definition at line 106 of file TimeoutCounter.h.

◆ journal_

beast::Journal xrpl::TimeoutCounter::journal_
protectedinherited

Definition at line 107 of file TimeoutCounter.h.

◆ mtx_

std::recursive_mutex xrpl::TimeoutCounter::mtx_
mutableprotectedinherited

Definition at line 108 of file TimeoutCounter.h.

◆ hash_

uint256 const xrpl::TimeoutCounter::hash_
protectedinherited

The hash of the object (in practice, always a ledger) we are trying to fetch.

Definition at line 112 of file TimeoutCounter.h.

◆ timeouts_

int xrpl::TimeoutCounter::timeouts_
protectedinherited

Definition at line 113 of file TimeoutCounter.h.

◆ complete_

bool xrpl::TimeoutCounter::complete_
protectedinherited

Definition at line 114 of file TimeoutCounter.h.

◆ failed_

bool xrpl::TimeoutCounter::failed_
protectedinherited

Definition at line 115 of file TimeoutCounter.h.

◆ progress_

bool xrpl::TimeoutCounter::progress_
protectedinherited

Whether forward progress has been made.

Definition at line 117 of file TimeoutCounter.h.

◆ timerInterval_

std::chrono::milliseconds xrpl::TimeoutCounter::timerInterval_
protectedinherited

The minimum time to wait between calls to execute().

Definition at line 119 of file TimeoutCounter.h.

◆ queueJobParameter_

QueueJobParameter xrpl::TimeoutCounter::queueJobParameter_
protectedinherited

Definition at line 121 of file TimeoutCounter.h.

◆ timer_

boost::asio::basic_waitable_timer<std::chrono::steady_clock> xrpl::TimeoutCounter::timer_
privateinherited

Definition at line 130 of file TimeoutCounter.h.