Skip to content

Commit

Permalink
Make max_weight optional in multisig.approve. (#1716)
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Dossa <[email protected]>
  • Loading branch information
Neopallium and adamdossa authored Sep 17, 2024
1 parent db18fa5 commit 6a479a8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
2 changes: 1 addition & 1 deletion integration/tests/multisig_permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ impl MuliSigState {
self.api
.call()
.multi_sig()
.approve(self.account.clone(), id, weight)?;
.approve(self.account.clone(), id, Some(weight))?;
let mut results = Vec::new();
for signer in &mut self.signers[1..self.sigs_required as usize] {
let res = approve_call.submit_and_watch(signer).await?;
Expand Down
13 changes: 13 additions & 0 deletions pallets/common/src/traits/multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ pub trait WeightInfo {
fn create_join_identity() -> Weight;
fn approve_join_identity() -> Weight;
fn join_identity() -> Weight;

fn default_max_weight(max_weight: &Option<Weight>) -> Weight {
max_weight.unwrap_or_else(|| {
// TODO: Use a better default weight.
Self::create_proposal()
})
}

fn approve_and_execute(max_weight: &Option<Weight>) -> Weight {
Self::approve()
.saturating_add(Self::execute_proposal())
.saturating_add(Self::default_max_weight(max_weight))
}
}

/// This trait is used to add a signer to a multisig and enable unlinking multisig from an identity
Expand Down
2 changes: 1 addition & 1 deletion pallets/multisig/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ benchmarks! {

approve {
let (alice, multisig, signers, users, proposal_id, proposal, ephemeral_multisig) = generate_multisig_and_create_proposal::<T>(3, 3).unwrap();
}: _(users[2].origin(), ephemeral_multisig, proposal_id, Weight::MAX)
}: _(users[2].origin(), ephemeral_multisig, proposal_id, None)
verify {
assert_vote_cast!(proposal_id, multisig, signers.last().unwrap());
}
Expand Down
9 changes: 3 additions & 6 deletions pallets/multisig/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,14 @@ pub mod pallet {
///
/// If quorum is reached, the proposal will be immediately executed.
#[pallet::call_index(2)]
#[pallet::weight({
<T as Config>::WeightInfo::approve()
.saturating_add(<T as Config>::WeightInfo::execute_proposal())
.saturating_add(*max_weight)
})]
#[pallet::weight(<T as Config>::WeightInfo::approve_and_execute(max_weight))]
pub fn approve(
origin: OriginFor<T>,
multisig: T::AccountId,
proposal_id: u64,
max_weight: Weight,
max_weight: Option<Weight>,
) -> DispatchResultWithPostInfo {
let max_weight = <T as Config>::WeightInfo::default_max_weight(&max_weight);
let signer = ensure_signed(origin)?;
with_base_weight(<T as Config>::WeightInfo::approve(), || {
Self::base_approve(&multisig, signer, proposal_id, max_weight)
Expand Down
21 changes: 8 additions & 13 deletions pallets/runtime/tests/src/multisig.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use frame_support::{
assert_err, assert_err_ignore_postinfo, assert_noop, assert_ok, assert_storage_noop,
dispatch::DispatchResult, dispatch::Weight, BoundedVec,
dispatch::DispatchResult, BoundedVec,
};

use pallet_multisig::{self as multisig, AdminDid, ProposalStates, ProposalVoteCounts, Votes};
Expand Down Expand Up @@ -246,7 +246,7 @@ fn change_multisig_sigs_required() {
charlie.clone(),
ms_address.clone(),
0,
Weight::MAX
None
));
next_block();
assert_eq!(MultiSig::ms_signs_required(ms_address), 1);
Expand Down Expand Up @@ -768,7 +768,7 @@ fn check_for_approval_closure() {
let multi_purpose_nonce = Identity::multi_purpose_nonce();

assert_storage_noop!(assert_err_ignore_postinfo!(
MultiSig::approve(dave.clone(), ms_address.clone(), proposal_id, Weight::MAX),
MultiSig::approve(dave.clone(), ms_address.clone(), proposal_id, None),
Error::ProposalAlreadyExecuted
));

Expand Down Expand Up @@ -854,7 +854,7 @@ fn reject_proposals() {
proposal_id1
));
assert_storage_noop!(assert_err_ignore_postinfo!(
MultiSig::approve(dave.clone(), ms_address.clone(), proposal_id1, Weight::MAX),
MultiSig::approve(dave.clone(), ms_address.clone(), proposal_id1, None),
Error::ProposalAlreadyRejected
));
let vote_count1 =
Expand Down Expand Up @@ -882,7 +882,7 @@ fn reject_proposals() {
proposal_id2
));
assert_storage_noop!(assert_err_ignore_postinfo!(
MultiSig::approve(dave.clone(), ms_address.clone(), proposal_id2, Weight::MAX),
MultiSig::approve(dave.clone(), ms_address.clone(), proposal_id2, None),
Error::ProposalAlreadyRejected
));

Expand Down Expand Up @@ -1299,7 +1299,7 @@ fn expired_proposals() {
bob.clone(),
ms_address.clone(),
proposal_id,
Weight::MAX
None
));

vote_count = ProposalVoteCounts::<TestStorage>::get(&ms_address, proposal_id).unwrap();
Expand All @@ -1315,12 +1315,7 @@ fn expired_proposals() {
// Approval fails when proposal has expired
set_timestamp(expires_at);
assert_noop!(
MultiSig::approve(
charlie.clone(),
ms_address.clone(),
proposal_id,
Weight::MAX
),
MultiSig::approve(charlie.clone(), ms_address.clone(), proposal_id, None),
Error::ProposalExpired
);

Expand All @@ -1340,7 +1335,7 @@ fn expired_proposals() {
charlie,
ms_address.clone(),
proposal_id,
Weight::MAX
None
));

vote_count = ProposalVoteCounts::<TestStorage>::get(&ms_address, proposal_id).unwrap();
Expand Down

0 comments on commit 6a479a8

Please sign in to comment.