|
| 1 | +use crate::*; |
| 2 | +use frame_support::{pallet_prelude::*, traits::OnRuntimeUpgrade}; |
| 3 | +use frame_system::{ConsumedWeight, EventRecord}; |
| 4 | +#[cfg(feature = "try-runtime")] |
| 5 | +use sp_runtime::TryRuntimeError; |
| 6 | + |
| 7 | +/// The log target. |
| 8 | +const TARGET: &'static str = "runtime::system::migration"; |
| 9 | + |
| 10 | +#[frame_support::storage_alias] |
| 11 | +pub(super) type Events<T: frame_system::Config> = StorageValue< |
| 12 | + frame_system::Pallet<T>, |
| 13 | + Vec< |
| 14 | + Box< |
| 15 | + EventRecord< |
| 16 | + <T as frame_system::Config>::RuntimeEvent, |
| 17 | + <T as frame_system::Config>::Hash, |
| 18 | + >, |
| 19 | + >, |
| 20 | + >, |
| 21 | + ValueQuery, |
| 22 | +>; |
| 23 | + |
| 24 | +#[frame_support::storage_alias] |
| 25 | +pub(super) type BlockWeight<T: frame_system::Config> = |
| 26 | + StorageValue<frame_system::Pallet<T>, ConsumedWeight, ValueQuery>; |
| 27 | + |
| 28 | +#[frame_support::storage_alias] |
| 29 | +pub(super) type Digest<T: frame_system::Config> = |
| 30 | + StorageValue<frame_system::Pallet<T>, generic::Digest, ValueQuery>; |
| 31 | + |
| 32 | +pub struct Migrate; |
| 33 | + |
| 34 | +impl OnRuntimeUpgrade for Migrate { |
| 35 | + fn on_runtime_upgrade() -> Weight { |
| 36 | + Weight::zero() |
| 37 | + } |
| 38 | + |
| 39 | + #[cfg(feature = "try-runtime")] |
| 40 | + fn post_upgrade(_state: Vec<u8>) -> Result<(), TryRuntimeError> { |
| 41 | + log::info!(target: TARGET, "In post upgrade"); |
| 42 | + let num_account_keys = frame_system::Account::<Runtime>::iter_keys().count() as u32; |
| 43 | + let num_accounts = frame_system::Account::<Runtime>::iter_values().count() as u32; |
| 44 | + log::info!(target: TARGET, "account keys: {}, decodable accounts: {}", num_account_keys, num_accounts); |
| 45 | + frame_system::Account::<Runtime>::iter().take(10).for_each(|(k, v)| { |
| 46 | + let account_bytes: [u8; 32] = k.clone().into(); |
| 47 | + log::info!(target: TARGET, " "); |
| 48 | + log::info!(target: TARGET, " "); |
| 49 | + log::info!(target: TARGET, "key account bytes: {:?} ", account_bytes); |
| 50 | + log::info!(target: TARGET, "Nonce: {:?}", v.nonce); |
| 51 | + log::info!(target: TARGET, "Consumers: {:?}", v.consumers); |
| 52 | + log::info!(target: TARGET, "Providers: {:?}", v.providers); |
| 53 | + log::info!(target: TARGET, "Sufficients: {:?}", v.sufficients); |
| 54 | + log::info!(target: TARGET, "Data: {:?}", v.data); |
| 55 | + }); |
| 56 | + log::info!(target: TARGET, "block weight: {:?}", BlockWeight::<Runtime>::get()); |
| 57 | + log::info!(target: TARGET, "digest: {:?}", Digest::<Runtime>::get()); |
| 58 | + log::info!(target: TARGET, "last runtime upgrade: {:?}", frame_system::LastRuntimeUpgrade::<Runtime>::get()); |
| 59 | + Ok(()) |
| 60 | + } |
| 61 | +} |
0 commit comments