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

WIP: implement StorageWeightReclaim as wrapping transaction extension with weight #5234

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
76d3373
impl
gui1117 Aug 3, 2024
ec44063
fix missing benchmark config
gui1117 Aug 5, 2024
46e26c7
refactor
gui1117 Aug 5, 2024
fd01c34
remove from + refactor
gui1117 Aug 5, 2024
ea81a0f
doc
gui1117 Aug 5, 2024
51d91b9
fix warning in CI
gui1117 Aug 5, 2024
30f8f4e
Update cumulus/pallets/weight-reclaim-tx/src/lib.rs
gui1117 Aug 6, 2024
4d99a45
Fix post_dispatch_details
gui1117 Aug 6, 2024
eb0cdff
Initial setup for more complete tests
gui1117 Aug 6, 2024
84a924b
fmt
gui1117 Aug 6, 2024
1f937e6
Revert "Fix post_dispatch_details"
gui1117 Aug 7, 2024
d9cf306
fix post_dispatch_details
gui1117 Aug 7, 2024
ad4c64e
Merge remote-tracking branch 'origin/george/restore-gav-tx-ext' into …
gui1117 Aug 7, 2024
16d87c2
Fix reclaim code and some test
gui1117 Aug 7, 2024
413e0b2
fixup
gui1117 Aug 7, 2024
458df34
Merge remote-tracking branch 'origin/george/restore-gav-tx-ext' into …
gui1117 Aug 7, 2024
c168718
fixup
gui1117 Aug 7, 2024
2752c44
Merge remote-tracking branch 'origin/george/restore-gav-tx-ext' into …
gui1117 Aug 10, 2024
4e46cf1
better naming
gui1117 Aug 10, 2024
93eca1c
fixup and fmt
gui1117 Aug 10, 2024
1cb14df
fix tests
gui1117 Aug 10, 2024
c8c90e8
pallet default weight using template benchmark
gui1117 Aug 10, 2024
b004477
support old rustc version
gui1117 Aug 10, 2024
b393b62
fmt
gui1117 Aug 10, 2024
e9e9125
fmt and typo
gui1117 Aug 10, 2024
49b97e4
fix licences
gui1117 Aug 10, 2024
076aa20
fix test service
gui1117 Aug 10, 2024
ed9599c
Merge remote-tracking branch 'origin/george/restore-gav-tx-ext' into …
gui1117 Oct 2, 2024
bb0c547
fix update
gui1117 Oct 2, 2024
ddb199d
fix errors
gui1117 Oct 2, 2024
dd7e6b2
fix impl
gui1117 Oct 2, 2024
375543d
implement it similar to tuples
gui1117 Oct 2, 2024
6b0ea4f
fix import
gui1117 Oct 3, 2024
61cd608
warnings
gui1117 Oct 3, 2024
a05d6be
prdoc
gui1117 Oct 3, 2024
c417a79
fix tests
gui1117 Oct 3, 2024
09512ea
cleanup unused dependency and allow deprecated in some tests
gui1117 Oct 4, 2024
16b8e2e
fix benchmark
gui1117 Oct 5, 2024
b38a2f0
Merge remote-tracking branch 'origin/george/restore-gav-tx-ext' into …
gui1117 Oct 5, 2024
0e0c0af
remove readme for new crate
gui1117 Oct 5, 2024
3b15c61
add dependency in doc crate
gui1117 Oct 5, 2024
a005518
fmt
gui1117 Oct 5, 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
50 changes: 36 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 @@ -704,6 +705,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",
]
78 changes: 78 additions & 0 deletions cumulus/pallets/weight-reclaim/src/benchmarks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// 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::DispatchTransaction;
use sp_runtime::traits::AsTransactionAuthorizedOrigin;

#[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> {
let ext = StorageWeightReclaim::<T, ()>::new(());


let origin = RawOrigin::Root.into();
let call = T::RuntimeCall::from(frame_system::Call::remark { remark: alloc::vec![] });

let info = DispatchInfo {
call_weight: Weight::zero().add_proof_size(1000),
extension_weight: Weight::zero(),
class: DispatchClass::Normal,
pays_fee: Pays::No,
};

let post_info_overestimate = 15;

let post_info = PostDispatchInfo {
actual_weight: Some(Weight::zero().add_proof_size(post_info_overestimate)),
pays_fee: Pays::No,
};

let initial_block_proof_size = 1_000_000;

let mut block_weight = frame_system::ConsumedWeight::default();
block_weight.accrue(Weight::from_parts(0, initial_block_proof_size), 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_eq!(final_block_proof_size, initial_block_proof_size - post_info_overestimate);

Ok(())
}

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