Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 12 additions & 5 deletions crates/pallet-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::staking::OperatorStatus;
#[cfg(feature = "runtime-benchmarks")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR #3557 adds a benchmark for the balance transfer check extension. How are you going to merge those changes in this set of benchmarks? Do we need to re-run the script after it merges?

If we're soon going to remove that extension, is it worth having the weights for it in the runtime?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partially answered in https://github.com/autonomys/subspace/pull/3578/files#r2143887125.

If we're soon going to remove that extension, is it worth having the weights for it in the runtime?

Not really removing the extension, I think we just change the enable_transfer from false to true, the extension is still there and we still need to do this check for every extrinsic.

pub use crate::staking::do_register_operator;
use crate::staking_epoch::EpochTransitionResult;
use crate::weights::WeightInfo;
pub use crate::weights::WeightInfo;
#[cfg(not(feature = "std"))]
use alloc::boxed::Box;
use alloc::collections::btree_map::BTreeMap;
Expand Down Expand Up @@ -1528,12 +1528,19 @@ mod pallet {
/// Even if the rest of the withdrawals are out of the unlocking period, the nominator
/// should call this extrinsic to unlock each withdrawal
#[pallet::call_index(10)]
#[pallet::weight(T::WeightInfo::unlock_funds())]
pub fn unlock_funds(origin: OriginFor<T>, operator_id: OperatorId) -> DispatchResult {
#[pallet::weight(T::WeightInfo::unlock_funds(T::WithdrawalLimit::get()))]
pub fn unlock_funds(
origin: OriginFor<T>,
operator_id: OperatorId,
) -> DispatchResultWithPostInfo {
let nominator_id = ensure_signed(origin)?;
do_unlock_funds::<T>(operator_id, nominator_id.clone())
let withdrawal_count = do_unlock_funds::<T>(operator_id, nominator_id.clone())
.map_err(crate::pallet::Error::<T>::from)?;
Ok(())

Ok(Some(T::WeightInfo::unlock_funds(
withdrawal_count.min(T::WithdrawalLimit::get()),
))
.into())
}

/// Unlocks the nominator under given operator given the unlocking period is complete.
Expand Down
9 changes: 7 additions & 2 deletions crates/pallet-domains/src/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1023,10 +1023,12 @@ pub(crate) fn do_withdraw_stake<T: Config>(
}

/// Unlocks any withdraws that are ready to be unlocked.
///
/// Return the number of withdrawals being unlocked
pub(crate) fn do_unlock_funds<T: Config>(
operator_id: OperatorId,
nominator_id: NominatorId<T>,
) -> Result<(), Error> {
) -> Result<u32, Error> {
let operator = Operators::<T>::get(operator_id).ok_or(Error::UnknownOperator)?;
ensure!(
*operator.status::<T>(operator_id) == OperatorStatus::Registered,
Expand All @@ -1049,6 +1051,7 @@ pub(crate) fn do_unlock_funds<T: Config>(

let head_domain_number = HeadDomainNumber::<T>::get(operator.current_domain_id);

let mut withdrawal_count = 0;
let mut total_unlocked_amount = BalanceOf::<T>::zero();
let mut total_storage_fee_refund = BalanceOf::<T>::zero();
loop {
Expand Down Expand Up @@ -1077,6 +1080,8 @@ pub(crate) fn do_unlock_funds<T: Config>(
total_storage_fee_refund = total_storage_fee_refund
.checked_add(&storage_fee_refund)
.ok_or(Error::BalanceOverflow)?;

withdrawal_count += 1;
}

// There is withdrawal but none being processed meaning the first withdrawal's unlock period has
Expand Down Expand Up @@ -1174,7 +1179,7 @@ pub(crate) fn do_unlock_funds<T: Config>(
});
}

Ok(())
Ok(withdrawal_count)
})
}

Expand Down
68 changes: 41 additions & 27 deletions crates/pallet-domains/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub trait WeightInfo {
fn nominate_operator() -> Weight;
fn deregister_operator() -> Weight;
fn withdraw_stake() -> Weight;
fn unlock_funds() -> Weight;
fn unlock_funds(w: u32) -> Weight;
fn unlock_nominator() -> Weight;
fn update_domain_operator_allow_list() -> Weight;
fn transfer_treasury_funds() -> Weight;
Expand Down Expand Up @@ -426,26 +426,33 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// Proof: `Domains::Operators` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Domains::LatestSubmittedER` (r:1 w:0)
/// Proof: `Domains::LatestSubmittedER` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Domains::DomainStakingSummary` (r:1 w:0)
/// Proof: `Domains::DomainStakingSummary` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Domains::Withdrawals` (r:1 w:1)
/// Proof: `Domains::Withdrawals` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Domains::OperatorEpochSharePrice` (r:1 w:0)
/// Proof: `Domains::OperatorEpochSharePrice` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Domains::LatestConfirmedDomainExecutionReceipt` (r:1 w:0)
/// Proof: `Domains::LatestConfirmedDomainExecutionReceipt` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Balances::Holds` (r:1 w:1)
/// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(5550), added: 8025, mode: `MaxEncodedLen`)
/// Storage: `Domains::HeadDomainNumber` (r:1 w:0)
/// Proof: `Domains::HeadDomainNumber` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Domains::DepositOnHold` (r:1 w:1)
/// Proof: `Domains::DepositOnHold` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `System::Account` (r:1 w:1)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// Storage: `Balances::Holds` (r:1 w:1)
/// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`)
/// Storage: `Domains::Deposits` (r:1 w:1)
/// Proof: `Domains::Deposits` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn unlock_funds() -> Weight {
/// The range of component `w` is `[1, 32]`.
fn unlock_funds(w: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `1290`
// Estimated: `9015`
// Minimum execution time: 144_271_000 picoseconds.
Weight::from_parts(147_196_000, 9015)
.saturating_add(T::DbWeight::get().reads(8_u64))
.saturating_add(T::DbWeight::get().writes(4_u64))
// Measured: `1157 + w * (36 ±0)`
// Estimated: `4622 + w * (36 ±0)`
// Minimum execution time: 94_000_000 picoseconds.
Weight::from_parts(86_675_591, 0)
.saturating_add(Weight::from_parts(0, 4622))
// Standard Error: 373_480
.saturating_add(Weight::from_parts(1_180_519, 0).saturating_mul(w.into()))
.saturating_add(T::DbWeight::get().reads(9))
.saturating_add(T::DbWeight::get().writes(5))
.saturating_add(Weight::from_parts(0, 36).saturating_mul(w.into()))
}
/// Storage: `Domains::Operators` (r:1 w:1)
/// Proof: `Domains::Operators` (`max_values`: None, `max_size`: None, mode: `Measured`)
Expand Down Expand Up @@ -1018,26 +1025,33 @@ impl WeightInfo for () {
/// Proof: `Domains::Operators` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Domains::LatestSubmittedER` (r:1 w:0)
/// Proof: `Domains::LatestSubmittedER` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Domains::DomainStakingSummary` (r:1 w:0)
/// Proof: `Domains::DomainStakingSummary` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Domains::Withdrawals` (r:1 w:1)
/// Proof: `Domains::Withdrawals` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Domains::OperatorEpochSharePrice` (r:1 w:0)
/// Proof: `Domains::OperatorEpochSharePrice` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Domains::LatestConfirmedDomainExecutionReceipt` (r:1 w:0)
/// Proof: `Domains::LatestConfirmedDomainExecutionReceipt` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Balances::Holds` (r:1 w:1)
/// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(5550), added: 8025, mode: `MaxEncodedLen`)
/// Storage: `Domains::HeadDomainNumber` (r:1 w:0)
/// Proof: `Domains::HeadDomainNumber` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `Domains::DepositOnHold` (r:1 w:1)
/// Proof: `Domains::DepositOnHold` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `System::Account` (r:1 w:1)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// Storage: `Balances::Holds` (r:1 w:1)
/// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`)
/// Storage: `Domains::Deposits` (r:1 w:1)
/// Proof: `Domains::Deposits` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn unlock_funds() -> Weight {
/// The range of component `w` is `[1, 32]`.
fn unlock_funds(w: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `1290`
// Estimated: `9015`
// Minimum execution time: 144_271_000 picoseconds.
Weight::from_parts(147_196_000, 9015)
.saturating_add(ParityDbWeight::get().reads(8_u64))
.saturating_add(ParityDbWeight::get().writes(4_u64))
// Measured: `1157 + w * (36 ±0)`
// Estimated: `4622 + w * (36 ±0)`
// Minimum execution time: 94_000_000 picoseconds.
Weight::from_parts(86_675_591, 0)
.saturating_add(Weight::from_parts(0, 4622))
// Standard Error: 373_480
.saturating_add(Weight::from_parts(1_180_519, 0).saturating_mul(w.into()))
.saturating_add(ParityDbWeight::get().reads(9))
.saturating_add(ParityDbWeight::get().writes(5))
.saturating_add(Weight::from_parts(0, 36).saturating_mul(w.into()))
}
/// Storage: `Domains::Operators` (r:1 w:1)
/// Proof: `Domains::Operators` (`max_values`: None, `max_size`: None, mode: `Measured`)
Expand Down
1 change: 1 addition & 0 deletions crates/pallet-rewards/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use sp_core::U256;
use sp_runtime::Saturating;
use sp_runtime::traits::{CheckedSub, Zero};
use subspace_runtime_primitives::{BlockNumber, FindBlockRewardAddress, FindVotingRewardAddresses};
pub use weights::WeightInfo;

type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
Expand Down
1 change: 1 addition & 0 deletions crates/pallet-runtime-configs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod benchmarking;
pub mod weights;

pub use pallet::*;
pub use weights::WeightInfo;

#[frame_support::pallet]
mod pallet {
Expand Down
2 changes: 1 addition & 1 deletion crates/pallet-subspace/src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
pub mod benchmarking;
pub mod weights;

use crate::extensions::weights::WeightInfo;
pub use crate::extensions::weights::WeightInfo;
use crate::pallet::Call as SubspaceCall;
use crate::{Config, Origin, Pallet as Subspace};
use frame_support::RuntimeDebugNoBound;
Expand Down
1 change: 1 addition & 0 deletions crates/pallet-subspace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ use subspace_verification::{
PieceCheckParams, VerifySolutionParams, check_reward_signature, derive_next_solution_range,
derive_pot_entropy,
};
pub use weights::WeightInfo;

/// Trigger an era change, if any should take place.
pub trait EraChangeTrigger {
Expand Down
6 changes: 6 additions & 0 deletions crates/subspace-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,22 @@ runtime-benchmarks = [
"frame-system-benchmarking/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-collective/runtime-benchmarks",
"pallet-democracy/runtime-benchmarks",
"pallet-domains/runtime-benchmarks",
"pallet-mmr/runtime-benchmarks",
"pallet-multisig/runtime-benchmarks",
"pallet-messenger/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-rewards/runtime-benchmarks",
"pallet-runtime-configs/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-subspace/runtime-benchmarks",
"pallet-sudo/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-transaction-payment/runtime-benchmarks",
"pallet-transporter/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
"sp-consensus-subspace/runtime-benchmarks",
"sp-messenger/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
Expand Down
12 changes: 12 additions & 0 deletions crates/subspace-runtime/src/fees.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::{Balances, Runtime, RuntimeCall, TransactionFees};
use frame_support::traits::fungible::Inspect;
#[cfg(feature = "runtime-benchmarks")]
use frame_support::traits::fungible::Mutate;
use frame_support::traits::tokens::WithdrawConsequence;
use frame_support::traits::{Currency, ExistenceRequirement, Get, Imbalance, WithdrawReasons};
use pallet_balances::NegativeImbalance;
Expand Down Expand Up @@ -120,4 +122,14 @@ impl pallet_transaction_payment::OnChargeTransaction<Runtime> for OnChargeTransa
_ => Err(InvalidTransaction::Payment.into()),
}
}

#[cfg(feature = "runtime-benchmarks")]
fn endow_account(who: &AccountId, amount: Self::Balance) {
Balances::set_balance(who, amount);
}

#[cfg(feature = "runtime-benchmarks")]
fn minimum_balance() -> Self::Balance {
<Balances as Currency<AccountId>>::minimum_balance()
}
}
Loading
Loading