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

Time-delay proxies #6770

Merged
38 commits merged into from
Aug 23, 2020
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c8abcbc
Time-delay proxies.
gavofyork Jul 30, 2020
d9b4f18
Tests
gavofyork Jul 31, 2020
a391766
Initial couple of benchmarks
gavofyork Aug 2, 2020
6b21ba2
Merge remote-tracking branch 'origin/master' into gav-delay-proxy
gavofyork Aug 2, 2020
e0552cb
Fix up runtime
gavofyork Aug 2, 2020
39d2dd7
Last couple of benchmarks
gavofyork Aug 2, 2020
905505c
Tests
gavofyork Aug 2, 2020
55b9db4
Docs
gavofyork Aug 2, 2020
4e6474b
Migration
gavofyork Aug 2, 2020
2143169
add tests to proxy benchmarks
shawntabrizi Aug 3, 2020
cd49b2e
generated benchmarks, not integrated
shawntabrizi Aug 3, 2020
202b3c1
Fix weight trait
shawntabrizi Aug 3, 2020
000ff6b
integrate weightinfo
shawntabrizi Aug 3, 2020
5b21635
Merge branch 'master' into gav-delay-proxy
shawntabrizi Aug 3, 2020
ef30122
default weight
shawntabrizi Aug 3, 2020
a87b928
Grumble
gavofyork Aug 4, 2020
402dd67
Deduplication, split proxy from announced_proxy and don't require rea…
gavofyork Aug 4, 2020
ffa36e8
Fix
gavofyork Aug 4, 2020
083bf24
Remoe superfluous
gavofyork Aug 4, 2020
61b57b6
Typos
gavofyork Aug 4, 2020
2492f06
Indent
gavofyork Aug 4, 2020
c02e86c
Fix
gavofyork Aug 4, 2020
c7f0962
Fixes
gavofyork Aug 4, 2020
b077e78
rename 'proxy_announced' -> 'announced_proxy'
shawntabrizi Aug 4, 2020
64e77b4
flip rename
shawntabrizi Aug 4, 2020
33c69ef
comments and spacing
shawntabrizi Aug 4, 2020
a7aa2eb
fix proxy_announced
shawntabrizi Aug 4, 2020
2395ffa
remove unneeded `execute` marker
shawntabrizi Aug 4, 2020
2c3649e
Avoid unneeded changes to extrinsic indices
gavofyork Aug 4, 2020
ec164eb
Merge remote-tracking branch 'origin/gav-delay-proxy' into gav-delay-…
gavofyork Aug 4, 2020
9a4d912
Cleanup
gavofyork Aug 4, 2020
34162ac
Fixes
gavofyork Aug 4, 2020
4094a17
Update Benchmarks and Weights for Delayed Proxy (#6811)
shawntabrizi Aug 4, 2020
2799ae1
Merge branch 'master' into gav-delay-proxy
shawntabrizi Aug 5, 2020
534734f
Merge branch 'master' into gav-delay-proxy
shawntabrizi Aug 19, 2020
c3bfd76
Merge remote-tracking branch 'origin/master' into gav-delay-proxy
gavofyork Aug 21, 2020
135462c
Bump runtime
gavofyork Aug 21, 2020
94d465c
Fix benchmark
gavofyork Aug 23, 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
9 changes: 8 additions & 1 deletion bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ parameter_types! {
// Additional storage item size of 33 bytes.
pub const ProxyDepositFactor: Balance = deposit(0, 33);
pub const MaxProxies: u16 = 32;
pub const AnnouncementDepositBase: Balance = deposit(1, 8);
pub const AnnouncementDepositFactor: Balance = deposit(0, 66);
pub const MaxPending: u16 = 32;
}

/// The type used to represent the kinds of proxying allowed.
Expand Down Expand Up @@ -260,7 +263,11 @@ impl pallet_proxy::Trait for Runtime {
type ProxyDepositBase = ProxyDepositBase;
type ProxyDepositFactor = ProxyDepositFactor;
type MaxProxies = MaxProxies;
type WeightInfo = ();
type WeightInfo = weights::pallet_proxy::WeightInfo;
type MaxPending = MaxPending;
type CallHasher = BlakeTwo256;
type AnnouncementDepositBase = AnnouncementDepositBase;
type AnnouncementDepositFactor = AnnouncementDepositFactor;
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions bin/node/runtime/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
//! A list of the different weight modules for our runtime.

pub mod pallet_balances;
pub mod pallet_proxy;
2 changes: 1 addition & 1 deletion bin/node/runtime/src/weights/pallet_balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//! Weights for the Balances Pallet
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0-rc5

use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight};

Expand Down
81 changes: 81 additions & 0 deletions bin/node/runtime/src/weights/pallet_proxy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright (C) 2020 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0-rc5

use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight};

