Skip to content

Commit

Permalink
feat: ✨ added benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Janislav committed Sep 11, 2023
1 parent 6090395 commit cb7fdb8
Show file tree
Hide file tree
Showing 3 changed files with 645 additions and 313 deletions.
7 changes: 7 additions & 0 deletions state-chain/pallets/cf-funding/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,5 +204,12 @@ benchmarks! {
let _ = call.dispatch_bypass_filter(T::EnsureGovernance::try_successful_origin().unwrap());
}

bind_executor_address {
let caller: T::AccountId = whitelisted_caller();
}:_(RawOrigin::Signed(caller.clone()), Default::default())
verify {
assert!(ExecutorAddressBinding::<T>::contains_key(&caller));
}

impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test,);
}
36 changes: 35 additions & 1 deletion state-chain/pallets/cf-funding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ pub mod pallet {
#[pallet::storage]
pub type RedemptionTTLSeconds<T: Config> = StorageValue<_, u64, ValueQuery>;

/// Registered addresses for an executor.
#[pallet::storage]
pub type ExecutorAddressBinding<T: Config> =
StorageMap<_, Blake2_128Concat, AccountId<T>, EthereumAddress, OptionQuery>;

/// List of restricted addresses
#[pallet::storage]
pub type RestrictedAddresses<T: Config> =
Expand Down Expand Up @@ -233,6 +238,9 @@ pub mod pallet {

/// An account has been bound to an address.
BoundRedeemAddress { account_id: AccountId<T>, address: EthereumAddress },

/// An account has been bound to an executor address.
BoundExecutorAddress { account_id: AccountId<T>, address: EthereumAddress },
}

#[pallet::error]
Expand Down Expand Up @@ -288,6 +296,9 @@ pub mod pallet {

/// Stop Bidding is disabled due to Safe Mode.
StopBiddingDisabled,

/// Wrong executor address
InvalidExecutorAddress,
}

#[pallet::call]
Expand Down Expand Up @@ -363,6 +374,13 @@ pub mod pallet {
) -> DispatchResultWithPostInfo {
let account_id = ensure_signed(origin)?;

if let Some(executor_addr) = ExecutorAddressBinding::<T>::get(&account_id) {
ensure!(
executor_addr == executor.unwrap_or_default(),
Error::<T>::InvalidExecutorAddress
);
}

ensure!(T::SafeMode::get().redeem_enabled, Error::<T>::RedeemDisabled);

// Not allowed to redeem if we are an active bidder in the auction phase
Expand Down Expand Up @@ -621,7 +639,7 @@ pub mod pallet {
///
/// - [BadOrigin](frame_support::error::BadOrigin)
#[pallet::call_index(7)]
#[pallet::weight(T::WeightInfo::update_restricted_addresses(addresses_to_add.len() as u32, addresses_to_remove.len() as u32))]
#[pallet::weight(T::WeightInfo::update_restricted_addresses(addresses_to_add.len() as u32, addresses_to_remove.len() as u32, 10 as u32))]
pub fn update_restricted_addresses(
origin: OriginFor<T>,
addresses_to_add: Vec<EthereumAddress>,
Expand Down Expand Up @@ -682,6 +700,22 @@ pub mod pallet {
Self::deposit_event(Event::<T>::RedemptionTaxAmountUpdated { amount });
Ok(())
}

/// Bind executor address.
#[pallet::call_index(10)]
#[pallet::weight(T::WeightInfo::bind_executor_address())]
pub fn bind_executor_address(
origin: OriginFor<T>,
executor_address: EthereumAddress,
) -> DispatchResultWithPostInfo {
let account_id = ensure_signed(origin)?;
ExecutorAddressBinding::<T>::insert(account_id.clone(), executor_address);
Self::deposit_event(Event::BoundExecutorAddress {
account_id,
address: executor_address,
});
Ok(().into())
}
}

#[pallet::genesis_config]
Expand Down
Loading

0 comments on commit cb7fdb8

Please sign in to comment.