Skip to content

Commit 3821a38

Browse files
remove set_weights extrinsic
1 parent 3e65beb commit 3821a38

File tree

8 files changed

+85
-281
lines changed

8 files changed

+85
-281
lines changed

pallets/subtensor/src/benchmarks.rs

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -36,45 +36,6 @@ benchmarks! {
3636

3737
}: register( RawOrigin::Signed( hotkey.clone() ), netuid, block_number, nonce, work, hotkey.clone(), coldkey.clone() )
3838

39-
benchmark_set_weights {
40-
41-
// This is a whitelisted caller who can make transaction without weights.
42-
let netuid: u16 = 1;
43-
let version_key: u64 = 1;
44-
let tempo: u16 = 1;
45-
let modality: u16 = 0;
46-
47-
Subtensor::<T>::init_new_network(netuid, tempo);
48-
Subtensor::<T>::set_max_allowed_uids( netuid, 4096 );
49-
50-
Subtensor::<T>::set_network_registration_allowed( netuid, true );
51-
Subtensor::<T>::set_max_registrations_per_block( netuid, 4096 );
52-
Subtensor::<T>::set_target_registrations_per_interval( netuid, 4096 );
53-
54-
let mut seed : u32 = 1;
55-
let mut dests: Vec<u16> = vec![];
56-
let mut weights: Vec<u16> = vec![];
57-
let signer : T::AccountId = account("Alice", 0, seed);
58-
59-
for id in 0..4096_u16 {
60-
let hotkey: T::AccountId = account("Alice", 0, seed);
61-
let coldkey: T::AccountId = account("Test", 0, seed);
62-
seed += 1;
63-
64-
Subtensor::<T>::set_burn(netuid, 1);
65-
let amount_to_be_staked = 1000000u32.into();
66-
Subtensor::<T>::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked);
67-
68-
Subtensor::<T>::do_burned_registration(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey.clone())?;
69-
70-
let uid = Subtensor::<T>::get_uid_for_net_and_hotkey(netuid, &hotkey.clone()).unwrap();
71-
Subtensor::<T>::set_validator_permit_for_uid(netuid, uid, true);
72-
dests.push(id);
73-
weights.push(id);
74-
}
75-
76-
}: set_weights(RawOrigin::Signed( signer.clone() ), netuid, dests, weights, version_key)
77-
7839

