Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 15 additions & 20 deletions rs/consensus/idkg/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,6 @@ pub fn get_idkg_chain_key_config_if_enabled(
.iter()
// Skip keys that don't need to run IDKG protocol
.filter(|key_config| key_config.key_id.is_idkg_key())
// A key that has `presignatures_to_create_in_advance` set to 0 is not active
.filter(|key_config| {
key_config
.pre_signatures_to_create_in_advance
.unwrap_or_default()
!= 0
})
.count();

if num_active_key_ids == 0 {
Expand Down Expand Up @@ -807,11 +800,11 @@ mod tests {
let (subnet_id, registry, version) =
set_up_get_chain_key_config_test(&malformed_chain_key_config, pool_config);

let config =
get_idkg_chain_key_config_if_enabled(subnet_id, version, registry.as_ref())
.expect("Should successfully get the config");

assert!(config.is_none());
let result =
get_idkg_chain_key_config_if_enabled(subnet_id, version, registry.as_ref());
assert_matches!(result, Err(RegistryClientError::DecodeError { error })
if error.contains("KeyConfig::pre_signatures_to_create_in_advance")
&& error.contains("should be non-zero"));
})
}

Expand All @@ -836,10 +829,8 @@ mod tests {
get_idkg_chain_key_config_if_enabled(subnet_id, version, registry.as_ref());

assert_matches!(result, Err(RegistryClientError::DecodeError{ error })
if error.contains("\
failed with Missing required struct field: \
KeyConfig::pre_signatures_to_create_in_advance\
")
if error.contains("KeyConfig::pre_signatures_to_create_in_advance")
&& error.contains("should be non-zero")
);
})
}
Expand All @@ -861,10 +852,12 @@ mod tests {
let (subnet_id, registry, version) =
set_up_get_chain_key_config_test(&malformed_chain_key_config, pool_config);

let config =
let result =
get_idkg_chain_key_config_if_enabled(subnet_id, version, registry.as_ref());

assert_matches!(config, Ok(None));
assert_matches!(result, Err(RegistryClientError::DecodeError { error })
if error.contains("KeyConfig::pre_signatures_to_create_in_advance")
&& error.contains("should be None"));
})
}

Expand All @@ -885,10 +878,12 @@ mod tests {
let (subnet_id, registry, version) =
set_up_get_chain_key_config_test(&malformed_chain_key_config, pool_config);

let config =
let result =
get_idkg_chain_key_config_if_enabled(subnet_id, version, registry.as_ref());

assert_matches!(config, Ok(None));
assert_matches!(result, Err(RegistryClientError::DecodeError { error })
if error.contains("KeyConfig::pre_signatures_to_create_in_advance")
&& error.contains("should be None"));
})
}