pub struct WeightInfo;
impl pallet_proxy::WeightInfo for WeightInfo {
fn proxy(p: u32, ) -> Weight {
(27894000 as Weight)
.saturating_add((196000 as Weight).saturating_mul(p as Weight))
.saturating_add(DbWeight::get().reads(1 as Weight))
}
fn proxy_announced(p: u32, ) -> Weight {
(78353000 as Weight)
.saturating_add((201000 as Weight).saturating_mul(p as Weight))
.saturating_add(DbWeight::get().reads(3 as Weight))
.saturating_add(DbWeight::get().writes(2 as Weight))
}
fn remove_announcement(p: u32, ) -> Weight {
(60264000 as Weight)
.saturating_add((4000 as Weight).saturating_mul(p as Weight))
.saturating_add(DbWeight::get().reads(2 as Weight))
.saturating_add(DbWeight::get().writes(2 as Weight))
}
fn reject_announcement(p: u32, ) -> Weight {
(60141000 as Weight)
.saturating_add((10000 as Weight).saturating_mul(p as Weight))
.saturating_add(DbWeight::get().reads(2 as Weight))
.saturating_add(DbWeight::get().writes(2 as Weight))
}
fn announce(p: u32, ) -> Weight {
(74751000 as Weight)
.saturating_add((208000 as Weight).saturating_mul(p as Weight))
.saturating_add(DbWeight::get().reads(3 as Weight))
.saturating_add(DbWeight::get().writes(2 as Weight))
}
fn add_proxy(p: u32, ) -> Weight {
(36250000 as Weight)
.saturating_add((223000 as Weight).saturating_mul(p as Weight))
.saturating_add(DbWeight::get().reads(1 as Weight))
.saturating_add(DbWeight::get().writes(1 as Weight))
}
fn remove_proxy(p: u32, ) -> Weight {
(32843000 as Weight)
.saturating_add((258000 as Weight).saturating_mul(p as Weight))
.saturating_add(DbWeight::get().reads(1 as Weight))
.saturating_add(DbWeight::get().writes(1 as Weight))
}
fn remove_proxies(p: u32, ) -> Weight {
(31834000 as Weight)
.saturating_add((203000 as Weight).saturating_mul(p as Weight))
.saturating_add(DbWeight::get().reads(1 as Weight))
gavofyork marked this conversation as resolved.
Show resolved Hide resolved
.saturating_add(DbWeight::get().writes(1 as Weight))
}
fn anonymous(p: u32, ) -> Weight {
(50947000 as Weight)
.saturating_add((44000 as Weight).saturating_mul(p as Weight))
.saturating_add(DbWeight::get().reads(2 as Weight))
.saturating_add(DbWeight::get().writes(1 as Weight))
}
fn kill_anonymous(p: u32, ) -> Weight {
(34213000 as Weight)
.saturating_add((208000 as Weight).saturating_mul(p as Weight))
.saturating_add(DbWeight::get().reads(1 as Weight))
.saturating_add(DbWeight::get().writes(1 as Weight))
}
}
187 changes: 177 additions & 10 deletions frame/proxy/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,60 @@
#![cfg(feature = "runtime-benchmarks")]

use super::*;
use frame_system::RawOrigin;
use frame_system::{RawOrigin, EventRecord};
use frame_benchmarking::{benchmarks, account};
use sp_runtime::traits::Bounded;
use crate::Module as Proxy;

const SEED: u32 = 0;

fn assert_last_event<T: Trait>(generic_event: <T as Trait>::Event) {
let events = frame_system::Module::<T>::events();
let system_event: <T as frame_system::Trait>::Event = generic_event.into();
// compare to the last event record
let EventRecord { event, .. } = &events[events.len() - 1];
assert_eq!(event, &system_event);
}

