-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1222 from opentensor/fix/migration-subnet-volume
Add subnet volume migration to fix try-runtime
- Loading branch information
Showing
5 changed files
with
78 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use super::*; | ||
use alloc::string::String; | ||
use frame_support::{traits::Get, weights::Weight}; | ||
|
||
pub fn migrate_subnet_volume<T: Config>() -> Weight { | ||
let migration_name = b"migrate_subnet_volume".to_vec(); | ||
|
||
// Initialize the weight with one read operation. | ||
let weight = T::DbWeight::get().reads(1); | ||
|
||
// Check if the migration has already run | ||
if HasMigrationRun::<T>::get(&migration_name) { | ||
log::info!( | ||
"Migration '{:?}' has already run. Skipping.", | ||
migration_name | ||
); | ||
return weight; | ||
} | ||
log::info!( | ||
"Running migration '{}'", | ||
String::from_utf8_lossy(&migration_name) | ||
); | ||
|
||
let mut migrated = 0u64; | ||
|
||
SubnetVolume::<T>::translate::<u64, _>(|_key, old_value| { | ||
migrated = migrated.saturating_add(1); | ||
Some(old_value as u128) // Convert and store as u128 | ||
}); | ||
|
||
log::info!("Migrated {} entries in SubnetVolume", migrated); | ||
weight.saturating_add(T::DbWeight::get().reads_writes(migrated, migrated)) | ||
} |
This file contains 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 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 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