subsystems.rs 9.96 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Copyright 2020 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.

//! Legacy way of defining subsystems.
//!
//! In the future, everything should be set up using the generated
Denis_P's avatar
Denis_P committed
20
//! overseer builder pattern instead.
21

22
use crate::dummy::DummySubsystem;
Shawn Tabrizi's avatar
Shawn Tabrizi committed
23
use polkadot_overseer_all_subsystems_gen::AllSubsystemsGen;
24
use polkadot_overseer_gen::MapSubsystem;
25
26
27
28
29
30
31
32
33
34
35

/// This struct is passed as an argument to create a new instance of an [`Overseer`].
///
/// As any entity that satisfies the interface may act as a [`Subsystem`] this allows
/// mocking in the test code:
///
/// Each [`Subsystem`] is supposed to implement some interface that is generic over
/// message type that is specific to this [`Subsystem`]. At the moment not all
/// subsystems are implemented and the rest can be mocked with the [`DummySubsystem`].
#[derive(Debug, Clone, AllSubsystemsGen)]
pub struct AllSubsystems<
Shawn Tabrizi's avatar
Shawn Tabrizi committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
	CV = (),
	CB = (),
	SD = (),
	AD = (),
	AR = (),
	BS = (),
	BD = (),
	P = (),
	RA = (),
	AS = (),
	NB = (),
	CA = (),
	CG = (),
	CP = (),
	ApD = (),
	ApV = (),
	GS = (),
	DC = (),
	DP = (),
	DD = (),
	CS = (),
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
> {
	/// A candidate validation subsystem.
	pub candidate_validation: CV,
	/// A candidate backing subsystem.
	pub candidate_backing: CB,
	/// A statement distribution subsystem.
	pub statement_distribution: SD,
	/// An availability distribution subsystem.
	pub availability_distribution: AD,
	/// An availability recovery subsystem.
	pub availability_recovery: AR,
	/// A bitfield signing subsystem.
	pub bitfield_signing: BS,
	/// A bitfield distribution subsystem.
	pub bitfield_distribution: BD,
	/// A provisioner subsystem.
	pub provisioner: P,
	/// A runtime API subsystem.
	pub runtime_api: RA,
	/// An availability store subsystem.
	pub availability_store: AS,
	/// A network bridge subsystem.
	pub network_bridge: NB,
	/// A Chain API subsystem.
	pub chain_api: CA,
	/// A Collation Generation subsystem.
	pub collation_generation: CG,
	/// A Collator Protocol subsystem.
	pub collator_protocol: CP,
	/// An Approval Distribution subsystem.
	pub approval_distribution: ApD,
	/// An Approval Voting subsystem.
	pub approval_voting: ApV,
	/// A Connection Request Issuer subsystem.
	pub gossip_support: GS,
Andronik Ordian's avatar
Andronik Ordian committed
92
93
94
95
96
97
98
99
	/// A Dispute Coordinator subsystem.
	pub dispute_coordinator: DC,
	/// A Dispute Participation subsystem.
	pub dispute_participation: DP,
	/// A Dispute Distribution subsystem.
	pub dispute_distribution: DD,
	/// A Chain Selection subsystem.
	pub chain_selection: CS,
100
101
}

