rippled
NodeFamily.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2020 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #include <ripple/app/ledger/LedgerMaster.h>
21 #include <ripple/app/main/Application.h>
22 #include <ripple/app/main/Tuning.h>
23 #include <ripple/shamap/NodeFamily.h>
24 
25 namespace ripple {
26 
28  : app_(app)
29  , db_(app.getNodeStore())
30  , j_(app.journal("NodeFamily"))
31  , fbCache_(std::make_shared<FullBelowCache>(
32  "Node family full below cache",
33  stopwatch(),
34  cm.collector(),
37  , tnCache_(std::make_shared<TreeNodeCache>(
38  "Node family tree node cache",
39  app.config().getValueFor(SizedItem::treeCacheSize),
40  std::chrono::seconds(
41  app.config().getValueFor(SizedItem::treeCacheAge)),
42  stopwatch(),
43  j_))
44 {
45 }
46 
47 void
49 {
50  fbCache_->sweep();
51  tnCache_->sweep();
52 }
53 
54 void
56 {
57  {
59  maxSeq_ = 0;
60  }
61 
62  fbCache_->reset();
63  tnCache_->reset();
64 }
65 
66 void
68 {
69  JLOG(j_.error()) << "Missing node in " << seq;
70 
72  if (maxSeq_ == 0)
73  {
74  maxSeq_ = seq;
75 
76  do
77  {
78  // Try to acquire the most recent missing ledger
79  seq = maxSeq_;
80 
81  lock.unlock();
82 
83  // This can invoke the missing node handler
85 
86  lock.lock();
87  } while (maxSeq_ != seq);
88  }
89  else if (maxSeq_ < seq)
90  {
91  // We found a more recent ledger with a missing node
92  maxSeq_ = seq;
93  }
94 }
95 
96 void
98 {
99  if (hash.isNonZero())
100  {
101  JLOG(j_.error()) << "Missing node in " << to_string(hash);
102 
104  hash, seq, InboundLedger::Reason::GENERIC);
105  }
106 }
107 
108 } // namespace ripple
ripple::Application
Definition: Application.h:101
ripple::NodeFamily::app_
Application & app_
Definition: NodeFamily.h:95
ripple::NodeFamily::sweep
void sweep() override
Definition: NodeFamily.cpp:48
ripple::TaggedCache
Map/cache combination.
Definition: TaggedCache.h:52
ripple::SizedItem
SizedItem
Definition: Config.h:48
ripple::base_uint::isNonZero
bool isNonZero() const
Definition: base_uint.h:444
ripple::detail::BasicFullBelowCache
Remembers which tree keys have all descendants resident.
Definition: FullBelowCache.h:37
ripple::InboundLedger::Reason::GENERIC
@ GENERIC
ripple::CollectorManager
Provides the beast::insight::Collector service.
Definition: CollectorManager.h:29
ripple::SizedItem::treeCacheAge
@ treeCacheAge
std::lock_guard
STL class.
ripple::stopwatch
Stopwatch & stopwatch()
Returns an instance of a wall clock.
Definition: chrono.h:86
ripple::fullBelowExpiration
constexpr std::chrono::seconds fullBelowExpiration
Definition: app/main/Tuning.h:26
ripple::to_string
std::string to_string(ListDisposition disposition)
Definition: ValidatorList.cpp:45
ripple::NodeFamily::reset
void reset() override
Definition: NodeFamily.cpp:55
ripple::Application::getInboundLedgers
virtual InboundLedgers & getInboundLedgers()=0
ripple::base_uint< 256 >
ripple::Application::getLedgerMaster
virtual LedgerMaster & getLedgerMaster()=0
ripple::InboundLedgers::acquire
virtual std::shared_ptr< Ledger const > acquire(uint256 const &hash, std::uint32_t seq, InboundLedger::Reason)=0
ripple::NodeFamily::j_
const beast::Journal j_
Definition: NodeFamily.h:97
ripple::NodeFamily::maxSeq_
LedgerIndex maxSeq_
Definition: NodeFamily.h:103
std::unique_lock
STL class.
beast::Journal::error
Stream error() const
Definition: Journal.h:333
ripple::NodeFamily::acquire
void acquire(uint256 const &hash, std::uint32_t seq)
Definition: NodeFamily.cpp:97
ripple::NodeFamily::NodeFamily
NodeFamily()=delete
std::uint32_t
ripple::NodeFamily::missingNode
void missingNode(std::uint32_t seq) override
Definition: NodeFamily.cpp:67
ripple::fullBelowTargetSize
constexpr std::size_t fullBelowTargetSize
Definition: app/main/Tuning.h:25
ripple::NodeFamily::maxSeqMutex_
std::mutex maxSeqMutex_
Definition: NodeFamily.h:104
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::SizedItem::treeCacheSize
@ treeCacheSize
ripple::NodeFamily::tnCache_
std::shared_ptr< TreeNodeCache > tnCache_
Definition: NodeFamily.h:100
std
STL namespace.
ripple::NodeFamily::fbCache_
std::shared_ptr< FullBelowCache > fbCache_
Definition: NodeFamily.h:99
ripple::LedgerMaster::getHashBySeq
uint256 getHashBySeq(std::uint32_t index)
Get a ledger's hash by sequence number using the cache.
Definition: LedgerMaster.cpp:1665