diff --git a/pallets/admin-utils/src/benchmarking.rs b/pallets/admin-utils/src/benchmarking.rs index 65ccf629e..af5ddb8ee 100644 --- a/pallets/admin-utils/src/benchmarking.rs +++ b/pallets/admin-utils/src/benchmarking.rs @@ -238,17 +238,6 @@ mod benchmarks { _(RawOrigin::Root, 1u16/*netuid*/, 3u64/*interval*/)/*sudo_set_commit_reveal_weights_interval()*/; } - #[benchmark] - fn sudo_set_commit_reveal_weights_enabled() { - pallet_subtensor::Pallet::::init_new_network( - 1u16, /*netuid*/ - 1u16, /*sudo_tempo*/ - ); - - #[extrinsic_call] - _(RawOrigin::Root, 1u16/*netuid*/, true/*enabled*/)/*set_commit_reveal_weights_enabled*/; - } - #[benchmark] fn sudo_set_hotkey_emission_tempo() { pallet_subtensor::Pallet::::init_new_network( diff --git a/pallets/admin-utils/src/lib.rs b/pallets/admin-utils/src/lib.rs index 85c7ef62c..45cc734b3 100644 --- a/pallets/admin-utils/src/lib.rs +++ b/pallets/admin-utils/src/lib.rs @@ -960,28 +960,6 @@ pub mod pallet { Ok(()) } - /// The extrinsic enabled/disables commit/reaveal for a given subnet. - /// It is only callable by the root account or subnet owner. - /// The extrinsic will call the Subtensor pallet to set the value. - #[pallet::call_index(49)] - #[pallet::weight(T::WeightInfo::sudo_set_commit_reveal_weights_enabled())] - pub fn sudo_set_commit_reveal_weights_enabled( - origin: OriginFor, - netuid: u16, - enabled: bool, - ) -> DispatchResult { - pallet_subtensor::Pallet::::ensure_subnet_owner_or_root(origin, netuid)?; - - ensure!( - pallet_subtensor::Pallet::::if_subnet_exist(netuid), - Error::::SubnetDoesNotExist - ); - - pallet_subtensor::Pallet::::set_commit_reveal_weights_enabled(netuid, enabled); - log::debug!("ToggleSetWeightsCommitReveal( netuid: {:?} ) ", netuid); - Ok(()) - } - /// Enables or disables Liquid Alpha for a given subnet. /// /// # Parameters diff --git a/pallets/admin-utils/src/weights.rs b/pallets/admin-utils/src/weights.rs index bda9c7916..dff4e7765 100644 --- a/pallets/admin-utils/src/weights.rs +++ b/pallets/admin-utils/src/weights.rs @@ -61,7 +61,6 @@ pub trait WeightInfo { fn sudo_set_network_registration_allowed() -> Weight; fn sudo_set_tempo() -> Weight; fn sudo_set_commit_reveal_weights_interval() -> Weight; - fn sudo_set_commit_reveal_weights_enabled() -> Weight; } /// Weights for `pallet_admin_utils` using the Substrate node and recommended hardware. @@ -422,15 +421,6 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } - fn sudo_set_commit_reveal_weights_enabled() -> Weight { - // Proof Size summary in bytes: - // Measured: `1111` - // Estimated: `4697` - // Minimum execution time: 46_450_000 picoseconds. - Weight::from_parts(47_279_000, 4697) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) - } } // For backwards compatibility and tests. @@ -793,16 +783,4 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(1)) .saturating_add(RocksDbWeight::get().writes(1)) } - fn sudo_set_commit_reveal_weights_enabled() -> Weight { - // -- Extrinsic Time -- - // Model: - // Time ~= 19.78 - // µs - // Reads = 1 - // Writes = 1 - // Recorded proof Size = 456 - Weight::from_parts(19_780_000, 456) - .saturating_add(RocksDbWeight::get().reads(1_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) - } -} \ No newline at end of file +} diff --git a/pallets/admin-utils/tests/tests.rs b/pallets/admin-utils/tests/tests.rs index 442275052..5b6fb9786 100644 --- a/pallets/admin-utils/tests/tests.rs +++ b/pallets/admin-utils/tests/tests.rs @@ -1113,29 +1113,6 @@ fn test_sudo_set_min_delegate_take() { }); } -#[test] -fn test_sudo_set_commit_reveal_weights_enabled() { - new_test_ext().execute_with(|| { - let netuid: u16 = 1; - add_network(netuid, 10); - - let to_be_set: bool = true; - let init_value: bool = SubtensorModule::get_commit_reveal_weights_enabled(netuid); - - assert_ok!(AdminUtils::sudo_set_commit_reveal_weights_enabled( - <::RuntimeOrigin>::root(), - netuid, - to_be_set - )); - - assert!(init_value != to_be_set); - assert_eq!( - SubtensorModule::get_commit_reveal_weights_enabled(netuid), - to_be_set - ); - }); -} - #[test] fn test_sudo_set_target_stakes_per_interval() { new_test_ext().execute_with(|| { diff --git a/pallets/subtensor/src/benchmarks.rs b/pallets/subtensor/src/benchmarks.rs index 6fd1cbf8b..9636bb0a5 100644 --- a/pallets/subtensor/src/benchmarks.rs +++ b/pallets/subtensor/src/benchmarks.rs @@ -531,7 +531,6 @@ batch_reveal_weights { Subtensor::::init_new_network(netuid, tempo); Subtensor::::set_network_registration_allowed(netuid, true); Subtensor::::set_network_pow_registration_allowed(netuid, true); - Subtensor::::set_commit_reveal_weights_enabled(netuid, true); Subtensor::::set_weights_set_rate_limit(netuid, 0); // Disable rate limiting for benchmarking let block_number: u64 = Subtensor::::get_current_block_as_u64(); diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index e98ecbd6a..903c15007 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -82,11 +82,8 @@ mod dispatches { weights: Vec, version_key: u64, ) -> DispatchResult { - if !Self::get_commit_reveal_weights_enabled(netuid) { - return Self::do_set_weights(origin, netuid, dests, weights, version_key); - } - - Err(Error::::CommitRevealEnabled.into()) + return Self::do_set_weights(origin, netuid, dests, weights, version_key); + // Err(Error::::CommitRevealEnabled.into()) } /// ---- Used to commit a hash of your weight values to later be revealed. diff --git a/pallets/subtensor/src/rpc_info/subnet_info.rs b/pallets/subtensor/src/rpc_info/subnet_info.rs index bdd420821..dcf2bca4a 100644 --- a/pallets/subtensor/src/rpc_info/subnet_info.rs +++ b/pallets/subtensor/src/rpc_info/subnet_info.rs @@ -51,7 +51,7 @@ pub struct SubnetInfov2 { identity: Option, } -#[freeze_struct("55b472510f10e76a")] +#[freeze_struct("61ae927da2880759")] #[derive(Decode, Encode, PartialEq, Eq, Clone, Debug)] pub struct SubnetHyperparams { rho: Compact, @@ -77,7 +77,6 @@ pub struct SubnetHyperparams { adjustment_alpha: Compact, difficulty: Compact, commit_reveal_weights_interval: Compact, - commit_reveal_weights_enabled: bool, alpha_high: Compact, alpha_low: Compact, liquid_alpha_enabled: bool, @@ -253,7 +252,6 @@ impl Pallet { let adjustment_alpha = Self::get_adjustment_alpha(netuid); let difficulty = Self::get_difficulty_as_u64(netuid); let commit_reveal_periods = Self::get_reveal_period(netuid); - let commit_reveal_weights_enabled = Self::get_commit_reveal_weights_enabled(netuid); let liquid_alpha_enabled = Self::get_liquid_alpha_enabled(netuid); let (alpha_low, alpha_high): (u16, u16) = Self::get_alpha_values(netuid); @@ -281,7 +279,6 @@ impl Pallet { adjustment_alpha: adjustment_alpha.into(), difficulty: difficulty.into(), commit_reveal_weights_interval: commit_reveal_periods.into(), - commit_reveal_weights_enabled, alpha_high: alpha_high.into(), alpha_low: alpha_low.into(), liquid_alpha_enabled, diff --git a/pallets/subtensor/src/subnets/weights.rs b/pallets/subtensor/src/subnets/weights.rs index c511bceae..709f955e1 100644 --- a/pallets/subtensor/src/subnets/weights.rs +++ b/pallets/subtensor/src/subnets/weights.rs @@ -43,19 +43,13 @@ impl Pallet { log::debug!("do_commit_weights(hotkey: {:?}, netuid: {:?})", who, netuid); - // 2. Ensure commit-reveal is enabled. - ensure!( - Self::get_commit_reveal_weights_enabled(netuid), - Error::::CommitRevealDisabled - ); - - // 3. Ensure the hotkey is registered on the network. + // 2. Ensure the hotkey is registered on the network. ensure!( Self::is_hotkey_registered_on_network(netuid, &who), Error::::HotKeyNotRegisteredInSubNet ); - // 4. Check that the commit rate does not exceed the allowed frequency. + // 3. Check that the commit rate does not exceed the allowed frequency. let commit_block = Self::get_current_block_as_u64(); let neuron_uid = Self::get_uid_for_net_and_hotkey(netuid, &who)?; ensure!( @@ -63,15 +57,15 @@ impl Pallet { Error::::CommittingWeightsTooFast ); - // 5. Calculate the reveal blocks based on network tempo and reveal period. + // 4. Calculate the reveal blocks based on network tempo and reveal period. let (first_reveal_block, last_reveal_block) = Self::get_reveal_blocks(netuid, commit_block); - // 6. Retrieve or initialize the VecDeque of commits for the hotkey. + // 5. Retrieve or initialize the VecDeque of commits for the hotkey. WeightCommits::::try_mutate(netuid, &who, |maybe_commits| -> DispatchResult { let mut commits: VecDeque<(H256, u64, u64, u64)> = maybe_commits.take().unwrap_or_default(); - // 7. Remove any expired commits from the front of the queue. + // 6. Remove any expired commits from the front of the queue. while let Some((_, commit_block_existing, _, _)) = commits.front() { if Self::is_commit_expired(netuid, *commit_block_existing) { commits.pop_front(); @@ -80,10 +74,10 @@ impl Pallet { } } - // 8. Verify that the number of unrevealed commits is within the allowed limit. + // 7. Verify that the number of unrevealed commits is within the allowed limit. ensure!(commits.len() < 10, Error::::TooManyUnrevealedCommits); - // 9. Append the new commit with calculated reveal blocks. + // 8. Append the new commit with calculated reveal blocks. commits.push_back(( commit_hash, commit_block, @@ -91,16 +85,16 @@ impl Pallet { last_reveal_block, )); - // 10. Store the updated commits queue back to storage. + // 9. Store the updated commits queue back to storage. *maybe_commits = Some(commits); - // 11. Emit the WeightsCommitted event + // 10. Emit the WeightsCommitted event Self::deposit_event(Event::WeightsCommitted(who.clone(), netuid, commit_hash)); - // 12. Update the last commit block for the hotkey's UID. + // 11. Update the last commit block for the hotkey's UID. Self::set_last_update_for_uid(netuid, neuron_uid, commit_block); - // 13. Return success. + // 12. Return success. Ok(()) }) } @@ -154,19 +148,13 @@ impl Pallet { log::debug!("do_reveal_weights( hotkey:{:?} netuid:{:?})", who, netuid); - // --- 2. Ensure commit-reveal is enabled for the network. - ensure!( - Self::get_commit_reveal_weights_enabled(netuid), - Error::::CommitRevealDisabled - ); - - // --- 3. Mutate the WeightCommits to retrieve existing commits for the user. + // --- 2. Mutate the WeightCommits to retrieve existing commits for the user. WeightCommits::::try_mutate_exists(netuid, &who, |maybe_commits| -> DispatchResult { let commits = maybe_commits .as_mut() .ok_or(Error::::NoWeightsCommitFound)?; - // --- 4. Remove any expired commits from the front of the queue, collecting their hashes. + // --- 3. Remove any expired commits from the front of the queue, collecting their hashes. let mut expired_hashes = Vec::new(); while let Some((hash, commit_block, _, _)) = commits.front() { if Self::is_commit_expired(netuid, *commit_block) { @@ -178,7 +166,7 @@ impl Pallet { } } - // --- 5. Hash the provided data. + // --- 4. Hash the provided data. let provided_hash: H256 = BlakeTwo256::hash_of(&( who.clone(), netuid, @@ -188,7 +176,7 @@ impl Pallet { version_key, )); - // --- 6. After removing expired commits, check if any commits are left. + // --- 5. After removing expired commits, check if any commits are left. if commits.is_empty() { // Check if provided_hash matches any expired commits if expired_hashes.contains(&provided_hash) { @@ -198,42 +186,42 @@ impl Pallet { } } - // --- 7. Search for the provided_hash in the non-expired commits. + // --- 6. Search for the provided_hash in the non-expired commits. if let Some(position) = commits .iter() .position(|(hash, _, _, _)| *hash == provided_hash) { - // --- 8. Get the commit block for the commit being revealed. + // --- 7. Get the commit block for the commit being revealed. let (_, commit_block, _, _) = commits .get(position) .ok_or(Error::::NoWeightsCommitFound)?; - // --- 9. Ensure the commit is ready to be revealed in the current block range. + // --- 8. Ensure the commit is ready to be revealed in the current block range. ensure!( Self::is_reveal_block_range(netuid, *commit_block), Error::::RevealTooEarly ); - // --- 10. Remove all commits up to and including the one being revealed. + // --- 9. Remove all commits up to and including the one being revealed. for _ in 0..=position { commits.pop_front(); } - // --- 11. If the queue is now empty, remove the storage entry for the user. + // --- 10. If the queue is now empty, remove the storage entry for the user. if commits.is_empty() { *maybe_commits = None; } - // --- 12. Proceed to set the revealed weights. + // --- 11. Proceed to set the revealed weights. Self::do_set_weights(origin, netuid, uids.clone(), values.clone(), version_key)?; - // --- 13. Emit the WeightsRevealed event. + // --- 12. Emit the WeightsRevealed event. Self::deposit_event(Event::WeightsRevealed(who.clone(), netuid, provided_hash)); - // --- 14. Return ok. + // --- 13. Return ok. Ok(()) } else { - // --- 15. The provided_hash does not match any non-expired commits. + // --- 14. The provided_hash does not match any non-expired commits. if expired_hashes.contains(&provided_hash) { Err(Error::::ExpiredWeightCommit.into()) } else { @@ -308,19 +296,13 @@ impl Pallet { netuid ); - // --- 3. Ensure commit-reveal is enabled for the network. - ensure!( - Self::get_commit_reveal_weights_enabled(netuid), - Error::::CommitRevealDisabled - ); - - // --- 4. Mutate the WeightCommits to retrieve existing commits for the user. + // --- 3. Mutate the WeightCommits to retrieve existing commits for the user. WeightCommits::::try_mutate_exists(netuid, &who, |maybe_commits| -> DispatchResult { let commits = maybe_commits .as_mut() .ok_or(Error::::NoWeightsCommitFound)?; - // --- 5. Remove any expired commits from the front of the queue, collecting their hashes. + // --- 4. Remove any expired commits from the front of the queue, collecting their hashes. let mut expired_hashes = Vec::new(); while let Some((hash, commit_block, _, _)) = commits.front() { if Self::is_commit_expired(netuid, *commit_block) { @@ -332,7 +314,7 @@ impl Pallet { } } - // --- 6. Prepare to collect all provided hashes and their corresponding reveals. + // --- 5. Prepare to collect all provided hashes and their corresponding reveals. let mut provided_hashes = Vec::new(); let mut reveals = Vec::new(); let mut revealed_hashes: Vec = Vec::with_capacity(num_reveals); @@ -342,7 +324,7 @@ impl Pallet { .zip(values_list) .zip(salts_list.into_iter().zip(version_keys)) { - // --- 6a. Hash the provided data. + // --- 5a. Hash the provided data. let provided_hash: H256 = BlakeTwo256::hash_of(&( who.clone(), netuid, @@ -355,14 +337,14 @@ impl Pallet { reveals.push((uids, values, version_key, provided_hash)); } - // --- 7. Validate all reveals first to ensure atomicity. + // --- 6. Validate all reveals first to ensure atomicity. for (_uids, _values, _version_key, provided_hash) in &reveals { - // --- 7a. Check if the provided_hash is in the non-expired commits. + // --- 6a. Check if the provided_hash is in the non-expired commits. if !commits .iter() .any(|(hash, _, _, _)| *hash == *provided_hash) { - // --- 7b. If not found, check if it matches any expired commits. + // --- 6b. If not found, check if it matches any expired commits. if expired_hashes.contains(provided_hash) { return Err(Error::::ExpiredWeightCommit.into()); } else { @@ -370,33 +352,33 @@ impl Pallet { } } - // --- 7c. Find the commit corresponding to the provided_hash. + // --- 6c. Find the commit corresponding to the provided_hash. let commit = commits .iter() .find(|(hash, _, _, _)| *hash == *provided_hash) .ok_or(Error::::NoWeightsCommitFound)?; - // --- 7d. Check if the commit is within the reveal window. + // --- 6d. Check if the commit is within the reveal window. ensure!( Self::is_reveal_block_range(netuid, commit.1), Error::::RevealTooEarly ); } - // --- 8. All reveals are valid. Proceed to remove and process each reveal. + // --- 7. All reveals are valid. Proceed to remove and process each reveal. for (uids, values, version_key, provided_hash) in reveals { - // --- 8a. Find the position of the provided_hash. + // --- 7a. Find the position of the provided_hash. if let Some(position) = commits .iter() .position(|(hash, _, _, _)| *hash == provided_hash) { - // --- 8b. Remove the commit from the queue. + // --- 7b. Remove the commit from the queue. commits.remove(position); - // --- 8c. Proceed to set the revealed weights. + // --- 7c. Proceed to set the revealed weights. Self::do_set_weights(origin.clone(), netuid, uids, values, version_key)?; - // --- 8d. Collect the revealed hash. + // --- 7d. Collect the revealed hash. revealed_hashes.push(provided_hash); } else if expired_hashes.contains(&provided_hash) { return Err(Error::::ExpiredWeightCommit.into()); @@ -405,19 +387,19 @@ impl Pallet { } } - // --- 9. If the queue is now empty, remove the storage entry for the user. + // --- 8. If the queue is now empty, remove the storage entry for the user. if commits.is_empty() { *maybe_commits = None; } - // --- 10. Emit the WeightsBatchRevealed event with all revealed hashes. + // --- 9. Emit the WeightsBatchRevealed event with all revealed hashes. Self::deposit_event(Event::WeightsBatchRevealed( who.clone(), netuid, revealed_hashes, )); - // --- 11. Return ok. + // --- 10. Return ok. Ok(()) }) } @@ -539,13 +521,6 @@ impl Pallet { // --- 9. Ensure the uid is not setting weights faster than the weights_set_rate_limit. let neuron_uid = Self::get_uid_for_net_and_hotkey(netuid, &hotkey)?; - let current_block: u64 = Self::get_current_block_as_u64(); - if !Self::get_commit_reveal_weights_enabled(netuid) { - ensure!( - Self::check_rate_limit(netuid, neuron_uid, current_block), - Error::::SettingWeightsTooFast - ); - } // --- 10. Check that the neuron uid is an allowed validator permitted to set non-self weights. ensure!( @@ -586,12 +561,7 @@ impl Pallet { // --- 17. Set weights under netuid, uid double map entry. Weights::::insert(netuid, neuron_uid, zipped_weights); - // --- 18. Set the activity for the weights on this network. - if !Self::get_commit_reveal_weights_enabled(netuid) { - Self::set_last_update_for_uid(netuid, neuron_uid, current_block); - } - - // --- 19. Emit the tracking event. + // --- 18. Emit the tracking event. log::debug!( "WeightsSet( netuid:{:?}, neuron_uid:{:?} )", netuid, @@ -599,7 +569,7 @@ impl Pallet { ); Self::deposit_event(Event::WeightsSet(netuid, neuron_uid)); - // --- 20. Return ok. + // --- 19. Return ok. Ok(()) } diff --git a/pallets/subtensor/src/utils/misc.rs b/pallets/subtensor/src/utils/misc.rs index 57cc38786..9661805c8 100644 --- a/pallets/subtensor/src/utils/misc.rs +++ b/pallets/subtensor/src/utils/misc.rs @@ -486,13 +486,6 @@ impl Pallet { Kappa::::insert(netuid, kappa); Self::deposit_event(Event::KappaSet(netuid, kappa)); } - pub fn get_commit_reveal_weights_enabled(netuid: u16) -> bool { - CommitRevealWeightsEnabled::::get(netuid) - } - pub fn set_commit_reveal_weights_enabled(netuid: u16, enabled: bool) { - CommitRevealWeightsEnabled::::set(netuid, enabled); - } - pub fn get_rho(netuid: u16) -> u16 { Rho::::get(netuid) } diff --git a/pallets/subtensor/tests/weights.rs b/pallets/subtensor/tests/weights.rs index 573e5d351..37ce91fe3 100644 --- a/pallets/subtensor/tests/weights.rs +++ b/pallets/subtensor/tests/weights.rs @@ -1342,8 +1342,6 @@ fn test_set_weights_commit_reveal_enabled_error() { let version_key: u64 = 0; let hotkey = U256::from(1); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); - assert_err!( SubtensorModule::set_weights( RuntimeOrigin::signed(hotkey), @@ -1354,75 +1352,6 @@ fn test_set_weights_commit_reveal_enabled_error() { ), Error::::CommitRevealEnabled ); - - SubtensorModule::set_commit_reveal_weights_enabled(netuid, false); - - assert_ok!(SubtensorModule::set_weights( - RuntimeOrigin::signed(hotkey), - netuid, - uids, - weights, - version_key - )); - }); -} - -#[test] -fn test_reveal_weights_when_commit_reveal_disabled() { - new_test_ext(1).execute_with(|| { - let netuid: u16 = 1; - let uids: Vec = vec![0, 1]; - let weight_values: Vec = vec![10, 10]; - let salt: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; - let version_key: u64 = 0; - let hotkey: U256 = U256::from(1); - - let commit_hash: H256 = BlakeTwo256::hash_of(&( - hotkey, - netuid, - uids.clone(), - weight_values.clone(), - salt.clone(), - version_key, - )); - - System::set_block_number(0); - - let tempo: u16 = 5; - add_network(netuid, tempo, 0); - - // Register neurons and set up configurations - register_ok_neuron(netuid, U256::from(3), U256::from(4), 300_000); - register_ok_neuron(netuid, U256::from(1), U256::from(2), 100_000); - SubtensorModule::set_weights_set_rate_limit(netuid, 5); - SubtensorModule::set_validator_permit_for_uid(netuid, 0, true); - SubtensorModule::set_validator_permit_for_uid(netuid, 1, true); - - // Enable commit-reveal and commit - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); - assert_ok!(SubtensorModule::commit_weights( - RuntimeOrigin::signed(hotkey), - netuid, - commit_hash - )); - - step_epochs(1, netuid); - - // Disable commit-reveal before reveal - SubtensorModule::set_commit_reveal_weights_enabled(netuid, false); - - // Attempt to reveal, should fail with CommitRevealDisabled - assert_err!( - SubtensorModule::reveal_weights( - RuntimeOrigin::signed(hotkey), - netuid, - uids, - weight_values, - salt, - version_key, - ), - Error::::CommitRevealDisabled - ); }); } @@ -1456,7 +1385,6 @@ fn test_commit_reveal_weights_ok() { SubtensorModule::set_weights_set_rate_limit(netuid, 5); SubtensorModule::set_validator_permit_for_uid(netuid, 0, true); SubtensorModule::set_validator_permit_for_uid(netuid, 1, true); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); // Commit at block 0 assert_ok!(SubtensorModule::commit_weights( @@ -1508,7 +1436,6 @@ fn test_commit_reveal_tempo_interval() { SubtensorModule::set_weights_set_rate_limit(netuid, 5); SubtensorModule::set_validator_permit_for_uid(netuid, 0, true); SubtensorModule::set_validator_permit_for_uid(netuid, 1, true); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); // Commit at block 0 assert_ok!(SubtensorModule::commit_weights( @@ -1629,8 +1556,6 @@ fn test_commit_reveal_hash() { SubtensorModule::set_validator_permit_for_uid(netuid, 0, true); SubtensorModule::set_validator_permit_for_uid(netuid, 1, true); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); - let commit_hash: H256 = BlakeTwo256::hash_of(&( hotkey, netuid, @@ -1685,134 +1610,6 @@ fn test_commit_reveal_hash() { }); } -#[test] -fn test_commit_reveal_disabled_or_enabled() { - new_test_ext(1).execute_with(|| { - let netuid: u16 = 1; - let uids: Vec = vec![0, 1]; - let weight_values: Vec = vec![10, 10]; - let salt: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; - let version_key: u64 = 0; - let hotkey: U256 = U256::from(1); - - let commit_hash: H256 = BlakeTwo256::hash_of(&( - hotkey, - netuid, - uids.clone(), - weight_values.clone(), - salt.clone(), - version_key, - )); - - add_network(netuid, 5, 0); - System::set_block_number(0); - - register_ok_neuron(netuid, U256::from(3), U256::from(4), 300_000); - register_ok_neuron(netuid, U256::from(1), U256::from(2), 100_000); - SubtensorModule::set_weights_set_rate_limit(netuid, 5); - SubtensorModule::set_validator_permit_for_uid(netuid, 0, true); - SubtensorModule::set_validator_permit_for_uid(netuid, 1, true); - - // Disable commit/reveal - SubtensorModule::set_commit_reveal_weights_enabled(netuid, false); - - // Attempt to commit, should fail - assert_err!( - SubtensorModule::commit_weights(RuntimeOrigin::signed(hotkey), netuid, commit_hash), - Error::::CommitRevealDisabled - ); - - // Enable commit/reveal - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); - - // Commit should now succeed - assert_ok!(SubtensorModule::commit_weights( - RuntimeOrigin::signed(hotkey), - netuid, - commit_hash - )); - - step_epochs(1, netuid); - - // Reveal should succeed - assert_ok!(SubtensorModule::reveal_weights( - RuntimeOrigin::signed(hotkey), - netuid, - uids, - weight_values, - salt, - version_key, - )); - }); -} - -#[test] -fn test_toggle_commit_reveal_weights_and_set_weights() { - new_test_ext(1).execute_with(|| { - let netuid: u16 = 1; - let uids: Vec = vec![0, 1]; - let weight_values: Vec = vec![10, 10]; - let salt: Vec = vec![1, 2, 3, 4, 5, 6, 7, 8]; - let version_key: u64 = 0; - let hotkey: U256 = U256::from(1); - - let commit_hash: H256 = BlakeTwo256::hash_of(&( - hotkey, - netuid, - uids.clone(), - weight_values.clone(), - salt.clone(), - version_key, - )); - - add_network(netuid, 5, 0); - System::set_block_number(0); - - register_ok_neuron(netuid, U256::from(3), U256::from(4), 300_000); - register_ok_neuron(netuid, U256::from(1), U256::from(2), 100_000); - SubtensorModule::set_validator_permit_for_uid(netuid, 0, true); - SubtensorModule::set_validator_permit_for_uid(netuid, 1, true); - SubtensorModule::set_weights_set_rate_limit(netuid, 5); - - // Enable commit/reveal - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); - - // Commit at block 0 - assert_ok!(SubtensorModule::commit_weights( - RuntimeOrigin::signed(hotkey), - netuid, - commit_hash - )); - - step_epochs(1, netuid); - - // Reveal in the next epoch - assert_ok!(SubtensorModule::reveal_weights( - RuntimeOrigin::signed(hotkey), - netuid, - uids.clone(), - weight_values.clone(), - salt.clone(), - version_key, - )); - - // Disable commit/reveal - SubtensorModule::set_commit_reveal_weights_enabled(netuid, false); - - // Advance to allow setting weights (due to rate limit) - step_block(5); - - // Set weights directly - assert_ok!(SubtensorModule::set_weights( - RuntimeOrigin::signed(hotkey), - netuid, - uids, - weight_values, - version_key, - )); - }); -} - #[test] fn test_tempo_change_during_commit_reveal_process() { new_test_ext(0).execute_with(|| { @@ -1842,7 +1639,6 @@ fn test_tempo_change_during_commit_reveal_process() { SubtensorModule::set_weights_set_rate_limit(netuid, 5); SubtensorModule::set_validator_permit_for_uid(netuid, 0, true); SubtensorModule::set_validator_permit_for_uid(netuid, 1, true); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); assert_ok!(SubtensorModule::commit_weights( RuntimeOrigin::signed(hotkey), @@ -1975,7 +1771,6 @@ fn test_commit_reveal_multiple_commits() { SubtensorModule::set_weights_set_rate_limit(netuid, 0); SubtensorModule::set_validator_permit_for_uid(netuid, 0, true); SubtensorModule::set_validator_permit_for_uid(netuid, 1, true); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); // 1. Commit 10 times successfully let mut commit_info = Vec::new(); @@ -2315,8 +2110,6 @@ fn commit_reveal_set_weights( salt: Vec, version_key: u64, ) -> DispatchResult { - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); - let commit_hash: H256 = BlakeTwo256::hash_of(&( hotkey, netuid, @@ -2355,7 +2148,6 @@ fn test_expired_commits_handling_in_commit_and_reveal() { System::set_block_number(0); add_network(netuid, tempo, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 0); // Register neurons @@ -2539,7 +2331,6 @@ fn test_reveal_at_exact_epoch() { System::set_block_number(0); add_network(netuid, tempo, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 0); register_ok_neuron(netuid, U256::from(3), U256::from(4), 300_000); @@ -2686,7 +2477,6 @@ fn test_tempo_and_reveal_period_change_during_commit_reveal_process() { let initial_reveal_period: u64 = 1; add_network(netuid, initial_tempo, 0); SubtensorModule::set_reveal_period(netuid, initial_reveal_period); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 0); @@ -2861,7 +2651,6 @@ fn test_commit_reveal_order_enforcement() { System::set_block_number(0); add_network(netuid, tempo, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 0); register_ok_neuron(netuid, U256::from(3), U256::from(4), 300_000); @@ -2947,7 +2736,6 @@ fn test_reveal_at_exact_block() { System::set_block_number(0); add_network(netuid, tempo, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 0); register_ok_neuron(netuid, U256::from(3), U256::from(4), 300_000); @@ -3118,7 +2906,6 @@ fn test_successful_batch_reveal() { System::set_block_number(0); add_network(netuid, tempo, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 0); register_ok_neuron(netuid, U256::from(3), U256::from(4), 300_000); @@ -3180,7 +2967,6 @@ fn test_batch_reveal_with_expired_commits() { System::set_block_number(0); add_network(netuid, tempo, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 0); register_ok_neuron(netuid, U256::from(3), U256::from(4), 300_000); @@ -3282,8 +3068,6 @@ fn test_batch_reveal_with_invalid_input_lengths() { System::set_block_number(0); add_network(netuid, tempo, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); - // Base data for valid inputs let uids_list: Vec> = vec![vec![0, 1], vec![1, 0]]; let weight_values_list: Vec> = vec![vec![10, 20], vec![30, 40]]; @@ -3383,8 +3167,6 @@ fn test_batch_reveal_with_no_commits() { System::set_block_number(0); add_network(netuid, tempo, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); - // 1. Attempt to perform batch reveal without any commits let result = SubtensorModule::do_batch_reveal_weights( RuntimeOrigin::signed(hotkey), @@ -3411,8 +3193,6 @@ fn test_batch_reveal_before_reveal_period() { System::set_block_number(0); add_network(netuid, tempo, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); - register_ok_neuron(netuid, U256::from(3), U256::from(4), 300_000); register_ok_neuron(netuid, hotkey, U256::from(2), 100_000); SubtensorModule::set_weights_set_rate_limit(netuid, 0); @@ -3468,8 +3248,6 @@ fn test_batch_reveal_after_commits_expired() { System::set_block_number(0); add_network(netuid, tempo, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); - register_ok_neuron(netuid, U256::from(3), U256::from(4), 300_000); register_ok_neuron(netuid, hotkey, U256::from(2), 100_000); SubtensorModule::set_weights_set_rate_limit(netuid, 0); @@ -3534,35 +3312,6 @@ fn test_batch_reveal_after_commits_expired() { }); } -#[test] -fn test_batch_reveal_when_commit_reveal_disabled() { - new_test_ext(1).execute_with(|| { - let netuid: u16 = 1; - let hotkey = U256::from(1); - let version_keys: Vec = vec![0]; - let uids_list: Vec> = vec![vec![0, 1]]; - let weight_values_list: Vec> = vec![vec![10, 20]]; - let salts_list: Vec> = vec![vec![0u16; 8]]; - let tempo: u16 = 100; - - System::set_block_number(0); - add_network(netuid, tempo, 0); - - SubtensorModule::set_commit_reveal_weights_enabled(netuid, false); - - // 1. Attempt to perform batch reveal when commit-reveal is disabled - let result = SubtensorModule::do_batch_reveal_weights( - RuntimeOrigin::signed(hotkey), - netuid, - uids_list, - weight_values_list, - salts_list, - version_keys, - ); - assert_err!(result, Error::::CommitRevealDisabled); - }); -} - #[test] fn test_batch_reveal_with_out_of_order_commits() { new_test_ext(1).execute_with(|| { @@ -3576,7 +3325,6 @@ fn test_batch_reveal_with_out_of_order_commits() { System::set_block_number(0); add_network(netuid, tempo, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 0); register_ok_neuron(netuid, U256::from(3), U256::from(4), 300_000); @@ -3671,7 +3419,6 @@ fn test_highly_concurrent_commits_and_reveals_with_multiple_hotkeys() { // ==== Setup Network ==== add_network(netuid, initial_tempo, 0); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); SubtensorModule::set_weights_set_rate_limit(netuid, 0); SubtensorModule::set_reveal_period(netuid, initial_reveal_period); SubtensorModule::set_max_registrations_per_block(netuid, u16::MAX); @@ -3970,7 +3717,6 @@ fn test_get_reveal_blocks() { SubtensorModule::set_weights_set_rate_limit(netuid, 5); SubtensorModule::set_validator_permit_for_uid(netuid, 0, true); SubtensorModule::set_validator_permit_for_uid(netuid, 1, true); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); // **6. Commit Weights at Block 0** assert_ok!(SubtensorModule::commit_weights( @@ -4088,7 +3834,6 @@ fn test_commit_weights_rate_limit() { SubtensorModule::set_weights_set_rate_limit(netuid, 10); // Rate limit is 10 blocks SubtensorModule::set_validator_permit_for_uid(netuid, 0, true); SubtensorModule::set_validator_permit_for_uid(netuid, 1, true); - SubtensorModule::set_commit_reveal_weights_enabled(netuid, true); let neuron_uid = SubtensorModule::get_uid_for_net_and_hotkey(netuid, &hotkey).expect("expected uid"); @@ -4127,64 +3872,5 @@ fn test_commit_weights_rate_limit() { netuid, new_commit_hash )); - - SubtensorModule::set_commit_reveal_weights_enabled(netuid, false); - let weights_keys: Vec = vec![0]; - let weight_values: Vec = vec![1]; - - assert_err!( - SubtensorModule::set_weights( - RuntimeOrigin::signed(hotkey), - netuid, - weights_keys.clone(), - weight_values.clone(), - 0 - ), - Error::::SettingWeightsTooFast - ); - - step_block(10); - - assert_ok!(SubtensorModule::set_weights( - RuntimeOrigin::signed(hotkey), - netuid, - weights_keys.clone(), - weight_values.clone(), - 0 - )); - - assert_err!( - SubtensorModule::set_weights( - RuntimeOrigin::signed(hotkey), - netuid, - weights_keys.clone(), - weight_values.clone(), - 0 - ), - Error::::SettingWeightsTooFast - ); - - step_block(5); - - assert_err!( - SubtensorModule::set_weights( - RuntimeOrigin::signed(hotkey), - netuid, - weights_keys.clone(), - weight_values.clone(), - 0 - ), - Error::::SettingWeightsTooFast - ); - - step_block(5); - - assert_ok!(SubtensorModule::set_weights( - RuntimeOrigin::signed(hotkey), - netuid, - weights_keys.clone(), - weight_values.clone(), - 0 - )); }); }