diff --git a/bin/node/runtime/src/impls.rs b/bin/node/runtime/src/impls.rs index 8c4a1ed4bbda2..ac97e4e674541 100644 --- a/bin/node/runtime/src/impls.rs +++ b/bin/node/runtime/src/impls.rs @@ -21,7 +21,7 @@ use frame_support::{ pallet_prelude::*, traits::{ fungibles::{Balanced, Credit}, - Currency, OnUnbalanced, + Bounded, Currency, OnUnbalanced, StorePreimage, }, }; use pallet_alliance::{IdentityVerifier, ProposalIndex, ProposalProvider}; @@ -29,7 +29,7 @@ use pallet_asset_tx_payment::HandleCredit; use sp_std::prelude::*; use crate::{ - AccountId, AllianceMotion, Assets, Authorship, Balances, Hash, NegativeImbalance, Runtime, + AccountId, AllianceMotion, Assets, Authorship, Balances, NegativeImbalance, Preimage, Runtime, RuntimeCall, }; @@ -77,7 +77,7 @@ impl IdentityVerifier for AllianceIdentityVerifier { } pub struct AllianceProposalProvider; -impl ProposalProvider for AllianceProposalProvider { +impl ProposalProvider for AllianceProposalProvider { fn propose_proposal( who: AccountId, threshold: u32, @@ -89,24 +89,33 @@ impl ProposalProvider for AllianceProposalProvider fn vote_proposal( who: AccountId, - proposal: Hash, + proposal_bounded: Bounded, index: ProposalIndex, approve: bool, ) -> Result { - AllianceMotion::do_vote(who, proposal, index, approve) + AllianceMotion::do_vote(who, proposal_bounded, index, approve) } fn close_proposal( - proposal_hash: Hash, + proposal_bounded: Bounded, proposal_index: ProposalIndex, proposal_weight_bound: Weight, length_bound: u32, ) -> DispatchResultWithPostInfo { - AllianceMotion::do_close(proposal_hash, proposal_index, proposal_weight_bound, length_bound) + AllianceMotion::do_close( + proposal_bounded, + proposal_index, + proposal_weight_bound, + length_bound, + ) } - fn proposal_of(proposal_hash: Hash) -> Option { - AllianceMotion::proposal_of(proposal_hash) + fn proposal_of(proposal_bounded: Bounded) -> Option { + AllianceMotion::proposal_of(proposal_bounded) + } + + fn bound_proposal(proposal: RuntimeCall) -> Result, DispatchError> { + Preimage::bound(proposal) } } diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index aad86b28de32f..6d0088b15d060 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -1011,6 +1011,7 @@ impl pallet_collective::Config for Runtime { type WeightInfo = pallet_collective::weights::SubstrateWeight; type SetMembersOrigin = EnsureRoot; type MaxProposalWeight = MaxCollectivesProposalWeight; + type Preimages = Preimage; } parameter_types! { @@ -1072,6 +1073,7 @@ impl pallet_collective::Config for Runtime { type WeightInfo = pallet_collective::weights::SubstrateWeight; type SetMembersOrigin = EnsureRoot; type MaxProposalWeight = MaxCollectivesProposalWeight; + type Preimages = Preimage; } type EnsureRootOrHalfCouncil = EitherOfDiverse< @@ -1792,6 +1794,7 @@ impl pallet_collective::Config for Runtime { type WeightInfo = pallet_collective::weights::SubstrateWeight; type SetMembersOrigin = EnsureRoot; type MaxProposalWeight = MaxCollectivesProposalWeight; + type Preimages = Preimage; } parameter_types! { diff --git a/frame/alliance/src/benchmarking.rs b/frame/alliance/src/benchmarking.rs index 4906377829bc2..d804e0e550b12 100644 --- a/frame/alliance/src/benchmarking.rs +++ b/frame/alliance/src/benchmarking.rs @@ -26,10 +26,7 @@ use sp_std::{ }; use frame_benchmarking::v1::{account, benchmarks_instance_pallet, BenchmarkError}; -use frame_support::{ - bounded_vec, - traits::{EnsureOrigin, Get, UnfilteredDispatchable}, -}; +use frame_support::traits::{EnsureOrigin, Get, UnfilteredDispatchable}; use frame_system::{Pallet as System, RawOrigin as SystemOrigin}; use super::{Call as AllianceCall, Pallet as Alliance, *}; @@ -164,7 +161,7 @@ benchmarks_instance_pallet! { let threshold = m - 1; // Add previous proposals - let mut last_bound = frame_support::traits::Bounded::Inline(bounded_vec![]); + let mut last_bound = frame_support::traits::Bounded::Inline(vec![].try_into().unwrap()); for i in 0 .. p { // Proposals should be different let proposal: T::Proposal = AllianceCall::::set_rule { @@ -236,7 +233,7 @@ benchmarks_instance_pallet! { let threshold = m; // Add previous proposals - let mut last_bound = frame_support::traits::Bounded::Inline(bounded_vec![]); + let mut last_bound = frame_support::traits::Bounded::Inline(vec![].try_into().unwrap()); for i in 0 .. p { // Proposals should be different let proposal: T::Proposal = AllianceCall::::set_rule { @@ -314,7 +311,7 @@ benchmarks_instance_pallet! { let threshold = 2; // Add previous proposals - let mut last_bound = frame_support::traits::Bounded::Inline(bounded_vec![]); + let mut last_bound = frame_support::traits::Bounded::Inline(vec![].try_into().unwrap()); for i in 0 .. p { // Proposals should be different let proposal: T::Proposal = AllianceCall::::set_rule { @@ -397,7 +394,7 @@ benchmarks_instance_pallet! { let threshold = m - 1; // Add proposals - let mut last_bound = frame_support::traits::Bounded::Inline(bounded_vec![]); + let mut last_bound = frame_support::traits::Bounded::Inline(vec![].try_into().unwrap()); for i in 0 .. p { // Proposals should be different let proposal: T::Proposal = AllianceCall::::set_rule { @@ -466,7 +463,7 @@ benchmarks_instance_pallet! { let threshold = 2; // Add proposals - let mut last_bound = frame_support::traits::Bounded::Inline(bounded_vec![]); + let mut last_bound = frame_support::traits::Bounded::Inline(vec![].try_into().unwrap()); for i in 0 .. p { // Proposals should be different let proposal: T::Proposal = AllianceCall::::set_rule { diff --git a/frame/collective/src/benchmarking.rs b/frame/collective/src/benchmarking.rs index b45d0899cc167..a6fcda6d15e40 100644 --- a/frame/collective/src/benchmarking.rs +++ b/frame/collective/src/benchmarking.rs @@ -21,7 +21,6 @@ use super::*; use crate::Pallet as Collective; use frame_benchmarking::v1::{account, benchmarks_instance_pallet, whitelisted_caller}; -use frame_support::bounded_vec; use frame_system::{Call as SystemCall, Pallet as System, RawOrigin as SystemOrigin}; use sp_runtime::traits::Bounded; use sp_std::mem::size_of; @@ -235,7 +234,7 @@ benchmarks_instance_pallet! { let threshold = m - 1; // Add previous proposals - let mut last_bound = frame_support::traits::Bounded::Inline(bounded_vec![]); + let mut last_bound = frame_support::traits::Bounded::Inline(vec![].try_into().unwrap()); for i in 0 .. p { // Proposals should be different let proposal: T::Proposal = SystemCall::::remark { remark: id_to_remark_data(i, b as usize) }.into(); @@ -310,7 +309,7 @@ benchmarks_instance_pallet! { let threshold = m; // Add previous proposals - let mut last_bound = frame_support::traits::Bounded::Inline(bounded_vec![]); + let mut last_bound = frame_support::traits::Bounded::Inline(vec![].try_into().unwrap()); for i in 0 .. p { // Proposals should be different let proposal: T::Proposal = SystemCall::::remark { remark: id_to_remark_data(i, bytes as usize) }.into(); @@ -387,7 +386,7 @@ benchmarks_instance_pallet! { let threshold = 2; // Add previous proposals - let mut last_bound = frame_support::traits::Bounded::Inline(bounded_vec![]); + let mut last_bound = frame_support::traits::Bounded::Inline(vec![].try_into().unwrap()); for i in 0 .. p { // Proposals should be different let proposal: T::Proposal = SystemCall::::remark { remark: id_to_remark_data(i, b as usize) }.into(); @@ -473,7 +472,7 @@ benchmarks_instance_pallet! { let threshold = m - 1; // Add proposals - let mut last_bound = frame_support::traits::Bounded::Inline(bounded_vec![]); + let mut last_bound = frame_support::traits::Bounded::Inline(vec![].try_into().unwrap()); for i in 0 .. p { // Proposals should be different let proposal: T::Proposal = SystemCall::::remark { remark: id_to_remark_data(i, bytes as usize) }.into(); @@ -555,7 +554,7 @@ benchmarks_instance_pallet! { let threshold = 2; // Add proposals - let mut last_bound = frame_support::traits::Bounded::Inline(bounded_vec![]); + let mut last_bound = frame_support::traits::Bounded::Inline(vec![].try_into().unwrap()); for i in 0 .. p { // Proposals should be different let proposal: T::Proposal = SystemCall::::remark { remark: id_to_remark_data(i, b as usize) }.into(); @@ -626,7 +625,7 @@ benchmarks_instance_pallet! { let threshold = m - 1; // Add proposals - let mut last_bound = frame_support::traits::Bounded::Inline(bounded_vec![]); + let mut last_bound = frame_support::traits::Bounded::Inline(vec![].try_into().unwrap()); for i in 0 .. p { // Proposals should be different let proposal: T::Proposal = SystemCall::::remark { remark: id_to_remark_data(i, b as usize) }.into(); diff --git a/frame/collective/src/lib.rs b/frame/collective/src/lib.rs index 5cdc9f5ea8e2f..c5c7acea144c3 100644 --- a/frame/collective/src/lib.rs +++ b/frame/collective/src/lib.rs @@ -741,8 +741,8 @@ impl, I: 'static> Pallet { Votes { index, threshold, - ayes: frame_support::bounded_vec![], - nays: frame_support::bounded_vec![], + ayes: vec![].try_into().expect("empty vec is always bounded; qed"), + nays: vec![].try_into().expect("empty vec is always bounded; qed"), end, } }; diff --git a/frame/collective/src/migrations/v5.rs b/frame/collective/src/migrations/v5.rs index 9d45a1be9c064..86441ad348a4b 100644 --- a/frame/collective/src/migrations/v5.rs +++ b/frame/collective/src/migrations/v5.rs @@ -88,20 +88,14 @@ pub fn migrate, I: 'static>() -> Weight { let vote = crate::Votes::>::MaxMembers> { index: vote.index, threshold: vote.threshold, - ayes: vote.ayes.try_into().expect( - format!( - "runtime::collective migration failed, ayes for vote {:?} should not overflow; qed", - vote.index - ) - .as_str(), - ), - nays: vote.nays.try_into().expect( - format!( - "runtime::collective migration failed, nays for vote {:?} should not overflow; qed", - vote.index, - ) - .as_str(), - ), + ayes: vote + .ayes + .try_into() + .expect("runtime::collective migration failed, ayes overflow"), + nays: vote + .nays + .try_into() + .expect("runtime::collective migration failed, nays overflow"), end: vote.end, };