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