mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 23:31:07 +00:00
Add migration logs to pallet v2 (#8243)
* Add logs to proc macro pallet. * update logs.
This commit is contained in:
@@ -25,6 +25,29 @@ pub fn expand_hooks(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
let pallet_ident = &def.pallet_struct.pallet;
|
||||
let where_clause = &def.hooks.where_clause;
|
||||
let frame_system = &def.frame_system;
|
||||
let has_runtime_upgrade = def.hooks.has_runtime_upgrade;
|
||||
|
||||
let log_runtime_upgrade = if has_runtime_upgrade {
|
||||
// a migration is defined here.
|
||||
quote::quote! {
|
||||
#frame_support::log::info!(
|
||||
target: #frame_support::LOG_TARGET,
|
||||
"⚠️ {} declares internal migrations (which *might* execute), setting storage version to {:?}",
|
||||
pallet_name,
|
||||
new_storage_version,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// default.
|
||||
quote::quote! {
|
||||
#frame_support::log::info!(
|
||||
target: #frame_support::LOG_TARGET,
|
||||
"✅ no migration for {}, setting storage version to {:?}",
|
||||
pallet_name,
|
||||
new_storage_version,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
quote::quote_spanned!(def.hooks.attr_span =>
|
||||
impl<#type_impl_gen>
|
||||
@@ -60,14 +83,22 @@ pub fn expand_hooks(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
for #pallet_ident<#type_use_gen> #where_clause
|
||||
{
|
||||
fn on_runtime_upgrade() -> #frame_support::weights::Weight {
|
||||
// log info about the upgrade.
|
||||
let new_storage_version = #frame_support::crate_to_pallet_version!();
|
||||
let pallet_name = <
|
||||
<T as #frame_system::Config>::PalletInfo
|
||||
as
|
||||
#frame_support::traits::PalletInfo
|
||||
>::name::<Self>().unwrap_or("<unknown pallet name>");
|
||||
#log_runtime_upgrade
|
||||
|
||||
let result = <
|
||||
Self as #frame_support::traits::Hooks<
|
||||
<T as #frame_system::Config>::BlockNumber
|
||||
>
|
||||
>::on_runtime_upgrade();
|
||||
|
||||
#frame_support::crate_to_pallet_version!()
|
||||
.put_into_storage::<<T as #frame_system::Config>::PalletInfo, Self>();
|
||||
new_storage_version.put_into_storage::<<T as #frame_system::Config>::PalletInfo, Self>();
|
||||
|
||||
let additional_write = <
|
||||
<T as #frame_system::Config>::DbWeight as #frame_support::traits::Get<_>
|
||||
|
||||
@@ -28,6 +28,8 @@ pub struct HooksDef {
|
||||
pub where_clause: Option<syn::WhereClause>,
|
||||
/// The span of the pallet::hooks attribute.
|
||||
pub attr_span: proc_macro2::Span,
|
||||
/// Boolean flag, set to true if the `on_runtime_upgrade` method of hooks was implemented.
|
||||
pub has_runtime_upgrade: bool,
|
||||
}
|
||||
|
||||
impl HooksDef {
|
||||
@@ -66,10 +68,16 @@ impl HooksDef {
|
||||
return Err(syn::Error::new(item_trait.span(), msg));
|
||||
}
|
||||
|
||||
let has_runtime_upgrade = item.items.iter().any(|i| match i {
|
||||
syn::ImplItem::Method(method) => method.sig.ident == "on_runtime_upgrade",
|
||||
_ => false,
|
||||
});
|
||||
|
||||
Ok(Self {
|
||||
attr_span,
|
||||
index,
|
||||
instances,
|
||||
has_runtime_upgrade,
|
||||
where_clause: item.generics.where_clause.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1329,9 +1329,22 @@ macro_rules! decl_module {
|
||||
{
|
||||
fn on_runtime_upgrade() -> $return {
|
||||
$crate::sp_tracing::enter_span!($crate::sp_tracing::trace_span!("on_runtime_upgrade"));
|
||||
let pallet_name = <<
|
||||
$trait_instance
|
||||
as
|
||||
$system::Config
|
||||
>::PalletInfo as $crate::traits::PalletInfo>::name::<Self>().unwrap_or("<unknown pallet name>");
|
||||
let new_storage_version = $crate::crate_to_pallet_version!();
|
||||
|
||||
$crate::log::info!(
|
||||
target: $crate::LOG_TARGET,
|
||||
"⚠️ {} declares internal migrations (which *might* execute), setting storage version to {:?}",
|
||||
pallet_name,
|
||||
new_storage_version,
|
||||
);
|
||||
|
||||
let result: $return = (|| { $( $impl )* })();
|
||||
|
||||
let new_storage_version = $crate::crate_to_pallet_version!();
|
||||
new_storage_version
|
||||
.put_into_storage::<<$trait_instance as $system::Config>::PalletInfo, Self>();
|
||||
|
||||
@@ -1339,19 +1352,6 @@ macro_rules! decl_module {
|
||||
<$trait_instance as $system::Config>::DbWeight as $crate::traits::Get<_>
|
||||
>::get().writes(1);
|
||||
|
||||
let pallet_name = <<
|
||||
$trait_instance
|
||||
as
|
||||
$system::Config
|
||||
>::PalletInfo as $crate::traits::PalletInfo>::name::<Self>().expect("pallet will have name in the runtime; qed");
|
||||
|
||||
$crate::log::info!(
|
||||
target: $crate::LOG_TARGET,
|
||||
"⚠️ running migration for {} and setting new storage version to {:?}",
|
||||
pallet_name,
|
||||
new_storage_version,
|
||||
);
|
||||
|
||||
result.saturating_add(additional_write)
|
||||
}
|
||||
|
||||
@@ -1378,27 +1378,24 @@ macro_rules! decl_module {
|
||||
{
|
||||
fn on_runtime_upgrade() -> $crate::dispatch::Weight {
|
||||
$crate::sp_tracing::enter_span!($crate::sp_tracing::trace_span!("on_runtime_upgrade"));
|
||||
|
||||
let new_storage_version = $crate::crate_to_pallet_version!();
|
||||
new_storage_version
|
||||
.put_into_storage::<<$trait_instance as $system::Config>::PalletInfo, Self>();
|
||||
|
||||
let pallet_name = <<
|
||||
$trait_instance
|
||||
as
|
||||
$system::Config
|
||||
>::PalletInfo as $crate::traits::PalletInfo>::name::<Self>().expect("pallet will have name in the runtime; qed");
|
||||
>::PalletInfo as $crate::traits::PalletInfo>::name::<Self>().unwrap_or("<unknown pallet name>");
|
||||
let new_storage_version = $crate::crate_to_pallet_version!();
|
||||
|
||||
$crate::log::info!(
|
||||
target: $crate::LOG_TARGET,
|
||||
"✅ no migration for '{}' and setting new storage version to {:?}",
|
||||
"✅ no migration for {}, setting storage version to {:?}",
|
||||
pallet_name,
|
||||
new_storage_version,
|
||||
);
|
||||
|
||||
<
|
||||
<$trait_instance as $system::Config>::DbWeight as $crate::traits::Get<_>
|
||||
>::get().writes(1)
|
||||
new_storage_version
|
||||
.put_into_storage::<<$trait_instance as $system::Config>::PalletInfo, Self>();
|
||||
|
||||
<<$trait_instance as $system::Config>::DbWeight as $crate::traits::Get<_>>::get().writes(1)
|
||||
}
|
||||
|
||||
#[cfg(feature = "try-runtime")]
|
||||
|
||||
Reference in New Issue
Block a user