rippled
Loading...
Searching...
No Matches
RCLCensorshipDetector.h
1#ifndef XRPL_APP_CONSENSUS_RCLCENSORSHIPDETECTOR_H_INCLUDED
2#define XRPL_APP_CONSENSUS_RCLCENSORSHIPDETECTOR_H_INCLUDED
3
4#include <xrpl/basics/algorithm.h>
5#include <xrpl/shamap/SHAMap.h>
6
7#include <algorithm>
8#include <utility>
9#include <vector>
10
11namespace ripple {
12
13template <class TxID, class Sequence>
15{
16public:
17 struct TxIDSeq
18 {
20 Sequence seq;
21
22 TxIDSeq(TxID const& txid_, Sequence const& seq_)
23 : txid(txid_), seq(seq_)
24 {
25 }
26 };
27
28 friend bool
29 operator<(TxIDSeq const& lhs, TxIDSeq const& rhs)
30 {
31 if (lhs.txid != rhs.txid)
32 return lhs.txid < rhs.txid;
33 return lhs.seq < rhs.seq;
34 }
35
36 friend bool
37 operator<(TxIDSeq const& lhs, TxID const& rhs)
38 {
39 return lhs.txid < rhs;
40 }
41
42 friend bool
43 operator<(TxID const& lhs, TxIDSeq const& rhs)
44 {
45 return lhs < rhs.txid;
46 }
47
49
50private:
52
53public:
55
61 void
63 {
64 // We want to remove any entries that we proposed in a previous round
65 // that did not make it in yet if we are no longer proposing them.
66 // And we also want to preserve the Sequence of entries that we proposed
67 // in the last round and want to propose again.
68 std::sort(proposed.begin(), proposed.end());
70 proposed.begin(),
71 proposed.end(),
73 tracker_.cend(),
74 [](auto& x, auto const& y) { x.seq = y.seq; },
75 [](auto const& x, auto const& y) { return x.txid < y.txid; });
76 tracker_ = std::move(proposed);
77 }
78
92 template <class Predicate>
93 void
94 check(std::vector<TxID> accepted, Predicate&& pred)
95 {
96 auto acceptTxid = accepted.begin();
97 auto const ae = accepted.end();
98 std::sort(acceptTxid, ae);
99
100 // We want to remove all tracking entries for transactions that were
101 // accepted as well as those which match the predicate.
102
104 tracker_.begin(),
105 tracker_.end(),
106 accepted.begin(),
107 accepted.end(),
108 [&pred](auto const& x) { return pred(x.txid, x.seq); },
111 }
112
118 void
120 {
121 tracker_.clear();
122 }
123};
124
125} // namespace ripple
126
127#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:6
void generalized_set_intersection(InputIter1 first1, InputIter1 last1, InputIter2 first2, InputIter2 last2, Action action, Comp comp)
Definition algorithm.h:17
@ 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:55
T sort(T... args)
TxIDSeq(TxID const &txid_, Sequence const &seq_)