rippled
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 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::tnTRANSACTION_NM, 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 bool
108 exists(Tx::ID const& entry) const
109 {
110 return map_->hasItem(entry);
111 }
112
124 boost::intrusive_ptr<SHAMapItem const> const&
125 find(Tx::ID const& entry) const
126 {
127 return map_->peekItem(entry);
128 }
129
131 ID
132 id() const
133 {
134 return map_->getHash().as_uint256();
135 }
136
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), "xrpl::RCLTxSet::compare : either side is set");
159
160 ret[k] = static_cast<bool>(v.first);
161 }
162 return ret;
163 }
164
167};
168} // 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
Represents a set of transactions in RCLConsensus.
Definition RCLCxTx.h:43
std::shared_ptr< SHAMap > map_
The SHAMap representing the transactions.
Definition RCLCxTx.h:166
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
ID id() const
The unique ID/hash of the transaction set.
Definition RCLCxTx.h:132
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
STL namespace.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
base_uint< 256 > uint256
Definition base_uint.h:526