Skip to content

Commit

Permalink
remove set_weights extrinsic
Browse files Browse the repository at this point in the history
  • Loading branch information
andreea-popescu-reef committed Nov 21, 2024
1 parent 3e65beb commit 0eb4947
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 269 deletions.
39 changes: 0 additions & 39 deletions pallets/subtensor/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<T>::init_new_network(netuid, tempo);
Subtensor::<T>::set_max_allowed_uids( netuid, 4096 );

Subtensor::<T>::set_network_registration_allowed( netuid, true );
Subtensor::<T>::set_max_registrations_per_block( netuid, 4096 );
Subtensor::<T>::set_target_registrations_per_interval( netuid, 4096 );

let mut seed : u32 = 1;
let mut dests: Vec<u16> = vec![];
let mut weights: Vec<u16> = 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::<T>::set_burn(netuid, 1);
let amount_to_be_staked = 1000000u32.into();
Subtensor::<T>::add_balance_to_coldkey_account(&coldkey.clone(), amount_to_be_staked);

Subtensor::<T>::do_burned_registration(RawOrigin::Signed(coldkey.clone()).into(), netuid, hotkey.clone())?;

let uid = Subtensor::<T>::get_uid_for_net_and_hotkey(netuid, &hotkey.clone()).unwrap();
Subtensor::<T>::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.
Expand Down
16 changes: 0 additions & 16 deletions pallets/subtensor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()))
Expand Down
73 changes: 0 additions & 73 deletions pallets/subtensor/src/macros/dispatches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,79 +13,6 @@ mod dispatches {
/// Dispatchable functions must be annotated with a weight and must return a DispatchResult.
#[pallet::call]
impl<T: Config> Pallet<T> {
/// --- 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`: (<T as frame_system::Config>Origin):
/// - The caller, a hotkey who wishes to set their weights.
///
/// * `netuid` (u16):
/// - The network uid we are setting these weights on.
///
/// * `dests` (Vec<u16>):
/// - The edge endpoint for the weight, i.e. j for w_ij.
///
/// * 'weights' (Vec<u16>):
/// - 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<T>,
netuid: u16,
dests: Vec<u16>,
weights: Vec<u16>,
version_key: u64,
) -> DispatchResult {
return Self::do_set_weights(origin, netuid, dests, weights, version_key);
// Err(Error::<T>::CommitRevealEnabled.into())
}

/// ---- Used to commit a hash of your weight values to later be revealed.
///
/// # Args:
Expand Down
2 changes: 1 addition & 1 deletion pallets/subtensor/src/subnets/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ impl<T: Config> Pallet<T> {
})
}

/// ---- The implementation for the extrinsic set_weights.
/// ---- Used by reveal weights to set the weights on chain.
///
/// # Args:
/// * 'origin': (<T as frame_system::Config>RuntimeOrigin):
Expand Down
22 changes: 11 additions & 11 deletions pallets/subtensor/tests/children.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1882,7 +1882,7 @@ fn test_childkey_single_parent_emission() {
let uids: Vec<u16> = vec![1]; // Only set weight for the child (UID 1)
let values: Vec<u16> = 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,
Expand Down Expand Up @@ -2028,7 +2028,7 @@ fn test_childkey_multiple_parents_emission() {
let uids: Vec<u16> = vec![0, 1, 2];
let values: Vec<u16> = 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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -3293,7 +3293,7 @@ fn test_childkey_set_weights_single_parent() {
let uids: Vec<u16> = vec![1]; // Only set weight for the child (UID 1)
let values: Vec<u16> = 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(),
Expand All @@ -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(),
Expand All @@ -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,
Expand Down Expand Up @@ -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(),
Expand All @@ -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,
Expand Down
Loading

0 comments on commit 0eb4947

Please sign in to comment.