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

Stored call in multisig #6319

Merged
merged 31 commits into from
Jun 17, 2020
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c7584c0
Stored call in multisig
gavofyork Jun 10, 2020
0ddd158
Docs.
gavofyork Jun 10, 2020
c30f54f
Benchmarks.
gavofyork Jun 10, 2020
dbac9eb
Fix
gavofyork Jun 10, 2020
3669489
Update frame/multisig/src/lib.rs
gavofyork Jun 10, 2020
9f59d31
patch benchmarks
shawntabrizi Jun 11, 2020
69682e5
Minor grumbles.
gavofyork Jun 11, 2020
e48f3e4
Merge branch 'gav-multisig-stored-call' of github.com:paritytech/subs…
gavofyork Jun 11, 2020
a363d4b
Update as_multi weight
shawntabrizi Jun 11, 2020
1c69bb0
Merge branch 'gav-multisig-stored-call' of https://github.com/parityt…
shawntabrizi Jun 11, 2020
a8343cb
Fixes and refactoring.
gavofyork Jun 11, 2020
fdcab27
Merge branch 'gav-multisig-stored-call' of github.com:paritytech/subs…
gavofyork Jun 11, 2020
bd5f05e
Split out threshold=1 and opaquify Call.
gavofyork Jun 11, 2020
8b9aaae
Compiles, tests pass, weights are broken
shawntabrizi Jun 14, 2020
09da872
Update benchmarks, add working tests
shawntabrizi Jun 14, 2020
2b5c361
Add benchmark to threshold 1, add event too
shawntabrizi Jun 14, 2020
2cf2832
suppress warning for now
shawntabrizi Jun 14, 2020
9a2d25f
@xlc improvment nit
shawntabrizi Jun 14, 2020
db75543
Update weight and tests
shawntabrizi Jun 15, 2020
6275b9c
Test for weight check
shawntabrizi Jun 15, 2020
5c9a7af
Merge branch 'master' into gav-multisig-stored-call
shawntabrizi Jun 15, 2020
81195da
Fix line width
shawntabrizi Jun 15, 2020
7a75cf7
one more line width error
shawntabrizi Jun 15, 2020
9dd0585
Apply suggestions from code review
shawntabrizi Jun 15, 2020
7af9a83
Merge branch 'master' into gav-multisig-stored-call
shawntabrizi Jun 15, 2020
f64e26d
fix merge
shawntabrizi Jun 15, 2020
9becf6e
more @apopiak feedback
shawntabrizi Jun 15, 2020
5bd6514
Multisig handles no preimage
shawntabrizi Jun 16, 2020
5cc17da
Optimize return weight after dispatch
shawntabrizi Jun 16, 2020
a053de8
Merge remote-tracking branch 'origin/master' into gav-multisig-stored…
gavofyork Jun 16, 2020
9e2d5b6
Error on failed deposit.
gavofyork Jun 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 26 additions & 20 deletions frame/multisig/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use frame_support::{traits::{Get, ReservableCurrency, Currency},
dispatch::{DispatchResultWithPostInfo, DispatchErrorWithPostInfo, PostDispatchInfo},
};
use frame_system::{self as system, ensure_signed, RawOrigin};
use sp_runtime::{DispatchError, DispatchResult, traits::Dispatchable};
use sp_runtime::{DispatchError, DispatchResult, traits::{Dispatchable, Zero}};

mod tests;
mod benchmarking;
Expand Down Expand Up @@ -154,6 +154,8 @@ decl_error! {
UnexpectedTimepoint,
/// The maximum weight information provided was too low.
WeightTooLow,
/// The data to be stored is already stored.
AlreadyStored,
}
}

Expand Down Expand Up @@ -552,7 +554,7 @@ impl<T: Trait> Module<T> {
ensure!(call.get_dispatch_info().weight <= max_weight, Error::<T>::WeightTooLow);

let result = call.dispatch(RawOrigin::Signed(id.clone()).into());
let _ = T::Currency::unreserve(&m.depositor, m.deposit);
T::Currency::unreserve(&m.depositor, m.deposit);
<Multisigs<T>>::remove(&id, call_hash);
Self::clear_call(&call_hash);
Self::deposit_event(RawEvent::MultisigExecuted(
Expand All @@ -570,9 +572,12 @@ impl<T: Trait> Module<T> {
// don't have threshold approvals even with our signature.

// Store the call if desired.
let stored = maybe_call
.filter(|_| store)
.map_or(false, |data| Self::store_call(who.clone(), &call_hash, data));
let stored = if let Some(data) = maybe_call.filter(|_| store) {
Self::store_call_and_reserve(who.clone(), &call_hash, data, BalanceOf::<T>::zero())?;
true
} else {
false
};

if let Some(pos) = maybe_pos {
// Record approval.
Expand Down Expand Up @@ -600,12 +605,15 @@ impl<T: Trait> Module<T> {

// Just start the operation by recording it in storage.
let deposit = T::DepositBase::get() + T::DepositFactor::get() * threshold.into();
T::Currency::reserve(&who, deposit)?;

// Store the call if desired.
let stored = maybe_call
.filter(|_| store)
.map_or(false, |data| Self::store_call(who.clone(), &call_hash, data));
let stored = if let Some(data) = maybe_call.filter(|_| store) {
Self::store_call_and_reserve(who.clone(), &call_hash, data, deposit)?;
true
} else {
T::Currency::reserve(&who, deposit)?;
shawntabrizi marked this conversation as resolved.
Show resolved Hide resolved
false
};

<Multisigs<T>>::insert(&id, call_hash, Multisig {
when: Self::timepoint(),
Expand All @@ -630,17 +638,15 @@ impl<T: Trait> Module<T> {
/// We store `data` here because storing `call` would result in needing another `.encode`.
///
/// Returns a `bool` indicating whether the data did end up being stored.
fn store_call(who: T::AccountId, hash: &[u8; 32], data: Vec<u8>) -> bool {
if !Calls::<T>::contains_key(hash) {
let deposit = T::DepositBase::get()
+ T::DepositFactor::get() * BalanceOf::<T>::from(((data.len() + 31) / 32) as u32);
if T::Currency::reserve(&who, deposit).is_ok() {
// Only store the data if the deposit was paid.
Calls::<T>::insert(&hash, (data, who, deposit));
return true
}
}
false
fn store_call_and_reserve(who: T::AccountId, hash: &[u8; 32], data: Vec<u8>, other_deposit: BalanceOf<T>)
-> DispatchResult
{
ensure!(!Calls::<T>::contains_key(hash), Error::<T>::AlreadyStored);
let deposit = other_deposit + T::DepositBase::get()
+ T::DepositFactor::get() * BalanceOf::<T>::from(((data.len() + 31) / 32) as u32);
T::Currency::reserve(&who, deposit)?;
Calls::<T>::insert(&hash, (data, who, deposit));
Ok(())
}

/// Attempt to decode and return the call, provided by the user or from storage.
Expand Down