Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
update
  • Loading branch information
Doordashcon committed Jun 16, 2022
commit b3562c50f027db7b530a96b75897a041b82016a7
12 changes: 8 additions & 4 deletions frame/conviction-voting/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ benchmarks! {
remove_other_vote {
let caller = funded_account::<T>("caller", 0);
let voter = funded_account::<T>("caller", 0);
let voter_lookup = T::Lookup::unlookup(voter.clone());
whitelist_account!(caller);
let old_account_vote = account_vote::<T>(100u32.into());

Expand All @@ -166,7 +167,7 @@ benchmarks! {

let index = polls[0];
assert!(T::Polls::end_ongoing(index, false).is_ok());
}: _(RawOrigin::Signed(caller.clone()), voter.clone(), class.clone(), index)
}: _(RawOrigin::Signed(caller.clone()), voter_lookup, class.clone(), index)
verify {
assert_matches!(
VotingFor::<T>::get(&voter, &class),
Expand All @@ -181,6 +182,7 @@ benchmarks! {
let class = T::Polls::max_ongoing().0;
let polls = &all_polls[&class];
let voter = funded_account::<T>("voter", 0);
let voter_lookup = T::Lookup::unlookup(voter.clone());
let caller = funded_account::<T>("caller", 0);
whitelist_account!(caller);

Expand All @@ -196,7 +198,7 @@ benchmarks! {
Voting::Casting(Casting { votes, .. }) if votes.len() == r as usize
);

}: _(RawOrigin::Signed(caller.clone()), class.clone(), voter, Conviction::Locked1x, delegated_balance)
}: _(RawOrigin::Signed(caller.clone()), class.clone(), voter_lookup, Conviction::Locked1x, delegated_balance)
verify {
assert_matches!(VotingFor::<T>::get(&caller, &class), Voting::Delegating(_));
}
Expand All @@ -208,6 +210,7 @@ benchmarks! {
let class = T::Polls::max_ongoing().0;
let polls = &all_polls[&class];
let voter = funded_account::<T>("voter", 0);
let voter_lookup = T::Lookup::unlookup(voter.clone());
let caller = funded_account::<T>("caller", 0);
whitelist_account!(caller);

Expand All @@ -217,7 +220,7 @@ benchmarks! {
ConvictionVoting::<T>::delegate(
RawOrigin::Signed(caller.clone()).into(),
class.clone(),
voter.clone(),
voter_lookup,
Conviction::Locked1x,
delegated_balance,
)?;
Expand All @@ -238,6 +241,7 @@ benchmarks! {

unlock {
let caller = funded_account::<T>("caller", 0);
let caller_lookup = T::Lookup::unlookup(caller.clone());
whitelist_account!(caller);
let normal_account_vote = account_vote::<T>(T::Currency::free_balance(&caller) - 100u32.into());
let big_account_vote = account_vote::<T>(T::Currency::free_balance(&caller));
Expand Down Expand Up @@ -265,7 +269,7 @@ benchmarks! {
ConvictionVoting::<T>::remove_vote(RawOrigin::Signed(caller.clone()).into(), Some(class.clone()), polls[0])?;

// We can now unlock on `class` from 200 to 100...
}: _(RawOrigin::Signed(caller.clone()), class, caller.clone())
}: _(RawOrigin::Signed(caller.clone()), class, caller_lookup)
verify {
assert_eq!(orig_usable, <T::Currency as fungible::Inspect<T::AccountId>>::reducible_balance(&caller, false));
}
Expand Down
11 changes: 7 additions & 4 deletions frame/conviction-voting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use frame_support::{
},
};
use sp_runtime::{
traits::{AtLeast32BitUnsigned, Saturating, Zero},
traits::{AtLeast32BitUnsigned, Saturating, Zero, StaticLookup},
ArithmeticError, Perbill,
};
use sp_std::prelude::*;
Expand Down Expand Up @@ -246,11 +246,12 @@ pub mod pallet {
pub fn delegate(
origin: OriginFor<T>,
class: ClassOf<T, I>,
to: T::AccountId,
to: <T::Lookup as StaticLookup>::Source,
conviction: Conviction,
balance: BalanceOf<T, I>,
) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
let to = T::Lookup::lookup(to)?;
let votes = Self::try_delegate(who, class, to, conviction, balance)?;

Ok(Some(T::WeightInfo::delegate(votes)).into())
Expand Down Expand Up @@ -295,9 +296,10 @@ pub mod pallet {
pub fn unlock(
origin: OriginFor<T>,
class: ClassOf<T, I>,
target: T::AccountId,
target: <T::Lookup as StaticLookup>::Source,
) -> DispatchResult {
ensure_signed(origin)?;
let target = T::Lookup::lookup(target)?;
Self::update_lock(&class, &target);
Ok(())
}
Expand Down Expand Up @@ -360,11 +362,12 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::remove_other_vote())]
pub fn remove_other_vote(
origin: OriginFor<T>,
target: T::AccountId,
target: <T::Lookup as StaticLookup>::Source,
class: ClassOf<T, I>,
index: PollIndexOf<T, I>,
) -> DispatchResult {
let who = ensure_signed(origin)?;
let target = T::Lookup::lookup(target)?;
let scope = if target == who { UnvoteScope::Any } else { UnvoteScope::OnlyExpired };
Self::try_remove_vote(&target, index, Some(class), scope)?;
Ok(())
Expand Down
18 changes: 12 additions & 6 deletions frame/democracy/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,10 @@ benchmarks! {
let caller = funded_account::<T>("caller", 0);
// Caller will initially delegate to `old_delegate`
let old_delegate: T::AccountId = funded_account::<T>("old_delegate", r);
let old_delegate_lookup = T::Lookup::unlookup(old_delegate.clone());
Democracy::<T>::delegate(
RawOrigin::Signed(caller.clone()).into(),
old_delegate.clone(),
old_delegate_lookup,
Conviction::Locked1x,
delegated_balance,
)?;
Expand All @@ -495,6 +496,7 @@ benchmarks! {
assert_eq!(balance, delegated_balance, "delegation balance didn't work");
// Caller will now switch to `new_delegate`
let new_delegate: T::AccountId = funded_account::<T>("new_delegate", r);
let new_delegate_lookup = T::Lookup::unlookup(new_delegate.clone());
let account_vote = account_vote::<T>(initial_balance);
// We need to create existing direct votes for the `new_delegate`
for i in 0..r {
Expand All @@ -507,7 +509,7 @@ benchmarks! {
};
assert_eq!(votes.len(), r as usize, "Votes were not recorded.");
whitelist_account!(caller);
}: _(RawOrigin::Signed(caller.clone()), new_delegate.clone(), Conviction::Locked1x, delegated_balance)
}: _(RawOrigin::Signed(caller.clone()), new_delegate_lookup, Conviction::Locked1x, delegated_balance)
verify {
let (target, balance) = match VotingOf::<T>::get(&caller) {
Voting::Delegating { target, balance, .. } => (target, balance),
Expand All @@ -531,9 +533,10 @@ benchmarks! {
let caller = funded_account::<T>("caller", 0);
// Caller will delegate
let the_delegate: T::AccountId = funded_account::<T>("delegate", r);
let the_delegate_lookup = T::Lookup::unlookup(the_delegate.clone());
Democracy::<T>::delegate(
RawOrigin::Signed(caller.clone()).into(),
the_delegate.clone(),
the_delegate_lookup,
Conviction::Locked1x,
delegated_balance,
)?;
Expand Down Expand Up @@ -640,6 +643,7 @@ benchmarks! {
let r in 1 .. MAX_REFERENDUMS;

let locker = funded_account::<T>("locker", 0);
let locker_lookup = T::Lookup::unlookup(locker.clone());
// Populate votes so things are locked
let base_balance: BalanceOf<T> = 100u32.into();
let small_vote = account_vote::<T>(base_balance);
Expand All @@ -652,7 +656,7 @@ benchmarks! {

let caller = funded_account::<T>("caller", 0);
whitelist_account!(caller);
}: unlock(RawOrigin::Signed(caller), locker.clone())
}: unlock(RawOrigin::Signed(caller), locker_lookup)
verify {
// Note that we may want to add a `get_lock` api to actually verify
let voting = VotingOf::<T>::get(&locker);
Expand All @@ -664,6 +668,7 @@ benchmarks! {
let r in 1 .. MAX_REFERENDUMS;

let locker = funded_account::<T>("locker", 0);
let locker_lookup = T::Lookup::unlookup(locker.clone());
// Populate votes so things are locked
let base_balance: BalanceOf<T> = 100u32.into();
let small_vote = account_vote::<T>(base_balance);
Expand All @@ -690,7 +695,7 @@ benchmarks! {

let caller = funded_account::<T>("caller", 0);
whitelist_account!(caller);
}: unlock(RawOrigin::Signed(caller), locker.clone())
}: unlock(RawOrigin::Signed(caller), locker_lookup)
verify {
let votes = match VotingOf::<T>::get(&locker) {
Voting::Direct { votes, .. } => votes,
Expand Down Expand Up @@ -736,6 +741,7 @@ benchmarks! {
let r in 1 .. MAX_REFERENDUMS;

let caller = funded_account::<T>("caller", r);
let caller_lookup = T::Lookup::unlookup(caller.clone());
let account_vote = account_vote::<T>(100u32.into());

for i in 0 .. r {
Expand All @@ -751,7 +757,7 @@ benchmarks! {

let referendum_index = r - 1;
whitelist_account!(caller);
}: _(RawOrigin::Signed(caller.clone()), caller.clone(), referendum_index)
}: _(RawOrigin::Signed(caller.clone()), caller_lookup, referendum_index)
verify {
let votes = match VotingOf::<T>::get(&caller) {
Voting::Direct { votes, .. } => votes,
Expand Down
11 changes: 7 additions & 4 deletions frame/democracy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ use frame_support::{
};
use scale_info::TypeInfo;
use sp_runtime::{
traits::{Bounded, Dispatchable, Hash, Saturating, Zero},
traits::{Bounded, Dispatchable, Hash, Saturating, Zero, StaticLookup},
ArithmeticError, DispatchError, DispatchResult, RuntimeDebug,
};
use sp_std::prelude::*;
Expand Down Expand Up @@ -941,11 +941,12 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::delegate(T::MaxVotes::get()))]
pub fn delegate(
origin: OriginFor<T>,
to: T::AccountId,
to: <T::Lookup as StaticLookup>::Source,
conviction: Conviction,
balance: BalanceOf<T>,
) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
let to = T::Lookup::lookup(to)?;
let votes = Self::try_delegate(who, to, conviction, balance)?;

Ok(Some(T::WeightInfo::delegate(votes)).into())
Expand Down Expand Up @@ -1124,8 +1125,9 @@ pub mod pallet {
T::WeightInfo::unlock_set(T::MaxVotes::get())
.max(T::WeightInfo::unlock_remove(T::MaxVotes::get()))
)]
pub fn unlock(origin: OriginFor<T>, target: T::AccountId) -> DispatchResult {
pub fn unlock(origin: OriginFor<T>, target: <T::Lookup as StaticLookup>::Source) -> DispatchResult {
ensure_signed(origin)?;
let target = T::Lookup::lookup(target)?;
Self::update_lock(&target);
Ok(())
}
Expand Down Expand Up @@ -1181,10 +1183,11 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::remove_other_vote(T::MaxVotes::get()))]
pub fn remove_other_vote(
origin: OriginFor<T>,
target: T::AccountId,
target: <T::Lookup as StaticLookup>::Source,
index: ReferendumIndex,
) -> DispatchResult {
let who = ensure_signed(origin)?;
let target = T::Lookup::lookup(target)?;
let scope = if target == who { UnvoteScope::Any } else { UnvoteScope::OnlyExpired };
Self::try_remove_vote(&target, index, scope)?;
Ok(())
Expand Down
15 changes: 10 additions & 5 deletions frame/identity/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) {
fn add_registrars<T: Config>(r: u32) -> Result<(), &'static str> {
for i in 0..r {
let registrar: T::AccountId = account("registrar", i, SEED);
let registrar_lookup = T::Lookup::unlookup(registrar.clone());
let _ = T::Currency::make_free_balance_be(&registrar, BalanceOf::<T>::max_value());
Identity::<T>::add_registrar(RawOrigin::Root.into(), registrar.clone())?;
Identity::<T>::add_registrar(RawOrigin::Root.into(), registrar_lookup)?;
Identity::<T>::set_fee(RawOrigin::Signed(registrar.clone()).into(), i, 10u32.into())?;
let fields =
IdentityFields(
Expand Down Expand Up @@ -256,10 +257,11 @@ benchmarks! {

set_fee {
let caller: T::AccountId = whitelisted_caller();
let caller_lookup = T::Lookup::unlookup(caller.clone());

let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::<T>(r)?;

Identity::<T>::add_registrar(RawOrigin::Root.into(), caller.clone())?;
Identity::<T>::add_registrar(RawOrigin::Root.into(), caller_lookup)?;
let registrars = Registrars::<T>::get();
ensure!(registrars[r as usize].as_ref().unwrap().fee == 0u32.into(), "Fee already set.");
}: _(RawOrigin::Signed(caller), r, 100u32.into())
Expand All @@ -270,11 +272,12 @@ benchmarks! {

set_account_id {
let caller: T::AccountId = whitelisted_caller();
let caller_lookup = T::Lookup::unlookup(caller.clone());
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());

let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::<T>(r)?;

Identity::<T>::add_registrar(RawOrigin::Root.into(), caller.clone())?;
Identity::<T>::add_registrar(RawOrigin::Root.into(), caller_lookup)?;
let registrars = Registrars::<T>::get();
ensure!(registrars[r as usize].as_ref().unwrap().account == caller, "id not set.");
}: _(RawOrigin::Signed(caller), r, account("new", 0, SEED))
Expand All @@ -285,11 +288,12 @@ benchmarks! {

set_fields {
let caller: T::AccountId = whitelisted_caller();
let caller_lookup = T::Lookup::unlookup(caller.clone());
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());

let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::<T>(r)?;

Identity::<T>::add_registrar(RawOrigin::Root.into(), caller.clone())?;
Identity::<T>::add_registrar(RawOrigin::Root.into(), caller_lookup)?;
let fields = IdentityFields(
IdentityField::Display | IdentityField::Legal | IdentityField::Web | IdentityField::Riot
| IdentityField::Email | IdentityField::PgpFingerprint | IdentityField::Image | IdentityField::Twitter
Expand All @@ -310,6 +314,7 @@ benchmarks! {
let _ = T::Currency::make_free_balance_be(&user, BalanceOf::<T>::max_value());

let caller: T::AccountId = whitelisted_caller();
let caller_lookup = T::Lookup::unlookup(caller.clone());
let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());

let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::<T>(r)?;
Expand All @@ -318,7 +323,7 @@ benchmarks! {
Identity::<T>::set_identity(user_origin.clone(), Box::new(info))?;
};

Identity::<T>::add_registrar(RawOrigin::Root.into(), caller.clone())?;
Identity::<T>::add_registrar(RawOrigin::Root.into(), caller_lookup)?;
Identity::<T>::request_judgement(user_origin, r, 10u32.into())?;
}: _(RawOrigin::Signed(caller), r, user_lookup, Judgement::Reasonable)
verify {
Expand Down
6 changes: 4 additions & 2 deletions frame/identity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,10 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::add_registrar(T::MaxRegistrars::get()))]
pub fn add_registrar(
origin: OriginFor<T>,
account: T::AccountId,
account: <T::Lookup as StaticLookup>::Source,
) -> DispatchResultWithPostInfo {
T::RegistrarOrigin::ensure_origin(origin)?;
let account = T::Lookup::lookup(account)?;

let (i, registrar_count) = <Registrars<T>>::try_mutate(
|registrars| -> Result<(RegistrarIndex, usize), DispatchError> {
Expand Down Expand Up @@ -672,9 +673,10 @@ pub mod pallet {
pub fn set_account_id(
origin: OriginFor<T>,
#[pallet::compact] index: RegistrarIndex,
new: T::AccountId,
new: <T::Lookup as StaticLookup>::Source,
) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
let new = T::Lookup::lookup(new)?;

let registrars = <Registrars<T>>::mutate(|rs| -> Result<usize, DispatchError> {
rs.get_mut(index as usize)
Expand Down
6 changes: 4 additions & 2 deletions frame/indices/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ benchmarks! {
let caller: T::AccountId = whitelisted_caller();
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
let recipient: T::AccountId = account("recipient", 0, SEED);
let recipient_lookup = T::Lookup::unlookup(recipient.clone());
T::Currency::make_free_balance_be(&recipient, BalanceOf::<T>::max_value());
// Claim the index
Indices::<T>::claim(RawOrigin::Signed(caller.clone()).into(), account_index)?;
}: _(RawOrigin::Signed(caller.clone()), recipient.clone(), account_index)
}: _(RawOrigin::Signed(caller.clone()), recipient_lookup, account_index)
verify {
assert_eq!(Accounts::<T>::get(account_index).unwrap().0, recipient);
}
Expand All @@ -70,10 +71,11 @@ benchmarks! {
let original: T::AccountId = account("original", 0, SEED);
T::Currency::make_free_balance_be(&original, BalanceOf::<T>::max_value());
let recipient: T::AccountId = account("recipient", 0, SEED);
let recipient_lookup = T::Lookup::unlookup(recipient.clone());
T::Currency::make_free_balance_be(&recipient, BalanceOf::<T>::max_value());
// Claim the index
Indices::<T>::claim(RawOrigin::Signed(original).into(), account_index)?;
}: _(RawOrigin::Root, recipient.clone(), account_index, false)
}: _(RawOrigin::Root, recipient_lookup, account_index, false)
verify {
assert_eq!(Accounts::<T>::get(account_index).unwrap().0, recipient);
}
Expand Down
Loading