Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Create sp-weights crate to store weight primitives #12219

Merged
merged 35 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6e10966
Create sp-weights crate to store weight primitives
KiChjang Sep 7, 2022
5e4dd1d
Merge remote-tracking branch 'origin/master' into kckyeung/sp-weights
KiChjang Sep 8, 2022
43ab5e6
Fix templates
KiChjang Sep 8, 2022
e5bace0
Fix templates
KiChjang Sep 8, 2022
87a1ff4
Fixes
KiChjang Sep 8, 2022
6b1c48c
Fixes
KiChjang Sep 8, 2022
f17e1b2
cargo fmt
KiChjang Sep 8, 2022
48a88cc
Fixes
KiChjang Sep 8, 2022
19ae7dd
Fixes
KiChjang Sep 8, 2022
4728a95
Use deprecated type alias instead of deprecated unit types
KiChjang Sep 8, 2022
70b56ec
Use deprecated subtraits instead of deprecated hollow new traits
KiChjang Sep 8, 2022
8415f32
Fixes
KiChjang Sep 8, 2022
39ba7b9
Allow deprecation in macro expansion
KiChjang Sep 8, 2022
d7bcf1f
Add missing where clause during call macro expansion
KiChjang Sep 9, 2022
fb468e9
cargo fmt
KiChjang Sep 9, 2022
c51cde5
Fixes
KiChjang Sep 9, 2022
e4c44fa
cargo fmt
KiChjang Sep 9, 2022
ef1be20
Fixes
KiChjang Sep 9, 2022
12c3e06
Fixes
KiChjang Sep 9, 2022
1937813
Fixes
KiChjang Sep 9, 2022
531986c
Fixes
KiChjang Sep 9, 2022
51b7b21
Move FRAME-specific weight files back to frame_support
KiChjang Sep 12, 2022
d43dd83
Fixes
KiChjang Sep 12, 2022
88223b7
Merge branch 'master' into kckyeung/sp-weights
shawntabrizi Sep 12, 2022
d029aa4
Update frame/support/src/dispatch.rs
KiChjang Sep 13, 2022
029f121
Update frame/support/src/dispatch.rs
KiChjang Sep 13, 2022
f6dc099
Update frame/support/src/dispatch.rs
KiChjang Sep 13, 2022
56407a5
Add missing header
KiChjang Sep 13, 2022
3c5455a
Rewrite module docs
KiChjang Sep 13, 2022
eca462f
Merge remote-tracking branch 'origin/master' into kckyeung/sp-weights
KiChjang Sep 13, 2022
3f8e33f
Fixes
KiChjang Sep 13, 2022
785fe95
Fixes
KiChjang Sep 13, 2022
8bcc6f1
Fixes
KiChjang Sep 13, 2022
9e235f9
Fixes
KiChjang Sep 13, 2022
1880f7a
cargo fmt
KiChjang Sep 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use deprecated subtraits instead of deprecated hollow new traits
  • Loading branch information
KiChjang committed Sep 8, 2022
commit 70b56ec99b2ee581667b66409c8447cdd56a8d44
2 changes: 2 additions & 0 deletions frame/support/procedural/src/construct_runtime/expand/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ pub fn expand_outer_dispatch(
}
}
}
// Deprecated, but will warn when used
impl #scrate::weights::GetDispatchInfo for Call {}
impl #scrate::dispatch::GetCallMetadata for Call {
fn get_call_metadata(&self) -> #scrate::dispatch::CallMetadata {
use #scrate::dispatch::GetCallName;
Expand Down
63 changes: 44 additions & 19 deletions frame/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,44 +93,69 @@ pub mod unsigned {
}

