From 80c9dbebf90cdfbbfa233928d5ae3f939bae544c Mon Sep 17 00:00:00 2001 From: Tobi Demeco Date: Thu, 14 Nov 2024 18:04:57 -0300 Subject: [PATCH 1/4] feat: :construction: setup benchmarking of `storage-providers` pallet --- Cargo.lock | 1 + pallets/providers/Cargo.toml | 2 + pallets/providers/src/benchmarking.rs | 590 ++++++++++++++++++++++++++ pallets/providers/src/lib.rs | 5 +- pallets/providers/src/mock.rs | 39 +- pallets/providers/src/utils.rs | 4 - runtime/src/lib.rs | 1 + 7 files changed, 635 insertions(+), 7 deletions(-) create mode 100644 pallets/providers/src/benchmarking.rs diff --git a/Cargo.lock b/Cargo.lock index 5966243a..bec19ead 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7945,6 +7945,7 @@ dependencies = [ "pallet-balances 39.0.0", "pallet-payment-streams", "pallet-proofs-dealer", + "pallet-randomness", "pallet-storage-providers-runtime-api", "parity-scale-codec", "scale-info", diff --git a/pallets/providers/Cargo.toml b/pallets/providers/Cargo.toml index 03374c4e..958912b2 100644 --- a/pallets/providers/Cargo.toml +++ b/pallets/providers/Cargo.toml @@ -20,6 +20,7 @@ scale-info = { workspace = true } # Local pallet-storage-providers-runtime-api = { workspace = true } +pallet-randomness = { workspace = true, optional = true } shp-constants = { workspace = true } shp-traits = { workspace = true, default-features = false } @@ -54,6 +55,7 @@ runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", + "pallet-randomness/runtime-benchmarks", "shp-traits/runtime-benchmarks", "shp-treasury-funding/runtime-benchmarks", "sp-runtime/runtime-benchmarks", diff --git a/pallets/providers/src/benchmarking.rs b/pallets/providers/src/benchmarking.rs new file mode 100644 index 00000000..2f7f713f --- /dev/null +++ b/pallets/providers/src/benchmarking.rs @@ -0,0 +1,590 @@ +//! Benchmarking setup for pallet-storage-providers + +#![cfg(feature = "runtime-benchmarks")] + +use super::*; +use frame_benchmarking::v2::*; + +#[benchmarks(where T: crate::Config + pallet_randomness::Config)] +mod benchmarks { + use frame_support::{ + assert_ok, + traits::{ + fungible::{Inspect, InspectHold, Mutate}, + Get, + }, + BoundedVec, + }; + use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin}; + use sp_runtime::{ + format, + traits::{Hash, One}, + }; + + use super::*; + use crate::{pallet, types::*, Call, Config, Event, Pallet}; + + type BalanceOf = <::NativeBalance as Inspect< + ::AccountId, + >>::Balance; + + fn run_to_block(n: BlockNumberFor) { + assert!( + n > frame_system::Pallet::::block_number(), + "Cannot go back in time" + ); + + while frame_system::Pallet::::block_number() < n { + frame_system::Pallet::::set_block_number( + frame_system::Pallet::::block_number() + One::one(), + ); + } + } + + fn register_provider( + index: u32, + ) -> Result<(T::AccountId, T::ProviderId), BenchmarkError> { + let sp_account: T::AccountId = account("SP", index, 0); + let sp_id_seed = format!("benchmark_sp_{}", index); + let sp_id = <::ProviderIdHashing as Hash>::hash(sp_id_seed.as_bytes()); + let initial_capacity = 1_000_000u32; // 1 TB + let mut multiaddresses: BoundedVec, MaxMultiAddressAmount> = + BoundedVec::new(); + multiaddresses.force_push( + "/ip4/127.0.0.1/udp/1234" + .as_bytes() + .to_vec() + .try_into() + .ok() + .unwrap(), + ); + let sp_balance = match 1_000_000_000_000_000u128.try_into() { + Ok(balance) => balance, + Err(_) => return Err(BenchmarkError::Stop("Balance conversion failed.")), + }; + assert_ok!(::NativeBalance::mint_into( + &sp_account, + sp_balance, + )); + + // Make sure the sp_account is not already in use + if AccountIdToBackupStorageProviderId::::contains_key(&sp_account) { + return Err(BenchmarkError::Stop("Provider account already in use.")); + } + + // Make sure the sp_id is not already in use + if BackupStorageProviders::::contains_key(&sp_id) { + return Err(BenchmarkError::Stop("Provider ID already in use.")); + } + + AccountIdToBackupStorageProviderId::::insert(&sp_account, sp_id); + BackupStorageProviders::::insert( + &sp_id, + BackupStorageProvider { + capacity: initial_capacity.into(), + capacity_used: Default::default(), + multiaddresses, + root: Default::default(), + last_capacity_change: Default::default(), + owner_account: sp_account.clone(), + payment_account: sp_account.clone(), + reputation_weight: ::StartingReputationWeight::get(), + sign_up_block: Default::default(), + }, + ); + + Ok((sp_account, sp_id)) + } + + #[benchmark] + fn request_msp_sign_up() -> Result<(), BenchmarkError> { + /*********** Setup initial conditions: ***********/ + // Set up an account with some balance. + let user_account: T::AccountId = account("Alice", 0, 0); + let user_balance = match 1_000_000_000_000_000u128.try_into() { + Ok(balance) => balance, + Err(_) => return Err(BenchmarkError::Stop("Balance conversion failed.")), + }; + assert_ok!(::NativeBalance::mint_into( + &user_account, + user_balance, + )); + + // Setup the parameters of the MSP to register + let capacity = 100000u32; + let mut multiaddresses: BoundedVec, MaxMultiAddressAmount> = + BoundedVec::new(); + multiaddresses.force_push( + "/ip4/127.0.0.1/udp/1234" + .as_bytes() + .to_vec() + .try_into() + .ok() + .unwrap(), + ); + let value_prop_price_per_unit_of_data_per_block = 1u32; + let commitment: BoundedVec::MaxCommitmentSize> = + vec![1, 2, 3].try_into().unwrap(); + let value_prop_max_data_limit = 100u32; + let payment_account = user_account.clone(); + + /*********** Call the extrinsic to benchmark: ***********/ + #[extrinsic_call] + _( + RawOrigin::Signed(user_account.clone()), + capacity.into(), + multiaddresses.clone(), + value_prop_price_per_unit_of_data_per_block.into(), + commitment, + value_prop_max_data_limit.into(), + payment_account, + ); + + /*********** Post-benchmark checks: ***********/ + // Verify that the event of the MSP requesting to sign up was emitted + let expected_event = + ::RuntimeEvent::from(Event::::MspRequestSignUpSuccess { + who: user_account.clone(), + capacity: capacity.into(), + multiaddresses: multiaddresses.clone(), + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + // Verify that the funds were held from the MSP's account for the provider's deposit + let held_funds = ::NativeBalance::balance_on_hold( + &HoldReason::StorageProviderDeposit.into(), + &user_account, + ); + assert!(held_funds > 0u32.into()); + + // Verify that the request to sign up exists in storage + let msp_sign_up_request = SignUpRequests::::get(user_account); + assert!(msp_sign_up_request.is_some()); + let sign_up_info = msp_sign_up_request.unwrap().sp_sign_up_request; + match sign_up_info { + SignUpRequestSpParams::MainStorageProvider(sign_up_request_params) => { + let msp_info = sign_up_request_params.msp_info; + assert_eq!(msp_info.capacity, capacity.into()); + assert_eq!(msp_info.multiaddresses, multiaddresses); + } + SignUpRequestSpParams::BackupStorageProvider(_) => { + return Err(BenchmarkError::Stop( + "Expected MainStorageProvider sign up request.", + )); + } + } + + Ok(()) + } + + #[benchmark] + fn request_bsp_sign_up() -> Result<(), BenchmarkError> { + /*********** Setup initial conditions: ***********/ + // Set up an account with some balance. + let user_account: T::AccountId = account("Alice", 0, 0); + let user_balance = match 1_000_000_000_000_000u128.try_into() { + Ok(balance) => balance, + Err(_) => return Err(BenchmarkError::Stop("Balance conversion failed.")), + }; + assert_ok!(::NativeBalance::mint_into( + &user_account, + user_balance, + )); + + // Setup the parameters of the BSP to register + let capacity = 100000u32; + let mut multiaddresses: BoundedVec, MaxMultiAddressAmount> = + BoundedVec::new(); + multiaddresses.force_push( + "/ip4/127.0.0.1/udp/1234" + .as_bytes() + .to_vec() + .try_into() + .ok() + .unwrap(), + ); + let payment_account = user_account.clone(); + + /*********** Call the extrinsic to benchmark: ***********/ + #[extrinsic_call] + _( + RawOrigin::Signed(user_account.clone()), + capacity.into(), + multiaddresses.clone(), + payment_account, + ); + + /*********** Post-benchmark checks: ***********/ + // Verify that the event of the BSP requesting to sign up was emitted + let expected_event = + ::RuntimeEvent::from(Event::::BspRequestSignUpSuccess { + who: user_account.clone(), + capacity: capacity.into(), + multiaddresses: multiaddresses.clone(), + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + // Verify that the funds were held from the BSP's account for the provider's deposit + let held_funds = ::NativeBalance::balance_on_hold( + &HoldReason::StorageProviderDeposit.into(), + &user_account, + ); + assert!(held_funds > 0u32.into()); + + // Verify that the request to sign up exists in storage + let bsp_sign_up_request = SignUpRequests::::get(user_account); + assert!(bsp_sign_up_request.is_some()); + let sign_up_info = bsp_sign_up_request.unwrap().sp_sign_up_request; + match sign_up_info { + SignUpRequestSpParams::MainStorageProvider(_) => { + return Err(BenchmarkError::Stop( + "Expected BackupStorageProvider sign up request.", + )); + } + SignUpRequestSpParams::BackupStorageProvider(bsp_info) => { + assert_eq!(bsp_info.capacity, capacity.into()); + assert_eq!(bsp_info.multiaddresses, multiaddresses); + } + } + + Ok(()) + } + + #[benchmark] + fn confirm_sign_up_bsp() -> Result<(), BenchmarkError> { + /*********** Setup initial conditions: ***********/ + // Set up an account with some balance. + let user_account: T::AccountId = account("Alice", 0, 0); + let user_balance = match 1_000_000_000_000_000u128.try_into() { + Ok(balance) => balance, + Err(_) => return Err(BenchmarkError::Stop("Balance conversion failed.")), + }; + assert_ok!(::NativeBalance::mint_into( + &user_account, + user_balance, + )); + + // Setup the parameters of the BSP to register + let capacity = 100000u32; + let mut multiaddresses: BoundedVec, MaxMultiAddressAmount> = + BoundedVec::new(); + multiaddresses.force_push( + "/ip4/127.0.0.1/udp/1234" + .as_bytes() + .to_vec() + .try_into() + .ok() + .unwrap(), + ); + let payment_account = user_account.clone(); + + // Request the sign up of the BSP + Pallet::::request_bsp_sign_up( + RawOrigin::Signed(user_account.clone()).into(), + capacity.into(), + multiaddresses.clone(), + payment_account, + ) + .map_err(|_| BenchmarkError::Stop("Failed to request BSP sign up."))?; + + // Verify that the event of the BSP requesting to sign up was emitted + let expected_event = + ::RuntimeEvent::from(Event::::BspRequestSignUpSuccess { + who: user_account.clone(), + capacity: capacity.into(), + multiaddresses: multiaddresses.clone(), + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + // Advance enough blocks to set up a valid random seed + let random_seed = ::Hashing::hash(b"random_seed"); + run_to_block::(10u32.into()); + pallet_randomness::LatestOneEpochAgoRandomness::::set(Some(( + random_seed, + frame_system::Pallet::::block_number(), + ))); + + /*********** Call the extrinsic to benchmark: ***********/ + #[extrinsic_call] + confirm_sign_up(RawOrigin::Signed(user_account.clone()), None); + + /*********** Post-benchmark checks: ***********/ + // Verify that the event of the sign up confirmation was emitted + let expected_event = + ::RuntimeEvent::from(Event::::BspSignUpSuccess { + who: user_account.clone(), + bsp_id: AccountIdToBackupStorageProviderId::::get(&user_account).unwrap(), + capacity: capacity.into(), + multiaddresses: multiaddresses.clone(), + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + // Verify that the BSP is now in the providers' storage + let bsp_id = AccountIdToBackupStorageProviderId::::get(&user_account).unwrap(); + let bsp = BackupStorageProviders::::get(&bsp_id); + assert!(bsp.is_some()); + + Ok(()) + } + + #[benchmark(extra)] + fn confirm_sign_up_msp() -> Result<(), BenchmarkError> { + /*********** Setup initial conditions: ***********/ + // Set up an account with some balance. + let user_account: T::AccountId = account("Alice", 0, 0); + let user_balance = match 1_000_000_000_000_000u128.try_into() { + Ok(balance) => balance, + Err(_) => return Err(BenchmarkError::Stop("Balance conversion failed.")), + }; + assert_ok!(::NativeBalance::mint_into( + &user_account, + user_balance, + )); + + // Setup the parameters of the MSP to register + let capacity = 100000u32; + let mut multiaddresses: BoundedVec, MaxMultiAddressAmount> = + BoundedVec::new(); + multiaddresses.force_push( + "/ip4/127.0.0.1/udp/1234" + .as_bytes() + .to_vec() + .try_into() + .ok() + .unwrap(), + ); + let value_prop_price_per_unit_of_data_per_block = 1u32; + let commitment: BoundedVec::MaxCommitmentSize> = + vec![1, 2, 3].try_into().unwrap(); + let value_prop_max_data_limit = 100u32; + let payment_account = user_account.clone(); + + // Request the sign up of the MSP + Pallet::::request_msp_sign_up( + RawOrigin::Signed(user_account.clone()).into(), + capacity.into(), + multiaddresses.clone(), + value_prop_price_per_unit_of_data_per_block.into(), + commitment.clone(), + value_prop_max_data_limit.into(), + payment_account, + ) + .map_err(|_| BenchmarkError::Stop("Failed to request MSP sign up."))?; + + // Verify that the event of the MSP requesting to sign up was emitted + let expected_event = + ::RuntimeEvent::from(Event::::MspRequestSignUpSuccess { + who: user_account.clone(), + capacity: 100000u32.into(), + multiaddresses: multiaddresses.clone(), + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + // Advance enough blocks to set up a valid random seed + let random_seed = ::Hashing::hash(b"random_seed"); + run_to_block::(10u32.into()); + pallet_randomness::LatestOneEpochAgoRandomness::::set(Some(( + random_seed, + frame_system::Pallet::::block_number(), + ))); + + /*********** Call the extrinsic to benchmark: ***********/ + #[extrinsic_call] + confirm_sign_up(RawOrigin::Signed(user_account.clone()), None); + + /*********** Post-benchmark checks: ***********/ + // Verify that the event of the sign up confirmation was emitted + let value_prop = ValueProposition::::new( + value_prop_price_per_unit_of_data_per_block.into(), + commitment, + value_prop_max_data_limit.into(), + ); + let value_prop_with_id = ValuePropositionWithId:: { + id: value_prop.derive_id(), + value_prop: value_prop.clone(), + }; + let expected_event = + ::RuntimeEvent::from(Event::::MspSignUpSuccess { + who: user_account.clone(), + msp_id: AccountIdToMainStorageProviderId::::get(&user_account).unwrap(), + capacity: 100000u32.into(), + multiaddresses: multiaddresses.clone(), + value_prop: value_prop_with_id, + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + // Verify that the MSP is now in the providers' storage + let msp_id = AccountIdToMainStorageProviderId::::get(&user_account).unwrap(); + let msp = MainStorageProviders::::get(&msp_id); + assert!(msp.is_some()); + + Ok(()) + } + + #[benchmark] + fn cancel_sign_up() -> Result<(), BenchmarkError> { + /*********** Setup initial conditions: ***********/ + // Set up an account with some balance. + let user_account: T::AccountId = account("Alice", 0, 0); + let user_balance = match 1_000_000_000_000_000u128.try_into() { + Ok(balance) => balance, + Err(_) => return Err(BenchmarkError::Stop("Balance conversion failed.")), + }; + assert_ok!(::NativeBalance::mint_into( + &user_account, + user_balance, + )); + + // Setup the parameters of the BSP to register + let capacity = 100000u32; + let mut multiaddresses: BoundedVec, MaxMultiAddressAmount> = + BoundedVec::new(); + multiaddresses.force_push( + "/ip4/127.0.0.1/udp/1234" + .as_bytes() + .to_vec() + .try_into() + .ok() + .unwrap(), + ); + let payment_account = user_account.clone(); + + // Request the sign up of the BSP + Pallet::::request_bsp_sign_up( + RawOrigin::Signed(user_account.clone()).into(), + capacity.into(), + multiaddresses.clone(), + payment_account, + ) + .map_err(|_| BenchmarkError::Stop("Failed to request BSP sign up."))?; + + // Verify that the event of the BSP requesting to sign up was emitted + let expected_event = + ::RuntimeEvent::from(Event::::BspRequestSignUpSuccess { + who: user_account.clone(), + capacity: capacity.into(), + multiaddresses: multiaddresses.clone(), + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + /*********** Call the extrinsic to benchmark: ***********/ + #[extrinsic_call] + _(RawOrigin::Signed(user_account.clone())); + + /*********** Post-benchmark checks: ***********/ + // Verify that the event of the sign up cancellation was emitted + let expected_event = + ::RuntimeEvent::from(Event::::SignUpRequestCanceled { + who: user_account.clone(), + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + // Verify that the request to sign up was removed from storage + let bsp_sign_up_request = SignUpRequests::::get(user_account.clone()); + assert!(bsp_sign_up_request.is_none()); + + // And that the deposit was returned + let held_funds = ::NativeBalance::balance_on_hold( + &HoldReason::StorageProviderDeposit.into(), + &user_account, + ); + assert_eq!(held_funds, 0u32.into()); + + Ok(()) + } + + #[benchmark] + fn msp_sign_off() -> Result<(), BenchmarkError> { + /*********** Setup initial conditions: ***********/ + // Set up an account with some balance. + let user_account: T::AccountId = account("Alice", 0, 0); + let user_balance = match 1_000_000_000_000_000u128.try_into() { + Ok(balance) => balance, + Err(_) => return Err(BenchmarkError::Stop("Balance conversion failed.")), + }; + assert_ok!(::NativeBalance::mint_into( + &user_account, + user_balance, + )); + + // Setup the parameters of the MSP to register + let capacity = 100000u32; + let mut multiaddresses: BoundedVec, MaxMultiAddressAmount> = + BoundedVec::new(); + multiaddresses.force_push( + "/ip4/127.0.0.1/udp/1234" + .as_bytes() + .to_vec() + .try_into() + .ok() + .unwrap(), + ); + let value_prop_price_per_unit_of_data_per_block = 1u32; + let commitment: BoundedVec::MaxCommitmentSize> = + vec![1, 2, 3].try_into().unwrap(); + let value_prop_max_data_limit = 100u32; + let payment_account = user_account.clone(); + + // Request the sign up of the MSP + Pallet::::request_msp_sign_up( + RawOrigin::Signed(user_account.clone()).into(), + capacity.into(), + multiaddresses.clone(), + value_prop_price_per_unit_of_data_per_block.into(), + commitment.clone(), + value_prop_max_data_limit.into(), + payment_account, + ) + .map_err(|_| BenchmarkError::Stop("Failed to request MSP sign up."))?; + + // Verify that the event of the MSP requesting to sign up was emitted + let expected_event = + ::RuntimeEvent::from(Event::::MspRequestSignUpSuccess { + who: user_account.clone(), + capacity: 100000u32.into(), + multiaddresses: multiaddresses.clone(), + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + // Advance enough blocks to set up a valid random seed + let random_seed = ::Hashing::hash(b"random_seed"); + run_to_block::(10u32.into()); + pallet_randomness::LatestOneEpochAgoRandomness::::set(Some(( + random_seed, + frame_system::Pallet::::block_number(), + ))); + + // Confirm the sign up of the MSP + Pallet::::confirm_sign_up(RawOrigin::Signed(user_account.clone()).into(), None); + + // Verify that the MSP is now in the providers' storage + let msp_id = AccountIdToMainStorageProviderId::::get(&user_account).unwrap(); + let msp = MainStorageProviders::::get(&msp_id); + assert!(msp.is_some()); + + /*********** Call the extrinsic to benchmark: ***********/ + #[extrinsic_call] + _(RawOrigin::Signed(user_account.clone())); + + /*********** Post-benchmark checks: ***********/ + // Verify that the event of the MSP sign off was emitted + let expected_event = + ::RuntimeEvent::from(Event::::MspSignOffSuccess { + who: user_account.clone(), + msp_id, + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + // Verify that the MSP was removed from the providers' storage + let msp = MainStorageProviders::::get(&msp_id); + assert!(msp.is_none()); + + Ok(()) + } + + impl_benchmark_test_suite! { + Pallet, + crate::mock::ExtBuilder::build(), + crate::mock::Test, + } +} diff --git a/pallets/providers/src/lib.rs b/pallets/providers/src/lib.rs index b0a131a1..a68ad1f4 100644 --- a/pallets/providers/src/lib.rs +++ b/pallets/providers/src/lib.rs @@ -10,9 +10,10 @@ pub mod types; mod utils; +// pub mod weights; -// TODO #[cfg(feature = "runtime-benchmarks")] -// TODO mod benchmarking; +#[cfg(feature = "runtime-benchmarks")] +mod benchmarking; #[cfg(test)] mod mock; diff --git a/pallets/providers/src/mock.rs b/pallets/providers/src/mock.rs index d240e325..d11bdfc2 100644 --- a/pallets/providers/src/mock.rs +++ b/pallets/providers/src/mock.rs @@ -9,6 +9,7 @@ use frame_support::{ }; use frame_system::pallet_prelude::BlockNumberFor; use pallet_proofs_dealer::SlashableProviders; +use pallet_randomness::GetBabeData; use shp_file_metadata::FileMetadata; use shp_traits::{ CommitmentVerifier, FileMetadataInterface, MaybeDebug, ProofSubmittersInterface, @@ -17,7 +18,7 @@ use shp_traits::{ use shp_treasury_funding::NoCutTreasuryCutCalculator; use sp_core::{hashing::blake2_256, ConstU128, ConstU32, ConstU64, Get, Hasher, H256}; use sp_runtime::{ - traits::{BlakeTwo256, Convert, IdentityLookup}, + traits::{BlakeTwo256, BlockNumberProvider, Convert, IdentityLookup}, BuildStorage, DispatchError, Perbill, SaturatedConversion, }; use sp_trie::{CompactProof, LayoutV1, MemoryDB, TrieConfiguration, TrieLayout}; @@ -59,6 +60,8 @@ mod test_runtime { pub type ProofsDealer = pallet_proofs_dealer; #[runtime::pallet_index(4)] pub type PaymentStreams = pallet_payment_streams; + #[runtime::pallet_index(5)] + pub type RandomnessPallet = pallet_randomness; } parameter_types! { @@ -119,6 +122,40 @@ impl Get for TreasuryAccount { } } +// Randomness pallet: +pub struct MockRelaychainDataProvider; +impl BlockNumberProvider for MockRelaychainDataProvider { + type BlockNumber = u32; + fn current_block_number() -> Self::BlockNumber { + frame_system::Pallet::::block_number() + .saturating_sub(1) + .try_into() + .unwrap() + } +} + +pub struct BabeDataGetter; +impl GetBabeData for BabeDataGetter { + fn get_epoch_index() -> u64 { + frame_system::Pallet::::block_number() + } + fn get_epoch_randomness() -> H256 { + H256::from_slice(&blake2_256(&Self::get_epoch_index().to_le_bytes())) + } + fn get_parent_randomness() -> H256 { + H256::from_slice(&blake2_256( + &Self::get_epoch_index().saturating_sub(1).to_le_bytes(), + )) + } +} + +impl pallet_randomness::Config for Test { + type RuntimeEvent = RuntimeEvent; + type BabeDataGetter = BabeDataGetter; + type RelayBlockGetter = MockRelaychainDataProvider; + type WeightInfo = (); +} + // Proofs dealer pallet: impl pallet_proofs_dealer::Config for Test { type RuntimeEvent = RuntimeEvent; diff --git a/pallets/providers/src/utils.rs b/pallets/providers/src/utils.rs index d083f45c..5f7a5bf4 100644 --- a/pallets/providers/src/utils.rs +++ b/pallets/providers/src/utils.rs @@ -72,8 +72,6 @@ where pub fn do_request_msp_sign_up( sign_up_request: MainStorageProviderSignUpRequest, ) -> DispatchResult { - // todo!("If this comment is present, it means this function is still incomplete even though it compiles.") - let who = sign_up_request.msp_info.owner_account.clone(); // Check that the user does not have a pending sign up request @@ -153,8 +151,6 @@ where /// This function holds the logic that checks if a user can request to sign up as a Backup Storage Provider /// and, if so, stores the request in the SignUpRequests mapping pub fn do_request_bsp_sign_up(bsp_info: &BackupStorageProvider) -> DispatchResult { - // todo!("If this comment is present, it means this function is still incomplete even though it compiles.") - let who = &bsp_info.owner_account; // Check that the user does not have a pending sign up request diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index bc006c12..51198cfe 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -305,6 +305,7 @@ mod benches { [nfts, Nfts] [pallet_parameters, Parameters] [pallet_proofs_dealer, ProofsDealer] + [pallet_storage_providers, Providers] ); } From 8655d774200669acf7227d9edaae82d1c3f4f1a5 Mon Sep 17 00:00:00 2001 From: Tobi Demeco Date: Fri, 15 Nov 2024 10:37:20 -0300 Subject: [PATCH 2/4] feat: :construction: add more benchmarks to the `storage-providers` pallet --- pallets/providers/src/benchmarking.rs | 777 +++++++++++++++++++++++++- 1 file changed, 776 insertions(+), 1 deletion(-) diff --git a/pallets/providers/src/benchmarking.rs b/pallets/providers/src/benchmarking.rs index 2f7f713f..f6ca30bd 100644 --- a/pallets/providers/src/benchmarking.rs +++ b/pallets/providers/src/benchmarking.rs @@ -18,7 +18,7 @@ mod benchmarks { use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin}; use sp_runtime::{ format, - traits::{Hash, One}, + traits::{Bounded, Hash, One}, }; use super::*; @@ -582,6 +582,781 @@ mod benchmarks { Ok(()) } + #[benchmark] + fn bsp_sign_off() -> Result<(), BenchmarkError> { + /*********** Setup initial conditions: ***********/ + // Set up an account with some balance. + let user_account: T::AccountId = account("Alice", 0, 0); + let user_balance = match 1_000_000_000_000_000u128.try_into() { + Ok(balance) => balance, + Err(_) => return Err(BenchmarkError::Stop("Balance conversion failed.")), + }; + assert_ok!(::NativeBalance::mint_into( + &user_account, + user_balance, + )); + + // Setup the parameters of the BSP to register + let capacity = 100000u32; + let mut multiaddresses: BoundedVec, MaxMultiAddressAmount> = + BoundedVec::new(); + multiaddresses.force_push( + "/ip4/127.0.0.1/udp/1234" + .as_bytes() + .to_vec() + .try_into() + .ok() + .unwrap(), + ); + let payment_account = user_account.clone(); + + // Request the sign up of the BSP + Pallet::::request_bsp_sign_up( + RawOrigin::Signed(user_account.clone()).into(), + capacity.into(), + multiaddresses.clone(), + payment_account, + ) + .map_err(|_| BenchmarkError::Stop("Failed to request BSP sign up."))?; + + // Verify that the event of the BSP requesting to sign up was emitted + let expected_event = + ::RuntimeEvent::from(Event::::BspRequestSignUpSuccess { + who: user_account.clone(), + capacity: capacity.into(), + multiaddresses: multiaddresses.clone(), + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + // Advance enough blocks to set up a valid random seed + let random_seed = ::Hashing::hash(b"random_seed"); + run_to_block::(10u32.into()); + pallet_randomness::LatestOneEpochAgoRandomness::::set(Some(( + random_seed, + frame_system::Pallet::::block_number(), + ))); + + // Confirm the sign up of the BSP + Pallet::::confirm_sign_up(RawOrigin::Signed(user_account.clone()).into(), None); + + // Verify that the BSP is now in the providers' storage + let bsp_id = AccountIdToBackupStorageProviderId::::get(&user_account).unwrap(); + let bsp = BackupStorageProviders::::get(&bsp_id); + assert!(bsp.is_some()); + + // Advance enough blocks to allow the BSP to sign off + run_to_block::( + frame_system::Pallet::::block_number() + + ::BspSignUpLockPeriod::get(), + ); + + /*********** Call the extrinsic to benchmark: ***********/ + #[extrinsic_call] + _(RawOrigin::Signed(user_account.clone())); + + /*********** Post-benchmark checks: ***********/ + // Verify that the event of the BSP sign off was emitted + let expected_event = + ::RuntimeEvent::from(Event::::BspSignOffSuccess { + who: user_account.clone(), + bsp_id, + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + // Verify that the BSP was removed from the providers' storage + let bsp = MainStorageProviders::::get(&bsp_id); + assert!(bsp.is_none()); + + Ok(()) + } + + #[benchmark] + fn change_capacity_bsp_less_deposit() -> Result<(), BenchmarkError> { + /*********** Setup initial conditions: ***********/ + // Set up an account with some balance. + let user_account: T::AccountId = account("Alice", 0, 0); + let user_balance = match 1_000_000_000_000_000u128.try_into() { + Ok(balance) => balance, + Err(_) => return Err(BenchmarkError::Stop("Balance conversion failed.")), + }; + assert_ok!(::NativeBalance::mint_into( + &user_account, + user_balance, + )); + + // Setup the parameters of the BSP to register + let initial_capacity = 100000u32; + let mut multiaddresses: BoundedVec, MaxMultiAddressAmount> = + BoundedVec::new(); + multiaddresses.force_push( + "/ip4/127.0.0.1/udp/1234" + .as_bytes() + .to_vec() + .try_into() + .ok() + .unwrap(), + ); + let payment_account = user_account.clone(); + + // Request the sign up of the BSP + Pallet::::request_bsp_sign_up( + RawOrigin::Signed(user_account.clone()).into(), + initial_capacity.into(), + multiaddresses.clone(), + payment_account, + ) + .map_err(|_| BenchmarkError::Stop("Failed to request BSP sign up."))?; + + // Verify that the event of the BSP requesting to sign up was emitted + let expected_event = + ::RuntimeEvent::from(Event::::BspRequestSignUpSuccess { + who: user_account.clone(), + capacity: initial_capacity.into(), + multiaddresses: multiaddresses.clone(), + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + // Advance enough blocks to set up a valid random seed + let random_seed = ::Hashing::hash(b"random_seed"); + run_to_block::(10u32.into()); + pallet_randomness::LatestOneEpochAgoRandomness::::set(Some(( + random_seed, + frame_system::Pallet::::block_number(), + ))); + + // Confirm the sign up of the BSP + Pallet::::confirm_sign_up(RawOrigin::Signed(user_account.clone()).into(), None); + + // Verify that the BSP is now in the providers' storage + let bsp_id = AccountIdToBackupStorageProviderId::::get(&user_account).unwrap(); + let bsp = BackupStorageProviders::::get(&bsp_id); + assert!(bsp.is_some()); + + // Get the current deposit of the BSP + let initial_deposit = ::NativeBalance::balance_on_hold( + &HoldReason::StorageProviderDeposit.into(), + &user_account, + ); + + // Advance enough blocks to allow the BSP to change its capacity + run_to_block::( + frame_system::Pallet::::block_number() + + ::MinBlocksBetweenCapacityChanges::get(), + ); + + // Make the new capacity less than the previous one so part of the deposit has to be released + let new_capacity = 50000u32; + + /*********** Call the extrinsic to benchmark: ***********/ + #[extrinsic_call] + change_capacity(RawOrigin::Signed(user_account.clone()), new_capacity.into()); + + /*********** Post-benchmark checks: ***********/ + // Verify that the event of the capacity change was emitted + let expected_event = + ::RuntimeEvent::from(Event::::CapacityChanged { + who: user_account.clone(), + provider_id: StorageProviderId::BackupStorageProvider(bsp_id), + old_capacity: initial_capacity.into(), + new_capacity: new_capacity.into(), + next_block_when_change_allowed: frame_system::Pallet::::block_number() + + ::MinBlocksBetweenCapacityChanges::get(), + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + // Verify that the capacity was changed + let bsp = BackupStorageProviders::::get(&bsp_id).unwrap(); + assert_eq!(bsp.capacity, new_capacity.into()); + + // And that part of the deposit was released + let current_deposit = ::NativeBalance::balance_on_hold( + &HoldReason::StorageProviderDeposit.into(), + &user_account, + ); + assert!(current_deposit < initial_deposit); + + Ok(()) + } + + #[benchmark] + fn change_capacity_bsp_more_deposit() -> Result<(), BenchmarkError> { + /*********** Setup initial conditions: ***********/ + // Set up an account with some balance. + let user_account: T::AccountId = account("Alice", 0, 0); + let user_balance = match 1_000_000_000_000_000u128.try_into() { + Ok(balance) => balance, + Err(_) => return Err(BenchmarkError::Stop("Balance conversion failed.")), + }; + assert_ok!(::NativeBalance::mint_into( + &user_account, + user_balance, + )); + + // Setup the parameters of the BSP to register + let initial_capacity = 100000u32; + let mut multiaddresses: BoundedVec, MaxMultiAddressAmount> = + BoundedVec::new(); + multiaddresses.force_push( + "/ip4/127.0.0.1/udp/1234" + .as_bytes() + .to_vec() + .try_into() + .ok() + .unwrap(), + ); + let payment_account = user_account.clone(); + + // Request the sign up of the BSP + Pallet::::request_bsp_sign_up( + RawOrigin::Signed(user_account.clone()).into(), + initial_capacity.into(), + multiaddresses.clone(), + payment_account, + ) + .map_err(|_| BenchmarkError::Stop("Failed to request BSP sign up."))?; + + // Verify that the event of the BSP requesting to sign up was emitted + let expected_event = + ::RuntimeEvent::from(Event::::BspRequestSignUpSuccess { + who: user_account.clone(), + capacity: initial_capacity.into(), + multiaddresses: multiaddresses.clone(), + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + // Advance enough blocks to set up a valid random seed + let random_seed = ::Hashing::hash(b"random_seed"); + run_to_block::(10u32.into()); + pallet_randomness::LatestOneEpochAgoRandomness::::set(Some(( + random_seed, + frame_system::Pallet::::block_number(), + ))); + + // Confirm the sign up of the BSP + Pallet::::confirm_sign_up(RawOrigin::Signed(user_account.clone()).into(), None); + + // Verify that the BSP is now in the providers' storage + let bsp_id = AccountIdToBackupStorageProviderId::::get(&user_account).unwrap(); + let bsp = BackupStorageProviders::::get(&bsp_id); + assert!(bsp.is_some()); + + // Get the current deposit of the BSP + let initial_deposit = ::NativeBalance::balance_on_hold( + &HoldReason::StorageProviderDeposit.into(), + &user_account, + ); + + // Advance enough blocks to allow the BSP to change its capacity + run_to_block::( + frame_system::Pallet::::block_number() + + ::MinBlocksBetweenCapacityChanges::get(), + ); + + // Make the new capacity more than the previous one so funds have to be held + let new_capacity = 150000u32; + + /*********** Call the extrinsic to benchmark: ***********/ + #[extrinsic_call] + change_capacity(RawOrigin::Signed(user_account.clone()), new_capacity.into()); + + /*********** Post-benchmark checks: ***********/ + // Verify that the event of the capacity change was emitted + let expected_event = + ::RuntimeEvent::from(Event::::CapacityChanged { + who: user_account.clone(), + provider_id: StorageProviderId::BackupStorageProvider(bsp_id), + old_capacity: initial_capacity.into(), + new_capacity: new_capacity.into(), + next_block_when_change_allowed: frame_system::Pallet::::block_number() + + ::MinBlocksBetweenCapacityChanges::get(), + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + // Verify that the capacity was changed + let bsp = BackupStorageProviders::::get(&bsp_id).unwrap(); + assert_eq!(bsp.capacity, new_capacity.into()); + + // And that more deposit was held + let current_deposit = ::NativeBalance::balance_on_hold( + &HoldReason::StorageProviderDeposit.into(), + &user_account, + ); + assert!(current_deposit > initial_deposit); + + Ok(()) + } + + #[benchmark] + fn change_capacity_msp_less_deposit() -> Result<(), BenchmarkError> { + /*********** Setup initial conditions: ***********/ + // Set up an account with some balance. + let user_account: T::AccountId = account("Alice", 0, 0); + let user_balance = match 1_000_000_000_000_000u128.try_into() { + Ok(balance) => balance, + Err(_) => return Err(BenchmarkError::Stop("Balance conversion failed.")), + }; + assert_ok!(::NativeBalance::mint_into( + &user_account, + user_balance, + )); + + // Setup the parameters of the MSP to register + let initial_capacity = 100000u32; + let mut multiaddresses: BoundedVec, MaxMultiAddressAmount> = + BoundedVec::new(); + multiaddresses.force_push( + "/ip4/127.0.0.1/udp/1234" + .as_bytes() + .to_vec() + .try_into() + .ok() + .unwrap(), + ); + let value_prop_price_per_unit_of_data_per_block = 1u32; + let commitment: BoundedVec::MaxCommitmentSize> = + vec![1, 2, 3].try_into().unwrap(); + let value_prop_max_data_limit = 100u32; + let payment_account = user_account.clone(); + + // Request the sign up of the MSP + Pallet::::request_msp_sign_up( + RawOrigin::Signed(user_account.clone()).into(), + initial_capacity.into(), + multiaddresses.clone(), + value_prop_price_per_unit_of_data_per_block.into(), + commitment.clone(), + value_prop_max_data_limit.into(), + payment_account, + ) + .map_err(|_| BenchmarkError::Stop("Failed to request MSP sign up."))?; + + // Verify that the event of the MSP requesting to sign up was emitted + let expected_event = + ::RuntimeEvent::from(Event::::MspRequestSignUpSuccess { + who: user_account.clone(), + capacity: initial_capacity.into(), + multiaddresses: multiaddresses.clone(), + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + // Advance enough blocks to set up a valid random seed + let random_seed = ::Hashing::hash(b"random_seed"); + run_to_block::(10u32.into()); + pallet_randomness::LatestOneEpochAgoRandomness::::set(Some(( + random_seed, + frame_system::Pallet::::block_number(), + ))); + + // Confirm the sign up of the MSP + Pallet::::confirm_sign_up(RawOrigin::Signed(user_account.clone()).into(), None); + + // Verify that the MSP is now in the providers' storage + let msp_id = AccountIdToMainStorageProviderId::::get(&user_account).unwrap(); + let msp = MainStorageProviders::::get(&msp_id); + assert!(msp.is_some()); + + // Get the current deposit of the MSP + let initial_deposit = ::NativeBalance::balance_on_hold( + &HoldReason::StorageProviderDeposit.into(), + &user_account, + ); + + // Advance enough blocks to allow the MSP to change its capacity + run_to_block::( + frame_system::Pallet::::block_number() + + ::MinBlocksBetweenCapacityChanges::get(), + ); + + // Make the new capacity less than the previous one so part of the deposit has to be released + let new_capacity = 50000u32; + + /*********** Call the extrinsic to benchmark: ***********/ + #[extrinsic_call] + change_capacity(RawOrigin::Signed(user_account.clone()), new_capacity.into()); + + /*********** Post-benchmark checks: ***********/ + // Verify that the event of the capacity change was emitted + let expected_event = + ::RuntimeEvent::from(Event::::CapacityChanged { + who: user_account.clone(), + provider_id: StorageProviderId::MainStorageProvider(msp_id), + old_capacity: initial_capacity.into(), + new_capacity: new_capacity.into(), + next_block_when_change_allowed: frame_system::Pallet::::block_number() + + ::MinBlocksBetweenCapacityChanges::get(), + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + // Verify that the capacity was changed + let msp = MainStorageProviders::::get(&msp_id).unwrap(); + assert_eq!(msp.capacity, new_capacity.into()); + + // And that part of the deposit was released + let current_deposit = ::NativeBalance::balance_on_hold( + &HoldReason::StorageProviderDeposit.into(), + &user_account, + ); + assert!(current_deposit < initial_deposit); + + Ok(()) + } + + #[benchmark] + fn change_capacity_msp_more_deposit() -> Result<(), BenchmarkError> { + /*********** Setup initial conditions: ***********/ + // Set up an account with some balance. + let user_account: T::AccountId = account("Alice", 0, 0); + let user_balance = match 1_000_000_000_000_000u128.try_into() { + Ok(balance) => balance, + Err(_) => return Err(BenchmarkError::Stop("Balance conversion failed.")), + }; + assert_ok!(::NativeBalance::mint_into( + &user_account, + user_balance, + )); + + // Setup the parameters of the MSP to register + let initial_capacity = 100000u32; + let mut multiaddresses: BoundedVec, MaxMultiAddressAmount> = + BoundedVec::new(); + multiaddresses.force_push( + "/ip4/127.0.0.1/udp/1234" + .as_bytes() + .to_vec() + .try_into() + .ok() + .unwrap(), + ); + let value_prop_price_per_unit_of_data_per_block = 1u32; + let commitment: BoundedVec::MaxCommitmentSize> = + vec![1, 2, 3].try_into().unwrap(); + let value_prop_max_data_limit = 100u32; + let payment_account = user_account.clone(); + + // Request the sign up of the MSP + Pallet::::request_msp_sign_up( + RawOrigin::Signed(user_account.clone()).into(), + initial_capacity.into(), + multiaddresses.clone(), + value_prop_price_per_unit_of_data_per_block.into(), + commitment.clone(), + value_prop_max_data_limit.into(), + payment_account, + ) + .map_err(|_| BenchmarkError::Stop("Failed to request MSP sign up."))?; + + // Verify that the event of the MSP requesting to sign up was emitted + let expected_event = + ::RuntimeEvent::from(Event::::MspRequestSignUpSuccess { + who: user_account.clone(), + capacity: initial_capacity.into(), + multiaddresses: multiaddresses.clone(), + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + // Advance enough blocks to set up a valid random seed + let random_seed = ::Hashing::hash(b"random_seed"); + run_to_block::(10u32.into()); + pallet_randomness::LatestOneEpochAgoRandomness::::set(Some(( + random_seed, + frame_system::Pallet::::block_number(), + ))); + + // Confirm the sign up of the MSP + Pallet::::confirm_sign_up(RawOrigin::Signed(user_account.clone()).into(), None); + + // Verify that the MSP is now in the providers' storage + let msp_id = AccountIdToMainStorageProviderId::::get(&user_account).unwrap(); + let msp = MainStorageProviders::::get(&msp_id); + assert!(msp.is_some()); + + // Get the current deposit of the MSP + let initial_deposit = ::NativeBalance::balance_on_hold( + &HoldReason::StorageProviderDeposit.into(), + &user_account, + ); + + // Advance enough blocks to allow the MSP to change its capacity + run_to_block::( + frame_system::Pallet::::block_number() + + ::MinBlocksBetweenCapacityChanges::get(), + ); + + // Make the new capacity more than the previous one so funds have to be held + let new_capacity = 150000u32; + + /*********** Call the extrinsic to benchmark: ***********/ + #[extrinsic_call] + change_capacity(RawOrigin::Signed(user_account.clone()), new_capacity.into()); + + /*********** Post-benchmark checks: ***********/ + // Verify that the event of the capacity change was emitted + let expected_event = + ::RuntimeEvent::from(Event::::CapacityChanged { + who: user_account.clone(), + provider_id: StorageProviderId::MainStorageProvider(msp_id), + old_capacity: initial_capacity.into(), + new_capacity: new_capacity.into(), + next_block_when_change_allowed: frame_system::Pallet::::block_number() + + ::MinBlocksBetweenCapacityChanges::get(), + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + // Verify that the capacity was changed + let msp = MainStorageProviders::::get(&msp_id).unwrap(); + assert_eq!(msp.capacity, new_capacity.into()); + + // And that more deposit was held + let current_deposit = ::NativeBalance::balance_on_hold( + &HoldReason::StorageProviderDeposit.into(), + &user_account, + ); + assert!(current_deposit > initial_deposit); + + Ok(()) + } + + #[benchmark] + fn add_value_prop() -> Result<(), BenchmarkError> { + /*********** Setup initial conditions: ***********/ + // Set up an account with some balance. + let user_account: T::AccountId = account("Alice", 0, 0); + let user_balance = match 1_000_000_000_000_000u128.try_into() { + Ok(balance) => balance, + Err(_) => return Err(BenchmarkError::Stop("Balance conversion failed.")), + }; + assert_ok!(::NativeBalance::mint_into( + &user_account, + user_balance, + )); + + // Setup the parameters of the MSP to register + let initial_capacity = 100000u32; + let mut multiaddresses: BoundedVec, MaxMultiAddressAmount> = + BoundedVec::new(); + multiaddresses.force_push( + "/ip4/127.0.0.1/udp/1234" + .as_bytes() + .to_vec() + .try_into() + .ok() + .unwrap(), + ); + let value_prop_price_per_unit_of_data_per_block = 1u32; + let commitment: BoundedVec::MaxCommitmentSize> = + vec![1, 2, 3].try_into().unwrap(); + let value_prop_max_data_limit = 100u32; + let payment_account = user_account.clone(); + + // Request the sign up of the MSP + Pallet::::request_msp_sign_up( + RawOrigin::Signed(user_account.clone()).into(), + initial_capacity.into(), + multiaddresses.clone(), + value_prop_price_per_unit_of_data_per_block.into(), + commitment.clone(), + value_prop_max_data_limit.into(), + payment_account, + ) + .map_err(|_| BenchmarkError::Stop("Failed to request MSP sign up."))?; + + // Verify that the event of the MSP requesting to sign up was emitted + let expected_event = + ::RuntimeEvent::from(Event::::MspRequestSignUpSuccess { + who: user_account.clone(), + capacity: initial_capacity.into(), + multiaddresses: multiaddresses.clone(), + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + // Advance enough blocks to set up a valid random seed + let random_seed = ::Hashing::hash(b"random_seed"); + run_to_block::(10u32.into()); + pallet_randomness::LatestOneEpochAgoRandomness::::set(Some(( + random_seed, + frame_system::Pallet::::block_number(), + ))); + + // Confirm the sign up of the MSP + Pallet::::confirm_sign_up(RawOrigin::Signed(user_account.clone()).into(), None); + + // Verify that the MSP is now in the providers' storage + let msp_id = AccountIdToMainStorageProviderId::::get(&user_account).unwrap(); + let msp = MainStorageProviders::::get(&msp_id); + assert!(msp.is_some()); + + // Setup the parameters of the value proposition to add. Since the extrinsic has to derive the ID + // by concatenating and then hashing the encoded parameters, to get the worst case scenario we make + // this parameters as big as possible. + let value_prop_price_per_unit_of_data_per_block = BalanceOf::::max_value(); + let commitment: BoundedVec::MaxCommitmentSize> = vec![ + 1; + ::MaxCommitmentSize::get() + .try_into() + .unwrap() + ] + .try_into() + .unwrap(); + let value_prop_max_data_limit = StorageDataUnit::::max_value(); + + /*********** Call the extrinsic to benchmark: ***********/ + #[extrinsic_call] + _( + RawOrigin::Signed(user_account.clone()), + value_prop_price_per_unit_of_data_per_block.into(), + commitment.clone(), + value_prop_max_data_limit.into(), + ); + + /*********** Post-benchmark checks: ***********/ + // Verify that the event of the value proposition addition was emitted + let value_prop = ValueProposition::::new( + value_prop_price_per_unit_of_data_per_block.into(), + commitment.clone(), + value_prop_max_data_limit.into(), + ); + let value_prop_id = value_prop.derive_id(); + let expected_event = + ::RuntimeEvent::from(Event::::ValuePropAdded { + msp_id, + value_prop_id: value_prop_id.clone(), + value_prop: value_prop.clone(), + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + // Verify that the value proposition was added + let value_prop_in_storage = + MainStorageProviderIdsToValuePropositions::::get(&msp_id, &value_prop_id); + assert!(value_prop_in_storage.is_some()); + assert_eq!(value_prop_in_storage.unwrap(), value_prop); + + Ok(()) + } + + #[benchmark] + fn make_value_prop_unavailable() -> Result<(), BenchmarkError> { + /*********** Setup initial conditions: ***********/ + // Set up an account with some balance. + let user_account: T::AccountId = account("Alice", 0, 0); + let user_balance = match 1_000_000_000_000_000u128.try_into() { + Ok(balance) => balance, + Err(_) => return Err(BenchmarkError::Stop("Balance conversion failed.")), + }; + assert_ok!(::NativeBalance::mint_into( + &user_account, + user_balance, + )); + + // Setup the parameters of the MSP to register + let initial_capacity = 100000u32; + let mut multiaddresses: BoundedVec, MaxMultiAddressAmount> = + BoundedVec::new(); + multiaddresses.force_push( + "/ip4/127.0.0.1/udp/1234" + .as_bytes() + .to_vec() + .try_into() + .ok() + .unwrap(), + ); + let value_prop_price_per_unit_of_data_per_block = 1u32; + let commitment: BoundedVec::MaxCommitmentSize> = + vec![1, 2, 3].try_into().unwrap(); + let value_prop_max_data_limit = 100u32; + let payment_account = user_account.clone(); + + // Request the sign up of the MSP + Pallet::::request_msp_sign_up( + RawOrigin::Signed(user_account.clone()).into(), + initial_capacity.into(), + multiaddresses.clone(), + value_prop_price_per_unit_of_data_per_block.into(), + commitment.clone(), + value_prop_max_data_limit.into(), + payment_account, + ) + .map_err(|_| BenchmarkError::Stop("Failed to request MSP sign up."))?; + + // Verify that the event of the MSP requesting to sign up was emitted + let expected_event = + ::RuntimeEvent::from(Event::::MspRequestSignUpSuccess { + who: user_account.clone(), + capacity: initial_capacity.into(), + multiaddresses: multiaddresses.clone(), + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + // Advance enough blocks to set up a valid random seed + let random_seed = ::Hashing::hash(b"random_seed"); + run_to_block::(10u32.into()); + pallet_randomness::LatestOneEpochAgoRandomness::::set(Some(( + random_seed, + frame_system::Pallet::::block_number(), + ))); + + // Confirm the sign up of the MSP + Pallet::::confirm_sign_up(RawOrigin::Signed(user_account.clone()).into(), None); + + // Verify that the MSP is now in the providers' storage + let msp_id = AccountIdToMainStorageProviderId::::get(&user_account).unwrap(); + let msp = MainStorageProviders::::get(&msp_id); + assert!(msp.is_some()); + + // Setup the parameters of the value proposition to add. + let value_prop_price_per_unit_of_data_per_block = 1u32.into(); + let commitment: BoundedVec::MaxCommitmentSize> = + vec![1, 2, 3].try_into().unwrap(); + let value_prop_max_data_limit = 100u32.into(); + + // Add the value proposition to the MSP + Pallet::::add_value_prop( + RawOrigin::Signed(user_account.clone()).into(), + value_prop_price_per_unit_of_data_per_block.into(), + commitment.clone(), + value_prop_max_data_limit.into(), + ); + + /*********** Post-benchmark checks: ***********/ + // Verify that the event of the value proposition addition was emitted + let value_prop = ValueProposition::::new( + value_prop_price_per_unit_of_data_per_block.into(), + commitment.clone(), + value_prop_max_data_limit.into(), + ); + let value_prop_id = value_prop.derive_id(); + let expected_event = + ::RuntimeEvent::from(Event::::ValuePropAdded { + msp_id, + value_prop_id: value_prop_id.clone(), + value_prop: value_prop.clone(), + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + /*********** Call the extrinsic to benchmark: ***********/ + #[extrinsic_call] + _( + RawOrigin::Signed(user_account.clone()), + value_prop_id.clone(), + ); + + /*********** Post-benchmark checks: ***********/ + // Verify that the event of the value proposition being made unavailable was emitted + let expected_event = + ::RuntimeEvent::from(Event::::ValuePropUnavailable { + msp_id, + value_prop_id: value_prop_id.clone(), + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + // Verify that the value proposition was indeed made unavailable + let value_prop_in_storage = + MainStorageProviderIdsToValuePropositions::::get(&msp_id, &value_prop_id); + assert!(value_prop_in_storage.is_some()); + assert_eq!(value_prop_in_storage.unwrap().available, false); + + Ok(()) + } + impl_benchmark_test_suite! { Pallet, crate::mock::ExtBuilder::build(), From 37af7b331fb07cbd9dd365c9b12b07cda58da972 Mon Sep 17 00:00:00 2001 From: Tobi Demeco Date: Fri, 15 Nov 2024 18:07:19 -0300 Subject: [PATCH 3/4] feat: :sparkles: finish benchmarking `pallet-storage-providers` --- client/forest-manager/Cargo.toml | 2 + pallets/bucket-nfts/src/mock.rs | 1 + pallets/file-system/src/mock.rs | 1 + pallets/payment-streams/src/mock.rs | 1 + pallets/proofs-dealer/src/mock.rs | 1 + pallets/providers/Cargo.toml | 6 +- pallets/providers/src/benchmarking.rs | 686 ++++++++++++++++-- pallets/providers/src/lib.rs | 47 +- pallets/providers/src/mock.rs | 1 + pallets/providers/src/tests.rs | 1 + pallets/providers/src/types.rs | 22 + pallets/providers/src/weights.rs | 763 ++++++++++++++++++++ pallets/randomness/src/lib.rs | 2 +- runtime/src/configs/mod.rs | 1 + xcm-simulator/src/storagehub/configs/mod.rs | 1 + 15 files changed, 1439 insertions(+), 97 deletions(-) create mode 100644 pallets/providers/src/weights.rs diff --git a/client/forest-manager/Cargo.toml b/client/forest-manager/Cargo.toml index a66933c1..9eb983b5 100644 --- a/client/forest-manager/Cargo.toml +++ b/client/forest-manager/Cargo.toml @@ -46,6 +46,8 @@ std = [ "sp-core/std", "sp-runtime/std", "sp-state-machine/std", + "shp-forest-verifier/std", + "shp-traits/std", "sp-trie/std", "shc-common/std", ] diff --git a/pallets/bucket-nfts/src/mock.rs b/pallets/bucket-nfts/src/mock.rs index fdefb118..9cf49d75 100644 --- a/pallets/bucket-nfts/src/mock.rs +++ b/pallets/bucket-nfts/src/mock.rs @@ -346,6 +346,7 @@ impl Get> for DefaultMerkleRoot { impl pallet_storage_providers::Config for Test { type RuntimeEvent = RuntimeEvent; + type WeightInfo = (); type ProvidersRandomness = MockRandomness; type PaymentStreams = PaymentStreams; type FileMetadataManager = FileMetadata< diff --git a/pallets/file-system/src/mock.rs b/pallets/file-system/src/mock.rs index 1c9a144a..70b55eba 100644 --- a/pallets/file-system/src/mock.rs +++ b/pallets/file-system/src/mock.rs @@ -278,6 +278,7 @@ impl Get> for DefaultMerkleRoot { } impl pallet_storage_providers::Config for Test { type RuntimeEvent = RuntimeEvent; + type WeightInfo = (); type ProvidersRandomness = MockRandomness; type PaymentStreams = PaymentStreams; type FileMetadataManager = shp_file_metadata::FileMetadata< diff --git a/pallets/payment-streams/src/mock.rs b/pallets/payment-streams/src/mock.rs index 890873a4..b419f9f9 100644 --- a/pallets/payment-streams/src/mock.rs +++ b/pallets/payment-streams/src/mock.rs @@ -188,6 +188,7 @@ impl Randomness> for MockRandomness { impl pallet_storage_providers::Config for Test { type RuntimeEvent = RuntimeEvent; + type WeightInfo = (); type ProvidersRandomness = MockRandomness; type FileMetadataManager = MockFileMetadataManager; type NativeBalance = Balances; diff --git a/pallets/proofs-dealer/src/mock.rs b/pallets/proofs-dealer/src/mock.rs index 2e40ede7..0fe2f1f6 100644 --- a/pallets/proofs-dealer/src/mock.rs +++ b/pallets/proofs-dealer/src/mock.rs @@ -175,6 +175,7 @@ impl Convert, Balance> for BlockNumberToBalance { // Storage Providers pallet: impl pallet_storage_providers::Config for Test { type RuntimeEvent = RuntimeEvent; + type WeightInfo = (); type ProvidersRandomness = MockRandomness; type PaymentStreams = PaymentStreams; type FileMetadataManager = MockFileMetadataManager; diff --git a/pallets/providers/Cargo.toml b/pallets/providers/Cargo.toml index 958912b2..ab0589f2 100644 --- a/pallets/providers/Cargo.toml +++ b/pallets/providers/Cargo.toml @@ -19,8 +19,9 @@ codec = { workspace = true } scale-info = { workspace = true } # Local -pallet-storage-providers-runtime-api = { workspace = true } +pallet-proofs-dealer = { workspace = true, optional = true } pallet-randomness = { workspace = true, optional = true } +pallet-storage-providers-runtime-api = { workspace = true } shp-constants = { workspace = true } shp-traits = { workspace = true, default-features = false } @@ -39,6 +40,7 @@ serde = { workspace = true } #Local pallet-proofs-dealer = { workspace = true } pallet-payment-streams = { workspace = true } +pallet-randomness = { workspace = true } shp-file-metadata = { workspace = true } shp-treasury-funding = { workspace = true } @@ -56,6 +58,7 @@ runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", "pallet-randomness/runtime-benchmarks", + "pallet-proofs-dealer/runtime-benchmarks", "shp-traits/runtime-benchmarks", "shp-treasury-funding/runtime-benchmarks", "sp-runtime/runtime-benchmarks", @@ -69,6 +72,7 @@ std = [ "pallet-storage-providers-runtime-api/std", "pallet-proofs-dealer/std", "pallet-payment-streams/std", + "pallet-randomness/std", "scale-info/std", "shp-constants/std", "shp-traits/std", diff --git a/pallets/providers/src/benchmarking.rs b/pallets/providers/src/benchmarking.rs index f6ca30bd..4c779bef 100644 --- a/pallets/providers/src/benchmarking.rs +++ b/pallets/providers/src/benchmarking.rs @@ -5,21 +5,23 @@ use super::*; use frame_benchmarking::v2::*; -#[benchmarks(where T: crate::Config + pallet_randomness::Config)] +#[benchmarks(where + T: crate::Config + pallet_randomness::Config + pallet_proofs_dealer::Config, + <::ProvidersPallet as shp_traits::ReadChallengeableProvidersInterface>::ProviderId: From<::ProviderId> +)] mod benchmarks { use frame_support::{ assert_ok, traits::{ fungible::{Inspect, InspectHold, Mutate}, + tokens::Fortitude, Get, }, BoundedVec, }; use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin}; - use sp_runtime::{ - format, - traits::{Bounded, Hash, One}, - }; + use sp_runtime::traits::{Bounded, Hash, Zero}; + use sp_std::vec; use super::*; use crate::{pallet, types::*, Call, Config, Event, Pallet}; @@ -34,71 +36,17 @@ mod benchmarks { "Cannot go back in time" ); - while frame_system::Pallet::::block_number() < n { - frame_system::Pallet::::set_block_number( - frame_system::Pallet::::block_number() + One::one(), - ); - } - } - - fn register_provider( - index: u32, - ) -> Result<(T::AccountId, T::ProviderId), BenchmarkError> { - let sp_account: T::AccountId = account("SP", index, 0); - let sp_id_seed = format!("benchmark_sp_{}", index); - let sp_id = <::ProviderIdHashing as Hash>::hash(sp_id_seed.as_bytes()); - let initial_capacity = 1_000_000u32; // 1 TB - let mut multiaddresses: BoundedVec, MaxMultiAddressAmount> = - BoundedVec::new(); - multiaddresses.force_push( - "/ip4/127.0.0.1/udp/1234" - .as_bytes() - .to_vec() - .try_into() - .ok() - .unwrap(), - ); - let sp_balance = match 1_000_000_000_000_000u128.try_into() { - Ok(balance) => balance, - Err(_) => return Err(BenchmarkError::Stop("Balance conversion failed.")), - }; - assert_ok!(::NativeBalance::mint_into( - &sp_account, - sp_balance, - )); - - // Make sure the sp_account is not already in use - if AccountIdToBackupStorageProviderId::::contains_key(&sp_account) { - return Err(BenchmarkError::Stop("Provider account already in use.")); - } - - // Make sure the sp_id is not already in use - if BackupStorageProviders::::contains_key(&sp_id) { - return Err(BenchmarkError::Stop("Provider ID already in use.")); - } - - AccountIdToBackupStorageProviderId::::insert(&sp_account, sp_id); - BackupStorageProviders::::insert( - &sp_id, - BackupStorageProvider { - capacity: initial_capacity.into(), - capacity_used: Default::default(), - multiaddresses, - root: Default::default(), - last_capacity_change: Default::default(), - owner_account: sp_account.clone(), - payment_account: sp_account.clone(), - reputation_weight: ::StartingReputationWeight::get(), - sign_up_block: Default::default(), - }, - ); - - Ok((sp_account, sp_id)) + frame_system::Pallet::::set_block_number(frame_system::Pallet::::block_number() + n); } #[benchmark] fn request_msp_sign_up() -> Result<(), BenchmarkError> { /*********** Setup initial conditions: ***********/ + // Make sure the block number is not 0 so events can be deposited. + if frame_system::Pallet::::block_number() == Zero::zero() { + run_to_block::(1u32.into()); + } + // Set up an account with some balance. let user_account: T::AccountId = account("Alice", 0, 0); let user_balance = match 1_000_000_000_000_000u128.try_into() { @@ -180,6 +128,11 @@ mod benchmarks { #[benchmark] fn request_bsp_sign_up() -> Result<(), BenchmarkError> { /*********** Setup initial conditions: ***********/ + // Make sure the block number is not 0 so events can be deposited. + if frame_system::Pallet::::block_number() == Zero::zero() { + run_to_block::(1u32.into()); + } + // Set up an account with some balance. let user_account: T::AccountId = account("Alice", 0, 0); let user_balance = match 1_000_000_000_000_000u128.try_into() { @@ -253,6 +206,11 @@ mod benchmarks { #[benchmark] fn confirm_sign_up_bsp() -> Result<(), BenchmarkError> { /*********** Setup initial conditions: ***********/ + // Make sure the block number is not 0 so events can be deposited. + if frame_system::Pallet::::block_number() == Zero::zero() { + run_to_block::(1u32.into()); + } + // Set up an account with some balance. let user_account: T::AccountId = account("Alice", 0, 0); let user_balance = match 1_000_000_000_000_000u128.try_into() { @@ -327,9 +285,14 @@ mod benchmarks { Ok(()) } - #[benchmark(extra)] + #[benchmark] fn confirm_sign_up_msp() -> Result<(), BenchmarkError> { /*********** Setup initial conditions: ***********/ + // Make sure the block number is not 0 so events can be deposited. + if frame_system::Pallet::::block_number() == Zero::zero() { + run_to_block::(1u32.into()); + } + // Set up an account with some balance. let user_account: T::AccountId = account("Alice", 0, 0); let user_balance = match 1_000_000_000_000_000u128.try_into() { @@ -424,6 +387,11 @@ mod benchmarks { #[benchmark] fn cancel_sign_up() -> Result<(), BenchmarkError> { /*********** Setup initial conditions: ***********/ + // Make sure the block number is not 0 so events can be deposited. + if frame_system::Pallet::::block_number() == Zero::zero() { + run_to_block::(1u32.into()); + } + // Set up an account with some balance. let user_account: T::AccountId = account("Alice", 0, 0); let user_balance = match 1_000_000_000_000_000u128.try_into() { @@ -496,6 +464,11 @@ mod benchmarks { #[benchmark] fn msp_sign_off() -> Result<(), BenchmarkError> { /*********** Setup initial conditions: ***********/ + // Make sure the block number is not 0 so events can be deposited. + if frame_system::Pallet::::block_number() == Zero::zero() { + run_to_block::(1u32.into()); + } + // Set up an account with some balance. let user_account: T::AccountId = account("Alice", 0, 0); let user_balance = match 1_000_000_000_000_000u128.try_into() { @@ -555,7 +528,8 @@ mod benchmarks { ))); // Confirm the sign up of the MSP - Pallet::::confirm_sign_up(RawOrigin::Signed(user_account.clone()).into(), None); + Pallet::::confirm_sign_up(RawOrigin::Signed(user_account.clone()).into(), None) + .map_err(|_| BenchmarkError::Stop("Failed to confirm MSP sign up."))?; // Verify that the MSP is now in the providers' storage let msp_id = AccountIdToMainStorageProviderId::::get(&user_account).unwrap(); @@ -585,6 +559,11 @@ mod benchmarks { #[benchmark] fn bsp_sign_off() -> Result<(), BenchmarkError> { /*********** Setup initial conditions: ***********/ + // Make sure the block number is not 0 so events can be deposited. + if frame_system::Pallet::::block_number() == Zero::zero() { + run_to_block::(1u32.into()); + } + // Set up an account with some balance. let user_account: T::AccountId = account("Alice", 0, 0); let user_balance = match 1_000_000_000_000_000u128.try_into() { @@ -637,7 +616,8 @@ mod benchmarks { ))); // Confirm the sign up of the BSP - Pallet::::confirm_sign_up(RawOrigin::Signed(user_account.clone()).into(), None); + Pallet::::confirm_sign_up(RawOrigin::Signed(user_account.clone()).into(), None) + .map_err(|_| BenchmarkError::Stop("Failed to confirm BSP sign up."))?; // Verify that the BSP is now in the providers' storage let bsp_id = AccountIdToBackupStorageProviderId::::get(&user_account).unwrap(); @@ -673,6 +653,11 @@ mod benchmarks { #[benchmark] fn change_capacity_bsp_less_deposit() -> Result<(), BenchmarkError> { /*********** Setup initial conditions: ***********/ + // Make sure the block number is not 0 so events can be deposited. + if frame_system::Pallet::::block_number() == Zero::zero() { + run_to_block::(1u32.into()); + } + // Set up an account with some balance. let user_account: T::AccountId = account("Alice", 0, 0); let user_balance = match 1_000_000_000_000_000u128.try_into() { @@ -725,7 +710,8 @@ mod benchmarks { ))); // Confirm the sign up of the BSP - Pallet::::confirm_sign_up(RawOrigin::Signed(user_account.clone()).into(), None); + Pallet::::confirm_sign_up(RawOrigin::Signed(user_account.clone()).into(), None) + .map_err(|_| BenchmarkError::Stop("Failed to confirm BSP sign up."))?; // Verify that the BSP is now in the providers' storage let bsp_id = AccountIdToBackupStorageProviderId::::get(&user_account).unwrap(); @@ -781,6 +767,11 @@ mod benchmarks { #[benchmark] fn change_capacity_bsp_more_deposit() -> Result<(), BenchmarkError> { /*********** Setup initial conditions: ***********/ + // Make sure the block number is not 0 so events can be deposited. + if frame_system::Pallet::::block_number() == Zero::zero() { + run_to_block::(1u32.into()); + } + // Set up an account with some balance. let user_account: T::AccountId = account("Alice", 0, 0); let user_balance = match 1_000_000_000_000_000u128.try_into() { @@ -833,7 +824,8 @@ mod benchmarks { ))); // Confirm the sign up of the BSP - Pallet::::confirm_sign_up(RawOrigin::Signed(user_account.clone()).into(), None); + Pallet::::confirm_sign_up(RawOrigin::Signed(user_account.clone()).into(), None) + .map_err(|_| BenchmarkError::Stop("Failed to confirm BSP sign up."))?; // Verify that the BSP is now in the providers' storage let bsp_id = AccountIdToBackupStorageProviderId::::get(&user_account).unwrap(); @@ -889,6 +881,11 @@ mod benchmarks { #[benchmark] fn change_capacity_msp_less_deposit() -> Result<(), BenchmarkError> { /*********** Setup initial conditions: ***********/ + // Make sure the block number is not 0 so events can be deposited. + if frame_system::Pallet::::block_number() == Zero::zero() { + run_to_block::(1u32.into()); + } + // Set up an account with some balance. let user_account: T::AccountId = account("Alice", 0, 0); let user_balance = match 1_000_000_000_000_000u128.try_into() { @@ -948,7 +945,8 @@ mod benchmarks { ))); // Confirm the sign up of the MSP - Pallet::::confirm_sign_up(RawOrigin::Signed(user_account.clone()).into(), None); + Pallet::::confirm_sign_up(RawOrigin::Signed(user_account.clone()).into(), None) + .map_err(|_| BenchmarkError::Stop("Failed to confirm MSP sign up."))?; // Verify that the MSP is now in the providers' storage let msp_id = AccountIdToMainStorageProviderId::::get(&user_account).unwrap(); @@ -1004,6 +1002,11 @@ mod benchmarks { #[benchmark] fn change_capacity_msp_more_deposit() -> Result<(), BenchmarkError> { /*********** Setup initial conditions: ***********/ + // Make sure the block number is not 0 so events can be deposited. + if frame_system::Pallet::::block_number() == Zero::zero() { + run_to_block::(1u32.into()); + } + // Set up an account with some balance. let user_account: T::AccountId = account("Alice", 0, 0); let user_balance = match 1_000_000_000_000_000u128.try_into() { @@ -1063,7 +1066,8 @@ mod benchmarks { ))); // Confirm the sign up of the MSP - Pallet::::confirm_sign_up(RawOrigin::Signed(user_account.clone()).into(), None); + Pallet::::confirm_sign_up(RawOrigin::Signed(user_account.clone()).into(), None) + .map_err(|_| BenchmarkError::Stop("Failed to confirm MSP sign up."))?; // Verify that the MSP is now in the providers' storage let msp_id = AccountIdToMainStorageProviderId::::get(&user_account).unwrap(); @@ -1119,6 +1123,11 @@ mod benchmarks { #[benchmark] fn add_value_prop() -> Result<(), BenchmarkError> { /*********** Setup initial conditions: ***********/ + // Make sure the block number is not 0 so events can be deposited. + if frame_system::Pallet::::block_number() == Zero::zero() { + run_to_block::(1u32.into()); + } + // Set up an account with some balance. let user_account: T::AccountId = account("Alice", 0, 0); let user_balance = match 1_000_000_000_000_000u128.try_into() { @@ -1178,7 +1187,8 @@ mod benchmarks { ))); // Confirm the sign up of the MSP - Pallet::::confirm_sign_up(RawOrigin::Signed(user_account.clone()).into(), None); + Pallet::::confirm_sign_up(RawOrigin::Signed(user_account.clone()).into(), None) + .map_err(|_| BenchmarkError::Stop("Failed to confirm MSP sign up."))?; // Verify that the MSP is now in the providers' storage let msp_id = AccountIdToMainStorageProviderId::::get(&user_account).unwrap(); @@ -1236,6 +1246,11 @@ mod benchmarks { #[benchmark] fn make_value_prop_unavailable() -> Result<(), BenchmarkError> { /*********** Setup initial conditions: ***********/ + // Make sure the block number is not 0 so events can be deposited. + if frame_system::Pallet::::block_number() == Zero::zero() { + run_to_block::(1u32.into()); + } + // Set up an account with some balance. let user_account: T::AccountId = account("Alice", 0, 0); let user_balance = match 1_000_000_000_000_000u128.try_into() { @@ -1295,7 +1310,8 @@ mod benchmarks { ))); // Confirm the sign up of the MSP - Pallet::::confirm_sign_up(RawOrigin::Signed(user_account.clone()).into(), None); + Pallet::::confirm_sign_up(RawOrigin::Signed(user_account.clone()).into(), None) + .map_err(|_| BenchmarkError::Stop("Failed to confirm MSP sign up."))?; // Verify that the MSP is now in the providers' storage let msp_id = AccountIdToMainStorageProviderId::::get(&user_account).unwrap(); @@ -1303,10 +1319,10 @@ mod benchmarks { assert!(msp.is_some()); // Setup the parameters of the value proposition to add. - let value_prop_price_per_unit_of_data_per_block = 1u32.into(); + let value_prop_price_per_unit_of_data_per_block: BalanceOf = 1u32.into(); let commitment: BoundedVec::MaxCommitmentSize> = - vec![1, 2, 3].try_into().unwrap(); - let value_prop_max_data_limit = 100u32.into(); + vec![3, 2, 1].try_into().unwrap(); + let value_prop_max_data_limit: T::StorageDataUnit = 100u32.into(); // Add the value proposition to the MSP Pallet::::add_value_prop( @@ -1314,9 +1330,9 @@ mod benchmarks { value_prop_price_per_unit_of_data_per_block.into(), commitment.clone(), value_prop_max_data_limit.into(), - ); + ) + .map_err(|_| BenchmarkError::Stop("Failed to add value proposition."))?; - /*********** Post-benchmark checks: ***********/ // Verify that the event of the value proposition addition was emitted let value_prop = ValueProposition::::new( value_prop_price_per_unit_of_data_per_block.into(), @@ -1357,6 +1373,518 @@ mod benchmarks { Ok(()) } + #[benchmark] + fn add_multiaddress() -> Result<(), BenchmarkError> { + /*********** Setup initial conditions: ***********/ + // Make sure the block number is not 0 so events can be deposited. + if frame_system::Pallet::::block_number() == Zero::zero() { + run_to_block::(1u32.into()); + } + + // Set up an account with some balance. + let user_account: T::AccountId = account("Alice", 0, 0); + let user_balance = match 1_000_000_000_000_000u128.try_into() { + Ok(balance) => balance, + Err(_) => return Err(BenchmarkError::Stop("Balance conversion failed.")), + }; + assert_ok!(::NativeBalance::mint_into( + &user_account, + user_balance, + )); + + // Setup the parameters of the BSP to register + // (we register a BSP since the extrinsic first checks if the account is a MSP, so + // the worst case scenario is for the provider to be a BSP) + let initial_capacity = 100000u32; + let mut multiaddresses: BoundedVec, MaxMultiAddressAmount> = + BoundedVec::new(); + multiaddresses.force_push( + "/ip4/127.0.0.1/udp/1234" + .as_bytes() + .to_vec() + .try_into() + .ok() + .unwrap(), + ); + let payment_account = user_account.clone(); + + // Request the sign up of the BSP + Pallet::::request_bsp_sign_up( + RawOrigin::Signed(user_account.clone()).into(), + initial_capacity.into(), + multiaddresses.clone(), + payment_account, + ) + .map_err(|_| BenchmarkError::Stop("Failed to request BSP sign up."))?; + + // Verify that the event of the BSP requesting to sign up was emitted + let expected_event = + ::RuntimeEvent::from(Event::::BspRequestSignUpSuccess { + who: user_account.clone(), + capacity: initial_capacity.into(), + multiaddresses: multiaddresses.clone(), + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + // Advance enough blocks to set up a valid random seed + let random_seed = ::Hashing::hash(b"random_seed"); + run_to_block::(10u32.into()); + pallet_randomness::LatestOneEpochAgoRandomness::::set(Some(( + random_seed, + frame_system::Pallet::::block_number(), + ))); + + // Confirm the sign up of the BSP + Pallet::::confirm_sign_up(RawOrigin::Signed(user_account.clone()).into(), None) + .map_err(|_| BenchmarkError::Stop("Failed to confirm BSP sign up."))?; + + // Verify that the BSP is now in the providers' storage + let bsp_id = AccountIdToBackupStorageProviderId::::get(&user_account).unwrap(); + let bsp = BackupStorageProviders::::get(&bsp_id); + assert!(bsp.is_some()); + + // Setup the multiaddress to add. The worst case scenario is to make it as big as possible since + // it has to be copied to storage. + let new_multiaddress: MultiAddress = vec![ + 1; + ::MaxMultiAddressSize::get( + ) + .try_into() + .unwrap() + ] + .try_into() + .unwrap(); + + /*********** Call the extrinsic to benchmark: ***********/ + #[extrinsic_call] + _( + RawOrigin::Signed(user_account.clone()), + new_multiaddress.clone(), + ); + + /*********** Post-benchmark checks: ***********/ + // Verify that the event of the added multiaddress was emitted + let expected_event = + ::RuntimeEvent::from(Event::::MultiAddressAdded { + provider_id: bsp_id, + new_multiaddress: new_multiaddress.clone(), + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + // Verify that the multiaddress was added to the BSP + let bsp = BackupStorageProviders::::get(&bsp_id).unwrap(); + assert!(bsp.multiaddresses.contains(&new_multiaddress)); + + Ok(()) + } + + #[benchmark] + fn remove_multiaddress() -> Result<(), BenchmarkError> { + /*********** Setup initial conditions: ***********/ + // Make sure the block number is not 0 so events can be deposited. + if frame_system::Pallet::::block_number() == Zero::zero() { + run_to_block::(1u32.into()); + } + + // Set up an account with some balance. + let user_account: T::AccountId = account("Alice", 0, 0); + let user_balance = match 1_000_000_000_000_000u128.try_into() { + Ok(balance) => balance, + Err(_) => return Err(BenchmarkError::Stop("Balance conversion failed.")), + }; + assert_ok!(::NativeBalance::mint_into( + &user_account, + user_balance, + )); + + // Setup the parameters of the BSP to register + // (we register a BSP since the extrinsic first checks if the account is a MSP, so + // the worst case scenario is for the provider to be a BSP) + let initial_capacity = 100000u32; + let mut multiaddresses: BoundedVec, MaxMultiAddressAmount> = + BoundedVec::new(); + multiaddresses.force_push( + "/ip4/127.0.0.1/udp/1234" + .as_bytes() + .to_vec() + .try_into() + .ok() + .unwrap(), + ); + let payment_account = user_account.clone(); + + // Request the sign up of the BSP + Pallet::::request_bsp_sign_up( + RawOrigin::Signed(user_account.clone()).into(), + initial_capacity.into(), + multiaddresses.clone(), + payment_account, + ) + .map_err(|_| BenchmarkError::Stop("Failed to request BSP sign up."))?; + + // Verify that the event of the BSP requesting to sign up was emitted + let expected_event = + ::RuntimeEvent::from(Event::::BspRequestSignUpSuccess { + who: user_account.clone(), + capacity: initial_capacity.into(), + multiaddresses: multiaddresses.clone(), + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + // Advance enough blocks to set up a valid random seed + let random_seed = ::Hashing::hash(b"random_seed"); + run_to_block::(10u32.into()); + pallet_randomness::LatestOneEpochAgoRandomness::::set(Some(( + random_seed, + frame_system::Pallet::::block_number(), + ))); + + // Confirm the sign up of the BSP + Pallet::::confirm_sign_up(RawOrigin::Signed(user_account.clone()).into(), None) + .map_err(|_| BenchmarkError::Stop("Failed to confirm BSP sign up."))?; + + // Verify that the BSP is now in the providers' storage + let bsp_id = AccountIdToBackupStorageProviderId::::get(&user_account).unwrap(); + let bsp = BackupStorageProviders::::get(&bsp_id); + assert!(bsp.is_some()); + + // Since the extrinsic iterates over all the provider's multiaddresses to find the one to delete, we fill + // the provider with the maximum amount of multiaddresses and try to delete the last one. + for i in 0..::MaxMultiAddressAmount::get() - 1 { + let new_multiaddress: MultiAddress = vec![ + i as u8; + ::MaxMultiAddressSize::get() + .try_into() + .unwrap() + ] + .try_into() + .unwrap(); + Pallet::::add_multiaddress( + RawOrigin::Signed(user_account.clone()).into(), + new_multiaddress.clone(), + ) + .map_err(|_| BenchmarkError::Stop("Failed to add multiaddress."))?; + // Verify that the multiaddress was added to the BSP + let bsp = BackupStorageProviders::::get(&bsp_id).unwrap(); + assert!(bsp.multiaddresses.contains(&new_multiaddress)); + } + + // Setup the multiaddress to remove. + let multiaddress_to_remove: MultiAddress = vec![ + (::MaxMultiAddressAmount::get() - 2) as u8; + ::MaxMultiAddressSize::get() + .try_into() + .unwrap() + ] + .try_into() + .unwrap(); + + // Make sure the multiaddress to remove is present in the provider + let bsp = BackupStorageProviders::::get(&bsp_id).unwrap(); + assert!(bsp.multiaddresses.contains(&multiaddress_to_remove)); + + /*********** Call the extrinsic to benchmark: ***********/ + #[extrinsic_call] + _( + RawOrigin::Signed(user_account.clone()), + multiaddress_to_remove.clone(), + ); + + /*********** Post-benchmark checks: ***********/ + // Verify that the event of removing a multiaddress was emitted + let expected_event = + ::RuntimeEvent::from(Event::::MultiAddressRemoved { + provider_id: bsp_id, + removed_multiaddress: multiaddress_to_remove.clone(), + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + // Verify that the multiaddress is no longer present in the BSP + let bsp = BackupStorageProviders::::get(&bsp_id).unwrap(); + assert!(!bsp.multiaddresses.contains(&multiaddress_to_remove)); + + Ok(()) + } + + #[benchmark] + fn force_msp_sign_up() -> Result<(), BenchmarkError> { + /*********** Setup initial conditions: ***********/ + // Make sure the block number is not 0 so events can be deposited. + if frame_system::Pallet::::block_number() == Zero::zero() { + run_to_block::(1u32.into()); + } + + // Set up an account with some balance. + let user_account: T::AccountId = account("Alice", 0, 0); + let user_balance = match 1_000_000_000_000_000u128.try_into() { + Ok(balance) => balance, + Err(_) => return Err(BenchmarkError::Stop("Balance conversion failed.")), + }; + assert_ok!(::NativeBalance::mint_into( + &user_account, + user_balance, + )); + + // Setup the parameters of the MSP to register + let msp_id_seed = "benchmark_force_msp"; + let msp_id = + <::ProviderIdHashing as Hash>::hash(msp_id_seed.as_bytes()); + let capacity = 100000u32; + let mut multiaddresses: BoundedVec, MaxMultiAddressAmount> = + BoundedVec::new(); + multiaddresses.force_push( + "/ip4/127.0.0.1/udp/1234" + .as_bytes() + .to_vec() + .try_into() + .ok() + .unwrap(), + ); + let value_prop_price_per_unit_of_data_per_block = 1u32; + let commitment: BoundedVec::MaxCommitmentSize> = + vec![1, 2, 3].try_into().unwrap(); + let value_prop_max_data_limit = 100u32; + let payment_account = user_account.clone(); + + /*********** Call the extrinsic to benchmark: ***********/ + #[extrinsic_call] + _( + RawOrigin::Root, + user_account.clone(), + msp_id, + capacity.into(), + multiaddresses.clone(), + value_prop_price_per_unit_of_data_per_block.into(), + commitment.clone(), + value_prop_max_data_limit.into(), + payment_account, + ); + + /*********** Post-benchmark checks: ***********/ + // Verify that the event of the MSP requesting to sign up was emitted + let msp_request_sign_up_event = + ::RuntimeEvent::from(Event::::MspRequestSignUpSuccess { + who: user_account.clone(), + capacity: capacity.into(), + multiaddresses: multiaddresses.clone(), + }); + frame_system::Pallet::::assert_has_event(msp_request_sign_up_event.into()); + + // Verify that the event of the MSP actually signing up was emitted + let msp_sign_up_event = + ::RuntimeEvent::from(Event::::MspSignUpSuccess { + who: user_account.clone(), + msp_id: msp_id, + multiaddresses: multiaddresses.clone(), + capacity: capacity.into(), + value_prop: ValuePropositionWithId::::build( + value_prop_price_per_unit_of_data_per_block.into(), + commitment.clone(), + value_prop_max_data_limit.into(), + ), + }); + frame_system::Pallet::::assert_has_event(msp_sign_up_event.into()); + + // Verify that the MSP is now in the providers' storage + let msp = MainStorageProviders::::get(&msp_id); + assert!(msp.is_some()); + + Ok(()) + } + + #[benchmark] + fn force_bsp_sign_up() -> Result<(), BenchmarkError> { + /*********** Setup initial conditions: ***********/ + // Make sure the block number is not 0 so events can be deposited. + if frame_system::Pallet::::block_number() == Zero::zero() { + run_to_block::(1u32.into()); + } + + // Set up an account with some balance. + let user_account: T::AccountId = account("Alice", 0, 0); + let user_balance = match 1_000_000_000_000_000u128.try_into() { + Ok(balance) => balance, + Err(_) => return Err(BenchmarkError::Stop("Balance conversion failed.")), + }; + assert_ok!(::NativeBalance::mint_into( + &user_account, + user_balance, + )); + + // Setup the parameters of the BSP to register + let bsp_seed = "benchmark_force_bsp"; + let bsp_id = <::ProviderIdHashing as Hash>::hash(bsp_seed.as_bytes()); + let capacity = 100000u32; + let mut multiaddresses: BoundedVec, MaxMultiAddressAmount> = + BoundedVec::new(); + multiaddresses.force_push( + "/ip4/127.0.0.1/udp/1234" + .as_bytes() + .to_vec() + .try_into() + .ok() + .unwrap(), + ); + let payment_account = user_account.clone(); + + /*********** Call the extrinsic to benchmark: ***********/ + #[extrinsic_call] + _( + RawOrigin::Root, + user_account.clone(), + bsp_id, + capacity.into(), + multiaddresses.clone(), + payment_account, + None, + ); + + /*********** Post-benchmark checks: ***********/ + // Verify that the event of the BSP requesting to sign up was emitted + let bsp_request_sign_up_event = + ::RuntimeEvent::from(Event::::BspRequestSignUpSuccess { + who: user_account.clone(), + capacity: capacity.into(), + multiaddresses: multiaddresses.clone(), + }); + frame_system::Pallet::::assert_has_event(bsp_request_sign_up_event.into()); + + // Verify that the event of the BSP actually signing up was emitted + let bsp_sign_up_event = + ::RuntimeEvent::from(Event::::BspSignUpSuccess { + who: user_account.clone(), + bsp_id: bsp_id, + multiaddresses: multiaddresses.clone(), + capacity: capacity.into(), + }); + frame_system::Pallet::::assert_has_event(bsp_sign_up_event.into()); + + // Verify that the BSP is now in the providers' storage + let bsp = BackupStorageProviders::::get(&bsp_id); + assert!(bsp.is_some()); + + Ok(()) + } + + #[benchmark] + fn slash() -> Result<(), BenchmarkError> { + // TODO: once provider sign off is implemented for providers that run out of stake, + // add a benchmark to check which is the worst case scenario for this extrinsic + use pallet_proofs_dealer::types::ProviderIdFor as ProofsDealerProviderIdFor; + /*********** Setup initial conditions: ***********/ + // Make sure the block number is not 0 so events can be deposited. + if frame_system::Pallet::::block_number() == Zero::zero() { + run_to_block::(1u32.into()); + } + + // Set up an account with some balance. + let user_account: T::AccountId = account("Alice", 0, 0); + let user_balance = match 1_000_000_000_000_000u128.try_into() { + Ok(balance) => balance, + Err(_) => return Err(BenchmarkError::Stop("Balance conversion failed.")), + }; + assert_ok!(::NativeBalance::mint_into( + &user_account, + user_balance, + )); + + // Setup the parameters of the BSP to register + // (we register a BSP since the extrinsic first checks if the account is a MSP, so + // the worst case scenario is for the provider to be a BSP) + let initial_capacity = 100000u32; + let mut multiaddresses: BoundedVec, MaxMultiAddressAmount> = + BoundedVec::new(); + multiaddresses.force_push( + "/ip4/127.0.0.1/udp/1234" + .as_bytes() + .to_vec() + .try_into() + .ok() + .unwrap(), + ); + let payment_account = user_account.clone(); + + // Request the sign up of the BSP + Pallet::::request_bsp_sign_up( + RawOrigin::Signed(user_account.clone()).into(), + initial_capacity.into(), + multiaddresses.clone(), + payment_account, + ) + .map_err(|_| BenchmarkError::Stop("Failed to request BSP sign up."))?; + + // Verify that the event of the BSP requesting to sign up was emitted + let expected_event = + ::RuntimeEvent::from(Event::::BspRequestSignUpSuccess { + who: user_account.clone(), + capacity: initial_capacity.into(), + multiaddresses: multiaddresses.clone(), + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + // Advance enough blocks to set up a valid random seed + let random_seed = ::Hashing::hash(b"random_seed"); + run_to_block::(10u32.into()); + pallet_randomness::LatestOneEpochAgoRandomness::::set(Some(( + random_seed, + frame_system::Pallet::::block_number(), + ))); + + // Confirm the sign up of the BSP + Pallet::::confirm_sign_up(RawOrigin::Signed(user_account.clone()).into(), None) + .map_err(|_| BenchmarkError::Stop("Failed to confirm BSP sign up."))?; + + // Verify that the BSP is now in the providers' storage + let bsp_id = AccountIdToBackupStorageProviderId::::get(&user_account).unwrap(); + let bsp = BackupStorageProviders::::get(&bsp_id); + assert!(bsp.is_some()); + + // Accrue failed proof submissions for this provider + let bsp_id_as_pd: ProofsDealerProviderIdFor = bsp_id.into(); + pallet_proofs_dealer::SlashableProviders::::insert(bsp_id_as_pd, 3); + + // Get the amount to be slashed + let amount_to_slash = Pallet::::compute_worst_case_scenario_slashable_amount(&bsp_id) + .map_err(|_| { + BenchmarkError::Stop("Failed to compute worst case scenario slashable amount.") + })?; + + // The amount slashed will be the minimum between the amount to slash and the available + // funds to slash of the provider + let provider_stake = ::NativeBalance::balance_on_hold( + &HoldReason::StorageProviderDeposit.into(), + &user_account, + ); + let liquid_held_provider_funds = + ::NativeBalance::reducible_total_balance_on_hold( + &user_account, + Fortitude::Polite, + ); + let amount_to_slash = amount_to_slash + .min(provider_stake) + .min(liquid_held_provider_funds); + assert!(amount_to_slash <= provider_stake); + + /*********** Call the extrinsic to benchmark: ***********/ + #[extrinsic_call] + _(RawOrigin::Signed(user_account.clone()), bsp_id); + + /*********** Post-benchmark checks: ***********/ + // Verify that the event of the provider being slashed was emitted + let expected_event = ::RuntimeEvent::from(Event::::Slashed { + provider_id: bsp_id, + amount_slashed: amount_to_slash, + }); + frame_system::Pallet::::assert_last_event(expected_event.into()); + + // Verify that the accrued failed proof submissions have been cleared + let accrued_failed_proofs = + pallet_proofs_dealer::SlashableProviders::::get(bsp_id_as_pd); + assert!(accrued_failed_proofs.is_none()); + + Ok(()) + } + impl_benchmark_test_suite! { Pallet, crate::mock::ExtBuilder::build(), diff --git a/pallets/providers/src/lib.rs b/pallets/providers/src/lib.rs index 7d1ec7dd..e5b6a926 100644 --- a/pallets/providers/src/lib.rs +++ b/pallets/providers/src/lib.rs @@ -10,7 +10,7 @@ pub mod types; mod utils; -// pub mod weights; +pub mod weights; #[cfg(feature = "runtime-benchmarks")] mod benchmarking; @@ -30,7 +30,7 @@ use types::{ #[frame_support::pallet] pub mod pallet { - use super::types::*; + use super::{types::*, weights::WeightInfo}; use codec::{FullCodec, HasCompact}; use frame_support::traits::Randomness; use frame_support::{ @@ -54,6 +54,9 @@ pub mod pallet { /// Because this pallet emits events, it depends on the runtime's definition of an event. type RuntimeEvent: From> + IsType<::RuntimeEvent>; + /// Weight information for extrinsics in this pallet. + type WeightInfo: crate::weights::WeightInfo; + /// Type to access randomness to salt AccountIds and get the corresponding ProviderId type ProvidersRandomness: Randomness, BlockNumberFor>; @@ -681,7 +684,7 @@ pub mod pallet { /// /// Emits `MspRequestSignUpSuccess` event when successful. #[pallet::call_index(0)] - #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] + #[pallet::weight(T::WeightInfo::request_msp_sign_up())] pub fn request_msp_sign_up( origin: OriginFor, capacity: StorageDataUnit, @@ -750,7 +753,7 @@ pub mod pallet { /// /// Emits `BspRequestSignUpSuccess` event when successful. #[pallet::call_index(1)] - #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] + #[pallet::weight(T::WeightInfo::request_bsp_sign_up())] pub fn request_bsp_sign_up( origin: OriginFor, capacity: StorageDataUnit, @@ -811,7 +814,10 @@ pub mod pallet { /// - The deposit that the user has to pay to register as a SP is held when the user requests to register as a SP /// - If this extrinsic is successful, it will be free for the caller, to incentive state debloating #[pallet::call_index(2)] - #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] + #[pallet::weight({ + T::WeightInfo::confirm_sign_up_bsp() + //.max(T::WeightInfo::confirm_sign_up_msp()) + })] pub fn confirm_sign_up( origin: OriginFor, provider_account: Option, @@ -843,7 +849,7 @@ pub mod pallet { /// /// Emits `SignUpRequestCanceled` event when successful. #[pallet::call_index(3)] - #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] + #[pallet::weight(T::WeightInfo::cancel_sign_up())] pub fn cancel_sign_up(origin: OriginFor) -> DispatchResultWithPostInfo { // Check that the extrinsic was signed and get the signer. let who = ensure_signed(origin)?; @@ -872,7 +878,7 @@ pub mod pallet { /// /// Emits `MspSignOffSuccess` event when successful. #[pallet::call_index(4)] - #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] + #[pallet::weight(T::WeightInfo::msp_sign_off())] pub fn msp_sign_off(origin: OriginFor) -> DispatchResultWithPostInfo { // Check that the extrinsic was signed and get the signer. let who = ensure_signed(origin)?; @@ -903,7 +909,7 @@ pub mod pallet { /// /// Emits `BspSignOffSuccess` event when successful. #[pallet::call_index(5)] - #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] + #[pallet::weight(T::WeightInfo::bsp_sign_off())] pub fn bsp_sign_off(origin: OriginFor) -> DispatchResultWithPostInfo { // Check that the extrinsic was signed and get the signer. let who = ensure_signed(origin)?; @@ -943,7 +949,16 @@ pub mod pallet { /// /// Emits `CapacityChanged` event when successful. #[pallet::call_index(6)] - #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] + #[pallet::weight({ + let weight_msp_less_deposit = T::WeightInfo::change_capacity_msp_less_deposit(); + let weight_msp_more_deposit = T::WeightInfo::change_capacity_msp_more_deposit(); + let weight_bsp_less_deposit = T::WeightInfo::change_capacity_bsp_less_deposit(); + let weight_bsp_more_deposit = T::WeightInfo::change_capacity_bsp_more_deposit(); + weight_msp_less_deposit + .max(weight_msp_more_deposit) + .max(weight_bsp_less_deposit) + .max(weight_bsp_more_deposit) + })] pub fn change_capacity( origin: OriginFor, new_capacity: StorageDataUnit, @@ -975,7 +990,7 @@ pub mod pallet { /// /// Emits `ValuePropAdded` event when successful. #[pallet::call_index(7)] - #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] + #[pallet::weight(T::WeightInfo::add_value_prop())] pub fn add_value_prop( origin: OriginFor, price_per_unit_of_data_per_block: BalanceOf, @@ -1008,7 +1023,7 @@ pub mod pallet { /// This operation cannot be reversed. You can only add new value propositions. /// This will not affect existing buckets which are using this value proposition. #[pallet::call_index(8)] - #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] + #[pallet::weight(T::WeightInfo::make_value_prop_unavailable())] pub fn make_value_prop_unavailable( origin: OriginFor, value_prop_id: ValuePropIdFor, @@ -1045,7 +1060,7 @@ pub mod pallet { /// /// Emits `MultiAddressAdded` event when successful. #[pallet::call_index(9)] - #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] + #[pallet::weight(T::WeightInfo::add_multiaddress())] pub fn add_multiaddress( origin: OriginFor, new_multiaddress: MultiAddress, @@ -1082,7 +1097,7 @@ pub mod pallet { /// /// Emits `MultiAddressRemoved` event when successful. #[pallet::call_index(10)] - #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] + #[pallet::weight(T::WeightInfo::remove_multiaddress())] pub fn remove_multiaddress( origin: OriginFor, multiaddress: MultiAddress, @@ -1126,7 +1141,7 @@ pub mod pallet { /// /// Emits `MspRequestSignUpSuccess` and `MspSignUpSuccess` events when successful. #[pallet::call_index(11)] - #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] + #[pallet::weight(T::WeightInfo::force_msp_sign_up())] pub fn force_msp_sign_up( origin: OriginFor, who: T::AccountId, @@ -1203,7 +1218,7 @@ pub mod pallet { /// /// Emits `BspRequestSignUpSuccess` and `BspSignUpSuccess` events when successful. #[pallet::call_index(12)] - #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] + #[pallet::weight(T::WeightInfo::force_bsp_sign_up())] pub fn force_bsp_sign_up( origin: OriginFor, who: T::AccountId, @@ -1256,7 +1271,7 @@ pub mod pallet { /// A Storage Provider is _slashable_ iff it has failed to respond to challenges for providing proofs of storage. /// In the context of the StorageHub protocol, the proofs-dealer pallet marks a Storage Provider as _slashable_ when it fails to respond to challenges. #[pallet::call_index(13)] - #[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))] + #[pallet::weight(T::WeightInfo::slash())] pub fn slash( origin: OriginFor, provider_id: ProviderIdFor, diff --git a/pallets/providers/src/mock.rs b/pallets/providers/src/mock.rs index 3a2de206..6e7c1b8b 100644 --- a/pallets/providers/src/mock.rs +++ b/pallets/providers/src/mock.rs @@ -295,6 +295,7 @@ impl Convert, Balance> for BlockNumberToBalance { // Storage providers pallet: impl crate::Config for Test { type RuntimeEvent = RuntimeEvent; + type WeightInfo = (); type ProvidersRandomness = MockRandomness; type NativeBalance = Balances; type RuntimeHoldReason = RuntimeHoldReason; diff --git a/pallets/providers/src/tests.rs b/pallets/providers/src/tests.rs index b1a7a366..2dadd28a 100644 --- a/pallets/providers/src/tests.rs +++ b/pallets/providers/src/tests.rs @@ -5707,6 +5707,7 @@ fn run_to_block(n: u64) { assert!(n > System::block_number(), "Cannot go back in time"); while System::block_number() < n { + pallet_randomness::InherentIncluded::::put(()); AllPalletsWithSystem::on_finalize(System::block_number()); System::set_block_number(System::block_number() + 1); AllPalletsWithSystem::on_initialize(System::block_number()); diff --git a/pallets/providers/src/types.rs b/pallets/providers/src/types.rs index 94d36d3a..3d4e723a 100644 --- a/pallets/providers/src/types.rs +++ b/pallets/providers/src/types.rs @@ -17,6 +17,28 @@ pub struct ValuePropositionWithId { pub value_prop: ValueProposition, } +impl ValuePropositionWithId { + pub fn new(id: ValuePropIdFor, value_prop: ValueProposition) -> Self { + Self { id, value_prop } + } + + pub fn build( + price_per_unit_of_data_per_block: BalanceOf, + commitment: Commitment, + bucket_data_limit: StorageDataUnit, + ) -> Self { + let value_prop = ValueProposition::::new( + price_per_unit_of_data_per_block, + commitment, + bucket_data_limit, + ); + Self { + id: value_prop.derive_id(), + value_prop, + } + } +} + #[derive(Encode, Decode, MaxEncodedLen, TypeInfo, RuntimeDebugNoBound, PartialEq, Eq, Clone)] #[scale_info(skip_type_params(T))] pub struct ValueProposition { diff --git a/pallets/providers/src/weights.rs b/pallets/providers/src/weights.rs new file mode 100644 index 00000000..51b761d5 --- /dev/null +++ b/pallets/providers/src/weights.rs @@ -0,0 +1,763 @@ + +//! Autogenerated weights for `pallet_storage_providers` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 43.0.0 +//! DATE: 2024-11-15, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `Tobi-G14`, CPU: `AMD Ryzen 9 7940HS w/ Radeon 780M Graphics` +//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: `1024` + +// Executed Command: +// frame-omni-bencher +// v1 +// benchmark +// pallet +// --runtime +// target/production/wbuild/storage-hub-runtime/storage_hub_runtime.wasm +// --pallet +// pallet_storage_providers +// --extrinsic +// +// --output +// pallets/providers/src/weights.rs +// --template +// ../../personal/polkadot/polkadot-sdk/substrate/.maintain/frame-weight-template.hbs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use core::marker::PhantomData; + +/// Weight functions needed for `pallet_storage_providers`. +pub trait WeightInfo { + fn request_msp_sign_up() -> Weight; + fn request_bsp_sign_up() -> Weight; + fn confirm_sign_up_bsp() -> Weight; + fn confirm_sign_up_msp() -> Weight; + fn cancel_sign_up() -> Weight; + fn msp_sign_off() -> Weight; + fn bsp_sign_off() -> Weight; + fn change_capacity_bsp_less_deposit() -> Weight; + fn change_capacity_bsp_more_deposit() -> Weight; + fn change_capacity_msp_less_deposit() -> Weight; + fn change_capacity_msp_more_deposit() -> Weight; + fn add_value_prop() -> Weight; + fn make_value_prop_unavailable() -> Weight; + fn add_multiaddress() -> Weight; + fn remove_multiaddress() -> Weight; + fn force_msp_sign_up() -> Weight; + fn force_bsp_sign_up() -> Weight; + fn slash() -> Weight; +} + +/// Weights for `pallet_storage_providers` using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +impl WeightInfo for SubstrateWeight { + /// Storage: `Providers::SignUpRequests` (r:1 w:1) + /// Proof: `Providers::SignUpRequests` (`max_values`: None, `max_size`: Some(1679), added: 4154, mode: `MaxEncodedLen`) + /// Storage: `Providers::AccountIdToMainStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToMainStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::AccountIdToBackupStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToBackupStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// 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(175), added: 2650, mode: `MaxEncodedLen`) + fn request_msp_sign_up() -> Weight { + // Proof Size summary in bytes: + // Measured: `216` + // Estimated: `5144` + // Minimum execution time: 61_059_000 picoseconds. + Weight::from_parts(62_537_000, 5144) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `Providers::SignUpRequests` (r:1 w:1) + /// Proof: `Providers::SignUpRequests` (`max_values`: None, `max_size`: Some(1679), added: 4154, mode: `MaxEncodedLen`) + /// Storage: `Providers::AccountIdToMainStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToMainStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::AccountIdToBackupStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToBackupStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// 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(175), added: 2650, mode: `MaxEncodedLen`) + fn request_bsp_sign_up() -> Weight { + // Proof Size summary in bytes: + // Measured: `216` + // Estimated: `5144` + // Minimum execution time: 66_729_000 picoseconds. + Weight::from_parts(67_999_000, 5144) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `Providers::SignUpRequests` (r:1 w:1) + /// Proof: `Providers::SignUpRequests` (`max_values`: None, `max_size`: Some(1679), added: 4154, mode: `MaxEncodedLen`) + /// Storage: `Randomness::LatestOneEpochAgoRandomness` (r:1 w:0) + /// Proof: `Randomness::LatestOneEpochAgoRandomness` (`max_values`: Some(1), `max_size`: Some(36), added: 531, mode: `MaxEncodedLen`) + /// Storage: `Providers::TotalBspsCapacity` (r:1 w:1) + /// Proof: `Providers::TotalBspsCapacity` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `Providers::BspCount` (r:1 w:1) + /// Proof: `Providers::BspCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Providers::GlobalBspsReputationWeight` (r:1 w:1) + /// Proof: `Providers::GlobalBspsReputationWeight` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Providers::AccountIdToBackupStorageProviderId` (r:0 w:1) + /// Proof: `Providers::AccountIdToBackupStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::BackupStorageProviders` (r:0 w:1) + /// Proof: `Providers::BackupStorageProviders` (`max_values`: None, `max_size`: Some(683), added: 3158, mode: `MaxEncodedLen`) + fn confirm_sign_up_bsp() -> Weight { + // Proof Size summary in bytes: + // Measured: `411` + // Estimated: `5144` + // Minimum execution time: 27_060_000 picoseconds. + Weight::from_parts(28_984_000, 5144) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + /// Storage: `Providers::SignUpRequests` (r:1 w:1) + /// Proof: `Providers::SignUpRequests` (`max_values`: None, `max_size`: Some(1679), added: 4154, mode: `MaxEncodedLen`) + /// Storage: `Randomness::LatestOneEpochAgoRandomness` (r:1 w:0) + /// Proof: `Randomness::LatestOneEpochAgoRandomness` (`max_values`: Some(1), `max_size`: Some(36), added: 531, mode: `MaxEncodedLen`) + /// Storage: `Providers::MainStorageProviderIdsToValuePropositions` (r:1 w:1) + /// Proof: `Providers::MainStorageProviderIdsToValuePropositions` (`max_values`: None, `max_size`: Some(1123), added: 3598, mode: `MaxEncodedLen`) + /// Storage: `Providers::MspCount` (r:1 w:1) + /// Proof: `Providers::MspCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Providers::AccountIdToMainStorageProviderId` (r:0 w:1) + /// Proof: `Providers::AccountIdToMainStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::MainStorageProviders` (r:0 w:1) + /// Proof: `Providers::MainStorageProviders` (`max_values`: None, `max_size`: Some(647), added: 3122, mode: `MaxEncodedLen`) + /// Storage: `PaymentStreams::PrivilegedProviders` (r:0 w:1) + /// Proof: `PaymentStreams::PrivilegedProviders` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + fn confirm_sign_up_msp() -> Weight { + // Proof Size summary in bytes: + // Measured: `404` + // Estimated: `5144` + // Minimum execution time: 35_154_000 picoseconds. + Weight::from_parts(38_046_000, 5144) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + /// Storage: `Providers::SignUpRequests` (r:1 w:1) + /// Proof: `Providers::SignUpRequests` (`max_values`: None, `max_size`: Some(1679), added: 4154, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(175), added: 2650, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + fn cancel_sign_up() -> Weight { + // Proof Size summary in bytes: + // Measured: `502` + // Estimated: `5144` + // Minimum execution time: 45_111_000 picoseconds. + Weight::from_parts(46_671_000, 5144) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `Providers::AccountIdToMainStorageProviderId` (r:1 w:1) + /// Proof: `Providers::AccountIdToMainStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::MainStorageProviders` (r:1 w:1) + /// Proof: `Providers::MainStorageProviders` (`max_values`: None, `max_size`: Some(647), added: 3122, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(175), added: 2650, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Providers::MspCount` (r:1 w:1) + /// Proof: `Providers::MspCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `PaymentStreams::PrivilegedProviders` (r:0 w:1) + /// Proof: `PaymentStreams::PrivilegedProviders` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + fn msp_sign_off() -> Weight { + // Proof Size summary in bytes: + // Measured: `623` + // Estimated: `4112` + // Minimum execution time: 53_953_000 picoseconds. + Weight::from_parts(55_795_000, 4112) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + /// Storage: `Providers::AccountIdToBackupStorageProviderId` (r:1 w:1) + /// Proof: `Providers::AccountIdToBackupStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::BackupStorageProviders` (r:1 w:1) + /// Proof: `Providers::BackupStorageProviders` (`max_values`: None, `max_size`: Some(683), added: 3158, mode: `MaxEncodedLen`) + /// Storage: `Providers::TotalBspsCapacity` (r:1 w:1) + /// Proof: `Providers::TotalBspsCapacity` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(175), added: 2650, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Providers::BspCount` (r:1 w:1) + /// Proof: `Providers::BspCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Providers::GlobalBspsReputationWeight` (r:1 w:1) + /// Proof: `Providers::GlobalBspsReputationWeight` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + fn bsp_sign_off() -> Weight { + // Proof Size summary in bytes: + // Measured: `673` + // Estimated: `4148` + // Minimum execution time: 57_803_000 picoseconds. + Weight::from_parts(61_995_000, 4148) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(7_u64)) + } + /// Storage: `Providers::AccountIdToMainStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToMainStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::AccountIdToBackupStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToBackupStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::BackupStorageProviders` (r:1 w:1) + /// Proof: `Providers::BackupStorageProviders` (`max_values`: None, `max_size`: Some(683), added: 3158, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(175), added: 2650, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Providers::TotalBspsCapacity` (r:1 w:1) + /// Proof: `Providers::TotalBspsCapacity` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + fn change_capacity_bsp_less_deposit() -> Weight { + // Proof Size summary in bytes: + // Measured: `673` + // Estimated: `4148` + // Minimum execution time: 56_804_000 picoseconds. + Weight::from_parts(59_551_000, 4148) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) + } + /// Storage: `Providers::AccountIdToMainStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToMainStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::AccountIdToBackupStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToBackupStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::BackupStorageProviders` (r:1 w:1) + /// Proof: `Providers::BackupStorageProviders` (`max_values`: None, `max_size`: Some(683), added: 3158, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(175), added: 2650, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Providers::TotalBspsCapacity` (r:1 w:1) + /// Proof: `Providers::TotalBspsCapacity` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + fn change_capacity_bsp_more_deposit() -> Weight { + // Proof Size summary in bytes: + // Measured: `673` + // Estimated: `4148` + // Minimum execution time: 71_410_000 picoseconds. + Weight::from_parts(74_459_000, 4148) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) + } + /// Storage: `Providers::AccountIdToMainStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToMainStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::MainStorageProviders` (r:1 w:1) + /// Proof: `Providers::MainStorageProviders` (`max_values`: None, `max_size`: Some(647), added: 3122, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(175), added: 2650, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + fn change_capacity_msp_less_deposit() -> Weight { + // Proof Size summary in bytes: + // Measured: `623` + // Estimated: `4112` + // Minimum execution time: 52_830_000 picoseconds. + Weight::from_parts(55_119_000, 4112) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `Providers::AccountIdToMainStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToMainStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::MainStorageProviders` (r:1 w:1) + /// Proof: `Providers::MainStorageProviders` (`max_values`: None, `max_size`: Some(647), added: 3122, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(175), added: 2650, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + fn change_capacity_msp_more_deposit() -> Weight { + // Proof Size summary in bytes: + // Measured: `623` + // Estimated: `4112` + // Minimum execution time: 68_248_000 picoseconds. + Weight::from_parts(69_881_000, 4112) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `Providers::AccountIdToMainStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToMainStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::MainStorageProviderIdsToValuePropositions` (r:1 w:1) + /// Proof: `Providers::MainStorageProviderIdsToValuePropositions` (`max_values`: None, `max_size`: Some(1123), added: 3598, mode: `MaxEncodedLen`) + fn add_value_prop() -> Weight { + // Proof Size summary in bytes: + // Measured: `355` + // Estimated: `4588` + // Minimum execution time: 24_604_000 picoseconds. + Weight::from_parts(25_884_000, 4588) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Providers::AccountIdToMainStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToMainStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::MainStorageProviderIdsToValuePropositions` (r:1 w:1) + /// Proof: `Providers::MainStorageProviderIdsToValuePropositions` (`max_values`: None, `max_size`: Some(1123), added: 3598, mode: `MaxEncodedLen`) + fn make_value_prop_unavailable() -> Weight { + // Proof Size summary in bytes: + // Measured: `395` + // Estimated: `4588` + // Minimum execution time: 19_142_000 picoseconds. + Weight::from_parts(21_327_000, 4588) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Providers::AccountIdToMainStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToMainStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::AccountIdToBackupStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToBackupStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::BackupStorageProviders` (r:1 w:1) + /// Proof: `Providers::BackupStorageProviders` (`max_values`: None, `max_size`: Some(683), added: 3158, mode: `MaxEncodedLen`) + fn add_multiaddress() -> Weight { + // Proof Size summary in bytes: + // Measured: `444` + // Estimated: `4148` + // Minimum execution time: 22_899_000 picoseconds. + Weight::from_parts(31_991_000, 4148) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Providers::AccountIdToMainStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToMainStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::AccountIdToBackupStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToBackupStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::BackupStorageProviders` (r:1 w:1) + /// Proof: `Providers::BackupStorageProviders` (`max_values`: None, `max_size`: Some(683), added: 3158, mode: `MaxEncodedLen`) + fn remove_multiaddress() -> Weight { + // Proof Size summary in bytes: + // Measured: `852` + // Estimated: `4148` + // Minimum execution time: 24_917_000 picoseconds. + Weight::from_parts(26_685_000, 4148) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Providers::SignUpRequests` (r:1 w:1) + /// Proof: `Providers::SignUpRequests` (`max_values`: None, `max_size`: Some(1679), added: 4154, mode: `MaxEncodedLen`) + /// Storage: `Providers::AccountIdToMainStorageProviderId` (r:1 w:1) + /// Proof: `Providers::AccountIdToMainStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::AccountIdToBackupStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToBackupStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// 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(175), added: 2650, mode: `MaxEncodedLen`) + /// Storage: `Providers::MainStorageProviderIdsToValuePropositions` (r:1 w:1) + /// Proof: `Providers::MainStorageProviderIdsToValuePropositions` (`max_values`: None, `max_size`: Some(1123), added: 3598, mode: `MaxEncodedLen`) + /// Storage: `Providers::MspCount` (r:1 w:1) + /// Proof: `Providers::MspCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Providers::MainStorageProviders` (r:0 w:1) + /// Proof: `Providers::MainStorageProviders` (`max_values`: None, `max_size`: Some(647), added: 3122, mode: `MaxEncodedLen`) + /// Storage: `PaymentStreams::PrivilegedProviders` (r:0 w:1) + /// Proof: `PaymentStreams::PrivilegedProviders` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + fn force_msp_sign_up() -> Weight { + // Proof Size summary in bytes: + // Measured: `216` + // Estimated: `5144` + // Minimum execution time: 83_771_000 picoseconds. + Weight::from_parts(85_883_000, 5144) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(8_u64)) + } + /// Storage: `Providers::SignUpRequests` (r:1 w:1) + /// Proof: `Providers::SignUpRequests` (`max_values`: None, `max_size`: Some(1679), added: 4154, mode: `MaxEncodedLen`) + /// Storage: `Providers::AccountIdToMainStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToMainStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::AccountIdToBackupStorageProviderId` (r:1 w:1) + /// Proof: `Providers::AccountIdToBackupStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// 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(175), added: 2650, mode: `MaxEncodedLen`) + /// Storage: `Providers::TotalBspsCapacity` (r:1 w:1) + /// Proof: `Providers::TotalBspsCapacity` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `Providers::BspCount` (r:1 w:1) + /// Proof: `Providers::BspCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Providers::GlobalBspsReputationWeight` (r:1 w:1) + /// Proof: `Providers::GlobalBspsReputationWeight` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Providers::BackupStorageProviders` (r:0 w:1) + /// Proof: `Providers::BackupStorageProviders` (`max_values`: None, `max_size`: Some(683), added: 3158, mode: `MaxEncodedLen`) + fn force_bsp_sign_up() -> Weight { + // Proof Size summary in bytes: + // Measured: `216` + // Estimated: `5144` + // Minimum execution time: 75_083_000 picoseconds. + Weight::from_parts(76_457_000, 5144) + .saturating_add(T::DbWeight::get().reads(8_u64)) + .saturating_add(T::DbWeight::get().writes(8_u64)) + } + /// Storage: `Providers::MainStorageProviders` (r:1 w:0) + /// Proof: `Providers::MainStorageProviders` (`max_values`: None, `max_size`: Some(647), added: 3122, mode: `MaxEncodedLen`) + /// Storage: `Providers::BackupStorageProviders` (r:1 w:0) + /// Proof: `Providers::BackupStorageProviders` (`max_values`: None, `max_size`: Some(683), added: 3158, mode: `MaxEncodedLen`) + /// Storage: `ProofsDealer::SlashableProviders` (r:1 w:1) + /// Proof: `ProofsDealer::SlashableProviders` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) + /// Storage: `Parameters::Parameters` (r:1 w:0) + /// Proof: `Parameters::Parameters` (`max_values`: None, `max_size`: Some(36), added: 2511, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(175), added: 2650, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:2 w:2) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + fn slash() -> Weight { + // Proof Size summary in bytes: + // Measured: `867` + // Estimated: `6196` + // Minimum execution time: 62_963_000 picoseconds. + Weight::from_parts(65_689_000, 6196) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) + } +} + +// For backwards compatibility and tests. +impl WeightInfo for () { + /// Storage: `Providers::SignUpRequests` (r:1 w:1) + /// Proof: `Providers::SignUpRequests` (`max_values`: None, `max_size`: Some(1679), added: 4154, mode: `MaxEncodedLen`) + /// Storage: `Providers::AccountIdToMainStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToMainStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::AccountIdToBackupStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToBackupStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// 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(175), added: 2650, mode: `MaxEncodedLen`) + fn request_msp_sign_up() -> Weight { + // Proof Size summary in bytes: + // Measured: `216` + // Estimated: `5144` + // Minimum execution time: 61_059_000 picoseconds. + Weight::from_parts(62_537_000, 5144) + .saturating_add(RocksDbWeight::get().reads(5_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) + } + /// Storage: `Providers::SignUpRequests` (r:1 w:1) + /// Proof: `Providers::SignUpRequests` (`max_values`: None, `max_size`: Some(1679), added: 4154, mode: `MaxEncodedLen`) + /// Storage: `Providers::AccountIdToMainStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToMainStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::AccountIdToBackupStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToBackupStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// 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(175), added: 2650, mode: `MaxEncodedLen`) + fn request_bsp_sign_up() -> Weight { + // Proof Size summary in bytes: + // Measured: `216` + // Estimated: `5144` + // Minimum execution time: 66_729_000 picoseconds. + Weight::from_parts(67_999_000, 5144) + .saturating_add(RocksDbWeight::get().reads(5_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) + } + /// Storage: `Providers::SignUpRequests` (r:1 w:1) + /// Proof: `Providers::SignUpRequests` (`max_values`: None, `max_size`: Some(1679), added: 4154, mode: `MaxEncodedLen`) + /// Storage: `Randomness::LatestOneEpochAgoRandomness` (r:1 w:0) + /// Proof: `Randomness::LatestOneEpochAgoRandomness` (`max_values`: Some(1), `max_size`: Some(36), added: 531, mode: `MaxEncodedLen`) + /// Storage: `Providers::TotalBspsCapacity` (r:1 w:1) + /// Proof: `Providers::TotalBspsCapacity` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `Providers::BspCount` (r:1 w:1) + /// Proof: `Providers::BspCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Providers::GlobalBspsReputationWeight` (r:1 w:1) + /// Proof: `Providers::GlobalBspsReputationWeight` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Providers::AccountIdToBackupStorageProviderId` (r:0 w:1) + /// Proof: `Providers::AccountIdToBackupStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::BackupStorageProviders` (r:0 w:1) + /// Proof: `Providers::BackupStorageProviders` (`max_values`: None, `max_size`: Some(683), added: 3158, mode: `MaxEncodedLen`) + fn confirm_sign_up_bsp() -> Weight { + // Proof Size summary in bytes: + // Measured: `411` + // Estimated: `5144` + // Minimum execution time: 27_060_000 picoseconds. + Weight::from_parts(28_984_000, 5144) + .saturating_add(RocksDbWeight::get().reads(5_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) + } + /// Storage: `Providers::SignUpRequests` (r:1 w:1) + /// Proof: `Providers::SignUpRequests` (`max_values`: None, `max_size`: Some(1679), added: 4154, mode: `MaxEncodedLen`) + /// Storage: `Randomness::LatestOneEpochAgoRandomness` (r:1 w:0) + /// Proof: `Randomness::LatestOneEpochAgoRandomness` (`max_values`: Some(1), `max_size`: Some(36), added: 531, mode: `MaxEncodedLen`) + /// Storage: `Providers::MainStorageProviderIdsToValuePropositions` (r:1 w:1) + /// Proof: `Providers::MainStorageProviderIdsToValuePropositions` (`max_values`: None, `max_size`: Some(1123), added: 3598, mode: `MaxEncodedLen`) + /// Storage: `Providers::MspCount` (r:1 w:1) + /// Proof: `Providers::MspCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Providers::AccountIdToMainStorageProviderId` (r:0 w:1) + /// Proof: `Providers::AccountIdToMainStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::MainStorageProviders` (r:0 w:1) + /// Proof: `Providers::MainStorageProviders` (`max_values`: None, `max_size`: Some(647), added: 3122, mode: `MaxEncodedLen`) + /// Storage: `PaymentStreams::PrivilegedProviders` (r:0 w:1) + /// Proof: `PaymentStreams::PrivilegedProviders` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + fn confirm_sign_up_msp() -> Weight { + // Proof Size summary in bytes: + // Measured: `404` + // Estimated: `5144` + // Minimum execution time: 35_154_000 picoseconds. + Weight::from_parts(38_046_000, 5144) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) + } + /// Storage: `Providers::SignUpRequests` (r:1 w:1) + /// Proof: `Providers::SignUpRequests` (`max_values`: None, `max_size`: Some(1679), added: 4154, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(175), added: 2650, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + fn cancel_sign_up() -> Weight { + // Proof Size summary in bytes: + // Measured: `502` + // Estimated: `5144` + // Minimum execution time: 45_111_000 picoseconds. + Weight::from_parts(46_671_000, 5144) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) + } + /// Storage: `Providers::AccountIdToMainStorageProviderId` (r:1 w:1) + /// Proof: `Providers::AccountIdToMainStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::MainStorageProviders` (r:1 w:1) + /// Proof: `Providers::MainStorageProviders` (`max_values`: None, `max_size`: Some(647), added: 3122, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(175), added: 2650, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Providers::MspCount` (r:1 w:1) + /// Proof: `Providers::MspCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `PaymentStreams::PrivilegedProviders` (r:0 w:1) + /// Proof: `PaymentStreams::PrivilegedProviders` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + fn msp_sign_off() -> Weight { + // Proof Size summary in bytes: + // Measured: `623` + // Estimated: `4112` + // Minimum execution time: 53_953_000 picoseconds. + Weight::from_parts(55_795_000, 4112) + .saturating_add(RocksDbWeight::get().reads(5_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) + } + /// Storage: `Providers::AccountIdToBackupStorageProviderId` (r:1 w:1) + /// Proof: `Providers::AccountIdToBackupStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::BackupStorageProviders` (r:1 w:1) + /// Proof: `Providers::BackupStorageProviders` (`max_values`: None, `max_size`: Some(683), added: 3158, mode: `MaxEncodedLen`) + /// Storage: `Providers::TotalBspsCapacity` (r:1 w:1) + /// Proof: `Providers::TotalBspsCapacity` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(175), added: 2650, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Providers::BspCount` (r:1 w:1) + /// Proof: `Providers::BspCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Providers::GlobalBspsReputationWeight` (r:1 w:1) + /// Proof: `Providers::GlobalBspsReputationWeight` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + fn bsp_sign_off() -> Weight { + // Proof Size summary in bytes: + // Measured: `673` + // Estimated: `4148` + // Minimum execution time: 57_803_000 picoseconds. + Weight::from_parts(61_995_000, 4148) + .saturating_add(RocksDbWeight::get().reads(7_u64)) + .saturating_add(RocksDbWeight::get().writes(7_u64)) + } + /// Storage: `Providers::AccountIdToMainStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToMainStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::AccountIdToBackupStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToBackupStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::BackupStorageProviders` (r:1 w:1) + /// Proof: `Providers::BackupStorageProviders` (`max_values`: None, `max_size`: Some(683), added: 3158, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(175), added: 2650, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Providers::TotalBspsCapacity` (r:1 w:1) + /// Proof: `Providers::TotalBspsCapacity` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + fn change_capacity_bsp_less_deposit() -> Weight { + // Proof Size summary in bytes: + // Measured: `673` + // Estimated: `4148` + // Minimum execution time: 56_804_000 picoseconds. + Weight::from_parts(59_551_000, 4148) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(4_u64)) + } + /// Storage: `Providers::AccountIdToMainStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToMainStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::AccountIdToBackupStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToBackupStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::BackupStorageProviders` (r:1 w:1) + /// Proof: `Providers::BackupStorageProviders` (`max_values`: None, `max_size`: Some(683), added: 3158, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(175), added: 2650, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Providers::TotalBspsCapacity` (r:1 w:1) + /// Proof: `Providers::TotalBspsCapacity` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + fn change_capacity_bsp_more_deposit() -> Weight { + // Proof Size summary in bytes: + // Measured: `673` + // Estimated: `4148` + // Minimum execution time: 71_410_000 picoseconds. + Weight::from_parts(74_459_000, 4148) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(4_u64)) + } + /// Storage: `Providers::AccountIdToMainStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToMainStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::MainStorageProviders` (r:1 w:1) + /// Proof: `Providers::MainStorageProviders` (`max_values`: None, `max_size`: Some(647), added: 3122, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(175), added: 2650, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + fn change_capacity_msp_less_deposit() -> Weight { + // Proof Size summary in bytes: + // Measured: `623` + // Estimated: `4112` + // Minimum execution time: 52_830_000 picoseconds. + Weight::from_parts(55_119_000, 4112) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) + } + /// Storage: `Providers::AccountIdToMainStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToMainStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::MainStorageProviders` (r:1 w:1) + /// Proof: `Providers::MainStorageProviders` (`max_values`: None, `max_size`: Some(647), added: 3122, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(175), added: 2650, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + fn change_capacity_msp_more_deposit() -> Weight { + // Proof Size summary in bytes: + // Measured: `623` + // Estimated: `4112` + // Minimum execution time: 68_248_000 picoseconds. + Weight::from_parts(69_881_000, 4112) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) + } + /// Storage: `Providers::AccountIdToMainStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToMainStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::MainStorageProviderIdsToValuePropositions` (r:1 w:1) + /// Proof: `Providers::MainStorageProviderIdsToValuePropositions` (`max_values`: None, `max_size`: Some(1123), added: 3598, mode: `MaxEncodedLen`) + fn add_value_prop() -> Weight { + // Proof Size summary in bytes: + // Measured: `355` + // Estimated: `4588` + // Minimum execution time: 24_604_000 picoseconds. + Weight::from_parts(25_884_000, 4588) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: `Providers::AccountIdToMainStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToMainStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::MainStorageProviderIdsToValuePropositions` (r:1 w:1) + /// Proof: `Providers::MainStorageProviderIdsToValuePropositions` (`max_values`: None, `max_size`: Some(1123), added: 3598, mode: `MaxEncodedLen`) + fn make_value_prop_unavailable() -> Weight { + // Proof Size summary in bytes: + // Measured: `395` + // Estimated: `4588` + // Minimum execution time: 19_142_000 picoseconds. + Weight::from_parts(21_327_000, 4588) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: `Providers::AccountIdToMainStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToMainStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::AccountIdToBackupStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToBackupStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::BackupStorageProviders` (r:1 w:1) + /// Proof: `Providers::BackupStorageProviders` (`max_values`: None, `max_size`: Some(683), added: 3158, mode: `MaxEncodedLen`) + fn add_multiaddress() -> Weight { + // Proof Size summary in bytes: + // Measured: `444` + // Estimated: `4148` + // Minimum execution time: 22_899_000 picoseconds. + Weight::from_parts(31_991_000, 4148) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: `Providers::AccountIdToMainStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToMainStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::AccountIdToBackupStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToBackupStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::BackupStorageProviders` (r:1 w:1) + /// Proof: `Providers::BackupStorageProviders` (`max_values`: None, `max_size`: Some(683), added: 3158, mode: `MaxEncodedLen`) + fn remove_multiaddress() -> Weight { + // Proof Size summary in bytes: + // Measured: `852` + // Estimated: `4148` + // Minimum execution time: 24_917_000 picoseconds. + Weight::from_parts(26_685_000, 4148) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + /// Storage: `Providers::SignUpRequests` (r:1 w:1) + /// Proof: `Providers::SignUpRequests` (`max_values`: None, `max_size`: Some(1679), added: 4154, mode: `MaxEncodedLen`) + /// Storage: `Providers::AccountIdToMainStorageProviderId` (r:1 w:1) + /// Proof: `Providers::AccountIdToMainStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::AccountIdToBackupStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToBackupStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// 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(175), added: 2650, mode: `MaxEncodedLen`) + /// Storage: `Providers::MainStorageProviderIdsToValuePropositions` (r:1 w:1) + /// Proof: `Providers::MainStorageProviderIdsToValuePropositions` (`max_values`: None, `max_size`: Some(1123), added: 3598, mode: `MaxEncodedLen`) + /// Storage: `Providers::MspCount` (r:1 w:1) + /// Proof: `Providers::MspCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Providers::MainStorageProviders` (r:0 w:1) + /// Proof: `Providers::MainStorageProviders` (`max_values`: None, `max_size`: Some(647), added: 3122, mode: `MaxEncodedLen`) + /// Storage: `PaymentStreams::PrivilegedProviders` (r:0 w:1) + /// Proof: `PaymentStreams::PrivilegedProviders` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + fn force_msp_sign_up() -> Weight { + // Proof Size summary in bytes: + // Measured: `216` + // Estimated: `5144` + // Minimum execution time: 83_771_000 picoseconds. + Weight::from_parts(85_883_000, 5144) + .saturating_add(RocksDbWeight::get().reads(7_u64)) + .saturating_add(RocksDbWeight::get().writes(8_u64)) + } + /// Storage: `Providers::SignUpRequests` (r:1 w:1) + /// Proof: `Providers::SignUpRequests` (`max_values`: None, `max_size`: Some(1679), added: 4154, mode: `MaxEncodedLen`) + /// Storage: `Providers::AccountIdToMainStorageProviderId` (r:1 w:0) + /// Proof: `Providers::AccountIdToMainStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// Storage: `Providers::AccountIdToBackupStorageProviderId` (r:1 w:1) + /// Proof: `Providers::AccountIdToBackupStorageProviderId` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) + /// 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(175), added: 2650, mode: `MaxEncodedLen`) + /// Storage: `Providers::TotalBspsCapacity` (r:1 w:1) + /// Proof: `Providers::TotalBspsCapacity` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `Providers::BspCount` (r:1 w:1) + /// Proof: `Providers::BspCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Providers::GlobalBspsReputationWeight` (r:1 w:1) + /// Proof: `Providers::GlobalBspsReputationWeight` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Providers::BackupStorageProviders` (r:0 w:1) + /// Proof: `Providers::BackupStorageProviders` (`max_values`: None, `max_size`: Some(683), added: 3158, mode: `MaxEncodedLen`) + fn force_bsp_sign_up() -> Weight { + // Proof Size summary in bytes: + // Measured: `216` + // Estimated: `5144` + // Minimum execution time: 75_083_000 picoseconds. + Weight::from_parts(76_457_000, 5144) + .saturating_add(RocksDbWeight::get().reads(8_u64)) + .saturating_add(RocksDbWeight::get().writes(8_u64)) + } + /// Storage: `Providers::MainStorageProviders` (r:1 w:0) + /// Proof: `Providers::MainStorageProviders` (`max_values`: None, `max_size`: Some(647), added: 3122, mode: `MaxEncodedLen`) + /// Storage: `Providers::BackupStorageProviders` (r:1 w:0) + /// Proof: `Providers::BackupStorageProviders` (`max_values`: None, `max_size`: Some(683), added: 3158, mode: `MaxEncodedLen`) + /// Storage: `ProofsDealer::SlashableProviders` (r:1 w:1) + /// Proof: `ProofsDealer::SlashableProviders` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) + /// Storage: `Parameters::Parameters` (r:1 w:0) + /// Proof: `Parameters::Parameters` (`max_values`: None, `max_size`: Some(36), added: 2511, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(175), added: 2650, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:2 w:2) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + fn slash() -> Weight { + // Proof Size summary in bytes: + // Measured: `867` + // Estimated: `6196` + // Minimum execution time: 62_963_000 picoseconds. + Weight::from_parts(65_689_000, 6196) + .saturating_add(RocksDbWeight::get().reads(7_u64)) + .saturating_add(RocksDbWeight::get().writes(4_u64)) + } +} diff --git a/pallets/randomness/src/lib.rs b/pallets/randomness/src/lib.rs index 3fc8ca10..7067a39f 100644 --- a/pallets/randomness/src/lib.rs +++ b/pallets/randomness/src/lib.rs @@ -91,7 +91,7 @@ pub mod pallet { /// Ensures the mandatory inherent was included in the block #[pallet::storage] - pub(crate) type InherentIncluded = StorageValue<_, ()>; + pub type InherentIncluded = StorageValue<_, ()>; #[pallet::call] impl Pallet { diff --git a/runtime/src/configs/mod.rs b/runtime/src/configs/mod.rs index a9a553c1..e949bb82 100644 --- a/runtime/src/configs/mod.rs +++ b/runtime/src/configs/mod.rs @@ -462,6 +462,7 @@ impl Get> for DefaultMerkleRoot { impl pallet_storage_providers::Config for Runtime { type RuntimeEvent = RuntimeEvent; + type WeightInfo = pallet_storage_providers::weights::SubstrateWeight; type ProvidersRandomness = pallet_randomness::RandomnessFromOneEpochAgo; type PaymentStreams = PaymentStreams; type FileMetadataManager = FileMetadata< diff --git a/xcm-simulator/src/storagehub/configs/mod.rs b/xcm-simulator/src/storagehub/configs/mod.rs index b6773b3e..f239182b 100644 --- a/xcm-simulator/src/storagehub/configs/mod.rs +++ b/xcm-simulator/src/storagehub/configs/mod.rs @@ -476,6 +476,7 @@ impl Get> for DefaultMerkleRoot { } impl pallet_storage_providers::Config for Runtime { type RuntimeEvent = RuntimeEvent; + type WeightInfo = pallet_storage_providers::weights::SubstrateWeight; type ProvidersRandomness = pallet_randomness::RandomnessFromOneEpochAgo; type PaymentStreams = PaymentStreams; type FileMetadataManager = shp_file_metadata::FileMetadata< From 5b528775a8246fede2f31ab3f1e0c78dc2524040 Mon Sep 17 00:00:00 2001 From: Tobi Demeco Date: Fri, 15 Nov 2024 18:08:46 -0300 Subject: [PATCH 4/4] style: :rotating_light: run cargo fmt --- pallets/proofs-dealer/src/mock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/proofs-dealer/src/mock.rs b/pallets/proofs-dealer/src/mock.rs index 0fe2f1f6..01037428 100644 --- a/pallets/proofs-dealer/src/mock.rs +++ b/pallets/proofs-dealer/src/mock.rs @@ -175,7 +175,7 @@ impl Convert, Balance> for BlockNumberToBalance { // Storage Providers pallet: impl pallet_storage_providers::Config for Test { type RuntimeEvent = RuntimeEvent; - type WeightInfo = (); + type WeightInfo = (); type ProvidersRandomness = MockRandomness; type PaymentStreams = PaymentStreams; type FileMetadataManager = MockFileMetadataManager;