rippled
Loading...
Searching...
No Matches
RCLCensorshipDetector.h
1#pragma once
2
3#include <xrpl/basics/algorithm.h>
4#include <xrpl/shamap/SHAMap.h>
5
6#include <algorithm>
7#include <utility>
8#include <vector>
9
10namespace xrpl {
11
12template <class TxID, class Sequence>
14{
15public:
16 struct TxIDSeq
17 {
19 Sequence seq;
20
21 TxIDSeq(TxID const& txid_, Sequence const& seq_) : txid(txid_), seq(seq_)
22 {
23 }
24 };
25
26 friend bool
27 operator<(TxIDSeq const& lhs, TxIDSeq const& rhs)
28 {
29 if (lhs.txid != rhs.txid)
30 return lhs.txid < rhs.txid;
31 return lhs.seq < rhs.seq;
32 }
33
34 friend bool
35 operator<(TxIDSeq const& lhs, TxID const& rhs)
36 {
37 return lhs.txid < rhs;
38 }
39
40 friend bool
41 operator<(TxID const& lhs, TxIDSeq const& rhs)
42 {
43 return lhs < rhs.txid;
44 }
45
47
48private:
50
51public:
53
59 void
61 {
62 // We want to remove any entries that we proposed in a previous round
63 // that did not make it in yet if we are no longer proposing them.
64 // And we also want to preserve the Sequence of entries that we proposed
65 // in the last round and want to propose again.
66 std::sort(proposed.begin(), proposed.end());
68 proposed.begin(),
69 proposed.end(),
71 tracker_.cend(),
72 [](auto& x, auto const& y) { x.seq = y.seq; },
73 [](auto const& x, auto const& y) { return x.txid < y.txid; });
74 tracker_ = std::move(proposed);
75 }
76
90 template <class Predicate>
91 void
92 check(std::vector<TxID> accepted, Predicate&& pred)
93 {
94 auto acceptTxid = accepted.begin();
95 auto const ae = accepted.end();
96 std::sort(acceptTxid, ae);
97
98 // We want to remove all tracking entries for transactions that were
99 // accepted as well as those which match the predicate.
100
102 tracker_.begin(),
103 tracker_.end(),
104 accepted.begin(),
105 accepted.end(),
106 [&pred](auto const& x) { return pred(x.txid, x.seq); },
109 }
110
116 void
118 {
119 tracker_.clear();
120 }
121};
122
123} // namespace xrpl
T begin(T... args)
void reset()
Removes all elements from the tracker.
void propose(TxIDSeqVec proposed)
Add transactions being proposed for the current consensus round.
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.
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:5
FwdIter1 remove_if_intersect_or_match(FwdIter1 first1, FwdIter1 last1, InputIter2 first2, InputIter2 last2, Pred pred, Comp comp)
Definition algorithm.h:54
void generalized_set_intersection(InputIter1 first1, InputIter1 last1, InputIter2 first2, InputIter2 last2, Action action, Comp comp)
Definition algorithm.h:16
@ accepted
Manifest is valid.
T sort(T... args)
TxIDSeq(TxID const &txid_, Sequence const &seq_)