Skip to content

Commit 470f4b8

Browse files
Added authorship pallet migration to the RuntimeUpgrades struct. Developed the system pallet migration to verify the correct decoding of the block weight and digest storage items. Developed the authorship pallet migration. Developed the society pallet verifier migration. Developed the xcmp queue pallet verifier migration.
1 parent c9ed12f commit 470f4b8

File tree

7 files changed

+143
-2
lines changed

7 files changed

+143
-2
lines changed

runtime/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,16 @@ pub type RuntimeUpgrades = (
143143
migrations::transaction_payment::v0::Migrate,
144144
migrations::uniques::v0::MigrateToV1,
145145
migrations::vesting::v0::MigrateToV1,
146+
migrations::authorship::v0::Migrate,
146147
migrations::general::GeneralMigration,
147148
migrations::identity_verifier::Migrate,
148149
migrations::aura_verifier::Migrate,
149150
migrations::balances_verifier::Migrate,
150151
migrations::collator_selection_verifier::Migrate,
151152
migrations::dmp_queue_verifier::Migrate,
152-
migrations::proxy_verifier::Migrate
153+
migrations::proxy_verifier::Migrate,
154+
migrations::society_verifier::Migrate,
155+
migrations::xcmp_queue_verifier::Migrate
153156
);
154157

155158
/// Executive: handles dispatch to the various modules.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use super::*;
2+
use crate::*;
3+
use frame_support::{
4+
pallet_prelude::*,
5+
traits::{Currency, OnRuntimeUpgrade},
6+
};
7+
8+
#[cfg(feature = "try-runtime")]
9+
use sp_runtime::TryRuntimeError;
10+
11+
/// The log target.
12+
const TARGET: &'static str = "runtime::authorship::migration";
13+
14+
pub mod v0 {
15+
use super::*;
16+
/// The actual type isn't important, as we only delete the key in the state.
17+
#[frame_support::storage_alias]
18+
pub(super) type Uncles<T: pallet_authorship::Config> =
19+
StorageValue<pallet_authorship::Pallet<T>, (), ValueQuery>;
20+
21+
#[frame_support::storage_alias]
22+
pub(super) type DidSetUncles<T: pallet_authorship::Config> =
23+
StorageValue<pallet_authorship::Pallet<T>, bool, ValueQuery>;
24+
25+
pub struct Migrate;
26+
27+
impl OnRuntimeUpgrade for Migrate {
28+
fn on_runtime_upgrade() -> Weight {
29+
Uncles::<Runtime>::kill();
30+
DidSetUncles::<Runtime>::kill();
31+
log::info!(target: TARGET, "Killed deprecated storages");
32+
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(0, 2)
33+
}
34+
}
35+
}

runtime/src/migrations/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ pub mod vesting;
1010
pub mod collator_selection_verifier;
1111
pub mod dmp_queue_verifier;
1212
pub mod proxy_verifier;
13+
pub mod society_verifier;
14+
pub mod xcmp_queue_verifier;
15+
pub mod authorship;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use crate::*;
2+
use frame_support::{
3+
pallet_prelude::*,
4+
traits::{Currency, OnRuntimeUpgrade},
5+
};
6+
use frame_system::pallet_prelude::BlockNumberFor;
7+
use super::*;
8+
9+
#[cfg(feature = "try-runtime")]
10+
use sp_runtime::TryRuntimeError;
11+
12+
/// The log target.
13+
const TARGET: &'static str = "runtime::society_verifier::migration";
14+
15+
pub struct Migrate;
16+
17+
impl OnRuntimeUpgrade for Migrate {
18+
19+
fn on_runtime_upgrade() -> Weight {
20+
return Weight::zero()
21+
}
22+
23+
#[cfg(feature = "try-runtime")]
24+
fn post_upgrade(state: Vec<u8>) -> Result<(), TryRuntimeError> {
25+
log::info!(target: TARGET, "In post upgrade");
26+
27+
let candidates_count = pallet_society::Candidates::<Runtime>::iter_keys().count() as u32;
28+
let decodable_candidates_count = pallet_society::Candidates::<Runtime>::iter_values().count() as u32;
29+
// IdentityOf::<Runtime>::get(key)
30+
pallet_society::Candidates::<Runtime>::iter().for_each(|(k, v)| {
31+
let account_bytes: [u8; 32] = k.clone().into();
32+
log::info!(" ");
33+
log::info!(" ");
34+
log::info!("key account bytes: {:?} ", account_bytes);
35+
log::info!("Candidacy: {:?}", v);
36+
});
37+
log::info!(target: TARGET, "Num candidates: {}, decodable: {}", candidates_count, decodable_candidates_count);
38+
Ok(())
39+
}
40+
}

