Add new subnet identity version with agent_docs_url#2501
Add new subnet identity version with agent_docs_url#2501bdmason wants to merge 4 commits intoopentensor:devnet-readyfrom
Conversation
| pub fn migrate_subnet_identity_v3_to_v4<T: Config>() -> Weight { | ||
| let migration_name = b"migrate_subnet_identity_v3_to_v4".to_vec(); | ||
| let mut weight = T::DbWeight::get().reads(1); | ||
|
|
||
| if HasMigrationRun::<T>::get(&migration_name) { | ||
| log::info!( | ||
| "Migration '{:?}' has already run. Skipping.", | ||
| String::from_utf8_lossy(&migration_name) | ||
| ); | ||
| return weight; | ||
| } | ||
|
|
||
| log::info!( | ||
| "Running migration '{}'", | ||
| String::from_utf8_lossy(&migration_name), | ||
| ); | ||
|
|
||
| let mut migrated_count: u64 = 0; | ||
|
|
||
| for (netuid, v3_identity) in SubnetIdentitiesV3::<T>::iter() { | ||
| let v4_identity = SubnetIdentityOfV4 { | ||
| subnet_name: v3_identity.subnet_name, | ||
| github_repo: v3_identity.github_repo, | ||
| subnet_contact: v3_identity.subnet_contact, | ||
| subnet_url: v3_identity.subnet_url, | ||
| discord: v3_identity.discord, | ||
| description: v3_identity.description, | ||
| logo_url: v3_identity.logo_url, | ||
| additional: v3_identity.additional, | ||
| agent_docs_url: vec![], | ||
| }; | ||
| SubnetIdentitiesV4::<T>::insert(netuid, v4_identity); | ||
| migrated_count += 1; | ||
| } | ||
|
|
||
| weight = weight.saturating_add(T::DbWeight::get().reads(migrated_count)); | ||
| weight = weight.saturating_add(T::DbWeight::get().writes(migrated_count)); | ||
|
|
||
| // Remove old V3 entries | ||
| remove_prefix::<T>("SubtensorModule", "SubnetIdentitiesV3", &mut weight); | ||
|
|
||
| HasMigrationRun::<T>::insert(&migration_name, true); | ||
| weight = weight.saturating_add(T::DbWeight::get().writes(1)); | ||
|
|
||
| log::info!( | ||
| "Migration '{:?}' completed successfully. Migrated {migrated_count:?} subnet identities.", | ||
| String::from_utf8_lossy(&migration_name) | ||
| ); | ||
|
|
||
| weight | ||
| } |
There was a problem hiding this comment.
This should be done in place for V3.
pallets/subtensor/src/lib.rs
Outdated
| } | ||
|
|
||
| /// Struct for SubnetIdentitiesV4. | ||
| pub type SubnetIdentityOfV4 = SubnetIdentityV4; |
There was a problem hiding this comment.
This line is useless. What should be defined is SubnetIdentityOf<T> and it should be used across the codebase to avoid having to rename everytime there is a change.
You can get an example here
pallets/subtensor/src/lib.rs
Outdated
| /// --- MAP ( netuid ) --> SubnetIdentityOfV4 | ||
| #[pallet::storage] | ||
| pub type SubnetIdentitiesV4<T: Config> = | ||
| StorageMap<_, Blake2_128Concat, NetUid, SubnetIdentityOfV4, OptionQuery>; |
There was a problem hiding this comment.
Not needed. We shouldn't be adding a new storage map for each version.
|
@l0r1s I've made the changes requested. I think this makes the storage item look more consistent, but it does not eliminate the downstream breaking change. It just makes it more subtle.
We still need to document this as a breaking change for anyone using |
Description
Adds a new field
agent_docs_urlto subnet identities.Related Issue(s)
NA
Type of Change
Breaking Change
Any applications reading the old storage item would need to use the new one.
Checklist
./scripts/fix_rust.shto ensure my code is formatted and linted correctlyScreenshots (if applicable)
Please include any relevant screenshots or GIFs that demonstrate the changes made.
Additional Notes
Please provide any additional information or context that may be helpful for reviewers.