-
Notifications
You must be signed in to change notification settings - Fork 212
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
l0r1s
wants to merge
22
commits into
devnet-ready
Choose a base branch
from
feat/dynamic-symbol
base: devnet-ready
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+833
−525
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
430859b
export SYMBOLS + DEFAULT_SYMBOL constants
l0r1s ecc88be
added utils for tests
l0r1s ecd42d4
added set_symbol extrinsic
l0r1s ef811a8
update the registration logic when setting symbol
l0r1s ae5df93
added tests
l0r1s e25e77b
disallow using root symbol
l0r1s d16a06f
cargo clippy
l0r1s 6a42285
cargo fmt
l0r1s abc9e47
Merge branch 'devnet-ready' into feat/dynamic-symbol
l0r1s 4476a52
cargo clippy
l0r1s 52d46fd
cargo fix
l0r1s a76294b
cargo fmt
l0r1s a1ad985
fix test
l0r1s 8f96894
fix failing tests due to root symbol exclusion
l0r1s b774e4a
make symbols static
l0r1s fe60a3a
remove the use of get_symbol_for_subnet in metagraph/dynamic_info, us…
l0r1s 15ba642
fix clippy + fmt
l0r1s b693505
fix/added new tests
l0r1s 301a5a5
make it faster + rename to update_symbol
l0r1s 84ec48e
fix HashSet to BTreeSet
l0r1s 83308b4
added benchmark + weight
l0r1s 6d039d5
cargo fmt
l0r1s File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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 | ||
.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<_>>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(()) | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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