xrpld
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 OpenLedgerT
24{
25 explicit constexpr OpenLedgerT() = default;
27
33inline constexpr struct BatchViewT
34{
35 explicit constexpr BatchViewT() = 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 kInitialBufferSize = kilobytes(256);
51
52 class TxsIterImpl;
53
54 struct TxData
55 {
58
59 // Constructor needed for emplacement in std::map
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 rules,
139 std::shared_ptr<void const> hold = nullptr);
140
142 : OpenView(kOpenLedger, &*base, rules, base)
143 {
144 }
145
146 OpenView(BatchViewT, 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(SLE::ref sle) override;
228
229 void
230 rawInsert(SLE::ref sle) override;
231
232 void
233 rawReplace(SLE::ref 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
static constexpr size_t kInitialBufferSize
Definition OpenView.h:50
void rawDestroyXRP(XRPAmount const &fee) override
Destroy XRP.
Definition OpenView.cpp:249
std::size_t txCount() const
Return the number of tx inserted since creation.
Definition OpenView.cpp:120
tx_type txRead(key_type const &key) const override
Read a transaction from the tx map.
Definition OpenView.cpp:209
OpenView()=delete
LedgerHeader header_
Definition OpenView.h:82
OpenView(OpenView &&)=default
Fees const & fees() const override
Returns the fees for the base ledger.
Definition OpenView.cpp:142
txs_map txs_
Definition OpenView.h:80
std::unique_ptr< TxsType::iter_base > txsEnd() const override
Definition OpenView.cpp:197
void rawInsert(SLE::ref sle) override
Unconditionally insert a state item.
Definition OpenView.cpp:237
std::size_t baseTxCount_
In batch mode, the number of transactions already executed.
Definition OpenView.h:88
std::map< key_type, TxData, std::less< key_type >, boost::container::pmr::polymorphic_allocator< std::pair< key_type const, TxData > > > txs_map
Definition OpenView.h:71
OpenView(BatchViewT, OpenView &base)
Definition OpenView.h:146
bool txExists(key_type const &key) const override
Returns true if a tx exists in the tx map.
Definition OpenView.cpp:203
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< SlesType::iter_base > slesBegin() const override
Definition OpenView.cpp:173
SLE::const_pointer read(Keylet const &k) const override
Return the state item associated with a key.
Definition OpenView.cpp:167
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:160
std::unique_ptr< SlesType::iter_base > slesUpperBound(uint256 const &key) const override
Definition OpenView.cpp:185
void rawErase(SLE::ref sle) override
Delete an existing state item.
Definition OpenView.cpp:231
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:259
ReadView const * base_
Definition OpenView.h:83
LedgerHeader const & header() const override
Returns information about the ledger.
Definition OpenView.cpp:136
void apply(TxsRawView &to) const
Apply changes.
Definition OpenView.cpp:126
Rules const & rules() const override
Returns the tx processing rules.
Definition OpenView.cpp:148
bool exists(Keylet const &k) const override
Determine if a state item exists.
Definition OpenView.cpp:154
std::unique_ptr< TxsType::iter_base > txsBegin() const override
Definition OpenView.cpp:191
std::unique_ptr< boost::container::pmr::monotonic_buffer_resource > monotonicResource_
Definition OpenView.h:79
std::unique_ptr< SlesType::iter_base > slesEnd() const override
Definition OpenView.cpp:179
OpenView(OpenLedgerT, Rules const &rules, std::shared_ptr< ReadView const > const &base)
Definition OpenView.h:141
detail::RawStateTable items_
Definition OpenView.h:84
void rawReplace(SLE::ref sle) override
Unconditionally replace a state item.
Definition OpenView.cpp:243
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:33
std::shared_ptr< STLedgerEntry > const & ref
std::shared_ptr< STLedgerEntry const > const_pointer
Interface for changing ledger entries with transactions.
Definition RawView.h:75
STL namespace.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
constexpr struct xrpl::BatchViewT kBatchView
constexpr auto kilobytes(T value) noexcept
constexpr struct xrpl::OpenLedgerT kOpenLedger
BaseUInt< 256 > uint256
Definition base_uint.h:562
Batch view construction tag.
Definition OpenView.h:34
constexpr BatchViewT()=default
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.
Open ledger construction tag.
Definition OpenView.h:24
constexpr OpenLedgerT()=default
std::shared_ptr< Serializer const > txn
Definition OpenView.h:56
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