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>
59 ,
j_(app.journal(
"InboundLedger"))
62 ,
mCounter(collector->make_counter(
"ledger_fetches"))
92 inbound = std::make_shared<InboundLedger>(
100 if (inbound->isFailed())
104 inbound->update(seq);
106 if (!inbound->isComplete())
111 if (inbound->getLedger()->stateMap().family().isShardBacked())
120 <<
"Acquiring shard with no shard store available";
123 if (inbound->getLedger()->stateMap().family().isShardBacked())
124 shardStore->setStored(inbound->getLedger());
126 shardStore->storeLedger(inbound->getLedger());
128 return inbound->getLedger();
171 protocol::TMLedgerData& packet = *packet_ptr;
173 JLOG(
j_.
trace()) <<
"Got data (" << packet.nodes().size()
174 <<
") for acquiring ledger: " << hash;
176 auto ledger =
find(hash);
180 JLOG(
j_.
trace()) <<
"Got data for ledger we're no longer acquiring";
184 if (packet.type() == protocol::liAS_NODE)
226 if (
auto ledger =
find(hash))
243 for (
int i = 0; i < packet_ptr->nodes().size(); ++i)
245 auto const& node = packet_ptr->nodes(i);
247 if (!node.has_nodeid() || !node.has_nodedata())
260 newNode->getNodeHash().as_uint256(),
261 std::make_shared<Blob>(s.
begin(), s.
end()));
312 ret[beast::lexicalCastThrow<std::string>(it.second)]
313 [jss::failed] =
true;
315 ret[
to_string(it.first)][jss::failed] =
true;
319 for (
auto const& it : acquires)
326 ret[
to_string(it.first)] = it.second->getJson(0);
347 for (
auto const&
acquire : acquires)
369 if (it->second->getLastAction() > now)
392 JLOG(
j_.
debug()) <<
"Swept " << stuffToSweep.
size() <<
" out of "
393 << total <<
" inbound ledgers.";
435 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.
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.
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
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
static std::shared_ptr< SHAMapAbstractNode > makeFromWire(Slice rawNode)
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
void doLedgerData(LedgerHash hash)
Called (indirectly) only by gotLedgerData().
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
static const std::chrono::minutes kReacquireInterval
virtual ~InboundLedgers()=0
bool isStopping() const
Returns true if the stoppable should stop.