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/InboundLedgers.h>
5#include <xrpld/app/ledger/LedgerMaster.h>
6#include <xrpld/app/main/Application.h>
7#include <xrpld/app/main/CollectorManager.h>
8#include <xrpld/app/main/Tuning.h>
9#include <xrpld/core/Config.h>
10
11#include <xrpl/basics/Log.h>
12#include <xrpl/basics/base_uint.h>
13#include <xrpl/basics/chrono.h>
14#include <xrpl/shamap/FullBelowCache.h>
15#include <xrpl/shamap/TreeNodeCache.h>
16
17#include <chrono>
18#include <cstdint>
19#include <memory>
20#include <mutex>
21
22namespace xrpl {
23
25 : app_(app)
26 , db_(app.getNodeStore())
27 , j_(app.getJournal("NodeFamily"))
28 , fbCache_(
29 std::make_shared<FullBelowCache>(
30 "Node family full below cache",
31 stopwatch(),
32 app.getJournal("NodeFamilyFulLBelowCache"),
33 cm.collector(),
36 , tnCache_(
37 std::make_shared<TreeNodeCache>(
38 "Node family tree node cache",
39 app.config().getValueFor(SizedItem::TreeCacheSize),
40 std::chrono::seconds(app.config().getValueFor(SizedItem::TreeCacheAge)),
41 stopwatch(),
42 j_))
43{
44}
45
46void
48{
49 fbCache_->sweep();
50 tnCache_->sweep();
51}
52
53void
55{
56 {
58 maxSeq_ = 0;
59 }
60
61 (*fbCache_).reset();
62 (*tnCache_).reset();
63}
64
65void
67{
68 JLOG(j_.error()) << "Missing node in " << seq;
70 if (maxSeq_ == 0)
71 {
72 maxSeq_ = seq;
73
74 do
75 {
76 // Try to acquire the most recent missing ledger
77 seq = maxSeq_;
78
79 lock.unlock();
80
81 // This can invoke the missing node handler
82 acquire(app_.getLedgerMaster().getHashBySeq(seq), seq);
83
84 lock.lock();
85 } while (maxSeq_ != seq);
86 }
87 else if (maxSeq_ < seq)
88 {
89 // We found a more recent ledger with a missing node
90 maxSeq_ = seq;
91 }
92}
93
94void
96{
97 if (hash.isNonZero())
98 {
99 JLOG(j_.error()) << "Missing node in " << to_string(hash);
100
101 app_.getInboundLedgers().acquire(hash, seq, InboundLedger::Reason::GENERIC);
102 }
103}
104
105} // namespace xrpl
bool isNonZero() const
Definition base_uint.h:567
Provides the beast::insight::Collector service.
void reset() override
std::shared_ptr< TreeNodeCache > tnCache_
Definition NodeFamily.h:87
Application & app_
Definition NodeFamily.h:82
void acquire(uint256 const &hash, std::uint32_t seq)
void sweep() override
std::mutex maxSeqMutex_
Definition NodeFamily.h:91
NodeFamily()=delete
std::shared_ptr< FullBelowCache > fbCache_
Definition NodeFamily.h:86
node_store::Database & db_
Definition NodeFamily.h:83
beast::Journal const j_
Definition NodeFamily.h:84
LedgerIndex maxSeq_
Definition NodeFamily.h:90
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:101
constexpr std::size_t kFullBelowTargetSize
detail::BasicFullBelowCache FullBelowCache
constexpr std::chrono::seconds kFullBelowExpiration
TaggedCache< uint256, SHAMapTreeNode, false, intr_ptr::SharedWeakUnionPtr< SHAMapTreeNode >, SHAMapTreeNodePtr > TreeNodeCache
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:651
BaseUInt< 256 > uint256
Definition base_uint.h:580