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
34 std::make_unique<boost::container::pmr::monotonic_buffer_resource>(
36 }
38
41 std::make_unique<boost::container::pmr::monotonic_buffer_resource>(
43 }
46
48
52 operator=(RawStateTable const&) = delete;
53
54 void
55 apply(RawView& to) const;
56
57 [[nodiscard]] bool
58 exists(ReadView const& base, Keylet const& k) const;
59
60 [[nodiscard]] std::optional<key_type>
61 succ(ReadView const& base, key_type const& key, std::optional<key_type> const& last) const;
62
63 void
64 erase(SLE::Ref sle);
65
66 void
67 insert(SLE::Ref sle);
68
69 void
70 replace(SLE::Ref sle);
71
72 [[nodiscard]] SLE::const_pointer
73 read(ReadView const& base, Keylet const& k) const;
74
75 void
76 destroyXRP(XRPAmount const& fee);
77
79 slesBegin(ReadView const& base) const;
80
82 slesEnd(ReadView const& base) const;
83
85 slesUpperBound(ReadView const& base, UInt256 const& key) const;
86
87private:
88 enum class Action {
92 };
93
94 class SlesIterImpl;
95
96 struct SleAction
97 {
100
101 // Constructor needed for emplacement in std::map
105 };
106
107 // Use boost::pmr functionality instead of the std::pmr
108 // functions b/c clang does not support pmr yet (as-of 9/2020)
110 key_type,
111 SleAction,
113 boost::container::pmr::polymorphic_allocator<std::pair<key_type const, SleAction>>>;
114 // monotonic_resource_ must outlive `items_`. Make a pointer so it may be
115 // easily moved.
118
120};
121
122} // 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 > pointer
std::shared_ptr< STLedgerEntry > const & Ref
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
std::unique_ptr< ReadView::SlesType::IterBase > slesEnd(ReadView const &base) const
bool exists(ReadView const &base, Keylet const &k) const
RawStateTable & operator=(RawStateTable &&)=delete
std::unique_ptr< ReadView::SlesType::IterBase > slesUpperBound(ReadView const &base, UInt256 const &key) const
std::map< key_type, SleAction, std::less<>, boost::container::pmr::polymorphic_allocator< std::pair< key_type const, SleAction > > > ItemsT
SLE::const_pointer read(ReadView const &base, Keylet const &k) 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::IterBase > slesBegin(ReadView const &base) const
ReadView::key_type key_type
RawStateTable(RawStateTable const &rhs)
void destroyXRP(XRPAmount const &fee)
RawStateTable(RawStateTable &&)=default
STL namespace.
T get(Section const &section, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
BaseUInt< 256 > UInt256
Definition base_uint.h:581
constexpr auto kilobytes(T value) noexcept
A pair of SHAMap key and LedgerEntryType.
Definition Keylet.h:20
SleAction(Action action, SLE::pointer sle)