diff --git a/pallets/subtensor/src/benchmarks.rs b/pallets/subtensor/src/benchmarks.rs index 9636bb0a5..b986dc6e4 100644 --- a/pallets/subtensor/src/benchmarks.rs +++ b/pallets/subtensor/src/benchmarks.rs @@ -36,45 +36,6 @@ benchmarks! { }: register( RawOrigin::Signed( hotkey.clone() ), netuid, block_number, nonce, work, hotkey.clone(), coldkey.clone() ) - benchmark_set_weights { - - // This is a whitelisted caller who can make transaction without weights. - let netuid: u16 = 1; - let version_key: u64 = 1; - let tempo: u16 = 1; - let modality: u16 = 0; - - Subtensor::::init_new_network(netuid, tempo); - Subtensor::::set_max_allowed_uids( netuid, 4096 ); - - Subtensor::::set_network_registration_allowed( netuid, true ); - Subtensor::::set_max_registrations_per_block( netuid, 4096 ); - Subtensor::::set_target_registrations_per_interval( netuid, 4096 ); - - let mut seed : u32 = 1; - let mut dests: Vec = vec![]; - let mut weights: Vec = vec![]; - let signer : T::AccountId = account("Alice", 0, seed); - - for id in 0..4096_u16 { - let hotkey: T::AccountId = account("Alice", 0, seed); - let coldkey: T::AccountId = account("Test", 0, seed); - seed += 1; - - Subtensor::::set_burn(netuid, 1); - let amount_to_be_staked = 1000000u32.into(); - Subtensor::::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked); - - Subtensor::::do_burned_registration(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey.clone())?; - - let uid = Subtensor::::get_uid_for_net_and_hotkey(netuid, &hotkey.clone()).unwrap(); - Subtensor::::set_validator_permit_for_uid(netuid, uid, true); - dests.push(id); - weights.push(id); - } - - }: set_weights(RawOrigin::Signed( signer.clone() ), netuid, dests, weights, version_key) - benchmark_become_delegate { // This is a whitelisted caller who can make transaction without weights. diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index 1155076ae..483b534d5 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -1488,18 +1488,6 @@ where Err(InvalidTransaction::Custom(6).into()) } } - Some(Call::set_weights { netuid, .. }) => { - if Self::check_weights_min_stake(who, *netuid) { - let priority: u64 = Self::get_priority_set_weights(who, *netuid); - Ok(ValidTransaction { - priority, - longevity: 1, - ..Default::default() - }) - } else { - Err(InvalidTransaction::Custom(3).into()) - } - } Some(Call::set_root_weights { netuid, hotkey, .. }) => { if Self::check_weights_min_stake(hotkey, *netuid) { let priority: u64 = Self::get_priority_set_weights(hotkey, *netuid); @@ -1589,10 +1577,6 @@ where let transaction_fee = 0; Ok((CallType::RemoveStake, transaction_fee, who.clone())) } - Some(Call::set_weights { .. }) => { - let transaction_fee = 0; - Ok((CallType::SetWeights, transaction_fee, who.clone())) - } Some(Call::commit_weights { .. }) => { let transaction_fee = 0; Ok((CallType::SetWeights, transaction_fee, who.clone())) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 903c15007..788d40059 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -13,79 +13,6 @@ mod dispatches { /// Dispatchable functions must be annotated with a weight and must return a DispatchResult. #[pallet::call] impl Pallet { - /// --- Sets the caller weights for the incentive mechanism. The call can be - /// made from the hotkey account so is potentially insecure, however, the damage - /// of changing weights is minimal if caught early. This function includes all the - /// checks that the passed weights meet the requirements. Stored as u16s they represent - /// rational values in the range [0,1] which sum to 1 and can be interpreted as - /// probabilities. The specific weights determine how inflation propagates outward - /// from this peer. - /// - /// Note: The 16 bit integers weights should represent 1.0 as the max u16. - /// However, the function normalizes all integers to u16_max anyway. This means that if the sum of all - /// elements is larger or smaller than the amount of elements * u16_max, all elements - /// will be corrected for this deviation. - /// - /// # Args: - /// * `origin`: (Origin): - /// - The caller, a hotkey who wishes to set their weights. - /// - /// * `netuid` (u16): - /// - The network uid we are setting these weights on. - /// - /// * `dests` (Vec): - /// - The edge endpoint for the weight, i.e. j for w_ij. - /// - /// * 'weights' (Vec): - /// - The u16 integer encoded weights. Interpreted as rational - /// values in the range [0,1]. They must sum to in32::MAX. - /// - /// * 'version_key' ( u64 ): - /// - The network version key to check if the validator is up to date. - /// - /// # Event: - /// * WeightsSet; - /// - On successfully setting the weights on chain. - /// - /// # Raises: - /// * 'SubNetworkDoesNotExist': - /// - Attempting to set weights on a non-existent network. - /// - /// * 'NotRegistered': - /// - Attempting to set weights from a non registered account. - /// - /// * 'WeightVecNotEqualSize': - /// - Attempting to set weights with uids not of same length. - /// - /// * 'DuplicateUids': - /// - Attempting to set weights with duplicate uids. - /// - /// * 'UidsLengthExceedUidsInSubNet': - /// - Attempting to set weights above the max allowed uids. - /// - /// * 'UidVecContainInvalidOne': - /// - Attempting to set weights with invalid uids. - /// - /// * 'WeightVecLengthIsLow': - /// - Attempting to set weights with fewer weights than min. - /// - /// * 'MaxWeightExceeded': - /// - Attempting to set weights with max value exceeding limit. - #[pallet::call_index(0)] - #[pallet::weight((Weight::from_parts(22_060_000_000, 0) - .saturating_add(T::DbWeight::get().reads(4106)) - .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] - pub fn set_weights( - origin: OriginFor, - netuid: u16, - dests: Vec, - weights: Vec, - version_key: u64, - ) -> DispatchResult { - 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. /// /// # Args: diff --git a/pallets/subtensor/src/subnets/weights.rs b/pallets/subtensor/src/subnets/weights.rs index 709f955e1..d11b0c3fc 100644 --- a/pallets/subtensor/src/subnets/weights.rs +++ b/pallets/subtensor/src/subnets/weights.rs @@ -404,7 +404,7 @@ impl Pallet { }) } - /// ---- The implementation for the extrinsic set_weights. + /// ---- Used by reveal weights to set the weights on chain. /// /// # Args: /// * 'origin': (RuntimeOrigin): diff --git a/pallets/subtensor/tests/children.rs b/pallets/subtensor/tests/children.rs index 644833345..507040fd0 100644 --- a/pallets/subtensor/tests/children.rs +++ b/pallets/subtensor/tests/children.rs @@ -1882,7 +1882,7 @@ fn test_childkey_single_parent_emission() { let uids: Vec = vec![1]; // Only set weight for the child (UID 1) let values: Vec = vec![u16::MAX]; // Use maximum value for u16 let version_key = SubtensorModule::get_weights_version_key(netuid); - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( origin, netuid, uids, @@ -2028,7 +2028,7 @@ fn test_childkey_multiple_parents_emission() { let uids: Vec = vec![0, 1, 2]; let values: Vec = vec![0, 65354, 65354]; let version_key = SubtensorModule::get_weights_version_key(netuid); - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(weight_setter), netuid, uids, @@ -2205,7 +2205,7 @@ fn test_parent_child_chain_emission() { // Ensure we can set weights without rate limiting SubtensorModule::set_weights_set_rate_limit(netuid, 0); - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( origin, netuid, uids, @@ -2350,7 +2350,7 @@ fn test_dynamic_parent_child_relationships() { // Ensure we can set weights without rate limiting SubtensorModule::set_weights_set_rate_limit(netuid, 0); - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( origin, netuid, uids, @@ -3084,7 +3084,7 @@ fn test_rank_trust_incentive_calculation_with_parent_child() { .chain(other_validators.iter().map(|(h, _)| h)) .chain(std::iter::once(&child_hotkey)) { - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(*hotkey), netuid, all_uids.clone(), @@ -3131,7 +3131,7 @@ fn test_rank_trust_incentive_calculation_with_parent_child() { )); // Child now sets weights as a validator - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(child_hotkey), netuid, all_uids.clone(), @@ -3293,7 +3293,7 @@ fn test_childkey_set_weights_single_parent() { let uids: Vec = vec![1]; // Only set weight for the child (UID 1) let values: Vec = vec![u16::MAX]; // Use maximum value for u16 let version_key = SubtensorModule::get_weights_version_key(netuid); - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( origin, netuid, uids.clone(), @@ -3312,7 +3312,7 @@ fn test_childkey_set_weights_single_parent() { // Check the child cannot set weights assert_noop!( - SubtensorModule::set_weights( + SubtensorModule::do_set_weights( RuntimeOrigin::signed(child), netuid, uids.clone(), @@ -3334,7 +3334,7 @@ fn test_childkey_set_weights_single_parent() { ); // Check the child can set weights - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(child), netuid, uids, @@ -3395,7 +3395,7 @@ fn test_set_weights_no_parent() { // Check the hotkey cannot set weights assert_noop!( - SubtensorModule::set_weights( + SubtensorModule::do_set_weights( RuntimeOrigin::signed(hotkey), netuid, uids.clone(), @@ -3417,7 +3417,7 @@ fn test_set_weights_no_parent() { ); // Check the hotkey can set weights - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(hotkey), netuid, uids, diff --git a/pallets/subtensor/tests/epoch.rs b/pallets/subtensor/tests/epoch.rs index df2c95d81..00892d35f 100644 --- a/pallets/subtensor/tests/epoch.rs +++ b/pallets/subtensor/tests/epoch.rs @@ -215,7 +215,7 @@ fn init_run_epochs( let sparse_weights = input_weights[*uid as usize].clone(); weights = sparse_weights.iter().map(|(_, w)| *w).collect(); let srvs: Vec = sparse_weights.iter().map(|(s, _)| *s).collect(); - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(U256::from(*uid as u64)), netuid, srvs, @@ -223,7 +223,7 @@ fn init_run_epochs( 0 )); } else { - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(U256::from(*uid as u64)), netuid, servers.to_vec(), @@ -234,7 +234,7 @@ fn init_run_epochs( } if server_self { for uid in servers { - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(U256::from(*uid as u64)), netuid, vec![*uid], @@ -517,21 +517,21 @@ fn init_run_epochs( // SubtensorModule::set_validator_permit_for_uid(0, 0, true); // SubtensorModule::set_validator_permit_for_uid(0, 1, true); // SubtensorModule::set_validator_permit_for_uid(0, 2, true); -// assert_ok!(SubtensorModule::set_weights( +// assert_ok!(SubtensorModule::do_set_weights( // RuntimeOrigin::signed(U256::from(0)), // netuid, // vec![0, 1, 2], // vec![u16::MAX / 3, u16::MAX / 3, u16::MAX], // 0 // )); -// assert_ok!(SubtensorModule::set_weights( +// assert_ok!(SubtensorModule::do_set_weights( // RuntimeOrigin::signed(U256::from(1)), // netuid, // vec![1, 2], // vec![u16::MAX / 2, u16::MAX / 2], // 0 // )); -// assert_ok!(SubtensorModule::set_weights( +// assert_ok!(SubtensorModule::do_set_weights( // RuntimeOrigin::signed(U256::from(2)), // netuid, // vec![2], @@ -568,7 +568,7 @@ fn test_1_graph() { SubtensorModule::append_neuron(netuid, &hotkey, 0); assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 1); run_to_block(1); // run to next block to ensure weights are set on nodes after their registration block - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(U256::from(uid)), netuid, vec![uid], @@ -635,7 +635,7 @@ fn test_10_graph() { assert_eq!(SubtensorModule::get_subnetwork_n(netuid), 10); run_to_block(1); // run to next block to ensure weights are set on nodes after their registration block for i in 0..10 { - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(U256::from(i)), netuid, vec![i as u16], @@ -1015,7 +1015,7 @@ fn test_bonds() { // === Set weights [val->srv1: 0.1, val->srv2: 0.2, val->srv3: 0.3, val->srv4: 0.4] for uid in 0..(n/2) as u64 { - assert_ok!(SubtensorModule::set_weights(RuntimeOrigin::signed(U256::from(uid)), netuid, ((n/2)..n).collect(), vec![ u16::MAX/4, u16::MAX/2, (u16::MAX/4)*3, u16::MAX], 0)); + assert_ok!(SubtensorModule::do_set_weights(RuntimeOrigin::signed(U256::from(uid)), netuid, ((n/2)..n).collect(), vec![ u16::MAX/4, u16::MAX/2, (u16::MAX/4)*3, u16::MAX], 0)); } if sparse { SubtensorModule::epoch( netuid, 1_000_000_000 ); } else { SubtensorModule::epoch_dense( netuid, 1_000_000_000 ); } @@ -1060,7 +1060,7 @@ fn test_bonds() { // === Set self-weight only on val1 let uid = 0; - assert_ok!(SubtensorModule::set_weights(RuntimeOrigin::signed(U256::from(uid)), netuid, vec![uid], vec![u16::MAX], 0)); + assert_ok!(SubtensorModule::do_set_weights(RuntimeOrigin::signed(U256::from(uid)), netuid, vec![uid], vec![u16::MAX], 0)); next_block(); if sparse { SubtensorModule::epoch( netuid, 1_000_000_000 ); } else { SubtensorModule::epoch_dense( netuid, 1_000_000_000 ); } @@ -1107,7 +1107,7 @@ fn test_bonds() { // === Set self-weight only on val2 let uid = 1; - assert_ok!(SubtensorModule::set_weights(RuntimeOrigin::signed(U256::from(uid)), netuid, vec![uid], vec![u16::MAX], 0)); + assert_ok!(SubtensorModule::do_set_weights(RuntimeOrigin::signed(U256::from(uid)), netuid, vec![uid], vec![u16::MAX], 0)); next_block(); if sparse { SubtensorModule::epoch( netuid, 1_000_000_000 ); } else { SubtensorModule::epoch_dense( netuid, 1_000_000_000 ); } @@ -1143,7 +1143,7 @@ fn test_bonds() { // === Set self-weight only on val3 let uid = 2; - assert_ok!(SubtensorModule::set_weights(RuntimeOrigin::signed(U256::from(uid)), netuid, vec![uid], vec![u16::MAX], 0)); + assert_ok!(SubtensorModule::do_set_weights(RuntimeOrigin::signed(U256::from(uid)), netuid, vec![uid], vec![u16::MAX], 0)); next_block(); if sparse { SubtensorModule::epoch( netuid, 1_000_000_000 ); } else { SubtensorModule::epoch_dense( netuid, 1_000_000_000 ); } @@ -1178,7 +1178,7 @@ fn test_bonds() { assert_eq!(bonds[3][7], 65535); // === Set val3->srv4: 1 - assert_ok!(SubtensorModule::set_weights(RuntimeOrigin::signed(U256::from(2)), netuid, vec![7], vec![u16::MAX], 0)); + assert_ok!(SubtensorModule::do_set_weights(RuntimeOrigin::signed(U256::from(2)), netuid, vec![7], vec![u16::MAX], 0)); next_block(); if sparse { SubtensorModule::epoch( netuid, 1_000_000_000 ); } else { SubtensorModule::epoch_dense( netuid, 1_000_000_000 ); } @@ -1322,7 +1322,7 @@ fn test_bonds_with_liquid_alpha() { // Set weights for uid in 0..(n / 2) { SubtensorModule::set_validator_permit_for_uid(netuid, uid, true); - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(U256::from(uid)), netuid, ((n / 2)..n).collect(), @@ -1401,7 +1401,7 @@ fn test_bonds_with_liquid_alpha() { // === Set self-weight only on val1 let uid = 0; - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(U256::from(uid)), netuid, vec![uid], @@ -1423,7 +1423,7 @@ fn test_bonds_with_liquid_alpha() { // === Set self-weight only on val2 let uid = 1; - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(U256::from(uid)), netuid, vec![uid], @@ -1574,7 +1574,7 @@ fn test_active_stake() { // === Set weights [val1->srv1: 0.5, val1->srv2: 0.5, val2->srv1: 0.5, val2->srv2: 0.5] for uid in 0..(n / 2) as u64 { - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(U256::from(uid)), netuid, ((n / 2)..n).collect(), @@ -1614,7 +1614,7 @@ fn test_active_stake() { run_to_block(activity_cutoff + 2); // run to block where validator (uid 0, 1) weights become outdated // === Update uid 0 weights - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(U256::from(0)), netuid, ((n / 2)..n).collect(), @@ -1674,7 +1674,7 @@ fn test_active_stake() { } // === Update uid 1 weights as well - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(U256::from(1)), netuid, ((n / 2)..n).collect(), @@ -1783,7 +1783,7 @@ fn test_outdated_weights() { // === Set weights [val1->srv1: 2/3, val1->srv2: 1/3, val2->srv1: 2/3, val2->srv2: 1/3, srv1->srv1: 1, srv2->srv2: 1] for uid in 0..(n / 2) as u64 { - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(U256::from(uid)), netuid, ((n / 2)..n).collect(), @@ -1792,7 +1792,7 @@ fn test_outdated_weights() { )); } for uid in ((n / 2) as u64)..n as u64 { - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(U256::from(uid)), netuid, vec![uid as u16], @@ -1862,7 +1862,7 @@ fn test_outdated_weights() { next_block(); // run to next block to outdate weights and bonds set on deregistered uid // === Update weights from only uid=0 - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(U256::from(0)), netuid, ((n / 2)..n).collect(), @@ -1986,7 +1986,7 @@ fn test_zero_weights() { // === Self-weights only: set weights [srv->srv: 1] for uid in ((n / 2) as u64)..n as u64 { - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(U256::from(uid)), netuid, vec![uid as u16], @@ -2022,7 +2022,7 @@ fn test_zero_weights() { // === Set weights [val->srv: 1/(n/2)] for uid in 0..(n / 2) as u64 { - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(U256::from(uid)), netuid, ((n / 2)..n).collect(), @@ -2076,7 +2076,7 @@ fn test_zero_weights() { // === Set new weights [val->srv: 1/(n/2)] to check that updated weights would produce non-zero incentive for uid in 0..(n / 2) as u64 { - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(U256::from(uid)), netuid, ((n / 2)..n).collect(), diff --git a/pallets/subtensor/tests/weights.rs b/pallets/subtensor/tests/weights.rs index 37ce91fe3..9893a5cd0 100644 --- a/pallets/subtensor/tests/weights.rs +++ b/pallets/subtensor/tests/weights.rs @@ -21,26 +21,6 @@ use substrate_fixed::types::I32F32; pub fn set_weights() tests *****************************/ -// Test the call passes through the subtensor module. -#[test] -fn test_set_weights_dispatch_info_ok() { - new_test_ext(0).execute_with(|| { - let dests = vec![1, 1]; - let weights = vec![1, 1]; - let netuid: u16 = 1; - let version_key: u64 = 0; - let call = RuntimeCall::SubtensorModule(SubtensorCall::set_weights { - netuid, - dests, - weights, - version_key, - }); - let dispatch_info = call.get_dispatch_info(); - - assert_eq!(dispatch_info.class, DispatchClass::Normal); - assert_eq!(dispatch_info.pays_fee, Pays::No); - }); -} #[test] fn test_set_rootweights_dispatch_info_ok() { new_test_ext(0).execute_with(|| { @@ -261,66 +241,6 @@ fn test_reveal_weights_dispatch_info_ok() { }); } -#[test] -fn test_set_weights_validate() { - // Testing the signed extension validate function - // correctly filters the `set_weights` transaction. - - new_test_ext(0).execute_with(|| { - let netuid: u16 = 1; - let coldkey = U256::from(0); - let hotkey: U256 = U256::from(1); - assert_ne!(hotkey, coldkey); - - let who = hotkey; // The hotkey signs this transaction - - let call = RuntimeCall::SubtensorModule(SubtensorCall::set_weights { - netuid, - dests: vec![1, 1], - weights: vec![1, 1], - version_key: 0, - }); - - // Create netuid - add_network(netuid, 0, 0); - // Register the hotkey - SubtensorModule::append_neuron(netuid, &hotkey, 0); - Owner::::insert(hotkey, coldkey); - - let min_stake = 500_000_000_000; - // Set the minimum stake - SubtensorModule::set_weights_min_stake(min_stake); - - // Verify stake is less than minimum - assert!(SubtensorModule::get_total_stake_for_hotkey(&hotkey) < min_stake); - let info: DispatchInfo = - DispatchInfoOf::<::RuntimeCall>::default(); - - let extension = pallet_subtensor::SubtensorSignedExtension::::new(); - // Submit to the signed extension validate function - let result_no_stake = extension.validate(&who, &call.clone(), &info, 10); - // Should fail due to insufficient stake - assert_err!( - result_no_stake, - TransactionValidityError::Invalid(InvalidTransaction::Custom(3)) - ); - - // Increase the stake to be equal to the minimum - SubtensorModule::increase_stake_on_hotkey_account(&hotkey, min_stake); - - // Verify stake is equal to minimum - assert_eq!( - SubtensorModule::get_total_stake_for_hotkey(&hotkey), - min_stake - ); - - // Submit to the signed extension validate function - let result_min_stake = extension.validate(&who, &call.clone(), &info, 10); - // Now the call should pass - assert_ok!(result_min_stake); - }); -} - #[test] fn test_reveal_weights_validate() { // Testing the signed extension validate function @@ -408,7 +328,7 @@ fn test_set_weights_is_root_error() { let hotkey = U256::from(1); assert_err!( - SubtensorModule::set_weights( + SubtensorModule::do_set_weights( RuntimeOrigin::signed(hotkey), root_netuid, uids.clone(), @@ -438,7 +358,7 @@ fn test_weights_err_no_validator_permit() { let weights_keys: Vec = vec![1, 2]; let weight_values: Vec = vec![1, 2]; - let result = SubtensorModule::set_weights( + let result = SubtensorModule::do_set_weights( RuntimeOrigin::signed(hotkey_account_id), netuid, weights_keys, @@ -453,7 +373,7 @@ fn test_weights_err_no_validator_permit() { SubtensorModule::get_uid_for_net_and_hotkey(netuid, &hotkey_account_id) .expect("Not registered."); SubtensorModule::set_validator_permit_for_uid(netuid, neuron_uid, true); - let result = SubtensorModule::set_weights( + let result = SubtensorModule::do_set_weights( RuntimeOrigin::signed(hotkey_account_id), netuid, weights_keys, @@ -490,7 +410,7 @@ fn test_set_weights_min_stake_failed() { // Check that it fails at the pallet level. SubtensorModule::set_weights_min_stake(100_000_000_000_000); assert_eq!( - SubtensorModule::set_weights( + SubtensorModule::do_set_weights( RuntimeOrigin::signed(hotkey), netuid, dests.clone(), @@ -501,7 +421,7 @@ fn test_set_weights_min_stake_failed() { ); // Now passes SubtensorModule::increase_stake_on_hotkey_account(&hotkey, 100_000_000_000_000); - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(hotkey), netuid, dests.clone(), @@ -527,14 +447,14 @@ fn test_weights_version_key() { let weights_keys: Vec = vec![0]; let weight_values: Vec = vec![1]; - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(hotkey), netuid0, weights_keys.clone(), weight_values.clone(), 0 )); - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(hotkey), netuid1, weights_keys.clone(), @@ -549,14 +469,14 @@ fn test_weights_version_key() { SubtensorModule::set_weights_version_key(netuid1, key1); // Setting works with version key. - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(hotkey), netuid0, weights_keys.clone(), weight_values.clone(), key0 )); - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(hotkey), netuid1, weights_keys.clone(), @@ -565,7 +485,7 @@ fn test_weights_version_key() { )); // validator:20313 >= network:12312 (accepted: validator newer) - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(hotkey), netuid0, weights_keys.clone(), @@ -576,7 +496,7 @@ fn test_weights_version_key() { // Setting fails with incorrect keys. // validator:12312 < network:20313 (rejected: validator not updated) assert_eq!( - SubtensorModule::set_weights( + SubtensorModule::do_set_weights( RuntimeOrigin::signed(hotkey), netuid1, weights_keys.clone(), @@ -615,7 +535,7 @@ fn test_weights_err_setting_weights_too_fast() { // Note that LastUpdate has default 0 for new uids, but if they have actually set weights on block 0 // then they are allowed to set weights again once more without a wait restriction, to accommodate the default. - let result = SubtensorModule::set_weights( + let result = SubtensorModule::do_set_weights( RuntimeOrigin::signed(hotkey_account_id), netuid, weights_keys.clone(), @@ -626,7 +546,7 @@ fn test_weights_err_setting_weights_too_fast() { run_to_block(1); for i in 1..100 { - let result = SubtensorModule::set_weights( + let result = SubtensorModule::do_set_weights( RuntimeOrigin::signed(hotkey_account_id), netuid, weights_keys.clone(), @@ -790,14 +710,19 @@ fn test_weights_err_max_weight_limit() { // Non self-weight fails. let uids: Vec = vec![1, 2, 3, 4]; let values: Vec = vec![u16::MAX / 4, u16::MAX / 4, u16::MAX / 54, u16::MAX / 4]; - let result = - SubtensorModule::set_weights(RuntimeOrigin::signed(U256::from(0)), 1, uids, values, 0); + let result = SubtensorModule::do_set_weights( + RuntimeOrigin::signed(U256::from(0)), + 1, + uids, + values, + 0, + ); assert_eq!(result, Err(Error::::MaxWeightExceeded.into())); // Self-weight is a success. let uids: Vec = vec![0]; // Self. let values: Vec = vec![u16::MAX]; // normalizes to u32::MAX - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(U256::from(0)), 1, uids, @@ -813,7 +738,7 @@ fn test_no_signature() { new_test_ext(0).execute_with(|| { let uids: Vec = vec![]; let values: Vec = vec![]; - let result = SubtensorModule::set_weights(RuntimeOrigin::none(), 1, uids, values, 0); + let result = SubtensorModule::do_set_weights(RuntimeOrigin::none(), 1, uids, values, 0); assert_eq!(result, Err(DispatchError::BadOrigin)); }); } @@ -888,7 +813,7 @@ fn test_set_weight_not_enough_values() { // Should fail because we are only setting a single value and its not the self weight. let weight_keys: Vec = vec![1]; // not weight. let weight_values: Vec = vec![88]; // random value. - let result = SubtensorModule::set_weights( + let result = SubtensorModule::do_set_weights( RuntimeOrigin::signed(account_id), 1, weight_keys, @@ -900,7 +825,7 @@ fn test_set_weight_not_enough_values() { // Shouldnt fail because we setting a single value but it is the self weight. let weight_keys: Vec = vec![0]; // self weight. let weight_values: Vec = vec![88]; // random value. - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(account_id), 1, weight_keys, @@ -943,7 +868,7 @@ fn test_set_weight_too_many_uids() { // Should fail because we are setting more weights than there are neurons. let weight_keys: Vec = vec![0, 1, 2, 3, 4]; // more uids than neurons in subnet. let weight_values: Vec = vec![88, 102, 303, 1212, 11]; // random value. - let result = SubtensorModule::set_weights( + let result = SubtensorModule::do_set_weights( RuntimeOrigin::signed(U256::from(1)), 1, weight_keys, @@ -958,7 +883,7 @@ fn test_set_weight_too_many_uids() { // Shouldnt fail because we are setting less weights than there are neurons. let weight_keys: Vec = vec![0, 1]; // Only on neurons that exist. let weight_values: Vec = vec![10, 10]; // random value. - assert_ok!(SubtensorModule::set_weights( + assert_ok!(SubtensorModule::do_set_weights( RuntimeOrigin::signed(U256::from(1)), 1, weight_keys, @@ -1343,7 +1268,7 @@ fn test_set_weights_commit_reveal_enabled_error() { let hotkey = U256::from(1); assert_err!( - SubtensorModule::set_weights( + SubtensorModule::do_set_weights( RuntimeOrigin::signed(hotkey), netuid, uids.clone(), diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 750320a7b..1935cce2c 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -336,8 +336,7 @@ impl Contains for SafeModeWhitelistedCalls { | RuntimeCall::SafeMode(_) | RuntimeCall::Timestamp(_) | RuntimeCall::SubtensorModule( - pallet_subtensor::Call::set_weights { .. } - | pallet_subtensor::Call::set_root_weights { .. } + pallet_subtensor::Call::set_root_weights { .. } | pallet_subtensor::Call::serve_axon { .. } ) | RuntimeCall::Commitments(pallet_commitments::Call::set_commitment { .. })