Collective pallet: max proposal weight (#13771)

* collective: max proposal weight

* fix test

---------

Co-authored-by: parity-processbot <>
This commit is contained in:
Muharem Ismailov
2023-04-19 13:00:27 +02:00
committed by GitHub
parent e458bf3795
commit f8b77f64f3
5 changed files with 66 additions and 2 deletions
+14
View File
@@ -217,6 +217,10 @@ pub mod pallet {
/// Origin allowed to set collective members
type SetMembersOrigin: EnsureOrigin<<Self as frame_system::Config>::RuntimeOrigin>;
/// The maximum weight of a dispatch call that can be proposed and executed.
#[pallet::constant]
type MaxProposalWeight: Get<Weight>;
}
#[pallet::genesis_config]
@@ -667,6 +671,11 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
) -> Result<(u32, DispatchResultWithPostInfo), DispatchError> {
let proposal_len = proposal.encoded_size();
ensure!(proposal_len <= length_bound as usize, Error::<T, I>::WrongProposalLength);
let proposal_weight = proposal.get_dispatch_info().weight;
ensure!(
proposal_weight.all_lte(T::MaxProposalWeight::get()),
Error::<T, I>::WrongProposalWeight
);
let proposal_hash = T::Hashing::hash_of(&proposal);
ensure!(!<ProposalOf<T, I>>::contains_key(proposal_hash), Error::<T, I>::DuplicateProposal);
@@ -689,6 +698,11 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
) -> Result<(u32, u32), DispatchError> {
let proposal_len = proposal.encoded_size();
ensure!(proposal_len <= length_bound as usize, Error::<T, I>::WrongProposalLength);
let proposal_weight = proposal.get_dispatch_info().weight;
ensure!(
proposal_weight.all_lte(T::MaxProposalWeight::get()),
Error::<T, I>::WrongProposalWeight
);
let proposal_hash = T::Hashing::hash_of(&proposal);
ensure!(!<ProposalOf<T, I>>::contains_key(proposal_hash), Error::<T, I>::DuplicateProposal);