diff --git a/Cargo.lock b/Cargo.lock index 96778c1cd..a8e37a57d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8409,6 +8409,7 @@ dependencies = [ "cumulus-relay-chain-interface", "frame-benchmarking", "frame-benchmarking-cli", + "frame-support", "futures", "hex-literal 0.3.4", "jsonrpsee", diff --git a/nodes/parachain/Cargo.toml b/nodes/parachain/Cargo.toml index 1be933404..5eaaf5e64 100644 --- a/nodes/parachain/Cargo.toml +++ b/nodes/parachain/Cargo.toml @@ -30,6 +30,7 @@ macros = { workspace = true } # Substrate frame-benchmarking.workspace = true frame-benchmarking-cli.workspace = true +frame-support.workspace = true pallet-transaction-payment-rpc.workspace = true sc-basic-authorship.workspace = true sc-chain-spec.workspace = true diff --git a/nodes/parachain/src/chain_spec/politest.rs b/nodes/parachain/src/chain_spec/politest.rs index 1f2440c31..b3407fa55 100644 --- a/nodes/parachain/src/chain_spec/politest.rs +++ b/nodes/parachain/src/chain_spec/politest.rs @@ -19,14 +19,14 @@ //! Polimec Testnet chain specification use cumulus_primitives_core::ParaId; -use frame_benchmarking::__private::traits::fungible::Inspect; +use frame_support::traits::fungible::Inspect; use politest_runtime::{ pallet_parachain_staking::{ inflation::{perbill_annual_to_perbill_round, BLOCKS_PER_YEAR}, InflationInfo, Range, }, AccountId, AuraId as AuthorityId, Balance, MinCandidateStk, OracleProvidersMembershipConfig, Runtime, - RuntimeGenesisConfig, EXISTENTIAL_DEPOSIT, PLMC, + RuntimeGenesisConfig, PLMC, }; use sc_service::ChainType; use sp_core::{crypto::UncheckedInto, sr25519}; @@ -202,9 +202,18 @@ fn testnet_genesis( let accounts = endowed_accounts.iter().map(|(account, _)| account.clone()).collect::>(); let funding_accounts = vec![ - (::PalletId::get().into_account_truncating(), ::NativeCurrency::minimum_balance()), - (::ProtocolGrowthTreasury::get(), ::NativeCurrency::minimum_balance()), - (::ContributionTreasury::get(), ::NativeCurrency::minimum_balance()), + ( + ::PalletId::get().into_account_truncating(), + ::NativeCurrency::minimum_balance(), + ), + ( + ::ProtocolGrowthTreasury::get(), + ::NativeCurrency::minimum_balance(), + ), + ( + ::ContributionTreasury::get(), + ::NativeCurrency::minimum_balance(), + ), ]; endowed_accounts.append(&mut funding_accounts.clone()); diff --git a/pallets/funding/src/benchmarking.rs b/pallets/funding/src/benchmarking.rs index 2429396f3..585a0fd82 100644 --- a/pallets/funding/src/benchmarking.rs +++ b/pallets/funding/src/benchmarking.rs @@ -339,9 +339,7 @@ pub fn fill_projects_to_update( ) { // fill the `ProjectsToUpdate` vectors from @ expected_insertion_block to @ expected_insertion_block+x, to benchmark all the failed insertion attempts for _ in 0..fully_filled_vecs_from_insertion { - while ProjectsToUpdate::::try_append(expected_insertion_block, (&69u32, UpdateType::EvaluationEnd)).is_ok() { - continue; - } + ProjectsToUpdate::::insert(expected_insertion_block, (&69u32, UpdateType::EvaluationEnd)); expected_insertion_block += 1u32.into(); } } @@ -570,14 +568,9 @@ mod benchmarks { let project_id = inst.create_new_project(project_metadata, issuer.clone()); // start_evaluation fn will try to add an automatic transition 1 block after the last evaluation block - let mut block_number: BlockNumberFor = inst.current_block() + T::EvaluationDuration::get() + One::one(); + let block_number: BlockNumberFor = inst.current_block() + T::EvaluationDuration::get() + One::one(); // fill the `ProjectsToUpdate` vectors from @ block_number to @ block_number+x, to benchmark all the failed insertion attempts - for _ in 0..x { - while ProjectsToUpdate::::try_append(block_number, (&69u32, UpdateType::EvaluationEnd)).is_ok() { - continue; - } - block_number += 1u32.into(); - } + fill_projects_to_update::(x, block_number); let jwt = get_mock_jwt(issuer.clone(), InvestorType::Institutional, generate_did_from_account(issuer.clone())); #[extrinsic_call] start_evaluation(RawOrigin::Signed(issuer), jwt, project_id); diff --git a/pallets/funding/src/functions.rs b/pallets/funding/src/functions.rs index 3a7c94d97..0f0e18051 100644 --- a/pallets/funding/src/functions.rs +++ b/pallets/funding/src/functions.rs @@ -2009,9 +2009,10 @@ impl Pallet { // There is a limit for how many projects can update each block, so we need to make sure we don't exceed that limit let mut block_number = block_number; for i in 1..T::MaxProjectsToUpdateInsertionAttempts::get() + 1 { - if ProjectsToUpdate::::try_append(block_number, store.clone()).is_err() { + if ProjectsToUpdate::::get(block_number).is_some() { block_number += 1u32.into(); } else { + ProjectsToUpdate::::insert(block_number, store); return Ok(i); } } diff --git a/pallets/funding/src/instantiator.rs b/pallets/funding/src/instantiator.rs index 6f48a1e68..2163d3fb3 100644 --- a/pallets/funding/src/instantiator.rs +++ b/pallets/funding/src/instantiator.rs @@ -1011,11 +1011,12 @@ impl< pub fn get_update_block(&mut self, project_id: ProjectId, update_type: &UpdateType) -> Option> { self.execute(|| { - ProjectsToUpdate::::iter().find_map(|(block, update_vec)| { - update_vec - .iter() - .find(|(pid, update)| *pid == project_id && update == update_type) - .map(|(_pid, _update)| block) + ProjectsToUpdate::::iter().find_map(|(block, update_tup)| { + if project_id == update_tup.0 && update_type == &update_tup.1 { + Some(block) + } else { + None + } }) }) } diff --git a/pallets/funding/src/lib.rs b/pallets/funding/src/lib.rs index 210710157..47f602c6c 100644 --- a/pallets/funding/src/lib.rs +++ b/pallets/funding/src/lib.rs @@ -484,13 +484,7 @@ pub mod pallet { #[pallet::storage] /// A map to know in which block to update which active projects using on_initialize. - pub type ProjectsToUpdate = StorageMap< - _, - Blake2_128Concat, - BlockNumberFor, - BoundedVec<(ProjectId, UpdateType), T::MaxProjectsToUpdatePerBlock>, - ValueQuery, - >; + pub type ProjectsToUpdate = StorageMap<_, Blake2_128Concat, BlockNumberFor, (ProjectId, UpdateType)>; #[pallet::storage] /// Keep track of the PLMC bonds made to each project by each evaluator @@ -1161,7 +1155,7 @@ pub mod pallet { fn on_initialize(now: BlockNumberFor) -> Weight { // Get the projects that need to be updated on this block and update them let mut used_weight = Weight::from_parts(0, 0); - for (project_id, update_type) in ProjectsToUpdate::::take(now) { + if let Some((project_id, update_type)) = ProjectsToUpdate::::take(now) { match update_type { // EvaluationRound -> AuctionInitializePeriod | ProjectFailed UpdateType::EvaluationEnd => { diff --git a/pallets/funding/src/tests/misc.rs b/pallets/funding/src/tests/misc.rs index 6d1f76d82..cb2ed718b 100644 --- a/pallets/funding/src/tests/misc.rs +++ b/pallets/funding/src/tests/misc.rs @@ -553,8 +553,7 @@ mod bug_hunting { let automatic_auction_start = auction_initialize_period_end_block + 1u64; for i in 0..max_insertion_attempts { let key: BlockNumberFor = automatic_auction_start + i as u64; - let val: BoundedVec<(ProjectId, UpdateType), ::MaxProjectsToUpdatePerBlock> = - vec![(69u32, UpdateType::EvaluationEnd)].try_into().unwrap(); + let val: (ProjectId, UpdateType) = (69u32, UpdateType::EvaluationEnd); inst.execute(|| crate::ProjectsToUpdate::::insert(key, val)); } diff --git a/pallets/funding/src/weights.rs b/pallets/funding/src/weights.rs index b96c9a5d2..b03604b52 100644 --- a/pallets/funding/src/weights.rs +++ b/pallets/funding/src/weights.rs @@ -277,43 +277,52 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().writes(7_u64)) .saturating_add(Weight::from_parts(0, 2839).saturating_mul(x.into())) } - /// Storage: `PolimecFunding::ProjectsMetadata` (r:1 w:0) - /// Proof: `PolimecFunding::ProjectsMetadata` (`max_values`: None, `max_size`: Some(334), added: 2809, mode: `MaxEncodedLen`) - /// Storage: `PolimecFunding::ProjectsDetails` (r:1 w:1) - /// Proof: `PolimecFunding::ProjectsDetails` (`max_values`: None, `max_size`: Some(349), added: 2824, mode: `MaxEncodedLen`) - /// Storage: `PolimecFunding::Contributions` (r:256 w:1) - /// Proof: `PolimecFunding::Contributions` (`max_values`: None, `max_size`: Some(364), added: 2839, mode: `MaxEncodedLen`) + /// Storage: `Timestamp::Now` (r:1 w:0) + /// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `Funding::ProjectsDetails` (r:1 w:1) + /// Proof: `Funding::ProjectsDetails` (`max_values`: None, `max_size`: Some(380), added: 2855, mode: `MaxEncodedLen`) + /// Storage: `Funding::DidWithWinningBids` (r:1 w:0) + /// Proof: `Funding::DidWithWinningBids` (`max_values`: None, `max_size`: Some(95), added: 2570, mode: `MaxEncodedLen`) + /// Storage: `Funding::ProjectsMetadata` (r:1 w:0) + /// Proof: `Funding::ProjectsMetadata` (`max_values`: None, `max_size`: Some(441), added: 2916, mode: `MaxEncodedLen`) + /// Storage: `Funding::Contributions` (r:16 w:1) + /// Proof: `Funding::Contributions` (`max_values`: None, `max_size`: Some(194), added: 2669, mode: `MaxEncodedLen`) + /// Storage: `Funding::ContributionBoughtUSD` (r:1 w:1) + /// Proof: `Funding::ContributionBoughtUSD` (`max_values`: None, `max_size`: Some(110), added: 2585, mode: `MaxEncodedLen`) /// Storage: `Oracle::Values` (r:2 w:0) /// Proof: `Oracle::Values` (`max_values`: None, `max_size`: Some(36), added: 2511, mode: `MaxEncodedLen`) - /// Storage: `PolimecFunding::NextContributionId` (r:1 w:1) - /// Proof: `PolimecFunding::NextContributionId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Funding::RetailParticipations` (r:1 w:1) + /// Proof: `Funding::RetailParticipations` (`max_values`: None, `max_size`: Some(175), added: 2650, mode: `MaxEncodedLen`) + /// Storage: `Funding::NextContributionId` (r:1 w:1) + /// Proof: `Funding::NextContributionId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Funding::Evaluations` (r:1 w:0) + /// Proof: `Funding::Evaluations` (`max_values`: None, `max_size`: Some(196), added: 2671, mode: `MaxEncodedLen`) /// Storage: `Balances::Holds` (r:1 w:1) /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(1149), added: 3624, mode: `MaxEncodedLen`) - /// Storage: `PolimecFunding::Evaluations` (r:1 w:0) - /// Proof: `PolimecFunding::Evaluations` (`max_values`: None, `max_size`: Some(345), added: 2820, mode: `MaxEncodedLen`) - /// Storage: `StatemintAssets::Asset` (r:1 w:1) - /// Proof: `StatemintAssets::Asset` (`max_values`: None, `max_size`: Some(210), added: 2685, mode: `MaxEncodedLen`) - /// Storage: `StatemintAssets::Account` (r:2 w:2) - /// Proof: `StatemintAssets::Account` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`) - /// Storage: `PolimecFunding::ProjectsToUpdate` (r:9833 w:1) - /// Proof: `PolimecFunding::ProjectsToUpdate` (`max_values`: None, `max_size`: Some(27), added: 2502, mode: `MaxEncodedLen`) - /// The range of component `x` is `[1, 255]`. + /// Storage: `ForeignAssets::Asset` (r:1 w:1) + /// Proof: `ForeignAssets::Asset` (`max_values`: None, `max_size`: Some(210), added: 2685, mode: `MaxEncodedLen`) + /// Storage: `ForeignAssets::Account` (r:2 w:2) + /// Proof: `ForeignAssets::Account` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`) + /// Storage: `Funding::ProjectsToUpdate` (r:100 w:1) + /// Proof: `Funding::ProjectsToUpdate` (`max_values`: None, `max_size`: Some(26), added: 2501, mode: `MaxEncodedLen`) + /// The range of component `x` is `[0, 15]`. /// The range of component `y` is `[1, 99]`. - /// The range of component `z` is `[1, 10000]`. - fn contribution_ends_round(x: u32, y: u32 ) -> Weight { + fn contribution_ends_round(x: u32, y: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `44564 + x * (137 ±0) + y * (254 ±0) + z * (21 ±0)` - // Estimated: `15401 + x * (2839 ±0) + y * (92965 ±6_111) + z * (1905 ±59)` - // Minimum execution time: 1_120_000_000 picoseconds. - Weight::from_parts(55_806_166, 15401) - // Standard Error: 7_331_488 - .saturating_add(Weight::from_parts(111_668_126, 0).saturating_mul(y.into())) - // Standard Error: 71_852 - .saturating_add(T::DbWeight::get().reads(17_u64)) - .saturating_add(T::DbWeight::get().reads((37_u64).saturating_mul(y.into()))) - .saturating_add(T::DbWeight::get().writes(8_u64)) - .saturating_add(Weight::from_parts(0, 2839).saturating_mul(x.into())) - .saturating_add(Weight::from_parts(0, 92965).saturating_mul(y.into())) + // Measured: `3093 + x * (134 ±0) + y * (28 ±0)` + // Estimated: `6208 + x * (2669 ±0) + y * (2501 ±0)` + // Minimum execution time: 269_000_000 picoseconds. + Weight::from_parts(243_223_951, 6208) + // Standard Error: 103_493 + .saturating_add(Weight::from_parts(3_497_884, 0).saturating_mul(x.into())) + // Standard Error: 16_476 + .saturating_add(Weight::from_parts(1_907_293, 0).saturating_mul(y.into())) + .saturating_add(T::DbWeight::get().reads(16_u64)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into()))) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(y.into()))) + .saturating_add(T::DbWeight::get().writes(10_u64)) + .saturating_add(Weight::from_parts(0, 2669).saturating_mul(x.into())) + .saturating_add(Weight::from_parts(0, 2501).saturating_mul(y.into())) } /// Storage: `PolimecFunding::ProjectsDetails` (r:1 w:0) /// Proof: `PolimecFunding::ProjectsDetails` (`max_values`: None, `max_size`: Some(349), added: 2824, mode: `MaxEncodedLen`) @@ -806,43 +815,52 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().writes(7_u64)) .saturating_add(Weight::from_parts(0, 2839).saturating_mul(x.into())) } - /// Storage: `PolimecFunding::ProjectsMetadata` (r:1 w:0) - /// Proof: `PolimecFunding::ProjectsMetadata` (`max_values`: None, `max_size`: Some(334), added: 2809, mode: `MaxEncodedLen`) - /// Storage: `PolimecFunding::ProjectsDetails` (r:1 w:1) - /// Proof: `PolimecFunding::ProjectsDetails` (`max_values`: None, `max_size`: Some(349), added: 2824, mode: `MaxEncodedLen`) - /// Storage: `PolimecFunding::Contributions` (r:256 w:1) - /// Proof: `PolimecFunding::Contributions` (`max_values`: None, `max_size`: Some(364), added: 2839, mode: `MaxEncodedLen`) + /// Storage: `Timestamp::Now` (r:1 w:0) + /// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `Funding::ProjectsDetails` (r:1 w:1) + /// Proof: `Funding::ProjectsDetails` (`max_values`: None, `max_size`: Some(380), added: 2855, mode: `MaxEncodedLen`) + /// Storage: `Funding::DidWithWinningBids` (r:1 w:0) + /// Proof: `Funding::DidWithWinningBids` (`max_values`: None, `max_size`: Some(95), added: 2570, mode: `MaxEncodedLen`) + /// Storage: `Funding::ProjectsMetadata` (r:1 w:0) + /// Proof: `Funding::ProjectsMetadata` (`max_values`: None, `max_size`: Some(441), added: 2916, mode: `MaxEncodedLen`) + /// Storage: `Funding::Contributions` (r:16 w:1) + /// Proof: `Funding::Contributions` (`max_values`: None, `max_size`: Some(194), added: 2669, mode: `MaxEncodedLen`) + /// Storage: `Funding::ContributionBoughtUSD` (r:1 w:1) + /// Proof: `Funding::ContributionBoughtUSD` (`max_values`: None, `max_size`: Some(110), added: 2585, mode: `MaxEncodedLen`) /// Storage: `Oracle::Values` (r:2 w:0) /// Proof: `Oracle::Values` (`max_values`: None, `max_size`: Some(36), added: 2511, mode: `MaxEncodedLen`) - /// Storage: `PolimecFunding::NextContributionId` (r:1 w:1) - /// Proof: `PolimecFunding::NextContributionId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Funding::RetailParticipations` (r:1 w:1) + /// Proof: `Funding::RetailParticipations` (`max_values`: None, `max_size`: Some(175), added: 2650, mode: `MaxEncodedLen`) + /// Storage: `Funding::NextContributionId` (r:1 w:1) + /// Proof: `Funding::NextContributionId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Funding::Evaluations` (r:1 w:0) + /// Proof: `Funding::Evaluations` (`max_values`: None, `max_size`: Some(196), added: 2671, mode: `MaxEncodedLen`) /// Storage: `Balances::Holds` (r:1 w:1) /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(1149), added: 3624, mode: `MaxEncodedLen`) - /// Storage: `PolimecFunding::Evaluations` (r:1 w:0) - /// Proof: `PolimecFunding::Evaluations` (`max_values`: None, `max_size`: Some(345), added: 2820, mode: `MaxEncodedLen`) - /// Storage: `StatemintAssets::Asset` (r:1 w:1) - /// Proof: `StatemintAssets::Asset` (`max_values`: None, `max_size`: Some(210), added: 2685, mode: `MaxEncodedLen`) - /// Storage: `StatemintAssets::Account` (r:2 w:2) - /// Proof: `StatemintAssets::Account` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`) - /// Storage: `PolimecFunding::ProjectsToUpdate` (r:9833 w:1) - /// Proof: `PolimecFunding::ProjectsToUpdate` (`max_values`: None, `max_size`: Some(27), added: 2502, mode: `MaxEncodedLen`) - /// The range of component `x` is `[1, 255]`. + /// Storage: `ForeignAssets::Asset` (r:1 w:1) + /// Proof: `ForeignAssets::Asset` (`max_values`: None, `max_size`: Some(210), added: 2685, mode: `MaxEncodedLen`) + /// Storage: `ForeignAssets::Account` (r:2 w:2) + /// Proof: `ForeignAssets::Account` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`) + /// Storage: `Funding::ProjectsToUpdate` (r:100 w:1) + /// Proof: `Funding::ProjectsToUpdate` (`max_values`: None, `max_size`: Some(26), added: 2501, mode: `MaxEncodedLen`) + /// The range of component `x` is `[0, 15]`. /// The range of component `y` is `[1, 99]`. - /// The range of component `z` is `[1, 10000]`. - fn contribution_ends_round(x: u32, y: u32 ) -> Weight { + fn contribution_ends_round(x: u32, y: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `44564 + x * (137 ±0) + y * (254 ±0) + z * (21 ±0)` - // Estimated: `15401 + x * (2839 ±0) + y * (92965 ±6_111) + z * (1905 ±59)` - // Minimum execution time: 1_120_000_000 picoseconds. - Weight::from_parts(55_806_166, 15401) - // Standard Error: 7_331_488 - .saturating_add(Weight::from_parts(111_668_126, 0).saturating_mul(y.into())) - // Standard Error: 71_852 - .saturating_add(RocksDbWeight::get().reads(17_u64)) - .saturating_add(RocksDbWeight::get().reads((37_u64).saturating_mul(y.into()))) - .saturating_add(RocksDbWeight::get().writes(8_u64)) - .saturating_add(Weight::from_parts(0, 2839).saturating_mul(x.into())) - .saturating_add(Weight::from_parts(0, 92965).saturating_mul(y.into())) + // Measured: `3093 + x * (134 ±0) + y * (28 ±0)` + // Estimated: `6208 + x * (2669 ±0) + y * (2501 ±0)` + // Minimum execution time: 269_000_000 picoseconds. + Weight::from_parts(243_223_951, 6208) + // Standard Error: 103_493 + .saturating_add(Weight::from_parts(3_497_884, 0).saturating_mul(x.into())) + // Standard Error: 16_476 + .saturating_add(Weight::from_parts(1_907_293, 0).saturating_mul(y.into())) + .saturating_add(RocksDbWeight::get().reads(16_u64)) + .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(x.into()))) + .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(y.into()))) + .saturating_add(RocksDbWeight::get().writes(10_u64)) + .saturating_add(Weight::from_parts(0, 2669).saturating_mul(x.into())) + .saturating_add(Weight::from_parts(0, 2501).saturating_mul(y.into())) } /// Storage: `PolimecFunding::ProjectsDetails` (r:1 w:0) /// Proof: `PolimecFunding::ProjectsDetails` (`max_values`: None, `max_size`: Some(349), added: 2824, mode: `MaxEncodedLen`)