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

Make hooks and call attributes optional in pallet macro #8853

Merged
8 commits merged into from
May 20, 2021

Conversation

KiChjang
Copy link
Contributor

Fixes #8725.

@KiChjang KiChjang added A0-please_review Pull request needs code review. B3-apinoteworthy C1-low PR touches the given topic and has a low impact on builders. D5-nicetohaveaudit ⚠️ PR contains trivial changes to logic that should be properly reviewed. labels May 19, 2021
@shawntabrizi
Copy link
Member

Follow up is to clean any empty call or hooks in existing pallets :)

@shawntabrizi shawntabrizi added D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit and removed D5-nicetohaveaudit ⚠️ PR contains trivial changes to logic that should be properly reviewed. labels May 19, 2021
Copy link
Contributor

@coriolinus coriolinus left a comment

Choose a reason for hiding this comment

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

Very clean! Would be nice to see empty hooks, call in FRAME pallets also removed.

Copy link
Contributor

@gui1117 gui1117 left a comment

Choose a reason for hiding this comment

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

maybe it is better not to generate any Call enum when user doesn't requires it. from construct_runtime point of view I think the call enum should be optional.

But I'm ok to have an empty Call enum generated.

frame/support/src/lib.rs Show resolved Hide resolved
frame/support/procedural/src/pallet/parse/call.rs Outdated Show resolved Hide resolved
frame/support/procedural/src/pallet/parse/hooks.rs Outdated Show resolved Hide resolved
frame/support/src/lib.rs Show resolved Hide resolved
@KiChjang
Copy link
Contributor Author

@thiolliere So the reason why I didn't opt for not generating a Call enum is because the expanded code looked as if other code was dependent on it. I just tried applying the following change and it indeed gave me compiler errors:

diff --git a/frame/support/procedural/src/pallet/expand/call.rs b/frame/support/procedural/src/pallet/expand/call.rs
index 0d28f5583..aa21576bd 100644
--- a/frame/support/procedural/src/pallet/expand/call.rs
+++ b/frame/support/procedural/src/pallet/expand/call.rs
@@ -15,20 +15,16 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-use crate::pallet::{Def, parse::call::CallDef};
+use crate::pallet::Def;
 use frame_support_procedural_tools::clean_type_string;
 use syn::spanned::Spanned;
 
 /// * Generate enum call and implement various trait on it.
 /// * Implement Callable and call_function on `Pallet`
 pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
-       let empty_call;
        let call = match def.call.as_ref() {
                Some(call) => call,
-               None => {
-                       empty_call = CallDef::empty(def.pallet_struct.attr_span);
-                       &empty_call
-               }
+               None => return proc_macro2::TokenStream::new(),
        };
        let frame_support = &def.frame_support;
        let frame_system = &def.frame_system;

Errors:

