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 <xrpld/ledger/CachedSLEs.h>
24#include <xrpld/ledger/ReadView.h>
25#include <xrpl/basics/hardened_hash.h>
26#include <map>
27#include <memory>
28#include <mutex>
29#include <type_traits>
30
31namespace ripple {
32
33namespace detail {
34
36{
37private:
42
43public:
44 CachedViewImpl() = delete;
47 operator=(CachedViewImpl const&) = delete;
48
50 : base_(*base), cache_(cache)
51 {
52 }
53
54 //
55 // ReadView
56 //
57
58 bool
59 exists(Keylet const& k) const override;
60
62 read(Keylet const& k) const override;
63
64 bool
65 open() const override
66 {
67 return base_.open();
68 }
69
70 LedgerInfo const&
71 info() const override
72 {
73 return base_.info();
74 }
75
76 Fees const&
77 fees() const override
78 {
79 return base_.fees();
80 }
81
82 Rules const&
83 rules() const override
84 {
85 return base_.rules();
86 }
87
90 key_type const& key,
91 std::optional<key_type> const& last = std::nullopt) const override
92 {
93 return base_.succ(key, last);
94 }
95
97 slesBegin() const override
98 {
99 return base_.slesBegin();
100 }
101
103 slesEnd() const override
104 {
105 return base_.slesEnd();
106 }
107
109 slesUpperBound(uint256 const& key) const override
110 {
111 return base_.slesUpperBound(key);
112 }
113
115 txsBegin() const override
116 {
117 return base_.txsBegin();
118 }
119
121 txsEnd() const override
122 {
123 return base_.txsEnd();
124 }
125
126 bool
127 txExists(key_type const& key) const override
128 {
129 return base_.txExists(key);
130 }
131
132 tx_type
133 txRead(key_type const& key) const override
134 {
135 return base_.txRead(key);
136 }
137
138 //
139 // DigestAwareReadView
140 //
141
143 digest(key_type const& key) const override
144 {
145 return base_.digest(key);
146 }
147};
148
149} // namespace detail
150
155template <class Base>
157{
158private:
160
162
163public:
164 using base_type = Base;
165
166 CachedView() = delete;
167 CachedView(CachedView const&) = delete;
169 operator=(CachedView const&) = delete;
170
172 : CachedViewImpl(base.get(), cache), sp_(base)
173 {
174 }
175
181 base() const
182 {
183 return sp_;
184 }
185};
186
187} // namespace ripple
188
189#endif
Wraps a DigestAwareReadView to provide caching.
Definition: CachedView.h:157
std::shared_ptr< Base const > const & base() const
Returns the base type.
Definition: CachedView.h:181
std::shared_ptr< Base const > sp_
Definition: CachedView.h:161
CachedView(std::shared_ptr< Base const > const &base, CachedSLEs &cache)
Definition: CachedView.h:171
CachedView & operator=(CachedView const &)=delete
CachedView(CachedView const &)=delete
ReadView that associates keys with digests.
Definition: ReadView.h:259
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:58
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:35
Map/cache combination.
Definition: TaggedCache.h:57
std::unique_ptr< txs_type::iter_base > txsEnd() const override
Definition: CachedView.h:121
tx_type txRead(key_type const &key) const override
Read a transaction from the tx map.
Definition: CachedView.h:133
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:143
DigestAwareReadView const & base_
Definition: CachedView.h:38
std::unique_ptr< sles_type::iter_base > slesUpperBound(uint256 const &key) const override
Definition: CachedView.h:109
bool txExists(key_type const &key) const override
Returns true if a tx exists in the tx map.
Definition: CachedView.h:127
std::shared_ptr< SLE const > read(Keylet const &k) const override
Return the state item associated with a key.
Definition: CachedView.cpp:34
LedgerInfo const & info() const override
Returns information about the ledger.
Definition: CachedView.h:71
bool exists(Keylet const &k) const override
Determine if a state item exists.
Definition: CachedView.cpp:28
std::unique_ptr< txs_type::iter_base > txsBegin() const override
Definition: CachedView.h:115
CachedViewImpl(CachedViewImpl const &)=delete
std::unordered_map< key_type, uint256, hardened_hash<> > map_
Definition: CachedView.h:41
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:89
std::unique_ptr< sles_type::iter_base > slesBegin() const override
Definition: CachedView.h:97
std::unique_ptr< sles_type::iter_base > slesEnd() const override
Definition: CachedView.h:103
CachedViewImpl(DigestAwareReadView const *base, CachedSLEs &cache)
Definition: CachedView.h:49
Rules const & rules() const override
Returns the tx processing rules.
Definition: CachedView.h:83
Fees const & fees() const override
Returns the fees for the base ledger.
Definition: CachedView.h:77
bool open() const override
Returns true if this reflects an open ledger.
Definition: CachedView.h:65
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
T get(Section const &section, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
Definition: BasicConfig.h:356
Reflects the fee settings for a particular ledger.
Definition: protocol/Fees.h:33
A pair of SHAMap key and LedgerEntryType.
Definition: Keylet.h:39
Information about the notional ledger backing the view.
Definition: LedgerHeader.h:34