rippled
Loading...
Searching...
No Matches
OpenView.h
1#pragma once
2
3#include <xrpl/ledger/RawView.h>
4#include <xrpl/ledger/ReadView.h>
5#include <xrpl/ledger/detail/RawStateTable.h>
6#include <xrpl/protocol/STArray.h>
7#include <xrpl/protocol/XRPAmount.h>
8
9#include <boost/container/pmr/monotonic_buffer_resource.hpp>
10#include <boost/container/pmr/polymorphic_allocator.hpp>
11
12#include <functional>
13#include <utility>
14
15namespace xrpl {
16
23inline constexpr struct open_ledger_t
24{
25 explicit constexpr open_ledger_t() = default;
27
33inline constexpr struct batch_view_t
34{
35 explicit constexpr batch_view_t() = default;
37
38//------------------------------------------------------------------------------
39
44class OpenView final : public ReadView, public TxsRawView
45{
46private:
47 // Initial size for the monotonic_buffer_resource used for allocations
48 // The size was chosen from the old `qalloc` code (which this replaces).
49 // It is unclear how the size initially chosen in qalloc.
50 static constexpr size_t initialBufferSize = kilobytes(256);
51
52 class txs_iter_impl;
53
54 struct txData
55 {
58
59 // Constructor needed for emplacement in std::map
63 : txn(txn_), meta(meta_)
64 {
65 }
66 };
67
68 // List of tx, key order
69 // Use boost::pmr functionality instead of std::pmr
70 // functions b/c clang does not support pmr yet (as-of 9/2020)
73 txData,
75 boost::container::pmr::polymorphic_allocator<std::pair<key_type const, txData>>>;
76
77 // monotonic_resource_ must outlive `items_`. Make a pointer so it may be
78 // easily moved.
86
89
90 bool open_ = true;
91
92public:
93 OpenView() = delete;
95 operator=(OpenView&&) = delete;
97 operator=(OpenView const&) = delete;
98
99 OpenView(OpenView&&) = default;
100
113 OpenView(OpenView const&);
114
135 OpenView(
137 ReadView const* base,
138 Rules const& rules,
139 std::shared_ptr<void const> hold = nullptr);
140
142 : OpenView(open_ledger, &*base, rules, base)
143 {
144 }
145
146 OpenView(batch_view_t, OpenView& base) : OpenView(std::addressof(base))
147 {
148 baseTxCount_ = base.txCount();
149 }
150
162 OpenView(ReadView const* base, std::shared_ptr<void const> hold = nullptr);
163
165 bool
166 open() const override
167 {
168 return open_;
169 }
170
177 txCount() const;
178
180 void
181 apply(TxsRawView& to) const;
182
183 // ReadView
184
185 LedgerHeader const&
186 header() const override;
187
188 Fees const&
189 fees() const override;
190
191 Rules const&
192 rules() const override;
193
194 bool
195 exists(Keylet const& k) const override;
196
198 succ(key_type const& key, std::optional<key_type> const& last = std::nullopt) const override;
199
201 read(Keylet const& k) const override;
202
204 slesBegin() const override;
205
207 slesEnd() const override;
208
210 slesUpperBound(uint256 const& key) const override;
211
213 txsBegin() const override;
214
216 txsEnd() const override;
217
218 bool
219 txExists(key_type const& key) const override;
220
221 tx_type
222 txRead(key_type const& key) const override;
223
224 // RawView
225
226 void
227 rawErase(std::shared_ptr<SLE> const& sle) override;
228
229 void
230 rawInsert(std::shared_ptr<SLE> const& sle) override;
231
232 void
233 rawReplace(std::shared_ptr<SLE> const& sle) override;
234
235 void
236 rawDestroyXRP(XRPAmount const& fee) override;
237
238 // TxsRawView
239
240 void
242 key_type const& key,
244 std::shared_ptr<Serializer const> const& metaData) override;
245};
246
247} // namespace xrpl
Writable ledger view that accumulates state and tx changes.
Definition OpenView.h:45
void rawErase(std::shared_ptr< SLE > const &sle) override
Delete an existing state item.
Definition OpenView.cpp:214
void rawDestroyXRP(XRPAmount const &fee) override
Destroy XRP.
Definition OpenView.cpp:232
std::size_t txCount() const
Return the number of tx inserted since creation.
Definition OpenView.cpp:103
tx_type txRead(key_type const &key) const override
Read a transaction from the tx map.
Definition OpenView.cpp:192
void rawInsert(std::shared_ptr< SLE > const &sle) override
Unconditionally insert a state item.
Definition OpenView.cpp:220
OpenView()=delete
OpenView(open_ledger_t, Rules const &rules, std::shared_ptr< ReadView const > const &base)
Definition OpenView.h:141
LedgerHeader header_
Definition OpenView.h:82
OpenView(OpenView &&)=default
OpenView(batch_view_t, OpenView &base)
Definition OpenView.h:146
Fees const & fees() const override
Returns the fees for the base ledger.
Definition OpenView.cpp:125
txs_map txs_
Definition OpenView.h:80
std::unique_ptr< txs_type::iter_base > txsEnd() const override
Definition OpenView.cpp:180
std::size_t baseTxCount_
In batch mode, the number of transactions already executed.
Definition OpenView.h:88
void rawReplace(std::shared_ptr< SLE > const &sle) override
Unconditionally replace a state item.
Definition OpenView.cpp:226
bool txExists(key_type const &key) const override
Returns true if a tx exists in the tx map.
Definition OpenView.cpp:186
OpenView & operator=(OpenView const &)=delete
std::shared_ptr< void const > hold_
Definition OpenView.h:85
bool open() const override
Returns true if this reflects an open ledger.
Definition OpenView.h:166
std::unique_ptr< sles_type::iter_base > slesBegin() const override
Definition OpenView.cpp:156
std::unique_ptr< boost::container::pmr::monotonic_buffer_resource > monotonic_resource_
Definition OpenView.h:79
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:143
std::unique_ptr< sles_type::iter_base > slesUpperBound(uint256 const &key) const override
Definition OpenView.cpp:168
OpenView & operator=(OpenView &&)=delete
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:242
std::shared_ptr< SLE const > read(Keylet const &k) const override
Return the state item associated with a key.
Definition OpenView.cpp:150
ReadView const * base_
Definition OpenView.h:83
LedgerHeader const & header() const override
Returns information about the ledger.
Definition OpenView.cpp:119
void apply(TxsRawView &to) const
Apply changes.
Definition OpenView.cpp:109
Rules const & rules() const override
Returns the tx processing rules.
Definition OpenView.cpp:131
bool exists(Keylet const &k) const override
Determine if a state item exists.
Definition OpenView.cpp:137
static constexpr size_t initialBufferSize
Definition OpenView.h:50
std::unique_ptr< txs_type::iter_base > txsBegin() const override
Definition OpenView.cpp:174
std::unique_ptr< sles_type::iter_base > slesEnd() const override
Definition OpenView.cpp:162
detail::RawStateTable items_
Definition OpenView.h:84
A view into a ledger.
Definition ReadView.h:31
std::pair< std::shared_ptr< STTx const >, std::shared_ptr< STObject const > > tx_type
Definition ReadView.h:33
uint256 key_type
Definition ReadView.h:35
Rules controlling protocol behavior.
Definition Rules.h:18
Interface for changing ledger entries with transactions.
Definition RawView.h:75
T is_same_v
STL namespace.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
constexpr struct xrpl::batch_view_t batch_view
constexpr struct xrpl::open_ledger_t open_ledger
constexpr auto kilobytes(T value) noexcept
Reflects the fee settings for a particular ledger.
A pair of SHAMap key and LedgerEntryType.
Definition Keylet.h:19
Information about the notional ledger backing the view.
txData(std::shared_ptr< Serializer const > const &txn_, std::shared_ptr< Serializer const > const &meta_)
Definition OpenView.h:60
std::shared_ptr< Serializer const > meta
Definition OpenView.h:57
std::shared_ptr< Serializer const > txn
Definition OpenView.h:56
Batch view construction tag.
Definition OpenView.h:34
constexpr batch_view_t()=default
Open ledger construction tag.
Definition OpenView.h:24
constexpr open_ledger_t()=default