error[E0277]: the trait bound `pallet2::Pallet<Runtime>: Callable<Runtime>` is not satisfied in `Call`
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ within `Call`, the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime>`                                                       
    | 
   ::: /home/keith/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs:365:20
    |
365 |   pub trait From<T>: Sized {
    |                      ----- required by this bound in `From`
    |
    = note: required because it appears within the type `Call`
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime, Instance1>: Callable<Runtime>` is not satisfied in `Call`
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ within `Call`, the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime, Instance1>`                                            
    | 
   ::: /home/keith/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs:365:20
    |
365 |   pub trait From<T>: Sized {
    |                      ----- required by this bound in `From`
    |
    = note: required because it appears within the type `Call`
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime>: Callable<Runtime>` is not satisfied
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime>`                                                                      
    |
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime>: Callable<Runtime>` is not satisfied
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime>`                                                                      
    |
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime, Instance1>: Callable<Runtime>` is not satisfied
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime, Instance1>`                                                           
    |
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime, Instance1>: Callable<Runtime>` is not satisfied
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime, Instance1>`                                                           
    |
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime>: Callable<Runtime>` is not satisfied
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime>`                                                                      
    |
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime, Instance1>: Callable<Runtime>` is not satisfied
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime, Instance1>`                                                           
    |
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime>: Callable<Runtime>` is not satisfied in `Call`
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ within `Call`, the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime>`                                                       
    | 
   ::: /home/keith/.cargo/registry/src/github.com-1ecc6299db9ec823/parity-scale-codec-2.1.0/src/codec.rs:270:19
    |
270 |   pub trait Decode: Sized {
    |                     ----- required by this bound in `_::_parity_scale_codec::Decode`                                                                      
    |
    = note: required because it appears within the type `Call`
    = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime, Instance1>: Callable<Runtime>` is not satisfied in `Call`
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ within `Call`, the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime, Instance1>`                                            
    | 
   ::: /home/keith/.cargo/registry/src/github.com-1ecc6299db9ec823/parity-scale-codec-2.1.0/src/codec.rs:270:19
    |
270 |   pub trait Decode: Sized {
    |                     ----- required by this bound in `_::_parity_scale_codec::Decode`                                                                      
    |
    = note: required because it appears within the type `Call`
    = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime>: Callable<Runtime>` is not satisfied in `Call`
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ within `Call`, the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime>`                                                       
    | 
   ::: /home/keith/.cargo/registry/src/github.com-1ecc6299db9ec823/parity-scale-codec-2.1.0/src/encode_like.rs:73:41
    |
73  |   pub trait EncodeLike<T: Encode = Self>: Sized + Encode {}
    |                                           ----- required by this bound in `EncodeLike`                                                                    
    |
    = note: required because it appears within the type `Call`
    = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime, Instance1>: Callable<Runtime>` is not satisfied in `Call`
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ within `Call`, the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime, Instance1>`                                            
    | 
   ::: /home/keith/.cargo/registry/src/github.com-1ecc6299db9ec823/parity-scale-codec-2.1.0/src/encode_like.rs:73:41
    |
73  |   pub trait EncodeLike<T: Encode = Self>: Sized + Encode {}
    |                                           ----- required by this bound in `EncodeLike`                                                                    
    |
    = note: required because it appears within the type `Call`
    = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime>: Callable<Runtime>` is not satisfied in `Call`
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ within `Call`, the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime>`                                                       
    | 
   ::: /home/keith/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/clone.rs:108:18
    |
108 |   pub trait Clone: Sized {
    |                    ----- required by this bound in `Clone`
    |
    = note: required because it appears within the type `Call`
    = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime, Instance1>: Callable<Runtime>` is not satisfied in `Call`
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ within `Call`, the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime, Instance1>`                                            
    | 
   ::: /home/keith/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/clone.rs:108:18
    |
108 |   pub trait Clone: Sized {
    |                    ----- required by this bound in `Clone`
    |
    = note: required because it appears within the type `Call`
    = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime>: Callable<Runtime>` is not satisfied in `Call`
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ within `Call`, the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime>`                                                       
    | 
   ::: /home/keith/Workspace/substrate/primitives/runtime/src/generic/unchecked_extrinsic.rs:39:40
    |
39  |   pub struct UncheckedExtrinsic<Address, Call, Signature, Extra>
    |                                          ---- required by this bound in `sp_runtime::generic::UncheckedExtrinsic`                                         
    |
    = note: required because it appears within the type `Call`
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime, Instance1>: Callable<Runtime>` is not satisfied in `Call`
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ within `Call`, the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime, Instance1>`                                            
    | 
   ::: /home/keith/Workspace/substrate/primitives/runtime/src/generic/unchecked_extrinsic.rs:39:40
    |
39  |   pub struct UncheckedExtrinsic<Address, Call, Signature, Extra>
    |                                          ---- required by this bound in `sp_runtime::generic::UncheckedExtrinsic`                                         
    |
    = note: required because it appears within the type `Call`
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `sp_runtime::generic::UncheckedExtrinsic<u32, Call, (), ()>: _::_parity_scale_codec::Decode` is not satisfied
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ the trait `_::_parity_scale_codec::Decode` is not implemented for `sp_runtime::generic::UncheckedExtrinsic<u32, Call, (), ()>`                       
    |
    = help: the following implementations were found:
              <sp_runtime::generic::UncheckedExtrinsic<Address, Call, Signature, Extra> as _::_parity_scale_codec::Decode>
    = note: required because of the requirements on the impl of `Codec` for `sp_runtime::generic::UncheckedExtrinsic<u32, Call, (), ()>`
    = note: required because of the requirements on the impl of `BlockT` for `sp_runtime::generic::Block<sp_runtime::generic::Header<u32, BlakeTwo256>, sp_runtime::generic::UncheckedExtrinsic<u32, Call, (), ()>>`
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `sp_runtime::generic::UncheckedExtrinsic<u32, Call, (), ()>: _::_parity_scale_codec::Encode` is not satisfied
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ the trait `_::_parity_scale_codec::Encode` is not implemented for `sp_runtime::generic::UncheckedExtrinsic<u32, Call, (), ()>`                       
    |
    = help: the following implementations were found:
              <sp_runtime::generic::UncheckedExtrinsic<Address, Call, Signature, Extra> as _::_parity_scale_codec::Encode>
    = note: required because of the requirements on the impl of `Codec` for `sp_runtime::generic::UncheckedExtrinsic<u32, Call, (), ()>`
    = note: required because of the requirements on the impl of `BlockT` for `sp_runtime::generic::Block<sp_runtime::generic::Header<u32, BlakeTwo256>, sp_runtime::generic::UncheckedExtrinsic<u32, Call, (), ()>>`
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime>: Callable<Runtime>` is not satisfied in `Call`
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ within `Call`, the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime>`                                                       
    |
    = note: required because it appears within the type `Call`
    = note: required because of the requirements on the impl of `Extrinsic` for `sp_runtime::generic::UncheckedExtrinsic<u32, Call, (), ()>`
    = note: required because of the requirements on the impl of `BlockT` for `sp_runtime::generic::Block<sp_runtime::generic::Header<u32, BlakeTwo256>, sp_runtime::generic::UncheckedExtrinsic<u32, Call, (), ()>>`
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime, Instance1>: Callable<Runtime>` is not satisfied in `Call`
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ within `Call`, the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime, Instance1>`                                            
    |
    = note: required because it appears within the type `Call`
    = note: required because of the requirements on the impl of `Extrinsic` for `sp_runtime::generic::UncheckedExtrinsic<u32, Call, (), ()>`
    = note: required because of the requirements on the impl of `BlockT` for `sp_runtime::generic::Block<sp_runtime::generic::Header<u32, BlakeTwo256>, sp_runtime::generic::UncheckedExtrinsic<u32, Call, (), ()>>`
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime>: Callable<Runtime>` is not satisfied in `Call`
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ within `Call`, the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime>`                                                       
    | 
   ::: /home/keith/Workspace/substrate/primitives/runtime/src/generic/unchecked_extrinsic.rs:39:40
    |
39  |   pub struct UncheckedExtrinsic<Address, Call, Signature, Extra>
    |                                          ---- required by this bound in `sp_runtime::generic::UncheckedExtrinsic`                                         
    |
    = note: required because it appears within the type `Call`
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime, Instance1>: Callable<Runtime>` is not satisfied in `Call`
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ within `Call`, the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime, Instance1>`                                            
    | 
   ::: /home/keith/Workspace/substrate/primitives/runtime/src/generic/unchecked_extrinsic.rs:39:40
    |
39  |   pub struct UncheckedExtrinsic<Address, Call, Signature, Extra>
    |                                          ---- required by this bound in `sp_runtime::generic::UncheckedExtrinsic`                                         
    |
    = note: required because it appears within the type `Call`
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime>: Callable<Runtime>` is not satisfied in `Call`
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ within `Call`, the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime>`                                                       
    | 
   ::: /home/keith/Workspace/substrate/primitives/runtime/src/generic/unchecked_extrinsic.rs:39:40
    |
39  |   pub struct UncheckedExtrinsic<Address, Call, Signature, Extra>
    |                                          ---- required by this bound in `sp_runtime::generic::UncheckedExtrinsic`                                         
    |
    = note: required because it appears within the type `Call`
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime, Instance1>: Callable<Runtime>` is not satisfied in `Call`
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ within `Call`, the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime, Instance1>`                                            
    | 
   ::: /home/keith/Workspace/substrate/primitives/runtime/src/generic/unchecked_extrinsic.rs:39:40
    |
39  |   pub struct UncheckedExtrinsic<Address, Call, Signature, Extra>
    |                                          ---- required by this bound in `sp_runtime::generic::UncheckedExtrinsic`                                         
    |
    = note: required because it appears within the type `Call`
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime>: Callable<Runtime>` is not satisfied
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime>`                                                                      
    |
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime>: Callable<Runtime>` is not satisfied
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime>`                                                                      
    |
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime>: Callable<Runtime>` is not satisfied
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime>`                                                                      
    |
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime, Instance1>: Callable<Runtime>` is not satisfied
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime, Instance1>`                                                           
    |
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime, Instance1>: Callable<Runtime>` is not satisfied
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime, Instance1>`                                                           
    |
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime, Instance1>: Callable<Runtime>` is not satisfied
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime, Instance1>`                                                           
    |
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime>: Callable<Runtime>` is not satisfied in `Call`
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ within `Call`, the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime>`                                                       
    | 
   ::: /home/keith/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/result.rs:241:17
    |
241 |   pub enum Result<T, E> {
    |                   - required by this bound in `Result`
    |
    = note: required because it appears within the type `Call`
    = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime, Instance1>: Callable<Runtime>` is not satisfied in `Call`
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ within `Call`, the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime, Instance1>`                                            
    | 
   ::: /home/keith/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/result.rs:241:17
    |
241 |   pub enum Result<T, E> {
    |                   - required by this bound in `Result`
    |
    = note: required because it appears within the type `Call`
    = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `sp_runtime::generic::UncheckedExtrinsic<u32, Call, (), ()>: _::_parity_scale_codec::Decode` is not satisfied
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ the trait `_::_parity_scale_codec::Decode` is not implemented for `sp_runtime::generic::UncheckedExtrinsic<u32, Call, (), ()>`                       
    |
    = help: the following implementations were found:
              <sp_runtime::generic::UncheckedExtrinsic<Address, Call, Signature, Extra> as _::_parity_scale_codec::Decode>
    = note: required because of the requirements on the impl of `Codec` for `sp_runtime::generic::UncheckedExtrinsic<u32, Call, (), ()>`
    = note: required because of the requirements on the impl of `BlockT` for `sp_runtime::generic::Block<sp_runtime::generic::Header<u32, BlakeTwo256>, sp_runtime::generic::UncheckedExtrinsic<u32, Call, (), ()>>`
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `sp_runtime::generic::UncheckedExtrinsic<u32, Call, (), ()>: _::_parity_scale_codec::Encode` is not satisfied
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ the trait `_::_parity_scale_codec::Encode` is not implemented for `sp_runtime::generic::UncheckedExtrinsic<u32, Call, (), ()>`                       
    |
    = help: the following implementations were found:
              <sp_runtime::generic::UncheckedExtrinsic<Address, Call, Signature, Extra> as _::_parity_scale_codec::Encode>
    = note: required because of the requirements on the impl of `Codec` for `sp_runtime::generic::UncheckedExtrinsic<u32, Call, (), ()>`
    = note: required because of the requirements on the impl of `BlockT` for `sp_runtime::generic::Block<sp_runtime::generic::Header<u32, BlakeTwo256>, sp_runtime::generic::UncheckedExtrinsic<u32, Call, (), ()>>`
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime>: Callable<Runtime>` is not satisfied in `Call`
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ within `Call`, the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime>`                                                       
    |
    = note: required because it appears within the type `Call`
    = note: required because of the requirements on the impl of `Extrinsic` for `sp_runtime::generic::UncheckedExtrinsic<u32, Call, (), ()>`
    = note: required because of the requirements on the impl of `BlockT` for `sp_runtime::generic::Block<sp_runtime::generic::Header<u32, BlakeTwo256>, sp_runtime::generic::UncheckedExtrinsic<u32, Call, (), ()>>`
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime, Instance1>: Callable<Runtime>` is not satisfied in `Call`
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ within `Call`, the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime, Instance1>`                                            
    |
    = note: required because it appears within the type `Call`
    = note: required because of the requirements on the impl of `Extrinsic` for `sp_runtime::generic::UncheckedExtrinsic<u32, Call, (), ()>`
    = note: required because of the requirements on the impl of `BlockT` for `sp_runtime::generic::Block<sp_runtime::generic::Header<u32, BlakeTwo256>, sp_runtime::generic::UncheckedExtrinsic<u32, Call, (), ()>>`
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime>: Callable<Runtime>` is not satisfied in `Call`
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ within `Call`, the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime>`                                                       
    | 
   ::: /home/keith/Workspace/substrate/primitives/runtime/src/generic/unchecked_extrinsic.rs:39:40
    |
39  |   pub struct UncheckedExtrinsic<Address, Call, Signature, Extra>
    |                                          ---- required by this bound in `sp_runtime::generic::UncheckedExtrinsic`                                         
    |
    = note: required because it appears within the type `Call`
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime, Instance1>: Callable<Runtime>` is not satisfied in `Call`
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ within `Call`, the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime, Instance1>`                                            
    | 
   ::: /home/keith/Workspace/substrate/primitives/runtime/src/generic/unchecked_extrinsic.rs:39:40
    |
39  |   pub struct UncheckedExtrinsic<Address, Call, Signature, Extra>
    |                                          ---- required by this bound in `sp_runtime::generic::UncheckedExtrinsic`                                         
    |
    = note: required because it appears within the type `Call`
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime>: Callable<Runtime>` is not satisfied in `Call`
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ within `Call`, the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime>`                                                       
    | 
   ::: /home/keith/Workspace/substrate/primitives/runtime/src/generic/unchecked_extrinsic.rs:39:40
    |
39  |   pub struct UncheckedExtrinsic<Address, Call, Signature, Extra>
    |                                          ---- required by this bound in `sp_runtime::generic::UncheckedExtrinsic`                                         
    |
    = note: required because it appears within the type `Call`
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `pallet2::Pallet<Runtime, Instance1>: Callable<Runtime>` is not satisfied in `Call`
   --> frame/support/test/tests/pallet_instance.rs:298:1
    |
298 | / frame_support::construct_runtime!(
299 | |     pub enum Runtime where
300 | |         Block = Block,
301 | |         NodeBlock = Block,
...   |
311 | |     }
312 | | );
    | |__^ within `Call`, the trait `Callable<Runtime>` is not implemented for `pallet2::Pallet<Runtime, Instance1>`                                            
    | 
   ::: /home/keith/Workspace/substrate/primitives/runtime/src/generic/unchecked_extrinsic.rs:39:40
    |
39  |   pub struct UncheckedExtrinsic<Address, Call, Signature, Extra>
    |                                          ---- required by this bound in `sp_runtime::generic::UncheckedExtrinsic`                                         
    |
    = note: required because it appears within the type `Call`
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 40 previous errors

@gui1117
Copy link
Contributor

gui1117 commented May 19, 2021

this work to me: cargo test -p frame-support-test --test pallet_instance

diff --git a/frame/support/procedural/src/pallet/expand/call.rs b/frame/support/procedural/src/pallet/expand/call.rs
index 0d28f55839..e5cf2c848b 100644
--- a/frame/support/procedural/src/pallet/expand/call.rs
+++ b/frame/support/procedural/src/pallet/expand/call.rs
@@ -22,12 +22,10 @@ use syn::spanned::Spanned;
 /// * Generate enum call and implement various trait on it.
 /// * Implement Callable and call_function on `Pallet`
 pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream {
-       let empty_call;
        let call = match def.call.as_ref() {
                Some(call) => call,
                None => {
-                       empty_call = CallDef::empty(def.pallet_struct.attr_span);
-                       &empty_call
+                       return Default::default()
                }
        };
        let frame_support = &def.frame_support;
diff --git a/frame/support/test/tests/pallet_instance.rs b/frame/support/test/tests/pallet_instance.rs
index 846a96a237..08fd636bf6 100644
--- a/frame/support/test/tests/pallet_instance.rs
+++ b/frame/support/test/tests/pallet_instance.rs
@@ -306,8 +306,8 @@ frame_support::construct_runtime!(
                Instance1Example: pallet::<Instance1>::{
                        Pallet, Call, Event<T>, Config, Storage, Inherent, Origin<T>, ValidateUnsigned
                },
-               Example2: pallet2::{Pallet, Call, Event<T>, Config<T>, Storage},
-               Instance1Example2: pallet2::<Instance1>::{Pallet, Call, Event<T>, Config<T>, Storage},
+               Example2: pallet2::{Pallet, Event<T>, Config<T>, Storage},
+               Instance1Example2: pallet2::<Instance1>::{Pallet, Event<T>, Config<T>, Storage},
        }
 );

Pallet without call needs not to have the Call part in the their element list in consturct_runtime

@KiChjang
Copy link
Contributor Author

KiChjang commented May 19, 2021

Ah ok, looks like the errors come from importing a non-existent Call part.

EDIT: Actually, now that I think about it, what's the best way of producing an error message for users trying to use the Call enum in the construct_runtime macro? Right now as you can see, it generates about 20 compiler error messages for a small error, which isn't very helpful for debugging purposes. We wouldn't have these errors if the user wrote a blank #[pallet::call] implementation.

@KiChjang
Copy link
Contributor Author

KiChjang commented May 19, 2021

Okay, so let me take a step back and think about the workflow of a FRAME developer. Suppose that my requirements at the moment required me to create a new pallet that doesn't contain any calls. Right now, I still have to write an empty implementation under the #[pallet::call] attribute, and for good measure against future changing requirements, I import the Call part anyway in construct_runtime.

If we were to not generate the Call enum altogether, this would ban the ability for FRAME developers to use the Call part in construct_runtime if the #[pallet::call] attribute is not explicitly specified. Back to my example, when requirements do change and now I have to write some calls to the pallet, then I'll have to always remember to use the Call part in my runtime -- there is no more "importing Call just for the sake of forwards-compatibility reasons", or rather, if I want some form of forwards-compat, then I'll have to write an empty impl for #[pallet::call] in order to use that in my runtime, the default behaviour is just to not generate any Call enum at all.

So I guess the question would be whether this is a good default to have. I can definitely see it being a sensible default to not generate unnecessary code, but I'm just wondering if this would come at the expense of development friction.

(Ideally speaking, this problem would be solved by #8084 where we would have the logic to decide whether or not to generate the Call enum, but let's assume that we don't have this feature implemented yet)

@gui1117
Copy link
Contributor

gui1117 commented May 20, 2021

I agree, there is a tradeoff between:

  • easy construct_runtime configuration: always put the Call part. and always generate a call from the pallet side
  • more correct pallet declaration: declare the call part only when there is the pallet::call attribute. But then people needs not to put the Call part in construct_runtime, and adding call in the pallet requires adding the Call part in construct_runtime.

So I'm ok to generate an empty Call generated here

Copy link
Contributor

@gui1117 gui1117 left a comment

Choose a reason for hiding this comment

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

still minor doc comment #8853 (comment) #8853 (comment)

But it is good to me

@KiChjang
Copy link
Contributor Author

bot merge

@ghost
Copy link

ghost commented May 20, 2021

Trying merge.

@ghost ghost merged commit 6aa388e into master May 20, 2021
@ghost ghost deleted the kckyeung/optional-hooks-and-call branch May 20, 2021 19:31
nazar-pc pushed a commit to autonomys/substrate that referenced this pull request Aug 8, 2021
)

* Make #[pallet::hooks] optional

* Make #[pallet::call] optional

* Remove unused imports

* Update UI test expectations

* Update UI test expectations

* Remove unnecessary HooksDef::empty method

* Remove unnecessary CallDef::empty method

* Clarify what would happen when no call or hooks are specified in a pallet
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pallet enhancement: hook and call as optional item
4 participants