xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
include
xrpl
ledger
detail
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
20
namespace
xrpl::detail
{
21
22
// Helper class that buffers raw modifications
23
class
RawStateTable
24
{
25
public
:
26
using
key_type
=
ReadView::key_type
;
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
32
RawStateTable
()
33
:
monotonicResource_
{
34
std
::make_unique<
boost
::container::pmr::monotonic_buffer_resource>(
35
kInitialBufferSize
),
36
}
37
,
items_
{
monotonicResource_
.
get
()} {};
38
39
RawStateTable
(
RawStateTable
const
& rhs)
40
:
monotonicResource_
{
41
std
::make_unique<
boost
::container::pmr::monotonic_buffer_resource>(
42
kInitialBufferSize
),
43
}
44
,
items_
{rhs.
items_
,
monotonicResource_
.
get
()}
45
,
dropsDestroyed_
{rhs.
dropsDestroyed_
} {};
46
47
RawStateTable
(
RawStateTable
&&) =
default
;
48
49
RawStateTable
&
50
operator=
(
RawStateTable
&&) =
delete
;
51
RawStateTable
&
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
78
[[nodiscard]]
std::unique_ptr<ReadView::SlesType::IterBase>
79
slesBegin
(
ReadView
const
& base)
const
;
80
81
[[nodiscard]]
std::unique_ptr<ReadView::SlesType::IterBase>
82
slesEnd
(
ReadView
const
& base)
const
;
83
84
[[nodiscard]]
std::unique_ptr<ReadView::SlesType::IterBase>
85
slesUpperBound
(
ReadView
const
& base,
UInt256
const
& key)
const
;
86
87
private
:
88
enum class
Action
{
89
Erase
,
90
Insert
,
91
Replace
,
92
};
93
94
class
SlesIterImpl;
95
96
struct
SleAction
97
{
98
Action
action
;
99
SLE::pointer
sle
;
100
101
// Constructor needed for emplacement in std::map
102
SleAction
(
Action
action
,
SLE::pointer
sle
) :
action
(
action
),
sle
(
std
::move(
sle
))
103
{
104
}
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)
109
using
ItemsT
=
std::map
<
110
key_type
,
111
SleAction
,
112
std::less<>
,
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.
116
std::unique_ptr<boost::container::pmr::monotonic_buffer_resource>
monotonicResource_
;
117
ItemsT
items_
;
118
119
XRPAmount
dropsDestroyed_
{0};
120
};
121
122
}
// namespace xrpl::detail
xrpl::RawView
Interface for ledger entry changes.
Definition
RawView.h:18
xrpl::ReadView
A view into a ledger.
Definition
ReadView.h:41
xrpl::ReadView::key_type
UInt256 key_type
Definition
ReadView.h:45
xrpl::STLedgerEntry::pointer
std::shared_ptr< STLedgerEntry > pointer
Definition
STLedgerEntry.h:34
xrpl::STLedgerEntry::Ref
std::shared_ptr< STLedgerEntry > const & Ref
Definition
STLedgerEntry.h:35
xrpl::STLedgerEntry::const_pointer
std::shared_ptr< STLedgerEntry const > const_pointer
Definition
STLedgerEntry.h:36
xrpl::XRPAmount
Definition
XRPAmount.h:29
xrpl::detail::RawStateTable::operator=
RawStateTable & operator=(RawStateTable const &)=delete
xrpl::detail::RawStateTable::succ
std::optional< key_type > succ(ReadView const &base, key_type const &key, std::optional< key_type > const &last) const
Definition
RawStateTable.cpp:211
xrpl::detail::RawStateTable::items_
ItemsT items_
Definition
RawStateTable.h:117
xrpl::detail::RawStateTable::slesEnd
std::unique_ptr< ReadView::SlesType::IterBase > slesEnd(ReadView const &base) const
Definition
RawStateTable.cpp:346
xrpl::detail::RawStateTable::exists
bool exists(ReadView const &base, Keylet const &k) const
Definition
RawStateTable.cpp:192
xrpl::detail::RawStateTable::operator=
RawStateTable & operator=(RawStateTable &&)=delete
xrpl::detail::RawStateTable::slesUpperBound
std::unique_ptr< ReadView::SlesType::IterBase > slesUpperBound(ReadView const &base, UInt256 const &key) const
Definition
RawStateTable.cpp:353
xrpl::detail::RawStateTable::ItemsT
std::map< key_type, SleAction, std::less<>, boost::container::pmr::polymorphic_allocator< std::pair< key_type const, SleAction > > > ItemsT
Definition
RawStateTable.h:109
xrpl::detail::RawStateTable::read
SLE::const_pointer read(ReadView const &base, Keylet const &k) const
Definition
RawStateTable.cpp:317
xrpl::detail::RawStateTable::erase
void erase(SLE::Ref sle)
Definition
RawStateTable.cpp:244
xrpl::detail::RawStateTable::monotonicResource_
std::unique_ptr< boost::container::pmr::monotonic_buffer_resource > monotonicResource_
Definition
RawStateTable.h:116
xrpl::detail::RawStateTable::Action
Action
Definition
RawStateTable.h:88
xrpl::detail::RawStateTable::Action::Replace
@ Replace
Definition
RawStateTable.h:91
xrpl::detail::RawStateTable::Action::Insert
@ Insert
Definition
RawStateTable.h:90
xrpl::detail::RawStateTable::Action::Erase
@ Erase
Definition
RawStateTable.h:89
xrpl::detail::RawStateTable::kInitialBufferSize
static constexpr size_t kInitialBufferSize
Definition
RawStateTable.h:30
xrpl::detail::RawStateTable::apply
void apply(RawView &to) const
Definition
RawStateTable.cpp:170
xrpl::detail::RawStateTable::slesBegin
std::unique_ptr< ReadView::SlesType::IterBase > slesBegin(ReadView const &base) const
Definition
RawStateTable.cpp:339
xrpl::detail::RawStateTable::key_type
ReadView::key_type key_type
Definition
RawStateTable.h:26
xrpl::detail::RawStateTable::insert
void insert(SLE::Ref sle)
Definition
RawStateTable.cpp:270
xrpl::detail::RawStateTable::RawStateTable
RawStateTable(RawStateTable const &rhs)
Definition
RawStateTable.h:39
xrpl::detail::RawStateTable::destroyXRP
void destroyXRP(XRPAmount const &fee)
Definition
RawStateTable.cpp:333
xrpl::detail::RawStateTable::RawStateTable
RawStateTable(RawStateTable &&)=default
xrpl::detail::RawStateTable::RawStateTable
RawStateTable()
Definition
RawStateTable.h:32
xrpl::detail::RawStateTable::replace
void replace(SLE::Ref sle)
Definition
RawStateTable.cpp:295
xrpl::detail::RawStateTable::dropsDestroyed_
XRPAmount dropsDestroyed_
Definition
RawStateTable.h:119
cstddef
functional
std::less
map
memory
boost
Definition
IPAddress.h:102
std
STL namespace.
xrpl::detail
Definition
base_uint.h:37
xrpl::get
T get(Section const §ion, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
Definition
BasicConfig.h:360
xrpl::UInt256
BaseUInt< 256 > UInt256
Definition
base_uint.h:581
xrpl::kilobytes
constexpr auto kilobytes(T value) noexcept
Definition
ByteUtilities.h:7
optional
xrpl::Keylet
A pair of SHAMap key and LedgerEntryType.
Definition
Keylet.h:20
xrpl::detail::RawStateTable::SleAction
Definition
RawStateTable.h:97
xrpl::detail::RawStateTable::SleAction::sle
SLE::pointer sle
Definition
RawStateTable.h:99
xrpl::detail::RawStateTable::SleAction::SleAction
SleAction(Action action, SLE::pointer sle)
Definition
RawStateTable.h:102
xrpl::detail::RawStateTable::SleAction::action
Action action
Definition
RawStateTable.h:98
std::unique_ptr
utility
Generated by
1.17.0