Skip to content

Allow owners to change their subnet symbol #1770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 22 commits into
base: devnet-ready
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions pallets/subtensor/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1355,4 +1355,20 @@ mod pallet_benchmarks {
#[extrinsic_call]
_(RawOrigin::Signed(coldkey), hotkey);
}

#[benchmark]
fn update_symbol() {
let coldkey: T::AccountId = whitelisted_caller();
let netuid = NetUid::from(1);
let tempo: u16 = 1;
Subtensor::<T>::init_new_network(netuid, tempo);
SubnetOwner::<T>::insert(netuid, coldkey.clone());

let new_symbol = Subtensor::<T>::get_symbol_for_subnet(NetUid::from(42));

#[extrinsic_call]
_(RawOrigin::Signed(coldkey), netuid, new_symbol.clone());

assert_eq!(TokenSymbol::<T>::get(netuid), new_symbol);
}
}
49 changes: 49 additions & 0 deletions pallets/subtensor/src/macros/dispatches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use frame_support::pallet_macros::pallet_section;
/// This can later be imported into the pallet using [`import_section`].
#[pallet_section]
mod dispatches {
use crate::subnets::symbols::SYMBOLS;
use frame_support::traits::schedule::DispatchTime;
use frame_support::traits::schedule::v3::Anon as ScheduleAnon;
use frame_system::pallet_prelude::BlockNumberFor;
Expand Down Expand Up @@ -2069,5 +2070,53 @@ mod dispatches {
PendingChildKeyCooldown::<T>::put(cooldown);
Ok(())
}

/// Updates the symbol for a subnet.
///
/// # Arguments
/// * `origin` - The origin of the call, which must be the subnet owner or root.
/// * `netuid` - The unique identifier of the subnet on which the symbol is being set.
/// * `symbol` - The symbol to set for the subnet.
///
/// # Errors
/// Returns an error if:
/// * The transaction is not signed by the subnet owner.
/// * The symbol does not exist.
/// * The symbol is already in use by another subnet.
///
/// # Events
/// Emits a `SymbolUpdated` event on success.
#[pallet::call_index(110)]
#[pallet::weight((
Weight::from_parts(10_000, 0).saturating_add(T::DbWeight::get().reads_writes(2, 1)),
DispatchClass::Operational,
Pays::Yes
))]
pub fn update_symbol(
origin: OriginFor<T>,
netuid: NetUid,
symbol: Vec<u8>,
) -> DispatchResult {
Self::ensure_subnet_owner_or_root(origin, netuid)?;

if SYMBOLS
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a good candidate for the function (you have a couple "symbols related functions" within this PR

.iter()
.skip(1) // Skip the root symbol
.find(|s| *s == &symbol)
.is_none()
{
return Err(Error::<T>::SymbolDoesNotExist.into());
}

let used_symbols = TokenSymbol::<T>::iter_values().collect::<Vec<_>>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the second unbounded iteration here. @gregzaitsev Do we care about weights optimizations here?

if used_symbols.contains(&symbol) {
return Err(Error::<T>::SymbolAlreadyInUse.into());
}

TokenSymbol::<T>::insert(netuid, symbol.clone());

Self::deposit_event(Event::SymbolUpdated { netuid, symbol });
Ok(())
}
}
}
4 changes: 4 additions & 0 deletions pallets/subtensor/src/macros/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,5 +218,9 @@ mod errors {
SameNetuid,
/// The caller does not have enough balance for the operation.
InsufficientBalance,
/// Symbol does not exist.
SymbolDoesNotExist,
/// Symbol already in use.
SymbolAlreadyInUse,
}
}
8 changes: 8 additions & 0 deletions pallets/subtensor/src/macros/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,5 +353,13 @@ mod events {
/// the subnet ID
netuid: NetUid,
},

