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/core/JobQueue.h>
27 #include <ripple/nodestore/DatabaseShard.h>
28 #include <ripple/protocol/jss.h>
29 #include <ripple/beast/core/LexicalCast.h>
30 #include <ripple/beast/container/aged_map.h>
60 ,
j_ (app.journal (
"InboundLedger"))
63 ,
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();
166 protocol::TMLedgerData& packet = *packet_ptr;
169 <<
"Got data (" << packet.nodes ().size ()
170 <<
") for acquiring ledger: " << hash;
172 auto ledger =
find (hash);
177 <<
"Got data for ledger we're no longer acquiring";
181 if (packet.type () == protocol::liAS_NODE)
217 for (
auto const& it : inboundLedgers)
219 if (it.second->isActive ())
222 timeoutCount += it.
second->getTimeouts ();
245 if (
auto ledger =
find (hash))
261 for (
int i = 0; i < packet_ptr->nodes ().size (); ++i)
263 auto const& node = packet_ptr->nodes (i);
265 if (!node.has_nodeid () || !node.has_nodedata ())
268 auto id_string = node.nodeid();
280 auto blob = std::make_shared<Blob> (s.
begin(), s.
end());
283 newNode->getNodeHash().as_uint256(), blob);
331 ret[beast::lexicalCastThrow <std::string>(
332 it.second)][jss::failed] =
true;
334 ret[
to_string (it.first)][jss::failed] =
true;
338 for (
auto const& it : acquires)
345 ret[
to_string (it.first)] = it.second->getJson(0);
365 for (
auto const&
acquire : acquires)
386 if (it->second->getLastAction () > now)
388 it->second->touch ();
391 else if ((it->second->getLastAction () +
410 "Swept " << stuffToSweep.
size () <<
411 " out of " << total <<
" inbound ledgers.";
450 return std::make_unique<InboundLedgersImp> (app, clock, parent, collector);
Json::Value getInfo() override
void doLedgerData(LedgerHash hash) 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 std::shared_ptr< SHAMapAbstractNode > make(Slice const &rawNode, std::uint32_t seq, SHANodeFormat format, SHAMapHash const &hash, bool hashValid, beast::Journal j, SHAMapNodeID const &id=SHAMapNodeID{})
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)
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.
beast::abstract_clock< std::chrono::steady_clock > clock_type
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.
void gotFetchPack() override
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_
bool gotLedgerData(LedgerHash const &hash, std::shared_ptr< Peer > peer, std::shared_ptr< protocol::TMLedgerData > packet_ptr) override
We received a TMLedgerData from a peer.
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
Copies a ledger stored in a different database to this one.
virtual NodeStore::Database & getNodeStore()=0
virtual beast::Journal journal(std::string const &name)=0
Associative container where each element is also indexed by time.
bool isFailure(uint256 const &h) override
void add(double value, time_point now)
std::recursive_mutex mLock
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 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
int getFetchCount(int &timeoutCount) override
typename std::chrono::steady_clock ::time_point time_point
InboundLedgersImp(Application &app, clock_type &clock, Stoppable &parent, beast::insight::Collector::ptr const &collector)
void addFetchPack(uint256 const &hash, std::shared_ptr< Blob > &data)
std::shared_ptr< InboundLedger > find(uint256 const &hash) override
static const std::chrono::minutes kReacquireInterval
virtual ~InboundLedgers()=0
bool isStopping() const
Returns true if the stoppable should stop.