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"))
100 inbound = std::make_shared<InboundLedger>(
113 if (inbound->isFailed())
117 inbound->update(seq);
119 if (!inbound->isComplete())
124 if (inbound->getLedger()->stateMap().family().isShardBacked())
133 <<
"Acquiring shard with no shard store available";
136 if (inbound->getLedger()->stateMap().family().isShardBacked())
137 shardStore->setStored(inbound->getLedger());
139 shardStore->storeLedger(inbound->getLedger());
141 return inbound->getLedger();
184 if (
auto ledger =
find(hash))
186 JLOG(
j_.
trace()) <<
"Got data (" << packet->nodes().size()
187 <<
") for acquiring ledger: " << hash;
200 JLOG(
j_.
trace()) <<
"Got data for ledger " << hash
201 <<
" which we're no longer acquiring";
205 if (packet->type() == protocol::liAS_NODE)
245 for (
int i = 0; i < packet_ptr->nodes().size(); ++i)
247 auto const& node = packet_ptr->nodes(i);
249 if (!node.has_nodeid() || !node.has_nodedata())
259 newNode->serializeWithPrefix(s);
262 newNode->getHash().as_uint256(),
263 std::make_shared<Blob>(s.
begin(), s.
end()));
317 ret[
to_string(it.first)][jss::failed] =
true;
321 for (
auto const& it : acqs)
328 ret[
to_string(it.first)] = it.second->getJson(0);
349 for (
auto const&
acquire : acquires)
373 auto const la = it->second->getLastAction();
397 <<
"Swept " << stuffToSweep.
size() <<
" out of " << total
398 <<
" inbound ledgers. Duration: "
399 << std::chrono::duration_cast<std::chrono::milliseconds>(
439 return std::make_unique<InboundLedgersImp>(
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)
A metric for measuring an integral value.
Stream trace() const
Severity stream access functions.
std::unique_ptr< PeerSetBuilder > mPeerSetBuilder
std::unique_ptr< InboundLedgers > make_InboundLedgers(Application &app, InboundLedgers::clock_type &clock, beast::insight::Collector::ptr const &collector)
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.
static std::shared_ptr< SHAMapTreeNode > makeFromWire(Slice rawNode)
virtual NetworkOPs & getOPs()=0
virtual time_point now() const =0
Returns the current time.
std::size_t fetchRate() override
Returns the rate of historical ledger fetches per minute.
virtual bool isNeedNetworkLedger()=0
InboundLedgersImp(Application &app, clock_type &clock, beast::insight::Collector::ptr const &collector, std::unique_ptr< PeerSetBuilder > peerSetBuilder)
@ 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_
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)
std::unique_ptr< PeerSetBuilder > make_PeerSetBuilder(Application &app)
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
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
bool gotLedgerData(LedgerHash const &hash, std::shared_ptr< Peer > peer, std::shared_ptr< protocol::TMLedgerData > packet) override
We received a TMLedgerData from a peer.
beast::abstract_clock< std::chrono::steady_clock > clock_type
std::shared_ptr< InboundLedger > find(uint256 const &hash) override