rippled
Loading...
Searching...
No Matches
RCLCxTx.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012-2016 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_APP_CONSENSUS_RCLCXTX_H_INCLUDED
21#define RIPPLE_APP_CONSENSUS_RCLCXTX_H_INCLUDED
22
23#include <xrpld/shamap/SHAMap.h>
24
25namespace ripple {
26
33{
34public:
36 using ID = uint256;
37
42 RCLCxTx(boost::intrusive_ptr<SHAMapItem const> txn) : tx_(std::move(txn))
43 {
44 }
45
47 ID const&
48 id() const
49 {
50 return tx_->key();
51 }
52
54 boost::intrusive_ptr<SHAMapItem const> tx_;
55};
56
63{
64public:
66 using ID = uint256;
68 using Tx = RCLCxTx;
69
70 //< Provide a mutable view of a TxSet
72 {
73 friend class RCLTxSet;
76
77 public:
78 MutableTxSet(RCLTxSet const& src) : map_{src.map_->snapShot(true)}
79 {
80 }
81
87 bool
88 insert(Tx const& t)
89 {
90 return map_->addItem(SHAMapNodeType::tnTRANSACTION_NM, t.tx_);
91 }
92
98 bool
99 erase(Tx::ID const& entry)
100 {
101 return map_->delItem(entry);
102 }
103 };
104
110 {
111 XRPL_ASSERT(
112 map_, "ripple::RCLTxSet::MutableTxSet::RCLTxSet : non-null input");
113 }
114
119 RCLTxSet(MutableTxSet const& m) : map_{m.map_->snapShot(false)}
120 {
121 }
122
128 bool
129 exists(Tx::ID const& entry) const
130 {
131 return map_->hasItem(entry);
132 }
133
145 boost::intrusive_ptr<SHAMapItem const> const&
146 find(Tx::ID const& entry) const
147 {
148 return map_->peekItem(entry);
149 }
150
152 ID
153 id() const
154 {
155 return map_->getHash().as_uint256();
156 }
157
167 compare(RCLTxSet const& j) const
168 {
169 SHAMap::Delta delta;
170
171 // Bound the work we do in case of a malicious
172 // map_ from a trusted validator
173 map_->compare(*(j.map_), delta, 65536);
174
176 for (auto const& [k, v] : delta)
177 {
178 XRPL_ASSERT(
179 (v.first && !v.second) || (v.second && !v.first),
180 "ripple::RCLTxSet::compare : either side is set");
181
182 ret[k] = static_cast<bool>(v.first);
183 }
184 return ret;
185 }
186
189};
190} // namespace ripple
191#endif
Represents a transaction in RCLConsensus.
Definition RCLCxTx.h:33
ID const & id() const
The unique identifier/hash of the transaction.
Definition RCLCxTx.h:48
RCLCxTx(boost::intrusive_ptr< SHAMapItem const > txn)
Constructor.
Definition RCLCxTx.h:42
boost::intrusive_ptr< SHAMapItem const > tx_
The SHAMapItem that represents the transaction.
Definition RCLCxTx.h:54
uint256 ID
Unique identifier/hash of transaction.
Definition RCLCxTx.h:36
MutableTxSet(RCLTxSet const &src)
Definition RCLCxTx.h:78
bool insert(Tx const &t)
Insert a new transaction into the set.
Definition RCLCxTx.h:88
bool erase(Tx::ID const &entry)
Remove a transaction from the set.
Definition RCLCxTx.h:99
std::shared_ptr< SHAMap > map_
The SHAMap representing the transactions.
Definition RCLCxTx.h:75
Represents a set of transactions in RCLConsensus.
Definition RCLCxTx.h:63
bool exists(Tx::ID const &entry) const
Test if a transaction is in the set.
Definition RCLCxTx.h:129
RCLTxSet(MutableTxSet const &m)
Constructor from a previously created MutableTxSet.
Definition RCLCxTx.h:119
RCLTxSet(std::shared_ptr< SHAMap > m)
Constructor.
Definition RCLCxTx.h:109
boost::intrusive_ptr< SHAMapItem const > const & find(Tx::ID const &entry) const
Lookup a transaction.
Definition RCLCxTx.h:146
uint256 ID
Unique identifier/hash of the set of transactions.
Definition RCLCxTx.h:66
ID id() const
The unique ID/hash of the transaction set.
Definition RCLCxTx.h:153
std::map< Tx::ID, bool > compare(RCLTxSet const &j) const
Find transactions not in common between this and another transaction set.
Definition RCLCxTx.h:167
std::shared_ptr< SHAMap > map_
The SHAMap representing the transactions.
Definition RCLCxTx.h:188
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
base_uint< 256 > uint256
Definition base_uint.h:558
STL namespace.