7940
benchmark_become_delegate {
8041
// This is a whitelisted caller who can make transaction without weights.

pallets/subtensor/src/lib.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,18 +1488,6 @@ where
14881488
Err(InvalidTransaction::Custom(6).into())
14891489
}
14901490
}
1491-
Some(Call::set_weights { netuid, .. }) => {
1492-
if Self::check_weights_min_stake(who, *netuid) {
1493-
let priority: u64 = Self::get_priority_set_weights(who, *netuid);
1494-
Ok(ValidTransaction {
1495-
priority,
1496-
longevity: 1,
1497-
..Default::default()
1498-
})
1499-
} else {
1500-
Err(InvalidTransaction::Custom(3).into())
1501-
}
1502-
}
15031491
Some(Call::set_root_weights { netuid, hotkey, .. }) => {
15041492
if Self::check_weights_min_stake(hotkey, *netuid) {
15051493
let priority: u64 = Self::get_priority_set_weights(hotkey, *netuid);
@@ -1589,10 +1577,6 @@ where
15891577
let transaction_fee = 0;
15901578
Ok((CallType::RemoveStake, transaction_fee, who.clone()))
15911579
}
1592-
Some(Call::set_weights { .. }) => {
1593-
let transaction_fee = 0;
1594-
Ok((CallType::SetWeights, transaction_fee, who.clone()))
1595-
}
15961580
Some(Call::commit_weights { .. }) => {
15971581
let transaction_fee = 0;
15981582
Ok((CallType::SetWeights, transaction_fee, who.clone()))

pallets/subtensor/src/macros/dispatches.rs

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -13,79 +13,6 @@ mod dispatches {
1313
/// Dispatchable functions must be annotated with a weight and must return a DispatchResult.
1414
#[pallet::call]
1515
impl<T: Config> Pallet<T> {
16-
/// --- Sets the caller weights for the incentive mechanism. The call can be
17-
/// made from the hotkey account so is potentially insecure, however, the damage
18-
/// of changing weights is minimal if caught early. This function includes all the
19-
/// checks that the passed weights meet the requirements. Stored as u16s they represent
20-
/// rational values in the range [0,1] which sum to 1 and can be interpreted as
21-
/// probabilities. The specific weights determine how inflation propagates outward
22-
/// from this peer.
23-
///
24-
/// Note: The 16 bit integers weights should represent 1.0 as the max u16.
25-
/// However, the function normalizes all integers to u16_max anyway. This means that if the sum of all
26-
/// elements is larger or smaller than the amount of elements * u16_max, all elements
27-
/// will be corrected for this deviation.
28-
///
29-
/// # Args:
30-
/// * `origin`: (<T as frame_system::Config>Origin):
31-
/// - The caller, a hotkey who wishes to set their weights.
32-
///
33-
/// * `netuid` (u16):
34-
/// - The network uid we are setting these weights on.
35-
///
36-
/// * `dests` (Vec<u16>):
37-
/// - The edge endpoint for the weight, i.e. j for w_ij.
38-
///
39-
/// * 'weights' (Vec<u16>):
40-
/// - The u16 integer encoded weights. Interpreted as rational
41-
/// values in the range [0,1]. They must sum to in32::MAX.
42-
///
43-
/// * 'version_key' ( u64 ):
44-
/// - The network version key to check if the validator is up to date.
45-
///
46-
/// # Event:
47-
/// * WeightsSet;
48-
/// - On successfully setting the weights on chain.
49-
///
50-
/// # Raises:
51-
/// * 'SubNetworkDoesNotExist':
52-
/// - Attempting to set weights on a non-existent network.
53-
///
54-
/// * 'NotRegistered':
55-
/// - Attempting to set weights from a non registered account.
56-
///
57-
/// * 'WeightVecNotEqualSize':
58-
/// - Attempting to set weights with uids not of same length.
59-
///
60-
/// * 'DuplicateUids':
61-
/// - Attempting to set weights with duplicate uids.
62-
///
63-
/// * 'UidsLengthExceedUidsInSubNet':
64-
/// - Attempting to set weights above the max allowed uids.
65-
///
66-
/// * 'UidVecContainInvalidOne':
67-
/// - Attempting to set weights with invalid uids.
68-
///
69-
/// * 'WeightVecLengthIsLow':
70-
/// - Attempting to set weights with fewer weights than min.
71-
///
72-
/// * 'MaxWeightExceeded':
73-
/// - Attempting to set weights with max value exceeding limit.
74-
#[pallet::call_index(0)]
75-
#[pallet::weight((Weight::from_parts(22_060_000_000, 0)
76-
.saturating_add(T::DbWeight::get().reads(4106))
77-
.saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))]
78-
pub fn set_weights(
79-
origin: OriginFor<T>,
80-
netuid: u16,
81-
dests: Vec<u16>,
82-
weights: Vec<u16>,
83-
version_key: u64,
84-
) -> DispatchResult {
85-
return Self::do_set_weights(origin, netuid, dests, weights, version_key);
86-
// Err(Error::<T>::CommitRevealEnabled.into())
87-
}
88-
8916
/// ---- Used to commit a hash of your weight values to later be revealed.
9017
///
9118
/// # Args:

pallets/subtensor/src/subnets/weights.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ impl<T: Config> Pallet<T> {
404404
})
405405
}
406406

407-
/// ---- The implementation for the extrinsic set_weights.
407+
/// ---- Used by reveal weights to set the weights on chain.
408408
///
409409
/// # Args:
410410
/// * 'origin': (<T as frame_system::Config>RuntimeOrigin):
@@ -519,57 +519,55 @@ impl<T: Config> Pallet<T> {
519519
Error::<T>::IncorrectWeightVersionKey
520520
);
521521

522-
// --- 9. Ensure the uid is not setting weights faster than the weights_set_rate_limit.
522+
// --- 8. Check that the neuron uid is an allowed validator permitted to set non-self weights.
523523
let neuron_uid = Self::get_uid_for_net_and_hotkey(netuid, &hotkey)?;
524-
525-
// --- 10. Check that the neuron uid is an allowed validator permitted to set non-self weights.
526524
ensure!(
527525
Self::check_validator_permit(netuid, neuron_uid, &uids, &values),
528526
Error::<T>::NeuronNoValidatorPermit
529527
);
530528

