This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Stored call in multisig #6319
Merged
Merged
Stored call in multisig #6319
Changes from 5 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
c7584c0
Stored call in multisig
gavofyork 0ddd158
Docs.
gavofyork c30f54f
Benchmarks.
gavofyork dbac9eb
Fix
gavofyork 3669489
Update frame/multisig/src/lib.rs
gavofyork 9f59d31
patch benchmarks
shawntabrizi 69682e5
Minor grumbles.
gavofyork e48f3e4
Merge branch 'gav-multisig-stored-call' of github.com:paritytech/subs…
gavofyork a363d4b
Update as_multi weight
shawntabrizi 1c69bb0
Merge branch 'gav-multisig-stored-call' of https://github.com/parityt…
shawntabrizi a8343cb
Fixes and refactoring.
gavofyork fdcab27
Merge branch 'gav-multisig-stored-call' of github.com:paritytech/subs…
gavofyork bd5f05e
Split out threshold=1 and opaquify Call.
gavofyork 8b9aaae
Compiles, tests pass, weights are broken
shawntabrizi 09da872
Update benchmarks, add working tests
shawntabrizi 2b5c361
Add benchmark to threshold 1, add event too
shawntabrizi 2cf2832
suppress warning for now
shawntabrizi 9a2d25f
@xlc improvment nit
shawntabrizi db75543
Update weight and tests
shawntabrizi 6275b9c
Test for weight check
shawntabrizi 5c9a7af
Merge branch 'master' into gav-multisig-stored-call
shawntabrizi 81195da
Fix line width
shawntabrizi 7a75cf7
one more line width error
shawntabrizi 9dd0585
Apply suggestions from code review
shawntabrizi 7af9a83
Merge branch 'master' into gav-multisig-stored-call
shawntabrizi f64e26d
fix merge
shawntabrizi 9becf6e
more @apopiak feedback
shawntabrizi 5bd6514
Multisig handles no preimage
shawntabrizi 5cc17da
Optimize return weight after dispatch
shawntabrizi a053de8
Merge remote-tracking branch 'origin/master' into gav-multisig-stored…
gavofyork 9e2d5b6
Error on failed deposit.
gavofyork File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,6 +122,8 @@ decl_storage! { | |
pub Multisigs: double_map | ||
hasher(twox_64_concat) T::AccountId, hasher(blake2_128_concat) [u8; 32] | ||
=> Option<Multisig<T::BlockNumber, BalanceOf<T>, T::AccountId>>; | ||
|
||
pub Calls: map hasher(identity) [u8; 32] => Option<(Vec<u8>, T::AccountId, BalanceOf<T>)>; | ||
} | ||
} | ||
|
||
|
@@ -278,6 +280,7 @@ decl_module! { | |
other_signatories: Vec<T::AccountId>, | ||
maybe_timepoint: Option<Timepoint<T::BlockNumber>>, | ||
call: Box<<T as Trait>::Call>, | ||
store_call: bool, | ||
) -> DispatchResultWithPostInfo { | ||
let who = ensure_signed(origin)?; | ||
// We're now executing as a freshly authenticated new account, so the previous call | ||
|
@@ -292,7 +295,12 @@ decl_module! { | |
let signatories = Self::ensure_sorted_and_insert(other_signatories, who.clone())?; | ||
|
||
let id = Self::multi_account_id(&signatories, threshold); | ||
let call_hash = call.using_encoded(blake2_256); | ||
|
||
let encoded_call = call.encode(); | ||
let call_hash = blake2_256(&encoded_call); | ||
if store_call { | ||
Self::store_call(who.clone(), &call_hash, encoded_call)?; | ||
gavofyork marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
if let Some(mut m) = <Multisigs<T>>::get(&id, call_hash) { | ||
let timepoint = maybe_timepoint.ok_or(Error::<T>::NoTimepoint)?; | ||
|
@@ -315,6 +323,7 @@ decl_module! { | |
let result = call.dispatch(frame_system::RawOrigin::Signed(id.clone()).into()); | ||
let _ = T::Currency::unreserve(&m.depositor, m.deposit); | ||
<Multisigs<T>>::remove(&id, call_hash); | ||
Self::take_call(&call_hash); | ||
Self::deposit_event(RawEvent::MultisigExecuted( | ||
who, timepoint, id, call_hash, result.map(|_| ()).map_err(|e| e.error) | ||
)); | ||
|
@@ -425,6 +434,17 @@ decl_module! { | |
ensure!(m.when == timepoint, Error::<T>::WrongTimepoint); | ||
ensure!(m.approvals.len() < threshold as usize, Error::<T>::NoApprovalsNeeded); | ||
if let Err(pos) = m.approvals.binary_search(&who) { | ||
if m.approvals.len() + 1 == threshold as usize { | ||
if let Some(call) = Self::take_call(&call_hash) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should change the weight calculation of the dispatchable. |
||
let result = call.dispatch(frame_system::RawOrigin::Signed(id.clone()).into()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also should change the weight. In my estimation you are running into the same issues I had in collective which also has stored calls that are (potentially) executed later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
let _ = T::Currency::unreserve(&m.depositor, m.deposit); | ||
<Multisigs<T>>::remove(&id, call_hash); | ||
Self::deposit_event(RawEvent::MultisigExecuted( | ||
who, timepoint, id, call_hash, result.map(|_| ()).map_err(|e| e.error) | ||
)); | ||
return Ok(()); | ||
} | ||
} | ||
m.approvals.insert(pos, who.clone()); | ||
<Multisigs<T>>::insert(&id, call_hash, m); | ||
Self::deposit_event(RawEvent::MultisigApproval(who, timepoint, id, call_hash)); | ||
|
@@ -506,7 +526,8 @@ decl_module! { | |
ensure!(m.depositor == who, Error::<T>::NotOwner); | ||
|
||
let _ = T::Currency::unreserve(&m.depositor, m.deposit); | ||
<Multisigs<T>>::remove(&id, call_hash); | ||
<Multisigs<T>>::remove(&id, &call_hash); | ||
Self::take_call(&call_hash); | ||
|
||
Self::deposit_event(RawEvent::MultisigCancelled(who, timepoint, id, call_hash)); | ||
Ok(()) | ||
|
@@ -524,6 +545,26 @@ impl<T: Trait> Module<T> { | |
T::AccountId::decode(&mut &entropy[..]).unwrap_or_default() | ||
} | ||
|
||
/// Place a call's encoded data in storage, reserving funds as appropriate. | ||
fn store_call(who: T::AccountId, hash: &[u8; 32], data: Vec<u8>) -> DispatchResult { | ||
if !Calls::<T>::contains_key(hash) { | ||
let deposit = T::DepositBase::get() | ||
+ T::DepositFactor::get() * BalanceOf::<T>::from(((data.len() + 31) / 32) as u32); | ||
apopiak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
T::Currency::reserve(&who, deposit)?; | ||
// we store `data` here because storing `call` would result in needing another `.encode`. | ||
Calls::<T>::insert(&hash, (data, who, deposit)); | ||
} | ||
Ok(()) | ||
} | ||
|
||
/// Attempt to remove a call from storage, returning it and any deposit on it to the owner. | ||
fn take_call(hash: &[u8; 32]) -> Option<<T as Trait>::Call> { | ||
Calls::<T>::take(hash).and_then(|(data, who, deposit)| { | ||
T::Currency::unreserve(&who, deposit); | ||
Decode::decode(&mut &data[..]).ok() | ||
}) | ||
} | ||
|
||
/// The current `Timepoint`. | ||
pub fn timepoint() -> Timepoint<T::BlockNumber> { | ||
Timepoint { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: maybe add descriptive type defs for
[u8; 32]
(CallHash
?) andVec<u8>
(EncodedCall
) ?