@@ -13,6 +13,7 @@ use mixnet_contract_common::{
13
13
use rocket:: fairing:: AdHoc ;
14
14
use serde:: Serialize ;
15
15
use std:: collections:: HashMap ;
16
+ use std:: collections:: HashSet ;
16
17
use std:: sync:: atomic:: { AtomicBool , Ordering } ;
17
18
use std:: sync:: Arc ;
18
19
use std:: time:: Duration ;
@@ -40,6 +41,9 @@ struct ValidatorCacheInner {
40
41
mixnodes : Cache < Vec < MixNodeBond > > ,
41
42
gateways : Cache < Vec < GatewayBond > > ,
42
43
44
+ mixnodes_blacklist : Cache < HashSet < IdentityKey > > ,
45
+ gateways_blacklist : Cache < HashSet < IdentityKey > > ,
46
+
43
47
rewarded_set : Cache < Vec < MixNodeBond > > ,
44
48
active_set : Cache < Vec < MixNodeBond > > ,
45
49
@@ -203,6 +207,8 @@ impl ValidatorCache {
203
207
routes:: get_gateways,
204
208
routes:: get_active_set,
205
209
routes:: get_rewarded_set,
210
+ routes:: get_blacklisted_mixnodes,
211
+ routes:: get_blacklisted_gateways,
206
212
] ,
207
213
)
208
214
} )
@@ -225,12 +231,82 @@ impl ValidatorCache {
225
231
inner. current_reward_params . update ( epoch_rewarding_params) ;
226
232
}
227
233
228
- pub async fn mixnodes ( & self ) -> Cache < Vec < MixNodeBond > > {
229
- self . inner . read ( ) . await . mixnodes . clone ( )
234
+ pub async fn mixnodes_blacklist ( & self ) -> Cache < HashSet < IdentityKey > > {
235
+ self . inner . read ( ) . await . mixnodes_blacklist . clone ( )
236
+ }
237
+
238
+ pub async fn gateways_blacklist ( & self ) -> Cache < HashSet < IdentityKey > > {
239
+ self . inner . read ( ) . await . gateways_blacklist . clone ( )
240
+ }
241
+
242
+ pub async fn insert_mixnodes_blacklist ( & mut self , mix_identity : IdentityKey ) {
243
+ self . inner
244
+ . write ( )
245
+ . await
246
+ . mixnodes_blacklist
247
+ . value
248
+ . insert ( mix_identity) ;
249
+ }
250
+
251
+ pub async fn remove_mixnodes_blacklist ( & mut self , mix_identity : & str ) {
252
+ self . inner
253
+ . write ( )
254
+ . await
255
+ . mixnodes_blacklist
256
+ . value
257
+ . remove ( mix_identity) ;
258
+ }
259
+
260
+ pub async fn insert_gateways_blacklist ( & mut self , gateway_identity : IdentityKey ) {
261
+ self . inner
262
+ . write ( )
263
+ . await
264
+ . gateways_blacklist
265
+ . value
266
+ . insert ( gateway_identity) ;
267
+ }
268
+
269
+ pub async fn remove_gateways_blacklist ( & mut self , gateway_identity : & str ) {
270
+ self . inner
271
+ . write ( )
272
+ . await
273
+ . gateways_blacklist
274
+ . value
275
+ . remove ( gateway_identity) ;
276
+ }
277
+
278
+ pub async fn mixnodes ( & self ) -> Vec < MixNodeBond > {
279
+ let blacklist = self . mixnodes_blacklist ( ) . await . value ;
280
+ self . inner
281
+ . read ( )
282
+ . await
283
+ . mixnodes
284
+ . value
285
+ . iter ( )
286
+ . filter ( |mix| !blacklist. contains ( mix. identity ( ) ) )
287
+ . cloned ( )
288
+ . collect ( )
289
+ }
290
+
291
+ pub async fn mixnodes_all ( & self ) -> Vec < MixNodeBond > {
292
+ self . inner . read ( ) . await . mixnodes . value . clone ( )
293
+ }
294
+
295
+ pub async fn gateways ( & self ) -> Vec < GatewayBond > {
296
+ let blacklist = self . gateways_blacklist ( ) . await . value ;
297
+ self . inner
298
+ . read ( )
299
+ . await
300
+ . gateways
301
+ . value
302
+ . iter ( )
303
+ . filter ( |gateway| !blacklist. contains ( gateway. identity ( ) ) )
304
+ . cloned ( )
305
+ . collect ( )
230
306
}
231
307
232
- pub async fn gateways ( & self ) -> Cache < Vec < GatewayBond > > {
233
- self . inner . read ( ) . await . gateways . clone ( )
308
+ pub async fn gateways_all ( & self ) -> Vec < GatewayBond > {
309
+ self . inner . read ( ) . await . gateways . value . clone ( )
234
310
}
235
311
236
312
pub async fn rewarded_set ( & self ) -> Cache < Vec < MixNodeBond > > {
@@ -312,6 +388,8 @@ impl ValidatorCacheInner {
312
388
rewarded_set : Cache :: default ( ) ,
313
389
active_set : Cache :: default ( ) ,
314
390
current_reward_params : Cache :: new ( EpochRewardParams :: new_empty ( ) ) ,
391
+ mixnodes_blacklist : Cache :: default ( ) ,
392
+ gateways_blacklist : Cache :: default ( ) ,
315
393
// setting it to a dummy value on creation is fine, as nothing will be able to ready from it
316
394
// since 'initialised' flag won't be set
317
395
current_epoch : Cache :: new ( None ) ,
0 commit comments