1#include <xrpld/app/ledger/detail/SkipListAcquire.h>
3#include <xrpld/app/ledger/InboundLedger.h>
4#include <xrpld/app/ledger/InboundLedgers.h>
5#include <xrpld/app/ledger/LedgerMaster.h>
6#include <xrpld/app/ledger/LedgerReplayer.h>
7#include <xrpld/app/ledger/detail/TimeoutCounter.h>
8#include <xrpld/app/main/Application.h>
9#include <xrpld/overlay/Peer.h>
10#include <xrpld/overlay/PeerSet.h>
12#include <xrpl/basics/Log.h>
13#include <xrpl/basics/base_uint.h>
14#include <xrpl/beast/utility/instrumentation.h>
15#include <xrpl/core/Job.h>
16#include <xrpl/ledger/entries/LedgerHashesEntry.h>
17#include <xrpl/protocol/Indexes.h>
18#include <xrpl/protocol/SField.h>
19#include <xrpl/shamap/SHAMapItem.h>
21#include <boost/smart_ptr/intrusive_ptr.hpp>
43 .jobName =
"SkipListAcq",
45 app.getJournal(
"LedgerReplaySkipList"))
46 , inboundLedgers_(inboundLedgers)
47 , peerSet_(std::move(peerSet))
49 JLOG(journal_.trace()) <<
"Create " << hash_;
71 if (
auto const l =
app_.getLedgerMaster().getLedgerByHash(
hash_); l)
84 peer->hasLedger(
hash_, 0);
89 JLOG(
journal_.trace()) <<
"Add a peer " << peer->id() <<
" for " <<
hash_;
90 protocol::TMProofPathRequest request;
91 request.set_ledgerhash(
hash_.data(),
hash_.size());
93 request.set_type(protocol::TMLedgerMapType::lmACCOUNT_STATE);
94 peerSet_->sendRequest(request, peer);
99 <<
"Add a no feature peer " << peer->id() <<
" for " <<
hash_;
139 boost::intrusive_ptr<SHAMapItem const>
const& item)
141 XRPL_ASSERT(ledgerSeq != 0 && item,
"xrpl::SkipListAcquire::processData : valid inputs");
151 if (
auto const& skipList = sle->getFieldV256(sfHashes).value(); !skipList.empty())
161 JLOG(
journal_.error()) <<
"failed to retrieve Skip list from verified data " <<
hash_;
172 JLOG(
journal_.debug()) <<
"task added to a finished SkipListAcquire " <<
hash_;
188 hashIndex && hashIndex->isFieldPresent(sfHashes))
190 auto const& slist = hashIndex->getFieldV256(sfHashes).value();
199 JLOG(
journal_.error()) <<
"failed to retrieve Skip list from a ledger " <<
hash_;
218 XRPL_ASSERT(
isDone(),
"xrpl::SkipListAcquire::notify : is done");
224 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::function< void(bool successful, UInt256 const &hash)> OnSkipListDataCB
A callback used to notify that the SkipList is ready or failed.
std::vector< OnSkipListDataCB > dataReadyCallbacks_
std::shared_ptr< SkipListData const > getData() const
void onTimer(bool progress, ScopedLockType &peerSetLock) override
Hook called from invokeOnTimer().
InboundLedgers & inboundLedgers_
void onSkipListAcquired(std::vector< UInt256 > const &skipList, std::uint32_t ledgerSeq, ScopedLockType &sl)
Process the skip list.
~SkipListAcquire() override
SkipListAcquire(Application &app, InboundLedgers &inboundLedgers, UInt256 const &ledgerHash, std::unique_ptr< PeerSet > peerSet)
Constructor.
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.
void init(int numPeers)
Start the SkipListAcquire task.
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.
TimeoutCounter(Application &app, UInt256 const &targetHash, std::chrono::milliseconds timeoutInterval, QueueJobParameter &&jobParameter, beast::Journal journal)
void setTimer(ScopedLockType &)
Schedule a call to queueJob() after timerInterval_.
std::chrono::milliseconds timerInterval_
The minimum time to wait between calls to execute().
Keylet const & skip() noexcept
The index of the "short" skip list.
constexpr auto kSubTaskFallbackTimeout
constexpr auto kMaxNoFeaturePeerCount
constexpr std::uint32_t kSubTaskMaxTimeouts
constexpr std::uint32_t kMaxQueuedTasks
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
LedgerHashesEntry< ReadView > LedgerHashesEntryR
T shared_from_this(T... args)