pub mod weights {
use crate::dispatch;
pub use sp_weights::*;

#[deprecated = "Function has moved to `frame_support::dispatch`"]
pub fn extract_actual_pays_fee(
res: &crate::dispatch::DispatchResultWithPostInfo,
info: &crate::dispatch::DispatchInfo,
) -> crate::dispatch::Pays {
crate::dispatch::extract_actual_pays_fee(res, info)
res: &dispatch::DispatchResultWithPostInfo,
info: &dispatch::DispatchInfo,
) -> dispatch::Pays {
dispatch::extract_actual_pays_fee(res, info)
}
#[deprecated = "Function has moved to `frame_support::dispatch`"]
pub fn extract_actual_weight(
res: &crate::dispatch::DispatchResultWithPostInfo,
info: &crate::dispatch::DispatchInfo,
) -> sp_weights::Weight {
crate::dispatch::extract_actual_weight(res, info)
res: &dispatch::DispatchResultWithPostInfo,
info: &dispatch::DispatchInfo,
) -> Weight {
dispatch::extract_actual_weight(res, info)
}
#[deprecated = "Trait has moved to `frame_support::dispatch`"]
pub trait ClassifyDispatch<T> {}
pub trait ClassifyDispatch<T>: dispatch::ClassifyDispatch<T> {
fn classify_dispatch(&self, target: T) -> dispatch::DispatchClass {
<Self as dispatch::ClassifyDispatch<T>>::classify_dispatch(self, target)
}
}
#[deprecated = "Enum has moved to `frame_support::dispatch`"]
pub type DispatchClass = crate::dispatch::DispatchClass;
pub type DispatchClass = dispatch::DispatchClass;
#[deprecated = "Struct has moved to `frame_support::dispatch`"]
pub type DispatchInfo = crate::dispatch::DispatchInfo;
pub type DispatchInfo = dispatch::DispatchInfo;
#[deprecated = "Trait has moved to `frame_support::dispatch`"]
pub trait GetDispatchInfo {}
pub trait GetDispatchInfo: dispatch::GetDispatchInfo {
fn get_dispatch_info(&self) -> dispatch::DispatchInfo {
<Self as dispatch::GetDispatchInfo>::get_dispatch_info(self)
}
}
#[deprecated = "Trait has moved to `frame_support::dispatch`"]
pub trait OneOrMany {}
pub trait OneOrMany<T>: dispatch::OneOrMany<T> {
fn into_iter(self) -> Self::Iter where Self: Sized {
<Self as dispatch::OneOrMany<T>>::into_iter(self)
}
}
#[deprecated = "Enum has moved to `frame_support::dispatch`"]
pub type Pays = crate::dispatch::Pays;
pub type Pays = dispatch::Pays;
#[deprecated = "Trait has moved to `frame_support::dispatch`"]
pub trait PaysFee<T> {}
pub trait PaysFee<T>: dispatch::PaysFee<T> {
fn pays_fee(&self, target: T) -> dispatch::Pays {
<Self as dispatch::PaysFee<T>>::pays_fee(self, target)
}
}
#[deprecated = "Struct has moved to `frame_support::dispatch`"]
pub type PerDispatchClass<T> = crate::dispatch::PerDispatchClass<T>;
pub type PerDispatchClass<T> = dispatch::PerDispatchClass<T>;
#[deprecated = "Struct has moved to `frame_support::dispatch`"]
pub type PostDispatchInfo = crate::dispatch::PostDispatchInfo;
pub type PostDispatchInfo = dispatch::PostDispatchInfo;
#[deprecated = "Trait has moved to `frame_support::dispatch`"]
pub trait WeighData {}
pub trait WeighData<T>: dispatch::WeighData<T> {
fn weigh_data(&self, target: T) -> Weight {
<Self as dispatch::WeighData<T>>::weigh_data(self, target)
}
}
#[deprecated = "Trait has moved to `frame_support::dispatch`"]
pub trait WithPostDispatchInfo {}
pub trait WithPostDispatchInfo: dispatch::WithPostDispatchInfo {
fn with_weight(self, actual_weight: Weight) -> dispatch::DispatchErrorWithPostInfo where Self: Sized {
<Self as dispatch::WithPostDispatchInfo>::with_weight(self, actual_weight)
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm attempting to try a novel way to deprecate types that have been moved, and one of the ways that I can think of is to create new subtraits and type alias and immediately deprecating them, telling the FRAME dev that the trait/type has been moved to another location.

Would be nice if I get some eye balls on this to ensure that this is worthwhile to pursue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea here is to create code that still works like the old way, but would emit a deprecation warning about the usage. This would make it easier for people to migrate over to the new location by allowing them to do so at a time of their choosing, while still having code that works.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks decent to me, just not sure when and based on what criteria are we going to remove the old code? we also have not removed the old macros now for more than a year and it is unclear to me when we are going to.

If there's no clear answer to this, I think it is also reasonable to just break the code downstream instead of keeping a lot of duplicate code around.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could stick a comment stating that the old methods will be removed once we get to date x.

}

#[cfg(any(feature = "std", feature = "runtime-benchmarks", test))]
Expand Down