From 346d664b02314256a7be2b47683602a54d82c28c Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Mon, 16 Dec 2024 14:38:00 -0500 Subject: [PATCH] remove Test reshare block --- crates/shared/src/constants.rs | 3 -- .../src/validator/tests.rs | 35 ++++++++++++++++--- node/cli/src/chain_spec/dev.rs | 1 - node/cli/src/chain_spec/integration_tests.rs | 6 ---- node/cli/src/chain_spec/testnet.rs | 1 - pallets/attestation/src/mock.rs | 1 - pallets/propagation/src/mock.rs | 1 - pallets/registry/src/mock.rs | 1 - pallets/staking/src/lib.rs | 20 +---------- pallets/staking/src/mock.rs | 1 - 10 files changed, 32 insertions(+), 38 deletions(-) diff --git a/crates/shared/src/constants.rs b/crates/shared/src/constants.rs index ea5badf27..7b8ec635a 100644 --- a/crates/shared/src/constants.rs +++ b/crates/shared/src/constants.rs @@ -74,8 +74,5 @@ pub const MAX_SIGNERS: u8 = 15; /// Threshold for those signers pub const SIGNER_THRESHOLD: u8 = 2; -/// For testing to line up chain mock data and reshare_test -pub const TEST_RESHARE_BLOCK_NUMBER: u32 = 10; - /// Program version number, must be incremented if version number changes pub const PROGRAM_VERSION_NUMBER: u8 = 0; diff --git a/crates/threshold-signature-server/src/validator/tests.rs b/crates/threshold-signature-server/src/validator/tests.rs index e47e28f70..1bc4e2fad 100644 --- a/crates/threshold-signature-server/src/validator/tests.rs +++ b/crates/threshold-signature-server/src/validator/tests.rs @@ -75,6 +75,7 @@ async fn test_reshare_basic() { let api = get_api(&context[0].ws_url).await.unwrap(); let rpc = get_rpc(&context[0].ws_url).await.unwrap(); let alice_stash = AccountKeyring::AliceStash; + let dave_stash = AccountKeyring::DaveStash; let client = reqwest::Client::new(); // Get current signers @@ -96,6 +97,27 @@ async fn test_reshare_basic() { let key_share = unsafe_get(&client, hex::encode(NETWORK_PARENT_KEY), port).await; assert!(!key_share.is_empty()); } + next_signers.remove(0); + let binding = dave_stash.to_account_id().into(); + next_signers.push(&binding); + let block_number = rpc.chain_get_header(None).await.unwrap().unwrap().number + 1; + let storage_address_next_signers = entropy::storage().staking_extension().next_signers(); + let value_next_signers = + NextSignerInfo { confirmations: vec![], next_signers: next_signers.clone() }; + // Add reshare + let call = RuntimeCall::System(SystemsCall::set_storage { + items: vec![(storage_address_next_signers.to_root_bytes(), value_next_signers.encode())], + }); + call_set_storage(&api, &rpc, call).await; + + let storage_address_reshare_data = entropy::storage().staking_extension().reshare_data(); + let value_reshare_info = + ReshareInfo { block_number, new_signers: vec![dave_stash.public().encode()] }; + // Add reshare + let call = RuntimeCall::System(SystemsCall::set_storage { + items: vec![(storage_address_reshare_data.to_root_bytes(), value_reshare_info.encode())], + }); + call_set_storage(&api, &rpc, call).await; let key_share_before = unsafe_get(&client, hex::encode(NETWORK_PARENT_KEY), 3002).await; @@ -110,7 +132,7 @@ async fn test_reshare_basic() { if new_signer_ids != old_signer_ids { break Ok(new_signer_ids); } - if i > 120 { + if i > 240 { break Err("Timed out waiting for reshare"); } i += 1; @@ -187,8 +209,12 @@ async fn test_reshare_basic() { let key_share = unsafe_get(&client, hex::encode(NETWORK_PARENT_KEY), port).await; assert!(!key_share.is_empty()); } - let block_number = rpc.chain_get_header(None).await.unwrap().unwrap().number + 2; - let key_share_before_2 = unsafe_get(&client, hex::encode(NETWORK_PARENT_KEY), 3002).await; + let block_number = rpc.chain_get_header(None).await.unwrap().unwrap().number + 1; + let key_share_before_2 = unsafe_get(&client, hex::encode(NETWORK_PARENT_KEY), 3003).await; + + next_signers.remove(0); + let binding = alice_stash.to_account_id().into(); + next_signers.push(&binding); let storage_address_next_signers = entropy::storage().staking_extension().next_signers(); let value_next_signers = NextSignerInfo { confirmations: vec![], next_signers }; @@ -210,7 +236,7 @@ async fn test_reshare_basic() { // wait for roatate keyshare tokio::time::sleep(std::time::Duration::from_secs(60)).await; - let key_share_after_2 = unsafe_get(&client, hex::encode(NETWORK_PARENT_KEY), 3002).await; + let key_share_after_2 = unsafe_get(&client, hex::encode(NETWORK_PARENT_KEY), 3003).await; assert_ne!(key_share_before_2, key_share_after_2); clean_tests(); @@ -266,6 +292,7 @@ async fn test_reshare_validation_fail() { assert_eq!(err_stale_data, Err("Data is stale".to_string())); let block_number = rpc.chain_get_header(None).await.unwrap().unwrap().number + 1; + ocw_message.block_number = block_number; run_to_block(&rpc, block_number + 1).await; diff --git a/node/cli/src/chain_spec/dev.rs b/node/cli/src/chain_spec/dev.rs index bdbdcf4a4..8ee8e1179 100644 --- a/node/cli/src/chain_spec/dev.rs +++ b/node/cli/src/chain_spec/dev.rs @@ -250,7 +250,6 @@ pub fn development_genesis_config( }) .collect::>(), proactive_refresh_data: (vec![], vec![]), - mock_signer_rotate: (false, vec![], vec![]), jump_started_signers: None, }, "elections": ElectionsConfig { diff --git a/node/cli/src/chain_spec/integration_tests.rs b/node/cli/src/chain_spec/integration_tests.rs index 18a9523ea..192f7f646 100644 --- a/node/cli/src/chain_spec/integration_tests.rs +++ b/node/cli/src/chain_spec/integration_tests.rs @@ -66,10 +66,6 @@ pub fn integration_tests_config(jumpstarted: bool) -> ChainSpec { ], vec![], get_account_id_from_seed::("Alice"), - vec![ - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - ], jump_started_signers, )) .build() @@ -87,7 +83,6 @@ pub fn integration_tests_genesis_config( )>, initial_nominators: Vec, root_key: AccountId, - mock_signer_rotate_data: Vec, jump_started_signers: Option>, ) -> serde_json::Value { // Note that any endowed_accounts added here will be included in the `elections` and @@ -229,7 +224,6 @@ pub fn integration_tests_genesis_config( ], vec![PREGENERATED_NETWORK_VERIFYING_KEY.to_vec(), DAVE_VERIFYING_KEY.to_vec()], ), - mock_signer_rotate: (true, mock_signer_rotate_data, vec![get_account_id_from_seed::("Dave//stash")]), jump_started_signers, }, "elections": ElectionsConfig { diff --git a/node/cli/src/chain_spec/testnet.rs b/node/cli/src/chain_spec/testnet.rs index 590e14be3..64874f068 100644 --- a/node/cli/src/chain_spec/testnet.rs +++ b/node/cli/src/chain_spec/testnet.rs @@ -427,7 +427,6 @@ pub fn testnet_genesis_config( }) .collect::>(), proactive_refresh_data: (vec![], vec![]), - mock_signer_rotate: (false, vec![], vec![]), jump_started_signers: None, }, "elections": ElectionsConfig { diff --git a/pallets/attestation/src/mock.rs b/pallets/attestation/src/mock.rs index 32cd7369d..7378287ce 100644 --- a/pallets/attestation/src/mock.rs +++ b/pallets/attestation/src/mock.rs @@ -360,7 +360,6 @@ pub fn new_test_ext() -> sp_io::TestExternalities { (5, (0, NULL_ARR, vec![20], pck_encoded.to_vec().try_into().unwrap())), ], proactive_refresh_data: (vec![], vec![]), - mock_signer_rotate: (false, vec![], vec![]), jump_started_signers: None, }; pallet_staking_extension.assimilate_storage(&mut t).unwrap(); diff --git a/pallets/propagation/src/mock.rs b/pallets/propagation/src/mock.rs index 1fce23e1c..d379ce57f 100644 --- a/pallets/propagation/src/mock.rs +++ b/pallets/propagation/src/mock.rs @@ -406,7 +406,6 @@ pub fn new_test_ext() -> sp_io::TestExternalities { (2, (4, NULL_ARR, vec![11], BoundedVec::with_max_capacity())), ], proactive_refresh_data: (vec![], vec![]), - mock_signer_rotate: (false, vec![], vec![]), jump_started_signers: None, }; diff --git a/pallets/registry/src/mock.rs b/pallets/registry/src/mock.rs index 76054af22..b6cb1be25 100644 --- a/pallets/registry/src/mock.rs +++ b/pallets/registry/src/mock.rs @@ -393,7 +393,6 @@ pub fn new_test_ext() -> sp_io::TestExternalities { (7, (4, NULL_ARR, vec![50], BoundedVec::with_max_capacity())), ], proactive_refresh_data: (vec![], vec![]), - mock_signer_rotate: (false, vec![], vec![]), jump_started_signers: None, }; diff --git a/pallets/staking/src/lib.rs b/pallets/staking/src/lib.rs index 128b7cf4e..1d92324b6 100644 --- a/pallets/staking/src/lib.rs +++ b/pallets/staking/src/lib.rs @@ -61,7 +61,7 @@ use sp_staking::SessionIndex; pub mod pallet { use entropy_shared::{ QuoteContext, ValidatorInfo, X25519PublicKey, MAX_SIGNERS, - PREGENERATED_NETWORK_VERIFYING_KEY, TEST_RESHARE_BLOCK_NUMBER, VERIFICATION_KEY_LENGTH, + PREGENERATED_NETWORK_VERIFYING_KEY, VERIFICATION_KEY_LENGTH, }; use frame_support::{ dispatch::{DispatchResult, DispatchResultWithPostInfo}, @@ -262,8 +262,6 @@ pub mod pallet { pub threshold_servers: Vec>, /// validator info and accounts to take part in proactive refresh pub proactive_refresh_data: (Vec, Vec>), - /// validator info and account new signer to take part in a reshare - pub mock_signer_rotate: (bool, Vec, Vec), /// Whether to begin in an already jumpstarted state in order to be able to test signing /// using pre-generated keyshares pub jump_started_signers: Option>, @@ -295,22 +293,6 @@ pub mod pallet { proactive_refresh_keys: self.proactive_refresh_data.1.clone(), }; ProactiveRefresh::::put(refresh_info); - // mocks a signer rotation for tss new_reshare tests - if self.mock_signer_rotate.0 { - let next_signers = &mut self.mock_signer_rotate.1.clone(); - let mut new_signers = vec![]; - for new_signer in self.mock_signer_rotate.2.clone() { - next_signers.push(new_signer.clone()); - new_signers.push(new_signer.encode()) - } - let next_signers = next_signers.to_vec(); - NextSigners::::put(NextSignerInfo { next_signers, confirmations: vec![] }); - ReshareData::::put(ReshareInfo { - // To give enough time for test_reshare setup - block_number: TEST_RESHARE_BLOCK_NUMBER.into(), - new_signers, - }) - } if let Some(jump_started_signers) = &self.jump_started_signers { Signers::::put(jump_started_signers.clone()); diff --git a/pallets/staking/src/mock.rs b/pallets/staking/src/mock.rs index 21a35e06e..5162ccba9 100644 --- a/pallets/staking/src/mock.rs +++ b/pallets/staking/src/mock.rs @@ -441,7 +441,6 @@ pub fn new_test_ext() -> sp_io::TestExternalities { (6, (8, NULL_ARR, vec![40], BoundedVec::with_max_capacity())), ], proactive_refresh_data: (vec![], vec![]), - mock_signer_rotate: (false, vec![], vec![]), jump_started_signers: None, }; pallet_balances.assimilate_storage(&mut t).unwrap();