-
Notifications
You must be signed in to change notification settings - Fork 381
chore: add support for sev-enabled subnets in the registry #9038
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 5 commits
8d250c8
9570db8
7589699
b54a7e7
b0fce43
ee1fe09
b95586b
93751f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,9 @@ use crate::invariants::common::RegistrySnapshot; | |
| use ic_base_types::SubnetId; | ||
| use ic_protobuf::registry::{ | ||
| node::v1::NodeRecord, | ||
| subnet::v1::{CanisterCyclesCostSchedule, SubnetListRecord, SubnetRecord, SubnetType}, | ||
| subnet::v1::{ | ||
| CanisterCyclesCostSchedule, SubnetFeatures, SubnetListRecord, SubnetRecord, SubnetType, | ||
| }, | ||
| }; | ||
| use ic_registry_keys::{make_subnet_list_record_key, make_subnet_record_key}; | ||
| use ic_test_utilities_types::ids::{node_test_id, subnet_test_id}; | ||
|
|
@@ -17,6 +19,8 @@ fn only_application_subnets_can_be_free_cycles_cost_schedule() { | |
| setup_minimal_registry_snapshot_for_check_subnet_invariants( | ||
| system_subnet_id, | ||
| test_subnet_id, | ||
| 1, | ||
| false, | ||
r-birkner marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ); | ||
|
|
||
| // Trivial case. (Never forget the trivial case, because this is an edge | ||
|
|
@@ -54,9 +58,100 @@ fn only_application_subnets_can_be_free_cycles_cost_schedule() { | |
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn only_sev_enabled_subnets_consist_of_sev_enabled_nodes() { | ||
r-birkner marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
r-birkner marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| let system_subnet_id = subnet_test_id(1); | ||
| let test_subnet_id = subnet_test_id(2); | ||
| let test_node_id = node_test_id(103); | ||
|
|
||
| // get a snapshot without chip IDs | ||
| let (mut snapshot, mut test_subnet_record) = | ||
| setup_minimal_registry_snapshot_for_check_subnet_invariants( | ||
| system_subnet_id, | ||
| test_subnet_id, | ||
| 4, | ||
| false, | ||
| ); | ||
|
|
||
| // a non SEV-enabled subnet only with nodes without chip ID is compliant | ||
| check_subnet_invariants(&snapshot).unwrap(); | ||
|
|
||
| // a non SEV-enabled subnet with some nodes with and some without chip IDs is compliant | ||
| let test_node_record = NodeRecord { | ||
| chip_id: Some("a chip id".into()), | ||
| ..Default::default() | ||
| }; | ||
| snapshot.insert( | ||
| make_node_record_key(test_node_id).into_bytes(), | ||
| test_node_record.encode_to_vec(), | ||
| ); | ||
| check_subnet_invariants(&snapshot).unwrap(); | ||
|
|
||
| // an SEV-enabled subnet only with nodes without chip ID is NOT compliant | ||
| test_subnet_record.features = Some(SubnetFeatures { | ||
| sev_enabled: Some(true), | ||
| ..Default::default() | ||
| }); | ||
| snapshot.insert( | ||
| make_subnet_record_key(test_subnet_id).into_bytes(), | ||
| test_subnet_record.encode_to_vec(), | ||
| ); | ||
| let test_node_record = NodeRecord { | ||
| chip_id: None, | ||
| ..Default::default() | ||
| }; | ||
| snapshot.insert( | ||
| make_node_record_key(test_node_id).into_bytes(), | ||
| test_node_record.encode_to_vec(), | ||
| ); | ||
| assert_non_compliant_record( | ||
| &snapshot, | ||
| "subnet fbysm-3acaa-aaaaa-aaaap-yai is sev-enabled but at least one of its nodes is not", | ||
r-birkner marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ); | ||
|
|
||
| // get a snapshot with chip IDs | ||
| let (mut snapshot, mut test_subnet_record) = | ||
| setup_minimal_registry_snapshot_for_check_subnet_invariants( | ||
| system_subnet_id, | ||
| test_subnet_id, | ||
| 4, | ||
| true, | ||
| ); | ||
|
|
||
| // a non SEV-enabled subnet only with nodes without chip ID is compliant | ||
| check_subnet_invariants(&snapshot).unwrap(); | ||
|
|
||
| // an SEV-enabled subnet only with nodes with chip ID is compliant | ||
| test_subnet_record.features = Some(SubnetFeatures { | ||
| sev_enabled: Some(true), | ||
| ..Default::default() | ||
| }); | ||
| snapshot.insert( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The name |
||
| make_subnet_record_key(test_subnet_id).into_bytes(), | ||
| test_subnet_record.encode_to_vec(), | ||
| ); | ||
| check_subnet_invariants(&snapshot).unwrap(); | ||
|
|
||
| // an SEV-enabled subnet with some nodes with and some without chip ID is NOT compliant | ||
| let test_node_record = NodeRecord { | ||
| chip_id: None, | ||
| ..Default::default() | ||
| }; | ||
| snapshot.insert( | ||
| make_node_record_key(test_node_id).into_bytes(), | ||
| test_node_record.encode_to_vec(), | ||
| ); | ||
| assert_non_compliant_record( | ||
| &snapshot, | ||
| "subnet fbysm-3acaa-aaaaa-aaaap-yai is sev-enabled but at least one of its nodes is not", | ||
| ); | ||
| } | ||
|
|
||
| fn setup_minimal_registry_snapshot_for_check_subnet_invariants( | ||
| system_subnet_id: SubnetId, | ||
| test_subnet_id: SubnetId, | ||
| num_nodes_in_test_subnet: usize, | ||
| with_chip_id: bool, | ||
| ) -> (RegistrySnapshot, SubnetRecord) { | ||
| let mut snapshot = RegistrySnapshot::new(); | ||
|
|
||
|
|
@@ -84,11 +179,18 @@ fn setup_minimal_registry_snapshot_for_check_subnet_invariants( | |
| ); | ||
|
|
||
| // Add a test subnet in the subnet list. | ||
| let test_node_id = node_test_id(100); | ||
| snapshot.insert( | ||
| make_node_record_key(test_node_id.to_owned()).into_bytes(), | ||
| NodeRecord::default().encode_to_vec(), | ||
| ); | ||
| for i in 0..num_nodes_in_test_subnet { | ||
| let node_id = node_test_id((i + 100) as u64); | ||
| let mut node_record = NodeRecord::default(); | ||
| if with_chip_id { | ||
| node_record.chip_id = Some(format!("chip-id-{i}").into_bytes()); | ||
| } | ||
| snapshot.insert( | ||
| make_node_record_key(node_id.to_owned()).into_bytes(), | ||
| node_record.encode_to_vec(), | ||
| ); | ||
| } | ||
|
|
||
| let subnet_list_record = SubnetListRecord { | ||
| subnets: vec![ | ||
| system_subnet_id.get().into_vec(), | ||
|
|
@@ -99,8 +201,12 @@ fn setup_minimal_registry_snapshot_for_check_subnet_invariants( | |
| make_subnet_list_record_key().into_bytes(), | ||
| subnet_list_record.encode_to_vec(), | ||
| ); | ||
| let membership = (0..num_nodes_in_test_subnet) | ||
| .map(|i| node_test_id((i + 100) as u64).get().to_vec()) | ||
| .collect(); | ||
|
|
||
| let test_subnet_record = SubnetRecord { | ||
| membership: vec![test_node_id.get().to_vec()], | ||
| membership, | ||
| ..Default::default() | ||
| }; | ||
| snapshot.insert( | ||
|
|
@@ -116,5 +222,6 @@ fn assert_non_compliant_record(snapshot: &RegistrySnapshot, error_msg: &str) { | |
| panic!("Expected Err, but got Ok!"); | ||
| }; | ||
| let message = err.msg.to_lowercase(); | ||
| println!("Error message: {message}"); | ||
| assert!(message.contains(error_msg)); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.