Andronik Ordian's avatar
Andronik Ordian committed
102
103
impl<CV, CB, SD, AD, AR, BS, BD, P, RA, AS, NB, CA, CG, CP, ApD, ApV, GS, DC, DP, DD, CS>
	AllSubsystems<CV, CB, SD, AD, AR, BS, BD, P, RA, AS, NB, CA, CG, CP, ApD, ApV, GS, DC, DP, DD, CS>
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
{
	/// Create a new instance of [`AllSubsystems`].
	///
	/// Each subsystem is set to [`DummySystem`].
	///
	///# Note
	///
	/// Because of a bug in rustc it is required that when calling this function,
	/// you provide a "random" type for the first generic parameter:
	///
	/// ```
	/// polkadot_overseer::AllSubsystems::<()>::dummy();
	/// ```
	pub fn dummy() -> AllSubsystems<
		DummySubsystem,
		DummySubsystem,
		DummySubsystem,
		DummySubsystem,
		DummySubsystem,
		DummySubsystem,
		DummySubsystem,
		DummySubsystem,
		DummySubsystem,
		DummySubsystem,
		DummySubsystem,
		DummySubsystem,
		DummySubsystem,
		DummySubsystem,
		DummySubsystem,
		DummySubsystem,
		DummySubsystem,
Andronik Ordian's avatar
Andronik Ordian committed
135
136
137
138
		DummySubsystem,
		DummySubsystem,
		DummySubsystem,
		DummySubsystem,
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
	> {
		AllSubsystems {
			candidate_validation: DummySubsystem,
			candidate_backing: DummySubsystem,
			statement_distribution: DummySubsystem,
			availability_distribution: DummySubsystem,
			availability_recovery: DummySubsystem,
			bitfield_signing: DummySubsystem,
			bitfield_distribution: DummySubsystem,
			provisioner: DummySubsystem,
			runtime_api: DummySubsystem,
			availability_store: DummySubsystem,
			network_bridge: DummySubsystem,
			chain_api: DummySubsystem,
			collation_generation: DummySubsystem,
			collator_protocol: DummySubsystem,
			approval_distribution: DummySubsystem,
			approval_voting: DummySubsystem,
			gossip_support: DummySubsystem,
Andronik Ordian's avatar
Andronik Ordian committed
158
159
160
161
			dispute_coordinator: DummySubsystem,
			dispute_participation: DummySubsystem,
			dispute_distribution: DummySubsystem,
			chain_selection: DummySubsystem,
162
163
164
		}
	}

Denis_P's avatar
Denis_P committed
165
	/// Reference every individual subsystem.
Shawn Tabrizi's avatar
Shawn Tabrizi committed
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
	pub fn as_ref(
		&self,
	) -> AllSubsystems<
		&'_ CV,
		&'_ CB,
		&'_ SD,
		&'_ AD,
		&'_ AR,
		&'_ BS,
		&'_ BD,
		&'_ P,
		&'_ RA,
		&'_ AS,
		&'_ NB,
		&'_ CA,
		&'_ CG,
		&'_ CP,
		&'_ ApD,
		&'_ ApV,
		&'_ GS,
		&'_ DC,
		&'_ DP,
		&'_ DD,
		&'_ CS,
	> {
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
		AllSubsystems {
			candidate_validation: &self.candidate_validation,
			candidate_backing: &self.candidate_backing,
			statement_distribution: &self.statement_distribution,
			availability_distribution: &self.availability_distribution,
			availability_recovery: &self.availability_recovery,
			bitfield_signing: &self.bitfield_signing,
			bitfield_distribution: &self.bitfield_distribution,
			provisioner: &self.provisioner,
			runtime_api: &self.runtime_api,
			availability_store: &self.availability_store,
			network_bridge: &self.network_bridge,
			chain_api: &self.chain_api,
			collation_generation: &self.collation_generation,
			collator_protocol: &self.collator_protocol,
			approval_distribution: &self.approval_distribution,
			approval_voting: &self.approval_voting,
			gossip_support: &self.gossip_support,
Andronik Ordian's avatar
Andronik Ordian committed
209
210
211
212
			dispute_coordinator: &self.dispute_coordinator,
			dispute_participation: &self.dispute_participation,
			dispute_distribution: &self.dispute_distribution,
			chain_selection: &self.chain_selection,
213
214
215
216
		}
	}

	/// Map each subsystem.
Shawn Tabrizi's avatar
Shawn Tabrizi committed
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
	pub fn map_subsystems<Mapper>(
		self,
		mapper: Mapper,
	) -> AllSubsystems<
		<Mapper as MapSubsystem<CV>>::Output,
		<Mapper as MapSubsystem<CB>>::Output,
		<Mapper as MapSubsystem<SD>>::Output,
		<Mapper as MapSubsystem<AD>>::Output,
		<Mapper as MapSubsystem<AR>>::Output,
		<Mapper as MapSubsystem<BS>>::Output,
		<Mapper as MapSubsystem<BD>>::Output,
		<Mapper as MapSubsystem<P>>::Output,
		<Mapper as MapSubsystem<RA>>::Output,
		<Mapper as MapSubsystem<AS>>::Output,
		<Mapper as MapSubsystem<NB>>::Output,
		<Mapper as MapSubsystem<CA>>::Output,
		<Mapper as MapSubsystem<CG>>::Output,
		<Mapper as MapSubsystem<CP>>::Output,
		<Mapper as MapSubsystem<ApD>>::Output,
		<Mapper as MapSubsystem<ApV>>::Output,
		<Mapper as MapSubsystem<GS>>::Output,
		<Mapper as MapSubsystem<DC>>::Output,
		<Mapper as MapSubsystem<DP>>::Output,
		<Mapper as MapSubsystem<DD>>::Output,
		<Mapper as MapSubsystem<CS>>::Output,
	>
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
	where
		Mapper: MapSubsystem<CV>,
		Mapper: MapSubsystem<CB>,
		Mapper: MapSubsystem<SD>,
		Mapper: MapSubsystem<AD>,
		Mapper: MapSubsystem<AR>,
		Mapper: MapSubsystem<BS>,
		Mapper: MapSubsystem<BD>,
		Mapper: MapSubsystem<P>,
		Mapper: MapSubsystem<RA>,
		Mapper: MapSubsystem<AS>,
		Mapper: MapSubsystem<NB>,
		Mapper: MapSubsystem<CA>,
		Mapper: MapSubsystem<CG>,
		Mapper: MapSubsystem<CP>,
		Mapper: MapSubsystem<ApD>,
		Mapper: MapSubsystem<ApV>,
		Mapper: MapSubsystem<GS>,
Andronik Ordian's avatar
Andronik Ordian committed
261
262
263
264
		Mapper: MapSubsystem<DC>,
		Mapper: MapSubsystem<DP>,
		Mapper: MapSubsystem<DD>,
		Mapper: MapSubsystem<CS>,
265
266
	{
		AllSubsystems {
Shawn Tabrizi's avatar
Shawn Tabrizi committed
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
			candidate_validation: <Mapper as MapSubsystem<CV>>::map_subsystem(
				&mapper,
				self.candidate_validation,
			),
			candidate_backing: <Mapper as MapSubsystem<CB>>::map_subsystem(
				&mapper,
				self.candidate_backing,
			),
			statement_distribution: <Mapper as MapSubsystem<SD>>::map_subsystem(
				&mapper,
				self.statement_distribution,
			),
			availability_distribution: <Mapper as MapSubsystem<AD>>::map_subsystem(
				&mapper,
				self.availability_distribution,
			),
			availability_recovery: <Mapper as MapSubsystem<AR>>::map_subsystem(
				&mapper,
				self.availability_recovery,
			),
			bitfield_signing: <Mapper as MapSubsystem<BS>>::map_subsystem(
				&mapper,
				self.bitfield_signing,
			),
			bitfield_distribution: <Mapper as MapSubsystem<BD>>::map_subsystem(
				&mapper,
				self.bitfield_distribution,
			),
295
296
			provisioner: <Mapper as MapSubsystem<P>>::map_subsystem(&mapper, self.provisioner),
			runtime_api: <Mapper as MapSubsystem<RA>>::map_subsystem(&mapper, self.runtime_api),
Shawn Tabrizi's avatar
Shawn Tabrizi committed
297
298
299
300
301
302
303
304
			availability_store: <Mapper as MapSubsystem<AS>>::map_subsystem(
				&mapper,
				self.availability_store,
			),
			network_bridge: <Mapper as MapSubsystem<NB>>::map_subsystem(
				&mapper,
				self.network_bridge,
			),
305
			chain_api: <Mapper as MapSubsystem<CA>>::map_subsystem(&mapper, self.chain_api),
Shawn Tabrizi's avatar
Shawn Tabrizi committed
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
			collation_generation: <Mapper as MapSubsystem<CG>>::map_subsystem(
				&mapper,
				self.collation_generation,
			),
			collator_protocol: <Mapper as MapSubsystem<CP>>::map_subsystem(
				&mapper,
				self.collator_protocol,
			),
			approval_distribution: <Mapper as MapSubsystem<ApD>>::map_subsystem(
				&mapper,
				self.approval_distribution,
			),
			approval_voting: <Mapper as MapSubsystem<ApV>>::map_subsystem(
				&mapper,
				self.approval_voting,
			),
			gossip_support: <Mapper as MapSubsystem<GS>>::map_subsystem(
				&mapper,
				self.gossip_support,
			),
			dispute_coordinator: <Mapper as MapSubsystem<DC>>::map_subsystem(
				&mapper,
				self.dispute_coordinator,
			),
			dispute_participation: <Mapper as MapSubsystem<DP>>::map_subsystem(
				&mapper,
				self.dispute_participation,
			),
			dispute_distribution: <Mapper as MapSubsystem<DD>>::map_subsystem(
				&mapper,
				self.dispute_distribution,
			),
			chain_selection: <Mapper as MapSubsystem<CS>>::map_subsystem(
				&mapper,
				self.chain_selection,
			),
342
343
344
		}
	}
}