/// The symbol for a subnet has been updated.
SymbolUpdated {
/// The subnet ID
netuid: NetUid,
/// The symbol that has been updated
symbol: Vec<u8>,
},
}
}
2 changes: 1 addition & 1 deletion pallets/subtensor/src/rpc_info/dynamic_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl<T: Config> Pallet<T> {
.into_iter()
.map(Compact)
.collect(),
token_symbol: Self::get_symbol_for_subnet(netuid)
token_symbol: TokenSymbol::<T>::get(netuid)
.into_iter()
.map(Compact)
.collect(),
Expand Down
4 changes: 2 additions & 2 deletions pallets/subtensor/src/rpc_info/metagraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ impl<T: Config> Pallet<T> {
.into_iter()
.map(Compact)
.collect(), // Name
symbol: Self::get_symbol_for_subnet(netuid)
symbol: TokenSymbol::<T>::get(netuid)
.into_iter()
.map(Compact)
.collect(), // Symbol.
Expand Down Expand Up @@ -835,7 +835,7 @@ impl<T: Config> Pallet<T> {
Some(SelectiveMetagraphIndex::Symbol) => SelectiveMetagraph {
netuid: netuid.into(),
symbol: Some(
Self::get_symbol_for_subnet(netuid)
TokenSymbol::<T>::get(netuid)
.into_iter()
.map(Compact)
.collect(),
Expand Down
23 changes: 11 additions & 12 deletions pallets/subtensor/src/subnets/subnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,23 @@ impl<T: Config> Pallet<T> {
Error::<T>::NotEnoughBalanceToStake
);

// --- 5. Determine the netuid to register.
// --- 6. Determine the netuid to register.
let netuid_to_register = Self::get_next_netuid();

// --- 6. Perform the lock operation.
// --- 7. Perform the lock operation.
let actual_tao_lock_amount: u64 =
Self::remove_balance_from_coldkey_account(&coldkey, lock_amount)?;
log::debug!("actual_tao_lock_amount: {:?}", actual_tao_lock_amount);

// --- 7. Set the lock amount for use to determine pricing.
// --- 8. Set the lock amount for use to determine pricing.
Self::set_network_last_lock(actual_tao_lock_amount);

// --- 8. Set initial and custom parameters for the network.
// --- 9. Set initial and custom parameters for the network.
let default_tempo = DefaultTempo::<T>::get();
Self::init_new_network(netuid_to_register, default_tempo);
log::debug!("init_new_network: {:?}", netuid_to_register);

// --- 9 . Add the caller to the neuron set.
// --- 10. Add the caller to the neuron set.
Self::create_account_if_non_existent(&coldkey, hotkey);
Self::append_neuron(netuid_to_register, hotkey, current_block);
log::debug!(
Expand All @@ -173,24 +173,23 @@ impl<T: Config> Pallet<T> {
hotkey
);

// --- 10. Set the mechanism.
// --- 11. Set the mechanism.
SubnetMechanism::<T>::insert(netuid_to_register, mechid);
log::debug!(
"SubnetMechanism for netuid {:?} set to: {:?}",
netuid_to_register,
mechid
);

// --- 11. Set the creation terms.
// --- 12. Set the creation terms.
NetworkLastRegistered::<T>::set(current_block);
NetworkRegisteredAt::<T>::insert(netuid_to_register, current_block);

// --- 14. Init the pool by putting the lock as the initial alpha.
TokenSymbol::<T>::insert(
netuid_to_register,
Self::get_symbol_for_subnet(netuid_to_register),
); // Set subnet token symbol.
// --- 13. Set the symbol.
let symbol = Self::get_next_available_symbol(netuid_to_register);
TokenSymbol::<T>::insert(netuid_to_register, symbol);

// --- 14. Init the pool by putting the lock as the initial alpha.
// Put initial TAO from lock into subnet TAO and produce numerically equal amount of Alpha
// The initial TAO is the locked amount, with a minimum of 1 RAO and a cap of 100 TAO.
let pool_initial_tao = Self::get_network_min_lock();
Expand Down
Loading
Loading