@@ -21,13 +21,13 @@ use tracing::{debug, info};
21
21
use casper_types:: { Chainspec , ChainspecRawBytes , SecretKey } ;
22
22
23
23
use super :: {
24
- chain_info:: ChainInfo , Config , Event as NetworkEvent , FromIncoming , GossipedAddress , Identity ,
24
+ chain_info:: ChainInfo , Event as NetworkEvent , FromIncoming , GossipedAddress , Identity ,
25
25
MessageKind , Network , Payload ,
26
26
} ;
27
27
use crate :: {
28
28
components:: {
29
29
gossiper:: { self , GossipItem , Gossiper } ,
30
- Component , InitializedComponent ,
30
+ network , Component , InitializedComponent ,
31
31
} ,
32
32
effect:: {
33
33
announcements:: { ControlAnnouncement , GossiperAnnouncement , PeerBehaviorAnnouncement } ,
@@ -39,13 +39,13 @@ use crate::{
39
39
EffectBuilder , Effects ,
40
40
} ,
41
41
protocol,
42
- reactor:: { self , EventQueueHandle , Finalize , Reactor , Runner } ,
42
+ reactor:: { self , main_reactor :: Config , EventQueueHandle , Finalize , Reactor , Runner } ,
43
43
testing:: {
44
44
self , init_logging,
45
45
network:: { NetworkedReactor , Nodes , TestingNetwork } ,
46
46
ConditionCheckReactor ,
47
47
} ,
48
- types:: { NodeId , ValidatorMatrix } ,
48
+ types:: { NodeId , SyncHandling , ValidatorMatrix } ,
49
49
NodeRng ,
50
50
} ;
51
51
@@ -182,43 +182,6 @@ impl Reactor for TestReactor {
182
182
type Config = Config ;
183
183
type Error = anyhow:: Error ;
184
184
185
- fn new (
186
- cfg : Self :: Config ,
187
- _chainspec : Arc < Chainspec > ,
188
- _chainspec_raw_bytes : Arc < ChainspecRawBytes > ,
189
- our_identity : Identity ,
190
- registry : & Registry ,
191
- _event_queue : EventQueueHandle < Self :: Event > ,
192
- rng : & mut NodeRng ,
193
- ) -> anyhow:: Result < ( Self , Effects < Self :: Event > ) > {
194
- let secret_key = SecretKey :: random ( rng) ;
195
- let mut net = Network :: new (
196
- cfg,
197
- our_identity,
198
- None ,
199
- registry,
200
- ChainInfo :: create_for_testing ( ) ,
201
- ValidatorMatrix :: new_with_validator ( Arc :: new ( secret_key) ) ,
202
- ) ?;
203
- let gossiper_config = gossiper:: Config :: new_with_small_timeouts ( ) ;
204
- let address_gossiper = Gossiper :: < { GossipedAddress :: ID_IS_COMPLETE_ITEM } , _ > :: new (
205
- "address_gossiper" ,
206
- gossiper_config,
207
- registry,
208
- ) ?;
209
-
210
- net. start_initialization ( ) ;
211
- let effects = smallvec ! [ async { smallvec![ Event :: Net ( NetworkEvent :: Initialize ) ] } . boxed( ) ] ;
212
-
213
- Ok ( (
214
- TestReactor {
215
- net,
216
- address_gossiper,
217
- } ,
218
- effects,
219
- ) )
220
- }
221
-
222
185
fn dispatch_event (
223
186
& mut self ,
224
187
effect_builder : EffectBuilder < Self :: Event > ,
@@ -277,6 +240,45 @@ impl Reactor for TestReactor {
277
240
Event :: BlocklistAnnouncement ( _announcement) => Effects :: new ( ) ,
278
241
}
279
242
}
243
+
244
+ fn new (
245
+ cfg : Self :: Config ,
246
+ _chainspec : Arc < Chainspec > ,
247
+ _chainspec_raw_bytes : Arc < ChainspecRawBytes > ,
248
+ our_identity : Identity ,
249
+ registry : & Registry ,
250
+ _event_queue : EventQueueHandle < Self :: Event > ,
251
+ rng : & mut NodeRng ,
252
+ ) -> anyhow:: Result < ( Self , Effects < Self :: Event > ) > {
253
+ let secret_key = SecretKey :: random ( rng) ;
254
+ let allow_handshake = cfg. node . sync_handling != SyncHandling :: Isolated ;
255
+ let mut net = Network :: new (
256
+ cfg. network . clone ( ) ,
257
+ our_identity,
258
+ None ,
259
+ registry,
260
+ ChainInfo :: create_for_testing ( ) ,
261
+ ValidatorMatrix :: new_with_validator ( Arc :: new ( secret_key) ) ,
262
+ allow_handshake,
263
+ ) ?;
264
+ let gossiper_config = gossiper:: Config :: new_with_small_timeouts ( ) ;
265
+ let address_gossiper = Gossiper :: < { GossipedAddress :: ID_IS_COMPLETE_ITEM } , _ > :: new (
266
+ "address_gossiper" ,
267
+ gossiper_config,
268
+ registry,
269
+ ) ?;
270
+
271
+ net. start_initialization ( ) ;
272
+ let effects = smallvec ! [ async { smallvec![ Event :: Net ( NetworkEvent :: Initialize ) ] } . boxed( ) ] ;
273
+
274
+ Ok ( (
275
+ TestReactor {
276
+ net,
277
+ address_gossiper,
278
+ } ,
279
+ effects,
280
+ ) )
281
+ }
280
282
}
281
283
282
284
impl NetworkedReactor for TestReactor {
@@ -351,13 +353,15 @@ async fn run_two_node_network_five_times() {
351
353
let mut net = TestingNetwork :: new ( ) ;
352
354
353
355
let start = Instant :: now ( ) ;
354
- net. add_node_with_config (
355
- Config :: default_local_net_first_node ( first_node_port) ,
356
- & mut rng,
357
- )
358
- . await
359
- . unwrap ( ) ;
360
- net. add_node_with_config ( Config :: default_local_net ( first_node_port) , & mut rng)
356
+
357
+ let cfg = Config :: default ( ) . with_network_config (
358
+ network:: Config :: default_local_net_first_node ( first_node_port) ,
359
+ ) ;
360
+ net. add_node_with_config ( cfg, & mut rng) . await . unwrap ( ) ;
361
+
362
+ let cfg = Config :: default ( )
363
+ . with_network_config ( network:: Config :: default_local_net ( first_node_port) ) ;
364
+ net. add_node_with_config ( cfg. clone ( ) , & mut rng)
361
365
. await
362
366
. unwrap ( ) ;
363
367
let end = Instant :: now ( ) ;
@@ -417,12 +421,11 @@ async fn bind_to_real_network_interface() {
417
421
. ip ( ) ;
418
422
let port = testing:: unused_port_on_localhost ( ) ;
419
423
420
- let local_net_config = Config :: new ( ( local_addr, port) . into ( ) ) ;
424
+ let cfg =
425
+ Config :: default ( ) . with_network_config ( network:: Config :: new ( ( local_addr, port) . into ( ) ) ) ;
421
426
422
427
let mut net = TestingNetwork :: < TestReactor > :: new ( ) ;
423
- net. add_node_with_config ( local_net_config, & mut rng)
424
- . await
425
- . unwrap ( ) ;
428
+ net. add_node_with_config ( cfg, & mut rng) . await . unwrap ( ) ;
426
429
427
430
// The network should be fully connected.
428
431
let timeout = Duration :: from_secs ( 2 ) ;
@@ -452,17 +455,16 @@ async fn check_varying_size_network_connects() {
452
455
453
456
// Pick a random port in the higher ranges that is likely to be unused.
454
457
let first_node_port = testing:: unused_port_on_localhost ( ) ;
458
+ let cfg = Config :: default ( ) . with_network_config (
459
+ network:: Config :: default_local_net_first_node ( first_node_port) ,
460
+ ) ;
455
461
456
- let _ = net
457
- . add_node_with_config (
458
- Config :: default_local_net_first_node ( first_node_port) ,
459
- & mut rng,
460
- )
461
- . await
462
- . unwrap ( ) ;
462
+ let _ = net. add_node_with_config ( cfg, & mut rng) . await . unwrap ( ) ;
463
+ let cfg = Config :: default ( )
464
+ . with_network_config ( network:: Config :: default_local_net ( first_node_port) ) ;
463
465
464
466
for _ in 1 ..number_of_nodes {
465
- net. add_node_with_config ( Config :: default_local_net ( first_node_port ) , & mut rng)
467
+ net. add_node_with_config ( cfg . clone ( ) , & mut rng)
466
468
. await
467
469
. unwrap ( ) ;
468
470
}
@@ -506,16 +508,17 @@ async fn ensure_peers_metric_is_correct() {
506
508
// Pick a random port in the higher ranges that is likely to be unused.
507
509
let first_node_port = testing:: unused_port_on_localhost ( ) ;
508
510
509
- let _ = net
510
- . add_node_with_config (
511
- Config :: default_local_net_first_node ( first_node_port) ,
512
- & mut rng,
513
- )
514
- . await
515
- . unwrap ( ) ;
511
+ let cfg = Config :: default ( ) . with_network_config (
512
+ network:: Config :: default_local_net_first_node ( first_node_port) ,
513
+ ) ;
514
+
515
+ let _ = net. add_node_with_config ( cfg, & mut rng) . await . unwrap ( ) ;
516
+
517
+ let cfg = Config :: default ( )
518
+ . with_network_config ( network:: Config :: default_local_net ( first_node_port) ) ;
516
519
517
520
for _ in 1 ..number_of_nodes {
518
- net. add_node_with_config ( Config :: default_local_net ( first_node_port ) , & mut rng)
521
+ net. add_node_with_config ( cfg . clone ( ) , & mut rng)
519
522
. await
520
523
. unwrap ( ) ;
521
524
}
0 commit comments