Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement cumulus StorageWeightReclaim as wrapping transaction extension + frame system ReclaimWeight #6140

Open
wants to merge 55 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
d252ce1
storage weight reclaim
gui1117 Oct 19, 2024
670add6
move prdoc
gui1117 Oct 19, 2024
d1e480a
fmt
gui1117 Oct 20, 2024
06903c8
use new extension for bridge hub rococo
gui1117 Oct 20, 2024
9500cd1
fix macro
gui1117 Oct 20, 2024
9bc4f6c
remove unnecessary deprecated
gui1117 Oct 20, 2024
c316f8a
umbrella
gui1117 Oct 20, 2024
6e7b072
use in template
gui1117 Oct 20, 2024
b9f00fc
Merge branch 'master' into gui-storage-proof-size-reclaim-more-accurate
gui1117 Oct 20, 2024
7c777db
fix template
gui1117 Oct 20, 2024
f336a34
prdoc semver
gui1117 Oct 20, 2024
f40892f
complete wrapper including bare stuff
gui1117 Oct 20, 2024
337d5c8
coordinate refunds with a storage
gui1117 Oct 24, 2024
4740554
Merge remote-tracking branch 'origin/master' into gui-storage-proof-s…
gui1117 Oct 24, 2024
643cfda
do not change check weight position
gui1117 Oct 24, 2024
52cc2aa
fmt
gui1117 Oct 24, 2024
f4f5e19
remove forgotten dbg
gui1117 Oct 24, 2024
cf2275f
fix benchmark
gui1117 Oct 25, 2024
7a001e8
Merge branch 'master' into gui-storage-proof-size-reclaim-more-accurate
gui1117 Oct 25, 2024
9473523
Update from gui1117 running command 'bench --runtime asset-hub-rococo…
actions-user Oct 25, 2024
ac6ec39
Update from gui1117 running command 'bench --runtime asset-hub-westen…
actions-user Oct 25, 2024
b45868c
link to correct weights
gui1117 Oct 25, 2024
f8028e7
add system weight reclaim for solo and relay chains
gui1117 Oct 30, 2024
ae0f0b7
fixes
gui1117 Oct 30, 2024
a6d4bd1
fix WeightInfo usages
gui1117 Oct 30, 2024
5b7d968
fix CI
gui1117 Oct 31, 2024
eebb5c7
Update from gui1117 running command 'bench --pallet frame_system --cl…
actions-user Oct 31, 2024
906f150
Revert "Update from gui1117 running command 'bench --pallet frame_sys…
gui1117 Oct 31, 2024
e5b8bf6
fix test
gui1117 Oct 31, 2024
ba1b3bf
Update from gui1117 running command 'bench --pallet frame_system_exte…
actions-user Oct 31, 2024
be6b34e
remove unused
gui1117 Oct 31, 2024
bc625fc
better trace and some comment
gui1117 Oct 31, 2024
f792821
use weight reclaim everywhere
gui1117 Oct 31, 2024
1704d70
fmt
gui1117 Oct 31, 2024
10b0ef0
add tests
gui1117 Oct 31, 2024
5e8cae0
Update cumulus/pallets/weight-reclaim/src/lib.rs
gui1117 Nov 6, 2024
a0a0589
Update substrate/frame/system/src/lib.rs
gui1117 Nov 6, 2024
5322297
more explicit names
gui1117 Nov 6, 2024
472d63c
single operation on weight
gui1117 Nov 6, 2024
597fde4
return more accurate unspent from storage reclaim tx ext
gui1117 Nov 6, 2024
1ad6e56
Keep accrue when node proof size is bigger: https://github.com/parity…
gui1117 Nov 6, 2024
898caa6
outdated comment
gui1117 Nov 6, 2024
363f7d3
fix post info + tests
gui1117 Nov 6, 2024
fee7274
Update prdoc/pr_6140.prdoc
gui1117 Nov 10, 2024
17decb9
Update cumulus/pallets/weight-reclaim/src/benchmarks.rs
gui1117 Nov 14, 2024
79addc7
refactor
gui1117 Nov 14, 2024
d70e552
renames and defensive
gui1117 Nov 14, 2024
22dc356
better dbg
gui1117 Nov 14, 2024
e12b038
Merge remote-tracking branch 'origin/master' into gui-storage-proof-s…
gui1117 Nov 14, 2024
48a2450
fix master merge issue
gui1117 Nov 14, 2024
1a9aeee
fix merge + fix some import + fmt
gui1117 Nov 15, 2024
144fd7e
Merge branch 'master' into gui-storage-proof-size-reclaim-more-accurate
gui1117 Dec 2, 2024
3516356
fix master merge
gui1117 Dec 2, 2024
1c08968
necessary changes to cargo.lock
gui1117 Dec 2, 2024
204f806
prdoc
gui1117 Dec 2, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/runtimes-matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,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
49 changes: 35 additions & 14 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 @@ -709,6 +710,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-runtime = { workspace = true }
sp-io = { workspace = true }
sp-trie = { workspace = true }

frame-support = { workspace = true }
frame-system = { workspace = true }
frame-benchmarking = { optional = true, workspace = true }
cumulus-primitives-storage-weight-reclaim = { workspace = true }

# Other dependencies
codec = { features = ["derive"], workspace = true }
scale-info = { features = ["derive"], workspace = true }
log = { workspace = true, default-features = true }
derivative = { features = ["use_core"], workspace = true }
docify = { 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",
]
73 changes: 73 additions & 0 deletions cumulus/pallets/weight-reclaim/src/benchmarks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// 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() -> Result<(), frame_benchmarking::BenchmarkError> {
gui1117 marked this conversation as resolved.
Show resolved Hide resolved
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, |_| 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}"
);

Ok(())
}

impl_benchmark_test_suite!(Pallet, crate::tests::setup_test_ext_default(), crate::tests::Test);
}
Loading
Loading