xrpld
Loading...
Searching...
No Matches
RCLCxTx.h
1#pragma once
2
3#include <xrpl/shamap/SHAMap.h>
4
5namespace xrpl {
6
13{
14public:
16 using ID = uint256;
17
22 RCLCxTx(boost::intrusive_ptr<SHAMapItem const> txn) : tx(std::move(txn))
23 {
24 }
25
27 [[nodiscard]] ID const&
28 id() const
29 {
30 return tx->key();
31 }
32
34 boost::intrusive_ptr<SHAMapItem const> tx;
35};
36
43{
44public:
46 using ID = uint256;
48 using Tx = RCLCxTx;
49
50 //< Provide a mutable view of a TxSet
52 {
53 friend class RCLTxSet;
56
57 public:
58 MutableTxSet(RCLTxSet const& src) : map_{src.map->snapShot(true)}
59 {
60 }
61
67 bool
68 insert(Tx const& t)
69 {
70 return map_->addItem(SHAMapNodeType::TnTransactionNm, t.tx);
71 }
72
78 bool
79 erase(Tx::ID const& entry)
80 {
81 return map_->delItem(entry);
82 }
83 };
84
90 {
91 XRPL_ASSERT(map, "xrpl::RCLTxSet::MutableTxSet::RCLTxSet : non-null input");
92 }
93
98 RCLTxSet(MutableTxSet const& m) : map{m.map_->snapShot(false)}
99 {
100 }
101
107 [[nodiscard]] bool
108 exists(Tx::ID const& entry) const
109 {
110 return map->hasItem(entry);
111 }
112
124 [[nodiscard]] boost::intrusive_ptr<SHAMapItem const> const&
125 find(Tx::ID const& entry) const
126 {
127 return map->peekItem(entry);
128 }
129
131 [[nodiscard]] ID
132 id() const
133 {
134 return map->getHash().asUInt256();
135 }
136
145 [[nodiscard]] std::map<Tx::ID, bool>
146 compare(RCLTxSet const& j) const
147 {
148 SHAMap::Delta delta;
149
150 // Bound the work we do in case of a malicious
151 // map from a trusted validator
152 map->compare(*(j.map), delta, 65536);
153
155 for (auto const& [k, v] : delta)
156 {
157 XRPL_ASSERT(
158 (v.first && !v.second) || (v.second && !v.first),
159 "xrpl::RCLTxSet::compare : either side is set");
160
161 ret[k] = static_cast<bool>(v.first);
162 }
163 return ret;
164 }
165
168};
169} // namespace xrpl
Represents a transaction in RCLConsensus.
Definition RCLCxTx.h:13
boost::intrusive_ptr< SHAMapItem const > tx
The SHAMapItem that represents the transaction.
Definition RCLCxTx.h:34
RCLCxTx(boost::intrusive_ptr< SHAMapItem const > txn)
Constructor.
Definition RCLCxTx.h:22
ID const & id() const
The unique identifier/hash of the transaction.
Definition RCLCxTx.h:28
uint256 ID
Unique identifier/hash of transaction.
Definition RCLCxTx.h:16
MutableTxSet(RCLTxSet const &src)
Definition RCLCxTx.h:58
bool insert(Tx const &t)
Insert a new transaction into the set.
Definition RCLCxTx.h:68
std::shared_ptr< SHAMap > map_
The SHAMap representing the transactions.
Definition RCLCxTx.h:55
bool erase(Tx::ID const &entry)
Remove a transaction from the set.
Definition RCLCxTx.h:79
uint256 ID
Unique identifier/hash of the set of transactions.
Definition RCLCxTx.h:46
boost::intrusive_ptr< SHAMapItem const > const & find(Tx::ID const &entry) const
Lookup a transaction.
Definition RCLCxTx.h:125
RCLTxSet(MutableTxSet const &m)
Constructor from a previously created MutableTxSet.
Definition RCLCxTx.h:98
bool exists(Tx::ID const &entry) const
Test if a transaction is in the set.
Definition RCLCxTx.h:108
RCLCxTx Tx
The type that corresponds to a single transaction.
Definition RCLCxTx.h:48
ID id() const
The unique ID/hash of the transaction set.
Definition RCLCxTx.h:132
std::shared_ptr< SHAMap > map
The SHAMap representing the transactions.
Definition RCLCxTx.h:167
std::map< Tx::ID, bool > compare(RCLTxSet const &j) const
Find transactions not in common between this and another transaction set.
Definition RCLCxTx.h:146
RCLTxSet(std::shared_ptr< SHAMap > m)
Constructor.
Definition RCLCxTx.h:89
std::map< uint256, DeltaItem > Delta
Definition SHAMap.h:104
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:562