/
recover_subnet.rs
708 lines (632 loc) · 27.7 KB
/
recover_subnet.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
92
93
94
95
96
97
98
99
100
101
102
103
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
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
295
296
297
298
299
300
301
302
303
304
305
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
use candid::Encode;
use canister_test::{Canister, Runtime};
use ic_base_types::{subnet_id_into_protobuf, PrincipalId, SubnetId};
use ic_config::Config;
use ic_ic00_types::{EcdsaCurve, EcdsaKeyId};
use ic_interfaces_registry::RegistryClient;
use ic_nns_common::registry::encode_or_panic;
use ic_nns_test_utils::{
itest_helpers::{
forward_call_via_universal_canister, local_test_on_nns_subnet_with_mutations,
set_up_registry_canister, set_up_universal_canister, try_call_via_universal_canister,
},
registry::{get_value_or_panic, prepare_registry},
};
use ic_protobuf::registry::{
crypto::v1::{EcdsaCurve as pbEcdsaCurve, EcdsaKeyId as pbEcdsaKeyId, EcdsaSigningSubnetList},
subnet::v1::{CatchUpPackageContents, EcdsaConfig, SubnetListRecord, SubnetRecord},
};
use ic_registry_keys::{
make_catch_up_package_contents_key, make_crypto_threshold_signing_pubkey_key,
make_ecdsa_signing_subnet_list_key, make_subnet_list_record_key, make_subnet_record_key,
};
use ic_registry_subnet_features::DEFAULT_ECDSA_MAX_QUEUE_SIZE;
use ic_registry_transport::{insert, pb::v1::RegistryAtomicMutateRequest, upsert};
use ic_replica_tests::{canister_test_with_config_async, get_ic_config};
use ic_test_utilities::types::ids::subnet_test_id;
use ic_types::ReplicaVersion;
use registry_canister::{
init::RegistryCanisterInitPayloadBuilder,
mutations::{
common::decode_registry_value,
do_create_subnet::{CreateSubnetPayload, EcdsaInitialConfig, EcdsaKeyRequest},
do_recover_subnet::RecoverSubnetPayload,
},
};
use std::convert::TryFrom;
mod common;
use common::test_helpers::{
dummy_cup_for_subnet, get_cup_contents, get_subnet_holding_ecdsa_keys, get_subnet_record,
prepare_registry_with_nodes, set_up_universal_canister_as_governance,
setup_registry_synced_with_fake_client, wait_for_ecdsa_setup,
};
/// Test that calling "recover_subnet" produces the expected Registry mutations,
/// namely that a subnet's `CatchUpPackageContents` and node membership are
/// updated as expected.
///
/// A note on the use of local_test_on_nns_subnet_with_mutations:
///
/// During this test, we stand-up an IC (the NNS subnet), install the Registry
/// canister and Subnet Handler, and call the "recover_subnet" Subnet Handler
/// method. Any instance of the IC needs a Registry to run, and because when we
/// create a new IC there doesn't exist a Registry Canister yet (because there
/// is no IC to run it on), the new IC uses a fake/static Registry. Once we
/// start this IC, we then deploy the Registry _canister_ onto it, because the
/// Subnet Handler needs the Registry _canister_ to function. However, this puts
/// us into an awkward position where there are 2 registries: the fake/static
/// one used by the underlying IC, and the Registry canister installed on top of
/// this IC.
///
/// During this test, we want to assert that nodes can be replaced in a subnet,
/// and that new DKG material is generated for these nodes/subnet. The required
/// set-up for this is to create some node records and node cypto info and store
/// it in the Registry canister. These are the replacement nodes we want to
/// replace the subnet's old nodes. With everything set-up, we call
/// "recover_subnet", which calls ic00's "setup_initial_dkg" to generate the DKG
/// info for these nodes.
///
/// "setup_initial_dkg" is an async call that takes a list of node IDs and
/// eventually delivers these nodes to the Consensus component of the underlying
/// IC. To generate DKG material, Consensus looks up the node records and node
/// crypto info for these nodes in the Registry. HOWEVER, these nodes are not in
/// the IC's fake/static Registry! These nodes were only added to the Registry
/// _canister_, not the IC's fake/static Registry. In order to ensure that
/// Consensus has access to these node records, we use
/// `common::prepare_registry` to get the list of node mutations used by this
/// test. We then use `local_test_on_nns_subnet_with_mutations` to apply these
/// mutations to the fake/static Registry used by the underlying IC, and then in
/// this test, we also apply these same mutations to the Registry _canister_.
/// This ensures that both the fake/static Registry and Registry _canister_ are
/// sync'd on the same node records.
#[test]
fn test_recover_subnet_with_replacement_nodes() {
let num_nodes_in_subnet = 4_usize;
let num_unassigned_nodes = 5_usize;
let (init_mutate, subnet_id, unassigned_node_ids, node_mutations) =
prepare_registry(num_nodes_in_subnet, num_unassigned_nodes);
local_test_on_nns_subnet_with_mutations(node_mutations, move |runtime| {
async move {
// In order to correctly allow the subnet handler to call atomic_mutate, we
// must first create canisters to get their IDs, and only then install them.
// This way, we pass the initial payload to the registry so it would allow
// mutation by the subnet handler.
let registry = set_up_registry_canister(
&runtime,
RegistryCanisterInitPayloadBuilder::new()
.push_init_mutate_request(init_mutate)
.build(),
)
.await;
// Install the universal canister in place of the governance canister
let fake_governance_canister = set_up_universal_canister(&runtime).await;
// Since it takes the id reserved for the governance canister, it can
// impersonate it
assert_eq!(
fake_governance_canister.canister_id(),
ic_nns_constants::GOVERNANCE_CANISTER_ID
);
let cup_contents_key = make_catch_up_package_contents_key(subnet_id).into_bytes();
let initial_cup_contents: CatchUpPackageContents =
get_value_or_panic(®istry, &cup_contents_key).await;
// Ensure that the subnet record is there
let subnet_list_record = get_value_or_panic::<SubnetListRecord>(
®istry,
make_subnet_list_record_key().as_bytes(),
)
.await;
assert_eq!(subnet_list_record.subnets.len(), 2);
assert_eq!(subnet_list_record.subnets[1], subnet_id.get().to_vec());
let subnet_record = get_value_or_panic::<SubnetRecord>(
®istry,
make_subnet_record_key(subnet_id).as_bytes(),
)
.await;
assert_eq!(subnet_record.membership.len(), num_nodes_in_subnet);
let payload = RecoverSubnetPayload {
subnet_id: subnet_id.get(),
height: 10,
time_ns: 1200,
state_hash: vec![10, 20, 30],
replacement_nodes: Some(unassigned_node_ids.clone()),
registry_store_uri: None,
ecdsa_config: None,
};
assert!(
forward_call_via_universal_canister(
&fake_governance_canister,
®istry,
"recover_subnet",
Encode!(&payload).unwrap()
)
.await
);
let subnet_list_record = get_value_or_panic::<SubnetListRecord>(
®istry,
make_subnet_list_record_key().as_bytes(),
)
.await;
assert_eq!(subnet_list_record.subnets.len(), 2);
assert_eq!(subnet_list_record.subnets[1], subnet_id.get().to_vec());
let subnet_record = get_subnet_record(®istry, subnet_id).await;
// Assert that `membership` has been replaced by `unassigned_node_ids`
assert_eq!(subnet_record.membership.len(), num_unassigned_nodes);
for node_id in unassigned_node_ids {
let node_id = node_id.get().to_vec();
assert!(subnet_record.membership.iter().any(|x| *x == node_id));
}
let updated_cup_contents: CatchUpPackageContents =
get_value_or_panic(®istry, &cup_contents_key).await;
// Assert that the CatchUpPackageContents was updated as expected
assert_eq!(payload.height, updated_cup_contents.height);
assert_eq!(payload.time_ns, updated_cup_contents.time);
assert_eq!(payload.state_hash, updated_cup_contents.state_hash);
// DKG should have been changed
assert_ne!(
initial_cup_contents.initial_ni_dkg_transcript_low_threshold,
updated_cup_contents.initial_ni_dkg_transcript_low_threshold
);
assert_ne!(
initial_cup_contents.initial_ni_dkg_transcript_high_threshold,
updated_cup_contents.initial_ni_dkg_transcript_high_threshold
);
Ok(())
}
});
}
#[test]
fn test_recover_subnet_gets_ecdsa_keys_when_needed() {
let ic_config = get_ic_config();
let (config, _tmpdir) = Config::temp_config();
canister_test_with_config_async(config, ic_config, |local_runtime| async move {
let data_provider = local_runtime.registry_data_provider.clone();
let fake_client = local_runtime.registry_client.clone();
let runtime = Runtime::Local(local_runtime);
// get some nodes for our tests
let (init_mutate, mut node_ids) = prepare_registry_with_nodes(5, 0);
let key_1 = EcdsaKeyId {
curve: EcdsaCurve::Secp256k1,
name: "foo-bar".to_string(),
};
let subnet_to_recover_nodes = vec![node_ids.pop().unwrap()];
let subnet_to_recover: SubnetRecord = CreateSubnetPayload {
node_ids: subnet_to_recover_nodes.clone(),
unit_delay_millis: 10,
gossip_retransmission_request_ms: 10_000,
gossip_registry_poll_period_ms: 2000,
gossip_pfn_evaluation_period_ms: 50,
gossip_receive_check_cache_size: 1,
gossip_max_duplicity: 1,
gossip_max_chunk_wait_ms: 200,
gossip_max_artifact_streams_per_peer: 1,
replica_version_id: ReplicaVersion::default().into(),
..CreateSubnetPayload::default()
}
.into();
// Here we discover the IC's subnet ID (from our test harness)
// and then modify it to hold the key and sign for it.
let mut subnet_list_record = decode_registry_value::<SubnetListRecord>(
fake_client
.get_value(
&make_subnet_list_record_key(),
fake_client.get_latest_version(),
)
.unwrap()
.unwrap(),
);
let subnet_to_recover_subnet_id = subnet_test_id(1003);
subnet_list_record
.subnets
.push(subnet_to_recover_subnet_id.get().into_vec());
let subnet_principals = subnet_list_record
.subnets
.iter()
.map(|record| PrincipalId::try_from(record).unwrap())
.collect::<Vec<_>>();
let system_subnet_principal = subnet_principals.get(0).unwrap();
let system_subnet_id = SubnetId::new(*system_subnet_principal);
let mut subnet_record = decode_registry_value::<SubnetRecord>(
fake_client
.get_value(
&make_subnet_record_key(system_subnet_id),
fake_client.get_latest_version(),
)
.unwrap()
.unwrap(),
);
subnet_record.ecdsa_config = Some(EcdsaConfig {
quadruples_to_create_in_advance: 1,
key_ids: vec![(&key_1).into()],
max_queue_size: DEFAULT_ECDSA_MAX_QUEUE_SIZE,
signature_request_timeout_ns: None,
idkg_key_rotation_period_ms: None,
});
let modify_base_subnet_mutate = RegistryAtomicMutateRequest {
mutations: vec![upsert(
make_subnet_record_key(system_subnet_id),
encode_or_panic(&subnet_record),
)],
preconditions: vec![],
};
// Add the subnet we are recovering holding requested keys
// Note, because these mutations are also synced with underlying IC registry, they
// need a CUP
let mutations = vec![
upsert(
make_subnet_record_key(subnet_to_recover_subnet_id).into_bytes(),
encode_or_panic(&subnet_to_recover),
),
upsert(
make_subnet_list_record_key().into_bytes(),
encode_or_panic(&subnet_list_record),
),
insert(
make_crypto_threshold_signing_pubkey_key(subnet_to_recover_subnet_id).as_bytes(),
encode_or_panic(&vec![]),
),
insert(
make_catch_up_package_contents_key(subnet_to_recover_subnet_id).as_bytes(),
encode_or_panic(&dummy_cup_for_subnet(subnet_to_recover_nodes)),
),
];
let add_subnets_mutate = RegistryAtomicMutateRequest {
preconditions: vec![],
mutations,
};
let registry = setup_registry_synced_with_fake_client(
&runtime,
fake_client,
data_provider,
vec![
init_mutate,
add_subnets_mutate,
modify_base_subnet_mutate,
// ecdsa_signing_subnets_mutate,
],
)
.await;
// Then we need to ensure the CUP for our subnet under test
// does not contain the ecdsa_initializations, since we will be asserting those were added
let before_recover_cup_contents =
get_cup_contents(®istry, subnet_to_recover_subnet_id).await;
assert_eq!(before_recover_cup_contents.ecdsa_initializations.len(), 0);
// Install the universal canister in place of the governance canister
let fake_governance_canister = set_up_universal_canister_as_governance(&runtime).await;
println!("waiting for ecdsa setup");
wait_for_ecdsa_setup(&runtime, &fake_governance_canister, &key_1).await;
let signature_request_timeout_ns = Some(12345);
let idkg_key_rotation_period_ms = Some(12345);
let payload = RecoverSubnetPayload {
subnet_id: subnet_to_recover_subnet_id.get(),
height: 10,
time_ns: 1200,
state_hash: vec![10, 20, 30],
replacement_nodes: None,
registry_store_uri: None,
ecdsa_config: Some(EcdsaInitialConfig {
quadruples_to_create_in_advance: 1,
keys: vec![EcdsaKeyRequest {
key_id: key_1.clone(),
subnet_id: Some(system_subnet_id.get()),
}],
max_queue_size: Some(DEFAULT_ECDSA_MAX_QUEUE_SIZE),
signature_request_timeout_ns,
idkg_key_rotation_period_ms,
}),
};
// When we recover a subnet with specified ecdsa_keys
try_call_via_universal_canister(
&fake_governance_canister,
®istry,
"recover_subnet",
Encode!(&payload).unwrap(),
)
.await
.unwrap();
let cup_contents = get_cup_contents(®istry, subnet_to_recover_subnet_id).await;
// Check EcdsaInitializations
let dealings = &cup_contents.ecdsa_initializations;
assert_eq!(dealings.len(), 1);
assert_eq!(
dealings[0_usize].key_id,
Some(pbEcdsaKeyId {
curve: pbEcdsaCurve::Secp256k1.into(),
name: "foo-bar".to_string(),
})
);
// Check EcdsaConfig is correctly updated
let subnet_record = get_subnet_record(®istry, subnet_to_recover_subnet_id).await;
let ecdsa_config = subnet_record.ecdsa_config.unwrap();
assert_eq!(ecdsa_config.max_queue_size, DEFAULT_ECDSA_MAX_QUEUE_SIZE);
assert_eq!(
ecdsa_config.signature_request_timeout_ns,
signature_request_timeout_ns
);
assert_eq!(
ecdsa_config.idkg_key_rotation_period_ms,
idkg_key_rotation_period_ms
);
let key_ids = ecdsa_config.key_ids;
assert_eq!(key_ids.len(), 1);
assert_eq!(
key_ids[0_usize],
pbEcdsaKeyId {
curve: pbEcdsaCurve::Secp256k1.into(),
name: "foo-bar".to_string(),
}
);
});
}
#[test]
fn test_recover_subnet_without_ecdsa_key_removes_it_from_signing_list() {
let ic_config = get_ic_config();
let (config, _tmpdir) = Config::temp_config();
canister_test_with_config_async(config, ic_config, |local_runtime| async move {
let data_provider = local_runtime.registry_data_provider.clone();
let fake_client = local_runtime.registry_client.clone();
let runtime = Runtime::Local(local_runtime);
// get some nodes for our tests
let (init_mutate, mut node_ids) = prepare_registry_with_nodes(5, 0);
let key_1 = EcdsaKeyId {
curve: EcdsaCurve::Secp256k1,
name: "foo-bar".to_string(),
};
let subnet_to_recover_nodes = vec![node_ids.pop().unwrap()];
let subnet_to_recover =
get_subnet_holding_ecdsa_keys(&[key_1.clone()], subnet_to_recover_nodes.clone());
// Here we discover the IC's subnet ID (from our test harness)
// and then modify it to hold the key and sign for it.
let mut subnet_list_record = decode_registry_value::<SubnetListRecord>(
fake_client
.get_value(
&make_subnet_list_record_key(),
fake_client.get_latest_version(),
)
.unwrap()
.unwrap(),
);
let subnet_to_recover_subnet_id = subnet_test_id(1003);
subnet_list_record
.subnets
.push(subnet_to_recover_subnet_id.get().into_vec());
let subnet_principals = subnet_list_record
.subnets
.iter()
.map(|record| PrincipalId::try_from(record).unwrap())
.collect::<Vec<_>>();
let system_subnet_principal = subnet_principals.get(0).unwrap();
let system_subnet_id = SubnetId::new(*system_subnet_principal);
let mut subnet_record = decode_registry_value::<SubnetRecord>(
fake_client
.get_value(
&make_subnet_record_key(system_subnet_id),
fake_client.get_latest_version(),
)
.unwrap()
.unwrap(),
);
subnet_record.ecdsa_config = Some(EcdsaConfig {
quadruples_to_create_in_advance: 1,
key_ids: vec![(&key_1).into()],
max_queue_size: DEFAULT_ECDSA_MAX_QUEUE_SIZE,
signature_request_timeout_ns: None,
idkg_key_rotation_period_ms: None,
});
let modify_base_subnet_mutate = RegistryAtomicMutateRequest {
mutations: vec![upsert(
make_subnet_record_key(system_subnet_id),
encode_or_panic(&subnet_record),
)],
preconditions: vec![],
};
// Add the subnet we are recovering holding requested keys
// Note, because these mutations are also synced with underlying IC registry, they
// need a CUP
let mutations = vec![
upsert(
make_subnet_record_key(subnet_to_recover_subnet_id).into_bytes(),
encode_or_panic(&subnet_to_recover),
),
upsert(
make_subnet_list_record_key().into_bytes(),
encode_or_panic(&subnet_list_record),
),
insert(
make_crypto_threshold_signing_pubkey_key(subnet_to_recover_subnet_id).as_bytes(),
encode_or_panic(&vec![]),
),
insert(
make_catch_up_package_contents_key(subnet_to_recover_subnet_id).as_bytes(),
encode_or_panic(&dummy_cup_for_subnet(subnet_to_recover_nodes)),
),
];
let add_subnets_mutate = RegistryAtomicMutateRequest {
preconditions: vec![],
mutations,
};
// Enable signing with the recovering subnet - we will later check that
// this subnet is removed from the signing subnet list.
let ecdsa_signing_subnets_mutate = RegistryAtomicMutateRequest {
preconditions: vec![],
mutations: vec![insert(
make_ecdsa_signing_subnet_list_key(&key_1),
encode_or_panic(&EcdsaSigningSubnetList {
subnets: vec![subnet_id_into_protobuf(subnet_to_recover_subnet_id)],
}),
)],
};
let registry = setup_registry_synced_with_fake_client(
&runtime,
fake_client,
data_provider,
vec![
init_mutate,
add_subnets_mutate,
modify_base_subnet_mutate,
ecdsa_signing_subnets_mutate,
],
)
.await;
// Then we need to ensure the CUP for our subnet under test
// does not contain the ecdsa_initializations, since we will be asserting those were added
let before_recover_cup_contents =
get_cup_contents(®istry, subnet_to_recover_subnet_id).await;
assert_eq!(before_recover_cup_contents.ecdsa_initializations.len(), 0);
// Install the universal canister in place of the governance canister
let fake_governance_canister = set_up_universal_canister_as_governance(&runtime).await;
let signature_request_timeout_ns = Some(12345);
let idkg_key_rotation_period_ms = Some(12345);
let payload = RecoverSubnetPayload {
subnet_id: subnet_to_recover_subnet_id.get(),
height: 10,
time_ns: 1200,
state_hash: vec![10, 20, 30],
replacement_nodes: None,
registry_store_uri: None,
ecdsa_config: Some(EcdsaInitialConfig {
quadruples_to_create_in_advance: 1,
keys: vec![],
max_queue_size: Some(DEFAULT_ECDSA_MAX_QUEUE_SIZE),
signature_request_timeout_ns,
idkg_key_rotation_period_ms,
}),
};
// When we recover a subnet with specified ecdsa_keys
try_call_via_universal_canister(
&fake_governance_canister,
®istry,
"recover_subnet",
Encode!(&payload).unwrap(),
)
.await
.unwrap();
let cup_contents = get_cup_contents(®istry, subnet_to_recover_subnet_id).await;
// Check EcdsaInitializations
let dealings = &cup_contents.ecdsa_initializations;
assert_eq!(dealings.len(), 0);
// Check EcdsaConfig is correctly updated
let subnet_record = get_subnet_record(®istry, subnet_to_recover_subnet_id).await;
let ecdsa_config = subnet_record.ecdsa_config.unwrap();
assert_eq!(ecdsa_config.max_queue_size, DEFAULT_ECDSA_MAX_QUEUE_SIZE);
assert_eq!(
ecdsa_config.signature_request_timeout_ns,
signature_request_timeout_ns
);
assert_eq!(
ecdsa_config.idkg_key_rotation_period_ms,
idkg_key_rotation_period_ms
);
let key_ids = ecdsa_config.key_ids;
assert_eq!(key_ids.len(), 0);
// Check ecdsa_signing_subnets_list for key_1 is empty now.
let ecdsa_signing_subnet_list = ecdsa_signing_subnet_list(®istry, &key_1).await;
assert_eq!(
ecdsa_signing_subnet_list,
EcdsaSigningSubnetList { subnets: vec![] }
)
});
}
#[test]
fn test_recover_subnet_resets_the_halt_at_cup_height_flag() {
let ic_config = get_ic_config();
let (config, _tmpdir) = Config::temp_config();
canister_test_with_config_async(config, ic_config, |local_runtime| async move {
let data_provider = local_runtime.registry_data_provider.clone();
let fake_client = local_runtime.registry_client.clone();
let runtime = Runtime::Local(local_runtime);
// get some nodes for our tests
let (init_mutate, mut node_ids) = prepare_registry_with_nodes(5, 0);
let subnet_to_recover_nodes = vec![node_ids.pop().unwrap()];
let mut subnet_to_recover: SubnetRecord = CreateSubnetPayload {
unit_delay_millis: 10,
gossip_retransmission_request_ms: 10_000,
gossip_registry_poll_period_ms: 2000,
gossip_pfn_evaluation_period_ms: 50,
gossip_receive_check_cache_size: 1,
gossip_max_duplicity: 1,
gossip_max_chunk_wait_ms: 200,
gossip_max_artifact_streams_per_peer: 1,
replica_version_id: ReplicaVersion::default().into(),
node_ids: subnet_to_recover_nodes.clone(),
..Default::default()
}
.into();
// Set the `halt_at_cup_height` to `true`, to verify that it will be later set to `false`.
subnet_to_recover.halt_at_cup_height = true;
subnet_to_recover.is_halted = false;
let mut subnet_list_record = decode_registry_value::<SubnetListRecord>(
fake_client
.get_value(
&make_subnet_list_record_key(),
fake_client.get_latest_version(),
)
.unwrap()
.unwrap(),
);
let subnet_to_recover_subnet_id = subnet_test_id(1003);
subnet_list_record
.subnets
.push(subnet_to_recover_subnet_id.get().into_vec());
let mutations = vec![
upsert(
make_subnet_record_key(subnet_to_recover_subnet_id).into_bytes(),
encode_or_panic(&subnet_to_recover),
),
upsert(
make_subnet_list_record_key().into_bytes(),
encode_or_panic(&subnet_list_record),
),
insert(
make_crypto_threshold_signing_pubkey_key(subnet_to_recover_subnet_id).as_bytes(),
encode_or_panic(&vec![]),
),
insert(
make_catch_up_package_contents_key(subnet_to_recover_subnet_id).as_bytes(),
encode_or_panic(&dummy_cup_for_subnet(subnet_to_recover_nodes)),
),
];
let add_subnets_mutate = RegistryAtomicMutateRequest {
preconditions: vec![],
mutations,
};
let registry = setup_registry_synced_with_fake_client(
&runtime,
fake_client,
data_provider,
vec![init_mutate, add_subnets_mutate],
)
.await;
// Install the universal canister in place of the governance canister
let fake_governance_canister = set_up_universal_canister_as_governance(&runtime).await;
let payload = RecoverSubnetPayload {
subnet_id: subnet_to_recover_subnet_id.get(),
height: 10,
time_ns: 1200,
state_hash: vec![10, 20, 30],
replacement_nodes: None,
registry_store_uri: None,
ecdsa_config: None,
};
try_call_via_universal_canister(
&fake_governance_canister,
®istry,
"recover_subnet",
Encode!(&payload).unwrap(),
)
.await
.unwrap();
// Verify that the `halt_at_cup_height` and `is_halted` flags are correctly set.
let subnet_record = get_subnet_record(®istry, subnet_to_recover_subnet_id).await;
assert!(!subnet_record.halt_at_cup_height);
assert!(subnet_record.is_halted);
});
}
pub async fn ecdsa_signing_subnet_list(
registry: &Canister<'_>,
key_id: &EcdsaKeyId,
) -> EcdsaSigningSubnetList {
get_value_or_panic::<EcdsaSigningSubnetList>(
registry,
make_ecdsa_signing_subnet_list_key(key_id).as_bytes(),
)
.await
}