xrpld
Loading...
Searching...
No Matches
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
13namespace xrpl {
14
22{
23public:
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
60{
61public:
65 using ID = uint256;
69 using Tx = RCLCxTx;
70
71 //< Provide a mutable view of a TxSet
73 {
74 friend class RCLTxSet;
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
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
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
202};
203} // namespace xrpl
Represents a transaction in RCLConsensus.
Definition RCLCxTx.h:22
boost::intrusive_ptr< SHAMapItem const > tx
The SHAMapItem that represents the transaction.
Definition RCLCxTx.h:50
RCLCxTx(boost::intrusive_ptr< SHAMapItem const > txn)
Constructor.
Definition RCLCxTx.h:34
ID const & id() const
The unique identifier/hash of the transaction.
Definition RCLCxTx.h:42
uint256 ID
Unique identifier/hash of transaction.
Definition RCLCxTx.h:27
MutableTxSet(RCLTxSet const &src)
Definition RCLCxTx.h:81
bool insert(Tx const &t)
Insert a new transaction into the set.
Definition RCLCxTx.h:92
std::shared_ptr< SHAMap > map_
The SHAMap representing the transactions.
Definition RCLCxTx.h:78
bool erase(Tx::ID const &entry)
Remove a transaction from the set.
Definition RCLCxTx.h:104
uint256 ID
Unique identifier/hash of the set of transactions.
Definition RCLCxTx.h:65
boost::intrusive_ptr< SHAMapItem const > const & find(Tx::ID const &entry) const
Lookup a transaction.
Definition RCLCxTx.h:154
RCLTxSet(MutableTxSet const &m)
Constructor from a previously created MutableTxSet.
Definition RCLCxTx.h:125
bool exists(Tx::ID const &entry) const
Test if a transaction is in the set.
Definition RCLCxTx.h:136
RCLCxTx Tx
The type that corresponds to a single transaction.
Definition RCLCxTx.h:69
ID id() const
The unique ID/hash of the transaction set.
Definition RCLCxTx.h:163
std::shared_ptr< SHAMap > map
The SHAMap representing the transactions.
Definition RCLCxTx.h:201
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
RCLTxSet(std::shared_ptr< SHAMap > m)
Constructor.
Definition RCLCxTx.h:115
std::map< uint256, DeltaItem > Delta
Definition SHAMap.h:148
STL namespace.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
BaseUInt< 256 > uint256
Definition base_uint.h:580