-
Notifications
You must be signed in to change notification settings - Fork 803
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into gui-test-ci
- Loading branch information
Showing
119 changed files
with
4,286 additions
and
690 deletions.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,63 @@ | ||
[package] | ||
name = "cumulus-pallet-weight-reclaim" | ||
version = "1.0.0" | ||
authors.workspace = true | ||
edition.workspace = true | ||
license = "Apache-2.0" | ||
homepage.workspace = true | ||
repository.workspace = true | ||
description = "pallet and transaction extensions for accurate proof size reclaim" | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] | ||
|
||
[dependencies] | ||
# Substrate dependencies | ||
sp-io = { workspace = true } | ||
sp-runtime = { workspace = true } | ||
sp-trie = { workspace = true } | ||
|
||
cumulus-primitives-storage-weight-reclaim = { workspace = true } | ||
frame-benchmarking = { optional = true, workspace = true } | ||
frame-support = { workspace = true } | ||
frame-system = { workspace = true } | ||
|
||
# Other dependencies | ||
codec = { features = ["derive"], workspace = true } | ||
derivative = { features = ["use_core"], workspace = true } | ||
docify = { workspace = true } | ||
log = { workspace = true, default-features = true } | ||
scale-info = { features = ["derive"], workspace = true } | ||
|
||
[dev-dependencies] | ||
cumulus-primitives-proof-size-hostfunction = { workspace = true } | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"codec/std", | ||
"cumulus-primitives-proof-size-hostfunction/std", | ||
"cumulus-primitives-storage-weight-reclaim/std", | ||
"frame-benchmarking?/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
"log/std", | ||
"scale-info/std", | ||
"sp-io/std", | ||
"sp-runtime/std", | ||
"sp-trie/std", | ||
] | ||
runtime-benchmarks = [ | ||
"frame-benchmarking/runtime-benchmarks", | ||
"frame-support/runtime-benchmarks", | ||
"frame-system/runtime-benchmarks", | ||
"sp-runtime/runtime-benchmarks", | ||
] | ||
try-runtime = [ | ||
"frame-support/try-runtime", | ||
"frame-system/try-runtime", | ||
"sp-runtime/try-runtime", | ||
] |
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,71 @@ | ||
// Copyright (C) Parity Technologies (UK) Ltd. | ||
// This file is part of Cumulus. | ||
|
||
// Cumulus 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. | ||
|
||
// Cumulus 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 Cumulus. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
#![cfg(feature = "runtime-benchmarks")] | ||
|
||
use super::*; | ||
use frame_support::pallet_prelude::{DispatchClass, Pays}; | ||
use frame_system::RawOrigin; | ||
use sp_runtime::traits::{AsTransactionAuthorizedOrigin, DispatchTransaction}; | ||
|
||
#[frame_benchmarking::v2::benchmarks( | ||
where T: Send + Sync, | ||
<T as frame_system::Config>::RuntimeCall: | ||
Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>, | ||
<T as frame_system::Config>::RuntimeOrigin: AsTransactionAuthorizedOrigin, | ||
)] | ||
mod bench { | ||
use super::*; | ||
use frame_benchmarking::impl_test_function; | ||
|
||
#[benchmark] | ||
fn storage_weight_reclaim() { | ||
let ext = StorageWeightReclaim::<T, ()>::new(()); | ||
|
||
let origin = RawOrigin::Root.into(); | ||
let call = T::RuntimeCall::from(frame_system::Call::remark { remark: alloc::vec![] }); | ||
|
||
let overestimate = 10_000; | ||
let info = DispatchInfo { | ||
call_weight: Weight::zero().add_proof_size(overestimate), | ||
extension_weight: Weight::zero(), | ||
class: DispatchClass::Normal, | ||
pays_fee: Pays::No, | ||
}; | ||
|
||
let post_info = PostDispatchInfo { actual_weight: None, pays_fee: Pays::No }; | ||
|
||
let mut block_weight = frame_system::ConsumedWeight::default(); | ||
block_weight.accrue(Weight::from_parts(0, overestimate), info.class); | ||
|
||
frame_system::BlockWeight::<T>::put(block_weight); | ||
|
||
#[block] | ||
{ | ||
assert!(ext.test_run(origin, &call, &info, 0, 0, |_| Ok(post_info)).unwrap().is_ok()); | ||
} | ||
|
||
let final_block_proof_size = | ||
frame_system::BlockWeight::<T>::get().get(info.class).proof_size(); | ||
|
||
assert!( | ||
final_block_proof_size < overestimate, | ||
"The proof size measured should be less than {overestimate}" | ||
); | ||
} | ||
|
||
impl_benchmark_test_suite!(Pallet, crate::tests::setup_test_ext_default(), crate::tests::Test); | ||
} |
Oops, something went wrong.