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_
{
std
::make_unique<
boost
::container::pmr::monotonic_buffer_resource>(
34
kInitialBufferSize
)}
35
,
items_
{
monotonicResource_
.
get
()} {};
36
37
RawStateTable
(
RawStateTable
const
& rhs)
38
:
monotonicResource_
{
std
::make_unique<
boost
::container::pmr::monotonic_buffer_resource>(
39
kInitialBufferSize
)}
40
,
items_
{rhs.
items_
,
monotonicResource_
.
get
()}
41
,
dropsDestroyed_
{rhs.
dropsDestroyed_
} {};
42
43
RawStateTable
(
RawStateTable
&&) =
default
;
44
45
RawStateTable
&
46
operator=
(
RawStateTable
&&) =
delete
;
47
RawStateTable
&
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
74
[[nodiscard]]
std::unique_ptr<ReadView::SlesType::IterBase>
75
slesBegin
(
ReadView
const
& base)
const
;
76
77
[[nodiscard]]
std::unique_ptr<ReadView::SlesType::IterBase>
78
slesEnd
(
ReadView
const
& base)
const
;
79
80
[[nodiscard]]
std::unique_ptr<ReadView::SlesType::IterBase>
81
slesUpperBound
(
ReadView
const
& base,
UInt256
const
& key)
const
;
82
83
private
:
84
enum class
Action
{
85
Erase
,
86
Insert
,
87
Replace
,
88
};
89
90
class
SlesIterImpl;
91
92
struct
SleAction
93
{
94
Action
action
;
95
SLE::pointer
sle
;
96
97
// Constructor needed for emplacement in std::map
98
SleAction
(
Action
action
,
SLE::pointer
sle
) :
action
(
action
),
sle
(
std
::move(
sle
))
99
{
100
}
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)
105
using
ItemsT
=
std::map
<
106
key_type
,
107
SleAction
,
108
std::less<>
,
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.
112
std::unique_ptr<boost::container::pmr::monotonic_buffer_resource>
monotonicResource_
;
113
ItemsT
items_
;
114
115
XRPAmount
dropsDestroyed_
{0};
116
};
117
118
}
// 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:28
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:113
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:105
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:112
xrpl::detail::RawStateTable::Action
Action
Definition
RawStateTable.h:84
xrpl::detail::RawStateTable::Action::Replace
@ Replace
Definition
RawStateTable.h:87
xrpl::detail::RawStateTable::Action::Insert
@ Insert
Definition
RawStateTable.h:86
xrpl::detail::RawStateTable::Action::Erase
@ Erase
Definition
RawStateTable.h:85
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:37
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:115
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:580
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:93
xrpl::detail::RawStateTable::SleAction::sle
SLE::pointer sle
Definition
RawStateTable.h:95
xrpl::detail::RawStateTable::SleAction::SleAction
SleAction(Action action, SLE::pointer sle)
Definition
RawStateTable.h:98
xrpl::detail::RawStateTable::SleAction::action
Action action
Definition
RawStateTable.h:94
std::unique_ptr
utility
Generated by
1.17.0