1#include <xrpld/app/ledger/detail/SkipListAcquire.h>
3#include <xrpld/app/ledger/InboundLedger.h>
4#include <xrpld/app/ledger/LedgerReplayer.h>
5#include <xrpld/app/ledger/detail/TimeoutCounter.h>
6#include <xrpld/app/main/Application.h>
7#include <xrpld/overlay/Peer.h>
8#include <xrpld/overlay/PeerSet.h>
10#include <xrpl/basics/Log.h>
11#include <xrpl/basics/base_uint.h>
12#include <xrpl/beast/utility/instrumentation.h>
13#include <xrpl/core/Job.h>
14#include <xrpl/protocol/Indexes.h>
15#include <xrpl/protocol/SField.h>
16#include <xrpl/shamap/SHAMapItem.h>
18#include <boost/smart_ptr/intrusive_ptr.hpp>
40 .jobName =
"SkipListAcq",
42 app.getJournal(
"LedgerReplaySkipList"))
43 , inboundLedgers_(inboundLedgers)
44 , peerSet_(std::move(peerSet))
46 JLOG(journal_.trace()) <<
"Create " << hash_;
68 if (
auto const l =
app_.getLedgerMaster().getLedgerByHash(
hash_); l)
81 peer->hasLedger(
hash_, 0);
86 JLOG(
journal_.trace()) <<
"Add a peer " << peer->id() <<
" for " <<
hash_;
87 protocol::TMProofPathRequest request;
88 request.set_ledgerhash(
hash_.data(),
hash_.size());
90 request.set_type(protocol::TMLedgerMapType::lmACCOUNT_STATE);
91 peerSet_->sendRequest(request, peer);
96 <<
"Add a no feature peer " << peer->id() <<
" for " <<
hash_;
136 boost::intrusive_ptr<SHAMapItem const>
const& item)
138 XRPL_ASSERT(ledgerSeq != 0 && item,
"xrpl::SkipListAcquire::processData : valid inputs");
148 if (
auto const& skipList = sle->getFieldV256(sfHashes).value(); !skipList.empty())
158 JLOG(
journal_.error()) <<
"failed to retrieve Skip list from verified data " <<
hash_;
169 JLOG(
journal_.debug()) <<
"task added to a finished SkipListAcquire " <<
hash_;
184 if (
auto const hashIndex = ledger->read(
keylet::skip());
185 hashIndex && hashIndex->isFieldPresent(sfHashes))
187 auto const& slist = hashIndex->getFieldV256(sfHashes).value();
196 JLOG(
journal_.error()) <<
"failed to retrieve Skip list from a ledger " <<
hash_;
215 XRPL_ASSERT(
isDone(),
"xrpl::SkipListAcquire::notify : is done");
221 for (
auto& cb : toCall)
Manages the lifetime of inbound ledgers.
void addDataCallback(OnSkipListDataCB &&cb)
Add a callback that will be called when the skipList is ready or failed.
std::uint32_t noFeaturePeerCount_
std::weak_ptr< TimeoutCounter > pmDowncast() override
Return a weak pointer to this.
std::unique_ptr< PeerSet > peerSet_
std::shared_ptr< SkipListData const > data_
void trigger(std::size_t limit, ScopedLockType &sl)
Trigger another round.
void notify(ScopedLockType &sl)
Call the OnSkipListDataCB callbacks.
std::vector< OnSkipListDataCB > dataReadyCallbacks_
std::shared_ptr< SkipListData const > getData() const
void onTimer(bool progress, ScopedLockType &peerSetLock) override
Hook called from invokeOnTimer().
InboundLedgers & inboundLedgers_
~SkipListAcquire() override
std::function< void(bool successful, uint256 const &hash)> OnSkipListDataCB
A callback used to notify that the SkipList is ready or failed.
void onSkipListAcquired(std::vector< uint256 > const &skipList, std::uint32_t ledgerSeq, ScopedLockType &sl)
Process the skip list.
void retrieveSkipList(std::shared_ptr< Ledger const > const &ledger, ScopedLockType &sl)
Retrieve the skip list from the ledger.
void processData(std::uint32_t ledgerSeq, boost::intrusive_ptr< SHAMapItem const > const &item)
Process the data extracted from a peer's reply.
SkipListAcquire(Application &app, InboundLedgers &inboundLedgers, uint256 const &ledgerHash, std::unique_ptr< PeerSet > peerSet)
Constructor.
void init(int numPeers)
Start the SkipListAcquire task.
TimeoutCounter(Application &app, uint256 const &targetHash, std::chrono::milliseconds timeoutInterval, QueueJobParameter &&jobParameter, beast::Journal journal)
std::recursive_mutex mtx_
std::unique_lock< std::recursive_mutex > ScopedLockType
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 timerInterval_.
std::chrono::milliseconds timerInterval_
The minimum time to wait between calls to execute().
constexpr auto kSubTaskFallbackTimeout
constexpr auto kMaxNoFeaturePeerCount
constexpr std::uint32_t kSubTaskMaxTimeouts
constexpr std::uint32_t kMaxQueuedTasks
Keylet const & skip() noexcept
The index of the "short" skip list.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
T shared_from_this(T... args)