xrpld
Loading...
Searching...
No Matches
OpenView.h
1#pragma once
2
3#include <xrpl/basics/ByteUtilities.h>
4#include <xrpl/basics/base_uint.h>
5#include <xrpl/ledger/RawView.h>
6#include <xrpl/ledger/ReadView.h>
7#include <xrpl/ledger/detail/RawStateTable.h>
8#include <xrpl/protocol/Fees.h>
9#include <xrpl/protocol/Keylet.h>
10#include <xrpl/protocol/LedgerHeader.h>
11#include <xrpl/protocol/Rules.h>
12#include <xrpl/protocol/STLedgerEntry.h>
13#include <xrpl/protocol/Serializer.h>
14#include <xrpl/protocol/XRPAmount.h>
15
16#include <boost/container/pmr/monotonic_buffer_resource.hpp>
17#include <boost/container/pmr/polymorphic_allocator.hpp>
18
19#include <cstddef>
20#include <functional>
21#include <map>
22#include <memory>
23#include <optional>
24#include <utility>
25
26namespace xrpl {
27
35inline constexpr struct OpenLedgerT
36{
37 explicit constexpr OpenLedgerT() = default;
39
46inline constexpr struct BatchViewT
47{
48 explicit constexpr BatchViewT() = default;
50
51//------------------------------------------------------------------------------
52
58class OpenView final : public ReadView, public TxsRawView
59{
60private:
61 // Initial size for the monotonic_buffer_resource used for allocations
62 // The size was chosen from the old `qalloc` code (which this replaces).
63 // It is unclear how the size initially chosen in qalloc.
64 static constexpr size_t kInitialBufferSize = kilobytes(256);
65
66 class TxsIterImpl;
67
68 struct TxData
69 {
72
73 // Constructor needed for emplacement in std::map
80 };
81
82 // List of tx, key order
83 // Use boost::pmr functionality instead of std::pmr
84 // functions b/c clang does not support pmr yet (as-of 9/2020)
87 TxData,
89 boost::container::pmr::polymorphic_allocator<std::pair<key_type const, TxData>>>;
90
91 // monotonic_resource_ must outlive `items_`. Make a pointer so it may be
92 // easily moved.
100
105
106 bool open_ = true;
107
108public:
109 OpenView() = delete;
110 OpenView&
111 operator=(OpenView&&) = delete;
112 OpenView&
113 operator=(OpenView const&) = delete;
114
115 OpenView(OpenView&&) = default;
116
130 OpenView(OpenView const&);
131
153 OpenView(
155 ReadView const* base,
156 Rules rules,
157 std::shared_ptr<void const> hold = nullptr);
158
160 : OpenView(kOpenLedger, &*base, rules, base)
161 {
162 }
163
164 OpenView(BatchViewT, OpenView& base) : OpenView(std::addressof(base))
165 {
166 baseTxCount_ = base.txCount();
167 }
168
181 OpenView(ReadView const* base, std::shared_ptr<void const> hold = nullptr);
182
186 bool
187 open() const override
188 {
189 return open_;
190 }
191
199 txCount() const;
200
204 void
205 apply(TxsRawView& to) const;
206
207 // ReadView
208
209 LedgerHeader const&
210 header() const override;
211
212 Fees const&
213 fees() const override;
214
215 Rules const&
216 rules() const override;
217
218 bool
219 exists(Keylet const& k) const override;
220
222 succ(key_type const& key, std::optional<key_type> const& last = std::nullopt) const override;
223
225 read(Keylet const& k) const override;
226
228 slesBegin() const override;
229
231 slesEnd() const override;
232
234 slesUpperBound(uint256 const& key) const override;
235
237 txsBegin() const override;
238
240 txsEnd() const override;
241
242 bool
243 txExists(key_type const& key) const override;
244
245 tx_type
246 txRead(key_type const& key) const override;
247
248 // RawView
249
250 void
251 rawErase(SLE::ref sle) override;
252
253 void
254 rawInsert(SLE::ref sle) override;
255
256 void
257 rawReplace(SLE::ref sle) override;
258
259 void
260 rawDestroyXRP(XRPAmount const& fee) override;
261
262 // TxsRawView
263
264 void
266 key_type const& key,
268 std::shared_ptr<Serializer const> const& metaData) override;
269};
270
271} // namespace xrpl
static constexpr size_t kInitialBufferSize
Definition OpenView.h:64
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:96
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:94
std::map< key_type, TxData, std::less<>, boost::container::pmr::polymorphic_allocator< std::pair< key_type const, TxData > > > txs_map
Definition OpenView.h:85
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:104
OpenView(BatchViewT, OpenView &base)
Definition OpenView.h:164
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:99
bool open() const override
Returns true if this reflects an open ledger.
Definition OpenView.h:187
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:97
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:93
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:159
detail::RawStateTable items_
Definition OpenView.h:98
void rawReplace(SLE::ref sle) override
Unconditionally replace a state item.
Definition OpenView.cpp:243
A view into a ledger.
Definition ReadView.h:41
std::pair< std::shared_ptr< STTx const >, std::shared_ptr< STObject const > > tx_type
Definition ReadView.h:43
uint256 key_type
Definition ReadView.h:45
Rules controlling protocol behavior.
Definition Rules.h:40
std::shared_ptr< STLedgerEntry > const & ref
std::shared_ptr< STLedgerEntry const > const_pointer
Interface for changing ledger entries with transactions.
Definition RawView.h:84
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:580
Batch view construction tag.
Definition OpenView.h:47
constexpr BatchViewT()=default
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.
Open ledger construction tag.
Definition OpenView.h:36
constexpr OpenLedgerT()=default
std::shared_ptr< Serializer const > txn
Definition OpenView.h:70
TxData(std::shared_ptr< Serializer const > const &txn, std::shared_ptr< Serializer const > const &meta)
Definition OpenView.h:74
std::shared_ptr< Serializer const > meta
Definition OpenView.h:71