xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
xrpld
shamap
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
22
namespace
xrpl
{
23
24
NodeFamily::NodeFamily
(
Application
& app,
CollectorManager
& cm)
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(),
34
kFullBelowTargetSize
,
35
kFullBelowExpiration
))
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
46
void
47
NodeFamily::sweep
()
48
{
49
fbCache_
->sweep();
50
tnCache_
->sweep();
51
}
52
53
void
54
NodeFamily::reset
()
55
{
56
{
57
std::scoped_lock
const
lock(
maxSeqMutex_
);
58
maxSeq_
= 0;
59
}
60
61
(*fbCache_).reset();
62
(*tnCache_).reset();
63
}
64
65
void
66
NodeFamily::missingNodeAcquireBySeq
(
std::uint32_t
seq,
UInt256
const
& nodeHash)
67
{
68
JLOG(
j_
.error()) <<
"Missing node in "
<< seq;
69
std::unique_lock<std::mutex>
lock(
maxSeqMutex_
);
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
94
void
95
NodeFamily::acquire
(
UInt256
const
& hash,
std::uint32_t
seq)
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
chrono
xrpl::Application
Definition
Application.h:94
xrpl::BaseUInt::isNonZero
bool isNonZero() const
Definition
base_uint.h:567
xrpl::CollectorManager
Provides the beast::insight::Collector service.
Definition
CollectorManager.h:17
xrpl::InboundLedger::Reason::GENERIC
@ GENERIC
Definition
InboundLedger.h:43
xrpl::NodeFamily::acquire
void acquire(UInt256 const &hash, std::uint32_t seq)
Definition
NodeFamily.cpp:95
xrpl::NodeFamily::missingNodeAcquireBySeq
void missingNodeAcquireBySeq(std::uint32_t seq, UInt256 const &hash) override
Acquire ledger that has a missing node by ledger sequence.
Definition
NodeFamily.cpp:66
xrpl::NodeFamily::reset
void reset() override
Definition
NodeFamily.cpp:54
xrpl::NodeFamily::tnCache_
std::shared_ptr< TreeNodeCache > tnCache_
Definition
NodeFamily.h:87
xrpl::NodeFamily::app_
Application & app_
Definition
NodeFamily.h:82
xrpl::NodeFamily::sweep
void sweep() override
Definition
NodeFamily.cpp:47
xrpl::NodeFamily::maxSeqMutex_
std::mutex maxSeqMutex_
Definition
NodeFamily.h:91
xrpl::NodeFamily::NodeFamily
NodeFamily()=delete
xrpl::NodeFamily::fbCache_
std::shared_ptr< FullBelowCache > fbCache_
Definition
NodeFamily.h:86
xrpl::NodeFamily::db_
node_store::Database & db_
Definition
NodeFamily.h:83
xrpl::NodeFamily::j_
beast::Journal const j_
Definition
NodeFamily.h:84
xrpl::NodeFamily::maxSeq_
LedgerIndex maxSeq_
Definition
NodeFamily.h:90
cstdint
std::uint32_t
memory
mutex
std
STL namespace.
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::stopwatch
Stopwatch & stopwatch()
Returns an instance of a wall clock.
Definition
chrono.h:101
xrpl::kFullBelowTargetSize
constexpr std::size_t kFullBelowTargetSize
Definition
src/xrpld/app/main/Tuning.h:8
xrpl::FullBelowCache
detail::BasicFullBelowCache FullBelowCache
Definition
FullBelowCache.h:142
xrpl::kFullBelowExpiration
constexpr std::chrono::seconds kFullBelowExpiration
Definition
src/xrpld/app/main/Tuning.h:9
xrpl::SizedItem
SizedItem
Definition
src/xrpld/core/Config.h:31
xrpl::SizedItem::TreeCacheAge
@ TreeCacheAge
Definition
src/xrpld/core/Config.h:34
xrpl::SizedItem::TreeCacheSize
@ TreeCacheSize
Definition
src/xrpld/core/Config.h:33
xrpl::to_string
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition
base_uint.h:657
xrpl::TreeNodeCache
TaggedCache< UInt256, SHAMapTreeNode, false, intr_ptr::SharedWeakUnionPtr< SHAMapTreeNode >, SHAMapTreeNodePtr > TreeNodeCache
Definition
TreeNodeCache.h:10
xrpl::UInt256
BaseUInt< 256 > UInt256
Definition
base_uint.h:580
std::scoped_lock
std::unique_lock
Generated by
1.17.0