Skip to content

Commit

Permalink
Rename anonymous to pure proxy (paritytech#12283)
Browse files Browse the repository at this point in the history
* rename anon to pure proxy

* remove old weight comments

* fix merge

* Update frame/proxy/src/lib.rs

Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>

* fn pure -> fn create_pure

Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
  • Loading branch information
2 people authored and ark0f committed Feb 27, 2023
1 parent 3d1d774 commit dfae062
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 113 deletions.
2 changes: 1 addition & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ Runtime
-------

* Introduce stacked filtering (#6273)
* Allow "anonymous" proxied accounts (#6236)
* Allow "pure" proxied accounts (#6236)
* Allow over-weight collective proposals to be closed (#6163)
* Fix Election when ForceNone V1 (#6166)

Expand Down
24 changes: 12 additions & 12 deletions frame/proxy/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ benchmarks! {
let a in 0 .. T::MaxPending::get() - 1;
let p in 1 .. (T::MaxProxies::get() - 1) => add_proxies::<T>(p, None)?;
// In this case the caller is the "target" proxy
let caller: T::AccountId = account("anonymous", 0, SEED);
let caller: T::AccountId = account("pure", 0, SEED);
let delegate: T::AccountId = account("target", p - 1, SEED);
let delegate_lookup = T::Lookup::unlookup(delegate.clone());
T::Currency::make_free_balance_be(&delegate, BalanceOf::<T>::max_value() / 2u32.into());
Expand Down Expand Up @@ -218,7 +218,7 @@ benchmarks! {
assert_eq!(proxies.len() as u32, 0);
}

anonymous {
create_pure {
let p in 1 .. (T::MaxProxies::get() - 1) => add_proxies::<T>(p, None)?;
let caller: T::AccountId = whitelisted_caller();
}: _(
Expand All @@ -228,36 +228,36 @@ benchmarks! {
0
)
verify {
let anon_account = Pallet::<T>::anonymous_account(&caller, &T::ProxyType::default(), 0, None);
assert_last_event::<T>(Event::AnonymousCreated {
anonymous: anon_account,
let pure_account = Pallet::<T>::pure_account(&caller, &T::ProxyType::default(), 0, None);
assert_last_event::<T>(Event::PureCreated {
pure: pure_account,
who: caller,
proxy_type: T::ProxyType::default(),
disambiguation_index: 0,
}.into());
}

kill_anonymous {
kill_pure {
let p in 0 .. (T::MaxProxies::get() - 2);

let caller: T::AccountId = whitelisted_caller();
let caller_lookup = T::Lookup::unlookup(caller.clone());
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
Pallet::<T>::anonymous(
Pallet::<T>::create_pure(
RawOrigin::Signed(whitelisted_caller()).into(),
T::ProxyType::default(),
T::BlockNumber::zero(),
0
)?;
let height = system::Pallet::<T>::block_number();
let ext_index = system::Pallet::<T>::extrinsic_index().unwrap_or(0);
let anon = Pallet::<T>::anonymous_account(&caller, &T::ProxyType::default(), 0, None);
let pure_account = Pallet::<T>::pure_account(&caller, &T::ProxyType::default(), 0, None);

add_proxies::<T>(p, Some(anon.clone()))?;
ensure!(Proxies::<T>::contains_key(&anon), "anon proxy not created");
}: _(RawOrigin::Signed(anon.clone()), caller_lookup, T::ProxyType::default(), 0, height, ext_index)
add_proxies::<T>(p, Some(pure_account.clone()))?;
ensure!(Proxies::<T>::contains_key(&pure_account), "pure proxy not created");
}: _(RawOrigin::Signed(pure_account.clone()), caller_lookup, T::ProxyType::default(), 0, height, ext_index)
verify {
assert!(!Proxies::<T>::contains_key(&anon));
assert!(!Proxies::<T>::contains_key(&pure_account));
}

impl_benchmark_test_suite!(Proxy, crate::tests::new_test_ext(), crate::tests::Test);
Expand Down
109 changes: 30 additions & 79 deletions frame/proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,6 @@ pub mod pallet {
/// - `real`: The account that the proxy will make a call on behalf of.
/// - `force_proxy_type`: Specify the exact proxy type to be used and checked for this call.
/// - `call`: The call to be made by the `real` account.
///
/// # <weight>
/// Weight is a function of the number of proxies the user has (P).
/// # </weight>
#[pallet::weight({
let di = call.get_dispatch_info();
(T::WeightInfo::proxy(T::MaxProxies::get())
Expand Down Expand Up @@ -228,10 +224,6 @@ pub mod pallet {
/// - `proxy_type`: The permissions allowed for this proxy account.
/// - `delay`: The announcement period required of the initial proxy. Will generally be
/// zero.
///
/// # <weight>
/// Weight is a function of the number of proxies the user has (P).
/// # </weight>
#[pallet::weight(T::WeightInfo::add_proxy(T::MaxProxies::get()))]
pub fn add_proxy(
origin: OriginFor<T>,
Expand All @@ -251,10 +243,6 @@ pub mod pallet {
/// Parameters:
/// - `proxy`: The account that the `caller` would like to remove as a proxy.
/// - `proxy_type`: The permissions currently enabled for the removed proxy account.
///
/// # <weight>
/// Weight is a function of the number of proxies the user has (P).
/// # </weight>
#[pallet::weight(T::WeightInfo::remove_proxy(T::MaxProxies::get()))]
pub fn remove_proxy(
origin: OriginFor<T>,
Expand All @@ -271,12 +259,8 @@ pub mod pallet {
///
/// The dispatch origin for this call must be _Signed_.
///
/// WARNING: This may be called on accounts created by `anonymous`, however if done, then
/// WARNING: This may be called on accounts created by `pure`, however if done, then
/// the unreserved fees will be inaccessible. **All access to this account will be lost.**
///
/// # <weight>
/// Weight is a function of the number of proxies the user has (P).
/// # </weight>
#[pallet::weight(T::WeightInfo::remove_proxies(T::MaxProxies::get()))]
pub fn remove_proxies(origin: OriginFor<T>) -> DispatchResult {
let who = ensure_signed(origin)?;
Expand Down Expand Up @@ -304,22 +288,17 @@ pub mod pallet {
/// same sender, with the same parameters.
///
/// Fails if there are insufficient funds to pay for deposit.
///
/// # <weight>
/// Weight is a function of the number of proxies the user has (P).
/// # </weight>
/// TODO: Might be over counting 1 read
#[pallet::weight(T::WeightInfo::anonymous(T::MaxProxies::get()))]
pub fn anonymous(
#[pallet::weight(T::WeightInfo::create_pure(T::MaxProxies::get()))]
pub fn create_pure(
origin: OriginFor<T>,
proxy_type: T::ProxyType,
delay: T::BlockNumber,
index: u16,
) -> DispatchResult {
let who = ensure_signed(origin)?;

let anonymous = Self::anonymous_account(&who, &proxy_type, index, None);
ensure!(!Proxies::<T>::contains_key(&anonymous), Error::<T>::Duplicate);
let pure = Self::pure_account(&who, &proxy_type, index, None);
ensure!(!Proxies::<T>::contains_key(&pure), Error::<T>::Duplicate);

let proxy_def =
ProxyDefinition { delegate: who.clone(), proxy_type: proxy_type.clone(), delay };
Expand All @@ -329,9 +308,9 @@ pub mod pallet {
let deposit = T::ProxyDepositBase::get() + T::ProxyDepositFactor::get();
T::Currency::reserve(&who, deposit)?;

Proxies::<T>::insert(&anonymous, (bounded_proxies, deposit));
Self::deposit_event(Event::AnonymousCreated {
anonymous,
Proxies::<T>::insert(&pure, (bounded_proxies, deposit));
Self::deposit_event(Event::PureCreated {
pure,
who,
proxy_type,
disambiguation_index: index,
Expand All @@ -340,28 +319,24 @@ pub mod pallet {
Ok(())
}

/// Removes a previously spawned anonymous proxy.
/// Removes a previously spawned pure proxy.
///
/// WARNING: **All access to this account will be lost.** Any funds held in it will be
/// inaccessible.
///
/// Requires a `Signed` origin, and the sender account must have been created by a call to
/// `anonymous` with corresponding parameters.
///
/// - `spawner`: The account that originally called `anonymous` to create this account.
/// - `index`: The disambiguation index originally passed to `anonymous`. Probably `0`.
/// - `proxy_type`: The proxy type originally passed to `anonymous`.
/// - `height`: The height of the chain when the call to `anonymous` was processed.
/// - `ext_index`: The extrinsic index in which the call to `anonymous` was processed.
///
/// Fails with `NoPermission` in case the caller is not a previously created anonymous
/// account whose `anonymous` call has corresponding parameters.
///
/// # <weight>
/// Weight is a function of the number of proxies the user has (P).
/// # </weight>
#[pallet::weight(T::WeightInfo::kill_anonymous(T::MaxProxies::get()))]
pub fn kill_anonymous(
/// `pure` with corresponding parameters.
///
/// - `spawner`: The account that originally called `pure` to create this account.
/// - `index`: The disambiguation index originally passed to `pure`. Probably `0`.
/// - `proxy_type`: The proxy type originally passed to `pure`.
/// - `height`: The height of the chain when the call to `pure` was processed.
/// - `ext_index`: The extrinsic index in which the call to `pure` was processed.
///
/// Fails with `NoPermission` in case the caller is not a previously created pure
/// account whose `pure` call has corresponding parameters.
#[pallet::weight(T::WeightInfo::kill_pure(T::MaxProxies::get()))]
pub fn kill_pure(
origin: OriginFor<T>,
spawner: AccountIdLookupOf<T>,
proxy_type: T::ProxyType,
Expand All @@ -373,7 +348,7 @@ pub mod pallet {
let spawner = T::Lookup::lookup(spawner)?;

let when = (height, ext_index);
let proxy = Self::anonymous_account(&spawner, &proxy_type, index, Some(when));
let proxy = Self::pure_account(&spawner, &proxy_type, index, Some(when));
ensure!(proxy == who, Error::<T>::NoPermission);

let (_, deposit) = Proxies::<T>::take(&who);
Expand All @@ -397,12 +372,6 @@ pub mod pallet {
/// Parameters:
/// - `real`: The account that the proxy will make a call on behalf of.
/// - `call_hash`: The hash of the call to be made by the `real` account.
///
/// # <weight>
/// Weight is a function of:
/// - A: the number of announcements made.
/// - P: the number of proxies the user has.
/// # </weight>
#[pallet::weight(T::WeightInfo::announce(T::MaxPending::get(), T::MaxProxies::get()))]
pub fn announce(
origin: OriginFor<T>,
Expand Down Expand Up @@ -452,12 +421,6 @@ pub mod pallet {
/// Parameters:
/// - `real`: The account that the proxy will make a call on behalf of.
/// - `call_hash`: The hash of the call to be made by the `real` account.
///
/// # <weight>
/// Weight is a function of:
/// - A: the number of announcements made.
/// - P: the number of proxies the user has.
/// # </weight>
#[pallet::weight(T::WeightInfo::remove_announcement(
T::MaxPending::get(),
T::MaxProxies::get()
Expand All @@ -484,12 +447,6 @@ pub mod pallet {
/// Parameters:
/// - `delegate`: The account that previously announced the call.
/// - `call_hash`: The hash of the call to be made.
///
/// # <weight>
/// Weight is a function of:
/// - A: the number of announcements made.
/// - P: the number of proxies the user has.
/// # </weight>
#[pallet::weight(T::WeightInfo::reject_announcement(
T::MaxPending::get(),
T::MaxProxies::get()
Expand Down Expand Up @@ -519,12 +476,6 @@ pub mod pallet {
/// - `real`: The account that the proxy will make a call on behalf of.
/// - `force_proxy_type`: Specify the exact proxy type to be used and checked for this call.
/// - `call`: The call to be made by the `real` account.
///
/// # <weight>
/// Weight is a function of:
/// - A: the number of announcements made.
/// - P: the number of proxies the user has.
/// # </weight>
#[pallet::weight({
let di = call.get_dispatch_info();
(T::WeightInfo::proxy_announced(T::MaxPending::get(), T::MaxProxies::get())
Expand Down Expand Up @@ -565,10 +516,10 @@ pub mod pallet {
pub enum Event<T: Config> {
/// A proxy was executed correctly, with the given.
ProxyExecuted { result: DispatchResult },
/// Anonymous account has been created by new proxy with given
/// A pure account has been created by new proxy with given
/// disambiguation index and proxy type.
AnonymousCreated {
anonymous: T::AccountId,
PureCreated {
pure: T::AccountId,
who: T::AccountId,
proxy_type: T::ProxyType,
disambiguation_index: u16,
Expand Down Expand Up @@ -642,7 +593,7 @@ pub mod pallet {
}

impl<T: Config> Pallet<T> {
/// Calculate the address of an anonymous account.
/// Calculate the address of an pure account.
///
/// - `who`: The spawner account.
/// - `proxy_type`: The type of the proxy that the sender will be registered as over the
Expand All @@ -651,9 +602,9 @@ impl<T: Config> Pallet<T> {
/// - `index`: A disambiguation index, in case this is called multiple times in the same
/// transaction (e.g. with `utility::batch`). Unless you're using `batch` you probably just
/// want to use `0`.
/// - `maybe_when`: The block height and extrinsic index of when the anonymous account was
/// - `maybe_when`: The block height and extrinsic index of when the pure account was
/// created. None to use current block height and extrinsic index.
pub fn anonymous_account(
pub fn pure_account(
who: &T::AccountId,
proxy_type: &T::ProxyType,
index: u16,
Expand Down Expand Up @@ -830,9 +781,9 @@ impl<T: Config> Pallet<T> {
Some(Call::remove_proxy { ref proxy_type, .. })
if !def.proxy_type.is_superset(proxy_type) =>
false,
// Proxy call cannot remove all proxies or kill anonymous proxies unless it has full
// Proxy call cannot remove all proxies or kill pure proxies unless it has full
// permissions.
Some(Call::remove_proxies { .. }) | Some(Call::kill_anonymous { .. })
Some(Call::remove_proxies { .. }) | Some(Call::kill_pure { .. })
if def.proxy_type != T::ProxyType::default() =>
false,
_ => def.proxy_type.filter(c),
Expand Down
30 changes: 15 additions & 15 deletions frame/proxy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,42 +550,42 @@ fn proxying_works() {
}

#[test]
fn anonymous_works() {
fn pure_works() {
new_test_ext().execute_with(|| {
assert_ok!(Proxy::anonymous(RuntimeOrigin::signed(1), ProxyType::Any, 0, 0));
let anon = Proxy::anonymous_account(&1, &ProxyType::Any, 0, None);
assert_ok!(Proxy::create_pure(RuntimeOrigin::signed(1), ProxyType::Any, 0, 0));
let anon = Proxy::pure_account(&1, &ProxyType::Any, 0, None);
System::assert_last_event(
ProxyEvent::AnonymousCreated {
anonymous: anon,
ProxyEvent::PureCreated {
pure: anon,
who: 1,
proxy_type: ProxyType::Any,
disambiguation_index: 0,
}
.into(),
);

// other calls to anonymous allowed as long as they're not exactly the same.
assert_ok!(Proxy::anonymous(RuntimeOrigin::signed(1), ProxyType::JustTransfer, 0, 0));
assert_ok!(Proxy::anonymous(RuntimeOrigin::signed(1), ProxyType::Any, 0, 1));
let anon2 = Proxy::anonymous_account(&2, &ProxyType::Any, 0, None);
assert_ok!(Proxy::anonymous(RuntimeOrigin::signed(2), ProxyType::Any, 0, 0));
// other calls to pure allowed as long as they're not exactly the same.
assert_ok!(Proxy::create_pure(RuntimeOrigin::signed(1), ProxyType::JustTransfer, 0, 0));
assert_ok!(Proxy::create_pure(RuntimeOrigin::signed(1), ProxyType::Any, 0, 1));
let anon2 = Proxy::pure_account(&2, &ProxyType::Any, 0, None);
assert_ok!(Proxy::create_pure(RuntimeOrigin::signed(2), ProxyType::Any, 0, 0));
assert_noop!(
Proxy::anonymous(RuntimeOrigin::signed(1), ProxyType::Any, 0, 0),
Proxy::create_pure(RuntimeOrigin::signed(1), ProxyType::Any, 0, 0),
Error::<Test>::Duplicate
);
System::set_extrinsic_index(1);
assert_ok!(Proxy::anonymous(RuntimeOrigin::signed(1), ProxyType::Any, 0, 0));
assert_ok!(Proxy::create_pure(RuntimeOrigin::signed(1), ProxyType::Any, 0, 0));
System::set_extrinsic_index(0);
System::set_block_number(2);
assert_ok!(Proxy::anonymous(RuntimeOrigin::signed(1), ProxyType::Any, 0, 0));
assert_ok!(Proxy::create_pure(RuntimeOrigin::signed(1), ProxyType::Any, 0, 0));

let call = Box::new(call_transfer(6, 1));
assert_ok!(Balances::transfer(RuntimeOrigin::signed(3), anon, 5));
assert_ok!(Proxy::proxy(RuntimeOrigin::signed(1), anon, None, call));
System::assert_last_event(ProxyEvent::ProxyExecuted { result: Ok(()) }.into());
assert_eq!(Balances::free_balance(6), 1);

let call = Box::new(RuntimeCall::Proxy(ProxyCall::new_call_variant_kill_anonymous(
let call = Box::new(RuntimeCall::Proxy(ProxyCall::new_call_variant_kill_pure(
1,
ProxyType::Any,
0,
Expand All @@ -596,7 +596,7 @@ fn anonymous_works() {
let de = DispatchError::from(Error::<Test>::NoPermission).stripped();
System::assert_last_event(ProxyEvent::ProxyExecuted { result: Err(de) }.into());
assert_noop!(
Proxy::kill_anonymous(RuntimeOrigin::signed(1), 1, ProxyType::Any, 0, 1, 0),
Proxy::kill_pure(RuntimeOrigin::signed(1), 1, ProxyType::Any, 0, 1, 0),
Error::<Test>::NoPermission
);
assert_eq!(Balances::free_balance(1), 0);
Expand Down
Loading

0 comments on commit dfae062

Please sign in to comment.