xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
xrpld
app
consensus
RCLCxTx.h
1
#pragma once
2
3
#include <xrpl/basics/base_uint.h>
4
#include <xrpl/beast/utility/instrumentation.h>
5
#include <xrpl/shamap/SHAMap.h>
6
#include <xrpl/shamap/SHAMapItem.h>
7
#include <xrpl/shamap/SHAMapTreeNode.h>
8
9
#include <
map
>
10
#include <
memory
>
11
#include <
utility
>
12
13
namespace
xrpl
{
14
21
class
RCLCxTx
22
{
23
public
:
27
using
ID
=
UInt256
;
28
34
RCLCxTx
(boost::intrusive_ptr<SHAMapItem const> txn) :
tx
(
std
::move(txn))
35
{
36
}
37
41
[[nodiscard]]
ID
const
&
42
id
()
const
43
{
44
return
tx
->key();
45
}
46
50
boost::intrusive_ptr<SHAMapItem const>
tx
;
51
};
52
59
class
RCLTxSet
60
{
61
public
:
65
using
ID
=
UInt256
;
69
using
Tx
=
RCLCxTx
;
70
71
//< Provide a mutable view of a TxSet
72
class
MutableTxSet
73
{
74
friend
class
RCLTxSet
;
78
std::shared_ptr<SHAMap>
map_
;
79
80
public
:
81
MutableTxSet
(
RCLTxSet
const
& src) :
map_
{src.
map
->snapShot(true)}
82
{
83
}
84
91
bool
92
insert
(
Tx
const
& t)
93
{
94
return
map_
->addItem(
SHAMapNodeType::TnTransactionNm
, t.
tx
);
95
}
96
103
bool
104
erase
(
Tx::ID
const
& entry)
105
{
106
return
map_
->delItem(entry);
107
}
108
};
109
115
RCLTxSet
(
std::shared_ptr<SHAMap>
m) :
map
{
std
::move(m)}
116
{
117
XRPL_ASSERT(
map
,
"xrpl::RCLTxSet::MutableTxSet::RCLTxSet : non-null input"
);
118
}
119
125
RCLTxSet
(
MutableTxSet
const
& m) :
map
{m.map_->snapShot(false)}
126
{
127
}
128
135
[[nodiscard]]
bool
136
exists
(
Tx::ID
const
& entry)
const
137
{
138
return
map
->hasItem(entry);
139
}
140
153
[[nodiscard]] boost::intrusive_ptr<SHAMapItem const>
const
&
154
find
(
Tx::ID
const
& entry)
const
155
{
156
return
map
->peekItem(entry);
157
}
158
162
[[nodiscard]]
ID
163
id
()
const
164
{
165
return
map
->getHash().asUInt256();
166
}
167
177
[[nodiscard]]
std::map<Tx::ID, bool>
178
compare
(
RCLTxSet
const
& j)
const
179
{
180
SHAMap::Delta
delta;
181
182
// Bound the work we do in case of a malicious
183
// map from a trusted validator
184
map
->compare(*(j.
map
), delta, 65536);
185
186
std::map<UInt256, bool>
ret;
187
for
(
auto
const
& [k, v] : delta)
188
{
189
XRPL_ASSERT(
190
(v.first && !v.second) || (v.second && !v.first),
191
"xrpl::RCLTxSet::compare : either side is set"
);
192
193
ret[k] =
static_cast<
bool
>
(v.first);
194
}
195
return
ret;
196
}
197
201
std::shared_ptr<SHAMap>
map
;
202
};
203
}
// namespace xrpl
xrpl::RCLCxTx
Represents a transaction in RCLConsensus.
Definition
RCLCxTx.h:22
xrpl::RCLCxTx::tx
boost::intrusive_ptr< SHAMapItem const > tx
The SHAMapItem that represents the transaction.
Definition
RCLCxTx.h:50
xrpl::RCLCxTx::ID
UInt256 ID
Unique identifier/hash of transaction.
Definition
RCLCxTx.h:27
xrpl::RCLCxTx::RCLCxTx
RCLCxTx(boost::intrusive_ptr< SHAMapItem const > txn)
Constructor.
Definition
RCLCxTx.h:34
xrpl::RCLCxTx::id
ID const & id() const
The unique identifier/hash of the transaction.
Definition
RCLCxTx.h:42
xrpl::RCLTxSet::MutableTxSet
Definition
RCLCxTx.h:73
xrpl::RCLTxSet::MutableTxSet::MutableTxSet
MutableTxSet(RCLTxSet const &src)
Definition
RCLCxTx.h:81
xrpl::RCLTxSet::MutableTxSet::insert
bool insert(Tx const &t)
Insert a new transaction into the set.
Definition
RCLCxTx.h:92
xrpl::RCLTxSet::MutableTxSet::map_
std::shared_ptr< SHAMap > map_
The SHAMap representing the transactions.
Definition
RCLCxTx.h:78
xrpl::RCLTxSet::MutableTxSet::erase
bool erase(Tx::ID const &entry)
Remove a transaction from the set.
Definition
RCLCxTx.h:104
xrpl::RCLTxSet::MutableTxSet::RCLTxSet
friend class RCLTxSet
Definition
RCLCxTx.h:74
xrpl::RCLTxSet::find
boost::intrusive_ptr< SHAMapItem const > const & find(Tx::ID const &entry) const
Lookup a transaction.
Definition
RCLCxTx.h:154
xrpl::RCLTxSet::ID
UInt256 ID
Unique identifier/hash of the set of transactions.
Definition
RCLCxTx.h:65
xrpl::RCLTxSet::RCLTxSet
RCLTxSet(MutableTxSet const &m)
Constructor from a previously created MutableTxSet.
Definition
RCLCxTx.h:125
xrpl::RCLTxSet::exists
bool exists(Tx::ID const &entry) const
Test if a transaction is in the set.
Definition
RCLCxTx.h:136
xrpl::RCLTxSet::Tx
RCLCxTx Tx
The type that corresponds to a single transaction.
Definition
RCLCxTx.h:69
xrpl::RCLTxSet::id
ID id() const
The unique ID/hash of the transaction set.
Definition
RCLCxTx.h:163
xrpl::RCLTxSet::map
std::shared_ptr< SHAMap > map
The SHAMap representing the transactions.
Definition
RCLCxTx.h:201
xrpl::RCLTxSet::compare
std::map< Tx::ID, bool > compare(RCLTxSet const &j) const
Find transactions not in common between this and another transaction set.
Definition
RCLCxTx.h:178
xrpl::RCLTxSet::RCLTxSet
RCLTxSet(std::shared_ptr< SHAMap > m)
Constructor.
Definition
RCLCxTx.h:115
xrpl::SHAMap::Delta
std::map< UInt256, DeltaItem > Delta
Definition
SHAMap.h:148
map
memory
std
STL namespace.
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::SHAMapNodeType::TnTransactionNm
@ TnTransactionNm
Definition
SHAMapTreeNode.h:32
xrpl::UInt256
BaseUInt< 256 > UInt256
Definition
base_uint.h:580
std::shared_ptr
utility
Generated by
1.17.0