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#include <xrpl/basics/algorithm.h>
25#include <algorithm>
26#include <utility>
27#include <vector>
28
29namespace ripple {
30
31template <class TxID, class Sequence>
33{
34public:
35 struct TxIDSeq
36 {
38 Sequence seq;
39
40 TxIDSeq(TxID const& txid_, Sequence const& seq_)
41 : txid(txid_), seq(seq_)
42 {
43 }
44 };
45
46 friend bool
47 operator<(TxIDSeq const& lhs, TxIDSeq const& rhs)
48 {
49 if (lhs.txid != rhs.txid)
50 return lhs.txid < rhs.txid;
51 return lhs.seq < rhs.seq;
52 }
53
54 friend bool
55 operator<(TxIDSeq const& lhs, TxID const& rhs)
56 {
57 return lhs.txid < rhs;
58 }
59
60 friend bool
61 operator<(TxID const& lhs, TxIDSeq const& rhs)
62 {
63 return lhs < rhs.txid;
64 }
65
67
68private:
70
71public:
73
79 void
81 {
82 // We want to remove any entries that we proposed in a previous round
83 // that did not make it in yet if we are no longer proposing them.
84 // And we also want to preserve the Sequence of entries that we proposed
85 // in the last round and want to propose again.
86 std::sort(proposed.begin(), proposed.end());
88 proposed.begin(),
89 proposed.end(),
91 tracker_.cend(),
92 [](auto& x, auto const& y) { x.seq = y.seq; },
93 [](auto const& x, auto const& y) { return x.txid < y.txid; });
94 tracker_ = std::move(proposed);
95 }
96
110 template <class Predicate>
111 void
113 {
114 auto acceptTxid = accepted.begin();
115 auto const ae = accepted.end();
116 std::sort(acceptTxid, ae);
117
118 // We want to remove all tracking entries for transactions that were
119 // accepted as well as those which match the predicate.
120
122 tracker_.begin(),
123 tracker_.end(),
124 accepted.begin(),
125 accepted.end(),
126 [&pred](auto const& x) { return pred(x.txid, x.seq); },
129 }
130
136 void
138 {
139 tracker_.clear();
140 }
141};
142
143} // namespace ripple
144
145#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:26
void generalized_set_intersection(InputIter1 first1, InputIter1 last1, InputIter2 first2, InputIter2 last2, Action action, Comp comp)
Definition: algorithm.h:37
@ 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:75
T sort(T... args)
TxIDSeq(TxID const &txid_, Sequence const &seq_)