531-
// --- 11. Ensure the passed uids contain no duplicates.
529+
// --- 9. Ensure the passed uids contain no duplicates.
532530
ensure!(!Self::has_duplicate_uids(&uids), Error::<T>::DuplicateUids);
533531

534-
// --- 12. Ensure that the passed uids are valid for the network.
532+
// --- 10. Ensure that the passed uids are valid for the network.
535533
ensure!(
536534
!Self::contains_invalid_uids(netuid, &uids),
537535
Error::<T>::UidVecContainInvalidOne
538536
);
539537

540-
// --- 13. Ensure that the weights have the required length.
538+
// --- 11. Ensure that the weights have the required length.
541539
ensure!(
542540
Self::check_length(netuid, neuron_uid, &uids, &values),
543541
Error::<T>::WeightVecLengthIsLow
544542
);
545543

546-
// --- 14. Max-upscale the weights.
544+
// --- 12. Max-upscale the weights.
547545
let max_upscaled_weights: Vec<u16> = vec_u16_max_upscale_to_u16(&values);
548546

549-
// --- 15. Ensure the weights are max weight limited
547+
// --- 13. Ensure the weights are max weight limited
550548
ensure!(
551549
Self::max_weight_limited(netuid, neuron_uid, &uids, &max_upscaled_weights),
552550
Error::<T>::MaxWeightExceeded
553551
);
554552

555-
// --- 16. Zip weights for sinking to storage map.
553+
// --- 14. Zip weights for sinking to storage map.
556554
let mut zipped_weights: Vec<(u16, u16)> = vec![];
557555
for (uid, val) in uids.iter().zip(max_upscaled_weights.iter()) {
558556
zipped_weights.push((*uid, *val))
559557
}
560558

561-
// --- 17. Set weights under netuid, uid double map entry.
559+
// --- 15. Set weights under netuid, uid double map entry.
562560
Weights::<T>::insert(netuid, neuron_uid, zipped_weights);
563561

564-
// --- 18. Emit the tracking event.
562+
// --- 16. Emit the tracking event.
565563
log::debug!(
566564
"WeightsSet( netuid:{:?}, neuron_uid:{:?} )",
567565
netuid,
568566
neuron_uid
569567
);
570568
Self::deposit_event(Event::WeightsSet(netuid, neuron_uid));
571569

572-
// --- 19. Return ok.
570+
// --- 17. Return ok.
573571
Ok(())
574572
}
575573

