20 #include <ripple/app/ledger/InboundLedgers.h>
21 #include <ripple/app/ledger/LedgerMaster.h>
22 #include <ripple/app/main/Application.h>
23 #include <ripple/app/misc/NetworkOPs.h>
24 #include <ripple/basics/DecayingSample.h>
25 #include <ripple/basics/Log.h>
26 #include <ripple/beast/container/aged_map.h>
27 #include <ripple/beast/core/LexicalCast.h>
28 #include <ripple/core/JobQueue.h>
29 #include <ripple/nodestore/DatabaseShard.h>
30 #include <ripple/protocol/jss.h>
57 ,
j_(app.journal(
"InboundLedger"))
60 ,
mCounter(collector->make_counter(
"ledger_fetches"))
90 inbound = std::make_shared<InboundLedger>(
98 if (inbound->isFailed())
102 inbound->update(seq);
104 if (!inbound->isComplete())
109 if (inbound->getLedger()->stateMap().family().isShardBacked())
118 <<
"Acquiring shard with no shard store available";
121 if (inbound->getLedger()->stateMap().family().isShardBacked())
122 shardStore->setStored(inbound->getLedger());
124 shardStore->storeLedger(inbound->getLedger());
126 return inbound->getLedger();
169 if (
auto ledger =
find(hash))
171 JLOG(
j_.
trace()) <<
"Got data (" << packet->nodes().size()
172 <<
") for acquiring ledger: " << hash;
185 JLOG(
j_.
trace()) <<
"Got data for ledger " << hash
186 <<
" which we're no longer acquiring";
190 if (packet->type() == protocol::liAS_NODE)
231 for (
int i = 0; i < packet_ptr->nodes().size(); ++i)
233 auto const& node = packet_ptr->nodes(i);
235 if (!node.has_nodeid() || !node.has_nodedata())
245 newNode->serializeWithPrefix(s);
248 newNode->getHash().as_uint256(),
249 std::make_shared<Blob>(s.
begin(), s.
end()));
303 ret[
to_string(it.first)][jss::failed] =
true;
307 for (
auto const& it : acqs)
314 ret[
to_string(it.first)] = it.second->getJson(0);
335 for (
auto const&
acquire : acquires)
357 if (it->second->getLastAction() > now)
380 JLOG(
j_.
debug()) <<
"Swept " << stuffToSweep.
size() <<
" out of "
381 << total <<
" inbound ledgers.";
418 return std::make_unique<InboundLedgersImp>(app, clock, parent, collector);
Json::Value getInfo() override
DecayWindow< 30, clock_type > fetchRate_
std::enable_if_t< std::is_same< T, char >::value||std::is_same< T, unsigned char >::value, Slice > makeSlice(std::array< T, N > const &a)
void stopped()
Called by derived classes to indicate that the stoppable has stopped.
A metric for measuring an integral value.
Stream trace() const
Severity stream access functions.
static constexpr const std::chrono::minutes kReacquireInterval
virtual NodeStore::DatabaseShard * getShardStore()=0
void clearFailures() override
bool addJob(JobType type, std::string const &name, JobHandler &&jobHandler)
Adds a job to the JobQueue.
std::string to_string(ListDisposition disposition)
static std::shared_ptr< SHAMapTreeNode > makeFromWire(Slice rawNode)
std::unique_ptr< InboundLedgers > make_InboundLedgers(Application &app, InboundLedgers::clock_type &clock, Stoppable &parent, beast::insight::Collector::ptr const &collector)
virtual time_point now() const =0
Returns the current time.
std::size_t fetchRate() override
Returns the rate of historical ledger fetches per minute.
Provides an interface for starting and stopping.
@ objectValue
object value (collection of name/value pairs).
void logFailure(uint256 const &h, std::uint32_t seq) override
virtual LedgerMaster & getLedgerMaster()=0
std::shared_ptr< Ledger const > acquire(uint256 const &hash, std::uint32_t seq, InboundLedger::Reason reason) override
virtual JobQueue & getJobQueue()=0
A generic endpoint for log messages.
std::enable_if< is_aged_container< AgedContainer >::value, std::size_t >::type expire(AgedContainer &c, std::chrono::duration< Rep, Period > const &age)
Expire aged container items past the specified age.
void gotFetchPack() override
Abstract interface to a clock.
beast::aged_map< uint256, std::uint32_t > mRecentFailures
Manages the lifetime of inbound ledgers.
void onLedgerFetched() override
Called when a complete ledger is obtained.
std::mutex fetchRateMutex_
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
double value(time_point now)
virtual bool storeLedger(std::shared_ptr< Ledger const > const &srcLedger)=0
Store a ledger from a different database.
virtual NodeStore::Database & getNodeStore()=0
Associative container where each element is also indexed by time.
bool isFailure(uint256 const &h) override
void addFetchPack(uint256 const &hash, std::shared_ptr< Blob > data)
void add(double value, time_point now)
std::recursive_mutex mLock
void gotStaleData(std::shared_ptr< protocol::TMLedgerData > packet_ptr) override
We got some data for a ledger we are no longer acquiring Since we paid the price to receive it,...
beast::insight::Counter mCounter
bool gotLedgerData(LedgerHash const &hash, std::shared_ptr< Peer > peer, std::shared_ptr< protocol::TMLedgerData > packet) override
We received a TMLedgerData from a peer.
typename std::chrono::steady_clock ::time_point time_point
InboundLedgersImp(Application &app, clock_type &clock, Stoppable &parent, beast::insight::Collector::ptr const &collector)
beast::abstract_clock< std::chrono::steady_clock > clock_type
std::shared_ptr< InboundLedger > find(uint256 const &hash) override
bool isStopping() const
Returns true if the stoppable should stop.