diff --git a/rs/consensus/dkg/src/lib.rs b/rs/consensus/dkg/src/lib.rs index 35cca65960f6..f307e652278d 100644 --- a/rs/consensus/dkg/src/lib.rs +++ b/rs/consensus/dkg/src/lib.rs @@ -1625,7 +1625,7 @@ mod tests { .with_chain_key_config(ChainKeyConfig { key_configs: vec![KeyConfig { key_id: MasterPublicKeyId::VetKd(key_id.clone()), - pre_signatures_to_create_in_advance: 0, + pre_signatures_to_create_in_advance: None, max_queue_size: 20, }], signature_request_timeout_ns: None, @@ -2117,7 +2117,7 @@ mod tests { ChainKeyConfig { key_configs: vec![KeyConfig { key_id: MasterPublicKeyId::VetKd(test_vet_key()), - pre_signatures_to_create_in_advance: 0, + pre_signatures_to_create_in_advance: None, max_queue_size: 20, }], signature_request_timeout_ns: None, diff --git a/rs/consensus/dkg/src/utils.rs b/rs/consensus/dkg/src/utils.rs index 55f90f51b0bd..cfd51c1f23c1 100644 --- a/rs/consensus/dkg/src/utils.rs +++ b/rs/consensus/dkg/src/utils.rs @@ -191,7 +191,7 @@ mod tests { algorithm: SchnorrAlgorithm::Ed25519, name: String::from("schnorr_key_to_ignore"), }), - pre_signatures_to_create_in_advance: 50, + pre_signatures_to_create_in_advance: Some(50), max_queue_size: 50, }, KeyConfig { @@ -199,7 +199,7 @@ mod tests { curve: VetKdCurve::Bls12_381_G2, name: String::from("first_vet_kd_key"), }), - pre_signatures_to_create_in_advance: 0, + pre_signatures_to_create_in_advance: None, max_queue_size: 50, }, KeyConfig { @@ -207,7 +207,7 @@ mod tests { curve: VetKdCurve::Bls12_381_G2, name: String::from("second_vet_kd_key"), }), - pre_signatures_to_create_in_advance: 0, + pre_signatures_to_create_in_advance: None, max_queue_size: 50, }, ], diff --git a/rs/consensus/idkg/src/payload_builder.rs b/rs/consensus/idkg/src/payload_builder.rs index 9a19ed9cced3..36bcd858c6dc 100644 --- a/rs/consensus/idkg/src/payload_builder.rs +++ b/rs/consensus/idkg/src/payload_builder.rs @@ -1010,7 +1010,7 @@ mod tests { let chain_key_config = ChainKeyConfig { key_configs: vec![KeyConfig { key_id: key_id.clone().into(), - pre_signatures_to_create_in_advance: PRE_SIGNATURES_TO_CREATE_IN_ADVANCE, + pre_signatures_to_create_in_advance: Some(PRE_SIGNATURES_TO_CREATE_IN_ADVANCE), max_queue_size: 1, }], ..ChainKeyConfig::default() @@ -2355,7 +2355,7 @@ mod tests { let chain_key_config = ChainKeyConfig { key_configs: vec![KeyConfig { key_id: key_id.clone().into(), - pre_signatures_to_create_in_advance: 1, + pre_signatures_to_create_in_advance: Some(1), max_queue_size: 1, }], signature_request_timeout_ns: Some(100000), @@ -2458,7 +2458,7 @@ mod tests { let chain_key_config = ChainKeyConfig { key_configs: vec![KeyConfig { key_id: key_id.clone().into(), - pre_signatures_to_create_in_advance: 1, + pre_signatures_to_create_in_advance: Some(1), max_queue_size: 1, }], signature_request_timeout_ns: Some(100000), @@ -2617,7 +2617,7 @@ mod tests { let chain_key_config = ChainKeyConfig { key_configs: vec![KeyConfig { key_id: key_id.clone().into(), - pre_signatures_to_create_in_advance: 1, + pre_signatures_to_create_in_advance: Some(1), max_queue_size: 1, }], signature_request_timeout_ns: Some(100000), diff --git a/rs/consensus/idkg/src/payload_builder/pre_signatures.rs b/rs/consensus/idkg/src/payload_builder/pre_signatures.rs index 89bfb6d72d05..011cd93978d1 100644 --- a/rs/consensus/idkg/src/payload_builder/pre_signatures.rs +++ b/rs/consensus/idkg/src/payload_builder/pre_signatures.rs @@ -356,7 +356,11 @@ fn make_new_pre_signatures_if_needed_helper( .key_configs .iter() .find(|key_config| &key_config.key_id == key_id.inner()) - .map(|key_config| key_config.pre_signatures_to_create_in_advance as usize) + .map(|key_config| { + key_config + .pre_signatures_to_create_in_advance + .unwrap_or_default() as usize + }) else { return new_pre_signatures; }; @@ -592,7 +596,11 @@ pub(super) fn make_new_pre_signatures_by_priority( }; let max_stash_size = chain_key_config .key_config(key_id.inner()) - .map(|config| config.pre_signatures_to_create_in_advance) + .map(|config| { + config + .pre_signatures_to_create_in_advance + .unwrap_or_default() + }) .unwrap_or_default(); priority_queue.push(PrioritizedStash { count: *total_pre_signatures.get(key_id).unwrap_or(&0), @@ -1107,7 +1115,7 @@ pub(super) mod tests { .into_iter() .map(|(key_id, max)| KeyConfig { key_id: key_id.inner().clone(), - pre_signatures_to_create_in_advance: max as u32, + pre_signatures_to_create_in_advance: Some(max as u32), max_queue_size: 20, }) .collect(), @@ -1417,7 +1425,7 @@ pub(super) mod tests { let chain_key_config = ChainKeyConfig { key_configs: vec![KeyConfig { key_id: key_id.clone().into(), - pre_signatures_to_create_in_advance, + pre_signatures_to_create_in_advance: Some(pre_signatures_to_create_in_advance), max_queue_size: 1, }], ..ChainKeyConfig::default() @@ -1483,7 +1491,7 @@ pub(super) mod tests { let chain_key_config = ChainKeyConfig { key_configs: vec![KeyConfig { key_id: key_id.clone().into(), - pre_signatures_to_create_in_advance, + pre_signatures_to_create_in_advance: Some(pre_signatures_to_create_in_advance), max_queue_size: 1, }], ..ChainKeyConfig::default() diff --git a/rs/consensus/idkg/src/utils.rs b/rs/consensus/idkg/src/utils.rs index be7c0c0ed130..883c7d5e9a88 100644 --- a/rs/consensus/idkg/src/utils.rs +++ b/rs/consensus/idkg/src/utils.rs @@ -434,7 +434,12 @@ pub fn get_idkg_chain_key_config_if_enabled( // 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 != 0) + .filter(|key_config| { + key_config + .pre_signatures_to_create_in_advance + .unwrap_or_default() + != 0 + }) .count(); if num_active_key_ids == 0 { @@ -833,7 +838,7 @@ mod tests { key_id: MasterPublicKeyId::Ecdsa( EcdsaKeyId::from_str("Secp256k1:some_key").unwrap(), ), - pre_signatures_to_create_in_advance: 1, + pre_signatures_to_create_in_advance: Some(1), max_queue_size: 3, }], ..ChainKeyConfig::default() @@ -857,14 +862,14 @@ mod tests { key_id: MasterPublicKeyId::Ecdsa( EcdsaKeyId::from_str("Secp256k1:some_key_1").unwrap(), ), - pre_signatures_to_create_in_advance: 1, + pre_signatures_to_create_in_advance: Some(1), max_queue_size: 3, }; let key_config_2 = KeyConfig { key_id: MasterPublicKeyId::Schnorr( SchnorrKeyId::from_str("Ed25519:some_key_2").unwrap(), ), - pre_signatures_to_create_in_advance: 1, + pre_signatures_to_create_in_advance: Some(1), max_queue_size: 3, }; @@ -898,7 +903,7 @@ mod tests { key_id: MasterPublicKeyId::Ecdsa( EcdsaKeyId::from_str("Secp256k1:some_key").unwrap(), ), - pre_signatures_to_create_in_advance: 0, + pre_signatures_to_create_in_advance: Some(0), max_queue_size: 3, }], ..ChainKeyConfig::default() diff --git a/rs/consensus/tests/framework/mod.rs b/rs/consensus/tests/framework/mod.rs index 4341792854e8..1f7c6ac9dd86 100644 --- a/rs/consensus/tests/framework/mod.rs +++ b/rs/consensus/tests/framework/mod.rs @@ -71,11 +71,9 @@ pub fn setup_subnet( .iter() .map(|key_id| KeyConfig { key_id: key_id.clone(), - pre_signatures_to_create_in_advance: if key_id.requires_pre_signatures() { - 4 - } else { - 0 - }, + pre_signatures_to_create_in_advance: key_id + .requires_pre_signatures() + .then_some(4), max_queue_size: 40, }) .collect(), diff --git a/rs/consensus/vetkd/src/lib.rs b/rs/consensus/vetkd/src/lib.rs index 741742205e53..b933bd0a519c 100644 --- a/rs/consensus/vetkd/src/lib.rs +++ b/rs/consensus/vetkd/src/lib.rs @@ -1060,7 +1060,7 @@ mod tests { key_id: MasterPublicKeyId::VetKd( VetKdKeyId::from_str("bls12_381_g2:unused_key").unwrap(), ), - pre_signatures_to_create_in_advance: 0, + pre_signatures_to_create_in_advance: None, max_queue_size: 3, }], ..ChainKeyConfig::default() diff --git a/rs/consensus/vetkd/src/test_utils.rs b/rs/consensus/vetkd/src/test_utils.rs index 5bac0ea0612b..2563200769fd 100644 --- a/rs/consensus/vetkd/src/test_utils.rs +++ b/rs/consensus/vetkd/src/test_utils.rs @@ -82,19 +82,19 @@ pub(super) fn as_past_payload(payload: &[u8]) -> PastPayload<'_> { pub(super) fn make_chain_key_config() -> ChainKeyConfig { let key_config = KeyConfig { key_id: MasterPublicKeyId::Ecdsa(EcdsaKeyId::from_str("Secp256k1:some_key_1").unwrap()), - pre_signatures_to_create_in_advance: 1, + pre_signatures_to_create_in_advance: Some(1), max_queue_size: 3, }; let key_config_1 = KeyConfig { key_id: MasterPublicKeyId::VetKd(VetKdKeyId::from_str("bls12_381_g2:some_key").unwrap()), - pre_signatures_to_create_in_advance: 0, + pre_signatures_to_create_in_advance: None, max_queue_size: 3, }; let key_config_2 = KeyConfig { key_id: MasterPublicKeyId::VetKd( VetKdKeyId::from_str("bls12_381_g2:some_other_key").unwrap(), ), - pre_signatures_to_create_in_advance: 0, + pre_signatures_to_create_in_advance: None, max_queue_size: 3, }; diff --git a/rs/execution_environment/src/scheduler/test_utilities.rs b/rs/execution_environment/src/scheduler/test_utilities.rs index 192ded8b2ecd..ff2553dd04b2 100644 --- a/rs/execution_environment/src/scheduler/test_utilities.rs +++ b/rs/execution_environment/src/scheduler/test_utilities.rs @@ -868,7 +868,9 @@ impl SchedulerTestBuilder { key_id.clone(), ChainKeySettings { max_queue_size: 20, - pre_signatures_to_create_in_advance: 5, + pre_signatures_to_create_in_advance: key_id + .requires_pre_signatures() + .then_some(5), }, ); } diff --git a/rs/execution_environment/src/scheduler/threshold_signatures.rs b/rs/execution_environment/src/scheduler/threshold_signatures.rs index 4676b9b5e5a4..40bc787db093 100644 --- a/rs/execution_environment/src/scheduler/threshold_signatures.rs +++ b/rs/execution_environment/src/scheduler/threshold_signatures.rs @@ -85,7 +85,11 @@ pub(crate) fn update_signature_request_contexts( let max_stash_size = registry_settings .chain_key_settings .get(&key_id) - .map(|setting| setting.pre_signatures_to_create_in_advance) + .map(|setting| { + setting + .pre_signatures_to_create_in_advance + .unwrap_or_default() + }) .unwrap_or_default() as usize; let exceeding = stash.pre_signatures.len().saturating_sub(max_stash_size); if exceeding > 0 { @@ -127,7 +131,11 @@ pub(crate) fn update_signature_request_contexts( let max_ongoing_signatures = registry_settings .chain_key_settings .get(&key_id) - .map(|setting| setting.pre_signatures_to_create_in_advance) + .map(|setting| { + setting + .pre_signatures_to_create_in_advance + .unwrap_or_default() + }) .unwrap_or_default() as usize; match_delivered_pre_signatures_by_key_id( @@ -633,7 +641,9 @@ mod tests { .map(|key_id| { let settings = ChainKeySettings { max_queue_size: 20, - pre_signatures_to_create_in_advance: max_stash_size, + pre_signatures_to_create_in_advance: key_id + .requires_pre_signatures() + .then_some(max_stash_size), }; (key_id.inner().clone(), settings) }) diff --git a/rs/interfaces/src/execution_environment.rs b/rs/interfaces/src/execution_environment.rs index 592d398eb7d9..d6b1ed5e4446 100644 --- a/rs/interfaces/src/execution_environment.rs +++ b/rs/interfaces/src/execution_environment.rs @@ -1462,7 +1462,7 @@ pub struct RegistryExecutionSettings { #[derive(Clone, Eq, PartialEq, Debug)] pub struct ChainKeySettings { pub max_queue_size: u32, - pub pre_signatures_to_create_in_advance: u32, + pub pre_signatures_to_create_in_advance: Option, } pub trait Scheduler: Send { diff --git a/rs/messaging/src/message_routing/tests.rs b/rs/messaging/src/message_routing/tests.rs index 512f29ed79c6..3be7bbc4ee1f 100644 --- a/rs/messaging/src/message_routing/tests.rs +++ b/rs/messaging/src/message_routing/tests.rs @@ -734,7 +734,7 @@ fn try_read_registry_succeeds_with_fully_specified_registry_records() { curve: EcdsaCurve::Secp256k1, name: "ecdsa key 1".to_string(), }), - pre_signatures_to_create_in_advance: 891, + pre_signatures_to_create_in_advance: Some(891), max_queue_size: 891, }, KeyConfig { @@ -742,7 +742,7 @@ fn try_read_registry_succeeds_with_fully_specified_registry_records() { curve: EcdsaCurve::Secp256k1, name: "ecdsa key 2".to_string(), }), - pre_signatures_to_create_in_advance: 891, + pre_signatures_to_create_in_advance: Some(891), max_queue_size: 891, }, ], @@ -1701,7 +1701,7 @@ fn process_batch_updates_subnet_metrics() { name: "ecdsa key 1".to_string(), }), max_queue_size: 891, - pre_signatures_to_create_in_advance: 891, + pre_signatures_to_create_in_advance: Some(891), }, KeyConfig { key_id: MasterPublicKeyId::Ecdsa(EcdsaKeyId { @@ -1709,7 +1709,7 @@ fn process_batch_updates_subnet_metrics() { name: "ecdsa key 2".to_string(), }), max_queue_size: 891, - pre_signatures_to_create_in_advance: 891, + pre_signatures_to_create_in_advance: Some(891), }, ], ..Default::default() diff --git a/rs/recovery/src/admin_helper.rs b/rs/recovery/src/admin_helper.rs index 8ef0a31352c5..0012df9edcf1 100644 --- a/rs/recovery/src/admin_helper.rs +++ b/rs/recovery/src/admin_helper.rs @@ -182,9 +182,17 @@ impl AdminHelper { .map(|key_config| KeyConfigRequest { subnet_id, key_id: key_config.key_id.to_string(), - pre_signatures_to_create_in_advance: key_config - .pre_signatures_to_create_in_advance - .to_string(), + pre_signatures_to_create_in_advance: if key_config + .key_id + .requires_pre_signatures() + { + key_config + .pre_signatures_to_create_in_advance + .unwrap_or_default() + .to_string() + } else { + "".to_string() + }, max_queue_size: key_config.max_queue_size.to_string(), }) .collect::>(); @@ -467,7 +475,7 @@ mod tests { curve: EcdsaCurve::Secp256k1, name: "test_key_1".to_string(), }), - pre_signatures_to_create_in_advance: 77, + pre_signatures_to_create_in_advance: Some(77), max_queue_size: 30, }, KeyConfig { @@ -475,7 +483,7 @@ mod tests { algorithm: SchnorrAlgorithm::Bip340Secp256k1, name: "test_key_2".to_string(), }), - pre_signatures_to_create_in_advance: 12, + pre_signatures_to_create_in_advance: Some(12), max_queue_size: 32, }, KeyConfig { @@ -483,7 +491,7 @@ mod tests { curve: VetKdCurve::Bls12_381_G2, name: "test_key_3".to_string(), }), - pre_signatures_to_create_in_advance: 0, + pre_signatures_to_create_in_advance: None, max_queue_size: 32, }, ], @@ -523,7 +531,7 @@ mod tests { --initial-chain-key-configs-to-request '[\ {\"subnet_id\":\"mklno-zzmhy-zutel-oujwg-dzcli-h6nfy-2serg-gnwru-vuwck-hcxit-wqe\",\"key_id\":\"ecdsa:Secp256k1:test_key_1\",\"pre_signatures_to_create_in_advance\":\"77\",\"max_queue_size\":\"30\"},\ {\"subnet_id\":\"mklno-zzmhy-zutel-oujwg-dzcli-h6nfy-2serg-gnwru-vuwck-hcxit-wqe\",\"key_id\":\"schnorr:Bip340Secp256k1:test_key_2\",\"pre_signatures_to_create_in_advance\":\"12\",\"max_queue_size\":\"32\"},\ - {\"subnet_id\":\"mklno-zzmhy-zutel-oujwg-dzcli-h6nfy-2serg-gnwru-vuwck-hcxit-wqe\",\"key_id\":\"vetkd:Bls12_381_G2:test_key_3\",\"pre_signatures_to_create_in_advance\":\"0\",\"max_queue_size\":\"32\"}]' \ + {\"subnet_id\":\"mklno-zzmhy-zutel-oujwg-dzcli-h6nfy-2serg-gnwru-vuwck-hcxit-wqe\",\"key_id\":\"vetkd:Bls12_381_G2:test_key_3\",\"max_queue_size\":\"32\"}]' \ --idkg-key-rotation-period-ms 321654 \ --signature-request-timeout-ns 123456 \ --max-parallel-pre-signature-transcripts-in-creation 123654 \ diff --git a/rs/registry/admin/bin/create_subnet.rs b/rs/registry/admin/bin/create_subnet.rs index b3d2849432c0..578e9b1c40f9 100644 --- a/rs/registry/admin/bin/create_subnet.rs +++ b/rs/registry/admin/bin/create_subnet.rs @@ -90,7 +90,7 @@ pub(crate) struct ProposeToCreateSubnetCmd { /// each with a subnet ID to request this key from. /// /// key_id: Master public key ID formatted as "Scheme:AlgorithmID:KeyName". - /// pre_signatures_to_create_in_advance: Non-negative integer value. + /// pre_signatures_to_create_in_advance: Non-negative integer value (keys that do not require pre-signatures omit this field). /// max_queue_size: Integer value greater than or equal 1. /// subnet_id: Principal ID of a subnet holding the requested key. /// @@ -109,7 +109,12 @@ pub(crate) struct ProposeToCreateSubnetCmd { /// "pre_signatures_to_create_in_advance": "98", /// "max_queue_size": "154", /// "subnet_id": "gxevo-lhkam-aaaaa-aaaap-yai" - /// } + /// }, + /// { + /// "key_id": "vetkd:Bls12_381_G2:some_key_name_3", + /// "max_queue_size": "154", + /// "subnet_id": "gxevo-lhkam-aaaaa-aaaap-yai" + /// }, /// ]' /// ``` #[clap(long)] @@ -163,39 +168,49 @@ fn parse_key_config_requests_option( raw.iter() .map(|btree| { - let subnet_id = Some(btree - .get("subnet_id") - .map(|key| { - key.parse::() - .unwrap_or_else(|_| panic!("Could not parse subnet_id: '{key}'")) - }) - .expect("Each element of the JSON object must specify a 'subnet_id'.")); - - let key_id = Some(btree - .get("key_id") - .map(|key| { - key.parse::() - .unwrap_or_else(|_| panic!("Could not parse key_id: '{key}'")) - }) - .expect("Each element of the JSON object must specify a 'key_id'.")); - - let pre_signatures_to_create_in_advance = Some(btree - .get("pre_signatures_to_create_in_advance") - .map(|x| x.parse::().expect("pre_signatures_to_create_in_advance must be a u32.")) - .expect("Each element of the JSON object must specify a 'pre_signatures_to_create_in_advance'.")); - - let max_queue_size = Some(btree - .get("max_queue_size") - .map(|x| x.parse::().expect("max_queue_size must be a u32")) - .expect("Each element of the JSON object must specify a 'max_queue_size'.")); + let subnet_id = Some( + btree + .get("subnet_id") + .map(|key| { + key.parse::() + .unwrap_or_else(|_| panic!("Could not parse subnet_id: '{key}'")) + }) + .expect("Each element of the JSON object must specify a 'subnet_id'."), + ); + + let key_id = Some( + btree + .get("key_id") + .map(|key| { + key.parse::() + .unwrap_or_else(|_| panic!("Could not parse key_id: '{key}'")) + }) + .expect("Each element of the JSON object must specify a 'key_id'."), + ); + + let pre_signatures_to_create_in_advance = + btree.get("pre_signatures_to_create_in_advance").map(|x| { + x.parse::() + .expect("pre_signatures_to_create_in_advance must be a u32.") + }); + + let max_queue_size = Some( + btree + .get("max_queue_size") + .map(|x| x.parse::().expect("max_queue_size must be a u32")) + .expect("Each element of the JSON object must specify a 'max_queue_size'."), + ); let key_config = Some(do_create_subnet::KeyConfig { key_id, pre_signatures_to_create_in_advance, - max_queue_size + max_queue_size, }); - do_create_subnet::KeyConfigRequest { key_config, subnet_id } + do_create_subnet::KeyConfigRequest { + key_config, + subnet_id, + } }) .collect() } @@ -394,7 +409,6 @@ mod tests { }, { "key_id": "vetkd:Bls12_381_G2:some_key_name_3", - "pre_signatures_to_create_in_advance": "0", "max_queue_size": "154", "subnet_id": "gxevo-lhkam-aaaaa-aaaap-yai" }]"# @@ -452,7 +466,7 @@ mod tests { curve: VetKdCurve::Bls12_381_G2, name: "some_key_name_3".to_string(), })), - pre_signatures_to_create_in_advance: Some(0), + pre_signatures_to_create_in_advance: None, max_queue_size: Some(154), }), subnet_id: Some( diff --git a/rs/registry/admin/bin/recover_subnet.rs b/rs/registry/admin/bin/recover_subnet.rs index 3593340f6064..770bffcc4b8c 100644 --- a/rs/registry/admin/bin/recover_subnet.rs +++ b/rs/registry/admin/bin/recover_subnet.rs @@ -59,7 +59,7 @@ pub(crate) struct ProposeToUpdateRecoveryCupCmd { /// each with a subnet ID to request this key from. /// /// key_id: Master public key ID formatted as "Scheme:AlgorithmID:KeyName". - /// pre_signatures_to_create_in_advance: Non-negative integer value. + /// pre_signatures_to_create_in_advance: Non-negative integer value (keys that do not require pre-signatures omit this field). /// max_queue_size: Integer value greater than or equal 1. /// subnet_id: Principal ID of a subnet holding the requested key. /// @@ -78,6 +78,11 @@ pub(crate) struct ProposeToUpdateRecoveryCupCmd { /// "pre_signatures_to_create_in_advance": "98", /// "max_queue_size": "154", /// "subnet_id": "gxevo-lhkam-aaaaa-aaaap-yai" + /// }, + /// { + /// "key_id": "vetkd:Bls12_381_G2:some_key_name_3", + /// "max_queue_size": "154", + /// "subnet_id": "gxevo-lhkam-aaaaa-aaaap-yai" /// } /// ]' /// ``` @@ -128,39 +133,49 @@ fn parse_key_config_requests_option( raw.iter() .map(|btree| { - let subnet_id = Some(btree - .get("subnet_id") - .map(|key| { - key.parse::() - .unwrap_or_else(|_| panic!("Could not parse subnet_id: '{key}'")) - }) - .expect("Each element of the JSON object must specify a 'subnet_id'.")); - - let key_id = Some(btree - .get("key_id") - .map(|key| { - key.parse::() - .unwrap_or_else(|_| panic!("Could not parse key_id: '{key}'")) - }) - .expect("Each element of the JSON object must specify a 'key_id'.")); - - let pre_signatures_to_create_in_advance = Some(btree - .get("pre_signatures_to_create_in_advance") - .map(|x| x.parse::().expect("pre_signatures_to_create_in_advance must be a u32.")) - .expect("Each element of the JSON object must specify a 'pre_signatures_to_create_in_advance'.")); - - let max_queue_size = Some(btree - .get("max_queue_size") - .map(|x| x.parse::().expect("max_queue_size must be a u32")) - .expect("Each element of the JSON object must specify a 'max_queue_size'.")); + let subnet_id = Some( + btree + .get("subnet_id") + .map(|key| { + key.parse::() + .unwrap_or_else(|_| panic!("Could not parse subnet_id: '{key}'")) + }) + .expect("Each element of the JSON object must specify a 'subnet_id'."), + ); + + let key_id = Some( + btree + .get("key_id") + .map(|key| { + key.parse::() + .unwrap_or_else(|_| panic!("Could not parse key_id: '{key}'")) + }) + .expect("Each element of the JSON object must specify a 'key_id'."), + ); + + let pre_signatures_to_create_in_advance = + btree.get("pre_signatures_to_create_in_advance").map(|x| { + x.parse::() + .expect("pre_signatures_to_create_in_advance must be a u32.") + }); + + let max_queue_size = Some( + btree + .get("max_queue_size") + .map(|x| x.parse::().expect("max_queue_size must be a u32")) + .expect("Each element of the JSON object must specify a 'max_queue_size'."), + ); let key_config = Some(do_recover_subnet::KeyConfig { key_id, pre_signatures_to_create_in_advance, - max_queue_size + max_queue_size, }); - do_recover_subnet::KeyConfigRequest { key_config, subnet_id } + do_recover_subnet::KeyConfigRequest { + key_config, + subnet_id, + } }) .collect() } @@ -309,7 +324,6 @@ mod tests { }, { "key_id": "vetkd:Bls12_381_G2:some_key_name_3", - "pre_signatures_to_create_in_advance": "0", "max_queue_size": "154", "subnet_id": "gxevo-lhkam-aaaaa-aaaap-yai" }]"# @@ -364,7 +378,7 @@ mod tests { curve: VetKdCurve::Bls12_381_G2, name: "some_key_name_3".to_string(), })), - pre_signatures_to_create_in_advance: Some(0), + pre_signatures_to_create_in_advance: None, max_queue_size: Some(154), }), subnet_id: Some( diff --git a/rs/registry/admin/bin/update_subnet.rs b/rs/registry/admin/bin/update_subnet.rs index 4d13f1f7d767..32acebe92cd4 100644 --- a/rs/registry/admin/bin/update_subnet.rs +++ b/rs/registry/admin/bin/update_subnet.rs @@ -90,7 +90,7 @@ pub(crate) struct ProposeToUpdateSubnetCmd { /// is new for the specified subnet, it must also not already exist on the IC. /// /// key_id: master public key ID formatted as "Scheme:AlgorithmID:KeyName". - /// pre_signatures_to_create_in_advance: Non-negative integer value. + /// pre_signatures_to_create_in_advance: Non-negative integer value (keys that do not require pre-signatures omit this field). /// max_queue_size: integer value greater than or equal 1. /// /// Example (note that all values, including integers, are represented as strings): @@ -106,6 +106,10 @@ pub(crate) struct ProposeToUpdateSubnetCmd { /// "key_id": "schnorr:Bip340Secp256k1:some_key_name_2", /// "pre_signatures_to_create_in_advance": "98", /// "max_queue_size": "154" + /// }, + /// { + /// "key_id": "vetkd:Bls12_381_G2:some_key_name_3", + /// "max_queue_size": "154" /// } /// ]' /// ``` @@ -190,25 +194,34 @@ fn parse_chain_key_configs_option( raw.iter() .map(|btree| { - let key_id = Some(btree - .get("key_id") - .map(|key| { - key.parse::() - .unwrap_or_else(|_| panic!("Could not parse key_id: '{key}'")) - }) - .expect("Each element of the JSON object must specify a 'key_id'.")); - - let pre_signatures_to_create_in_advance = Some(btree - .get("pre_signatures_to_create_in_advance") - .map(|x| x.parse::().expect("pre_signatures_to_create_in_advance must be a u32.")) - .expect("Each element of the JSON object must specify a 'pre_signatures_to_create_in_advance'.")); - - let max_queue_size = Some(btree - .get("max_queue_size") - .map(|x| x.parse::().expect("max_queue_size must be a u32")) - .expect("Each element of the JSON object must specify a 'max_queue_size'.")); - - do_update_subnet::KeyConfig { key_id, pre_signatures_to_create_in_advance, max_queue_size } + let key_id = Some( + btree + .get("key_id") + .map(|key| { + key.parse::() + .unwrap_or_else(|_| panic!("Could not parse key_id: '{key}'")) + }) + .expect("Each element of the JSON object must specify a 'key_id'."), + ); + + let pre_signatures_to_create_in_advance = + btree.get("pre_signatures_to_create_in_advance").map(|x| { + x.parse::() + .expect("pre_signatures_to_create_in_advance must be a u32.") + }); + + let max_queue_size = Some( + btree + .get("max_queue_size") + .map(|x| x.parse::().expect("max_queue_size must be a u32")) + .expect("Each element of the JSON object must specify a 'max_queue_size'."), + ); + + do_update_subnet::KeyConfig { + key_id, + pre_signatures_to_create_in_advance, + max_queue_size, + } }) .collect() } @@ -451,7 +464,7 @@ mod tests { curve: EcdsaCurve::Secp256k1, name: "some_key_name_3".to_string(), }), - pre_signatures_to_create_in_advance: 555, + pre_signatures_to_create_in_advance: Some(555), max_queue_size: 444, }, KeyConfig { @@ -459,7 +472,7 @@ mod tests { curve: EcdsaCurve::Secp256k1, name: "some_key_name_4".to_string(), }), - pre_signatures_to_create_in_advance: 999, + pre_signatures_to_create_in_advance: Some(999), max_queue_size: 888, }, ], @@ -483,7 +496,6 @@ mod tests { }, { "key_id": "vetkd:Bls12_381_G2:some_key_name_5", - "pre_signatures_to_create_in_advance": "0", "max_queue_size": "154" }]"# .to_string(); @@ -557,7 +569,7 @@ mod tests { curve: VetKdCurve::Bls12_381_G2, name: "some_key_name_5".to_string(), })), - pre_signatures_to_create_in_advance: Some(0), + pre_signatures_to_create_in_advance: None, max_queue_size: Some(154), }, ], @@ -600,7 +612,6 @@ mod tests { }, { "key_id": "vetkd:Bls12_381_G2:some_key_name_3", - "pre_signatures_to_create_in_advance": "0", "max_queue_size": "154" }]"# .to_string(); @@ -645,7 +656,7 @@ mod tests { curve: VetKdCurve::Bls12_381_G2, name: "some_key_name_3".to_string(), })), - pre_signatures_to_create_in_advance: Some(0), + pre_signatures_to_create_in_advance: None, max_queue_size: Some(154), }, ], @@ -669,7 +680,7 @@ mod tests { curve: EcdsaCurve::Secp256k1, name: "some_key_name_1".to_string(), }), - pre_signatures_to_create_in_advance: 111_111, + pre_signatures_to_create_in_advance: Some(111_111), max_queue_size: 222_222, }], signature_request_timeout_ns: Some(777_777), @@ -692,7 +703,6 @@ mod tests { }, { "key_id": "vetkd:Bls12_381_G2:some_key_name_3", - "pre_signatures_to_create_in_advance": "0", "max_queue_size": "444" }]"# .to_string(); @@ -740,7 +750,7 @@ mod tests { curve: VetKdCurve::Bls12_381_G2, name: "some_key_name_3".to_string(), })), - pre_signatures_to_create_in_advance: Some(0), + pre_signatures_to_create_in_advance: None, max_queue_size: Some(444), }, ], diff --git a/rs/registry/canister/src/invariants/crypto.rs b/rs/registry/canister/src/invariants/crypto.rs index 8e6e0ec65fc4..1b05ba619cbb 100644 --- a/rs/registry/canister/src/invariants/crypto.rs +++ b/rs/registry/canister/src/invariants/crypto.rs @@ -289,12 +289,13 @@ fn check_chain_key_configs(snapshot: &RegistrySnapshot) -> Result<(), InvariantC let mut key_ids = BTreeSet::new(); for key_config in chain_key_config.key_configs { let key_id = key_config.key_id.clone(); - if key_config.pre_signatures_to_create_in_advance == 0 - && key_id.requires_pre_signatures() + if key_id.requires_pre_signatures() + && (key_config.pre_signatures_to_create_in_advance.is_none() + || key_config.pre_signatures_to_create_in_advance == Some(0)) { return Err(InvariantCheckError { msg: format!( - "`pre_signatures_to_create_in_advance` for key {key_id} of subnet {subnet_id:} cannot be zero.", + "pre_signatures_to_create_in_advance for key {key_id} of subnet {subnet_id:} must be present and non-zero", ), source: None, }); diff --git a/rs/registry/canister/src/invariants/crypto/tests.rs b/rs/registry/canister/src/invariants/crypto/tests.rs index 513a244373b4..207ee55f93d2 100644 --- a/rs/registry/canister/src/invariants/crypto/tests.rs +++ b/rs/registry/canister/src/invariants/crypto/tests.rs @@ -648,7 +648,7 @@ mod chain_key_enabled_subnet_lists { name: "vetkd_key".to_string(), })), }), - pre_signatures_to_create_in_advance: Some(0), + pre_signatures_to_create_in_advance: None, max_queue_size: Some(100), }, ], @@ -680,9 +680,19 @@ mod chain_key_enabled_subnet_lists { #[test] #[should_panic( - expected = "Missing required struct field: KeyConfig::pre_signatures_to_create_in_advance" + expected = "pre_signatures_to_create_in_advance for key ecdsa:Secp256k1:ecdsa_key of subnet ya35z-hhham-aaaaa-aaaap-yai must be present and non-zero" )] - fn should_fail_if_missing_pre_signatures() { + fn should_fail_if_pre_signatures_to_create_in_advance_is_missing_for_ecdsa_key() { + let mut config = invariant_compliant_chain_key_config(); + config.key_configs[0].pre_signatures_to_create_in_advance = None; + check_chain_key_config_invariant(config); + } + + #[test] + #[should_panic( + expected = "pre_signatures_to_create_in_advance for key schnorr:Bip340Secp256k1:schnorr_key of subnet ya35z-hhham-aaaaa-aaaap-yai must be present and non-zero" + )] + fn should_fail_if_pre_signatures_to_create_in_advance_is_missing_for_schnorr_key() { 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); @@ -690,14 +700,50 @@ 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 cannot be zero." + expected = "pre_signatures_to_create_in_advance for key ecdsa:Secp256k1:ecdsa_key of subnet ya35z-hhham-aaaaa-aaaap-yai must be present and non-zero" )] - fn should_fail_if_pre_signatures_is_zero() { + fn should_fail_if_pre_signatures_to_create_in_advance_is_zero_for_ecdsa_key() { 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] + #[should_panic( + expected = "pre_signatures_to_create_in_advance for key schnorr:Bip340Secp256k1:schnorr_key of subnet ya35z-hhham-aaaaa-aaaap-yai must be present and non-zero" + )] + fn should_fail_if_pre_signatures_to_create_in_advance_is_zero_for_schnorr_key() { + let mut config = invariant_compliant_chain_key_config(); + config.key_configs[1].pre_signatures_to_create_in_advance = Some(0); + check_chain_key_config_invariant(config); + } + + #[test] + fn should_succeed_if_pre_signatures_to_create_in_advance_is_missing_for_vetkd_key() { + use master_public_key_id::KeyId::Vetkd; + 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(Vetkd(_)) + ),); + key_config.pre_signatures_to_create_in_advance = None; + check_chain_key_config_invariant(config); + } + + #[test] + fn should_succeed_if_pre_signatures_to_create_in_advance_is_zero_for_vetkd_key() { + use master_public_key_id::KeyId::Vetkd; + 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(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() { diff --git a/rs/registry/canister/src/mutations/do_create_subnet.rs b/rs/registry/canister/src/mutations/do_create_subnet.rs index a689fe407854..5d0151e48a1d 100644 --- a/rs/registry/canister/src/mutations/do_create_subnet.rs +++ b/rs/registry/canister/src/mutations/do_create_subnet.rs @@ -394,7 +394,7 @@ impl From for KeyConfig { Self { key_id: Some(key_id), - pre_signatures_to_create_in_advance: Some(pre_signatures_to_create_in_advance), + pre_signatures_to_create_in_advance, max_queue_size: Some(max_queue_size), } } @@ -414,11 +414,16 @@ impl TryFrom for KeyConfigInternal { 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 { + if key_id.requires_pre_signatures() && pre_signatures_to_create_in_advance.is_none() { 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_some() { + return Err(format!( + "KeyConfig.pre_signatures_to_create_in_advance must not be specified for key {key_id} because it does not require pre-signatures." + )); + }; let Some(max_queue_size) = max_queue_size else { return Err("KeyConfig.max_queue_size must be specified.".to_string()); @@ -614,7 +619,7 @@ mod test { let chain_key_config = ChainKeyConfig { key_configs: vec![KeyConfigInternal { key_id: MasterPublicKeyId::Ecdsa(key_id.clone()), - pre_signatures_to_create_in_advance: 1, + pre_signatures_to_create_in_advance: Some(1), max_queue_size: DEFAULT_ECDSA_MAX_QUEUE_SIZE, }], signature_request_timeout_ns: None, @@ -678,7 +683,7 @@ mod test { let chain_key_config = ChainKeyConfig { key_configs: vec![KeyConfigInternal { key_id: MasterPublicKeyId::Ecdsa(key_id.clone()), - pre_signatures_to_create_in_advance: 1, + pre_signatures_to_create_in_advance: Some(1), max_queue_size: DEFAULT_ECDSA_MAX_QUEUE_SIZE, }], signature_request_timeout_ns: None, @@ -740,7 +745,7 @@ mod test { let chain_key_config = ChainKeyConfig { key_configs: vec![KeyConfigInternal { key_id: MasterPublicKeyId::Ecdsa(key_id.clone()), - pre_signatures_to_create_in_advance: 1, + pre_signatures_to_create_in_advance: Some(1), max_queue_size: DEFAULT_ECDSA_MAX_QUEUE_SIZE, }], signature_request_timeout_ns: None, diff --git a/rs/registry/canister/src/mutations/do_recover_subnet.rs b/rs/registry/canister/src/mutations/do_recover_subnet.rs index 53a5291ab41c..eab7a1377eba 100644 --- a/rs/registry/canister/src/mutations/do_recover_subnet.rs +++ b/rs/registry/canister/src/mutations/do_recover_subnet.rs @@ -358,7 +358,7 @@ impl From for KeyConfig { Self { key_id: Some(key_id), - pre_signatures_to_create_in_advance: Some(pre_signatures_to_create_in_advance), + pre_signatures_to_create_in_advance, max_queue_size: Some(max_queue_size), } } @@ -378,11 +378,16 @@ impl TryFrom for KeyConfigInternal { 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 { + if key_id.requires_pre_signatures() && pre_signatures_to_create_in_advance.is_none() { 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_some() { + return Err(format!( + "KeyConfig.pre_signatures_to_create_in_advance must not be specified for key {key_id} because it does not require pre-signatures." + )); + }; let Some(max_queue_size) = max_queue_size else { return Err("KeyConfig.max_queue_size must be specified.".to_string()); @@ -517,7 +522,7 @@ mod test { let chain_key_config = ChainKeyConfig { key_configs: vec![KeyConfigInternal { key_id: MasterPublicKeyId::Ecdsa(key_id.clone()), - pre_signatures_to_create_in_advance: 1, + pre_signatures_to_create_in_advance: Some(1), max_queue_size: DEFAULT_ECDSA_MAX_QUEUE_SIZE, }], signature_request_timeout_ns: None, diff --git a/rs/registry/canister/src/mutations/do_update_node_directly.rs b/rs/registry/canister/src/mutations/do_update_node_directly.rs index 46ff0df4a897..8fa563ed8f04 100644 --- a/rs/registry/canister/src/mutations/do_update_node_directly.rs +++ b/rs/registry/canister/src/mutations/do_update_node_directly.rs @@ -295,7 +295,7 @@ mod test { }); let key_config = KeyConfig { key_id, - pre_signatures_to_create_in_advance: 1, + pre_signatures_to_create_in_advance: Some(1), max_queue_size: DEFAULT_ECDSA_MAX_QUEUE_SIZE, }; subnet_record.chain_key_config = Some(ChainKeyConfigPb::from(ChainKeyConfig { @@ -352,7 +352,7 @@ mod test { }); let key_config = KeyConfig { key_id, - pre_signatures_to_create_in_advance: 1, + pre_signatures_to_create_in_advance: Some(1), max_queue_size: DEFAULT_ECDSA_MAX_QUEUE_SIZE, }; subnet_record.chain_key_config = Some(ChainKeyConfigPb::from(ChainKeyConfig { @@ -419,7 +419,7 @@ mod test { }); let key_config = KeyConfig { key_id, - pre_signatures_to_create_in_advance: 1, + pre_signatures_to_create_in_advance: Some(1), max_queue_size: DEFAULT_ECDSA_MAX_QUEUE_SIZE, }; subnet_record.chain_key_config = Some(ChainKeyConfigPb::from(ChainKeyConfig { diff --git a/rs/registry/canister/src/mutations/do_update_subnet.rs b/rs/registry/canister/src/mutations/do_update_subnet.rs index 67db8665e04b..598897920f22 100644 --- a/rs/registry/canister/src/mutations/do_update_subnet.rs +++ b/rs/registry/canister/src/mutations/do_update_subnet.rs @@ -278,7 +278,7 @@ impl From for ChainKeyConfig { max_queue_size, }| KeyConfig { key_id: Some(key_id), - pre_signatures_to_create_in_advance: Some(pre_signatures_to_create_in_advance), + pre_signatures_to_create_in_advance, max_queue_size: Some(max_queue_size), }, ) @@ -349,7 +349,7 @@ impl From for KeyConfig { Self { key_id: Some(key_id), - pre_signatures_to_create_in_advance: Some(pre_signatures_to_create_in_advance), + pre_signatures_to_create_in_advance, max_queue_size: Some(max_queue_size), } } @@ -368,11 +368,16 @@ impl TryFrom 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 { + if key_id.requires_pre_signatures() && pre_signatures_to_create_in_advance.is_none() { 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_some() { + return Err(format!( + "KeyConfig.pre_signatures_to_create_in_advance must not be specified for key {key_id} because it does not require pre-signatures." + )); + }; let Some(max_queue_size) = max_queue_size else { return Err("KeyConfig.max_queue_size must be specified.".to_string()); }; diff --git a/rs/registry/canister/tests/common/test_helpers.rs b/rs/registry/canister/tests/common/test_helpers.rs index 598d93cbb8be..b35c967b100e 100644 --- a/rs/registry/canister/tests/common/test_helpers.rs +++ b/rs/registry/canister/tests/common/test_helpers.rs @@ -65,11 +65,7 @@ pub fn get_subnet_holding_chain_keys( .into_iter() .map(|key_id| KeyConfig { key_id: key_id.clone(), - pre_signatures_to_create_in_advance: if key_id.requires_pre_signatures() { - 1 - } else { - 0 - }, + pre_signatures_to_create_in_advance: key_id.requires_pre_signatures().then_some(1), max_queue_size: DEFAULT_ECDSA_MAX_QUEUE_SIZE, }) .collect(), diff --git a/rs/registry/canister/tests/create_subnet.rs b/rs/registry/canister/tests/create_subnet.rs index 692ad15adec6..679d7135cb3c 100644 --- a/rs/registry/canister/tests/create_subnet.rs +++ b/rs/registry/canister/tests/create_subnet.rs @@ -264,7 +264,9 @@ fn test_accepted_proposal_with_chain_key_gets_keys_from_other_subnet(key_id: Mas subnet_record.chain_key_config = Some(ChainKeyConfigPb::from(ChainKeyConfig { key_configs: vec![KeyConfigInternal { key_id: key_id.clone(), - pre_signatures_to_create_in_advance: 100, + pre_signatures_to_create_in_advance: key_id + .requires_pre_signatures() + .then_some(100), max_queue_size: DEFAULT_ECDSA_MAX_QUEUE_SIZE, }], signature_request_timeout_ns: None, @@ -305,11 +307,9 @@ fn test_accepted_proposal_with_chain_key_gets_keys_from_other_subnet(key_id: Mas key_configs: vec![KeyConfigRequest { key_config: Some(KeyConfig { key_id: Some(key_id.clone()), - pre_signatures_to_create_in_advance: if key_id.requires_pre_signatures() { - Some(101) - } else { - Some(0) - }, + pre_signatures_to_create_in_advance: key_id + .requires_pre_signatures() + .then_some(101), max_queue_size: Some(DEFAULT_ECDSA_MAX_QUEUE_SIZE), }), subnet_id: Some(*system_subnet_principal), @@ -363,11 +363,9 @@ fn test_accepted_proposal_with_chain_key_gets_keys_from_other_subnet(key_id: Mas chain_key_config.key_configs, vec![KeyConfigInternal { key_id: key_id.clone(), - pre_signatures_to_create_in_advance: if key_id.requires_pre_signatures() { - 101 - } else { - 0 - }, + pre_signatures_to_create_in_advance: key_id + .requires_pre_signatures() + .then_some(101), max_queue_size: DEFAULT_ECDSA_MAX_QUEUE_SIZE, }], ); diff --git a/rs/registry/canister/tests/recover_subnet.rs b/rs/registry/canister/tests/recover_subnet.rs index 924cdcfa0ddf..2029b340b75f 100644 --- a/rs/registry/canister/tests/recover_subnet.rs +++ b/rs/registry/canister/tests/recover_subnet.rs @@ -288,11 +288,9 @@ fn test_recover_subnet_gets_chain_keys_when_needed(key_id: MasterPublicKeyId) { subnet_record.chain_key_config = Some(ChainKeyConfigPb::from(ChainKeyConfig { key_configs: vec![KeyConfigInternal { key_id: key_id.clone(), - pre_signatures_to_create_in_advance: if key_id.requires_pre_signatures() { - 100 - } else { - 0 - }, + pre_signatures_to_create_in_advance: key_id + .requires_pre_signatures() + .then_some(100), max_queue_size: DEFAULT_ECDSA_MAX_QUEUE_SIZE, }], signature_request_timeout_ns: None, @@ -382,7 +380,9 @@ fn test_recover_subnet_gets_chain_keys_when_needed(key_id: MasterPublicKeyId) { key_configs: vec![KeyConfigRequest { key_config: Some(KeyConfig { key_id: Some(key_id.clone()), - pre_signatures_to_create_in_advance: Some(1), + pre_signatures_to_create_in_advance: key_id + .requires_pre_signatures() + .then_some(1), max_queue_size: Some(DEFAULT_ECDSA_MAX_QUEUE_SIZE), }), subnet_id: Some(system_subnet_id.get()), @@ -434,7 +434,7 @@ fn test_recover_subnet_gets_chain_keys_when_needed(key_id: MasterPublicKeyId) { chain_key_config.key_configs, vec![KeyConfigPb { key_id: Some(MasterPublicKeyIdPb::from(&key_id)), - pre_signatures_to_create_in_advance: Some(1), + pre_signatures_to_create_in_advance: key_id.requires_pre_signatures().then_some(1), max_queue_size: Some(DEFAULT_ECDSA_MAX_QUEUE_SIZE), }] ); @@ -528,13 +528,9 @@ fn test_recover_subnet_without_chain_key_removes_it_from_signing_list(key_id: Ma let chain_key_config_pb = ChainKeyConfigPb { key_configs: vec![KeyConfigPb { key_id: Some(MasterPublicKeyIdPb::from(&key_id)), - pre_signatures_to_create_in_advance: Some( - if key_id.requires_pre_signatures() { - 1 - } else { - 0 - }, - ), + pre_signatures_to_create_in_advance: key_id + .requires_pre_signatures() + .then_some(1), max_queue_size: Some(DEFAULT_ECDSA_MAX_QUEUE_SIZE), }], signature_request_timeout_ns: None, @@ -996,7 +992,9 @@ fn test_recover_subnet_resets_cup_contents() { subnet_record.chain_key_config = Some(ChainKeyConfigPb::from(ChainKeyConfig { key_configs: vec![KeyConfigInternal { key_id: key_id.clone(), - pre_signatures_to_create_in_advance: 100, + pre_signatures_to_create_in_advance: key_id + .requires_pre_signatures() + .then_some(100), max_queue_size: DEFAULT_ECDSA_MAX_QUEUE_SIZE, }], signature_request_timeout_ns: None, @@ -1113,7 +1111,9 @@ fn test_recover_subnet_resets_cup_contents() { key_configs: vec![KeyConfigRequest { key_config: Some(KeyConfig { key_id: Some(key_id.clone()), - pre_signatures_to_create_in_advance: Some(1), + pre_signatures_to_create_in_advance: key_id + .requires_pre_signatures() + .then_some(1), max_queue_size: Some(DEFAULT_ECDSA_MAX_QUEUE_SIZE), }), subnet_id: Some(system_subnet_id.get()), @@ -1169,7 +1169,7 @@ fn test_recover_subnet_resets_cup_contents() { chain_key_config.key_configs, vec![KeyConfigPb { key_id: Some(MasterPublicKeyIdPb::from(&key_id)), - pre_signatures_to_create_in_advance: Some(1), + pre_signatures_to_create_in_advance: key_id.requires_pre_signatures().then_some(1), max_queue_size: Some(DEFAULT_ECDSA_MAX_QUEUE_SIZE), }] ); diff --git a/rs/registry/canister/tests/update_subnet.rs b/rs/registry/canister/tests/update_subnet.rs index 114f9cbd83c8..e08fef34c5ce 100644 --- a/rs/registry/canister/tests/update_subnet.rs +++ b/rs/registry/canister/tests/update_subnet.rs @@ -487,11 +487,7 @@ fn test_subnets_configuration_chain_key_fields_are_updated_correctly(key_id: Mas let chain_key_config = ChainKeyConfig { key_configs: vec![KeyConfig { key_id: Some(key_id.clone()), - pre_signatures_to_create_in_advance: Some(if key_id.requires_pre_signatures() { - 10 - } else { - 0 - }), + pre_signatures_to_create_in_advance: key_id.requires_pre_signatures().then_some(10), max_queue_size: Some(DEFAULT_ECDSA_MAX_QUEUE_SIZE), }], signature_request_timeout_ns, diff --git a/rs/registry/subnet_features/src/lib.rs b/rs/registry/subnet_features/src/lib.rs index 3f2babda5457..4bda93ea9e93 100644 --- a/rs/registry/subnet_features/src/lib.rs +++ b/rs/registry/subnet_features/src/lib.rs @@ -91,7 +91,7 @@ impl FromStr for SubnetFeatures { #[derive(Clone, Eq, PartialEq, Debug, CandidType, Deserialize, Serialize)] pub struct KeyConfig { pub key_id: MasterPublicKeyId, - pub pre_signatures_to_create_in_advance: u32, + pub pre_signatures_to_create_in_advance: Option, pub max_queue_size: u32, } @@ -105,8 +105,6 @@ impl From for pb::KeyConfig { let key_id = Some(pb_types::MasterPublicKeyId::from(&key_id)); - let pre_signatures_to_create_in_advance = Some(pre_signatures_to_create_in_advance); - Self { key_id, pre_signatures_to_create_in_advance, @@ -120,10 +118,7 @@ impl TryFrom for KeyConfig { fn try_from(value: pb::KeyConfig) -> Result { Ok(KeyConfig { - pre_signatures_to_create_in_advance: try_from_option_field( - value.pre_signatures_to_create_in_advance, - "KeyConfig::pre_signatures_to_create_in_advance", - )?, + pre_signatures_to_create_in_advance: value.pre_signatures_to_create_in_advance, key_id: try_from_option_field(value.key_id, "KeyConfig::key_id")?, max_queue_size: try_from_option_field( value.max_queue_size, @@ -233,7 +228,7 @@ mod tests { curve: EcdsaCurve::Secp256k1, name: "test_key1".to_string(), }), - pre_signatures_to_create_in_advance: 77, + pre_signatures_to_create_in_advance: Some(77), max_queue_size: 30, }, KeyConfig { @@ -241,7 +236,7 @@ mod tests { curve: VetKdCurve::Bls12_381_G2, name: "test_key2".to_string(), }), - pre_signatures_to_create_in_advance: 0, + pre_signatures_to_create_in_advance: Some(0), max_queue_size: 30, }, ], diff --git a/rs/state_machine_tests/src/lib.rs b/rs/state_machine_tests/src/lib.rs index 3f7ad6a1e009..90f77c9e086a 100644 --- a/rs/state_machine_tests/src/lib.rs +++ b/rs/state_machine_tests/src/lib.rs @@ -466,11 +466,9 @@ fn add_subnet_local_registry_records( .keys() .map(|key_id| KeyConfig { key_id: key_id.clone(), - pre_signatures_to_create_in_advance: if key_id.requires_pre_signatures() { - 1 - } else { - 0 - }, + pre_signatures_to_create_in_advance: key_id + .requires_pre_signatures() + .then_some(1), max_queue_size: DEFAULT_ECDSA_MAX_QUEUE_SIZE, }) .collect(), diff --git a/rs/test_utilities/execution_environment/src/lib.rs b/rs/test_utilities/execution_environment/src/lib.rs index 6054a4b7f174..884fd7a6823f 100644 --- a/rs/test_utilities/execution_environment/src/lib.rs +++ b/rs/test_utilities/execution_environment/src/lib.rs @@ -2498,7 +2498,9 @@ impl ExecutionTestBuilder { key_id.clone(), ChainKeySettings { max_queue_size: 20, - pre_signatures_to_create_in_advance: 5, + pre_signatures_to_create_in_advance: key_id + .requires_pre_signatures() + .then_some(5), }, ); diff --git a/rs/tests/ckbtc/src/lib.rs b/rs/tests/ckbtc/src/lib.rs index b002d0a22d87..cce0e53ce980 100644 --- a/rs/tests/ckbtc/src/lib.rs +++ b/rs/tests/ckbtc/src/lib.rs @@ -131,7 +131,7 @@ fn ckbtc_config(env: TestEnv) { curve: EcdsaCurve::Secp256k1, name: TEST_KEY_LOCAL.to_string(), }), - pre_signatures_to_create_in_advance: 10, + pre_signatures_to_create_in_advance: Some(10), max_queue_size: DEFAULT_ECDSA_MAX_QUEUE_SIZE, }], signature_request_timeout_ns: None, diff --git a/rs/tests/consensus/backup/common.rs b/rs/tests/consensus/backup/common.rs index b78f698cd7de..1bdaea1506bf 100644 --- a/rs/tests/consensus/backup/common.rs +++ b/rs/tests/consensus/backup/common.rs @@ -78,12 +78,9 @@ pub fn setup(env: TestEnv) { .into_iter() .map(|key_id| KeyConfig { max_queue_size: 20, - pre_signatures_to_create_in_advance: if key_id.requires_pre_signatures() - { - 7 - } else { - 0 - }, + pre_signatures_to_create_in_advance: key_id + .requires_pre_signatures() + .then_some(7), key_id, }) .collect(), diff --git a/rs/tests/consensus/subnet_recovery/common.rs b/rs/tests/consensus/subnet_recovery/common.rs index e396100d1fe5..551a4b867525 100644 --- a/rs/tests/consensus/subnet_recovery/common.rs +++ b/rs/tests/consensus/subnet_recovery/common.rs @@ -100,11 +100,7 @@ fn setup(env: TestEnv, cfg: SetupConfig) { .into_iter() .map(|key_id| KeyConfig { max_queue_size: DEFAULT_ECDSA_MAX_QUEUE_SIZE, - pre_signatures_to_create_in_advance: if key_id.requires_pre_signatures() { - 3 - } else { - 0 - }, + pre_signatures_to_create_in_advance: key_id.requires_pre_signatures().then_some(3), key_id, }) .collect(); diff --git a/rs/tests/consensus/tecdsa/tecdsa_performance_test_template.rs b/rs/tests/consensus/tecdsa/tecdsa_performance_test_template.rs index 951149559913..31ab772ca844 100644 --- a/rs/tests/consensus/tecdsa/tecdsa_performance_test_template.rs +++ b/rs/tests/consensus/tecdsa/tecdsa_performance_test_template.rs @@ -200,7 +200,9 @@ pub fn setup(env: TestEnv) { .into_iter() .map(|key_id| KeyConfig { max_queue_size: MAX_QUEUE_SIZE, - pre_signatures_to_create_in_advance: PRE_SIGNATURES_TO_CREATE, + pre_signatures_to_create_in_advance: key_id + .requires_pre_signatures() + .then_some(PRE_SIGNATURES_TO_CREATE), key_id, }) .collect(), diff --git a/rs/tests/consensus/tecdsa/tecdsa_two_signing_subnets_test.rs b/rs/tests/consensus/tecdsa/tecdsa_two_signing_subnets_test.rs index 8fb905fa69cb..5263a9a5dcd9 100644 --- a/rs/tests/consensus/tecdsa/tecdsa_two_signing_subnets_test.rs +++ b/rs/tests/consensus/tecdsa/tecdsa_two_signing_subnets_test.rs @@ -58,7 +58,7 @@ fn setup(env: TestEnv) { .with_chain_key_config(ChainKeyConfig { key_configs: vec![KeyConfig { max_queue_size: DEFAULT_ECDSA_MAX_QUEUE_SIZE, - pre_signatures_to_create_in_advance: 5, + pre_signatures_to_create_in_advance: Some(5), key_id: MasterPublicKeyId::Ecdsa(make_key(KEY_ID1)), }], signature_request_timeout_ns: None, diff --git a/rs/tests/consensus/tecdsa/tschnorr_message_sizes_test.rs b/rs/tests/consensus/tecdsa/tschnorr_message_sizes_test.rs index 3d0eeb340599..928f3b19d83e 100644 --- a/rs/tests/consensus/tecdsa/tschnorr_message_sizes_test.rs +++ b/rs/tests/consensus/tecdsa/tschnorr_message_sizes_test.rs @@ -78,7 +78,7 @@ fn setup(env: TestEnv) { .into_iter() .map(|key_id| KeyConfig { key_id, - pre_signatures_to_create_in_advance: 5, + pre_signatures_to_create_in_advance: Some(5), max_queue_size: DEFAULT_ECDSA_MAX_QUEUE_SIZE, }) .collect(), diff --git a/rs/tests/consensus/tecdsa/utils/src/lib.rs b/rs/tests/consensus/tecdsa/utils/src/lib.rs index 29c8496ee249..f149e7dff9fc 100644 --- a/rs/tests/consensus/tecdsa/utils/src/lib.rs +++ b/rs/tests/consensus/tecdsa/utils/src/lib.rs @@ -993,13 +993,9 @@ pub async fn add_chain_keys_with_timeout_and_rotation_period( .into_iter() .map(|key_id| KeyConfigUpdate { key_id: Some(key_id.clone()), - pre_signatures_to_create_in_advance: Some( - if key_id.requires_pre_signatures() { - 5 - } else { - 0 - }, - ), + pre_signatures_to_create_in_advance: key_id + .requires_pre_signatures() + .then_some(5), max_queue_size: Some(DEFAULT_ECDSA_MAX_QUEUE_SIZE), }) .collect(), @@ -1059,13 +1055,9 @@ pub async fn create_new_subnet_with_keys( .into_iter() .map(|(key_id, subnet_id)| KeyConfigRequest { key_config: Some(KeyConfigCreate { - pre_signatures_to_create_in_advance: Some( - if key_id.requires_pre_signatures() { - 4 - } else { - 0 - }, - ), + pre_signatures_to_create_in_advance: key_id + .requires_pre_signatures() + .then_some(4), max_queue_size: Some(DEFAULT_ECDSA_MAX_QUEUE_SIZE), key_id: Some(key_id), }), diff --git a/rs/tests/consensus/upgrade/upgrade_app_subnet_test.rs b/rs/tests/consensus/upgrade/upgrade_app_subnet_test.rs index 8d5e0d9c3dd3..d624cc44d396 100644 --- a/rs/tests/consensus/upgrade/upgrade_app_subnet_test.rs +++ b/rs/tests/consensus/upgrade/upgrade_app_subnet_test.rs @@ -33,11 +33,9 @@ fn setup(env: TestEnv) { .into_iter() .map(|key_id| KeyConfig { max_queue_size: DEFAULT_ECDSA_MAX_QUEUE_SIZE, - pre_signatures_to_create_in_advance: if key_id.requires_pre_signatures() { - 5 - } else { - 0 - }, + pre_signatures_to_create_in_advance: key_id + .requires_pre_signatures() + .then_some(5), key_id, }) .collect(), diff --git a/rs/tests/consensus/upgrade/upgrade_downgrade_app_subnet_test.rs b/rs/tests/consensus/upgrade/upgrade_downgrade_app_subnet_test.rs index 5c205b65f225..12e3d3494095 100644 --- a/rs/tests/consensus/upgrade/upgrade_downgrade_app_subnet_test.rs +++ b/rs/tests/consensus/upgrade/upgrade_downgrade_app_subnet_test.rs @@ -51,11 +51,9 @@ fn setup(env: TestEnv) { .into_iter() .map(|key_id| KeyConfig { max_queue_size: DEFAULT_ECDSA_MAX_QUEUE_SIZE, - pre_signatures_to_create_in_advance: if key_id.requires_pre_signatures() { - 5 - } else { - 0 - }, + pre_signatures_to_create_in_advance: key_id + .requires_pre_signatures() + .then_some(5), key_id, }) .collect(),