pallets/subtensor/tests/children.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,13 +1882,19 @@ fn test_childkey_single_parent_emission() {
18821882
let uids: Vec<u16> = vec![1]; // Only set weight for the child (UID 1)
18831883
let values: Vec<u16> = vec![u16::MAX]; // Use maximum value for u16
18841884
let version_key = SubtensorModule::get_weights_version_key(netuid);
1885-
assert_ok!(SubtensorModule::set_weights(
1885+
1886+
// TODO: replace with commit reveal ops - manually set_last_update_for_uid for now
1887+
assert_ok!(SubtensorModule::do_set_weights(
18861888
origin,
18871889
netuid,
18881890
uids,
18891891
values,
18901892
version_key
18911893
));
1894+
let neuron_uid =
1895+
SubtensorModule::get_uid_for_net_and_hotkey(netuid, &weight_setter).unwrap();
1896+
let current_block: u64 = SubtensorModule::get_current_block_as_u64();
1897+
SubtensorModule::set_last_update_for_uid(netuid, neuron_uid, current_block);
18921898

18931899
// Run epoch with a hardcoded emission value
18941900
let hardcoded_emission: u64 = 1_000_000_000; // 1 TAO
@@ -2028,7 +2034,7 @@ fn test_childkey_multiple_parents_emission() {
20282034
let uids: Vec<u16> = vec![0, 1, 2];
20292035
let values: Vec<u16> = vec![0, 65354, 65354];
20302036
let version_key = SubtensorModule::get_weights_version_key(netuid);
2031-
assert_ok!(SubtensorModule::set_weights(
2037+
assert_ok!(SubtensorModule::do_set_weights(
20322038
RuntimeOrigin::signed(weight_setter),
20332039
netuid,
20342040
uids,
@@ -2205,7 +2211,7 @@ fn test_parent_child_chain_emission() {
22052211
// Ensure we can set weights without rate limiting
22062212
SubtensorModule::set_weights_set_rate_limit(netuid, 0);
22072213

2208-
assert_ok!(SubtensorModule::set_weights(
2214+
assert_ok!(SubtensorModule::do_set_weights(
22092215
origin,
22102216
netuid,
22112217
uids,
@@ -2350,7 +2356,7 @@ fn test_dynamic_parent_child_relationships() {
23502356
// Ensure we can set weights without rate limiting
23512357
SubtensorModule::set_weights_set_rate_limit(netuid, 0);
23522358

2353-
assert_ok!(SubtensorModule::set_weights(
2359+
assert_ok!(SubtensorModule::do_set_weights(
23542360
origin,
23552361
netuid,
23562362
uids,
@@ -3084,13 +3090,17 @@ fn test_rank_trust_incentive_calculation_with_parent_child() {
30843090
.chain(other_validators.iter().map(|(h, _)| h))
30853091
.chain(std::iter::once(&child_hotkey))
30863092
{
3087-
assert_ok!(SubtensorModule::set_weights(
3093+
assert_ok!(SubtensorModule::do_set_weights(
30883094
RuntimeOrigin::signed(*hotkey),
30893095
netuid,
30903096
all_uids.clone(),
30913097
validator_weights.clone(),
30923098
0
30933099
));
3100+
// TODO: replace with commit reveal ops - manually set_last_update_for_uid for now
3101+
let neuron_uid = SubtensorModule::get_uid_for_net_and_hotkey(netuid, &hotkey).unwrap();
3102+
let current_block: u64 = SubtensorModule::get_current_block_as_u64();
3103+
SubtensorModule::set_last_update_for_uid(netuid, neuron_uid, current_block);
30943104
}
30953105

30963106
step_block(10);
@@ -3131,7 +3141,7 @@ fn test_rank_trust_incentive_calculation_with_parent_child() {
31313141
));
31323142

31333143
// Child now sets weights as a validator
3134-
assert_ok!(SubtensorModule::set_weights(
3144+
assert_ok!(SubtensorModule::do_set_weights(
31353145
RuntimeOrigin::signed(child_hotkey),
31363146
netuid,
31373147
all_uids.clone(),
@@ -3293,7 +3303,7 @@ fn test_childkey_set_weights_single_parent() {
32933303
let uids: Vec<u16> = vec![1]; // Only set weight for the child (UID 1)
32943304
let values: Vec<u16> = vec![u16::MAX]; // Use maximum value for u16
32953305
let version_key = SubtensorModule::get_weights_version_key(netuid);
3296-
assert_ok!(SubtensorModule::set_weights(
3306+
assert_ok!(SubtensorModule::do_set_weights(
32973307
origin,
32983308
netuid,
32993309
uids.clone(),
@@ -3312,7 +3322,7 @@ fn test_childkey_set_weights_single_parent() {
33123322

33133323
// Check the child cannot set weights
33143324
assert_noop!(
3315-
SubtensorModule::set_weights(
3325+
SubtensorModule::do_set_weights(
33163326
RuntimeOrigin::signed(child),
33173327
netuid,
33183328
uids.clone(),
@@ -3334,7 +3344,7 @@ fn test_childkey_set_weights_single_parent() {
33343344
);
33353345

33363346
// Check the child can set weights
3337-
assert_ok!(SubtensorModule::set_weights(
3347+
assert_ok!(SubtensorModule::do_set_weights(
33383348
RuntimeOrigin::signed(child),
33393349
netuid,
33403350
uids,
@@ -3395,7 +3405,7 @@ fn test_set_weights_no_parent() {
33953405

33963406
// Check the hotkey cannot set weights
33973407
assert_noop!(
3398-
SubtensorModule::set_weights(
3408+
SubtensorModule::do_set_weights(
33993409
RuntimeOrigin::signed(hotkey),
34003410
netuid,
34013411
uids.clone(),
@@ -3417,7 +3427,7 @@ fn test_set_weights_no_parent() {
34173427
);
34183428

34193429
// Check the hotkey can set weights
3420-
assert_ok!(SubtensorModule::set_weights(
3430+
assert_ok!(SubtensorModule::do_set_weights(
34213431
RuntimeOrigin::signed(hotkey),
34223432
netuid,
34233433
uids,

0 commit comments

Comments
 (0)