forked from paritytech/substrate
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pallet dev mode (paritytech#12536)
* stub for construct_dev_runtime! * revert * stub for dev_mode proc macro * preliminary docs for pallet::dev_mode (attribute) proc macro * add dev_mode to pallet_macros module * add docs item for dev_mode to frame_support * parsing of #[pallet(dev_mode)] * strip out dev_mode stub since it will be an arg for pallet instead * make pallet Def struct aware of dev mode * WIP * revert changes to call.rs * pass dev_mode to pallet parsing code * auto-specify default weights when in dev mode if not specified * add proof / expect for syn::parse in dev mode weight processing * set all storages to unbounded when in dev mode * just use 0 Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> * add invalid pallet arg test * add passing dev mode pallet test * add test confirming that dev mode features only work in dev mode * cargo fmt + clean up * bump CI * fix pallet ui test * add docs for dev mode * add warning about using dev mode in production circumstances * remove comment about no other attributes being supported * fix unneeded assignment * make warning more explicit * more explicit warning about using dev mode in production * simpler assignment for dev_mode boolean Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * add note about MEL requirement Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * add comment specifying why weights can be omitted in example Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * tweak wording of comments * bump ci Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
- Loading branch information
Showing
14 changed files
with
233 additions
and
12 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
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
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
error: Invalid pallet macro call: expected no attributes, e.g. macro call must be just `#[frame_support::pallet]` or `#[pallet]` | ||
--> $DIR/attr_non_empty.rs:1:26 | ||
error: Invalid pallet macro call: unexpected attribute. Macro call must be bare, such as `#[frame_support::pallet]` or `#[pallet]`, or must specify the `dev_mode` attribute, such as `#[frame_support::pallet(dev_mode)]` or #[pallet(dev_mode)]. | ||
--> tests/pallet_ui/attr_non_empty.rs:1:26 | ||
| | ||
1 | #[frame_support::pallet [foo]] | ||
| ^^^ |
33 changes: 33 additions & 0 deletions
33
frame/support/test/tests/pallet_ui/dev_mode_without_arg.rs
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,33 @@ | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
pub use pallet::*; | ||
|
||
#[frame_support::pallet] | ||
pub mod pallet { | ||
use frame_support::pallet_prelude::*; | ||
use frame_system::pallet_prelude::*; | ||
|
||
// The struct on which we build all of our Pallet logic. | ||
#[pallet::pallet] | ||
pub struct Pallet<T>(_); | ||
|
||
// Your Pallet's configuration trait, representing custom external types and interfaces. | ||
#[pallet::config] | ||
pub trait Config: frame_system::Config {} | ||
|
||
#[pallet::storage] | ||
type MyStorage<T: Config> = StorageValue<_, Vec<u8>>; | ||
|
||
// Your Pallet's callable functions. | ||
#[pallet::call] | ||
impl<T: Config> Pallet<T> { | ||
pub fn my_call(_origin: OriginFor<T>) -> DispatchResult { | ||
Ok(()) | ||
} | ||
} | ||
|
||
// Your Pallet's internal functions. | ||
impl<T: Config> Pallet<T> {} | ||
} | ||
|
||
fn main() {} |
11 changes: 11 additions & 0 deletions
11
frame/support/test/tests/pallet_ui/dev_mode_without_arg.stderr
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,11 @@ | ||
error: Invalid pallet::call, requires weight attribute i.e. `#[pallet::weight($expr)]` | ||
--> tests/pallet_ui/dev_mode_without_arg.rs:24:7 | ||
| | ||
24 | pub fn my_call(_origin: OriginFor<T>) -> DispatchResult { | ||
| ^^ | ||
|
||
error[E0432]: unresolved import `pallet` | ||
--> tests/pallet_ui/dev_mode_without_arg.rs:3:9 | ||
| | ||
3 | pub use pallet::*; | ||
| ^^^^^^ help: a similar path exists: `test_pallet::pallet` |
34 changes: 34 additions & 0 deletions
34
frame/support/test/tests/pallet_ui/dev_mode_without_arg_max_encoded_len.rs
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,34 @@ | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
pub use pallet::*; | ||
|
||
#[frame_support::pallet] | ||
pub mod pallet { | ||
use frame_support::pallet_prelude::*; | ||
use frame_system::pallet_prelude::*; | ||
|
||
// The struct on which we build all of our Pallet logic. | ||
#[pallet::pallet] | ||
pub struct Pallet<T>(_); | ||
|
||
// Your Pallet's configuration trait, representing custom external types and interfaces. | ||
#[pallet::config] | ||
pub trait Config: frame_system::Config {} | ||
|
||
#[pallet::storage] | ||
type MyStorage<T: Config> = StorageValue<_, Vec<u8>>; | ||
|
||
// Your Pallet's callable functions. | ||
#[pallet::call] | ||
impl<T: Config> Pallet<T> { | ||
#[pallet::weight(0)] | ||
pub fn my_call(_origin: OriginFor<T>) -> DispatchResult { | ||
Ok(()) | ||
} | ||
} | ||
|
||
// Your Pallet's internal functions. | ||
impl<T: Config> Pallet<T> {} | ||
} | ||
|
||
fn main() {} |
17 changes: 17 additions & 0 deletions
17
frame/support/test/tests/pallet_ui/dev_mode_without_arg_max_encoded_len.stderr
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,17 @@ | ||
error[E0277]: the trait bound `Vec<u8>: MaxEncodedLen` is not satisfied | ||
--> tests/pallet_ui/dev_mode_without_arg_max_encoded_len.rs:11:12 | ||
| | ||
11 | #[pallet::pallet] | ||
| ^^^^^^ the trait `MaxEncodedLen` is not implemented for `Vec<u8>` | ||
| | ||
= help: the following other types implement trait `MaxEncodedLen`: | ||
() | ||
(TupleElement0, TupleElement1) | ||
(TupleElement0, TupleElement1, TupleElement2) | ||
(TupleElement0, TupleElement1, TupleElement2, TupleElement3) | ||
(TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4) | ||
(TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5) | ||
(TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5, TupleElement6) | ||
(TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5, TupleElement6, TupleElement7) | ||
and 78 others | ||
= note: required because of the requirements on the impl of `StorageInfoTrait` for `frame_support::pallet_prelude::StorageValue<_GeneratedPrefixForStorageMyStorage<T>, Vec<u8>>` |
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,4 @@ | ||
#[frame_support::pallet(foo)] | ||
pub mod pallet {} | ||
|
||
fn main() {} |
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,5 @@ | ||
error: Invalid pallet macro call: unexpected attribute. Macro call must be bare, such as `#[frame_support::pallet]` or `#[pallet]`, or must specify the `dev_mode` attribute, such as `#[frame_support::pallet(dev_mode)]` or #[pallet(dev_mode)]. | ||
--> tests/pallet_ui/pallet_invalid_arg.rs:1:25 | ||
| | ||
1 | #[frame_support::pallet(foo)] | ||
| ^^^ |
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,35 @@ | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
pub use pallet::*; | ||
|
||
#[frame_support::pallet(dev_mode)] | ||
pub mod pallet { | ||
use frame_support::pallet_prelude::*; | ||
use frame_system::pallet_prelude::*; | ||
|
||
// The struct on which we build all of our Pallet logic. | ||
#[pallet::pallet] | ||
pub struct Pallet<T>(_); | ||
|
||
// Your Pallet's configuration trait, representing custom external types and interfaces. | ||
#[pallet::config] | ||
pub trait Config: frame_system::Config {} | ||
|
||
// The MEL requirement for bounded pallets is skipped by `dev_mode`. | ||
#[pallet::storage] | ||
type MyStorage<T: Config> = StorageValue<_, Vec<u8>>; | ||
|
||
// Your Pallet's callable functions. | ||
#[pallet::call] | ||
impl<T: Config> Pallet<T> { | ||
// No need to define a `weight` attribute here because of `dev_mode`. | ||
pub fn my_call(_origin: OriginFor<T>) -> DispatchResult { | ||
Ok(()) | ||
} | ||
} | ||
|
||
// Your Pallet's internal functions. | ||
impl<T: Config> Pallet<T> {} | ||
} | ||
|
||
fn main() {} |