fn add_proxies<T: Trait>(n: u32, maybe_who: Option<T::AccountId>) -> Result<(), &'static str> {
let caller = maybe_who.unwrap_or_else(|| account("caller", 0, SEED));
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
for i in 0..n {
Proxy::<T>::add_proxy(
RawOrigin::Signed(caller.clone()).into(),
account("target", i, SEED),
T::ProxyType::default()
T::ProxyType::default(),
T::BlockNumber::zero(),
)?;
}
Ok(())
}

fn add_announcements<T: Trait>(
n: u32,
maybe_who: Option<T::AccountId>,
maybe_real: Option<T::AccountId>
) -> Result<(), &'static str> {
let caller = maybe_who.unwrap_or_else(|| account("caller", 0, SEED));
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
let real = if let Some(real) = maybe_real {
real
} else {
let real = account("real", 0, SEED);
T::Currency::make_free_balance_be(&real, BalanceOf::<T>::max_value());
Proxy::<T>::add_proxy(
RawOrigin::Signed(real.clone()).into(),
caller.clone(),
T::ProxyType::default(),
T::BlockNumber::zero(),
)?;
real
};
for _ in 0..n {
Proxy::<T>::announce(
RawOrigin::Signed(caller.clone()).into(),
real.clone(),
T::CallHasher::hash_of(&("add_announcement", n)),
)?;
}
Ok(())
Expand All @@ -49,43 +88,167 @@ benchmarks! {
let p in ...;
// In this case the caller is the "target" proxy
let caller: T::AccountId = account("target", p - 1, SEED);
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
// ... and "real" is the traditional caller. This is not a typo.
let real: T::AccountId = account("caller", 0, SEED);
let call: <T as Trait>::Call = frame_system::Call::<T>::remark(vec![]).into();
add_announcements::<T>(T::MaxPending::get(), Some(caller.clone()), None)?;
}: _(RawOrigin::Signed(caller), real, Some(T::ProxyType::default()), Box::new(call), false)
verify {
assert_last_event::<T>(RawEvent::ProxyExecuted(Ok(())).into())
}

proxy_announced {
let p in ...;
// In this case the caller is the "target" proxy
let caller: T::AccountId = account("target", p - 1, SEED);
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
// ... and "real" is the traditional caller. This is not a typo.
let real: T::AccountId = account("caller", 0, SEED);
let call: <T as Trait>::Call = frame_system::Call::<T>::remark(vec![]).into();
Proxy::<T>::announce(
RawOrigin::Signed(caller.clone()).into(),
real.clone(),
T::CallHasher::hash_of(&call),
)?;
add_announcements::<T>(T::MaxPending::get() - 1, Some(caller.clone()), None)?;
}: proxy(RawOrigin::Signed(caller), real, Some(T::ProxyType::default()), Box::new(call), true)
verify {
assert_last_event::<T>(RawEvent::ProxyExecuted(Ok(())).into())
}

remove_announcement {
let p in ...;
// In this case the caller is the "target" proxy
let caller: T::AccountId = account("target", p - 1, SEED);
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
// ... and "real" is the traditional caller. This is not a typo.
let real: T::AccountId = account("caller", 0, SEED);
let call: <T as Trait>::Call = frame_system::Call::<T>::remark(vec![]).into();
Proxy::<T>::announce(
RawOrigin::Signed(caller.clone()).into(),
real.clone(),
T::CallHasher::hash_of(&call),
)?;
add_announcements::<T>(T::MaxPending::get() - 1, Some(caller.clone()), None)?;
}: _(RawOrigin::Signed(caller.clone()), real, T::CallHasher::hash_of(&call))
verify {
let (_, announcements) = Announcements::<T>::get(&caller);
assert_eq!(announcements.len() as u32, T::MaxPending::get() - 1);
}

reject_announcement {
let p in ...;
// In this case the caller is the "target" proxy
let caller: T::AccountId = account("target", p - 1, SEED);
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
// ... and "real" is the traditional caller. This is not a typo.
let real: T::AccountId = account("caller", 0, SEED);
let call: <T as Trait>::Call = frame_system::Call::<T>::remark(vec![]).into();
Proxy::<T>::announce(
RawOrigin::Signed(caller.clone()).into(),
real.clone(),
T::CallHasher::hash_of(&call),
)?;
add_announcements::<T>(T::MaxPending::get() - 1, Some(caller.clone()), None)?;
}: _(RawOrigin::Signed(real), caller.clone(), T::CallHasher::hash_of(&call))
verify {
let (_, announcements) = Announcements::<T>::get(&caller);
assert_eq!(announcements.len() as u32, T::MaxPending::get() - 1);
}

