-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update bucket_id type from u128 to u64 and add storage migration
- Loading branch information
Showing
2 changed files
with
52 additions
and
7 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,36 @@ | ||
use super::*; | ||
|
||
use frame_support::{ | ||
storage_alias, | ||
traits::{Get, GetStorageVersion, StorageVersion}, | ||
weights::Weight, | ||
BoundedVec, Twox64Concat, | ||
}; | ||
|
||
// only contains V1 storage format | ||
pub mod v1 { | ||
use super::*; | ||
|
||
#[storage_alias] | ||
pub(super) type Buckets<T: Config> = | ||
StorageMap<Pallet<T>, Twox64Concat, u64, Bucket<<T as frame_system::Config>::AccountId>>; | ||
} | ||
|
||
// contains checks and transforms storage to V2 format | ||
pub fn migrate_to_v2<T: Config>() -> Weight { | ||
// We transform the storage values from the old into the new format. | ||
Buckets::<T>::translate::<Bucket<T::AccountId>, _>(|_k: u64, bucket: Bucket<T::AccountId>| { | ||
Some(Bucket { | ||
bucket_id: bucket.bucket_id as u64, | ||
owner_id: bucket.owner_id, | ||
cluster_id: bucket.cluster_id, | ||
public_availability: bucket.public_availability, | ||
resources_reserved: bucket.resources_reserved, | ||
}) | ||
}); | ||
|
||
// Very inefficient, mostly here for illustration purposes. | ||
let count = Buckets::<T>::iter().count(); | ||
// Return the weight consumed by the migration. | ||
T::DbWeight::get().reads_writes(count as u64 + 1, count as u64 + 1) | ||
} |