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#include <xrpl/protocol/XRPAmount.h>
27
28#include <boost/container/pmr/monotonic_buffer_resource.hpp>
29#include <boost/container/pmr/polymorphic_allocator.hpp>
30
31#include <functional>
32#include <utility>
33
34namespace ripple {
35
43{
44 explicit open_ledger_t() = default;
45};
46
47extern open_ledger_t const open_ledger;
48
49//------------------------------------------------------------------------------
50
55class OpenView final : public ReadView, public TxsRawView
56{
57private:
58 // Initial size for the monotonic_buffer_resource used for allocations
59 // The size was chosen from the old `qalloc` code (which this replaces).
60 // It is unclear how the size initially chosen in qalloc.
61 static constexpr size_t initialBufferSize = kilobytes(256);
62
63 class txs_iter_impl;
64
65 struct txData
66 {
69
70 // Constructor needed for emplacement in std::map
74 : txn(txn_), meta(meta_)
75 {
76 }
77 };
78
79 // List of tx, key order
80 // Use boost::pmr functionality instead of std::pmr
81 // functions b/c clang does not support pmr yet (as-of 9/2020)
84 txData,
86 boost::container::pmr::polymorphic_allocator<
88
89 // monotonic_resource_ must outlive `items_`. Make a pointer so it may be
90 // easily moved.
99 bool open_ = true;
100
101public:
102 OpenView() = delete;
103 OpenView&
104 operator=(OpenView&&) = delete;
105 OpenView&
106 operator=(OpenView const&) = delete;
107
108 OpenView(OpenView&&) = default;
109
122 OpenView(OpenView const&);
123
145 OpenView(
147 ReadView const* base,
148 Rules const& rules,
149 std::shared_ptr<void const> hold = nullptr);
150
153 Rules const& rules,
155 : OpenView(open_ledger, &*base, rules, base)
156 {
157 }
171 OpenView(ReadView const* base, std::shared_ptr<void const> hold = nullptr);
172
174 bool
175 open() const override
176 {
177 return open_;
178 }
179
186 txCount() const;
187
189 void
190 apply(TxsRawView& to) const;
191
192 // ReadView
193
194 LedgerInfo const&
195 info() const override;
196
197 Fees const&
198 fees() const override;
199
200 Rules const&
201 rules() const override;
202
203 bool
204 exists(Keylet const& k) const override;
205
207 succ(
208 key_type const& key,
209 std::optional<key_type> const& last = std::nullopt) const override;
210
212 read(Keylet const& k) const override;
213
215 slesBegin() const override;
216
218 slesEnd() const override;
219
221 slesUpperBound(uint256 const& key) const override;
222
224 txsBegin() const override;
225
227 txsEnd() const override;
228
229 bool
230 txExists(key_type const& key) const override;
231
232 tx_type
233 txRead(key_type const& key) const override;
234
235 // RawView
236
237 void
238 rawErase(std::shared_ptr<SLE> const& sle) override;
239
240 void
241 rawInsert(std::shared_ptr<SLE> const& sle) override;
242
243 void
244 rawReplace(std::shared_ptr<SLE> const& sle) override;
245
246 void
247 rawDestroyXRP(XRPAmount const& fee) override;
248
249 // TxsRawView
250
251 void
253 key_type const& key,
255 std::shared_ptr<Serializer const> const& metaData) override;
256};
257
258} // namespace ripple
259
260#endif
Writable ledger view that accumulates state and tx changes.
Definition: OpenView.h:56
std::size_t txCount() const
Return the number of tx inserted since creation.
Definition: OpenView.cpp:124
std::unique_ptr< sles_type::iter_base > slesUpperBound(uint256 const &key) const override
Definition: OpenView.cpp:189
tx_type txRead(key_type const &key) const override
Read a transaction from the tx map.
Definition: OpenView.cpp:214
bool txExists(key_type const &key) const override
Returns true if a tx exists in the tx map.
Definition: OpenView.cpp:208
OpenView & operator=(OpenView &&)=delete
ReadView const * base_
Definition: OpenView.h:96
LedgerInfo const & info() const override
Returns information about the ledger.
Definition: OpenView.cpp:140
std::unique_ptr< boost::container::pmr::monotonic_buffer_resource > monotonic_resource_
Definition: OpenView.h:92
std::unique_ptr< sles_type::iter_base > slesEnd() const override
Definition: OpenView.cpp:183
static constexpr size_t initialBufferSize
Definition: OpenView.h:61
OpenView(open_ledger_t, Rules const &rules, std::shared_ptr< ReadView const > const &base)
Definition: OpenView.h:151
detail::RawStateTable items_
Definition: OpenView.h:97
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:164
LedgerInfo info_
Definition: OpenView.h:95
void rawDestroyXRP(XRPAmount const &fee) override
Destroy XRP.
Definition: OpenView.cpp:251
bool exists(Keylet const &k) const override
Determine if a state item exists.
Definition: OpenView.cpp:158
OpenView & operator=(OpenView const &)=delete
Rules const & rules() const override
Returns the tx processing rules.
Definition: OpenView.cpp:152
std::shared_ptr< SLE const > read(Keylet const &k) const override
Return the state item associated with a key.
Definition: OpenView.cpp:171
std::unique_ptr< sles_type::iter_base > slesBegin() const override
Definition: OpenView.cpp:177
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:261
void rawErase(std::shared_ptr< SLE > const &sle) override
Delete an existing state item.
Definition: OpenView.cpp:233
void rawReplace(std::shared_ptr< SLE > const &sle) override
Unconditionally replace a state item.
Definition: OpenView.cpp:245
void rawInsert(std::shared_ptr< SLE > const &sle) override
Unconditionally insert a state item.
Definition: OpenView.cpp:239
txs_map txs_
Definition: OpenView.h:93
bool open() const override
Returns true if this reflects an open ledger.
Definition: OpenView.h:175
std::shared_ptr< void const > hold_
Definition: OpenView.h:98
OpenView(OpenView &&)=default
std::unique_ptr< txs_type::iter_base > txsBegin() const override
Definition: OpenView.cpp:196
Fees const & fees() const override
Returns the fees for the base ledger.
Definition: OpenView.cpp:146
void apply(TxsRawView &to) const
Apply changes.
Definition: OpenView.cpp:130
std::unique_ptr< txs_type::iter_base > txsEnd() const override
Definition: OpenView.cpp:202
A view into a ledger.
Definition: ReadView.h:55
uint256 key_type
Definition: ReadView.h:60
std::pair< std::shared_ptr< STTx const >, std::shared_ptr< STObject const > > tx_type
Definition: ReadView.h:58
Rules controlling protocol behavior.
Definition: Rules.h:35
Interface for changing ledger entries with transactions.
Definition: RawView.h:98
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
constexpr auto kilobytes(T value) noexcept
Definition: ByteUtilities.h:27
open_ledger_t const open_ledger
Definition: OpenView.cpp:25
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:67
std::shared_ptr< Serializer const > meta
Definition: OpenView.h:68
txData(std::shared_ptr< Serializer const > const &txn_, std::shared_ptr< Serializer const > const &meta_)
Definition: OpenView.h:71
Open ledger construction tag.
Definition: OpenView.h:43