rippled
Loading...
Searching...
No Matches
CachedView.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 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#ifndef RIPPLE_LEDGER_CACHEDVIEW_H_INCLUDED
21#define RIPPLE_LEDGER_CACHEDVIEW_H_INCLUDED
22
23#include <xrpl/basics/hardened_hash.h>
24#include <xrpl/ledger/CachedSLEs.h>
25#include <xrpl/ledger/ReadView.h>
26
27#include <mutex>
28#include <type_traits>
29
30namespace ripple {
31
32namespace detail {
33
35{
36private:
41
42public:
43 CachedViewImpl() = delete;
46 operator=(CachedViewImpl const&) = delete;
47
49 : base_(*base), cache_(cache)
50 {
51 }
52
53 //
54 // ReadView
55 //
56
57 bool
58 exists(Keylet const& k) const override;
59
61 read(Keylet const& k) const override;
62
63 bool
64 open() const override
65 {
66 return base_.open();
67 }
68
69 LedgerInfo const&
70 info() const override
71 {
72 return base_.info();
73 }
74
75 Fees const&
76 fees() const override
77 {
78 return base_.fees();
79 }
80
81 Rules const&
82 rules() const override
83 {
84 return base_.rules();
85 }
86
89 key_type const& key,
90 std::optional<key_type> const& last = std::nullopt) const override
91 {
92 return base_.succ(key, last);
93 }
94
96 slesBegin() const override
97 {
98 return base_.slesBegin();
99 }
100
102 slesEnd() const override
103 {
104 return base_.slesEnd();
105 }
106
108 slesUpperBound(uint256 const& key) const override
109 {
110 return base_.slesUpperBound(key);
111 }
112
114 txsBegin() const override
115 {
116 return base_.txsBegin();
117 }
118
120 txsEnd() const override
121 {
122 return base_.txsEnd();
123 }
124
125 bool
126 txExists(key_type const& key) const override
127 {
128 return base_.txExists(key);
129 }
130
131 tx_type
132 txRead(key_type const& key) const override
133 {
134 return base_.txRead(key);
135 }
136
137 //
138 // DigestAwareReadView
139 //
140
142 digest(key_type const& key) const override
143 {
144 return base_.digest(key);
145 }
146};
147
148} // namespace detail
149
154template <class Base>
156{
157private:
159
161
162public:
163 using base_type = Base;
164
165 CachedView() = delete;
166 CachedView(CachedView const&) = delete;
168 operator=(CachedView const&) = delete;
169
171 : CachedViewImpl(base.get(), cache), sp_(base)
172 {
173 }
174
180 base() const
181 {
182 return sp_;
183 }
184};
185
186} // namespace ripple
187
188#endif
Wraps a DigestAwareReadView to provide caching.
Definition CachedView.h:156
std::shared_ptr< Base const > const & base() const
Returns the base type.
Definition CachedView.h:180
std::shared_ptr< Base const > sp_
Definition CachedView.h:160
CachedView(std::shared_ptr< Base const > const &base, CachedSLEs &cache)
Definition CachedView.h:170
CachedView & operator=(CachedView const &)=delete
CachedView(CachedView const &)=delete
ReadView that associates keys with digests.
Definition ReadView.h:255
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:54
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:38
Map/cache combination.
Definition TaggedCache.h:62
std::unique_ptr< txs_type::iter_base > txsEnd() const override
Definition CachedView.h:120
tx_type txRead(key_type const &key) const override
Read a transaction from the tx map.
Definition CachedView.h:132
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:142
DigestAwareReadView const & base_
Definition CachedView.h:37
std::unique_ptr< sles_type::iter_base > slesUpperBound(uint256 const &key) const override
Definition CachedView.h:108
bool txExists(key_type const &key) const override
Returns true if a tx exists in the tx map.
Definition CachedView.h:126
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:70
bool exists(Keylet const &k) const override
Determine if a state item exists.
std::unique_ptr< txs_type::iter_base > txsBegin() const override
Definition CachedView.h:114
CachedViewImpl(CachedViewImpl const &)=delete
std::unordered_map< key_type, uint256, hardened_hash<> > map_
Definition CachedView.h:40
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:88
std::unique_ptr< sles_type::iter_base > slesBegin() const override
Definition CachedView.h:96
std::unique_ptr< sles_type::iter_base > slesEnd() const override
Definition CachedView.h:102
CachedViewImpl(DigestAwareReadView const *base, CachedSLEs &cache)
Definition CachedView.h:48
Rules const & rules() const override
Returns the tx processing rules.
Definition CachedView.h:82
Fees const & fees() const override
Returns the fees for the base ledger.
Definition CachedView.h:76
bool open() const override
Returns true if this reflects an open ledger.
Definition CachedView.h:64
T is_same_v
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
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:39
Information about the notional ledger backing the view.