Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

paras: adjust weights for root dispatchables #6347

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 3 additions & 0 deletions runtime/kusama/src/weights/runtime_parachains_paras.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,7 @@ impl<T: frame_system::Config> runtime_parachains::paras::WeightInfo for WeightIn
.saturating_add(T::DbWeight::get().reads(5 as u64))
.saturating_add(T::DbWeight::get().writes(304 as u64))
}
fn force_schedule_code_upgrade_pvf_checking_enabled(_c: u32) -> Weight {
Weight::MAX
}
}
14 changes: 13 additions & 1 deletion runtime/parachains/src/paras/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use sp_runtime::traits::{One, Saturating};

mod pvf_check;

use self::pvf_check::{VoteCause, VoteOutcome};
use self::pvf_check::{enable_pvf_checking, VoteCause, VoteOutcome};

// 2 ^ 10, because binary search time complexity is O(log(2, n)) and n = 1024 gives us a big and
// round number.
Expand Down Expand Up @@ -109,6 +109,18 @@ benchmarks! {
verify {
assert_last_event::<T>(Event::CodeUpgradeScheduled(para_id).into());
}
force_schedule_code_upgrade_pvf_checking_enabled {
let c in 1 .. MAX_CODE_SIZE;
let new_code = ValidationCode(vec![0; c as usize]);
let para_id = ParaId::from(c as u32);
let block = T::BlockNumber::from(c);

enable_pvf_checking::<T>();
generate_disordered_upgrades::<T>();
}: _(RawOrigin::Root, para_id, new_code, block)
verify {
assert_last_event::<T>(Event::CodeUpgradeScheduled(para_id).into());
}
force_note_new_head {
let s in 1 .. MAX_HEAD_DATA_SIZE;
let para_id = ParaId::from(1000);
Expand Down
13 changes: 9 additions & 4 deletions runtime/parachains/src/paras/benchmarking/pvf_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ fn old_validation_code() -> ValidationCode {
ValidationCode(vec![1])
}

/// Enables pvf-checking in the configuration pallet.
pub fn enable_pvf_checking<T: Config>() {
let mut config = configuration::Pallet::<T>::config();
config.pvf_checking_enabled = true;
configuration::Pallet::<T>::force_set_active_config(config);
}

/// Prepares the PVF check statement and the validator signature to pass into
/// `include_pvf_check_statement` during benchmarking phase.
///
Expand Down Expand Up @@ -109,9 +116,7 @@ where
.collect::<Vec<_>>();

// 1. Make sure PVF pre-checking is enabled in the config.
let mut config = configuration::Pallet::<T>::config();
config.pvf_checking_enabled = true;
configuration::Pallet::<T>::force_set_active_config(config.clone());
enable_pvf_checking::<T>();

// 2. initialize a new session with deterministic validator set.
ParasShared::<T>::set_active_validators_ascending(validators.clone());
Expand All @@ -122,7 +127,7 @@ where
///
/// The subject of the vote (i.e. validation code) and the cause (upgrade/onboarding) is specified
/// by the test setup.
fn initialize_pvf_active_vote<T>(vote_cause: VoteCause)
pub fn initialize_pvf_active_vote<T>(vote_cause: VoteCause)
where
T: Config + shared::Config,
{
Expand Down
29 changes: 25 additions & 4 deletions runtime/parachains/src/paras/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,12 @@ impl<BlockNumber> PvfCheckActiveVoteState<BlockNumber> {
pub trait WeightInfo {
fn force_set_current_code(c: u32) -> Weight;
fn force_set_current_head(s: u32) -> Weight;
fn force_schedule_code_upgrade(c: u32) -> Weight;
fn force_note_new_head(s: u32) -> Weight;
fn force_queue_action() -> Weight;

fn force_schedule_code_upgrade(c: u32) -> Weight;
fn force_schedule_code_upgrade_pvf_checking_enabled(c: u32) -> Weight;

fn add_trusted_validation_code(c: u32) -> Weight;
fn poke_unused_validation_code() -> Weight;

Expand All @@ -491,6 +494,9 @@ impl WeightInfo for TestWeightInfo {
fn force_schedule_code_upgrade(_c: u32) -> Weight {
Weight::MAX
}
fn force_schedule_code_upgrade_pvf_checking_enabled(_c: u32) -> Weight {
Weight::MAX
}
fn force_note_new_head(_s: u32) -> Weight {
Weight::MAX
}
Expand Down Expand Up @@ -827,18 +833,33 @@ pub mod pallet {
}

/// Schedule an upgrade as if it was scheduled in the given relay parent block.
#[pallet::weight(<T as Config>::WeightInfo::force_schedule_code_upgrade(new_code.0.len() as u32))]
#[pallet::weight(
<T as Config>::WeightInfo::force_schedule_code_upgrade(new_code.0.len() as u32).max(
<T as Config>::WeightInfo::force_schedule_code_upgrade_pvf_checking_enabled(
new_code.0.len() as u32
)
)
)]
pub fn force_schedule_code_upgrade(
origin: OriginFor<T>,
para: ParaId,
new_code: ValidationCode,
relay_parent_number: T::BlockNumber,
) -> DispatchResult {
) -> DispatchResultWithPostInfo {
ensure_root(origin)?;
let config = configuration::Pallet::<T>::config();
let new_code_len = new_code.0.len() as u32;
Self::schedule_code_upgrade(para, new_code, relay_parent_number, &config);
Self::deposit_event(Event::CodeUpgradeScheduled(para));
Ok(())

let actual_weight = if config.pvf_checking_enabled {
<T as Config>::WeightInfo::force_schedule_code_upgrade_pvf_checking_enabled(
new_code_len,
)
} else {
<T as Config>::WeightInfo::force_schedule_code_upgrade(new_code_len)
};
Ok(Some(actual_weight).into())
}

/// Note a new block head for para within the context of the current block.
Expand Down
3 changes: 3 additions & 0 deletions runtime/polkadot/src/weights/runtime_parachains_paras.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,7 @@ impl<T: frame_system::Config> runtime_parachains::paras::WeightInfo for WeightIn
.saturating_add(T::DbWeight::get().reads(6 as u64))
.saturating_add(T::DbWeight::get().writes(304 as u64))
}
fn force_schedule_code_upgrade_pvf_checking_enabled(_c: u32) -> Weight {
Weight::MAX
}
}
3 changes: 3 additions & 0 deletions runtime/rococo/src/weights/runtime_parachains_paras.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,7 @@ impl<T: frame_system::Config> runtime_parachains::paras::WeightInfo for WeightIn
.saturating_add(T::DbWeight::get().reads(6 as u64))
.saturating_add(T::DbWeight::get().writes(304 as u64))
}
fn force_schedule_code_upgrade_pvf_checking_enabled(_c: u32) -> Weight {
Weight::MAX
}
}
3 changes: 3 additions & 0 deletions runtime/westend/src/weights/runtime_parachains_paras.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,7 @@ impl<T: frame_system::Config> runtime_parachains::paras::WeightInfo for WeightIn
.saturating_add(T::DbWeight::get().reads(5 as u64))
.saturating_add(T::DbWeight::get().writes(304 as u64))
}
fn force_schedule_code_upgrade_pvf_checking_enabled(_c: u32) -> Weight {
Weight::MAX
}
}