xrpld
Loading...
Searching...
No Matches
CollectorRef.h
1#pragma once
2
3#include <test/csf/SimTime.h>
4#include <test/csf/events.h>
5
6namespace xrpl::test::csf {
7
48{
49 using tp = SimTime;
50
51 // Interface for type-erased collector instance
53 {
54 virtual ~ICollector() = default;
55
56 virtual void
57 on(PeerID node, tp when, Share<Tx> const&) = 0;
58
59 virtual void
60 on(PeerID node, tp when, Share<TxSet> const&) = 0;
61
62 virtual void
63 on(PeerID node, tp when, Share<Validation> const&) = 0;
64
65 virtual void
66 on(PeerID node, tp when, Share<Ledger> const&) = 0;
67
68 virtual void
69 on(PeerID node, tp when, Share<Proposal> const&) = 0;
70
71 virtual void
72 on(PeerID node, tp when, Receive<Tx> const&) = 0;
73
74 virtual void
75 on(PeerID node, tp when, Receive<TxSet> const&) = 0;
76
77 virtual void
78 on(PeerID node, tp when, Receive<Validation> const&) = 0;
79
80 virtual void
81 on(PeerID node, tp when, Receive<Ledger> const&) = 0;
82
83 virtual void
84 on(PeerID node, tp when, Receive<Proposal> const&) = 0;
85
86 virtual void
87 on(PeerID node, tp when, Relay<Tx> const&) = 0;
88
89 virtual void
90 on(PeerID node, tp when, Relay<TxSet> const&) = 0;
91
92 virtual void
93 on(PeerID node, tp when, Relay<Validation> const&) = 0;
94
95 virtual void
96 on(PeerID node, tp when, Relay<Ledger> const&) = 0;
97
98 virtual void
99 on(PeerID node, tp when, Relay<Proposal> const&) = 0;
100
101 virtual void
102 on(PeerID node, tp when, SubmitTx const&) = 0;
103
104 virtual void
105 on(PeerID node, tp when, StartRound const&) = 0;
106
107 virtual void
108 on(PeerID node, tp when, CloseLedger const&) = 0;
109
110 virtual void
111 on(PeerID node, tp when, AcceptLedger const&) = 0;
112
113 virtual void
114 on(PeerID node, tp when, WrongPrevLedger const&) = 0;
115
116 virtual void
117 on(PeerID node, tp when, FullyValidateLedger const&) = 0;
118 };
119
120 // Bridge between type-ful collector T and type erased instance
121 template <class T>
122 class Any final : public ICollector
123 {
124 T& t_;
125
126 public:
127 Any(T& t) : t_{t}
128 {
129 }
130
131 // Can't copy
132 Any(Any const&) = delete;
133 Any&
134 operator=(Any const&) = delete;
135
136 Any(Any&&) = default;
137 Any&
138 operator=(Any&&) = default;
139
140 void
141 on(PeerID node, tp when, Share<Tx> const& e) override
142 {
143 t_.on(node, when, e);
144 }
145
146 void
147 on(PeerID node, tp when, Share<TxSet> const& e) override
148 {
149 t_.on(node, when, e);
150 }
151
152 void
153 on(PeerID node, tp when, Share<Validation> const& e) override
154 {
155 t_.on(node, when, e);
156 }
157
158 void
159 on(PeerID node, tp when, Share<Ledger> const& e) override
160 {
161 t_.on(node, when, e);
162 }
163
164 void
165 on(PeerID node, tp when, Share<Proposal> const& e) override
166 {
167 t_.on(node, when, e);
168 }
169
170 void
171 on(PeerID node, tp when, Receive<Tx> const& e) override
172 {
173 t_.on(node, when, e);
174 }
175
176 void
177 on(PeerID node, tp when, Receive<TxSet> const& e) override
178 {
179 t_.on(node, when, e);
180 }
181
182 void
183 on(PeerID node, tp when, Receive<Validation> const& e) override
184 {
185 t_.on(node, when, e);
186 }
187
188 void
189 on(PeerID node, tp when, Receive<Ledger> const& e) override
190 {
191 t_.on(node, when, e);
192 }
193
194 void
195 on(PeerID node, tp when, Receive<Proposal> const& e) override
196 {
197 t_.on(node, when, e);
198 }
199
200 void
201 on(PeerID node, tp when, Relay<Tx> const& e) override
202 {
203 t_.on(node, when, e);
204 }
205
206 void
207 on(PeerID node, tp when, Relay<TxSet> const& e) override
208 {
209 t_.on(node, when, e);
210 }
211
212 void
213 on(PeerID node, tp when, Relay<Validation> const& e) override
214 {
215 t_.on(node, when, e);
216 }
217
218 void
219 on(PeerID node, tp when, Relay<Ledger> const& e) override
220 {
221 t_.on(node, when, e);
222 }
223
224 void
225 on(PeerID node, tp when, Relay<Proposal> const& e) override
226 {
227 t_.on(node, when, e);
228 }
229
230 void
231 on(PeerID node, tp when, SubmitTx const& e) override
232 {
233 t_.on(node, when, e);
234 }
235
236 void
237 on(PeerID node, tp when, StartRound const& e) override
238 {
239 t_.on(node, when, e);
240 }
241
242 void
243 on(PeerID node, tp when, CloseLedger const& e) override
244 {
245 t_.on(node, when, e);
246 }
247
248 void
249 on(PeerID node, tp when, AcceptLedger const& e) override
250 {
251 t_.on(node, when, e);
252 }
253
254 void
255 on(PeerID node, tp when, WrongPrevLedger const& e) override
256 {
257 t_.on(node, when, e);
258 }
259
260 void
261 on(PeerID node, tp when, FullyValidateLedger const& e) override
262 {
263 t_.on(node, when, e);
264 }
265 };
266
268
269public:
270 template <class T>
271 CollectorRef(T& t) : impl_{new Any<T>(t)}
272 {
273 }
274
275 // Non-copyable
276 CollectorRef(CollectorRef const& c) = delete;
279
283
284 template <class E>
285 void
286 on(PeerID node, tp when, E const& e)
287 {
288 impl_->on(node, when, e);
289 }
290};
291
303{
305
306public:
307 template <class Collector>
308 void
309 add(Collector& collector)
310 {
311 collectors_.emplace_back(collector);
312 }
313
314 template <class E>
315 void
316 on(PeerID node, SimTime when, E const& e)
317 {
318 for (auto& c : collectors_)
319 {
320 c.on(node, when, e);
321 }
322 }
323};
324
325} // namespace xrpl::test::csf
void on(PeerID node, tp when, CloseLedger const &e) override
void on(PeerID node, tp when, Relay< Proposal > const &e) override
void on(PeerID node, tp when, Share< Validation > const &e) override
void on(PeerID node, tp when, Receive< Validation > const &e) override
void on(PeerID node, tp when, FullyValidateLedger const &e) override
void on(PeerID node, tp when, Relay< Tx > const &e) override
void on(PeerID node, tp when, Receive< TxSet > const &e) override
void on(PeerID node, tp when, AcceptLedger const &e) override
void on(PeerID node, tp when, Relay< Validation > const &e) override
void on(PeerID node, tp when, Receive< Tx > const &e) override
void on(PeerID node, tp when, Relay< Ledger > const &e) override
Any & operator=(Any &&)=default
Any & operator=(Any const &)=delete
void on(PeerID node, tp when, StartRound const &e) override
void on(PeerID node, tp when, Relay< TxSet > const &e) override
void on(PeerID node, tp when, Share< Proposal > const &e) override
void on(PeerID node, tp when, WrongPrevLedger const &e) override
void on(PeerID node, tp when, Share< Tx > const &e) override
void on(PeerID node, tp when, SubmitTx const &e) override
void on(PeerID node, tp when, Share< Ledger > const &e) override
void on(PeerID node, tp when, Receive< Proposal > const &e) override
void on(PeerID node, tp when, Share< TxSet > const &e) override
void on(PeerID node, tp when, Receive< Ledger > const &e) override
std::unique_ptr< ICollector > impl_
void on(PeerID node, tp when, E const &e)
CollectorRef & operator=(CollectorRef &&)=default
CollectorRef(CollectorRef &&)=default
CollectorRef(CollectorRef const &c)=delete
CollectorRef & operator=(CollectorRef &c)=delete
A container of CollectorRefs.
void add(Collector &collector)
void on(PeerID node, SimTime when, E const &e)
std::vector< CollectorRef > collectors_
TaggedInteger< std::uint32_t, PeerIDTag > PeerID
Definition Validation.h:15
SimClock::time_point SimTime
Definition SimTime.h:15
Peer accepted consensus results.
Definition events.h:99
Peer closed the open ledger.
Definition events.h:89
virtual void on(PeerID node, tp when, Receive< Tx > const &)=0
virtual void on(PeerID node, tp when, Relay< TxSet > const &)=0
virtual void on(PeerID node, tp when, Share< Proposal > const &)=0
virtual void on(PeerID node, tp when, WrongPrevLedger const &)=0
virtual void on(PeerID node, tp when, Receive< Validation > const &)=0
virtual void on(PeerID node, tp when, Relay< Ledger > const &)=0
virtual void on(PeerID node, tp when, Receive< TxSet > const &)=0
virtual void on(PeerID node, tp when, Share< TxSet > const &)=0
virtual void on(PeerID node, tp when, Relay< Validation > const &)=0
virtual void on(PeerID node, tp when, Relay< Proposal > const &)=0
virtual void on(PeerID node, tp when, AcceptLedger const &)=0
virtual void on(PeerID node, tp when, CloseLedger const &)=0
virtual void on(PeerID node, tp when, Receive< Ledger > const &)=0
virtual void on(PeerID node, tp when, Relay< Tx > const &)=0
virtual void on(PeerID node, tp when, Share< Tx > const &)=0
virtual void on(PeerID node, tp when, Share< Ledger > const &)=0
virtual void on(PeerID node, tp when, StartRound const &)=0
virtual void on(PeerID node, tp when, Share< Validation > const &)=0
virtual void on(PeerID node, tp when, FullyValidateLedger const &)=0
virtual void on(PeerID node, tp when, Receive< Proposal > const &)=0
virtual void on(PeerID node, tp when, SubmitTx const &)=0
Peer fully validated a new ledger.
Definition events.h:118
A value received from another peer as part of flooding.
Definition events.h:60
A value relayed to another peer as part of flooding.
Definition events.h:48
A value to be flooded to all other peers starting from this peer.
Definition events.h:39
Peer starts a new consensus round.
Definition events.h:78
A transaction submitted to a peer.
Definition events.h:70
Peer detected a wrong prior ledger during consensus.
Definition events.h:109