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 <xrpl/basics/algorithm.h>
24#include <xrpl/shamap/SHAMap.h>
25
26#include <algorithm>
27#include <utility>
28#include <vector>
29
30namespace ripple {
31
32template <class TxID, class Sequence>
34{
35public:
36 struct TxIDSeq
37 {
39 Sequence seq;
40
41 TxIDSeq(TxID const& txid_, Sequence const& seq_)
42 : txid(txid_), seq(seq_)
43 {
44 }
45 };
46
47 friend bool
48 operator<(TxIDSeq const& lhs, TxIDSeq const& rhs)
49 {
50 if (lhs.txid != rhs.txid)
51 return lhs.txid < rhs.txid;
52 return lhs.seq < rhs.seq;
53 }
54
55 friend bool
56 operator<(TxIDSeq const& lhs, TxID const& rhs)
57 {
58 return lhs.txid < rhs;
59 }
60
61 friend bool
62 operator<(TxID const& lhs, TxIDSeq const& rhs)
63 {
64 return lhs < rhs.txid;
65 }
66
68
69private:
71
72public:
74
80 void
82 {
83 // We want to remove any entries that we proposed in a previous round
84 // that did not make it in yet if we are no longer proposing them.
85 // And we also want to preserve the Sequence of entries that we proposed
86 // in the last round and want to propose again.
87 std::sort(proposed.begin(), proposed.end());
89 proposed.begin(),
90 proposed.end(),
92 tracker_.cend(),
93 [](auto& x, auto const& y) { x.seq = y.seq; },
94 [](auto const& x, auto const& y) { return x.txid < y.txid; });
95 tracker_ = std::move(proposed);
96 }
97
111 template <class Predicate>
112 void
114 {
115 auto acceptTxid = accepted.begin();
116 auto const ae = accepted.end();
117 std::sort(acceptTxid, ae);
118
119 // We want to remove all tracking entries for transactions that were
120 // accepted as well as those which match the predicate.
121
123 tracker_.begin(),
124 tracker_.end(),
125 accepted.begin(),
126 accepted.end(),
127 [&pred](auto const& x) { return pred(x.txid, x.seq); },
130 }
131
137 void
139 {
140 tracker_.clear();
141 }
142};
143
144} // namespace ripple
145
146#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_)