xrpld
Loading...
Searching...
No Matches
xrpl::TransactionAcquire Class Reference

#include <TransactionAcquire.h>

Inheritance diagram for xrpl::TransactionAcquire:
Collaboration diagram for xrpl::TransactionAcquire:

Public Types

using pointer = std::shared_ptr<TransactionAcquire>

Public Member Functions

 TransactionAcquire (Application &app, UInt256 const &hash, std::unique_ptr< PeerSet > peerSet, std::chrono::milliseconds retryInterval=kRetryInterval)
 ~TransactionAcquire () override=default
SHAMapAddNode takeNodes (std::vector< std::pair< SHAMapNodeID, SHAMapTreeNodePtr > > data, std::shared_ptr< Peer > const &peer)
void init (int startPeers)
void stillNeed ()
virtual void cancel ()
 Cancel the task by marking it as failed if the task is not done.
T shared_from_this (T... args)
T weak_from_this (T... args)

Public Attributes

friend Object

Static Public Attributes

static constexpr std::chrono::milliseconds kRetryInterval {250}
 How long to wait between retries, and so how long one timeout takes.

Protected Types

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

Protected Member Functions

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

Protected Attributes

std::shared_ptr< SHAMap > map_
Application & app_
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_ {0}
bool complete_ {false}
bool failed_ {false}
bool progress_ {false}
 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 &sl) override
 Hook called from invokeOnTimer().
void done ()
 Settle the acquired set and hand it on, or report the failure.
void addPeers (std::size_t limit)
void trigger (std::shared_ptr< Peer > const &)
std::weak_ptr< TimeoutCounter > pmDowncast () override
 Return a weak pointer to this.
void invokeOnTimer ()
 Calls onTimer() if in the right state.

Static Private Member Functions

static auto & getCounter () noexcept

Private Attributes

bool haveRoot_ {false}
std::unique_ptr< PeerSet > peerSet_
boost::asio::basic_waitable_timer< std::chrono::steady_clock > timer_

Detailed Description

Definition at line 25 of file TransactionAcquire.h.

Member Typedef Documentation

◆ pointer

◆ ScopedLockType

Definition at line 71 of file TimeoutCounter.h.

Constructor & Destructor Documentation

◆ TransactionAcquire()

xrpl::TransactionAcquire::TransactionAcquire ( Application & app,
UInt256 const & hash,
std::unique_ptr< PeerSet > peerSet,
std::chrono::milliseconds retryInterval = kRetryInterval )
Parameters
appThe application to run in.
hashThe set to acquire.
peerSetWhich peers to ask, and how to reach them.
retryIntervalHow long to wait between retries. TimeoutCounter requires more than 10ms and less than 30s.

Definition at line 34 of file TransactionAcquire.cpp.

◆ ~TransactionAcquire()

xrpl::TransactionAcquire::~TransactionAcquire ( )
overridedefault

Member Function Documentation

◆ takeNodes()

SHAMapAddNode xrpl::TransactionAcquire::takeNodes ( std::vector< std::pair< SHAMapNodeID, SHAMapTreeNodePtr > > data,
std::shared_ptr< Peer > const & peer )

Definition at line 184 of file TransactionAcquire.cpp.

◆ init()

void xrpl::TransactionAcquire::init ( int startPeers)

Definition at line 259 of file TransactionAcquire.cpp.

◆ stillNeed()

void xrpl::TransactionAcquire::stillNeed ( )

Definition at line 269 of file TransactionAcquire.cpp.

◆ onTimer()

void xrpl::TransactionAcquire::onTimer ( bool progress,
ScopedLockType & sl )
overrideprivatevirtual

Hook called from invokeOnTimer().

Parameters
progressWhether the subtype recorded progress since the last call.
slProof mtx_ is held. mtx_ is recursive, so a nested lock taken inside the call does not release it.

Implements xrpl::TimeoutCounter.

Definition at line 93 of file TransactionAcquire.cpp.

◆ done()

void xrpl::TransactionAcquire::done ( )
private

Settle the acquired set and hand it on, or report the failure.

Call under mtx_. Runs once per outcome, and a stillNeed() revival gives one object a second outcome.

Definition at line 52 of file TransactionAcquire.cpp.

◆ addPeers()

void xrpl::TransactionAcquire::addPeers ( std::size_t limit)
private

Definition at line 250 of file TransactionAcquire.cpp.

◆ trigger()

void xrpl::TransactionAcquire::trigger ( std::shared_ptr< Peer > const & peer)
private

Definition at line 115 of file TransactionAcquire.cpp.

◆ pmDowncast()

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

Return a weak pointer to this.

Implements xrpl::TimeoutCounter.

Definition at line 109 of file TransactionAcquire.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 105 of file TimeoutCounter.cpp.

◆ setTimer()

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

Schedule a call to queueJob() after timerInterval_.

Definition at line 40 of file TimeoutCounter.cpp.

◆ queueJob()

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

Queue a job to call invokeOnTimer().

Definition at line 58 of file TimeoutCounter.cpp.

◆ isDone()

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

Definition at line 117 of file TimeoutCounter.h.

◆ invokeOnTimer()

void xrpl::TimeoutCounter::invokeOnTimer ( )
privateinherited

Calls onTimer() if in the right state.

Only called by queueJob().

Definition at line 80 of file TimeoutCounter.cpp.

◆ getCounter()

auto & xrpl::CountedObject< TransactionAcquire >::getCounter ( )
staticprivatenoexceptinherited

Definition at line 113 of file CountedObject.h.

Member Data Documentation

◆ kRetryInterval

std::chrono::milliseconds xrpl::TransactionAcquire::kRetryInterval {250}
staticconstexpr

How long to wait between retries, and so how long one timeout takes.

Definition at line 35 of file TransactionAcquire.h.

◆ map_

std::shared_ptr<SHAMap> xrpl::TransactionAcquire::map_
protected

Definition at line 65 of file TransactionAcquire.h.

◆ haveRoot_

bool xrpl::TransactionAcquire::haveRoot_ {false}
private

Definition at line 68 of file TransactionAcquire.h.

◆ peerSet_

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

Definition at line 69 of file TransactionAcquire.h.

◆ app_

Application& xrpl::TimeoutCounter::app_
protectedinherited

Definition at line 124 of file TimeoutCounter.h.

◆ journal_

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

Definition at line 125 of file TimeoutCounter.h.

◆ mtx_

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

Definition at line 126 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 132 of file TimeoutCounter.h.

◆ timeouts_

int xrpl::TimeoutCounter::timeouts_ {0}
protectedinherited

Definition at line 133 of file TimeoutCounter.h.

◆ complete_

bool xrpl::TimeoutCounter::complete_ {false}
protectedinherited

Definition at line 134 of file TimeoutCounter.h.

◆ failed_

bool xrpl::TimeoutCounter::failed_ {false}
protectedinherited

Definition at line 135 of file TimeoutCounter.h.

◆ progress_

bool xrpl::TimeoutCounter::progress_ {false}
protectedinherited

Whether forward progress has been made.

Definition at line 139 of file TimeoutCounter.h.

◆ timerInterval_

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

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

Definition at line 143 of file TimeoutCounter.h.

◆ queueJobParameter_

QueueJobParameter xrpl::TimeoutCounter::queueJobParameter_
protectedinherited

Definition at line 145 of file TimeoutCounter.h.

◆ timer_

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

Definition at line 155 of file TimeoutCounter.h.

◆ Object

Definition at line 138 of file CountedObject.h.