diff --git a/crates/client/entropy_metadata.scale b/crates/client/entropy_metadata.scale index 6fd6b940f..04e9e8e25 100644 Binary files a/crates/client/entropy_metadata.scale and b/crates/client/entropy_metadata.scale differ diff --git a/crates/threshold-signature-server/src/user/api.rs b/crates/threshold-signature-server/src/user/api.rs index bd3c8e012..85ca987e4 100644 --- a/crates/threshold-signature-server/src/user/api.rs +++ b/crates/threshold-signature-server/src/user/api.rs @@ -292,14 +292,6 @@ async fn setup_dkg( app_state: AppState, ) -> Result<(), UserErr> { tracing::debug!("Preparing to execute DKG"); - // let block_hash = rpc - // .chain_get_block_hash(None) - // .await? - // .ok_or_else(|| UserErr::OptionUnwrapError("Error getting block hash".to_string()))?; - // let nonce_call = entropy::apis().account_nonce_api().account_nonce(signer.account_id().clone()); - // let nonce = api.runtime_api().at(block_hash).call(nonce_call).await?; - - // for (i, sig_request_account) in data.sig_request_accounts.into_iter().enumerate() { for sig_request_account in data.sig_request_accounts.into_iter() { let address_slice: &[u8; 32] = &sig_request_account .clone() @@ -324,7 +316,7 @@ async fn setup_dkg( } .to_string(); - let serialized_key_share = key_serialize(&key_share) + let serialized_key_share = key_serialize(&(key_share, aux_info)) .map_err(|_| UserErr::KvSerialize("Kv Serialize Error".to_string()))?; let reservation = app_state.kv_store.kv().reserve_key(string_verifying_key.clone()).await?; @@ -389,8 +381,7 @@ pub async fn confirm_registered( // TODO: Understand this better, potentially use sign_and_submit_default // or other method under sign_and_* if who.encode() == NETWORK_PARENT_KEY.encode() { - // TODO (Nando): Remove the subgroup argument - let jump_start_request = entropy::tx().registry().confirm_jump_start(0); + let jump_start_request = entropy::tx().registry().confirm_jump_start(); submit_transaction(api, rpc, signer, &jump_start_request, Some(nonce)).await?; } else { let confirm_register_request = entropy::tx().registry().confirm_register( diff --git a/crates/threshold-signature-server/src/user/tests.rs b/crates/threshold-signature-server/src/user/tests.rs index eb9e9599f..758f0be25 100644 --- a/crates/threshold-signature-server/src/user/tests.rs +++ b/crates/threshold-signature-server/src/user/tests.rs @@ -722,14 +722,14 @@ async fn test_jumpstart_network() { let alice = AccountKeyring::Alice; let cxt = test_context_stationary().await; - let (_validator_ips, _validator_ids, _) = - spawn_testing_validators(Some(DEFAULT_VERIFYING_KEY.to_vec()), false, false).await; + let (_validator_ips, _validator_ids) = spawn_testing_validators().await; let api = get_api(&cxt.node_proc.ws_url).await.unwrap(); let rpc = get_rpc(&cxt.node_proc.ws_url).await.unwrap(); let client = reqwest::Client::new(); let block_number = rpc.chain_get_header(None).await.unwrap().unwrap().number + 1; + let validators_info = vec![ entropy_shared::ValidatorInfo { ip_address: b"127.0.0.1:3001".to_vec(), @@ -741,6 +741,11 @@ async fn test_jumpstart_network() { x25519_public_key: X25519_PUBLIC_KEYS[1], tss_account: TSS_ACCOUNTS[1].clone().encode(), }, + entropy_shared::ValidatorInfo { + ip_address: b"127.0.0.1:3003".to_vec(), + x25519_public_key: X25519_PUBLIC_KEYS[2], + tss_account: TSS_ACCOUNTS[2].clone().encode(), + }, ]; let onchain_user_request = OcwMessageDkg { sig_request_accounts: vec![NETWORK_PARENT_KEY.encode()], @@ -753,14 +758,23 @@ async fn test_jumpstart_network() { run_to_block(&rpc, block_number + 1).await; // succeeds - let user_registration_response = client - .post("http://127.0.0.1:3002/user/new") - .body(onchain_user_request.clone().encode()) - .send() - .await - .unwrap(); + let response_results = join_all( + vec![3002, 3003] + .iter() + .map(|port| { + client + .post(format!("http://127.0.0.1:{}/user/new", port)) + .body(onchain_user_request.clone().encode()) + .send() + }) + .collect::>(), + ) + .await; + + for response_result in response_results { + assert_eq!(response_result.unwrap().text().await.unwrap(), ""); + } - assert_eq!(user_registration_response.text().await.unwrap(), ""); // wait for jump start event check that key exists in kvdb for _ in 0..45 { std::thread::sleep(std::time::Duration::from_millis(1000)); @@ -772,279 +786,13 @@ async fn test_jumpstart_network() { } } - let get_query = UnsafeQuery::new(hex::encode(NETWORK_PARENT_KEY), [].to_vec()).to_json(); - // check get key before registration to see if key gets replaced - let response_key = client - .post("http://127.0.0.1:3001/unsafe/get") - .header("Content-Type", "application/json") - .body(get_query.clone()) - .send() - .await - .unwrap(); + let response_key = unsafe_get(&client, hex::encode(NETWORK_PARENT_KEY), 3001).await; + // check to make sure keyshare is correct - let key_share: Option> = - entropy_kvdb::kv_manager::helpers::deserialize(&response_key.bytes().await.unwrap()); + let key_share: Option = + entropy_kvdb::kv_manager::helpers::deserialize(&response_key); assert_eq!(key_share.is_some(), true); - clean_tests(); -} - -#[tokio::test] -#[serial] -async fn test_return_addresses_of_subgroup() { - initialize_test_logger().await; - - let cxt = test_context_stationary().await; - let api = get_api(&cxt.node_proc.ws_url).await.unwrap(); - let rpc = get_rpc(&cxt.node_proc.ws_url).await.unwrap(); - - let result = return_all_addresses_of_subgroup(&api, &rpc, 0u8).await.unwrap(); - assert_eq!(result.len(), 1); -} - -#[tokio::test] -#[serial] -async fn test_send_and_receive_keys() { - initialize_test_logger().await; - clean_tests(); - - let alice = AccountKeyring::Alice; - let program_manager = AccountKeyring::Dave; - let signature_request_account = subxtAccountId32(alice.pair().public().0); - - let cxt = test_context_stationary().await; - setup_client().await; - let api = get_api(&cxt.node_proc.ws_url).await.unwrap(); - let rpc = get_rpc(&cxt.node_proc.ws_url).await.unwrap(); - - let share = { - let share = &KeyShare::::new_centralized(&mut rand_core::OsRng, 2, None)[0]; - entropy_kvdb::kv_manager::helpers::serialize(&share).unwrap() - }; - - let user_registration_info = UserRegistrationInfo { - key: alice.to_account_id().to_string(), - value: share.clone(), - proactive_refresh: false, - sig_request_address: Some(signature_request_account.clone()), - }; - - let (signer_alice, _) = get_signer_and_x25519_secret_from_mnemonic(DEFAULT_MNEMONIC).unwrap(); - - // First try sending a keyshare for a user who is not registering - should fail - let result = send_key( - &api, - &rpc, - &alice.to_account_id().into(), - &mut vec![ALICE_STASH_ADDRESS.clone(), alice.to_account_id().into()], - user_registration_info.clone(), - &signer_alice, - ) - .await; - - if let Err(UserErr::KeyShareRejected(error_message)) = result { - assert_eq!( - error_message, - "Not Registering error: Provided account ID not from a registering user".to_string() - ); - } else { - panic!("Should give not registering error"); - } - - // The happy path - the user is in a registering state - should succeed - let program_hash = store_program( - &api, - &rpc, - &program_manager.pair(), - TEST_PROGRAM_WASM_BYTECODE.to_owned(), - vec![], - vec![], - vec![], - ) - .await - .unwrap(); - - put_register_request_on_chain( - &api, - &rpc, - &alice.clone(), - alice.to_account_id().into(), - KeyVisibility::Public, - BoundedVec(vec![ProgramInstance { program_pointer: program_hash, program_config: vec![] }]), - ) - .await; - - // sends key to alice validator, while filtering out own key - send_key( - &api, - &rpc, - &alice.to_account_id().into(), - &mut vec![ALICE_STASH_ADDRESS.clone(), alice.to_account_id().into()], - user_registration_info.clone(), - &signer_alice, - ) - .await - .unwrap(); - - let get_query = UnsafeQuery::new(user_registration_info.key.clone(), vec![]).to_json(); - - let client = reqwest::Client::new(); - // check alice has new key - let response_new_key = client - .post("http://127.0.0.1:3001/unsafe/get") - .header("Content-Type", "application/json") - .body(get_query.clone()) - .send() - .await - .unwrap(); - - assert_eq!(response_new_key.bytes().await.unwrap(), &user_registration_info.value.clone()); - - // A keyshare can be overwritten when the user is still in a registering state - let some_other_share = { - let share = &KeyShare::::new_centralized(&mut rand_core::OsRng, 2, None)[0]; - entropy_kvdb::kv_manager::helpers::serialize(&share).unwrap() - }; - - let user_registration_info_overwrite = UserRegistrationInfo { - key: alice.to_account_id().to_string(), - value: some_other_share.clone(), - proactive_refresh: false, - sig_request_address: Some(signature_request_account.clone()), - }; - - let signed_message = serde_json::to_string( - &EncryptedSignedMessage::new( - signer_alice.signer(), - serde_json::to_vec(&user_registration_info_overwrite).unwrap(), - &X25519_PUBLIC_KEYS[0], - &[], - ) - .unwrap(), - ) - .unwrap(); - - let response_overwrites_key = client - .post("http://127.0.0.1:3001/user/receive_key") - .header("Content-Type", "application/json") - .body(signed_message.clone()) - .send() - .await - .unwrap(); - - assert_eq!(response_overwrites_key.status(), StatusCode::OK); - assert_eq!(response_overwrites_key.text().await.unwrap(), ""); - - // Check that the key has been successfully overwritten - let get_query = UnsafeQuery::new(user_registration_info.key.clone(), vec![]).to_json(); - let response_new_key = client - .post("http://127.0.0.1:3001/unsafe/get") - .header("Content-Type", "application/json") - .body(get_query.clone()) - .send() - .await - .unwrap(); - - assert_eq!(response_new_key.bytes().await.unwrap(), &some_other_share); - - // Try writing a 'forbidden key' - should fail - let user_registration_info_forbidden = UserRegistrationInfo { - key: "MNEMONIC".to_string(), - value: share.clone(), - proactive_refresh: false, - sig_request_address: Some(signature_request_account.clone()), - }; - - let signed_message = serde_json::to_string( - &EncryptedSignedMessage::new( - signer_alice.signer(), - serde_json::to_vec(&user_registration_info_forbidden).unwrap(), - &X25519_PUBLIC_KEYS[0], - &[], - ) - .unwrap(), - ) - .unwrap(); - - let response_overwrites_key = client - .post("http://127.0.0.1:3001/user/receive_key") - .header("Content-Type", "application/json") - .body(signed_message.clone()) - .send() - .await - .unwrap(); - - assert_eq!(response_overwrites_key.status(), StatusCode::INTERNAL_SERVER_ERROR); - assert_eq!(response_overwrites_key.text().await.unwrap(), "The given key is forbidden"); - - // Try sending a badly formed keyshare - should fail - let user_registration_info_bad_keyshare = UserRegistrationInfo { - key: alice.to_account_id().to_string(), - value: b"This will not deserialize to KeyShare".to_vec(), - proactive_refresh: false, - sig_request_address: Some(signature_request_account.clone()), - }; - - let signed_message = serde_json::to_string( - &EncryptedSignedMessage::new( - signer_alice.signer(), - serde_json::to_vec(&user_registration_info_bad_keyshare).unwrap(), - &X25519_PUBLIC_KEYS[0], - &[], - ) - .unwrap(), - ) - .unwrap(); - - let response_overwrites_key = client - .post("http://127.0.0.1:3001/user/receive_key") - .header("Content-Type", "application/json") - .body(signed_message.clone()) - .send() - .await - .unwrap(); - - assert_eq!(response_overwrites_key.status(), StatusCode::INTERNAL_SERVER_ERROR); - assert_eq!( - response_overwrites_key.text().await.unwrap(), - "Input Validation error: Not a valid keyshare" - ); - - clean_tests(); -} - -#[tokio::test] -#[serial] -async fn test_recover_key() { - initialize_test_logger().await; - clean_tests(); - - let cxt = test_node_process_testing_state(false).await; - setup_client().await; - let (_, bob_kv) = - create_clients("validator2".to_string(), vec![], vec![], &Some(ValidatorName::Bob)).await; - - let api = get_api(&cxt.ws_url).await.unwrap(); - let rpc = get_rpc(&cxt.ws_url).await.unwrap(); - let unsafe_query = UnsafeQuery::new("key".to_string(), vec![10]); - let client = reqwest::Client::new(); - - let _ = client - .post("http://127.0.0.1:3001/unsafe/put") - .header("Content-Type", "application/json") - .body(unsafe_query.clone().to_json()) - .send() - .await - .unwrap(); - - let (signer_alice, x25519_alice) = - get_signer_and_x25519_secret_from_mnemonic(DEFAULT_CHARLIE_MNEMONIC).unwrap(); - - recover_key(&api, &rpc, &bob_kv, &signer_alice, &x25519_alice, unsafe_query.key.clone()) - .await - .unwrap(); - let value = bob_kv.kv().get(&unsafe_query.key).await.unwrap(); - assert_eq!(value, unsafe_query.value); clean_tests(); } @@ -1377,7 +1125,7 @@ async fn test_faucet() { let entropy_api = get_api(&substrate_context.ws_url).await.unwrap(); let rpc = get_rpc(&substrate_context.ws_url).await.unwrap(); - let verifying_key = EVE_VERIFYING_KEY; //keyshare_option.clone().unwrap().verifying_key().to_encoded_point(true).as_bytes().to_vec(); + let verifying_key = EVE_VERIFYING_KEY; let verfiying_key_account_hash = blake2_256(&verifying_key); let verfiying_key_account = subxtAccountId32(verfiying_key_account_hash); diff --git a/pallets/registry/src/benchmarking.rs b/pallets/registry/src/benchmarking.rs index 07922d6c9..5e800cbc5 100644 --- a/pallets/registry/src/benchmarking.rs +++ b/pallets/registry/src/benchmarking.rs @@ -14,7 +14,7 @@ // along with this program. If not, see . //! Benchmarking setup for pallet-propgation -use entropy_shared::VERIFICATION_KEY_LENGTH; +use entropy_shared::{SIGNING_PARTY_SIZE, VERIFICATION_KEY_LENGTH}; use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller}; use frame_support::{ traits::{Currency, Get}, @@ -79,40 +79,45 @@ benchmarks! { } confirm_jump_start_done { - let c in 0 .. SIG_PARTIES as u32; + let c in 0 .. SIGNING_PARTY_SIZE as u32; let sig_req_account: T::AccountId = whitelisted_caller(); let validator_account: T::AccountId = whitelisted_caller(); - let threshold_account: T::AccountId = whitelisted_caller(); - let sig_party_size = MaxValidators::::get() / SIG_PARTIES as u32; - // add validators and a registering user - for i in 0..SIG_PARTIES { - let validators = add_non_syncing_validators::(sig_party_size, 0, i as u8); - >::insert(&threshold_account, &validators[i]); + let mut accounts = vec![]; + for i in 0..SIGNING_PARTY_SIZE { + accounts.push(account::("ts_account", i as u32, SEED)); + } + + let validators = add_non_syncing_validators::(SIGNING_PARTY_SIZE as u32, 0); + >::set(validators.clone()); + + for i in 0..SIGNING_PARTY_SIZE { + >::insert(accounts[i].clone(), &validators[i]); } + >::put(JumpStartDetails { jump_start_status: JumpStartStatus::InProgress(0), - confirmations: vec![1], - }); + confirmations: vec![validators[0].clone()], + }); let balance = ::Currency::minimum_balance() * 100u32.into(); - let _ = ::Currency::make_free_balance_be(&threshold_account, balance); - }: confirm_jump_start(RawOrigin::Signed(threshold_account), 0) + let _ = ::Currency::make_free_balance_be(&accounts[1], balance); + }: confirm_jump_start(RawOrigin::Signed(accounts[1].clone())) verify { assert_last_event::(Event::::FinishedNetworkJumpStart().into()); } confirm_jump_start_confirm { - let c in 0 .. SIG_PARTIES as u32; + let c in 0 .. SIGNING_PARTY_SIZE as u32; let sig_req_account: T::AccountId = whitelisted_caller(); let validator_account: T::AccountId = whitelisted_caller(); let threshold_account: T::AccountId = whitelisted_caller(); - let sig_party_size = MaxValidators::::get() / SIG_PARTIES as u32; // add validators and a registering user - for i in 0..SIG_PARTIES { - let validators = add_non_syncing_validators::(sig_party_size, 0, i as u8); + for i in 0..SIGNING_PARTY_SIZE { + let validators = add_non_syncing_validators::(SIGNING_PARTY_SIZE as u32, 0); + >::set(validators.clone()); >::insert(&threshold_account, &validators[i]); } >::put(JumpStartDetails { @@ -123,9 +128,11 @@ benchmarks! { let balance = ::Currency::minimum_balance() * 100u32.into(); let _ = ::Currency::make_free_balance_be(&threshold_account, balance); - }: confirm_jump_start(RawOrigin::Signed(threshold_account), 0) + }: confirm_jump_start(RawOrigin::Signed(threshold_account.clone())) verify { - assert_last_event::(Event::::JumpStartConfirmation(0).into()); + let validator_stash = + pallet_staking_extension::Pallet::::threshold_to_stash(&threshold_account).unwrap(); + assert_last_event::(Event::::JumpStartConfirmation(validator_stash, 1).into()); } register { @@ -256,8 +263,6 @@ benchmarks! { confirm_register_registering { let c in 1 .. MaxValidators::::get(); - // non synced validators - let n in 0 .. MaxValidators::::get(); let program = vec![0u8]; let configuration_schema = vec![1u8]; let auxiliary_data_schema = vec![2u8]; @@ -272,13 +277,12 @@ benchmarks! { let validator_account: T::AccountId = whitelisted_caller(); let threshold_account: T::AccountId = whitelisted_caller(); - // add validators and a registering user - // adds an extra validator so requires confirmations is > validators and doesn't confirm - let validators = add_non_syncing_validators::(c + 1, n); - >::insert(&threshold_account, &validators[(c -1) as usize]); - - >::set(validators); + // add validators and a registering user + // adds an extra validator so requires confirmations is > validators and doesn't confirm + let validators = add_non_syncing_validators::(c + 1, 0); + >::insert(&threshold_account, &validators[(c -1) as usize]); + >::set(validators); >::insert(&sig_req_account, RegisteringDetails:: { program_modification_account: sig_req_account.clone(), @@ -296,8 +300,7 @@ benchmarks! { confirm_register_failed_registering { let c in 1 .. MaxValidators::::get(); - // non synced validators - let n in 0 .. MaxValidators::::get(); + let program = vec![0u8]; let configuration_schema = vec![1u8]; let auxiliary_data_schema = vec![2u8]; @@ -314,7 +317,7 @@ benchmarks! { let random_account = account::("ts_account", 10, SEED); let invalid_verifying_key = BoundedVec::try_from(vec![2; VERIFICATION_KEY_LENGTH as usize]).unwrap(); // add validators and a registering user with different verifying key - let validators = add_non_syncing_validators::(c, n); + let validators = add_non_syncing_validators::(c, 0); >::insert(&threshold_account, &validators[(c -1) as usize]); let confirmations = vec![random_account.clone(); (c -1).try_into().unwrap()]; @@ -337,8 +340,7 @@ benchmarks! { confirm_register_registered { let c in 1 .. MaxValidators::::get(); - // non synced validators - let n in 0 .. MaxValidators::::get(); + let program = vec![0u8]; let configuration_schema = vec![1u8]; let auxiliary_data_schema = vec![2u8]; @@ -353,7 +355,7 @@ confirm_register_registered { let threshold_account: T::AccountId = whitelisted_caller(); let random_account = account::("ts_account", 10, SEED); // add validators, a registering user and one less than all confirmations - let validators = add_non_syncing_validators::(c, n); + let validators = add_non_syncing_validators::(c, 0); >::insert(&threshold_account, &validators[(c -1) as usize]); let confirmations = vec![random_account.clone(); (c -1).try_into().unwrap()]; diff --git a/pallets/registry/src/lib.rs b/pallets/registry/src/lib.rs index ac9e1df38..afcc3904b 100644 --- a/pallets/registry/src/lib.rs +++ b/pallets/registry/src/lib.rs @@ -120,11 +120,20 @@ pub mod pallet { pub version_number: u8, } /// Details of status of jump starting the network - #[derive(Clone, Encode, Decode, Eq, PartialEqNoBound, RuntimeDebug, TypeInfo, Default)] + #[derive( + Clone, + Encode, + Decode, + Eq, + PartialEqNoBound, + RuntimeDebug, + TypeInfo, + frame_support::DefaultNoBound, + )] #[scale_info(skip_type_params(T))] - pub struct JumpStartDetails { + pub struct JumpStartDetails { pub jump_start_status: JumpStartStatus, - pub confirmations: Vec, + pub confirmations: Vec, } #[pallet::genesis_config] @@ -195,7 +204,7 @@ pub mod pallet { /// A concept of what progress status the jumpstart is #[pallet::storage] #[pallet::getter(fn jump_start_progress)] - pub type JumpStartProgress = StorageValue<_, JumpStartDetails, ValueQuery>; + pub type JumpStartProgress = StorageValue<_, JumpStartDetails, ValueQuery>; // Pallets use events to inform users when important changes are made. // https://substrate.dev/docs/en/knowledgebase/runtime/events @@ -206,8 +215,8 @@ pub mod pallet { StartedNetworkJumpStart(), /// The network has been jump started successfully. FinishedNetworkJumpStart(), - /// The network has had a jump start confirmation. [signing_subgroup] - JumpStartConfirmation(u8), + /// The network has had a jump start confirmation. [who, confirmation_count] + JumpStartConfirmation(T::ValidatorId, u8), /// An account has signaled to be registered. [signature request account] SignalRegister(T::AccountId), /// An account has been registered. [who, verifying_key] @@ -294,57 +303,62 @@ pub mod pallet { ::WeightInfo::confirm_jump_start_confirm(SIGNING_PARTY_SIZE as u32) .max(::WeightInfo::confirm_jump_start_done(SIGNING_PARTY_SIZE as u32)) })] - pub fn confirm_jump_start( - origin: OriginFor, - signing_subgroup: u8, - ) -> DispatchResultWithPostInfo { + pub fn confirm_jump_start(origin: OriginFor) -> DispatchResultWithPostInfo { // check is validator let ts_server_account = ensure_signed(origin)?; + let validator_stash = pallet_staking_extension::Pallet::::threshold_to_stash(&ts_server_account) .ok_or(Error::::NoThresholdKey)?; - // let validator_subgroup = - // pallet_staking_extension::Pallet::::validator_to_subgroup(&validator_stash) - // .ok_or(Error::::SigningGroupError)?; - // ensure!(validator_subgroup == signing_subgroup, Error::::NotInSigningGroup); + let validators = pallet_session::Pallet::::validators(); + ensure!(validators.contains(&validator_stash), Error::::NotValidator); + let mut jump_start_info = JumpStartProgress::::get(); + // check in progress ensure!( matches!(jump_start_info.jump_start_status, JumpStartStatus::InProgress(_)), Error::::JumpStartNotInProgress ); - ensure!( - !jump_start_info.confirmations.contains(&signing_subgroup), + !jump_start_info.confirmations.contains(&validator_stash), Error::::AlreadyConfirmed ); - let confirmation_length = jump_start_info.confirmations.len() as u32; // TODO (#927): Add another check, such as a signature or a verifying key comparison, to // ensure that registration was indeed successful. // // If it fails we'll need to allow another jumpstart. - // - // TODO (Nando): make this a const - if jump_start_info.confirmations.len() == (3 - 1) as usize { - // T::SigningPartySize::get() - 1 { + if jump_start_info.confirmations.len() == (SIGNING_PARTY_SIZE - 1) { // registration finished, lock call + jump_start_info.confirmations.push(validator_stash); + let confirmations = jump_start_info.confirmations.len(); + JumpStartProgress::::put(JumpStartDetails { jump_start_status: JumpStartStatus::Done, confirmations: vec![], }); + Self::deposit_event(Event::FinishedNetworkJumpStart()); + return Ok(Some(::WeightInfo::confirm_jump_start_done( - confirmation_length, + confirmations as u32, )) .into()); } else { // Add confirmation wait for next one - jump_start_info.confirmations.push(signing_subgroup); + jump_start_info.confirmations.push(validator_stash.clone()); + let confirmations = jump_start_info.confirmations.len(); + JumpStartProgress::::put(jump_start_info); - Self::deposit_event(Event::JumpStartConfirmation(signing_subgroup)); + + Self::deposit_event(Event::JumpStartConfirmation( + validator_stash, + confirmations as u8, + )); + return Ok(Some(::WeightInfo::confirm_jump_start_confirm( - confirmation_length, + confirmations as u32, )) .into()); } diff --git a/pallets/registry/src/tests.rs b/pallets/registry/src/tests.rs index d51157e4e..7be263f81 100644 --- a/pallets/registry/src/tests.rs +++ b/pallets/registry/src/tests.rs @@ -14,7 +14,7 @@ // along with this program. If not, see . use codec::Encode; -use entropy_shared::{KeyVisibility, NETWORK_PARENT_KEY, VERIFICATION_KEY_LENGTH}; +use entropy_shared::{NETWORK_PARENT_KEY, VERIFICATION_KEY_LENGTH}; use frame_support::{ assert_noop, assert_ok, dispatch::{GetDispatchInfo, Pays}, @@ -24,7 +24,6 @@ use frame_support::{ use pallet_programs::ProgramInfo; use pallet_registry::Call as RegistryCall; use pallet_staking_extension::ServerInfo; -use sp_core::H256; use sp_runtime::{ traits::{Hash, SignedExtension}, transaction_validity::{TransactionValidity, ValidTransaction}, @@ -105,7 +104,7 @@ fn it_jumps_the_network() { Registry::jump_start_progress(), JumpStartDetails { jump_start_status: JumpStartStatus::InProgress(0), - confirmations: vec![] + confirmations: vec![], }, "Checks that jump start is in progress" ); @@ -133,38 +132,40 @@ fn it_jumps_the_network() { fn it_tests_jump_start_result() { new_test_ext().execute_with(|| { assert_noop!( - Registry::confirm_jump_start(RuntimeOrigin::signed(1), 0,), + Registry::confirm_jump_start(RuntimeOrigin::signed(1)), Error::::NoThresholdKey ); pallet_staking_extension::ThresholdToStash::::insert(1, 1); + + pallet_staking_extension::ThresholdToStash::::insert(7, 7); assert_noop!( - Registry::confirm_jump_start(RuntimeOrigin::signed(1), 3,), - Error::::NotInSigningGroup + Registry::confirm_jump_start(RuntimeOrigin::signed(7)), + Error::::NotValidator ); assert_noop!( - Registry::confirm_jump_start(RuntimeOrigin::signed(1), 0,), + Registry::confirm_jump_start(RuntimeOrigin::signed(1)), Error::::JumpStartNotInProgress ); // trigger jump start assert_ok!(Registry::jump_start_network(RuntimeOrigin::signed(1))); - assert_ok!(Registry::confirm_jump_start(RuntimeOrigin::signed(1), 0,)); + assert_ok!(Registry::confirm_jump_start(RuntimeOrigin::signed(1))); assert_eq!( Registry::jump_start_progress(), JumpStartDetails { jump_start_status: JumpStartStatus::InProgress(0), - confirmations: vec![0] + confirmations: vec![1] }, "Jump start recieves a confirmation" ); assert_noop!( - Registry::confirm_jump_start(RuntimeOrigin::signed(1), 0,), + Registry::confirm_jump_start(RuntimeOrigin::signed(1)), Error::::AlreadyConfirmed ); pallet_staking_extension::ThresholdToStash::::insert(2, 2); - assert_ok!(Registry::confirm_jump_start(RuntimeOrigin::signed(2), 1,)); + assert_ok!(Registry::confirm_jump_start(RuntimeOrigin::signed(2))); assert_eq!( Registry::jump_start_progress(), JumpStartDetails { jump_start_status: JumpStartStatus::Done, confirmations: vec![] },