runtime/src/migrations/system.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use frame_support::{
66
traits::{Currency, OnRuntimeUpgrade},
77
};
88
use frame_system::pallet_prelude::BlockNumberFor;
9+
use frame_system::ConsumedWeight;
910
#[cfg(feature = "try-runtime")]
1011
use sp_runtime::TryRuntimeError;
1112

@@ -35,6 +36,12 @@ pub mod v0 {
3536
pub(super) type Events<T: frame_system::Config> =
3637
StorageValue<frame_system::Pallet<T>, Vec<Box<EventRecord<<T as frame_system::Config>::RuntimeEvent, <T as frame_system::Config>::Hash>>>, ValueQuery>;
3738

39+
#[frame_support::storage_alias]
40+
pub(super) type BlockWeight<T: frame_system::Config> = StorageValue<frame_system::Pallet<T>, ConsumedWeight, ValueQuery>;
41+
42+
#[frame_support::storage_alias]
43+
pub(super) type Digest<T: frame_system::Config> = StorageValue<frame_system::Pallet<T>, generic::Digest, ValueQuery>;
44+
3845
pub struct Migrate;
3946

4047
impl OnRuntimeUpgrade for Migrate {
@@ -104,6 +111,9 @@ pub mod v0 {
104111
log::info!("Sufficients: {:?}", v.sufficients);
105112
log::info!("Data: {:?}", v.data);
106113
});
114+
log::info!(target: TARGET, "block weight: {:?}", BlockWeight::<Runtime>::get());
115+
log::info!(target: TARGET, "digest: {:?}", Digest::<Runtime>::get());
116+
log::info!(target: TARGET, "last runtime upgrade: {:?}", frame_system::LastRuntimeUpgrade::<Runtime>::get());
107117
// let events = Events::<Runtime>::get();
108118
// log::info!(target: TARGET, "num_events: {}", events.len());
109119
// events.iter().take(10).for_each(|v|{

runtime/src/migrations/transaction_payment.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ use sp_runtime::traits::Saturating;
5555
}
5656
//We are just updating the storage version, as the pallet is already on the latest version
5757
fn on_runtime_upgrade() -> Weight {
58-
let storage_version = StorageVersion::<Runtime>::get();
5958
let mut writes = 0;
6059
let storage_version = StorageVersion::<Runtime>::get();
6160
if storage_version == Releases::V1Ancient {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
use crate::*;
2+
use frame_support::{
3+
pallet_prelude::*,
4+
traits::{Currency, OnRuntimeUpgrade},
5+
};
6+
use frame_system::pallet_prelude::BlockNumberFor;
7+
use cumulus_pallet_xcmp_queue::{QueueConfigData, OverweightIndex};
8+
use cumulus_primitives_core::relay_chain::BlockNumber as RelayBlockNumber;
9+
use crate::ParaId;
10+
use super::*;
11+
12+
#[cfg(feature = "try-runtime")]
13+
use sp_runtime::TryRuntimeError;
14+
15+
/// The log target.
16+
const TARGET: &'static str = "runtime::xcmp_queue_verifier::migration";
17+
18+
19+
#[frame_support::storage_alias]
20+
pub(super) type Overweight<T: cumulus_pallet_xcmp_queue::Config> =
21+
CountedStorageMap<cumulus_pallet_xcmp_queue::Pallet<T>, Twox64Concat, OverweightIndex, (ParaId, RelayBlockNumber, Vec<u8>)>;
22+
23+
#[frame_support::storage_alias]
24+
pub(super) type QueueConfig<T: cumulus_pallet_xcmp_queue::Config> = StorageValue<cumulus_pallet_xcmp_queue::Pallet<T>, QueueConfigData, ValueQuery>;
25+
26+
pub struct Migrate;
27+
28+
impl OnRuntimeUpgrade for Migrate {
29+
30+
fn on_runtime_upgrade() -> Weight {
31+
return Weight::zero()
32+
}
33+
34+
#[cfg(feature = "try-runtime")]
35+
fn post_upgrade(state: Vec<u8>) -> Result<(), TryRuntimeError> {
36+
log::info!(target: TARGET, "In post upgrade");
37+
let overweight_tracked_count = Overweight::<Runtime>::count();
38+
let overweight_count = Overweight::<Runtime>::iter_keys().count() as u32;
39+
let decodable_overweight_count = Overweight::<Runtime>::iter_values().count() as u32;
40+
log::info!(target: TARGET, "Num overweight: {}, decodable: {}, tracked: {}", overweight_count, decodable_overweight_count, overweight_tracked_count);
41+
Overweight::<Runtime>::iter().for_each(|(k, v)| {
42+
log::info!(" ");
43+
log::info!(" ");
44+
log::info!("overweight index: {} ", k);
45+
log::info!("overweight: {:?}", v);
46+
});
47+
48+
log::info!("config data: {:?} ", QueueConfig::<Runtime>::get());
49+
Ok(())
50+
}
51+
}

0 commit comments

Comments
 (0)