Skip to content

Commit

Permalink
fix identity migration
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnReedV committed Jul 24, 2024
1 parent dd938c2 commit dc9ee3d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion pallets/subtensor/src/macros/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ mod hooks {
.saturating_add(migrations::migrate_populate_staking_hotkeys::migrate_populate_staking_hotkeys::<T>())
// Fix total coldkey stake.
// Storage version v8 -> v9
.saturating_add(migrations::migrate_fix_total_coldkey_stake::migrate_fix_total_coldkey_stake::<T>());
.saturating_add(migrations::migrate_fix_total_coldkey_stake::migrate_fix_total_coldkey_stake::<T>())
// Migrate Delegate Ids on chain
.saturating_add(migrations::migrate_chain_identity::migrate_set_hotkey_identities::<T>());
weight
}

Expand Down
11 changes: 10 additions & 1 deletion pallets/subtensor/src/migrations/migrate_chain_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn string_to_bounded_vec(input: &str) -> Result<BoundedVec<u8, ConstU32<1024>>,
}

pub fn migrate_set_hotkey_identities<T: Config>() -> Weight {
let migration_name = b"fix_total_coldkey_stake_v7".to_vec();
let migration_name = b"migrate_identities".to_vec();

// Initialize the weight with one read operation.
let mut weight = T::DbWeight::get().reads(1);
Expand Down Expand Up @@ -140,17 +140,26 @@ pub fn migrate_set_hotkey_identities<T: Config>() -> Weight {
&& identity.description.len() <= 1024
&& identity.additional.len() <= 1024;
if !is_valid {
log::info!(
"Bytes not correct"
);
continue;
}

// Get the owning coldkey.
let coldkey = Owner::<T>::get(decoded_hotkey.clone());
log::info!("ColdKey: {:?}", decoded_hotkey);

weight = weight.saturating_add(T::DbWeight::get().reads(1));

// Sink into the map.
Identities::<T>::insert(coldkey.clone(), identity.clone());
weight = weight.saturating_add(T::DbWeight::get().writes(1));
}
} else {
log::info!(
"Failed to decode JSON"
);
}
// Mark the migration as completed
HasMigrationRun::<T>::insert(&migration_name, true);
Expand Down

0 comments on commit dc9ee3d

Please sign in to comment.