Skip to content
This repository was archived by the owner on Jun 30, 2023. It is now read-only.

Commit

Permalink
Add call to set trustee proxy address (#94)
Browse files Browse the repository at this point in the history
Co-authored-by: AAweidai <[email protected]>
  • Loading branch information
hacpy and AAweidai authored Apr 18, 2022
1 parent 2228dbb commit 4981f93
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 23 deletions.
4 changes: 2 additions & 2 deletions scripts/generate_weights.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ bench_run() {
rustfmt "$output"
}

bench_run xpallet_gateway_bitcoin ./xpallets/gateway/bitcoin/src/weights.rs
# bench_run xpallet_gateway_bitcoin ./xpallets/gateway/bitcoin/src/weights.rs
bench_run xpallet_gateway_common ./xpallets/gateway/common/src/weights.rs
bench_run xpallet_gateway_records ./xpallets/gateway/records/src/weights.rs
# bench_run xpallet_gateway_records ./xpallets/gateway/records/src/weights.rs
12 changes: 12 additions & 0 deletions xpallets/gateway/common/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,17 @@ benchmarks! {
assert!(Pallet::<T>::trustee_intention_props_of(caller, Chain::Bitcoin).is_some());
}

set_trustee_proxy {
let caller: T::AccountId = alice::<T>();
assert!(Pallet::<T>::trustee_intention_props_of(caller.clone(), Chain::Bitcoin).is_some());
}: _(RawOrigin::Signed(caller.clone()), bob::<T>(), Chain::Bitcoin)
verify {
assert_eq!(
Pallet::<T>::trustee_intention_props_of(caller, Chain::Bitcoin).unwrap().0.proxy_account,
Some(bob::<T>())
);
}

set_trustee_info_config {
let config = TrusteeInfoConfig {
min_trustee_count: 5,
Expand Down Expand Up @@ -257,6 +268,7 @@ mod tests {
assert_ok!(Pallet::<Test>::test_benchmark_withdraw());
assert_ok!(Pallet::<Test>::test_benchmark_cancel_withdrawal());
assert_ok!(Pallet::<Test>::test_benchmark_setup_trustee());
assert_ok!(Pallet::<Test>::test_benchmark_set_trustee_proxy());
assert_ok!(Pallet::<Test>::test_benchmark_set_trustee_info_config());
assert_ok!(Pallet::<Test>::test_benchmark_change_trustee_transition_duration());
assert_ok!(Pallet::<Test>::test_benchmark_set_trustee_admin());
Expand Down
33 changes: 33 additions & 0 deletions xpallets/gateway/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,24 @@ pub mod pallet {
Ok(())
}

/// Set trustee's proxy account
#[pallet::weight(< T as Config >::WeightInfo::set_trustee_proxy())]
pub fn set_trustee_proxy(
origin: OriginFor<T>,
proxy_account: T::AccountId,
chain: Chain,
) -> DispatchResult {
let who = ensure_signed(origin)?;

ensure!(
TrusteeIntentionPropertiesOf::<T>::contains_key(&who, chain),
Error::<T>::NotRegistered
);

Self::set_trustee_proxy_impl(&who, proxy_account, chain);
Ok(())
}

/// Set the config of trustee information.
///
/// This is a root-only operation.
Expand Down Expand Up @@ -450,6 +468,8 @@ pub mod pallet {
Chain,
GenericTrusteeIntentionProps<T::AccountId>,
),
/// A trustee set his proxy account. [who, chain, proxy_account]
SetTrusteeProxy(T::AccountId, Chain, T::AccountId),
/// An account set its referral_account of some chain. [who, chain, referral_account]
ReferralBinded(T::AccountId, Chain, T::AccountId),
/// The trustee set of a chain was changed. [chain, session_number, session_info, script_info]
Expand Down Expand Up @@ -772,6 +792,19 @@ impl<T: Config> Pallet<T> {
Ok(())
}

pub fn set_trustee_proxy_impl(who: &T::AccountId, proxy_account: T::AccountId, chain: Chain) {
TrusteeIntentionPropertiesOf::<T>::mutate(who, chain, |t| {
if let Some(props) = t {
props.0.proxy_account = Some(proxy_account.clone());
}
});
Self::deposit_event(Event::<T>::SetTrusteeProxy(
who.clone(),
chain,
proxy_account,
));
}

pub fn ensure_not_current_trustee(who: &T::AccountId) -> bool {
if let Ok(info) = T::BitcoinTrusteeSessionProvider::current_trustee_session() {
!info.trustee_list.into_iter().any(|n| &n.0 == who)
Expand Down
49 changes: 28 additions & 21 deletions xpallets/gateway/common/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

//! Weights for xpallet_gateway_common
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2022-03-21, STEPS: 50, REPEAT: 20, LOW RANGE: [], HIGH RANGE: []
//! DATE: 2022-04-15, STEPS: 50, REPEAT: 20, LOW RANGE: [], HIGH RANGE: []
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("benchmarks"), DB CACHE: 128
// Executed Command:
Expand Down Expand Up @@ -34,6 +34,7 @@ pub trait WeightInfo {
fn withdraw() -> Weight;
fn cancel_withdrawal() -> Weight;
fn setup_trustee() -> Weight;
fn set_trustee_proxy() -> Weight;
fn set_trustee_info_config() -> Weight;
fn change_trustee_transition_duration() -> Weight;
fn set_trustee_admin() -> Weight;
Expand All @@ -45,36 +46,39 @@ pub trait WeightInfo {
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
fn withdraw() -> Weight {
(105_877_000 as Weight)
(100_827_000 as Weight)
.saturating_add(T::DbWeight::get().reads(8 as Weight))
.saturating_add(T::DbWeight::get().writes(4 as Weight))
}
fn cancel_withdrawal() -> Weight {
(36_626_000 as Weight)
(35_281_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}
fn setup_trustee() -> Weight {
(83_092_000 as Weight)
(81_660_000 as Weight)
.saturating_add(T::DbWeight::get().reads(7 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
fn set_trustee_proxy() -> Weight {
(25_285_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
fn set_trustee_info_config() -> Weight {
(3_875_000 as Weight).saturating_add(T::DbWeight::get().writes(1 as Weight))
(3_454_000 as Weight).saturating_add(T::DbWeight::get().writes(1 as Weight))
}
fn change_trustee_transition_duration() -> Weight {
(2_447_000 as Weight).saturating_add(T::DbWeight::get().writes(1 as Weight))
(2_245_000 as Weight).saturating_add(T::DbWeight::get().writes(1 as Weight))
}
fn set_trustee_admin() -> Weight {
(11_897_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
(3_477_000 as Weight).saturating_add(T::DbWeight::get().writes(1 as Weight))
}
fn set_trustee_admin_multiply() -> Weight {
(2_489_000 as Weight).saturating_add(T::DbWeight::get().writes(1 as Weight))
(2_291_000 as Weight).saturating_add(T::DbWeight::get().writes(1 as Weight))
}
fn claim_trustee_reward() -> Weight {
(167_065_000 as Weight)
(157_754_000 as Weight)
.saturating_add(T::DbWeight::get().reads(7 as Weight))
.saturating_add(T::DbWeight::get().writes(4 as Weight))
}
Expand All @@ -83,36 +87,39 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// For backwards compatibility and tests
impl WeightInfo for () {
fn withdraw() -> Weight {
(105_877_000 as Weight)
(100_827_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(8 as Weight))
.saturating_add(RocksDbWeight::get().writes(4 as Weight))
}
fn cancel_withdrawal() -> Weight {
(36_626_000 as Weight)
(35_281_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
.saturating_add(RocksDbWeight::get().writes(3 as Weight))
}
fn setup_trustee() -> Weight {
(83_092_000 as Weight)
(81_660_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(7 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
fn set_trustee_proxy() -> Weight {
(25_285_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
fn set_trustee_info_config() -> Weight {
(3_875_000 as Weight).saturating_add(RocksDbWeight::get().writes(1 as Weight))
(3_454_000 as Weight).saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
fn change_trustee_transition_duration() -> Weight {
(2_447_000 as Weight).saturating_add(RocksDbWeight::get().writes(1 as Weight))
(2_245_000 as Weight).saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
fn set_trustee_admin() -> Weight {
(11_897_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
(3_477_000 as Weight).saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
fn set_trustee_admin_multiply() -> Weight {
(2_489_000 as Weight).saturating_add(RocksDbWeight::get().writes(1 as Weight))
(2_291_000 as Weight).saturating_add(RocksDbWeight::get().writes(1 as Weight))
}
fn claim_trustee_reward() -> Weight {
(167_065_000 as Weight)
(157_754_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(7 as Weight))
.saturating_add(RocksDbWeight::get().writes(4 as Weight))
}
Expand Down

0 comments on commit 4981f93

Please sign in to comment.