Skip to content

Commit

Permalink
Merge branch 'master' into gui-test-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
gui1117 authored Jan 6, 2025
2 parents ac8804a + 63c73bf commit 7fa88bd
Show file tree
Hide file tree
Showing 119 changed files with 4,286 additions and 690 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/runtimes-matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
{
"name": "glutton-westend",
"package": "glutton-westend-runtime",
"path": "cumulus/parachains/runtimes/gluttons/glutton-westend",
"path": "cumulus/parachains/runtimes/glutton/glutton-westend",
"header": "cumulus/file_header.txt",
"template": "cumulus/templates/xcm-bench-template.hbs",
"bench_features": "runtime-benchmarks",
Expand Down
50 changes: 35 additions & 15 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ members = [
"cumulus/pallets/parachain-system/proc-macro",
"cumulus/pallets/session-benchmarking",
"cumulus/pallets/solo-to-para",
"cumulus/pallets/weight-reclaim",
"cumulus/pallets/xcm",
"cumulus/pallets/xcmp-queue",
"cumulus/parachains/common",
Expand Down Expand Up @@ -717,6 +718,7 @@ cumulus-pallet-parachain-system = { path = "cumulus/pallets/parachain-system", d
cumulus-pallet-parachain-system-proc-macro = { path = "cumulus/pallets/parachain-system/proc-macro", default-features = false }
cumulus-pallet-session-benchmarking = { path = "cumulus/pallets/session-benchmarking", default-features = false }
cumulus-pallet-solo-to-para = { path = "cumulus/pallets/solo-to-para", default-features = false }
cumulus-pallet-weight-reclaim = { path = "cumulus/pallets/weight-reclaim", default-features = false }
cumulus-pallet-xcm = { path = "cumulus/pallets/xcm", default-features = false }
cumulus-pallet-xcmp-queue = { path = "cumulus/pallets/xcmp-queue", default-features = false }
cumulus-ping = { path = "cumulus/parachains/pallets/ping", default-features = false }
Expand Down
63 changes: 63 additions & 0 deletions cumulus/pallets/weight-reclaim/Cargo.toml
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",
]
71 changes: 71 additions & 0 deletions cumulus/pallets/weight-reclaim/src/benchmarks.rs
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);
}
Loading

0 comments on commit 7fa88bd

Please sign in to comment.