difftreelog
refactor(preimage-execution) remove preimage length bound + fix benchmarks
in: master
7 files changed
Makefilediffbeforeafterboth137bench-app-promotion:137bench-app-promotion:138 make _bench PALLET=app-promotion PALLET_DIR=app-promotion138 make _bench PALLET=app-promotion PALLET_DIR=app-promotion139140.PHONY: bench-maintenance141bench-maintenance:142 make _bench PALLET=maintenance139143140.PHONY: bench144.PHONY: bench141# Disabled: bench-scheduler, bench-collator-selection, bench-identity145# Disabled: bench-scheduler, bench-collator-selection, bench-identity142bench: bench-common bench-evm-migration bench-unique bench-structure bench-fungible bench-refungible bench-nonfungible bench-configuration bench-foreign-assets146bench: bench-common bench-evm-migration bench-unique bench-structure bench-fungible bench-refungible bench-nonfungible bench-configuration bench-foreign-assets bench-maintenance143147144.PHONY: check148.PHONY: check145check:149check:pallets/maintenance/src/benchmarking.rsdiffbeforeafterboth17use super::*;17use super::*;18use crate::{Pallet as Maintenance, Config};18use crate::{Pallet as Maintenance, Config};191920use codec::Encode;20use frame_benchmarking::benchmarks;21use frame_benchmarking::benchmarks;21use frame_system::{Call as RuntimeCall, RawOrigin};22use frame_system::RawOrigin;22use frame_support::{ensure, pallet_prelude::Weight, traits::StorePreimage};23use frame_support::{ensure, pallet_prelude::Weight, traits::StorePreimage};23use codec::Encode;24use sp_std::vec;252426benchmarks! {25benchmarks! {27 enable {26 enable {38 }37 }393840 execute_preimage {39 execute_preimage {41 let call_hash = RuntimeCall::<T>::set_storage { items: vec![] }.encode();40 let call = <T as Config>::RuntimeCall::from(frame_system::Call::<T>::remark { remark: 1u32.encode() });42 let hash = T::Preimages::note(call_hash.into())?;41 let hash = T::Preimages::note(call.encode().into())?;43 }: _(RawOrigin::Root, hash, None, Weight::from_parts(100000000000, 100000000000))42 }: _(RawOrigin::Root, hash, Weight::from_parts(100000000000, 100000000000))44 verify {43 verify {45 }44 }46}45}pallets/maintenance/src/lib.rsdiffbeforeafterboth102 Ok(())102 Ok(())103 }103 }104104105 /// Execute a runtime call stored as a preimage.106 ///107 /// `weight_bound` is the maximum weight that the caller is willing108 /// to allow the extrinsic to be executed with.105 #[pallet::call_index(2)]109 #[pallet::call_index(2)]106 #[pallet::weight(<T as Config>::WeightInfo::execute_preimage())]110 #[pallet::weight(<T as Config>::WeightInfo::execute_preimage())]107 pub fn execute_preimage(111 pub fn execute_preimage(108 origin: OriginFor<T>,112 origin: OriginFor<T>,109 hash: H256,113 hash: H256,110 preimage_length: Option<u32>,111 weight_bound: Weight,114 weight_bound: Weight,112 ) -> DispatchResultWithPostInfo {115 ) -> DispatchResultWithPostInfo {113 use codec::Decode;116 use codec::Decode;114117115 ensure_root(origin)?;118 ensure_root(origin)?;116119117 let data = T::Preimages::fetch(&hash, preimage_length)?;120 let data = T::Preimages::fetch(&hash, None)?;118 weight_bound.set_proof_size(121 weight_bound.set_proof_size(119 weight_bound122 weight_bound120 .proof_size()123 .proof_size()135 );138 );136139137 match call.dispatch(frame_system::RawOrigin::Root.into()) {140 match call.dispatch(frame_system::RawOrigin::Root.into()) {138 Ok(post_info) => Ok(PostDispatchInfo {141 Ok(_) => Ok(Pays::No.into()),139 actual_weight: post_info.actual_weight,140 pays_fee: Pays::No,141 }),142 Err(error_and_info) => Err(DispatchErrorWithPostInfo {142 Err(error_and_info) => Err(DispatchErrorWithPostInfo {143 post_info: PostDispatchInfo {143 post_info: Pays::No.into(),144 actual_weight: error_and_info.post_info.actual_weight,145 pays_fee: Pays::No,146 },147 error: error_and_info.error,144 error: error_and_info.error,148 }),145 }),149 }146 }pallets/maintenance/src/weights.rsdiffbeforeafterboth3//! Autogenerated weights for pallet_maintenance3//! Autogenerated weights for pallet_maintenance4//!4//!5//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev5//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev6//! DATE: 2022-11-01, STEPS: `50`, REPEAT: 80, LOW RANGE: `[]`, HIGH RANGE: `[]`6//! DATE: 2023-02-22, STEPS: `50`, REPEAT: 80, LOW RANGE: `[]`, HIGH RANGE: `[]`7//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 10247//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024889// Executed Command:9// Executed Command:26#![cfg_attr(rustfmt, rustfmt_skip)]26#![cfg_attr(rustfmt, rustfmt_skip)]27#![allow(unused_parens)]27#![allow(unused_parens)]28#![allow(unused_imports)]28#![allow(unused_imports)]29#![allow(missing_docs)]29#![allow(clippy::unnecessary_cast)]30#![allow(clippy::unnecessary_cast)]303131use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};32use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};43impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {44impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {44 // Storage: Maintenance Enabled (r:0 w:1)45 // Storage: Maintenance Enabled (r:0 w:1)45 fn enable() -> Weight {46 fn enable() -> Weight {46 Weight::from_ref_time(7_367_000)47 Weight::from_ref_time(10_860_000 as u64)47 .saturating_add(T::DbWeight::get().writes(1))48 .saturating_add(T::DbWeight::get().writes(1 as u64))48 }49 }49 // Storage: Maintenance Enabled (r:0 w:1)50 // Storage: Maintenance Enabled (r:0 w:1)50 fn disable() -> Weight {51 fn disable() -> Weight {51 Weight::from_ref_time(7_273_000)52 Weight::from_ref_time(10_871_000 as u64)52 .saturating_add(T::DbWeight::get().writes(1))53 .saturating_add(T::DbWeight::get().writes(1 as u64))53 }54 }54 // Storage: 55 // Storage: Preimage StatusFor (r:1 w:0)56 // Storage: Preimage PreimageFor (r:1 w:0)55 fn execute_preimage() -> Weight {57 fn execute_preimage() -> Weight {56 Weight::from_ref_time(7_273_000)58 Weight::from_ref_time(10_068_000 as u64)57 .saturating_add(T::DbWeight::get().reads(2))58 .saturating_add(T::DbWeight::get().writes(1))59 .saturating_add(T::DbWeight::get().reads(2 as u64))59 }60 }60}61}616262// For backwards compatibility and tests63// For backwards compatibility and tests63impl WeightInfo for () {64impl WeightInfo for () {64 // Storage: Maintenance Enabled (r:0 w:1)65 // Storage: Maintenance Enabled (r:0 w:1)65 fn enable() -> Weight {66 fn enable() -> Weight {66 Weight::from_ref_time(7_367_000)67 Weight::from_ref_time(10_860_000 as u64)67 .saturating_add(RocksDbWeight::get().writes(1))68 .saturating_add(RocksDbWeight::get().writes(1 as u64))68 }69 }69 // Storage: Maintenance Enabled (r:0 w:1)70 // Storage: Maintenance Enabled (r:0 w:1)70 fn disable() -> Weight {71 fn disable() -> Weight {71 Weight::from_ref_time(7_273_000)72 Weight::from_ref_time(10_871_000 as u64)72 .saturating_add(RocksDbWeight::get().writes(1))73 .saturating_add(RocksDbWeight::get().writes(1 as u64))73 }74 }74 // Storage: 75 // Storage: Preimage StatusFor (r:1 w:0)76 // Storage: Preimage PreimageFor (r:1 w:0)75 fn execute_preimage() -> Weight {77 fn execute_preimage() -> Weight {76 Weight::from_ref_time(7_273_000)78 Weight::from_ref_time(10_068_000 as u64)77 .saturating_add(RocksDbWeight::get().reads(2))78 .saturating_add(RocksDbWeight::get().writes(1))79 .saturating_add(RocksDbWeight::get().reads(2 as u64))79 }80 }80}81}8182runtime/common/maintenance.rsdiffbeforeafterboth86 | RuntimeCall::Session(_)86 | RuntimeCall::Session(_)87 | RuntimeCall::Identity(_) => Err(TransactionValidityError::Invalid(InvalidTransaction::Call)),87 | RuntimeCall::Identity(_) => Err(TransactionValidityError::Invalid(InvalidTransaction::Call)),8889 #[cfg(feature = "preimage")]90 RuntimeCall::Preimage(_) => Err(TransactionValidityError::Invalid(InvalidTransaction::Call)),918892 #[cfg(feature = "pallet-test-utils")]89 #[cfg(feature = "pallet-test-utils")]93 RuntimeCall::TestUtils(_) => Err(TransactionValidityError::Invalid(InvalidTransaction::Call)),90 RuntimeCall::TestUtils(_) => Err(TransactionValidityError::Invalid(InvalidTransaction::Call)),runtime/common/runtime_apis.rsdiffbeforeafterboth568 #[cfg(feature = "foreign-assets")]568 #[cfg(feature = "foreign-assets")]569 list_benchmark!(list, extra, pallet_foreign_assets, ForeignAssets);569 list_benchmark!(list, extra, pallet_foreign_assets, ForeignAssets);570570571 list_benchmark!(list, extra, pallet_maintenance, Maintenance);571572572 // list_benchmark!(list, extra, pallet_evm_coder_substrate, EvmCoderSubstrate);573 // list_benchmark!(list, extra, pallet_evm_coder_substrate, EvmCoderSubstrate);573574632 #[cfg(feature = "foreign-assets")]633 #[cfg(feature = "foreign-assets")]633 add_benchmark!(params, batches, pallet_foreign_assets, ForeignAssets);634 add_benchmark!(params, batches, pallet_foreign_assets, ForeignAssets);635636 add_benchmark!(params, batches, pallet_maintenance, Maintenance);634637635 // add_benchmark!(params, batches, pallet_evm_coder_substrate, EvmCoderSubstrate);638 // add_benchmark!(params, batches, pallet_evm_coder_substrate, EvmCoderSubstrate);636639tests/src/maintenance.seqtest.tsdiffbeforeafterboth279 });279 });280280281 describe('Preimage Execution', () => {281 describe('Preimage Execution', () => {282 let preimageHash: string;282 const preimageHashes: string[] = [];283283284 async function notePreimage(helper: UniqueHelper, preimage: any): Promise<string> {284 async function notePreimage(helper: UniqueHelper, preimage: any): Promise<string> {285 const result = await helper.preimage.notePreimage(bob, preimage);285 const result = await helper.preimage.notePreimage(bob, preimage);306 },306 },307 ]);307 ]);308 const preimage = helper.constructApiCall('api.tx.identity.forceInsertIdentities', [randomIdentities]).method.toHex();308 const preimage = helper.constructApiCall('api.tx.identity.forceInsertIdentities', [randomIdentities]).method.toHex();309 preimageHash = await notePreimage(helper, preimage);309 preimageHashes.push(await notePreimage(helper, preimage));310 });310 });311 });311 });312312313 itSub('Successfully executes call in a preimage', async ({helper}) => {313 itSub('Successfully executes call in a preimage', async ({helper}) => {314 const result = await expect(helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.executePreimage', [314 const result = await expect(helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.executePreimage', [315 preimageHash, null, {refTime: 10000000000, proofSize: 10000000000},315 preimageHashes[0], {refTime: 10000000000, proofSize: 10000000000},316 ])).to.be.fulfilled;316 ])).to.be.fulfilled;317317318 // preimage is executed, and an appropriate event is present318 // preimage is executed, and an appropriate event is present319 const events = result.result.events.filter((x: any) => x.event.method === 'IdentitiesInserted' && x.event.section === 'identity');319 const events = result.result.events.filter((x: any) => x.event.method === 'IdentitiesInserted' && x.event.section === 'identity');320 expect(events.length).to.be.equal(1);320 expect(events.length).to.be.equal(1);321321322 // the preimage goes back to being unrequested322 // the preimage goes back to being unrequested323 expect(await helper.preimage.getPreimageInfo(preimageHash)).to.have.property('unrequested');323 expect(await helper.preimage.getPreimageInfo(preimageHashes[0])).to.have.property('unrequested');324 });324 });325325326 itSub('Does not allow execution of a preimage that would fail', async ({helper}) => {326 itSub('Does not allow execution of a preimage that would fail', async ({helper}) => {330 {Id: zeroAccount.address}, {Id: superuser.address}, 1000n,330 {Id: zeroAccount.address}, {Id: superuser.address}, 1000n,331 ]).method.toHex();331 ]).method.toHex();332 const preimageHash = await notePreimage(helper, preimage);332 const preimageHash = await notePreimage(helper, preimage);333 preimageHashes.push(preimageHash);333334334 await expect(helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.executePreimage', [335 await expect(helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.executePreimage', [335 preimageHash, null, {refTime: 100000000000, proofSize: 100000000000},336 preimageHash, {refTime: 100000000000, proofSize: 100000000000},336 ])).to.be.rejectedWith(/balances\.InsufficientBalance/);337 ])).to.be.rejectedWith(/balances\.InsufficientBalance/);337 });338 });338339339 itSub('Does not allow preimage execution with non-root', async ({helper}) => {340 itSub('Does not allow preimage execution with non-root', async ({helper}) => {340 await expect(helper.executeExtrinsic(bob, 'api.tx.maintenance.executePreimage', [341 await expect(helper.executeExtrinsic(bob, 'api.tx.maintenance.executePreimage', [341 preimageHash, null, {refTime: 100000000000, proofSize: 100000000000},342 preimageHashes[0], {refTime: 100000000000, proofSize: 100000000000},342 ])).to.be.rejectedWith(/BadOrigin/);343 ])).to.be.rejectedWith(/BadOrigin/);343 });344 });344345345 itSub('Does not allow execution of non-existent preimages', async ({helper}) => {346 itSub('Does not allow execution of non-existent preimages', async ({helper}) => {346 await expect(helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.executePreimage', [347 await expect(helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.executePreimage', [347 '0x1010101010101010101010101010101010101010101010101010101010101010', null, {refTime: 100000000000, proofSize: 100000000000},348 '0x1010101010101010101010101010101010101010101010101010101010101010', {refTime: 100000000000, proofSize: 100000000000},348 ])).to.be.rejectedWith(/Unavailable/);349 ])).to.be.rejectedWith(/Unavailable/);349 });350 });350351351 itSub('Does not allow preimage execution with less than minimum weights', async ({helper}) => {352 itSub('Does not allow preimage execution with less than minimum weights', async ({helper}) => {352 await expect(helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.executePreimage', [353 await expect(helper.getSudo().executeExtrinsic(superuser, 'api.tx.maintenance.executePreimage', [353 preimageHash, null, {refTime: 1000, proofSize: 1000},354 preimageHashes[0], {refTime: 1000, proofSize: 1000},354 ])).to.be.rejectedWith(/Exhausted/);355 ])).to.be.rejectedWith(/Exhausted/);355 });356 });356357357 after(async function() {358 after(async function() {358 await usingPlaygrounds(async (helper) => {359 await usingPlaygrounds(async (helper) => {359 if (helper.fetchMissingPalletNames([Pallets.Preimage, Pallets.Maintenance]).length != 0) return;360 if (helper.fetchMissingPalletNames([Pallets.Preimage, Pallets.Maintenance]).length != 0) return;360361362 for (const hash of preimageHashes) {361 await helper.preimage.unnotePreimage(bob, preimageHash);363 await helper.preimage.unnotePreimage(bob, hash);364 }362 });365 });363 });366 });364 });367 });