Skip to content

Commit 0eb4947

Browse files
remove set_weights extrinsic
1 parent 3e65beb commit 0eb4947

File tree

8 files changed

+65
-269
lines changed

8 files changed

+65
-269
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: 1 addition & 1 deletion
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):

pallets/subtensor/tests/children.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,7 +1882,7 @@ 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+
assert_ok!(SubtensorModule::do_set_weights(
18861886
origin,
18871887
netuid,
18881888
uids,
@@ -2028,7 +2028,7 @@ fn test_childkey_multiple_parents_emission() {
20282028
let uids: Vec<u16> = vec![0, 1, 2];
20292029
let values: Vec<u16> = vec![0, 65354, 65354];
20302030
let version_key = SubtensorModule::get_weights_version_key(netuid);
2031-
assert_ok!(SubtensorModule::set_weights(
2031+
assert_ok!(SubtensorModule::do_set_weights(
20322032
RuntimeOrigin::signed(weight_setter),
20332033
netuid,
20342034
uids,
@@ -2205,7 +2205,7 @@ fn test_parent_child_chain_emission() {
22052205
// Ensure we can set weights without rate limiting
22062206
SubtensorModule::set_weights_set_rate_limit(netuid, 0);
22072207

2208-
assert_ok!(SubtensorModule::set_weights(
2208+
assert_ok!(SubtensorModule::do_set_weights(
22092209
origin,
22102210
netuid,
22112211
uids,
@@ -2350,7 +2350,7 @@ fn test_dynamic_parent_child_relationships() {
23502350
// Ensure we can set weights without rate limiting
23512351
SubtensorModule::set_weights_set_rate_limit(netuid, 0);
23522352

2353-
assert_ok!(SubtensorModule::set_weights(
2353+
assert_ok!(SubtensorModule::do_set_weights(
23542354
origin,
23552355
netuid,
23562356
uids,
@@ -3084,7 +3084,7 @@ fn test_rank_trust_incentive_calculation_with_parent_child() {
30843084
.chain(other_validators.iter().map(|(h, _)| h))
30853085
.chain(std::iter::once(&child_hotkey))
30863086
{
3087-
assert_ok!(SubtensorModule::set_weights(
3087+
assert_ok!(SubtensorModule::do_set_weights(
30883088
RuntimeOrigin::signed(*hotkey),
30893089
netuid,
30903090
all_uids.clone(),
@@ -3131,7 +3131,7 @@ fn test_rank_trust_incentive_calculation_with_parent_child() {
31313131
));
31323132

31333133
// Child now sets weights as a validator
3134-
assert_ok!(SubtensorModule::set_weights(
3134+
assert_ok!(SubtensorModule::do_set_weights(
31353135
RuntimeOrigin::signed(child_hotkey),
31363136
netuid,
31373137
all_uids.clone(),
@@ -3293,7 +3293,7 @@ fn test_childkey_set_weights_single_parent() {
32933293
let uids: Vec<u16> = vec![1]; // Only set weight for the child (UID 1)
32943294
let values: Vec<u16> = vec![u16::MAX]; // Use maximum value for u16
32953295
let version_key = SubtensorModule::get_weights_version_key(netuid);
3296-
assert_ok!(SubtensorModule::set_weights(
3296+
assert_ok!(SubtensorModule::do_set_weights(
32973297
origin,
32983298
netuid,
32993299
uids.clone(),
@@ -3312,7 +3312,7 @@ fn test_childkey_set_weights_single_parent() {
33123312

33133313
// Check the child cannot set weights
33143314
assert_noop!(
3315-
SubtensorModule::set_weights(
3315+
SubtensorModule::do_set_weights(
33163316
RuntimeOrigin::signed(child),
33173317
netuid,
33183318
uids.clone(),
@@ -3334,7 +3334,7 @@ fn test_childkey_set_weights_single_parent() {
33343334
);
33353335

33363336
// Check the child can set weights
3337-
assert_ok!(SubtensorModule::set_weights(
3337+
assert_ok!(SubtensorModule::do_set_weights(
33383338
RuntimeOrigin::signed(child),
33393339
netuid,
33403340
uids,
@@ -3395,7 +3395,7 @@ fn test_set_weights_no_parent() {
33953395

33963396
// Check the hotkey cannot set weights
33973397
assert_noop!(
3398-
SubtensorModule::set_weights(
3398+
SubtensorModule::do_set_weights(
33993399
RuntimeOrigin::signed(hotkey),
34003400
netuid,
34013401
uids.clone(),
@@ -3417,7 +3417,7 @@ fn test_set_weights_no_parent() {
34173417
);
34183418

34193419
// Check the hotkey can set weights
3420-
assert_ok!(SubtensorModule::set_weights(
3420+
assert_ok!(SubtensorModule::do_set_weights(
34213421
RuntimeOrigin::signed(hotkey),
34223422
netuid,
34233423
uids,

0 commit comments

Comments
 (0)