rippled
Loading...
Searching...
No Matches
RawStateTable.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_RAWSTATETABLE_H_INCLUDED
21#define RIPPLE_LEDGER_RAWSTATETABLE_H_INCLUDED
22
23#include <xrpld/ledger/RawView.h>
24#include <xrpld/ledger/ReadView.h>
25
26#include <boost/container/pmr/monotonic_buffer_resource.hpp>
27#include <boost/container/pmr/polymorphic_allocator.hpp>
28
29#include <map>
30#include <utility>
31
32namespace ripple {
33namespace detail {
34
35// Helper class that buffers raw modifications
37{
38public:
40 // Initial size for the monotonic_buffer_resource used for allocations
41 // The size was chosen from the old `qalloc` code (which this replaces).
42 // It is unclear how the size initially chosen in qalloc.
43 static constexpr size_t initialBufferSize = kilobytes(256);
44
46 : monotonic_resource_{std::make_unique<
47 boost::container::pmr::monotonic_buffer_resource>(
50
52 : monotonic_resource_{std::make_unique<
53 boost::container::pmr::monotonic_buffer_resource>(
57
59
63 operator=(RawStateTable const&) = delete;
64
65 void
66 apply(RawView& to) const;
67
68 bool
69 exists(ReadView const& base, Keylet const& k) const;
70
72 succ(
73 ReadView const& base,
74 key_type const& key,
75 std::optional<key_type> const& last) const;
76
77 void
78 erase(std::shared_ptr<SLE> const& sle);
79
80 void
81 insert(std::shared_ptr<SLE> const& sle);
82
83 void
84 replace(std::shared_ptr<SLE> const& sle);
85
87 read(ReadView const& base, Keylet const& k) const;
88
89 void
90 destroyXRP(XRPAmount const& fee);
91
93 slesBegin(ReadView const& base) const;
94
96 slesEnd(ReadView const& base) const;
97
99 slesUpperBound(ReadView const& base, uint256 const& key) const;
100
101private:
102 enum class Action {
103 erase,
104 insert,
105 replace,
106 };
107
108 class sles_iter_impl;
109
111 {
114
115 // Constructor needed for emplacement in std::map
117 : action(action_), sle(sle_)
118 {
119 }
120 };
121
122 // Use boost::pmr functionality instead of the std::pmr
123 // functions b/c clang does not support pmr yet (as-of 9/2020)
125 key_type,
126 sleAction,
128 boost::container::pmr::polymorphic_allocator<
130 // monotonic_resource_ must outlive `items_`. Make a pointer so it may be
131 // easily moved.
135
137};
138
139} // namespace detail
140} // namespace ripple
141
142#endif
Interface for ledger entry changes.
Definition: RawView.h:37
A view into a ledger.
Definition: ReadView.h:55
uint256 key_type
Definition: ReadView.h:60
std::optional< key_type > succ(ReadView const &base, key_type const &key, std::optional< key_type > const &last) const
void destroyXRP(XRPAmount const &fee)
RawStateTable(RawStateTable const &rhs)
Definition: RawStateTable.h:51
bool exists(ReadView const &base, Keylet const &k) const
void apply(RawView &to) const
std::unique_ptr< ReadView::sles_type::iter_base > slesUpperBound(ReadView const &base, uint256 const &key) const
ReadView::key_type key_type
Definition: RawStateTable.h:39
RawStateTable & operator=(RawStateTable const &)=delete
std::shared_ptr< SLE const > read(ReadView const &base, Keylet const &k) const
std::unique_ptr< ReadView::sles_type::iter_base > slesBegin(ReadView const &base) const
RawStateTable & operator=(RawStateTable &&)=delete
std::unique_ptr< ReadView::sles_type::iter_base > slesEnd(ReadView const &base) const
std::unique_ptr< boost::container::pmr::monotonic_buffer_resource > monotonic_resource_
static constexpr size_t initialBufferSize
Definition: RawStateTable.h:43
RawStateTable(RawStateTable &&)=default
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
T get(Section const &section, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
Definition: BasicConfig.h:356
STL namespace.
A pair of SHAMap key and LedgerEntryType.
Definition: Keylet.h:39
sleAction(Action action_, std::shared_ptr< SLE > const &sle_)