rippled
Loading...
Searching...
No Matches
OpenView.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_OPENVIEW_H_INCLUDED
21#define RIPPLE_LEDGER_OPENVIEW_H_INCLUDED
22
23#include <xrpl/ledger/RawView.h>
24#include <xrpl/ledger/ReadView.h>
25#include <xrpl/ledger/detail/RawStateTable.h>
26#include <xrpl/protocol/STArray.h>
27#include <xrpl/protocol/XRPAmount.h>
28
29#include <boost/container/pmr/monotonic_buffer_resource.hpp>
30#include <boost/container/pmr/polymorphic_allocator.hpp>
31
32#include <functional>
33#include <utility>
34
35namespace ripple {
36
43inline constexpr struct open_ledger_t
44{
45 explicit constexpr open_ledger_t() = default;
47
53inline constexpr struct batch_view_t
54{
55 explicit constexpr batch_view_t() = default;
57
58//------------------------------------------------------------------------------
59
64class OpenView final : public ReadView, public TxsRawView
65{
66private:
67 // Initial size for the monotonic_buffer_resource used for allocations
68 // The size was chosen from the old `qalloc` code (which this replaces).
69 // It is unclear how the size initially chosen in qalloc.
70 static constexpr size_t initialBufferSize = kilobytes(256);
71
72 class txs_iter_impl;
73
74 struct txData
75 {
78
79 // Constructor needed for emplacement in std::map
83 : txn(txn_), meta(meta_)
84 {
85 }
86 };
87
88 // List of tx, key order
89 // Use boost::pmr functionality instead of std::pmr
90 // functions b/c clang does not support pmr yet (as-of 9/2020)
93 txData,
95 boost::container::pmr::polymorphic_allocator<
97
98 // monotonic_resource_ must outlive `items_`. Make a pointer so it may be
99 // easily moved.
108
111
112 bool open_ = true;
113
114public:
115 OpenView() = delete;
116 OpenView&
117 operator=(OpenView&&) = delete;
118 OpenView&
119 operator=(OpenView const&) = delete;
120
121 OpenView(OpenView&&) = default;
122
135 OpenView(OpenView const&);
136
157 OpenView(
159 ReadView const* base,
160 Rules const& rules,
161 std::shared_ptr<void const> hold = nullptr);
162
165 Rules const& rules,
167 : OpenView(open_ledger, &*base, rules, base)
168 {
169 }
170
171 OpenView(batch_view_t, OpenView& base) : OpenView(std::addressof(base))
172 {
173 baseTxCount_ = base.txCount();
174 }
175
187 OpenView(ReadView const* base, std::shared_ptr<void const> hold = nullptr);
188
190 bool
191 open() const override
192 {
193 return open_;
194 }
195
202 txCount() const;
203
205 void
206 apply(TxsRawView& to) const;
207
208 // ReadView
209
210 LedgerInfo const&
211 info() const override;
212
213 Fees const&
214 fees() const override;
215
216 Rules const&
217 rules() const override;
218
219 bool
220 exists(Keylet const& k) const override;
221
223 succ(
224 key_type const& key,
225 std::optional<key_type> const& last = std::nullopt) const override;
226
228 read(Keylet const& k) const override;
229
231 slesBegin() const override;
232
234 slesEnd() const override;
235
237 slesUpperBound(uint256 const& key) const override;
238
240 txsBegin() const override;
241
243 txsEnd() const override;
244
245 bool
246 txExists(key_type const& key) const override;
247
248 tx_type
249 txRead(key_type const& key) const override;
250
251 // RawView
252
253 void
254 rawErase(std::shared_ptr<SLE> const& sle) override;
255
256 void
257 rawInsert(std::shared_ptr<SLE> const& sle) override;
258
259 void
260 rawReplace(std::shared_ptr<SLE> const& sle) override;
261
262 void
263 rawDestroyXRP(XRPAmount const& fee) override;
264
265 // TxsRawView
266
267 void
269 key_type const& key,
271 std::shared_ptr<Serializer const> const& metaData) override;
272};
273
274} // namespace ripple
275
276#endif
Writable ledger view that accumulates state and tx changes.
Definition OpenView.h:65
std::size_t txCount() const
Return the number of tx inserted since creation.
Definition OpenView.cpp:122
std::unique_ptr< sles_type::iter_base > slesUpperBound(uint256 const &key) const override
Definition OpenView.cpp:187
tx_type txRead(key_type const &key) const override
Read a transaction from the tx map.
Definition OpenView.cpp:212
bool txExists(key_type const &key) const override
Returns true if a tx exists in the tx map.
Definition OpenView.cpp:206
OpenView & operator=(OpenView &&)=delete
ReadView const * base_
Definition OpenView.h:105
LedgerInfo const & info() const override
Returns information about the ledger.
Definition OpenView.cpp:138
std::unique_ptr< boost::container::pmr::monotonic_buffer_resource > monotonic_resource_
Definition OpenView.h:101
std::unique_ptr< sles_type::iter_base > slesEnd() const override
Definition OpenView.cpp:181
static constexpr size_t initialBufferSize
Definition OpenView.h:70
OpenView(open_ledger_t, Rules const &rules, std::shared_ptr< ReadView const > const &base)
Definition OpenView.h:163
detail::RawStateTable items_
Definition OpenView.h:106
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 OpenView.cpp:162
LedgerInfo info_
Definition OpenView.h:104
void rawDestroyXRP(XRPAmount const &fee) override
Destroy XRP.
Definition OpenView.cpp:249
bool exists(Keylet const &k) const override
Determine if a state item exists.
Definition OpenView.cpp:156
OpenView & operator=(OpenView const &)=delete
Rules const & rules() const override
Returns the tx processing rules.
Definition OpenView.cpp:150
std::shared_ptr< SLE const > read(Keylet const &k) const override
Return the state item associated with a key.
Definition OpenView.cpp:169
std::unique_ptr< sles_type::iter_base > slesBegin() const override
Definition OpenView.cpp:175
void rawTxInsert(key_type const &key, std::shared_ptr< Serializer const > const &txn, std::shared_ptr< Serializer const > const &metaData) override
Add a transaction to the tx map.
Definition OpenView.cpp:259
void rawErase(std::shared_ptr< SLE > const &sle) override
Delete an existing state item.
Definition OpenView.cpp:231
std::size_t baseTxCount_
In batch mode, the number of transactions already executed.
Definition OpenView.h:110
void rawReplace(std::shared_ptr< SLE > const &sle) override
Unconditionally replace a state item.
Definition OpenView.cpp:243
void rawInsert(std::shared_ptr< SLE > const &sle) override
Unconditionally insert a state item.
Definition OpenView.cpp:237
bool open() const override
Returns true if this reflects an open ledger.
Definition OpenView.h:191
std::shared_ptr< void const > hold_
Definition OpenView.h:107
OpenView(batch_view_t, OpenView &base)
Definition OpenView.h:171
OpenView(OpenView &&)=default
std::unique_ptr< txs_type::iter_base > txsBegin() const override
Definition OpenView.cpp:194
Fees const & fees() const override
Returns the fees for the base ledger.
Definition OpenView.cpp:144
void apply(TxsRawView &to) const
Apply changes.
Definition OpenView.cpp:128
std::unique_ptr< txs_type::iter_base > txsEnd() const override
Definition OpenView.cpp:200
A view into a ledger.
Definition ReadView.h:51
uint256 key_type
Definition ReadView.h:56
std::pair< std::shared_ptr< STTx const >, std::shared_ptr< STObject const > > tx_type
Definition ReadView.h:54
Rules controlling protocol behavior.
Definition Rules.h:38
Interface for changing ledger entries with transactions.
Definition RawView.h:95
T is_same_v
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
constexpr struct ripple::open_ledger_t open_ledger
constexpr struct ripple::batch_view_t batch_view
constexpr auto kilobytes(T value) noexcept
STL namespace.
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.
std::shared_ptr< Serializer const > txn
Definition OpenView.h:76
std::shared_ptr< Serializer const > meta
Definition OpenView.h:77
txData(std::shared_ptr< Serializer const > const &txn_, std::shared_ptr< Serializer const > const &meta_)
Definition OpenView.h:80
Batch view construction tag.
Definition OpenView.h:54
constexpr batch_view_t()=default
Open ledger construction tag.
Definition OpenView.h:44
constexpr open_ledger_t()=default