Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions nodes/parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 14 additions & 5 deletions nodes/parachain/src/chain_spec/politest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -202,9 +202,18 @@ fn testnet_genesis(
let accounts = endowed_accounts.iter().map(|(account, _)| account.clone()).collect::<Vec<_>>();

let funding_accounts = vec![
(<Runtime as pallet_funding::Config>::PalletId::get().into_account_truncating(), <Runtime as pallet_funding::Config>::NativeCurrency::minimum_balance()),
(<Runtime as pallet_funding::Config>::ProtocolGrowthTreasury::get(), <Runtime as pallet_funding::Config>::NativeCurrency::minimum_balance()),
(<Runtime as pallet_funding::Config>::ContributionTreasury::get(), <Runtime as pallet_funding::Config>::NativeCurrency::minimum_balance()),
(
<Runtime as pallet_funding::Config>::PalletId::get().into_account_truncating(),
<Runtime as pallet_funding::Config>::NativeCurrency::minimum_balance(),
),
(
<Runtime as pallet_funding::Config>::ProtocolGrowthTreasury::get(),
<Runtime as pallet_funding::Config>::NativeCurrency::minimum_balance(),
),
(
<Runtime as pallet_funding::Config>::ContributionTreasury::get(),
<Runtime as pallet_funding::Config>::NativeCurrency::minimum_balance(),
),
];
endowed_accounts.append(&mut funding_accounts.clone());

Expand Down
13 changes: 3 additions & 10 deletions pallets/funding/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,7 @@ pub fn fill_projects_to_update<T: Config>(
) {
// 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::<T>::try_append(expected_insertion_block, (&69u32, UpdateType::EvaluationEnd)).is_ok() {
continue;
}
ProjectsToUpdate::<T>::insert(expected_insertion_block, (&69u32, UpdateType::EvaluationEnd));
expected_insertion_block += 1u32.into();
}
}
Expand Down Expand Up @@ -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<T> = inst.current_block() + T::EvaluationDuration::get() + One::one();
let block_number: BlockNumberFor<T> = 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::<T>::try_append(block_number, (&69u32, UpdateType::EvaluationEnd)).is_ok() {
continue;
}
block_number += 1u32.into();
}
fill_projects_to_update::<T>(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);
Expand Down
3 changes: 2 additions & 1 deletion pallets/funding/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2009,9 +2009,10 @@ impl<T: Config> Pallet<T> {
// 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::<T>::try_append(block_number, store.clone()).is_err() {
if ProjectsToUpdate::<T>::get(block_number).is_some() {
block_number += 1u32.into();
} else {
ProjectsToUpdate::<T>::insert(block_number, store);
return Ok(i);
}
}
Expand Down
11 changes: 6 additions & 5 deletions pallets/funding/src/instantiator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1011,11 +1011,12 @@ impl<

pub fn get_update_block(&mut self, project_id: ProjectId, update_type: &UpdateType) -> Option<BlockNumberFor<T>> {
self.execute(|| {
ProjectsToUpdate::<T>::iter().find_map(|(block, update_vec)| {
update_vec
.iter()
.find(|(pid, update)| *pid == project_id && update == update_type)
.map(|(_pid, _update)| block)
ProjectsToUpdate::<T>::iter().find_map(|(block, update_tup)| {
if project_id == update_tup.0 && update_type == &update_tup.1 {
Some(block)
} else {
None
}
})
})
}
Expand Down
10 changes: 2 additions & 8 deletions pallets/funding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Config> = StorageMap<
_,
Blake2_128Concat,
BlockNumberFor<T>,
BoundedVec<(ProjectId, UpdateType), T::MaxProjectsToUpdatePerBlock>,
ValueQuery,
>;
pub type ProjectsToUpdate<T: Config> = StorageMap<_, Blake2_128Concat, BlockNumberFor<T>, (ProjectId, UpdateType)>;

#[pallet::storage]
/// Keep track of the PLMC bonds made to each project by each evaluator
Expand Down Expand Up @@ -1161,7 +1155,7 @@ pub mod pallet {
fn on_initialize(now: BlockNumberFor<T>) -> 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::<T>::take(now) {
if let Some((project_id, update_type)) = ProjectsToUpdate::<T>::take(now) {
match update_type {
// EvaluationRound -> AuctionInitializePeriod | ProjectFailed
UpdateType::EvaluationEnd => {
Expand Down
3 changes: 1 addition & 2 deletions pallets/funding/src/tests/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TestRuntime> = automatic_auction_start + i as u64;
let val: BoundedVec<(ProjectId, UpdateType), <TestRuntime as Config>::MaxProjectsToUpdatePerBlock> =
vec![(69u32, UpdateType::EvaluationEnd)].try_into().unwrap();
let val: (ProjectId, UpdateType) = (69u32, UpdateType::EvaluationEnd);
inst.execute(|| crate::ProjectsToUpdate::<TestRuntime>::insert(key, val));
}

Expand Down
142 changes: 80 additions & 62 deletions pallets/funding/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,43 +277,52 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
.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`)
Expand Down Expand Up @@ -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)
Comment thread
lrazovic marked this conversation as resolved.
/// 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`)
Expand Down