rippled
Loading...
Searching...
No Matches
OpenView.h
1#ifndef XRPL_LEDGER_OPENVIEW_H_INCLUDED
2#define XRPL_LEDGER_OPENVIEW_H_INCLUDED
3
4#include <xrpl/ledger/RawView.h>
5#include <xrpl/ledger/ReadView.h>
6#include <xrpl/ledger/detail/RawStateTable.h>
7#include <xrpl/protocol/STArray.h>
8#include <xrpl/protocol/XRPAmount.h>
9
10#include <boost/container/pmr/monotonic_buffer_resource.hpp>
11#include <boost/container/pmr/polymorphic_allocator.hpp>
12
13#include <functional>
14#include <utility>
15
16namespace ripple {
17
24inline constexpr struct open_ledger_t
25{
26 explicit constexpr open_ledger_t() = default;
28
34inline constexpr struct batch_view_t
35{
36 explicit constexpr batch_view_t() = default;
38
39//------------------------------------------------------------------------------
40
45class OpenView final : public ReadView, public TxsRawView
46{
47private:
48 // Initial size for the monotonic_buffer_resource used for allocations
49 // The size was chosen from the old `qalloc` code (which this replaces).
50 // It is unclear how the size initially chosen in qalloc.
51 static constexpr size_t initialBufferSize = kilobytes(256);
52
53 class txs_iter_impl;
54
55 struct txData
56 {
59
60 // Constructor needed for emplacement in std::map
64 : txn(txn_), meta(meta_)
65 {
66 }
67 };
68
69 // List of tx, key order
70 // Use boost::pmr functionality instead of std::pmr
71 // functions b/c clang does not support pmr yet (as-of 9/2020)
74 txData,
76 boost::container::pmr::polymorphic_allocator<
78
79 // monotonic_resource_ must outlive `items_`. Make a pointer so it may be
80 // easily moved.
89
92
93 bool open_ = true;
94
95public:
96 OpenView() = delete;
98 operator=(OpenView&&) = delete;
100 operator=(OpenView const&) = delete;
101
102 OpenView(OpenView&&) = default;
103
116 OpenView(OpenView const&);
117
138 OpenView(
140 ReadView const* base,
141 Rules const& rules,
142 std::shared_ptr<void const> hold = nullptr);
143
146 Rules const& rules,
148 : OpenView(open_ledger, &*base, rules, base)
149 {
150 }
151
152 OpenView(batch_view_t, OpenView& base) : OpenView(std::addressof(base))
153 {
154 baseTxCount_ = base.txCount();
155 }
156
168 OpenView(ReadView const* base, std::shared_ptr<void const> hold = nullptr);
169
171 bool
172 open() const override
173 {
174 return open_;
175 }
176
183 txCount() const;
184
186 void
187 apply(TxsRawView& to) const;
188
189 // ReadView
190
191 LedgerInfo const&
192 info() const override;
193
194 Fees const&
195 fees() const override;
196
197 Rules const&
198 rules() const override;
199
200 bool
201 exists(Keylet const& k) const override;
202
204 succ(
205 key_type const& key,
206 std::optional<key_type> const& last = std::nullopt) const override;
207
209 read(Keylet const& k) const override;
210
212 slesBegin() const override;
213
215 slesEnd() const override;
216
218 slesUpperBound(uint256 const& key) const override;
219
221 txsBegin() const override;
222
224 txsEnd() const override;
225
226 bool
227 txExists(key_type const& key) const override;
228
229 tx_type
230 txRead(key_type const& key) const override;
231
232 // RawView
233
234 void
235 rawErase(std::shared_ptr<SLE> const& sle) override;
236
237 void
238 rawInsert(std::shared_ptr<SLE> const& sle) override;
239
240 void
241 rawReplace(std::shared_ptr<SLE> const& sle) override;
242
243 void
244 rawDestroyXRP(XRPAmount const& fee) override;
245
246 // TxsRawView
247
248 void
250 key_type const& key,
252 std::shared_ptr<Serializer const> const& metaData) override;
253};
254
255} // namespace ripple
256
257#endif
Writable ledger view that accumulates state and tx changes.
Definition OpenView.h:46
std::size_t txCount() const
Return the number of tx inserted since creation.
Definition OpenView.cpp:103
std::unique_ptr< sles_type::iter_base > slesUpperBound(uint256 const &key) const override
Definition OpenView.cpp:168
tx_type txRead(key_type const &key) const override
Read a transaction from the tx map.
Definition OpenView.cpp:193
bool txExists(key_type const &key) const override
Returns true if a tx exists in the tx map.
Definition OpenView.cpp:187
OpenView & operator=(OpenView &&)=delete
ReadView const * base_
Definition OpenView.h:86
LedgerInfo const & info() const override
Returns information about the ledger.
Definition OpenView.cpp:119
std::unique_ptr< boost::container::pmr::monotonic_buffer_resource > monotonic_resource_
Definition OpenView.h:82
std::unique_ptr< sles_type::iter_base > slesEnd() const override
Definition OpenView.cpp:162
static constexpr size_t initialBufferSize
Definition OpenView.h:51
OpenView(open_ledger_t, Rules const &rules, std::shared_ptr< ReadView const > const &base)
Definition OpenView.h:144
detail::RawStateTable items_
Definition OpenView.h:87
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
LedgerInfo info_
Definition OpenView.h:85
void rawDestroyXRP(XRPAmount const &fee) override
Destroy XRP.
Definition OpenView.cpp:230
bool exists(Keylet const &k) const override
Determine if a state item exists.
Definition OpenView.cpp:137
OpenView & operator=(OpenView const &)=delete
Rules const & rules() const override
Returns the tx processing rules.
Definition OpenView.cpp:131
std::shared_ptr< SLE const > read(Keylet const &k) const override
Return the state item associated with a key.
Definition OpenView.cpp:150
std::unique_ptr< sles_type::iter_base > slesBegin() const override
Definition OpenView.cpp:156
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:240
void rawErase(std::shared_ptr< SLE > const &sle) override
Delete an existing state item.
Definition OpenView.cpp:212
std::size_t baseTxCount_
In batch mode, the number of transactions already executed.
Definition OpenView.h:91
void rawReplace(std::shared_ptr< SLE > const &sle) override
Unconditionally replace a state item.
Definition OpenView.cpp:224
void rawInsert(std::shared_ptr< SLE > const &sle) override
Unconditionally insert a state item.
Definition OpenView.cpp:218
bool open() const override
Returns true if this reflects an open ledger.
Definition OpenView.h:172
std::shared_ptr< void const > hold_
Definition OpenView.h:88
OpenView(batch_view_t, OpenView &base)
Definition OpenView.h:152
OpenView(OpenView &&)=default
std::unique_ptr< txs_type::iter_base > txsBegin() const override
Definition OpenView.cpp:175
Fees const & fees() const override
Returns the fees for the base ledger.
Definition OpenView.cpp:125
void apply(TxsRawView &to) const
Apply changes.
Definition OpenView.cpp:109
std::unique_ptr< txs_type::iter_base > txsEnd() const override
Definition OpenView.cpp:181
A view into a ledger.
Definition ReadView.h:32
uint256 key_type
Definition ReadView.h:37
std::pair< std::shared_ptr< STTx const >, std::shared_ptr< STObject const > > tx_type
Definition ReadView.h:35
Rules controlling protocol behavior.
Definition Rules.h:19
Interface for changing ledger entries with transactions.
Definition RawView.h:76
T is_same_v
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
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:20
Information about the notional ledger backing the view.
std::shared_ptr< Serializer const > txn
Definition OpenView.h:57
std::shared_ptr< Serializer const > meta
Definition OpenView.h:58
txData(std::shared_ptr< Serializer const > const &txn_, std::shared_ptr< Serializer const > const &meta_)
Definition OpenView.h:61
Batch view construction tag.
Definition OpenView.h:35
constexpr batch_view_t()=default
Open ledger construction tag.
Definition OpenView.h:25
constexpr open_ledger_t()=default