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