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/app/misc/CanonicalTXSet.h>
24#include <xrpld/shamap/SHAMap.h>
25#include <xrpl/basics/chrono.h>
26#include <xrpl/protocol/UintTypes.h>
27
28namespace ripple {
29
36{
37public:
39 using ID = uint256;
40
45 RCLCxTx(boost::intrusive_ptr<SHAMapItem const> txn) : tx_(std::move(txn))
46 {
47 }
48
50 ID const&
51 id() const
52 {
53 return tx_->key();
54 }
55
57 boost::intrusive_ptr<SHAMapItem const> tx_;
58};
59
66{
67public:
69 using ID = uint256;
71 using Tx = RCLCxTx;
72
73 //< Provide a mutable view of a TxSet
75 {
76 friend class RCLTxSet;
79
80 public:
81 MutableTxSet(RCLTxSet const& src) : map_{src.map_->snapShot(true)}
82 {
83 }
84
90 bool
91 insert(Tx const& t)
92 {
93 return map_->addItem(SHAMapNodeType::tnTRANSACTION_NM, t.tx_);
94 }
95
101 bool
102 erase(Tx::ID const& entry)
103 {
104 return map_->delItem(entry);
105 }
106 };
107
113 {
114 XRPL_ASSERT(
115 map_, "ripple::RCLTxSet::MutableTxSet::RCLTxSet : non-null input");
116 }
117
122 RCLTxSet(MutableTxSet const& m) : map_{m.map_->snapShot(false)}
123 {
124 }
125
131 bool
132 exists(Tx::ID const& entry) const
133 {
134 return map_->hasItem(entry);
135 }
136
148 boost::intrusive_ptr<SHAMapItem const> const&
149 find(Tx::ID const& entry) const
150 {
151 return map_->peekItem(entry);
152 }
153
155 ID
156 id() const
157 {
158 return map_->getHash().as_uint256();
159 }
160
170 compare(RCLTxSet const& j) const
171 {
172 SHAMap::Delta delta;
173
174 // Bound the work we do in case of a malicious
175 // map_ from a trusted validator
176 map_->compare(*(j.map_), delta, 65536);
177
179 for (auto const& [k, v] : delta)
180 {
181 XRPL_ASSERT(
182 (v.first && !v.second) || (v.second && !v.first),
183 "ripple::RCLTxSet::compare : either side is set");
184
185 ret[k] = static_cast<bool>(v.first);
186 }
187 return ret;
188 }
189
192};
193} // namespace ripple
194#endif
Represents a transaction in RCLConsensus.
Definition: RCLCxTx.h:36
ID const & id() const
The unique identifier/hash of the transaction.
Definition: RCLCxTx.h:51
RCLCxTx(boost::intrusive_ptr< SHAMapItem const > txn)
Constructor.
Definition: RCLCxTx.h:45
boost::intrusive_ptr< SHAMapItem const > tx_
The SHAMapItem that represents the transaction.
Definition: RCLCxTx.h:57
uint256 ID
Unique identifier/hash of transaction.
Definition: RCLCxTx.h:39
MutableTxSet(RCLTxSet const &src)
Definition: RCLCxTx.h:81
bool insert(Tx const &t)
Insert a new transaction into the set.
Definition: RCLCxTx.h:91
bool erase(Tx::ID const &entry)
Remove a transaction from the set.
Definition: RCLCxTx.h:102
std::shared_ptr< SHAMap > map_
The SHAMap representing the transactions.
Definition: RCLCxTx.h:78
Represents a set of transactions in RCLConsensus.
Definition: RCLCxTx.h:66
bool exists(Tx::ID const &entry) const
Test if a transaction is in the set.
Definition: RCLCxTx.h:132
RCLTxSet(MutableTxSet const &m)
Constructor from a previously created MutableTxSet.
Definition: RCLCxTx.h:122
RCLTxSet(std::shared_ptr< SHAMap > m)
Constructor.
Definition: RCLCxTx.h:112
boost::intrusive_ptr< SHAMapItem const > const & find(Tx::ID const &entry) const
Lookup a transaction.
Definition: RCLCxTx.h:149
uint256 ID
Unique identifier/hash of the set of transactions.
Definition: RCLCxTx.h:69
ID id() const
The unique ID/hash of the transaction set.
Definition: RCLCxTx.h:156
std::map< Tx::ID, bool > compare(RCLTxSet const &j) const
Find transactions not in common between this and another transaction set.
Definition: RCLCxTx.h:170
std::shared_ptr< SHAMap > map_
The SHAMap representing the transactions.
Definition: RCLCxTx.h:191
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
base_uint< 256 > uint256
Definition: base_uint.h:557
STL namespace.