announce {
let p in ...;
// In this case the caller is the "target" proxy
let caller: T::AccountId = account("target", p - 1, SEED);
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
// ... and "real" is the traditional caller. This is not a typo.
let real: T::AccountId = account("caller", 0, SEED);
add_announcements::<T>(T::MaxPending::get() - 1, Some(caller.clone()), None)?;
let call: <T as Trait>::Call = frame_system::Call::<T>::remark(vec![]).into();
}: _(RawOrigin::Signed(caller), real, Some(T::ProxyType::default()), Box::new(call))
let call_hash = T::CallHasher::hash_of(&call);
}: _(RawOrigin::Signed(caller.clone()), real.clone(), call_hash)
verify {
assert_last_event::<T>(RawEvent::Announced(real, caller, call_hash).into());
}

add_proxy {
let p in ...;
let caller: T::AccountId = account("caller", 0, SEED);
}: _(RawOrigin::Signed(caller), account("target", T::MaxProxies::get().into(), SEED), T::ProxyType::default())
}: _(
RawOrigin::Signed(caller.clone()),
account("target", T::MaxProxies::get().into(), SEED),
T::ProxyType::default(),
T::BlockNumber::zero()
)
verify {
let (proxies, _) = Proxies::<T>::get(caller);
assert_eq!(proxies.len() as u32, p + 1);
}

remove_proxy {
let p in ...;
let caller: T::AccountId = account("caller", 0, SEED);
}: _(RawOrigin::Signed(caller), account("target", 0, SEED), T::ProxyType::default())
}: _(
RawOrigin::Signed(caller.clone()),
account("target", 0, SEED),
T::ProxyType::default(),
T::BlockNumber::zero()
)
verify {
let (proxies, _) = Proxies::<T>::get(caller);
assert_eq!(proxies.len() as u32, p - 1);
}

remove_proxies {
let p in ...;
let caller: T::AccountId = account("caller", 0, SEED);
}: _(RawOrigin::Signed(caller))
}: _(RawOrigin::Signed(caller.clone()))
verify {
let (proxies, _) = Proxies::<T>::get(caller);
assert_eq!(proxies.len() as u32, 0);
}

anonymous {
let p in ...;
}: _(RawOrigin::Signed(account("caller", 0, SEED)), T::ProxyType::default(), 0)
let caller: T::AccountId = account("caller", 0, SEED);
}: _(
RawOrigin::Signed(caller.clone()),
T::ProxyType::default(),
T::BlockNumber::zero(),
0
)
verify {
let anon_account = Module::<T>::anonymous_account(&caller, &T::ProxyType::default(), 0, None);
assert_last_event::<T>(RawEvent::AnonymousCreated(
anon_account,
caller,
T::ProxyType::default(),
0,
).into());
}

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

let caller: T::AccountId = account("caller", 0, SEED);
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
Module::<T>::anonymous(RawOrigin::Signed(account("caller", 0, SEED)).into(), T::ProxyType::default(), 0)?;
Module::<T>::anonymous(
RawOrigin::Signed(account("caller", 0, SEED)).into(),
T::ProxyType::default(),
T::BlockNumber::zero(),
0
)?;
let height = system::Module::<T>::block_number();
let ext_index = system::Module::<T>::extrinsic_index().unwrap_or(0);
let anon = Module::<T>::anonymous_account(&caller, &T::ProxyType::default(), 0, None);

add_proxies::<T>(p, Some(anon.clone()))?;

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

#[cfg(test)]
Expand All @@ -98,6 +261,10 @@ mod tests {
fn test_benchmarks() {
new_test_ext().execute_with(|| {
assert_ok!(test_benchmark_proxy::<Test>());
assert_ok!(test_benchmark_proxy_announced::<Test>());
assert_ok!(test_benchmark_remove_announcement::<Test>());
assert_ok!(test_benchmark_reject_announcement::<Test>());
assert_ok!(test_benchmark_announce::<Test>());
assert_ok!(test_benchmark_add_proxy::<Test>());
assert_ok!(test_benchmark_remove_proxy::<Test>());
assert_ok!(test_benchmark_remove_proxies::<Test>());
Expand Down
Loading