Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
28 changes: 26 additions & 2 deletions rs/registry/canister/src/invariants/crypto/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ mod chain_key_enabled_subnet_lists {
#[should_panic(
expected = "Missing required struct field: KeyConfig::pre_signatures_to_create_in_advance"
)]
fn should_fail_if_missing_pre_signatures() {
fn should_fail_if_missing_pre_signatures_for_key_that_requires_pre_signatures() {
let mut config = invariant_compliant_chain_key_config();
config.key_configs[1].pre_signatures_to_create_in_advance = None;
check_chain_key_config_invariant(config);
Expand All @@ -692,12 +692,36 @@ mod chain_key_enabled_subnet_lists {
#[should_panic(
expected = "`pre_signatures_to_create_in_advance` for key ecdsa:Secp256k1:ecdsa_key of subnet ya35z-hhham-aaaaa-aaaap-yai cannot be zero."
)]
fn should_fail_if_pre_signatures_is_zero() {
fn should_fail_if_pre_signatures_is_zero_for_key_that_requires_pre_signatures() {
let mut config = invariant_compliant_chain_key_config();
config.key_configs[0].pre_signatures_to_create_in_advance = Some(0);
check_chain_key_config_invariant(config);
}

#[test]
fn should_succeed_if_pre_signatures_is_missing_for_key_that_does_not_require_pre_signatures() {
Comment thread
daniel-wong-dfinity-org marked this conversation as resolved.
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 = None;
check_chain_key_config_invariant(config);
}

#[test]
fn should_succeed_if_pre_signatures_is_zero_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);
check_chain_key_config_invariant(config);
}

#[test]
#[should_panic(expected = "Missing required struct field: KeyConfig::max_queue_size")]
fn should_fail_if_missing_queue_size() {
Expand Down
12 changes: 5 additions & 7 deletions rs/registry/canister/src/mutations/do_create_subnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,20 +413,18 @@ impl TryFrom<KeyConfig> for KeyConfigInternal {
let Some(key_id) = key_id else {
return Err("KeyConfig.key_id must be specified.".to_string());
};

let Some(pre_signatures_to_create_in_advance) = pre_signatures_to_create_in_advance else {
return Err(
"KeyConfig.pre_signatures_to_create_in_advance must be specified.".to_string(),
);
if key_id.requires_pre_signatures() && pre_signatures_to_create_in_advance.is_none() {
return Err(format!(
"KeyConfig.pre_signatures_to_create_in_advance must be specified for key {key_id}."
));
};

Comment thread
daniel-wong-dfinity-org marked this conversation as resolved.
let Some(max_queue_size) = max_queue_size else {
return Err("KeyConfig.max_queue_size must be specified.".to_string());
};

Ok(Self {
key_id,
pre_signatures_to_create_in_advance,
pre_signatures_to_create_in_advance: pre_signatures_to_create_in_advance.unwrap_or(0),
max_queue_size,
})
}
Expand Down
12 changes: 5 additions & 7 deletions rs/registry/canister/src/mutations/do_recover_subnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,20 +377,18 @@ impl TryFrom<KeyConfig> for KeyConfigInternal {
let Some(key_id) = key_id else {
return Err("KeyConfig.key_id must be specified.".to_string());
};

let Some(pre_signatures_to_create_in_advance) = pre_signatures_to_create_in_advance else {
return Err(
"KeyConfig.pre_signatures_to_create_in_advance must be specified.".to_string(),
);
if key_id.requires_pre_signatures() && pre_signatures_to_create_in_advance.is_none() {
return Err(format!(
"KeyConfig.pre_signatures_to_create_in_advance must be specified for key {key_id}."
));
};

Comment thread
daniel-wong-dfinity-org marked this conversation as resolved.
let Some(max_queue_size) = max_queue_size else {
return Err("KeyConfig.max_queue_size must be specified.".to_string());
};

Ok(Self {
key_id,
pre_signatures_to_create_in_advance,
pre_signatures_to_create_in_advance: pre_signatures_to_create_in_advance.unwrap_or(0),
max_queue_size,
})
}
Expand Down
10 changes: 5 additions & 5 deletions rs/registry/canister/src/mutations/do_update_subnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,18 +368,18 @@ impl TryFrom<KeyConfig> for KeyConfigInternal {
let Some(key_id) = key_id else {
return Err("KeyConfig.key_id must be specified.".to_string());
};
let Some(pre_signatures_to_create_in_advance) = pre_signatures_to_create_in_advance else {
return Err(
"KeyConfig.pre_signatures_to_create_in_advance must be specified.".to_string(),
);
if key_id.requires_pre_signatures() && pre_signatures_to_create_in_advance.is_none() {
return Err(format!(
"KeyConfig.pre_signatures_to_create_in_advance must be specified for key {key_id}."
));
};
let Some(max_queue_size) = max_queue_size else {
return Err("KeyConfig.max_queue_size must be specified.".to_string());
};

Ok(Self {
key_id,
pre_signatures_to_create_in_advance,
pre_signatures_to_create_in_advance: pre_signatures_to_create_in_advance.unwrap_or(0),
max_queue_size,
})
}
Expand Down
15 changes: 10 additions & 5 deletions rs/registry/subnet_features/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,17 @@ impl TryFrom<pb::KeyConfig> for KeyConfig {
type Error = ProxyDecodeError;

fn try_from(value: pb::KeyConfig) -> Result<Self, Self::Error> {
Ok(KeyConfig {
pre_signatures_to_create_in_advance: try_from_option_field(
value.pre_signatures_to_create_in_advance,
let key_id: MasterPublicKeyId = try_from_option_field(value.key_id, "KeyConfig::key_id")?;
if key_id.requires_pre_signatures() && value.pre_signatures_to_create_in_advance.is_none() {
return Err(ProxyDecodeError::MissingField(
"KeyConfig::pre_signatures_to_create_in_advance",
)?,
key_id: try_from_option_field(value.key_id, "KeyConfig::key_id")?,
));
}
Ok(KeyConfig {
pre_signatures_to_create_in_advance: value
.pre_signatures_to_create_in_advance
.unwrap_or(0),
key_id,
max_queue_size: try_from_option_field(
value.max_queue_size,
"KeyConfig::max_queue_size",
Expand Down