Expand Down
40 changes: 20 additions & 20 deletions rs/registry/canister/canbench/canbench_results.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,129 +2,129 @@ benches:
get_subnet_for_canister_100_times_100:
total:
calls: 1
instructions: 31025759
instructions: 31018983
heap_increase: 0
stable_memory_increase: 0
scopes: {}
get_subnet_for_canister_100_times_10k:
total:
calls: 1
instructions: 694110012
instructions: 702761588
heap_increase: 0
stable_memory_increase: 0
scopes: {}
get_subnet_for_canister_100_times_1k:
total:
calls: 1
instructions: 90967747
instructions: 91772955
heap_increase: 0
stable_memory_increase: 0
scopes: {}
measure_routing_table_invariant_checks_shards_and_unsharded:
total:
calls: 1
instructions: 268353620
instructions: 266793620
heap_increase: 138
stable_memory_increase: 0
scopes: {}
measure_snapshot_creation_with_1000_individual_entries:
total:
calls: 1
instructions: 20682683
instructions: 20682680
heap_increase: 2
stable_memory_increase: 0
scopes: {}
measure_snapshot_creation_with_100_000_individual_entries:
total:
calls: 1
instructions: 3581447942
instructions: 3581447939
heap_increase: 177
stable_memory_increase: 0
scopes: {}
measure_snapshot_creation_with_100_segments_of_1000_entries:
total:
calls: 1
instructions: 6435427
instructions: 6435424
heap_increase: 30
stable_memory_increase: 0
scopes: {}
measure_snapshot_creation_with_1_segment_of_1000_entries:
total:
calls: 1
instructions: 53955
instructions: 53952
heap_increase: 0
stable_memory_increase: 0
scopes: {}
migrate_canisters_10_times_100:
total:
calls: 1
instructions: 156361795
instructions: 153037656
heap_increase: 0
stable_memory_increase: 0
scopes: {}
migrate_canisters_10_times_10k:
total:
calls: 1
instructions: 10367776782
instructions: 10274465354
heap_increase: 0
stable_memory_increase: 0
scopes: {}
migrate_canisters_10_times_1k:
total:
calls: 1
instructions: 1032517212
instructions: 1021342939
heap_increase: 3
stable_memory_increase: 0
scopes: {}
upgrade_with_routing_table_100:
total:
calls: 1
instructions: 186143660
instructions: 185869684
heap_increase: 7
stable_memory_increase: 0
scopes:
post_upgrade:
calls: 1
instructions: 185263063
instructions: 184987710
heap_increase: 4
stable_memory_increase: 0
pre_upgrade:
calls: 1
instructions: 669662
instructions: 671039
heap_increase: 3
stable_memory_increase: 0
upgrade_with_routing_table_10k:
total:
calls: 1
instructions: 5626018276
instructions: 5619485071
heap_increase: 342
stable_memory_increase: 0
scopes:
post_upgrade:
calls: 1
instructions: 5603899441
instructions: 5597365201
heap_increase: 217
stable_memory_increase: 0
pre_upgrade:
calls: 1
instructions: 16603376
instructions: 16604363
heap_increase: 125
stable_memory_increase: 0
upgrade_with_routing_table_1k:
total:
calls: 1
instructions: 686509309
instructions: 685664368
heap_increase: 40
stable_memory_increase: 0
scopes:
post_upgrade:
calls: 1
instructions: 683633916
instructions: 682787584
heap_increase: 25
stable_memory_increase: 0
pre_upgrade:
calls: 1
instructions: 2201525
instructions: 2202916
heap_increase: 15
stable_memory_increase: 0
version: 0.4.1
11 changes: 10 additions & 1 deletion rs/registry/canister/src/invariants/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,23 @@ fn check_chain_key_configs(snapshot: &RegistrySnapshot) -> Result<(), InvariantC
for key_config in chain_key_config.key_configs {
let key_id = key_config.key_id.clone();
let pre_sigs = key_config.pre_signatures_to_create_in_advance;
if key_id.requires_pre_signatures() && (pre_sigs.is_none() || pre_sigs == Some(0)) {
let requires_pre_signatures = key_id.requires_pre_signatures();
if requires_pre_signatures && (pre_sigs.is_none() || pre_sigs == Some(0)) {
return Err(InvariantCheckError {
msg: format!(
"pre_signatures_to_create_in_advance for key {key_id} of subnet {subnet_id:} must be non-zero",
),
source: None,
});
}
if !requires_pre_signatures && pre_sigs.is_some() {
return Err(InvariantCheckError {
msg: format!(
"pre_signatures_to_create_in_advance for key {key_id} of subnet {subnet_id:} must be None",
),
source: None,
});
}
if !key_ids.insert(key_id) {
return Err(InvariantCheckError {
msg: format!(
Expand Down
11 changes: 7 additions & 4 deletions rs/registry/canister/src/invariants/crypto/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ mod chain_key_enabled_subnet_lists {

#[test]
#[should_panic(
expected = "Missing required struct field: KeyConfig::pre_signatures_to_create_in_advance"
expected = "KeyConfig::pre_signatures_to_create_in_advance for key schnorr:Bip340Secp256k1:schnorr_key should be non-zero"
)]
fn should_fail_if_missing_pre_signatures_for_key_that_requires_pre_signatures() {
let mut config = invariant_compliant_chain_key_config();
Expand All @@ -688,7 +688,7 @@ mod chain_key_enabled_subnet_lists {

#[test]
#[should_panic(
expected = "pre_signatures_to_create_in_advance for key ecdsa:Secp256k1:ecdsa_key of subnet ya35z-hhham-aaaaa-aaaap-yai must be non-zero"
expected = "KeyConfig::pre_signatures_to_create_in_advance for key ecdsa:Secp256k1:ecdsa_key should be non-zero"
)]
fn should_fail_if_pre_signatures_is_zero_for_key_that_requires_pre_signatures() {
let mut config = invariant_compliant_chain_key_config();
Expand All @@ -709,14 +709,17 @@ mod chain_key_enabled_subnet_lists {
}

#[test]
fn should_succeed_if_pre_signatures_is_zero_for_key_that_does_not_require_pre_signatures() {
#[should_panic(
expected = "KeyConfig::pre_signatures_to_create_in_advance for key vetkd:Bls12_381_G2:vetkd_key should be None, but got Some(1)."
)]
fn should_fail_if_pre_signatures_is_set_for_key_that_does_not_require_pre_signatures() {
let mut config = invariant_compliant_chain_key_config();
let key_config = &mut config.key_configs[2];
assert!(matches!(
key_config.key_id.as_ref().unwrap().key_id,
Some(master_public_key_id::KeyId::Vetkd(_))
),);
key_config.pre_signatures_to_create_in_advance = Some(0);
key_config.pre_signatures_to_create_in_advance = Some(1);
check_chain_key_config_invariant(config);
}

Expand Down
Loading
Loading