rippled
Loading...
Searching...
No Matches
CachedView.h
1#ifndef XRPL_LEDGER_CACHEDVIEW_H_INCLUDED
2#define XRPL_LEDGER_CACHEDVIEW_H_INCLUDED
3
4#include <xrpl/basics/hardened_hash.h>
5#include <xrpl/ledger/CachedSLEs.h>
6#include <xrpl/ledger/ReadView.h>
7
8#include <mutex>
9#include <type_traits>
10
11namespace ripple {
12
13namespace detail {
14
16{
17private:
22
23public:
24 CachedViewImpl() = delete;
27 operator=(CachedViewImpl const&) = delete;
28
30 : base_(*base), cache_(cache)
31 {
32 }
33
34 //
35 // ReadView
36 //
37
38 bool
39 exists(Keylet const& k) const override;
40
42 read(Keylet const& k) const override;
43
44 bool
45 open() const override
46 {
47 return base_.open();
48 }
49
50 LedgerInfo const&
51 info() const override
52 {
53 return base_.info();
54 }
55
56 Fees const&
57 fees() const override
58 {
59 return base_.fees();
60 }
61
62 Rules const&
63 rules() const override
64 {
65 return base_.rules();
66 }
67
70 key_type const& key,
71 std::optional<key_type> const& last = std::nullopt) const override
72 {
73 return base_.succ(key, last);
74 }
75
77 slesBegin() const override
78 {
79 return base_.slesBegin();
80 }
81
83 slesEnd() const override
84 {
85 return base_.slesEnd();
86 }
87
89 slesUpperBound(uint256 const& key) const override
90 {
91 return base_.slesUpperBound(key);
92 }
93
95 txsBegin() const override
96 {
97 return base_.txsBegin();
98 }
99
101 txsEnd() const override
102 {
103 return base_.txsEnd();
104 }
105
106 bool
107 txExists(key_type const& key) const override
108 {
109 return base_.txExists(key);
110 }
111
112 tx_type
113 txRead(key_type const& key) const override
114 {
115 return base_.txRead(key);
116 }
117
118 //
119 // DigestAwareReadView
120 //
121
123 digest(key_type const& key) const override
124 {
125 return base_.digest(key);
126 }
127};
128
129} // namespace detail
130
135template <class Base>
137{
138private:
140
142
143public:
144 using base_type = Base;
145
146 CachedView() = delete;
147 CachedView(CachedView const&) = delete;
149 operator=(CachedView const&) = delete;
150
152 : CachedViewImpl(base.get(), cache), sp_(base)
153 {
154 }
155
161 base() const
162 {
163 return sp_;
164 }
165};
166
167} // namespace ripple
168
169#endif
Wraps a DigestAwareReadView to provide caching.
Definition CachedView.h:137
std::shared_ptr< Base const > const & base() const
Returns the base type.
Definition CachedView.h:161
std::shared_ptr< Base const > sp_
Definition CachedView.h:141
CachedView(std::shared_ptr< Base const > const &base, CachedSLEs &cache)
Definition CachedView.h:151
CachedView & operator=(CachedView const &)=delete
CachedView(CachedView const &)=delete
ReadView that associates keys with digests.
Definition ReadView.h:236
virtual std::optional< digest_type > digest(key_type const &key) const =0
Return the digest associated with the key.
virtual std::optional< key_type > succ(key_type const &key, std::optional< key_type > const &last=std::nullopt) const =0
Return the key of the next state item.
virtual std::unique_ptr< sles_type::iter_base > slesUpperBound(key_type const &key) const =0
virtual std::unique_ptr< txs_type::iter_base > txsBegin() const =0
virtual std::unique_ptr< sles_type::iter_base > slesEnd() const =0
virtual bool open() const =0
Returns true if this reflects an open ledger.
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
std::pair< std::shared_ptr< STTx const >, std::shared_ptr< STObject const > > tx_type
Definition ReadView.h:35
virtual LedgerInfo const & info() const =0
Returns information about the ledger.
virtual Rules const & rules() const =0
Returns the tx processing rules.
virtual std::unique_ptr< txs_type::iter_base > txsEnd() const =0
virtual std::unique_ptr< sles_type::iter_base > slesBegin() const =0
virtual tx_type txRead(key_type const &key) const =0
Read a transaction from the tx map.
virtual bool txExists(key_type const &key) const =0
Returns true if a tx exists in the tx map.
Rules controlling protocol behavior.
Definition Rules.h:19
Map/cache combination.
Definition TaggedCache.h:43
std::unique_ptr< txs_type::iter_base > txsEnd() const override
Definition CachedView.h:101
tx_type txRead(key_type const &key) const override
Read a transaction from the tx map.
Definition CachedView.h:113
CachedViewImpl & operator=(CachedViewImpl const &)=delete
std::optional< digest_type > digest(key_type const &key) const override
Return the digest associated with the key.
Definition CachedView.h:123
DigestAwareReadView const & base_
Definition CachedView.h:18
std::unique_ptr< sles_type::iter_base > slesUpperBound(uint256 const &key) const override
Definition CachedView.h:89
bool txExists(key_type const &key) const override
Returns true if a tx exists in the tx map.
Definition CachedView.h:107
std::shared_ptr< SLE const > read(Keylet const &k) const override
Return the state item associated with a key.
LedgerInfo const & info() const override
Returns information about the ledger.
Definition CachedView.h:51
bool exists(Keylet const &k) const override
Determine if a state item exists.
Definition CachedView.cpp:8
std::unique_ptr< txs_type::iter_base > txsBegin() const override
Definition CachedView.h:95
CachedViewImpl(CachedViewImpl const &)=delete
std::unordered_map< key_type, uint256, hardened_hash<> > map_
Definition CachedView.h:21
std::optional< key_type > succ(key_type const &key, std::optional< key_type > const &last=std::nullopt) const override
Return the key of the next state item.
Definition CachedView.h:69
std::unique_ptr< sles_type::iter_base > slesBegin() const override
Definition CachedView.h:77
std::unique_ptr< sles_type::iter_base > slesEnd() const override
Definition CachedView.h:83
CachedViewImpl(DigestAwareReadView const *base, CachedSLEs &cache)
Definition CachedView.h:29
Rules const & rules() const override
Returns the tx processing rules.
Definition CachedView.h:63
Fees const & fees() const override
Returns the fees for the base ledger.
Definition CachedView.h:57
bool open() const override
Returns true if this reflects an open ledger.
Definition CachedView.h:45
T is_same_v
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
T get(Section const &section, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
Reflects the fee settings for a particular ledger.
A pair of SHAMap key and LedgerEntryType.
Definition Keylet.h:20
Information about the notional ledger backing the view.