xrpld
Loading...
Searching...
No Matches
RawStateTable.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/protocol/Keylet.h>
8#include <xrpl/protocol/STLedgerEntry.h>
9
10#include <boost/container/pmr/monotonic_buffer_resource.hpp>
11#include <boost/container/pmr/polymorphic_allocator.hpp>
12
13#include <cstddef>
14#include <functional>
15#include <map>
16#include <memory>
17#include <optional>
18#include <utility>
19
20namespace xrpl::detail {
21
22// Helper class that buffers raw modifications
24{
25public:
27 // Initial size for the monotonic_buffer_resource used for allocations
28 // The size was chosen from the old `qalloc` code (which this replaces).
29 // It is unclear how the size initially chosen in qalloc.
30 static constexpr size_t kInitialBufferSize = kilobytes(256);
31
33 : monotonicResource_{std::make_unique<boost::container::pmr::monotonic_buffer_resource>(
36
38 : monotonicResource_{std::make_unique<boost::container::pmr::monotonic_buffer_resource>(
42
44
48 operator=(RawStateTable const&) = delete;
49
50 void
51 apply(RawView& to) const;
52
53 [[nodiscard]] bool
54 exists(ReadView const& base, Keylet const& k) const;
55
56 [[nodiscard]] std::optional<key_type>
57 succ(ReadView const& base, key_type const& key, std::optional<key_type> const& last) const;
58
59 void
60 erase(SLE::ref sle);
61
62 void
63 insert(SLE::ref sle);
64
65 void
66 replace(SLE::ref sle);
67
68 [[nodiscard]] SLE::const_pointer
69 read(ReadView const& base, Keylet const& k) const;
70
71 void
72 destroyXRP(XRPAmount const& fee);
73
75 slesBegin(ReadView const& base) const;
76
78 slesEnd(ReadView const& base) const;
79
81 slesUpperBound(ReadView const& base, uint256 const& key) const;
82
83private:
84 enum class Action {
88 };
89
90 class SlesIterImpl;
91
92 struct SleAction
93 {
96
97 // Constructor needed for emplacement in std::map
101 };
102
103 // Use boost::pmr functionality instead of the std::pmr
104 // functions b/c clang does not support pmr yet (as-of 9/2020)
106 key_type,
107 SleAction,
109 boost::container::pmr::polymorphic_allocator<std::pair<key_type const, SleAction>>>;
110 // monotonic_resource_ must outlive `items_`. Make a pointer so it may be
111 // easily moved.
114
116};
117
118} // namespace xrpl::detail
Interface for ledger entry changes.
Definition RawView.h:18
A view into a ledger.
Definition ReadView.h:41
uint256 key_type
Definition ReadView.h:45
std::shared_ptr< STLedgerEntry > const & ref
std::shared_ptr< STLedgerEntry > pointer
std::shared_ptr< STLedgerEntry const > const_pointer
RawStateTable & operator=(RawStateTable const &)=delete
std::optional< key_type > succ(ReadView const &base, key_type const &key, std::optional< key_type > const &last) const
bool exists(ReadView const &base, Keylet const &k) const
RawStateTable & operator=(RawStateTable &&)=delete
SLE::const_pointer read(ReadView const &base, Keylet const &k) const
std::unique_ptr< ReadView::SlesType::iter_base > slesEnd(ReadView const &base) const
std::unique_ptr< boost::container::pmr::monotonic_buffer_resource > monotonicResource_
static constexpr size_t kInitialBufferSize
void apply(RawView &to) const
std::unique_ptr< ReadView::SlesType::iter_base > slesBegin(ReadView const &base) const
ReadView::key_type key_type
RawStateTable(RawStateTable const &rhs)
std::unique_ptr< ReadView::SlesType::iter_base > slesUpperBound(ReadView const &base, uint256 const &key) const
void destroyXRP(XRPAmount const &fee)
RawStateTable(RawStateTable &&)=default
std::map< key_type, SleAction, std::less<>, boost::container::pmr::polymorphic_allocator< std::pair< key_type const, SleAction > > > items_t
STL namespace.
T get(Section const &section, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
constexpr auto kilobytes(T value) noexcept
BaseUInt< 256 > uint256
Definition base_uint.h:580
A pair of SHAMap key and LedgerEntryType.
Definition Keylet.h:20
SleAction(Action action, SLE::pointer sle)