rippled
Loading...
Searching...
No Matches
RCLCensorshipDetector.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2018 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_RCLCENSORSHIPDETECTOR_H_INCLUDED
21#define RIPPLE_APP_CONSENSUS_RCLCENSORSHIPDETECTOR_H_INCLUDED
22
23#include <xrpld/shamap/SHAMap.h>
24
25#include <xrpl/basics/algorithm.h>
26
27#include <algorithm>
28#include <utility>
29#include <vector>
30
31namespace ripple {
32
33template <class TxID, class Sequence>
35{
36public:
37 struct TxIDSeq
38 {
40 Sequence seq;
41
42 TxIDSeq(TxID const& txid_, Sequence const& seq_)
43 : txid(txid_), seq(seq_)
44 {
45 }
46 };
47
48 friend bool
49 operator<(TxIDSeq const& lhs, TxIDSeq const& rhs)
50 {
51 if (lhs.txid != rhs.txid)
52 return lhs.txid < rhs.txid;
53 return lhs.seq < rhs.seq;
54 }
55
56 friend bool
57 operator<(TxIDSeq const& lhs, TxID const& rhs)
58 {
59 return lhs.txid < rhs;
60 }
61
62 friend bool
63 operator<(TxID const& lhs, TxIDSeq const& rhs)
64 {
65 return lhs < rhs.txid;
66 }
67
69
70private:
72
73public:
75
81 void
83 {
84 // We want to remove any entries that we proposed in a previous round
85 // that did not make it in yet if we are no longer proposing them.
86 // And we also want to preserve the Sequence of entries that we proposed
87 // in the last round and want to propose again.
88 std::sort(proposed.begin(), proposed.end());
90 proposed.begin(),
91 proposed.end(),
93 tracker_.cend(),
94 [](auto& x, auto const& y) { x.seq = y.seq; },
95 [](auto const& x, auto const& y) { return x.txid < y.txid; });
96 tracker_ = std::move(proposed);
97 }
98
112 template <class Predicate>
113 void
115 {
116 auto acceptTxid = accepted.begin();
117 auto const ae = accepted.end();
118 std::sort(acceptTxid, ae);
119
120 // We want to remove all tracking entries for transactions that were
121 // accepted as well as those which match the predicate.
122
124 tracker_.begin(),
125 tracker_.end(),
126 accepted.begin(),
127 accepted.end(),
128 [&pred](auto const& x) { return pred(x.txid, x.seq); },
131 }
132
138 void
140 {
141 tracker_.clear();
142 }
143};
144
145} // namespace ripple
146
147#endif
T begin(T... args)
void reset()
Removes all elements from the tracker.
friend bool operator<(TxIDSeq const &lhs, TxIDSeq const &rhs)
void check(std::vector< TxID > accepted, Predicate &&pred)
Determine which transactions made it and perform censorship detection.
void propose(TxIDSeqVec proposed)
Add transactions being proposed for the current consensus round.
T clear(T... args)
T end(T... args)
T erase(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
void generalized_set_intersection(InputIter1 first1, InputIter1 last1, InputIter2 first2, InputIter2 last2, Action action, Comp comp)
Definition algorithm.h:36
@ accepted
Manifest is valid.
FwdIter1 remove_if_intersect_or_match(FwdIter1 first1, FwdIter1 last1, InputIter2 first2, InputIter2 last2, Pred pred, Comp comp)
Definition algorithm.h:74
T sort(T... args)
TxIDSeq(TxID const &txid_, Sequence const &seq_)