xrpld
Loading...
Searching...
No Matches
NodeFamily.cpp
1#include <xrpld/shamap/NodeFamily.h>
2
3#include <xrpld/app/ledger/InboundLedger.h>
4#include <xrpld/app/ledger/LedgerMaster.h>
5#include <xrpld/app/main/Application.h>
6#include <xrpld/app/main/CollectorManager.h>
7#include <xrpld/app/main/Tuning.h>
8#include <xrpld/core/Config.h>
9
10#include <xrpl/basics/Log.h>
11#include <xrpl/basics/base_uint.h>
12#include <xrpl/basics/chrono.h>
13#include <xrpl/shamap/FullBelowCache.h>
14#include <xrpl/shamap/TreeNodeCache.h>
15
16#include <chrono>
17#include <cstdint>
18#include <memory>
19#include <mutex>
20
21namespace xrpl {
22
24 : app_(app)
25 , db_(app.getNodeStore())
26 , j_(app.getJournal("NodeFamily"))
27 , fbCache_(
28 std::make_shared<FullBelowCache>(
29 "Node family full below cache",
30 stopwatch(),
31 app.getJournal("NodeFamilyFulLBelowCache"),
32 cm.collector(),
35 , tnCache_(
36 std::make_shared<TreeNodeCache>(
37 "Node family tree node cache",
38 app.config().getValueFor(SizedItem::TreeCacheSize),
39 std::chrono::seconds(app.config().getValueFor(SizedItem::TreeCacheAge)),
40 stopwatch(),
41 j_))
42{
43}
44
45void
47{
48 fbCache_->sweep();
49 tnCache_->sweep();
50}
51
52void
54{
55 {
57 maxSeq_ = 0;
58 }
59
60 (*fbCache_).reset();
61 (*tnCache_).reset();
62}
63
64void
66{
67 JLOG(j_.error()) << "Missing node in " << seq;
69 if (maxSeq_ == 0)
70 {
71 maxSeq_ = seq;
72
73 do
74 {
75 // Try to acquire the most recent missing ledger
76 seq = maxSeq_;
77
78 lock.unlock();
79
80 // This can invoke the missing node handler
81 acquire(app_.getLedgerMaster().getHashBySeq(seq), seq);
82
83 lock.lock();
84 } while (maxSeq_ != seq);
85 }
86 else if (maxSeq_ < seq)
87 {
88 // We found a more recent ledger with a missing node
89 maxSeq_ = seq;
90 }
91}
92
93void
95{
96 if (hash.isNonZero())
97 {
98 JLOG(j_.error()) << "Missing node in " << to_string(hash);
99
100 app_.getInboundLedgers().acquire(hash, seq, InboundLedger::Reason::GENERIC);
101 }
102}
103
104} // namespace xrpl
bool isNonZero() const
Definition base_uint.h:549
Provides the beast::insight::Collector service.
void reset() override
std::shared_ptr< TreeNodeCache > tnCache_
Definition NodeFamily.h:78
Application & app_
Definition NodeFamily.h:73
NodeStore::Database & db_
Definition NodeFamily.h:74
void acquire(uint256 const &hash, std::uint32_t seq)
void sweep() override
std::mutex maxSeqMutex_
Definition NodeFamily.h:82
NodeFamily()=delete
std::shared_ptr< FullBelowCache > fbCache_
Definition NodeFamily.h:77
beast::Journal const j_
Definition NodeFamily.h:75
LedgerIndex maxSeq_
Definition NodeFamily.h:81
void missingNodeAcquireBySeq(std::uint32_t seq, uint256 const &hash) override
Acquire ledger that has a missing node by ledger sequence.
STL namespace.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
Stopwatch & stopwatch()
Returns an instance of a wall clock.
Definition chrono.h:94
constexpr std::size_t kFullBelowTargetSize
detail::BasicFullBelowCache FullBelowCache
constexpr std::chrono::seconds kFullBelowExpiration
TaggedCache< uint256, SHAMapTreeNode, false, intr_ptr::SharedWeakUnionPtr< SHAMapTreeNode >, SHAMapTreeNodePtr > TreeNodeCache
SizedItem
Definition Config.h:27
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:633
BaseUInt< 256 > uint256
Definition base_uint.h:562