rippled
Loading...
Searching...
No Matches
RCLCxTx.h
1#ifndef XRPL_APP_CONSENSUS_RCLCXTX_H_INCLUDED
2#define XRPL_APP_CONSENSUS_RCLCXTX_H_INCLUDED
3
4#include <xrpl/shamap/SHAMap.h>
5
6namespace ripple {
7
14{
15public:
17 using ID = uint256;
18
23 RCLCxTx(boost::intrusive_ptr<SHAMapItem const> txn) : tx_(std::move(txn))
24 {
25 }
26
28 ID const&
29 id() const
30 {
31 return tx_->key();
32 }
33
35 boost::intrusive_ptr<SHAMapItem const> tx_;
36};
37
44{
45public:
47 using ID = uint256;
49 using Tx = RCLCxTx;
50
51 //< Provide a mutable view of a TxSet
53 {
54 friend class RCLTxSet;
57
58 public:
59 MutableTxSet(RCLTxSet const& src) : map_{src.map_->snapShot(true)}
60 {
61 }
62
68 bool
69 insert(Tx const& t)
70 {
71 return map_->addItem(SHAMapNodeType::tnTRANSACTION_NM, t.tx_);
72 }
73
79 bool
80 erase(Tx::ID const& entry)
81 {
82 return map_->delItem(entry);
83 }
84 };
85
91 {
92 XRPL_ASSERT(
93 map_, "ripple::RCLTxSet::MutableTxSet::RCLTxSet : non-null input");
94 }
95
100 RCLTxSet(MutableTxSet const& m) : map_{m.map_->snapShot(false)}
101 {
102 }
103
109 bool
110 exists(Tx::ID const& entry) const
111 {
112 return map_->hasItem(entry);
113 }
114
126 boost::intrusive_ptr<SHAMapItem const> const&
127 find(Tx::ID const& entry) const
128 {
129 return map_->peekItem(entry);
130 }
131
133 ID
134 id() const
135 {
136 return map_->getHash().as_uint256();
137 }
138
148 compare(RCLTxSet const& j) const
149 {
150 SHAMap::Delta delta;
151
152 // Bound the work we do in case of a malicious
153 // map_ from a trusted validator
154 map_->compare(*(j.map_), delta, 65536);
155
157 for (auto const& [k, v] : delta)
158 {
159 XRPL_ASSERT(
160 (v.first && !v.second) || (v.second && !v.first),
161 "ripple::RCLTxSet::compare : either side is set");
162
163 ret[k] = static_cast<bool>(v.first);
164 }
165 return ret;
166 }
167
170};
171} // namespace ripple
172#endif
Represents a transaction in RCLConsensus.
Definition RCLCxTx.h:14
ID const & id() const
The unique identifier/hash of the transaction.
Definition RCLCxTx.h:29
RCLCxTx(boost::intrusive_ptr< SHAMapItem const > txn)
Constructor.
Definition RCLCxTx.h:23
boost::intrusive_ptr< SHAMapItem const > tx_
The SHAMapItem that represents the transaction.
Definition RCLCxTx.h:35
uint256 ID
Unique identifier/hash of transaction.
Definition RCLCxTx.h:17
MutableTxSet(RCLTxSet const &src)
Definition RCLCxTx.h:59
bool insert(Tx const &t)
Insert a new transaction into the set.
Definition RCLCxTx.h:69
bool erase(Tx::ID const &entry)
Remove a transaction from the set.
Definition RCLCxTx.h:80
std::shared_ptr< SHAMap > map_
The SHAMap representing the transactions.
Definition RCLCxTx.h:56
Represents a set of transactions in RCLConsensus.
Definition RCLCxTx.h:44
bool exists(Tx::ID const &entry) const
Test if a transaction is in the set.
Definition RCLCxTx.h:110
RCLTxSet(MutableTxSet const &m)
Constructor from a previously created MutableTxSet.
Definition RCLCxTx.h:100
RCLTxSet(std::shared_ptr< SHAMap > m)
Constructor.
Definition RCLCxTx.h:90
boost::intrusive_ptr< SHAMapItem const > const & find(Tx::ID const &entry) const
Lookup a transaction.
Definition RCLCxTx.h:127
uint256 ID
Unique identifier/hash of the set of transactions.
Definition RCLCxTx.h:47
ID id() const
The unique ID/hash of the transaction set.
Definition RCLCxTx.h:134
std::map< Tx::ID, bool > compare(RCLTxSet const &j) const
Find transactions not in common between this and another transaction set.
Definition RCLCxTx.h:148
std::shared_ptr< SHAMap > map_
The SHAMap representing the transactions.
Definition RCLCxTx.h:169
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
base_uint< 256 > uint256
Definition base_uint.h:539
STL namespace.