mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 21:41:12 +00:00
Make Multisig Pallet Bounded (#12457)
* Bounded multisig * just use u32 Co-authored-by: parity-processbot <>
This commit is contained in:
@@ -249,7 +249,7 @@ impl pallet_multisig::Config for Runtime {
|
||||
type Currency = Balances;
|
||||
type DepositBase = DepositBase;
|
||||
type DepositFactor = DepositFactor;
|
||||
type MaxSignatories = ConstU16<100>;
|
||||
type MaxSignatories = ConstU32<100>;
|
||||
type WeightInfo = pallet_multisig::weights::SubstrateWeight<Runtime>;
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ benchmarks! {
|
||||
|
||||
as_multi_create {
|
||||
// Signatories, need at least 2 total people
|
||||
let s in 2 .. T::MaxSignatories::get() as u32;
|
||||
let s in 2 .. T::MaxSignatories::get();
|
||||
// Transaction Length
|
||||
let z in 0 .. 10_000;
|
||||
let (mut signatories, call) = setup_multi::<T>(s, z)?;
|
||||
@@ -86,7 +86,7 @@ benchmarks! {
|
||||
|
||||
as_multi_approve {
|
||||
// Signatories, need at least 3 people (so we don't complete the multisig)
|
||||
let s in 3 .. T::MaxSignatories::get() as u32;
|
||||
let s in 3 .. T::MaxSignatories::get();
|
||||
// Transaction Length
|
||||
let z in 0 .. 10_000;
|
||||
let (mut signatories, call) = setup_multi::<T>(s, z)?;
|
||||
@@ -110,7 +110,7 @@ benchmarks! {
|
||||
|
||||
as_multi_complete {
|
||||
// Signatories, need at least 2 people
|
||||
let s in 2 .. T::MaxSignatories::get() as u32;
|
||||
let s in 2 .. T::MaxSignatories::get();
|
||||
// Transaction Length
|
||||
let z in 0 .. 10_000;
|
||||
let (mut signatories, call) = setup_multi::<T>(s, z)?;
|
||||
@@ -141,7 +141,7 @@ benchmarks! {
|
||||
|
||||
approve_as_multi_create {
|
||||
// Signatories, need at least 2 people
|
||||
let s in 2 .. T::MaxSignatories::get() as u32;
|
||||
let s in 2 .. T::MaxSignatories::get();
|
||||
// Transaction Length, not a component
|
||||
let z = 10_000;
|
||||
let (mut signatories, call) = setup_multi::<T>(s, z)?;
|
||||
@@ -159,7 +159,7 @@ benchmarks! {
|
||||
|
||||
approve_as_multi_approve {
|
||||
// Signatories, need at least 2 people
|
||||
let s in 2 .. T::MaxSignatories::get() as u32;
|
||||
let s in 2 .. T::MaxSignatories::get();
|
||||
// Transaction Length, not a component
|
||||
let z = 10_000;
|
||||
let (mut signatories, call) = setup_multi::<T>(s, z)?;
|
||||
@@ -190,7 +190,7 @@ benchmarks! {
|
||||
|
||||
cancel_as_multi {
|
||||
// Signatories, need at least 2 people
|
||||
let s in 2 .. T::MaxSignatories::get() as u32;
|
||||
let s in 2 .. T::MaxSignatories::get();
|
||||
// Transaction Length, not a component
|
||||
let z = 10_000;
|
||||
let (mut signatories, call) = setup_multi::<T>(s, z)?;
|
||||
|
||||
@@ -51,7 +51,7 @@ pub mod migrations;
|
||||
mod tests;
|
||||
pub mod weights;
|
||||
|
||||
use codec::{Decode, Encode};
|
||||
use codec::{Decode, Encode, MaxEncodedLen};
|
||||
use frame_support::{
|
||||
dispatch::{
|
||||
DispatchErrorWithPostInfo, DispatchResult, DispatchResultWithPostInfo, GetDispatchInfo,
|
||||
@@ -60,7 +60,7 @@ use frame_support::{
|
||||
ensure,
|
||||
traits::{Currency, Get, ReservableCurrency},
|
||||
weights::Weight,
|
||||
RuntimeDebug,
|
||||
BoundedVec, RuntimeDebug,
|
||||
};
|
||||
use frame_system::{self as system, RawOrigin};
|
||||
use scale_info::TypeInfo;
|
||||
@@ -94,7 +94,9 @@ type BalanceOf<T> =
|
||||
/// A global extrinsic index, formed as the extrinsic index within a block, together with that
|
||||
/// block's height. This allows a transaction in which a multisig operation of a particular
|
||||
/// composite was created to be uniquely identified.
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Encode, Decode, Default, RuntimeDebug, TypeInfo)]
|
||||
#[derive(
|
||||
Copy, Clone, Eq, PartialEq, Encode, Decode, Default, RuntimeDebug, TypeInfo, MaxEncodedLen,
|
||||
)]
|
||||
pub struct Timepoint<BlockNumber> {
|
||||
/// The height of the chain at the point in time.
|
||||
height: BlockNumber,
|
||||
@@ -103,8 +105,12 @@ pub struct Timepoint<BlockNumber> {
|
||||
}
|
||||
|
||||
/// An open multisig operation.
|
||||
#[derive(Clone, Eq, PartialEq, Encode, Decode, Default, RuntimeDebug, TypeInfo)]
|
||||
pub struct Multisig<BlockNumber, Balance, AccountId> {
|
||||
#[derive(Clone, Eq, PartialEq, Encode, Decode, Default, RuntimeDebug, TypeInfo, MaxEncodedLen)]
|
||||
#[scale_info(skip_type_params(MaxApprovals))]
|
||||
pub struct Multisig<BlockNumber, Balance, AccountId, MaxApprovals>
|
||||
where
|
||||
MaxApprovals: Get<u32>,
|
||||
{
|
||||
/// The extrinsic when the multisig operation was opened.
|
||||
when: Timepoint<BlockNumber>,
|
||||
/// The amount held in reserve of the `depositor`, to be returned once the operation ends.
|
||||
@@ -112,7 +118,7 @@ pub struct Multisig<BlockNumber, Balance, AccountId> {
|
||||
/// The account who opened it (i.e. the first to approve it).
|
||||
depositor: AccountId,
|
||||
/// The approvals achieved so far, including the depositor. Always sorted.
|
||||
approvals: Vec<AccountId>,
|
||||
approvals: BoundedVec<AccountId, MaxApprovals>,
|
||||
}
|
||||
|
||||
type CallHash = [u8; 32];
|
||||
@@ -159,7 +165,7 @@ pub mod pallet {
|
||||
|
||||
/// The maximum amount of signatories allowed in the multisig.
|
||||
#[pallet::constant]
|
||||
type MaxSignatories: Get<u16>;
|
||||
type MaxSignatories: Get<u32>;
|
||||
|
||||
/// Weight information for extrinsics in this pallet.
|
||||
type WeightInfo: WeightInfo;
|
||||
@@ -170,7 +176,6 @@ pub mod pallet {
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(super) trait Store)]
|
||||
#[pallet::without_storage_info]
|
||||
#[pallet::storage_version(STORAGE_VERSION)]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
@@ -182,7 +187,7 @@ pub mod pallet {
|
||||
T::AccountId,
|
||||
Blake2_128Concat,
|
||||
[u8; 32],
|
||||
Multisig<T::BlockNumber, BalanceOf<T>, T::AccountId>,
|
||||
Multisig<T::BlockNumber, BalanceOf<T>, T::AccountId, T::MaxSignatories>,
|
||||
>;
|
||||
|
||||
#[pallet::error]
|
||||
@@ -601,7 +606,9 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
if let Some(pos) = maybe_pos {
|
||||
// Record approval.
|
||||
m.approvals.insert(pos, who.clone());
|
||||
m.approvals
|
||||
.try_insert(pos, who.clone())
|
||||
.map_err(|_| Error::<T>::TooManySignatories)?;
|
||||
<Multisigs<T>>::insert(&id, call_hash, m);
|
||||
Self::deposit_event(Event::MultisigApproval {
|
||||
approving: who,
|
||||
@@ -629,6 +636,9 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
T::Currency::reserve(&who, deposit)?;
|
||||
|
||||
let initial_approvals =
|
||||
vec![who.clone()].try_into().map_err(|_| Error::<T>::TooManySignatories)?;
|
||||
|
||||
<Multisigs<T>>::insert(
|
||||
&id,
|
||||
call_hash,
|
||||
@@ -636,7 +646,7 @@ impl<T: Config> Pallet<T> {
|
||||
when: Self::timepoint(),
|
||||
deposit,
|
||||
depositor: who.clone(),
|
||||
approvals: vec![who.clone()],
|
||||
approvals: initial_approvals,
|
||||
},
|
||||
);
|
||||
Self::deposit_event(Event::NewMultisig { approving: who, multisig: id, call_hash });
|
||||
|
||||
@@ -24,7 +24,7 @@ use super::*;
|
||||
use crate as pallet_multisig;
|
||||
use frame_support::{
|
||||
assert_noop, assert_ok, parameter_types,
|
||||
traits::{ConstU16, ConstU32, ConstU64, Contains},
|
||||
traits::{ConstU32, ConstU64, Contains},
|
||||
};
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{
|
||||
@@ -107,7 +107,7 @@ impl Config for Test {
|
||||
type Currency = Balances;
|
||||
type DepositBase = ConstU64<1>;
|
||||
type DepositFactor = ConstU64<1>;
|
||||
type MaxSignatories = ConstU16<3>;
|
||||
type MaxSignatories = ConstU32<3>;
|
||||
type WeightInfo = ();
|
||||
}
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ impl pallet_balances::Config for Test {
|
||||
parameter_types! {
|
||||
pub const MultisigDepositBase: u64 = 1;
|
||||
pub const MultisigDepositFactor: u64 = 1;
|
||||
pub const MaxSignatories: u16 = 3;
|
||||
pub const MaxSignatories: u32 = 3;
|
||||
}
|
||||
|
||||
impl example::Config for Test {}
|
||||
|
||||
Reference in New Issue
Block a user