This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Change the Config of the MaxRococoNum Slot from a Constant to a Storage function #7217
Merged
paritytech-processbot
merged 61 commits into
master
from
alexd10s/revamp_assigned_slots_rococo
Aug 15, 2023
Merged
Changes from all commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
1217e20
set MaxPermanentSlots and MaxTemporarySlots with a extrinsic instead …
AlexD10S 8a0d765
delete the MaxPermanentSlots and MaxTemporarySlots constants from co…
AlexD10S 74daef0
merge master
AlexD10S 2d7f78f
migration code for assigned slots
AlexD10S ef02259
remove getters
AlexD10S c1792f2
little refactor
AlexD10S 89992b1
set values in the GenesisConfig
AlexD10S f68e45a
refactor in the migration, adding it in the rococo runtime
AlexD10S 9bc0f07
refactor: fmt
AlexD10S d189c76
Minor fix
al3mart 2bbbda7
pre_upgrade check
al3mart 81e269c
add migration to mod v1
al3mart 09c691b
Logs following Substrate#12873
al3mart 110ff1d
fix: current storage version set to 1
AlexD10S 6e18128
Merge branch 'master' into alexd10s/revamp_assigned_slots_rococo
al3mart e77d8d7
use enact when try-runtime
al3mart 98b2a38
Vec seems to be missing
al3mart 87c988b
merge master
al3mart eccbe04
feature gate import
al3mart 3ac81c7
merge master
al3mart 4fedca4
fix as per #13993
al3mart 25f1d71
address comments
al3mart 86b4e8f
address comments
al3mart 6854094
benchmarking for assign_perm_parachain_slot extrinsic
AlexD10S d95157f
benchmark all the extrinsics of the pallet
AlexD10S 4067e2e
merge master branch
AlexD10S 3142816
cargo fmt for assigned slots
AlexD10S 2f36bb8
migration added for westend
AlexD10S a944d52
Merge branch 'master' into alexd10s/revamp_assigned_slots_rococo
AlexD10S 9705b9d
licence in benchmarking file
AlexD10S c993252
Merge branch 'master' into alexd10s/revamp_assigned_slots_rococo
al3mart c04fb38
BuildGenesisConfig
al3mart a3af0ff
assigned_slots default in genesis
AlexD10S 03dd31b
cargo fmt
AlexD10S 1c059af
assigned_slots fix tests config
AlexD10S 200597a
cargo fmt
AlexD10S 5c2b2eb
fix benchmarking compile error
AlexD10S 4b5130c
Merge branch 'master' into alexd10s/revamp_assigned_slots_rococo
AlexD10S 473d073
fix benchmarking imports
AlexD10S 1cb2362
benchmark worst case scenario for validation code and head data
AlexD10S cbffba0
add assigned_slots in frame_benchmarking on Rococo and Westend
AlexD10S ca65088
modify values for para_id in benchmarking
AlexD10S 61b6a95
delete the assigned_slots in westend frame_benchmarking
AlexD10S 7be2dc0
fix benchmarkings and add it to westend
AlexD10S 34e8bc1
cargo fmt
AlexD10S 216cdb1
Merge branch 'master' of https://github.com/paritytech/polkadot into …
86f977f
".git/.scripts/commands/bench/bench.sh" --subcommand=runtime --runtim…
8b0d088
".git/.scripts/commands/bench/bench.sh" --subcommand=runtime --runtim…
38ea151
use generated weights in assigned_slots pallet
AlexD10S a022c7b
small changes in set_max_permanent_slots and set_max_temporary_slots
AlexD10S 86015e5
revert last commit
AlexD10S 4e5bcb8
Merge branch 'master' into alexd10s/revamp_assigned_slots_rococo
AlexD10S 9603fc6
address some comments
AlexD10S 176c8b3
wrap migration with VersionCheckedMigrateToV1
AlexD10S cd237a7
add experimental feature in pallet, and assers in post_upgrade migration
AlexD10S 795aed4
clean warnings
AlexD10S 16d2c52
clean unnecesary experimental flag
AlexD10S 9c6cf4b
Merge branch 'master' into alexd10s/revamp_assigned_slots_rococo
AlexD10S e855ce3
small typo in comments
AlexD10S 1061caa
cargo fmt
AlexD10S 9095fd0
small comments fixes
AlexD10S File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
// Copyright (C) Parity Technologies (UK) Ltd. | ||
// This file is part of Polkadot. | ||
|
||
// Polkadot is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Polkadot is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
//! Benchmarking for assigned_slots pallet | ||
|
||
#![cfg(feature = "runtime-benchmarks")] | ||
use super::*; | ||
|
||
use frame_benchmarking::v2::*; | ||
use frame_support::assert_ok; | ||
use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin}; | ||
use primitives::Id as ParaId; | ||
use sp_runtime::traits::Bounded; | ||
|
||
type CurrencyOf<T> = <<T as Config>::Leaser as Leaser<BlockNumberFor<T>>>::Currency; | ||
type BalanceOf<T> = <<<T as Config>::Leaser as Leaser<BlockNumberFor<T>>>::Currency as Currency< | ||
<T as frame_system::Config>::AccountId, | ||
>>::Balance; | ||
#[benchmarks(where T: Config)] | ||
mod benchmarks { | ||
use super::*; | ||
|
||
use crate::assigned_slots::Pallet as AssignedSlots; | ||
|
||
fn register_parachain<T: Config>(para_id: ParaId) { | ||
let who: T::AccountId = whitelisted_caller(); | ||
let worst_validation_code = T::Registrar::worst_validation_code(); | ||
let worst_head_data = T::Registrar::worst_head_data(); | ||
|
||
CurrencyOf::<T>::make_free_balance_be(&who, BalanceOf::<T>::max_value()); | ||
|
||
assert_ok!(T::Registrar::register( | ||
who, | ||
para_id, | ||
worst_head_data, | ||
worst_validation_code.clone() | ||
)); | ||
assert_ok!(paras::Pallet::<T>::add_trusted_validation_code( | ||
frame_system::Origin::<T>::Root.into(), | ||
worst_validation_code, | ||
)); | ||
T::Registrar::execute_pending_transitions(); | ||
} | ||
|
||
#[benchmark] | ||
fn assign_perm_parachain_slot() { | ||
let para_id = ParaId::from(1_u32); | ||
let caller = RawOrigin::Root; | ||
|
||
let _ = | ||
AssignedSlots::<T>::set_max_permanent_slots(frame_system::Origin::<T>::Root.into(), 10); | ||
register_parachain::<T>(para_id); | ||
|
||
let counter = PermanentSlotCount::<T>::get(); | ||
let current_lease_period: BlockNumberFor<T> = | ||
T::Leaser::lease_period_index(frame_system::Pallet::<T>::block_number()) | ||
.and_then(|x| Some(x.0)) | ||
.unwrap(); | ||
#[extrinsic_call] | ||
assign_perm_parachain_slot(caller, para_id); | ||
|
||
assert_eq!( | ||
PermanentSlots::<T>::get(para_id), | ||
Some(( | ||
current_lease_period, | ||
LeasePeriodOf::<T>::from(T::PermanentSlotLeasePeriodLength::get()), | ||
)) | ||
); | ||
assert_eq!(PermanentSlotCount::<T>::get(), counter + 1); | ||
} | ||
|
||
#[benchmark] | ||
fn assign_temp_parachain_slot() { | ||
let para_id = ParaId::from(2_u32); | ||
let caller = RawOrigin::Root; | ||
|
||
let _ = | ||
AssignedSlots::<T>::set_max_temporary_slots(frame_system::Origin::<T>::Root.into(), 10); | ||
register_parachain::<T>(para_id); | ||
|
||
let current_lease_period: BlockNumberFor<T> = | ||
T::Leaser::lease_period_index(frame_system::Pallet::<T>::block_number()) | ||
.and_then(|x| Some(x.0)) | ||
.unwrap(); | ||
|
||
let counter = TemporarySlotCount::<T>::get(); | ||
#[extrinsic_call] | ||
assign_temp_parachain_slot(caller, para_id, SlotLeasePeriodStart::Current); | ||
|
||
let tmp = ParachainTemporarySlot { | ||
manager: whitelisted_caller(), | ||
period_begin: current_lease_period, | ||
period_count: LeasePeriodOf::<T>::from(T::TemporarySlotLeasePeriodLength::get()), | ||
last_lease: Some(BlockNumberFor::<T>::zero()), | ||
lease_count: 1, | ||
}; | ||
assert_eq!(TemporarySlots::<T>::get(para_id), Some(tmp)); | ||
assert_eq!(TemporarySlotCount::<T>::get(), counter + 1); | ||
} | ||
|
||
#[benchmark] | ||
fn unassign_parachain_slot() { | ||
let para_id = ParaId::from(3_u32); | ||
let caller = RawOrigin::Root; | ||
|
||
let _ = | ||
AssignedSlots::<T>::set_max_temporary_slots(frame_system::Origin::<T>::Root.into(), 10); | ||
register_parachain::<T>(para_id); | ||
|
||
let _ = AssignedSlots::<T>::assign_temp_parachain_slot( | ||
caller.clone().into(), | ||
para_id, | ||
SlotLeasePeriodStart::Current, | ||
); | ||
|
||
let counter = TemporarySlotCount::<T>::get(); | ||
#[extrinsic_call] | ||
unassign_parachain_slot(caller, para_id); | ||
|
||
assert_eq!(TemporarySlots::<T>::get(para_id), None); | ||
assert_eq!(TemporarySlotCount::<T>::get(), counter - 1); | ||
} | ||
|
||
#[benchmark] | ||
fn set_max_permanent_slots() { | ||
let caller = RawOrigin::Root; | ||
#[extrinsic_call] | ||
set_max_permanent_slots(caller, u32::MAX); | ||
|
||
assert_eq!(MaxPermanentSlots::<T>::get(), u32::MAX); | ||
} | ||
|
||
#[benchmark] | ||
fn set_max_temporary_slots() { | ||
let caller = RawOrigin::Root; | ||
#[extrinsic_call] | ||
set_max_temporary_slots(caller, u32::MAX); | ||
|
||
assert_eq!(MaxTemporarySlots::<T>::get(), u32::MAX); | ||
} | ||
|
||
impl_benchmark_test_suite!( | ||
AssignedSlots, | ||
crate::assigned_slots::tests::new_test_ext(), | ||
crate::assigned_slots::tests::Test, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright (C) Parity Technologies (UK) Ltd. | ||
// This file is part of Polkadot. | ||
|
||
// Polkadot is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Polkadot is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
use super::{Config, MaxPermanentSlots, MaxTemporarySlots, Pallet, LOG_TARGET}; | ||
use frame_support::{ | ||
dispatch::GetStorageVersion, | ||
traits::{Get, OnRuntimeUpgrade}, | ||
}; | ||
|
||
#[cfg(feature = "try-runtime")] | ||
use frame_support::ensure; | ||
#[cfg(feature = "try-runtime")] | ||
use sp_std::vec::Vec; | ||
|
||
pub mod v1 { | ||
|
||
use super::*; | ||
pub struct MigrateToV1<T>(sp_std::marker::PhantomData<T>); | ||
impl<T: Config> OnRuntimeUpgrade for MigrateToV1<T> { | ||
#[cfg(feature = "try-runtime")] | ||
fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::TryRuntimeError> { | ||
let onchain_version = Pallet::<T>::on_chain_storage_version(); | ||
ensure!(onchain_version < 1, "assigned_slots::MigrateToV1 migration can be deleted"); | ||
Ok(Default::default()) | ||
} | ||
|
||
fn on_runtime_upgrade() -> frame_support::weights::Weight { | ||
let onchain_version = Pallet::<T>::on_chain_storage_version(); | ||
if onchain_version < 1 { | ||
const MAX_PERMANENT_SLOTS: u32 = 100; | ||
const MAX_TEMPORARY_SLOTS: u32 = 100; | ||
|
||
<MaxPermanentSlots<T>>::put(MAX_PERMANENT_SLOTS); | ||
<MaxTemporarySlots<T>>::put(MAX_TEMPORARY_SLOTS); | ||
// Return the weight consumed by the migration. | ||
T::DbWeight::get().reads_writes(1, 3) | ||
} else { | ||
log::info!(target: LOG_TARGET, "MigrateToV1 should be removed"); | ||
T::DbWeight::get().reads(1) | ||
} | ||
} | ||
|
||
#[cfg(feature = "try-runtime")] | ||
fn post_upgrade(_state: Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> { | ||
let onchain_version = Pallet::<T>::on_chain_storage_version(); | ||
ensure!(onchain_version == 1, "assigned_slots::MigrateToV1 needs to be run"); | ||
assert_eq!(<MaxPermanentSlots<T>>::get(), 100); | ||
assert_eq!(<MaxTemporarySlots<T>>::get(), 100); | ||
Ok(()) | ||
} | ||
} | ||
|
||
/// [`VersionUncheckedMigrateToV1`] wrapped in a | ||
/// [`frame_support::migrations::VersionedRuntimeUpgrade`], ensuring the migration is only | ||
/// performed when on-chain version is 0. | ||
#[cfg(feature = "experimental")] | ||
pub type VersionCheckedMigrateToV1<T> = frame_support::migrations::VersionedRuntimeUpgrade< | ||
0, | ||
1, | ||
MigrateToV1<T>, | ||
Pallet<T>, | ||
<T as frame_system::Config>::DbWeight, | ||
>; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This dispatchable calls
configure_slot_lease
which calllease_out
which mutates aVec
(shouldn't it be changed toBoundedVec
?) that perhaps should be max. populated to mimic the worst case scenario. Not sure since it is only one read/write but the size of it could differ.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added the
worst_validation_code
andworst_head_data
functions from the palletRegistrar
to register a parachain in our benchmarkings, so we are taking the worst case scenarios now.