diff --git a/.github/workflows/networking-benchmarks.yml b/.github/workflows/benchmarks-networking.yml similarity index 86% rename from .github/workflows/networking-benchmarks.yml rename to .github/workflows/benchmarks-networking.yml index e45ae601105d..79494b9a015c 100644 --- a/.github/workflows/networking-benchmarks.yml +++ b/.github/workflows/benchmarks-networking.yml @@ -17,7 +17,7 @@ jobs: uses: ./.github/workflows/reusable-preflight.yml build: - timeout-minutes: 80 + timeout-minutes: 50 needs: [preflight] runs-on: ${{ needs.preflight.outputs.RUNNER_BENCHMARK }} container: @@ -27,12 +27,8 @@ jobs: matrix: features: [ - { - bench: "notifications_protocol", - }, - { - bench: "request_response_protocol", - }, + { bench: "notifications_protocol" }, + { bench: "request_response_protocol" }, ] steps: - name: Checkout @@ -42,7 +38,7 @@ jobs: id: run-benchmarks run: | mkdir -p ./charts - forklift cargo bench -p sc-network --bench ${{ matrix.features.bench }} -- --output-format bencher | grep "^test" | tee ./charts/networking-bench.txt || echo "Benchmarks failed" + forklift cargo bench -p sc-network --bench ${{ matrix.features.bench }} -- --output-format bencher | grep "^test" | tee ./charts/${{ matrix.features.bench }}.txt || echo "Benchmarks failed" ls -lsa ./charts - name: Upload artifacts @@ -69,7 +65,13 @@ jobs: - name: Download artifacts uses: actions/download-artifact@v4.1.8 with: - name: networking-bench-${{ github.sha }} + name: notifications_protocol-${{ github.sha }} + path: ./charts + + - name: Download artifacts + uses: actions/download-artifact@v4.1.8 + with: + name: request_response_protocol-${{ github.sha }} path: ./charts - name: Setup git diff --git a/.github/workflows/subsystem-benchmarks.yml b/.github/workflows/benchmarks-subsystem.yml similarity index 100% rename from .github/workflows/subsystem-benchmarks.yml rename to .github/workflows/benchmarks-subsystem.yml diff --git a/.github/workflows/reusable-preflight.yml b/.github/workflows/reusable-preflight.yml index e1799adddcaf..8487ab107d7c 100644 --- a/.github/workflows/reusable-preflight.yml +++ b/.github/workflows/reusable-preflight.yml @@ -203,6 +203,7 @@ jobs: echo $( substrate-contracts-node --version | awk 'NF' ) estuary --version cargo-contract --version + taplo --version - name: Info forklift run: forklift version diff --git a/.github/workflows/runtimes-matrix.json b/.github/workflows/runtimes-matrix.json index 104e73521331..ff16b7397247 100644 --- a/.github/workflows/runtimes-matrix.json +++ b/.github/workflows/runtimes-matrix.json @@ -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", diff --git a/Cargo.lock b/Cargo.lock index 8ee01cf9e663..d90e3494ca4a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -959,11 +959,11 @@ dependencies = [ "cumulus-pallet-aura-ext 0.7.0", "cumulus-pallet-parachain-system 0.7.0", "cumulus-pallet-session-benchmarking 9.0.0", + "cumulus-pallet-weight-reclaim", "cumulus-pallet-xcm 0.7.0", "cumulus-pallet-xcmp-queue 0.7.0", "cumulus-primitives-aura 0.7.0", "cumulus-primitives-core 0.7.0", - "cumulus-primitives-storage-weight-reclaim 1.0.0", "cumulus-primitives-utility 0.7.0", "frame-benchmarking 28.0.0", "frame-executive 28.0.0", @@ -1095,11 +1095,11 @@ dependencies = [ "cumulus-pallet-aura-ext 0.7.0", "cumulus-pallet-parachain-system 0.7.0", "cumulus-pallet-session-benchmarking 9.0.0", + "cumulus-pallet-weight-reclaim", "cumulus-pallet-xcm 0.7.0", "cumulus-pallet-xcmp-queue 0.7.0", "cumulus-primitives-aura 0.7.0", "cumulus-primitives-core 0.7.0", - "cumulus-primitives-storage-weight-reclaim 1.0.0", "cumulus-primitives-utility 0.7.0", "frame-benchmarking 28.0.0", "frame-executive 28.0.0", @@ -2678,11 +2678,11 @@ dependencies = [ "cumulus-pallet-aura-ext 0.7.0", "cumulus-pallet-parachain-system 0.7.0", "cumulus-pallet-session-benchmarking 9.0.0", + "cumulus-pallet-weight-reclaim", "cumulus-pallet-xcm 0.7.0", "cumulus-pallet-xcmp-queue 0.7.0", "cumulus-primitives-aura 0.7.0", "cumulus-primitives-core 0.7.0", - "cumulus-primitives-storage-weight-reclaim 1.0.0", "cumulus-primitives-utility 0.7.0", "frame-benchmarking 28.0.0", "frame-executive 28.0.0", @@ -2917,11 +2917,11 @@ dependencies = [ "cumulus-pallet-aura-ext 0.7.0", "cumulus-pallet-parachain-system 0.7.0", "cumulus-pallet-session-benchmarking 9.0.0", + "cumulus-pallet-weight-reclaim", "cumulus-pallet-xcm 0.7.0", "cumulus-pallet-xcmp-queue 0.7.0", "cumulus-primitives-aura 0.7.0", "cumulus-primitives-core 0.7.0", - "cumulus-primitives-storage-weight-reclaim 1.0.0", "cumulus-primitives-utility 0.7.0", "frame-benchmarking 28.0.0", "frame-executive 28.0.0", @@ -3657,11 +3657,11 @@ dependencies = [ "cumulus-pallet-aura-ext 0.7.0", "cumulus-pallet-parachain-system 0.7.0", "cumulus-pallet-session-benchmarking 9.0.0", + "cumulus-pallet-weight-reclaim", "cumulus-pallet-xcm 0.7.0", "cumulus-pallet-xcmp-queue 0.7.0", "cumulus-primitives-aura 0.7.0", "cumulus-primitives-core 0.7.0", - "cumulus-primitives-storage-weight-reclaim 1.0.0", "cumulus-primitives-utility 0.7.0", "frame-benchmarking 28.0.0", "frame-executive 28.0.0", @@ -3964,11 +3964,11 @@ dependencies = [ "cumulus-pallet-aura-ext 0.7.0", "cumulus-pallet-parachain-system 0.7.0", "cumulus-pallet-session-benchmarking 9.0.0", + "cumulus-pallet-weight-reclaim", "cumulus-pallet-xcm 0.7.0", "cumulus-pallet-xcmp-queue 0.7.0", "cumulus-primitives-aura 0.7.0", "cumulus-primitives-core 0.7.0", - "cumulus-primitives-storage-weight-reclaim 1.0.0", "cumulus-primitives-utility 0.7.0", "frame-benchmarking 28.0.0", "frame-executive 28.0.0", @@ -4107,11 +4107,11 @@ dependencies = [ "cumulus-pallet-aura-ext 0.7.0", "cumulus-pallet-parachain-system 0.7.0", "cumulus-pallet-session-benchmarking 9.0.0", + "cumulus-pallet-weight-reclaim", "cumulus-pallet-xcm 0.7.0", "cumulus-pallet-xcmp-queue 0.7.0", "cumulus-primitives-aura 0.7.0", "cumulus-primitives-core 0.7.0", - "cumulus-primitives-storage-weight-reclaim 1.0.0", "cumulus-primitives-utility 0.7.0", "frame-benchmarking 28.0.0", "frame-executive 28.0.0", @@ -4208,11 +4208,11 @@ dependencies = [ "cumulus-pallet-aura-ext 0.7.0", "cumulus-pallet-parachain-system 0.7.0", "cumulus-pallet-session-benchmarking 9.0.0", + "cumulus-pallet-weight-reclaim", "cumulus-pallet-xcm 0.7.0", "cumulus-pallet-xcmp-queue 0.7.0", "cumulus-primitives-aura 0.7.0", "cumulus-primitives-core 0.7.0", - "cumulus-primitives-storage-weight-reclaim 1.0.0", "cumulus-primitives-utility 0.7.0", "frame-benchmarking 28.0.0", "frame-executive 28.0.0", @@ -5101,6 +5101,25 @@ dependencies = [ "sp-runtime 39.0.2", ] +[[package]] +name = "cumulus-pallet-weight-reclaim" +version = "1.0.0" +dependencies = [ + "cumulus-primitives-proof-size-hostfunction 0.2.0", + "cumulus-primitives-storage-weight-reclaim 1.0.0", + "derivative", + "docify", + "frame-benchmarking 28.0.0", + "frame-support 28.0.0", + "frame-system 28.0.0", + "log", + "parity-scale-codec", + "scale-info", + "sp-io 30.0.0", + "sp-runtime 31.0.1", + "sp-trie 29.0.0", +] + [[package]] name = "cumulus-pallet-xcm" version = "0.7.0" @@ -5551,10 +5570,10 @@ dependencies = [ name = "cumulus-test-client" version = "0.1.0" dependencies = [ + "cumulus-pallet-weight-reclaim", "cumulus-primitives-core 0.7.0", "cumulus-primitives-parachain-inherent 0.7.0", "cumulus-primitives-proof-size-hostfunction 0.2.0", - "cumulus-primitives-storage-weight-reclaim 1.0.0", "cumulus-test-relay-sproof-builder 0.7.0", "cumulus-test-runtime", "cumulus-test-service", @@ -5616,9 +5635,9 @@ version = "0.1.0" dependencies = [ "cumulus-pallet-aura-ext 0.7.0", "cumulus-pallet-parachain-system 0.7.0", + "cumulus-pallet-weight-reclaim", "cumulus-primitives-aura 0.7.0", "cumulus-primitives-core 0.7.0", - "cumulus-primitives-storage-weight-reclaim 1.0.0", "frame-executive 28.0.0", "frame-support 28.0.0", "frame-system 28.0.0", @@ -5670,8 +5689,8 @@ dependencies = [ "cumulus-client-pov-recovery", "cumulus-client-service", "cumulus-pallet-parachain-system 0.7.0", + "cumulus-pallet-weight-reclaim", "cumulus-primitives-core 0.7.0", - "cumulus-primitives-storage-weight-reclaim 1.0.0", "cumulus-relay-chain-inprocess-interface", "cumulus-relay-chain-interface", "cumulus-relay-chain-minimal-node", @@ -16863,11 +16882,11 @@ dependencies = [ "cumulus-pallet-aura-ext 0.7.0", "cumulus-pallet-parachain-system 0.7.0", "cumulus-pallet-session-benchmarking 9.0.0", + "cumulus-pallet-weight-reclaim", "cumulus-pallet-xcm 0.7.0", "cumulus-pallet-xcmp-queue 0.7.0", "cumulus-primitives-aura 0.7.0", "cumulus-primitives-core 0.7.0", - "cumulus-primitives-storage-weight-reclaim 1.0.0", "cumulus-primitives-utility 0.7.0", "enumflags2", "frame-benchmarking 28.0.0", @@ -16966,11 +16985,11 @@ dependencies = [ "cumulus-pallet-aura-ext 0.7.0", "cumulus-pallet-parachain-system 0.7.0", "cumulus-pallet-session-benchmarking 9.0.0", + "cumulus-pallet-weight-reclaim", "cumulus-pallet-xcm 0.7.0", "cumulus-pallet-xcmp-queue 0.7.0", "cumulus-primitives-aura 0.7.0", "cumulus-primitives-core 0.7.0", - "cumulus-primitives-storage-weight-reclaim 1.0.0", "cumulus-primitives-utility 0.7.0", "enumflags2", "frame-benchmarking 28.0.0", @@ -18777,6 +18796,7 @@ dependencies = [ "cumulus-pallet-parachain-system-proc-macro 0.6.0", "cumulus-pallet-session-benchmarking 9.0.0", "cumulus-pallet-solo-to-para 0.7.0", + "cumulus-pallet-weight-reclaim", "cumulus-pallet-xcm 0.7.0", "cumulus-pallet-xcmp-queue 0.7.0", "cumulus-ping 0.7.0", @@ -19365,8 +19385,8 @@ dependencies = [ "cumulus-client-service", "cumulus-pallet-aura-ext 0.7.0", "cumulus-pallet-parachain-system 0.7.0", + "cumulus-pallet-weight-reclaim", "cumulus-primitives-proof-size-hostfunction 0.2.0", - "cumulus-primitives-storage-weight-reclaim 1.0.0", "docify", "frame-benchmarking 28.0.0", "frame-executive 28.0.0", @@ -21579,12 +21599,12 @@ version = "0.6.0" dependencies = [ "cumulus-pallet-aura-ext 0.7.0", "cumulus-pallet-parachain-system 0.7.0", + "cumulus-pallet-weight-reclaim", "cumulus-pallet-xcm 0.7.0", "cumulus-pallet-xcmp-queue 0.7.0", "cumulus-ping 0.7.0", "cumulus-primitives-aura 0.7.0", "cumulus-primitives-core 0.7.0", - "cumulus-primitives-storage-weight-reclaim 1.0.0", "cumulus-primitives-utility 0.7.0", "frame-benchmarking 28.0.0", "frame-executive 28.0.0", diff --git a/Cargo.toml b/Cargo.toml index 64a11a340d10..c917a8a8fead 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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", @@ -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 } diff --git a/README.md b/README.md index 6c0dfbb2e7e4..24352cc28a1a 100644 --- a/README.md +++ b/README.md @@ -40,9 +40,9 @@ curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/paritytec ![Current Stable Release](https://raw.githubusercontent.com/paritytech/release-registry/main/badges/polkadot-sdk-latest.svg)  ![Next Stable Release](https://raw.githubusercontent.com/paritytech/release-registry/main/badges/polkadot-sdk-next.svg) -The Polkadot SDK is released every three months as a `stableYYMMDD` release. They are supported for +The Polkadot SDK is released every three months as a `stableYYMM` release. They are supported for one year with patches. See the next upcoming versions in the [Release -Registry](https://github.com/paritytech/release-registry/). +Registry](https://github.com/paritytech/release-registry/) and more docs in [RELEASE.md](./docs/RELEASE.md). You can use [`psvm`](https://github.com/paritytech/psvm) to update all dependencies to a specific version without needing to manually select the correct version for each crate. diff --git a/bridges/SECURITY.md b/bridges/SECURITY.md index 9f215c887654..ea19eca42cc3 100644 --- a/bridges/SECURITY.md +++ b/bridges/SECURITY.md @@ -13,6 +13,6 @@ If you think that your report might be eligible for the Bug Bounty Program, plea Please check up-to-date [Parity Bug Bounty Program rules](https://www.parity.io/bug-bounty) to find out the information about our Bug Bounty Program. -**Warning**: This is an unified SECURITY.md file for Paritytech GitHub Organization. The presence of this file does not +**Warning**: This is a unified SECURITY.md file for Paritytech GitHub Organization. The presence of this file does not mean that this repository is covered by the Bug Bounty program. Please always check the Bug Bounty Program scope for information. diff --git a/bridges/modules/messages/README.md b/bridges/modules/messages/README.md index a78c86802498..7d9a23b4ba14 100644 --- a/bridges/modules/messages/README.md +++ b/bridges/modules/messages/README.md @@ -13,7 +13,7 @@ module and the final goal is to hand message to the message dispatch mechanism. ## Overview -Message lane is an unidirectional channel, where messages are sent from source chain to the target chain. At the same +Message lane is a unidirectional channel, where messages are sent from source chain to the target chain. At the same time, a single instance of messages module supports both outbound lanes and inbound lanes. So the chain where the module is deployed (this chain), may act as a source chain for outbound messages (heading to a bridged chain) and as a target chain for inbound messages (coming from a bridged chain). diff --git a/cumulus/client/consensus/aura/src/equivocation_import_queue.rs b/cumulus/client/consensus/aura/src/equivocation_import_queue.rs index 68f2d37c8748..dbd9d5ba6a6f 100644 --- a/cumulus/client/consensus/aura/src/equivocation_import_queue.rs +++ b/cumulus/client/consensus/aura/src/equivocation_import_queue.rs @@ -97,6 +97,7 @@ where // This is done for example when gap syncing and it is expected that the block after the gap // was checked/chosen properly, e.g. by warp syncing to this block using a finality proof. if block_params.state_action.skip_execution_checks() || block_params.with_state() { + block_params.fork_choice = Some(ForkChoiceStrategy::Custom(block_params.with_state())); return Ok(block_params) } diff --git a/cumulus/docs/overview.md b/cumulus/docs/overview.md index 402c56042c49..82603257a871 100644 --- a/cumulus/docs/overview.md +++ b/cumulus/docs/overview.md @@ -70,7 +70,7 @@ A Parachain validator needs to validate a given PoVBlock, but without requiring the Parachain. To still make it possible to validate the Parachain block, the PoVBlock contains the witness data. The witness data is a proof that is collected while building the block. The proof will contain all trie nodes that are read during the block production. Cumulus uses the witness data to -reconstruct a partial trie and uses this a storage when executing the block. +reconstruct a partial trie and uses this as storage when executing the block. The outgoing messages are also collected at block production. These are messages from the Parachain the block is built for to other Parachains or to the relay chain itself. diff --git a/cumulus/docs/release.md b/cumulus/docs/release.md deleted file mode 100644 index 8302b7b9b7fc..000000000000 --- a/cumulus/docs/release.md +++ /dev/null @@ -1,135 +0,0 @@ -# Releases - -## Versioning - -### Example #1 - -``` -| Polkadot | v 0. 9.22 | -| Client | v 0. 9.22 0 | -| Runtime | v 9 22 0 | => 9220 -| semver | 0. 9.22 0 | -``` - -### Example #2 - -``` -| Polkadot | v 0.10.42 | -| Client | v 0.10.42 0 | -| Runtime | v 10.42 0 | => 10420 -| semver | 0.10.42 0 | -``` - -### Example #3 - -``` -| Polkadot | v 1. 2.18 | -| Client | v 1. 2.18 0 | -| Runtime | v 1 2 18 0 | => 102180 -| semver | 1. 2.18 0 | -``` - - -This document contains information related to the releasing process and describes a few of the steps and checks that are -performed during the release process. - -## Client - -### Burn In - -Ensure that Parity DevOps has run the new release on Westend and Kusama Asset Hub collators for 12h prior to publishing -the release. - -### Build Artifacts - -Add any necessary assets to the release. They should include: - -- Linux binaries - - GPG signature - - SHA256 checksum -- WASM binaries of the runtimes -- Source code - - -## Runtimes - -### Spec Version - -A new runtime release must bump the `spec_version`. This may follow a pattern with the client release (e.g. runtime -v9220 corresponds to v0.9.22). - -### Runtime version bump between RCs - -The clients need to be aware of runtime changes. However, we do not want to bump the `spec_version` for every single -release candidate. Instead, we can bump the `impl` field of the version to signal the change to the client. This applies -only to runtimes that have been deployed. - -### Old Migrations Removed - -Previous `on_runtime_upgrade` functions from old upgrades should be removed. - -### New Migrations - -Ensure that any migrations that are required due to storage or logic changes are included in the `on_runtime_upgrade` -function of the appropriate pallets. - -### Extrinsic Ordering & Storage - -Offline signing libraries depend on a consistent ordering of call indices and functions. Compare the metadata of the -current and new runtimes and ensure that the `module index, call index` tuples map to the same set of functions. It also -checks if there have been any changes in `storage`. In case of a breaking change, increase `transaction_version`. - -To verify the order has not changed, manually start the following -[Github Action](https://github.com/paritytech/polkadot-sdk/cumulus/.github/workflows/release-20_extrinsic-ordering-check-from-bin.yml). -It takes around a minute to run and will produce the report as artifact you need to manually check. - -To run it, in the _Run Workflow_ dropdown: -1. **Use workflow from**: to ignore, leave `master` as default -2. **The WebSocket url of the reference node**: - Asset Hub Polkadot: `wss://statemint-rpc.polkadot.io` - - Asset Hub Kusama: `wss://statemine-rpc.polkadot.io` - - Asset Hub Westend: `wss://westmint-rpc.polkadot.io` -3. **A url to a Linux binary for the node containing the runtime to test**: Paste the URL of the latest - release-candidate binary from the draft-release on Github. The binary has to previously be uploaded to S3 (Github url - link to the binary is constantly changing) - - E.g: https://releases.parity.io/cumulus/v0.9.270-rc3/polkadot-parachain -4. **The name of the chain under test. Usually, you would pass a local chain**: - Asset Hub Polkadot: - `asset-hub-polkadot-local` - - Asset Hub Kusama: `asset-hub-kusama-local` - - Asset Hub Westend: `asset-hub-westend-local` -5. Click **Run workflow** - -When the workflow is done, click on it and download the zip artifact, inside you'll find an `output.txt` file. The -things to look for in the output are lines like: - -- `[Identity] idx 28 -> 25 (calls 15)` - indicates the index for Identity has changed -- `[+] Society, Recovery` - indicates the new version includes 2 additional modules/pallets. -- If no indices have changed, every modules line should look something like `[Identity] idx 25 (calls 15)` - -**Note**: Adding new functions to the runtime does not constitute a breaking change as long as the indexes did not -change. - -**Note**: Extrinsic function signatures changes (adding/removing & ordering arguments) are not caught by the job, so -those changes should be reviewed "manually" - -### Benchmarks - -The Benchmarks can now be started from the CI. First find the CI pipeline from -[here](https://gitlab.parity.io/parity/mirrors/cumulus/-/pipelines?page=1&scope=all&ref=release-parachains-v9220) and -pick the latest. [Guide](https://github.com/paritytech/ci_cd/wiki/Benchmarks:-cumulus) - -### Integration Tests - -Until https://github.com/paritytech/ci_cd/issues/499 is done, tests will have to be run manually. -1. Go to https://github.com/paritytech/parachains-integration-tests and check out the release branch. E.g. -https://github.com/paritytech/parachains-integration-tests/tree/release-v9270-v0.9.27 for `release-parachains-v0.9.270` -2. Clone `release-parachains-` branch from Cumulus -3. `cargo build --release` -4. Copy `./target/polkadot-parachain` to `./bin` -5. Clone `it/release--fast-sudo` from Polkadot In case the branch does not exists (it is a manual process): - cherry pick `paritytech/polkadot@791c8b8` and run: - `find . -type f -name "*.toml" -print0 | xargs -0 sed -i '' -e 's/polkadot-vX.X.X/polkadot-v/g'` -6. `cargo build --release --features fast-runtime` -7. Copy `./target/polkadot` into `./bin` (in Cumulus) -8. Run the tests: - - Asset Hub Polkadot: `yarn zombienet-test -c ./examples/statemint/config.toml -t ./examples/statemint` - - Asset Hub Kusama: `yarn zombienet-test -c ./examples/statemine/config.toml -t ./examples/statemine` diff --git a/cumulus/pallets/weight-reclaim/Cargo.toml b/cumulus/pallets/weight-reclaim/Cargo.toml new file mode 100644 index 000000000000..8bde6abaff6a --- /dev/null +++ b/cumulus/pallets/weight-reclaim/Cargo.toml @@ -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", +] diff --git a/cumulus/pallets/weight-reclaim/src/benchmarks.rs b/cumulus/pallets/weight-reclaim/src/benchmarks.rs new file mode 100644 index 000000000000..78bebc967d96 --- /dev/null +++ b/cumulus/pallets/weight-reclaim/src/benchmarks.rs @@ -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 . + +#![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, + ::RuntimeCall: + Dispatchable, + ::RuntimeOrigin: AsTransactionAuthorizedOrigin, +)] +mod bench { + use super::*; + use frame_benchmarking::impl_test_function; + + #[benchmark] + fn storage_weight_reclaim() { + let ext = StorageWeightReclaim::::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::::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::::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); +} diff --git a/cumulus/pallets/weight-reclaim/src/lib.rs b/cumulus/pallets/weight-reclaim/src/lib.rs new file mode 100644 index 000000000000..bd9929033af1 --- /dev/null +++ b/cumulus/pallets/weight-reclaim/src/lib.rs @@ -0,0 +1,311 @@ +// 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 . + +//! Pallet and transaction extensions to reclaim PoV proof size weight after an extrinsic has been +//! applied. +//! +//! This crate provides: +//! * [`StorageWeightReclaim`] transaction extension: it must wrap the whole transaction extension +//! pipeline. +//! * The pallet required for the transaction extensions weight information and benchmarks. + +#![cfg_attr(not(feature = "std"), no_std)] + +extern crate alloc; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; +use codec::{Decode, Encode}; +use cumulus_primitives_storage_weight_reclaim::get_proof_size; +use derivative::Derivative; +use frame_support::{ + dispatch::{DispatchInfo, PostDispatchInfo}, + pallet_prelude::Weight, + traits::Defensive, +}; +use scale_info::TypeInfo; +use sp_runtime::{ + traits::{DispatchInfoOf, Dispatchable, Implication, PostDispatchInfoOf, TransactionExtension}, + transaction_validity::{TransactionSource, TransactionValidityError, ValidTransaction}, + DispatchResult, +}; + +#[cfg(feature = "runtime-benchmarks")] +pub mod benchmarks; +#[cfg(test)] +mod tests; +mod weights; + +pub use pallet::*; +pub use weights::WeightInfo; + +const LOG_TARGET: &'static str = "runtime::storage_reclaim_pallet"; + +/// Pallet to use alongside the transaction extension [`StorageWeightReclaim`], the pallet provides +/// weight information and benchmarks. +#[frame_support::pallet] +pub mod pallet { + use super::*; + + #[pallet::pallet] + pub struct Pallet(_); + + #[pallet::config] + pub trait Config: frame_system::Config { + type WeightInfo: WeightInfo; + } +} + +/// Storage weight reclaim mechanism. +/// +/// This extension must wrap all the transaction extensions: +#[doc = docify::embed!("./src/tests.rs", Tx)] +/// +/// This extension checks the size of the node-side storage proof before and after executing a given +/// extrinsic using the proof size host function. The difference between benchmarked and used weight +/// is reclaimed. +/// +/// If the benchmark was underestimating the proof size, then it is added to the block weight. +/// +/// For the time part of the weight, it does same as system `WeightReclaim` extension, it +/// calculates the unused weight using the post information and reclaim the unused weight. +/// So this extension can be used as a drop-in replacement for `WeightReclaim` extension for +/// parachains. +#[derive(Encode, Decode, TypeInfo, Derivative)] +#[derivative( + Clone(bound = "S: Clone"), + Eq(bound = "S: Eq"), + PartialEq(bound = "S: PartialEq"), + Default(bound = "S: Default") +)] +#[scale_info(skip_type_params(T))] +pub struct StorageWeightReclaim(pub S, core::marker::PhantomData); + +impl StorageWeightReclaim { + /// Create a new `StorageWeightReclaim` instance. + pub fn new(s: S) -> Self { + Self(s, Default::default()) + } +} + +impl From for StorageWeightReclaim { + fn from(s: S) -> Self { + Self::new(s) + } +} + +impl core::fmt::Debug for StorageWeightReclaim { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> Result<(), core::fmt::Error> { + #[cfg(feature = "std")] + let _ = write!(f, "StorageWeightReclaim<{:?}>", self.0); + + #[cfg(not(feature = "std"))] + let _ = write!(f, "StorageWeightReclaim"); + + Ok(()) + } +} + +impl> + TransactionExtension for StorageWeightReclaim +where + T::RuntimeCall: Dispatchable, +{ + const IDENTIFIER: &'static str = "StorageWeightReclaim"; + + type Implicit = S::Implicit; + + // Initial proof size and inner extension value. + type Val = (Option, S::Val); + + // Initial proof size and inner extension pre. + type Pre = (Option, S::Pre); + + fn implicit(&self) -> Result { + self.0.implicit() + } + + fn metadata() -> Vec { + let mut inner = S::metadata(); + inner.push(sp_runtime::traits::TransactionExtensionMetadata { + identifier: "StorageWeightReclaim", + ty: scale_info::meta_type::<()>(), + implicit: scale_info::meta_type::<()>(), + }); + inner + } + + fn weight(&self, call: &T::RuntimeCall) -> Weight { + T::WeightInfo::storage_weight_reclaim().saturating_add(self.0.weight(call)) + } + + fn validate( + &self, + origin: T::RuntimeOrigin, + call: &T::RuntimeCall, + info: &DispatchInfoOf, + len: usize, + self_implicit: Self::Implicit, + inherited_implication: &impl Implication, + source: TransactionSource, + ) -> Result<(ValidTransaction, Self::Val, T::RuntimeOrigin), TransactionValidityError> { + let proof_size = get_proof_size(); + + self.0 + .validate(origin, call, info, len, self_implicit, inherited_implication, source) + .map(|(validity, val, origin)| (validity, (proof_size, val), origin)) + } + + fn prepare( + self, + val: Self::Val, + origin: &T::RuntimeOrigin, + call: &T::RuntimeCall, + info: &DispatchInfoOf, + len: usize, + ) -> Result { + let (proof_size, inner_val) = val; + self.0.prepare(inner_val, origin, call, info, len).map(|pre| (proof_size, pre)) + } + + fn post_dispatch_details( + pre: Self::Pre, + info: &DispatchInfoOf, + post_info: &PostDispatchInfoOf, + len: usize, + result: &DispatchResult, + ) -> Result { + let (proof_size_before_dispatch, inner_pre) = pre; + + let mut post_info_with_inner = *post_info; + S::post_dispatch(inner_pre, info, &mut post_info_with_inner, len, result)?; + + let inner_refund = if let (Some(before_weight), Some(after_weight)) = + (post_info.actual_weight, post_info_with_inner.actual_weight) + { + before_weight.saturating_sub(after_weight) + } else { + Weight::zero() + }; + + let Some(proof_size_before_dispatch) = proof_size_before_dispatch else { + // We have no proof size information, there is nothing we can do. + return Ok(inner_refund); + }; + + let Some(proof_size_after_dispatch) = get_proof_size().defensive_proof( + "Proof recording enabled during prepare, now disabled. This should not happen.", + ) else { + return Ok(inner_refund) + }; + + // The consumed proof size as measured by the host. + let measured_proof_size = + proof_size_after_dispatch.saturating_sub(proof_size_before_dispatch); + + // The consumed weight as benchmarked. Calculated from post info and info. + // NOTE: `calc_actual_weight` will take the minimum of `post_info` and `info` weights. + // This means any underestimation of compute time in the pre dispatch info will not be + // taken into account. + let benchmarked_actual_weight = post_info_with_inner.calc_actual_weight(info); + + let benchmarked_actual_proof_size = benchmarked_actual_weight.proof_size(); + if benchmarked_actual_proof_size < measured_proof_size { + log::error!( + target: LOG_TARGET, + "Benchmarked storage weight smaller than consumed storage weight. \ + benchmarked: {benchmarked_actual_proof_size} consumed: {measured_proof_size}" + ); + } else { + log::trace!( + target: LOG_TARGET, + "Reclaiming storage weight. benchmarked: {benchmarked_actual_proof_size}, + consumed: {measured_proof_size}" + ); + } + + let accurate_weight = benchmarked_actual_weight.set_proof_size(measured_proof_size); + + let pov_size_missing_from_node = frame_system::BlockWeight::::mutate(|current_weight| { + let already_reclaimed = frame_system::ExtrinsicWeightReclaimed::::get(); + current_weight.accrue(already_reclaimed, info.class); + current_weight.reduce(info.total_weight(), info.class); + current_weight.accrue(accurate_weight, info.class); + + // If we encounter a situation where the node-side proof size is already higher than + // what we have in the runtime bookkeeping, we add the difference to the `BlockWeight`. + // This prevents that the proof size grows faster than the runtime proof size. + let extrinsic_len = frame_system::AllExtrinsicsLen::::get().unwrap_or(0); + let node_side_pov_size = proof_size_after_dispatch.saturating_add(extrinsic_len.into()); + let block_weight_proof_size = current_weight.total().proof_size(); + let pov_size_missing_from_node = + node_side_pov_size.saturating_sub(block_weight_proof_size); + if pov_size_missing_from_node > 0 { + log::warn!( + target: LOG_TARGET, + "Node-side PoV size higher than runtime proof size weight. node-side: \ + {node_side_pov_size} extrinsic_len: {extrinsic_len} runtime: \ + {block_weight_proof_size}, missing: {pov_size_missing_from_node}. Setting to \ + node-side proof size." + ); + current_weight + .accrue(Weight::from_parts(0, pov_size_missing_from_node), info.class); + } + + pov_size_missing_from_node + }); + + // The saturation will happen if the pre-dispatch weight is underestimating the proof + // size or if the node-side proof size is higher than expected. + // In this case the extrinsic proof size weight reclaimed is 0 and not a negative reclaim. + let accurate_unspent = info + .total_weight() + .saturating_sub(accurate_weight) + .saturating_sub(Weight::from_parts(0, pov_size_missing_from_node)); + frame_system::ExtrinsicWeightReclaimed::::put(accurate_unspent); + + // Call have already returned their unspent amount. + // (also transaction extension prior in the pipeline, but there shouldn't be any.) + let already_unspent_in_tx_ext_pipeline = post_info.calc_unspent(info); + Ok(accurate_unspent.saturating_sub(already_unspent_in_tx_ext_pipeline)) + } + + fn bare_validate( + call: &T::RuntimeCall, + info: &DispatchInfoOf, + len: usize, + ) -> frame_support::pallet_prelude::TransactionValidity { + S::bare_validate(call, info, len) + } + + fn bare_validate_and_prepare( + call: &T::RuntimeCall, + info: &DispatchInfoOf, + len: usize, + ) -> Result<(), TransactionValidityError> { + S::bare_validate_and_prepare(call, info, len) + } + + fn bare_post_dispatch( + info: &DispatchInfoOf, + post_info: &mut PostDispatchInfoOf, + len: usize, + result: &DispatchResult, + ) -> Result<(), TransactionValidityError> { + S::bare_post_dispatch(info, post_info, len, result)?; + + frame_system::Pallet::::reclaim_weight(info, post_info) + } +} diff --git a/cumulus/pallets/weight-reclaim/src/tests.rs b/cumulus/pallets/weight-reclaim/src/tests.rs new file mode 100644 index 000000000000..b87c107c7ec7 --- /dev/null +++ b/cumulus/pallets/weight-reclaim/src/tests.rs @@ -0,0 +1,1050 @@ +// 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 . + +#![cfg(test)] + +use super::*; +use cumulus_primitives_proof_size_hostfunction::PROOF_RECORDING_DISABLED; +use frame_support::{ + assert_ok, derive_impl, dispatch::GetDispatchInfo, pallet_prelude::DispatchClass, +}; +use sp_runtime::{ + generic, + traits::{Applyable, BlakeTwo256, DispatchTransaction, Get}, + BuildStorage, +}; +use sp_trie::proof_size_extension::ProofSizeExt; + +thread_local! { + static CHECK_WEIGHT_WEIGHT: core::cell::RefCell = Default::default(); + static STORAGE_WEIGHT_RECLAIM_WEIGHT: core::cell::RefCell = Default::default(); + static MOCK_EXT_WEIGHT: core::cell::RefCell = Default::default(); + static MOCK_EXT_REFUND: core::cell::RefCell = Default::default(); +} + +/// An extension which has some proof_size weight and some proof_size refund. +#[derive(Encode, Decode, Debug, Clone, PartialEq, Eq, scale_info::TypeInfo)] +pub struct MockExtensionWithRefund; + +impl TransactionExtension for MockExtensionWithRefund { + const IDENTIFIER: &'static str = "mock_extension_with_refund"; + type Implicit = (); + type Val = (); + type Pre = (); + fn weight(&self, _: &RuntimeCall) -> Weight { + MOCK_EXT_WEIGHT.with_borrow(|v| *v) + } + fn post_dispatch_details( + _pre: Self::Pre, + _info: &DispatchInfoOf, + _post_info: &PostDispatchInfoOf, + _len: usize, + _result: &DispatchResult, + ) -> Result { + Ok(MOCK_EXT_REFUND.with_borrow(|v| *v)) + } + fn bare_post_dispatch( + _info: &DispatchInfoOf, + post_info: &mut PostDispatchInfoOf, + _len: usize, + _result: &DispatchResult, + ) -> Result<(), TransactionValidityError> { + if let Some(ref mut w) = post_info.actual_weight { + *w -= MOCK_EXT_REFUND.with_borrow(|v| *v); + } + Ok(()) + } + + sp_runtime::impl_tx_ext_default!(RuntimeCall; validate prepare); +} + +pub type Tx = + crate::StorageWeightReclaim, MockExtensionWithRefund)>; +type AccountId = u64; +type Extrinsic = generic::UncheckedExtrinsic; +type Block = generic::Block, Extrinsic>; + +#[frame_support::runtime] +mod runtime { + #[runtime::runtime] + #[runtime::derive( + RuntimeCall, + RuntimeEvent, + RuntimeError, + RuntimeOrigin, + RuntimeFreezeReason, + RuntimeHoldReason, + RuntimeSlashReason, + RuntimeLockId, + RuntimeTask + )] + pub struct Test; + + #[runtime::pallet_index(0)] + pub type System = frame_system::Pallet; + + #[runtime::pallet_index(1)] + pub type WeightReclaim = crate::Pallet; +} + +pub struct MockWeightInfo; + +impl frame_system::ExtensionsWeightInfo for MockWeightInfo { + fn check_genesis() -> Weight { + Default::default() + } + fn check_mortality_mortal_transaction() -> Weight { + Default::default() + } + fn check_mortality_immortal_transaction() -> Weight { + Default::default() + } + fn check_non_zero_sender() -> Weight { + Default::default() + } + fn check_nonce() -> Weight { + Default::default() + } + fn check_spec_version() -> Weight { + Default::default() + } + fn check_tx_version() -> Weight { + Default::default() + } + fn check_weight() -> Weight { + CHECK_WEIGHT_WEIGHT.with_borrow(|v| *v) + } + fn weight_reclaim() -> Weight { + Default::default() + } +} + +impl frame_system::WeightInfo for MockWeightInfo { + fn remark(_b: u32) -> Weight { + Weight::from_parts(400, 0) + } + fn set_code() -> Weight { + Weight::zero() + } + fn set_storage(_i: u32) -> Weight { + Weight::zero() + } + fn kill_prefix(_p: u32) -> Weight { + Weight::zero() + } + fn kill_storage(_i: u32) -> Weight { + Weight::zero() + } + fn set_heap_pages() -> Weight { + Weight::zero() + } + fn remark_with_event(_b: u32) -> Weight { + Weight::zero() + } + fn authorize_upgrade() -> Weight { + Weight::zero() + } + fn apply_authorized_upgrade() -> Weight { + Weight::zero() + } +} + +impl crate::WeightInfo for MockWeightInfo { + fn storage_weight_reclaim() -> Weight { + STORAGE_WEIGHT_RECLAIM_WEIGHT.with_borrow(|v| *v) + } +} + +#[derive_impl(frame_system::config_preludes::TestDefaultConfig)] +impl frame_system::Config for Test { + type Block = Block; + type AccountData = (); + type MaxConsumers = frame_support::traits::ConstU32<3>; + type ExtensionsWeightInfo = MockWeightInfo; +} + +impl crate::Config for Test { + type WeightInfo = MockWeightInfo; +} + +fn new_test_ext() -> sp_io::TestExternalities { + RuntimeGenesisConfig::default().build_storage().unwrap().into() +} + +struct TestRecorder { + return_values: Box<[usize]>, + counter: core::sync::atomic::AtomicUsize, +} + +impl TestRecorder { + fn new(values: &[usize]) -> Self { + TestRecorder { return_values: values.into(), counter: Default::default() } + } +} + +impl sp_trie::ProofSizeProvider for TestRecorder { + fn estimate_encoded_size(&self) -> usize { + let counter = self.counter.fetch_add(1, core::sync::atomic::Ordering::Relaxed); + self.return_values[counter] + } +} + +fn setup_test_externalities(proof_values: &[usize]) -> sp_io::TestExternalities { + let mut test_ext = new_test_ext(); + let test_recorder = TestRecorder::new(proof_values); + test_ext.register_extension(ProofSizeExt::new(test_recorder)); + test_ext +} + +#[cfg(feature = "runtime-benchmarks")] +pub fn setup_test_ext_default() -> sp_io::TestExternalities { + setup_test_externalities(&[0; 32]) +} + +fn set_current_storage_weight(new_weight: u64) { + frame_system::BlockWeight::::mutate(|current_weight| { + current_weight.set(Weight::from_parts(0, new_weight), DispatchClass::Normal); + }); +} + +fn get_storage_weight() -> Weight { + *frame_system::BlockWeight::::get().get(DispatchClass::Normal) +} + +const CALL: &::RuntimeCall = + &RuntimeCall::System(frame_system::Call::set_heap_pages { pages: 0u64 }); +const ALICE_ORIGIN: frame_system::Origin = frame_system::Origin::::Signed(99); +const LEN: usize = 150; + +fn new_tx_ext() -> Tx { + Tx::new((frame_system::CheckWeight::new(), MockExtensionWithRefund)) +} + +fn new_extrinsic() -> generic::CheckedExtrinsic { + generic::CheckedExtrinsic { + format: generic::ExtrinsicFormat::Signed(99, new_tx_ext()), + function: RuntimeCall::System(frame_system::Call::remark { remark: vec![] }), + } +} + +#[allow(unused)] +mod doc { + type Runtime = super::Test; + use crate::StorageWeightReclaim; + + #[docify::export(Tx)] + type Tx = StorageWeightReclaim< + Runtime, + ( + frame_system::CheckNonce, + frame_system::CheckWeight, + // ... all other extensions + // No need for `frame_system::WeightReclaim` as the reclaim. + ), + >; +} + +#[test] +fn basic_refund_no_post_info() { + // The real cost will be 100 bytes of storage size + let mut test_ext = setup_test_externalities(&[0, 100]); + + test_ext.execute_with(|| { + set_current_storage_weight(1000); + + // Benchmarked storage weight: 500 + let info = DispatchInfo { call_weight: Weight::from_parts(0, 500), ..Default::default() }; + let mut post_info = PostDispatchInfo::default(); + + let tx_ext = new_tx_ext(); + + // Check weight should add 500 + 150 (len) to weight. + let (pre, _) = tx_ext + .validate_and_prepare(ALICE_ORIGIN.clone().into(), CALL, &info, LEN, 0) + .unwrap(); + + assert_eq!(pre.0, Some(0)); + + assert_ok!(Tx::post_dispatch(pre, &info, &mut post_info, LEN, &Ok(()))); + + assert_eq!(post_info.actual_weight, None); + assert_eq!(get_storage_weight().proof_size(), 1250); + }); +} + +#[test] +fn basic_refund_some_post_info() { + // The real cost will be 100 bytes of storage size + let mut test_ext = setup_test_externalities(&[0, 100]); + + test_ext.execute_with(|| { + set_current_storage_weight(1000); + + // Benchmarked storage weight: 500 + let info = DispatchInfo { call_weight: Weight::from_parts(0, 500), ..Default::default() }; + let mut post_info = PostDispatchInfo::default(); + post_info.actual_weight = Some(info.total_weight()); + + let tx_ext = new_tx_ext(); + + // Check weight should add 500 + 150 (len) to weight. + let (pre, _) = tx_ext + .validate_and_prepare(ALICE_ORIGIN.clone().into(), CALL, &info, LEN, 0) + .unwrap(); + + assert_eq!(pre.0, Some(0)); + + assert_ok!(Tx::post_dispatch(pre, &info, &mut post_info, LEN, &Ok(()))); + + assert_eq!(post_info.actual_weight.unwrap(), Weight::from_parts(0, 100)); + assert_eq!(get_storage_weight().proof_size(), 1250); + }); +} + +#[test] +fn does_nothing_without_extension() { + // Proof size extension not registered + let mut test_ext = new_test_ext(); + + test_ext.execute_with(|| { + set_current_storage_weight(1000); + + // Benchmarked storage weight: 500 + let info = DispatchInfo { call_weight: Weight::from_parts(0, 500), ..Default::default() }; + let mut post_info = PostDispatchInfo::default(); + post_info.actual_weight = Some(info.total_weight()); + + let tx_ext = new_tx_ext(); + + // Check weight should add 500 + 150 (len) to weight. + let (pre, _) = tx_ext + .validate_and_prepare(ALICE_ORIGIN.clone().into(), CALL, &info, LEN, 0) + .unwrap(); + + assert_eq!(pre.0, None); + + assert_ok!(Tx::post_dispatch(pre, &info, &mut post_info, LEN, &Ok(()))); + + assert_eq!(post_info.actual_weight.unwrap(), info.total_weight()); + assert_eq!(get_storage_weight().proof_size(), 1650); + }) +} + +#[test] +fn negative_refund_is_added_to_weight() { + let mut test_ext = setup_test_externalities(&[100, 300]); + + test_ext.execute_with(|| { + set_current_storage_weight(1000); + // Benchmarked storage weight: 100 + let info = DispatchInfo { call_weight: Weight::from_parts(0, 100), ..Default::default() }; + let mut post_info = PostDispatchInfo::default(); + post_info.actual_weight = Some(info.total_weight()); + + let tx_ext = new_tx_ext(); + + // Weight added should be 100 + 150 (len) + let (pre, _) = tx_ext + .validate_and_prepare(ALICE_ORIGIN.clone().into(), CALL, &info, LEN, 0) + .unwrap(); + + assert_eq!(pre.0, Some(100)); + + // We expect no refund + assert_ok!(Tx::post_dispatch(pre, &info, &mut post_info, LEN, &Ok(()))); + + assert_eq!(post_info.actual_weight.unwrap(), info.total_weight()); + assert_eq!( + get_storage_weight().proof_size(), + 1100 + LEN as u64 + info.total_weight().proof_size() + ); + }) +} + +#[test] +fn test_zero_proof_size() { + let mut test_ext = setup_test_externalities(&[0, 0]); + + test_ext.execute_with(|| { + let info = DispatchInfo { call_weight: Weight::from_parts(0, 500), ..Default::default() }; + let mut post_info = PostDispatchInfo::default(); + post_info.actual_weight = Some(info.total_weight()); + + let tx_ext = new_tx_ext(); + + let (pre, _) = tx_ext + .validate_and_prepare(ALICE_ORIGIN.clone().into(), CALL, &info, LEN, 0) + .unwrap(); + + assert_eq!(pre.0, Some(0)); + + assert_ok!(Tx::post_dispatch(pre, &info, &mut post_info, LEN, &Ok(()))); + + assert_eq!(post_info.actual_weight.unwrap(), Weight::from_parts(0, 0)); + // Proof size should be exactly equal to extrinsic length + assert_eq!(get_storage_weight().proof_size(), LEN as u64); + }); +} + +#[test] +fn test_larger_pre_dispatch_proof_size() { + let mut test_ext = setup_test_externalities(&[300, 100]); + + test_ext.execute_with(|| { + set_current_storage_weight(1300); + + let info = DispatchInfo { call_weight: Weight::from_parts(0, 500), ..Default::default() }; + let mut post_info = PostDispatchInfo::default(); + post_info.actual_weight = Some(info.total_weight()); + + let tx_ext = new_tx_ext(); + + // Adds 500 + 150 (len) weight, total weight is 1950 + let (pre, _) = tx_ext + .validate_and_prepare(ALICE_ORIGIN.clone().into(), CALL, &info, LEN, 0) + .unwrap(); + + assert_eq!(pre.0, Some(300)); + + // check weight: + // Refund 500 unspent weight according to `post_info`, total weight is now 1650 + // + // storage reclaim: + // Recorded proof size is negative -200, total weight is now 1450 + assert_ok!(Tx::post_dispatch(pre, &info, &mut post_info, LEN, &Ok(()))); + + assert_eq!(post_info.actual_weight.unwrap(), Weight::from_parts(0, 0)); + assert_eq!(get_storage_weight().proof_size(), 1450); + }); +} + +#[test] +fn test_incorporates_check_weight_unspent_weight() { + let mut test_ext = setup_test_externalities(&[100, 300]); + + test_ext.execute_with(|| { + set_current_storage_weight(1000); + + // Benchmarked storage weight: 300 + let info = DispatchInfo { call_weight: Weight::from_parts(100, 300), ..Default::default() }; + + // Actual weight is 50 + let mut post_info = PostDispatchInfo { + actual_weight: Some(Weight::from_parts(50, 250)), + pays_fee: Default::default(), + }; + + let tx_ext = new_tx_ext(); + + // Check weight should add 300 + 150 (len) of weight + let (pre, _) = tx_ext + .validate_and_prepare(ALICE_ORIGIN.clone().into(), CALL, &info, LEN, 0) + .unwrap(); + + assert_eq!(pre.0, Some(100)); + + // The `CheckWeight` extension will refund `actual_weight` from `PostDispatchInfo` + // we always need to call `post_dispatch` to verify that they interoperate correctly. + assert_ok!(Tx::post_dispatch(pre, &info, &mut post_info, LEN, &Ok(()))); + + assert_eq!(post_info.actual_weight.unwrap(), Weight::from_parts(50, 350 - LEN as u64)); + // Reclaimed 100 + assert_eq!(get_storage_weight().proof_size(), 1350); + }) +} + +#[test] +fn test_incorporates_check_weight_unspent_weight_on_negative() { + let mut test_ext = setup_test_externalities(&[100, 300]); + + test_ext.execute_with(|| { + set_current_storage_weight(1000); + // Benchmarked storage weight: 50 + let info = DispatchInfo { call_weight: Weight::from_parts(100, 50), ..Default::default() }; + + // Actual weight is 25 + let mut post_info = PostDispatchInfo { + actual_weight: Some(Weight::from_parts(50, 25)), + pays_fee: Default::default(), + }; + + let tx_ext = new_tx_ext(); + + // Adds 50 + 150 (len) weight, total weight 1200 + let (pre, _) = tx_ext + .validate_and_prepare(ALICE_ORIGIN.clone().into(), CALL, &info, LEN, 0) + .unwrap(); + assert_eq!(pre.0, Some(100)); + + // The `CheckWeight` extension will refund `actual_weight` from `PostDispatchInfo` + // CheckWeight: refunds unspent 25 weight according to `post_info`, 1175 + // + // storage reclaim: + // Adds 200 - 25 (unspent) == 175 weight, total weight 1350 + assert_ok!(Tx::post_dispatch(pre, &info, &mut post_info, LEN, &Ok(()))); + + assert_eq!(post_info.actual_weight.unwrap(), Weight::from_parts(50, 25)); + assert_eq!(get_storage_weight().proof_size(), 1350); + }) +} + +#[test] +fn test_nothing_reclaimed() { + let mut test_ext = setup_test_externalities(&[0, 100]); + + test_ext.execute_with(|| { + set_current_storage_weight(0); + // Benchmarked storage weight: 100 + let info = DispatchInfo { call_weight: Weight::from_parts(100, 100), ..Default::default() }; + + // Actual proof size is 100 + let mut post_info = PostDispatchInfo { + actual_weight: Some(Weight::from_parts(50, 100)), + pays_fee: Default::default(), + }; + + let tx_ext = new_tx_ext(); + + // Adds benchmarked weight 100 + 150 (len), total weight is now 250 + let (pre, _) = tx_ext + .validate_and_prepare(ALICE_ORIGIN.clone().into(), CALL, &info, LEN, 0) + .unwrap(); + + // Weight should go up by 150 len + 100 proof size weight, total weight 250 + assert_eq!(get_storage_weight().proof_size(), 250); + + // Should return `setup_test_externalities` proof recorder value: 100. + assert_eq!(pre.0, Some(0)); + + // The `CheckWeight` extension will refund `actual_weight` from `PostDispatchInfo` + // we always need to call `post_dispatch` to verify that they interoperate correctly. + // Nothing to refund, unspent is 0, total weight 250 + // + // weight reclaim: + // `setup_test_externalities` proof recorder value: 200, so this means the extrinsic + // actually used 100 proof size. + // Nothing to refund or add, weight matches proof recorder + assert_ok!(Tx::post_dispatch(pre, &info, &mut post_info, LEN, &Ok(()))); + + assert_eq!(post_info.actual_weight.unwrap(), Weight::from_parts(50, 100)); + // Check block len weight was not reclaimed: + // 100 weight + 150 extrinsic len == 250 proof size + assert_eq!(get_storage_weight().proof_size(), 250); + }) +} + +// Test for refund of calls and related proof size +#[test] +fn test_series() { + struct TestCfg { + measured_proof_size_pre_dispatch: u64, + measured_proof_size_post_dispatch: u64, + info_call_weight: Weight, + info_extension_weight: Weight, + post_info_actual_weight: Option, + block_weight_pre_dispatch: Weight, + mock_ext_refund: Weight, + assert_post_info_weight: Option, + assert_block_weight_post_dispatch: Weight, + } + + let base_extrinsic = <::BlockWeights as Get< + frame_system::limits::BlockWeights, + >>::get() + .per_class + .get(DispatchClass::Normal) + .base_extrinsic; + + let tests = vec![ + // Info is exact, no post info, no refund. + TestCfg { + measured_proof_size_pre_dispatch: 100, + measured_proof_size_post_dispatch: 400, + info_call_weight: Weight::from_parts(40, 100), + info_extension_weight: Weight::from_parts(60, 200), + post_info_actual_weight: None, + block_weight_pre_dispatch: Weight::from_parts(1000, 1000), + mock_ext_refund: Weight::from_parts(0, 0), + assert_post_info_weight: None, + assert_block_weight_post_dispatch: base_extrinsic + + Weight::from_parts(1100, 1300 + LEN as u64), + }, + // some tx ext refund is ignored, because post info is None. + TestCfg { + measured_proof_size_pre_dispatch: 100, + measured_proof_size_post_dispatch: 400, + info_call_weight: Weight::from_parts(40, 100), + info_extension_weight: Weight::from_parts(60, 200), + post_info_actual_weight: None, + block_weight_pre_dispatch: Weight::from_parts(1000, 1000), + mock_ext_refund: Weight::from_parts(20, 20), + assert_post_info_weight: None, + assert_block_weight_post_dispatch: base_extrinsic + + Weight::from_parts(1100, 1300 + LEN as u64), + }, + // some tx ext refund is ignored on proof size because lower than actual measure. + TestCfg { + measured_proof_size_pre_dispatch: 100, + measured_proof_size_post_dispatch: 400, + info_call_weight: Weight::from_parts(40, 100), + info_extension_weight: Weight::from_parts(60, 200), + post_info_actual_weight: Some(Weight::from_parts(100, 300)), + block_weight_pre_dispatch: Weight::from_parts(1000, 1000), + mock_ext_refund: Weight::from_parts(20, 20), + assert_post_info_weight: Some(Weight::from_parts(80, 300)), + assert_block_weight_post_dispatch: base_extrinsic + + Weight::from_parts(1080, 1300 + LEN as u64), + }, + // post info doesn't double refund the call and is missing some. + TestCfg { + measured_proof_size_pre_dispatch: 100, + measured_proof_size_post_dispatch: 350, + info_call_weight: Weight::from_parts(40, 100), + info_extension_weight: Weight::from_parts(60, 200), + post_info_actual_weight: Some(Weight::from_parts(60, 200)), + block_weight_pre_dispatch: Weight::from_parts(1000, 1000), + mock_ext_refund: Weight::from_parts(20, 20), + // 50 are missed in pov because 100 is unspent in post info but it should be only 50. + assert_post_info_weight: Some(Weight::from_parts(40, 200)), + assert_block_weight_post_dispatch: base_extrinsic + + Weight::from_parts(1040, 1250 + LEN as u64), + }, + // post info doesn't double refund the call and is accurate. + TestCfg { + measured_proof_size_pre_dispatch: 100, + measured_proof_size_post_dispatch: 250, + info_call_weight: Weight::from_parts(40, 100), + info_extension_weight: Weight::from_parts(60, 200), + post_info_actual_weight: Some(Weight::from_parts(60, 200)), + block_weight_pre_dispatch: Weight::from_parts(1000, 1000), + mock_ext_refund: Weight::from_parts(20, 20), + assert_post_info_weight: Some(Weight::from_parts(40, 150)), + assert_block_weight_post_dispatch: base_extrinsic + + Weight::from_parts(1040, 1150 + LEN as u64), + }, + // post info doesn't double refund the call and is accurate. Even if mock ext is refunding + // too much. + TestCfg { + measured_proof_size_pre_dispatch: 100, + measured_proof_size_post_dispatch: 250, + info_call_weight: Weight::from_parts(40, 100), + info_extension_weight: Weight::from_parts(60, 200), + post_info_actual_weight: Some(Weight::from_parts(60, 200)), + block_weight_pre_dispatch: Weight::from_parts(1000, 1000), + mock_ext_refund: Weight::from_parts(20, 300), + assert_post_info_weight: Some(Weight::from_parts(40, 150)), + assert_block_weight_post_dispatch: base_extrinsic + + Weight::from_parts(1040, 1150 + LEN as u64), + }, + ]; + + for (i, test) in tests.into_iter().enumerate() { + dbg!("test number: ", i); + MOCK_EXT_REFUND.with_borrow_mut(|v| *v = test.mock_ext_refund); + let mut test_ext = setup_test_externalities(&[ + test.measured_proof_size_pre_dispatch as usize, + test.measured_proof_size_post_dispatch as usize, + ]); + + test_ext.execute_with(|| { + frame_system::BlockWeight::::mutate(|current_weight| { + current_weight.set(test.block_weight_pre_dispatch, DispatchClass::Normal); + }); + // Benchmarked storage weight: 50 + let info = DispatchInfo { + call_weight: test.info_call_weight, + extension_weight: test.info_extension_weight, + ..Default::default() + }; + let mut post_info = PostDispatchInfo { + actual_weight: test.post_info_actual_weight, + pays_fee: Default::default(), + }; + let tx_ext = new_tx_ext(); + let (pre, _) = tx_ext + .validate_and_prepare(ALICE_ORIGIN.clone().into(), CALL, &info, LEN, 0) + .unwrap(); + assert_ok!(Tx::post_dispatch(pre, &info, &mut post_info, LEN, &Ok(()))); + + assert_eq!(post_info.actual_weight, test.assert_post_info_weight); + assert_eq!( + *frame_system::BlockWeight::::get().get(DispatchClass::Normal), + test.assert_block_weight_post_dispatch, + ); + }) + } +} + +#[test] +fn storage_size_reported_correctly() { + let mut test_ext = setup_test_externalities(&[1000]); + test_ext.execute_with(|| { + assert_eq!(get_proof_size(), Some(1000)); + }); + + let mut test_ext = new_test_ext(); + + let test_recorder = TestRecorder::new(&[0]); + + test_ext.register_extension(ProofSizeExt::new(test_recorder)); + + test_ext.execute_with(|| { + assert_eq!(get_proof_size(), Some(0)); + }); +} + +#[test] +fn storage_size_disabled_reported_correctly() { + let mut test_ext = setup_test_externalities(&[PROOF_RECORDING_DISABLED as usize]); + + test_ext.execute_with(|| { + assert_eq!(get_proof_size(), None); + }); +} + +#[test] +fn full_basic_refund() { + // Settings for the test: + let actual_used_proof_size = 200; + let check_weight = 100; + let storage_weight_reclaim = 100; + let mock_ext = 142; + let mock_ext_refund = 100; + + // Test execution: + CHECK_WEIGHT_WEIGHT.with_borrow_mut(|v| *v = Weight::from_parts(1, check_weight)); + STORAGE_WEIGHT_RECLAIM_WEIGHT + .with_borrow_mut(|v| *v = Weight::from_parts(1, storage_weight_reclaim)); + MOCK_EXT_WEIGHT.with_borrow_mut(|v| *v = Weight::from_parts(36, mock_ext)); + MOCK_EXT_REFUND.with_borrow_mut(|v| *v = Weight::from_parts(35, mock_ext_refund)); + + let initial_storage_weight = 1212u64; + + let mut test_ext = setup_test_externalities(&[ + initial_storage_weight as usize, + initial_storage_weight as usize + actual_used_proof_size, + ]); + + test_ext.execute_with(|| { + set_current_storage_weight(initial_storage_weight); + + let extrinsic = new_extrinsic(); + let call_info = extrinsic.function.get_dispatch_info(); + + let info = extrinsic.get_dispatch_info(); + let post_info = extrinsic.apply::(&info, LEN).unwrap().unwrap(); + + // Assertions: + assert_eq!( + post_info.actual_weight.unwrap().ref_time(), + call_info.call_weight.ref_time() + 3, + ); + assert_eq!( + post_info.actual_weight.unwrap().proof_size(), + // LEN is part of the base extrinsic, not the post info weight actual weight. + actual_used_proof_size as u64, + ); + assert_eq!( + get_storage_weight().proof_size(), + initial_storage_weight + actual_used_proof_size as u64 + LEN as u64 + ); + }); +} + +#[test] +fn full_accrue() { + // Settings for the test: + let actual_used_proof_size = 400; + let check_weight = 100; + let storage_weight_reclaim = 100; + let mock_ext = 142; + let mock_ext_refund = 100; + + // Test execution: + CHECK_WEIGHT_WEIGHT.with_borrow_mut(|v| *v = Weight::from_parts(1, check_weight)); + STORAGE_WEIGHT_RECLAIM_WEIGHT + .with_borrow_mut(|v| *v = Weight::from_parts(1, storage_weight_reclaim)); + MOCK_EXT_WEIGHT.with_borrow_mut(|v| *v = Weight::from_parts(36, mock_ext)); + MOCK_EXT_REFUND.with_borrow_mut(|v| *v = Weight::from_parts(35, mock_ext_refund)); + + let initial_storage_weight = 1212u64; + + let mut test_ext = setup_test_externalities(&[ + initial_storage_weight as usize, + initial_storage_weight as usize + actual_used_proof_size, + ]); + + test_ext.execute_with(|| { + set_current_storage_weight(initial_storage_weight); + + let extrinsic = new_extrinsic(); + let call_info = extrinsic.function.get_dispatch_info(); + + let info = extrinsic.get_dispatch_info(); + let post_info = extrinsic.apply::(&info, LEN).unwrap().unwrap(); + + // Assertions: + assert_eq!( + post_info.actual_weight.unwrap().ref_time(), + call_info.call_weight.ref_time() + 3, + ); + assert_eq!( + post_info.actual_weight.unwrap().proof_size(), + info.total_weight().proof_size(), // The post info doesn't get the accrue. + ); + assert_eq!( + get_storage_weight().proof_size(), + initial_storage_weight + actual_used_proof_size as u64 + LEN as u64 + ); + }); +} + +#[test] +fn bare_is_reclaimed() { + let mut test_ext = setup_test_externalities(&[]); + test_ext.execute_with(|| { + let info = DispatchInfo { + call_weight: Weight::from_parts(100, 100), + extension_weight: Weight::from_parts(100, 100), + class: DispatchClass::Normal, + pays_fee: Default::default(), + }; + let mut post_info = PostDispatchInfo { + actual_weight: Some(Weight::from_parts(100, 100)), + pays_fee: Default::default(), + }; + MOCK_EXT_REFUND.with_borrow_mut(|v| *v = Weight::from_parts(10, 10)); + + frame_system::BlockWeight::::mutate(|current_weight| { + current_weight + .set(Weight::from_parts(45, 45) + info.total_weight(), DispatchClass::Normal); + }); + + StorageWeightReclaim::::bare_post_dispatch( + &info, + &mut post_info, + 0, + &Ok(()), + ) + .expect("tx is valid"); + + assert_eq!( + *frame_system::BlockWeight::::get().get(DispatchClass::Normal), + Weight::from_parts(45 + 90, 45 + 90), + ); + }); +} + +#[test] +fn sets_to_node_storage_proof_if_higher() { + struct TestCfg { + initial_proof_size: u64, + post_dispatch_proof_size: u64, + mock_ext_proof_size: u64, + pre_dispatch_block_proof_size: u64, + assert_final_block_proof_size: u64, + } + + let tests = vec![ + // The storage proof reported by the proof recorder is higher than what is stored on + // the runtime side. + TestCfg { + initial_proof_size: 1000, + post_dispatch_proof_size: 1005, + mock_ext_proof_size: 0, + pre_dispatch_block_proof_size: 5, + // We expect that the storage weight was set to the node-side proof size (1005) + + // extrinsics length (150) + assert_final_block_proof_size: 1155, + }, + // In this second scenario the proof size on the node side is only lower + // after reclaim happened. + TestCfg { + initial_proof_size: 175, + post_dispatch_proof_size: 180, + mock_ext_proof_size: 100, + pre_dispatch_block_proof_size: 85, + // After the pre_dispatch, the BlockWeight proof size will be + // 85 (initial) + 100 (benched) + 150 (tx length) = 335 + // + // We expect that the storage weight was set to the node-side proof weight + // First we will reclaim 95, which leaves us with 240 BlockWeight. + // This is lower than 180 (proof size hf) + 150 (length). + // So we expect it to be set to 330. + assert_final_block_proof_size: 330, + }, + ]; + + for test in tests { + let mut test_ext = setup_test_externalities(&[ + test.initial_proof_size as usize, + test.post_dispatch_proof_size as usize, + ]); + + CHECK_WEIGHT_WEIGHT.with_borrow_mut(|v| *v = Weight::from_parts(0, 0)); + STORAGE_WEIGHT_RECLAIM_WEIGHT.with_borrow_mut(|v| *v = Weight::from_parts(0, 0)); + MOCK_EXT_WEIGHT.with_borrow_mut(|v| *v = Weight::from_parts(0, test.mock_ext_proof_size)); + + test_ext.execute_with(|| { + set_current_storage_weight(test.pre_dispatch_block_proof_size); + + let extrinsic = new_extrinsic(); + let call_info = extrinsic.function.get_dispatch_info(); + assert_eq!(call_info.call_weight.proof_size(), 0); + + let info = extrinsic.get_dispatch_info(); + let _post_info = extrinsic.apply::(&info, LEN).unwrap().unwrap(); + + assert_eq!(get_storage_weight().proof_size(), test.assert_final_block_proof_size); + }) + } +} + +#[test] +fn test_pov_missing_from_node_reclaim() { + // Test scenario: after dispatch the pov size from node side is less than block weight. + // Ensure `pov_size_missing_from_node` is calculated correctly, and `ExtrinsicWeightReclaimed` + // is updated correctly. + + // Proof size: + let bench_pre_dispatch_call = 220; + let bench_post_dispatch_actual = 90; + let len = 20; // Only one extrinsic in the scenario. So all extrinsics length. + let block_pre_dispatch = 100; + let missing_from_node = 50; + let node_diff = 70; + + let node_pre_dispatch = block_pre_dispatch + missing_from_node; + let node_post_dispatch = node_pre_dispatch + node_diff; + + // Initialize the test. + let mut test_ext = + setup_test_externalities(&[node_pre_dispatch as usize, node_post_dispatch as usize]); + + test_ext.execute_with(|| { + set_current_storage_weight(block_pre_dispatch); + let info = DispatchInfo { + call_weight: Weight::from_parts(0, bench_pre_dispatch_call), + extension_weight: Weight::from_parts(0, 0), + ..Default::default() + }; + let post_info = PostDispatchInfo { + actual_weight: Some(Weight::from_parts(0, bench_post_dispatch_actual)), + ..Default::default() + }; + + // Execute the transaction. + let tx_ext = StorageWeightReclaim::>::new( + frame_system::CheckWeight::new(), + ); + tx_ext + .test_run(ALICE_ORIGIN.clone().into(), CALL, &info, len as usize, 0, |_| Ok(post_info)) + .expect("valid") + .expect("success"); + + // Assert the results. + assert_eq!( + frame_system::BlockWeight::::get().get(DispatchClass::Normal).proof_size(), + node_post_dispatch + len, + ); + assert_eq!( + frame_system::ExtrinsicWeightReclaimed::::get().proof_size(), + bench_pre_dispatch_call - node_diff - missing_from_node, + ); + }); +} + +#[test] +fn test_ref_time_weight_reclaim() { + // Test scenario: after dispatch the time weight is refunded correctly. + + // Time weight: + let bench_pre_dispatch_call = 145; + let bench_post_dispatch_actual = 104; + let bench_mock_ext_weight = 63; + let bench_mock_ext_refund = 22; + let len = 20; // Only one extrinsic in the scenario. So all extrinsics length. + let block_pre_dispatch = 121; + let node_pre_dispatch = 0; + let node_post_dispatch = 0; + + // Initialize the test. + CHECK_WEIGHT_WEIGHT.with_borrow_mut(|v| *v = Weight::from_parts(0, 0)); + STORAGE_WEIGHT_RECLAIM_WEIGHT.with_borrow_mut(|v| *v = Weight::from_parts(0, 0)); + MOCK_EXT_WEIGHT.with_borrow_mut(|v| *v = Weight::from_parts(bench_mock_ext_weight, 0)); + MOCK_EXT_REFUND.with_borrow_mut(|v| *v = Weight::from_parts(bench_mock_ext_refund, 0)); + + let base_extrinsic = <::BlockWeights as Get< + frame_system::limits::BlockWeights, + >>::get() + .per_class + .get(DispatchClass::Normal) + .base_extrinsic; + + let mut test_ext = + setup_test_externalities(&[node_pre_dispatch as usize, node_post_dispatch as usize]); + + test_ext.execute_with(|| { + frame_system::BlockWeight::::mutate(|current_weight| { + current_weight.set(Weight::from_parts(block_pre_dispatch, 0), DispatchClass::Normal); + }); + let info = DispatchInfo { + call_weight: Weight::from_parts(bench_pre_dispatch_call, 0), + extension_weight: Weight::from_parts(bench_mock_ext_weight, 0), + ..Default::default() + }; + let post_info = PostDispatchInfo { + actual_weight: Some(Weight::from_parts(bench_post_dispatch_actual, 0)), + ..Default::default() + }; + + type InnerTxExt = (frame_system::CheckWeight, MockExtensionWithRefund); + // Execute the transaction. + let tx_ext = StorageWeightReclaim::::new(( + frame_system::CheckWeight::new(), + MockExtensionWithRefund, + )); + tx_ext + .test_run(ALICE_ORIGIN.clone().into(), CALL, &info, len as usize, 0, |_| Ok(post_info)) + .expect("valid transaction extension pipeline") + .expect("success"); + + // Assert the results. + assert_eq!( + frame_system::BlockWeight::::get().get(DispatchClass::Normal).ref_time(), + block_pre_dispatch + + base_extrinsic.ref_time() + + bench_post_dispatch_actual + + bench_mock_ext_weight - + bench_mock_ext_refund, + ); + assert_eq!( + frame_system::ExtrinsicWeightReclaimed::::get().ref_time(), + bench_pre_dispatch_call - bench_post_dispatch_actual + bench_mock_ext_refund, + ); + }); +} + +#[test] +fn test_metadata() { + assert_eq!( + StorageWeightReclaim::>::metadata() + .iter() + .map(|m| m.identifier) + .collect::>(), + vec!["CheckWeight", "StorageWeightReclaim"] + ); +} diff --git a/cumulus/pallets/weight-reclaim/src/weights.rs b/cumulus/pallets/weight-reclaim/src/weights.rs new file mode 100644 index 000000000000..e651c8a78318 --- /dev/null +++ b/cumulus/pallets/weight-reclaim/src/weights.rs @@ -0,0 +1,74 @@ +// 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 . + +//! Autogenerated weights for `cumulus_pallet_weight_reclaim` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-08-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `fedora`, CPU: `13th Gen Intel(R) Core(TM) i7-1360P` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` + +// Executed Command: +// ./target/release/parachain-template-node +// benchmark +// pallet +// --pallet +// cumulus-pallet-weight-reclaim +// --chain +// dev +// --output +// cumulus/pallets/weight-reclaim/src/weights.rs +// --template +// substrate/.maintain/frame-weight-template.hbs +// --extrinsic +// * + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use core::marker::PhantomData; + +/// Weight functions needed for `cumulus_pallet_weight_reclaim`. +pub trait WeightInfo { + fn storage_weight_reclaim() -> Weight; +} + +/// Weights for `cumulus_pallet_weight_reclaim` using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +impl WeightInfo for SubstrateWeight { + fn storage_weight_reclaim() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_247_000 picoseconds. + Weight::from_parts(2_466_000, 0) + } +} + +// For backwards compatibility and tests. +impl WeightInfo for () { + fn storage_weight_reclaim() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_247_000 picoseconds. + Weight::from_parts(2_466_000, 0) + } +} diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml b/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml index c954ddb7b8c7..abe59a8439a8 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml @@ -80,11 +80,11 @@ assets-common = { workspace = true } cumulus-pallet-aura-ext = { workspace = true } cumulus-pallet-parachain-system = { workspace = true } cumulus-pallet-session-benchmarking = { workspace = true } +cumulus-pallet-weight-reclaim = { workspace = true } cumulus-pallet-xcm = { workspace = true } cumulus-pallet-xcmp-queue = { features = ["bridging"], workspace = true } cumulus-primitives-aura = { workspace = true } cumulus-primitives-core = { workspace = true } -cumulus-primitives-storage-weight-reclaim = { workspace = true } cumulus-primitives-utility = { workspace = true } pallet-collator-selection = { workspace = true } parachain-info = { workspace = true } @@ -112,6 +112,7 @@ runtime-benchmarks = [ "assets-common/runtime-benchmarks", "cumulus-pallet-parachain-system/runtime-benchmarks", "cumulus-pallet-session-benchmarking/runtime-benchmarks", + "cumulus-pallet-weight-reclaim/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", "cumulus-primitives-core/runtime-benchmarks", "cumulus-primitives-utility/runtime-benchmarks", @@ -151,6 +152,7 @@ runtime-benchmarks = [ try-runtime = [ "cumulus-pallet-aura-ext/try-runtime", "cumulus-pallet-parachain-system/try-runtime", + "cumulus-pallet-weight-reclaim/try-runtime", "cumulus-pallet-xcm/try-runtime", "cumulus-pallet-xcmp-queue/try-runtime", "frame-executive/try-runtime", @@ -192,11 +194,11 @@ std = [ "cumulus-pallet-aura-ext/std", "cumulus-pallet-parachain-system/std", "cumulus-pallet-session-benchmarking/std", + "cumulus-pallet-weight-reclaim/std", "cumulus-pallet-xcm/std", "cumulus-pallet-xcmp-queue/std", "cumulus-primitives-aura/std", "cumulus-primitives-core/std", - "cumulus-primitives-storage-weight-reclaim/std", "cumulus-primitives-utility/std", "frame-benchmarking?/std", "frame-executive/std", diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index dd1535826152..1db152e39fd9 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -182,6 +182,10 @@ impl frame_system::Config for Runtime { type MaxConsumers = frame_support::traits::ConstU32<16>; } +impl cumulus_pallet_weight_reclaim::Config for Runtime { + type WeightInfo = weights::cumulus_pallet_weight_reclaim::WeightInfo; +} + impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. type Moment = u64; @@ -958,6 +962,7 @@ construct_runtime!( ParachainSystem: cumulus_pallet_parachain_system = 1, Timestamp: pallet_timestamp = 3, ParachainInfo: parachain_info = 4, + WeightReclaim: cumulus_pallet_weight_reclaim = 5, // Monetary stuff. Balances: pallet_balances = 10, @@ -1012,18 +1017,20 @@ pub type SignedBlock = generic::SignedBlock; /// BlockId type as expected by this runtime. pub type BlockId = generic::BlockId; /// The extension to the basic transaction logic. -pub type TxExtension = ( - frame_system::CheckNonZeroSender, - frame_system::CheckSpecVersion, - frame_system::CheckTxVersion, - frame_system::CheckGenesis, - frame_system::CheckEra, - frame_system::CheckNonce, - frame_system::CheckWeight, - pallet_asset_conversion_tx_payment::ChargeAssetTxPayment, - cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim, - frame_metadata_hash_extension::CheckMetadataHash, -); +pub type TxExtension = cumulus_pallet_weight_reclaim::StorageWeightReclaim< + Runtime, + ( + frame_system::CheckNonZeroSender, + frame_system::CheckSpecVersion, + frame_system::CheckTxVersion, + frame_system::CheckGenesis, + frame_system::CheckEra, + frame_system::CheckNonce, + frame_system::CheckWeight, + pallet_asset_conversion_tx_payment::ChargeAssetTxPayment, + frame_metadata_hash_extension::CheckMetadataHash, + ), +>; /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; @@ -1207,6 +1214,7 @@ mod benches { // NOTE: Make sure you point to the individual modules below. [pallet_xcm_benchmarks::fungible, XcmBalances] [pallet_xcm_benchmarks::generic, XcmGeneric] + [cumulus_pallet_weight_reclaim, WeightReclaim] ); } @@ -1854,20 +1862,8 @@ impl_runtime_apis! { type ToWestend = XcmBridgeHubRouterBench; - let whitelist: Vec = vec![ - // Block Number - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(), - // Total Issuance - hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(), - // Execution Phase - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(), - // Event Count - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(), - // System Events - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(), - //TODO: use from relay_well_known_keys::ACTIVE_CONFIG - hex_literal::hex!("06de3d8a54d27e44a9d5ce189618f22db4b49d95320d9021994c850f25b8e385").to_vec().into(), - ]; + use frame_support::traits::WhitelistedStorageKeys; + let whitelist: Vec = AllPalletsWithSystem::whitelisted_storage_keys(); let mut batches = Vec::::new(); let params = (&config, &whitelist); diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/cumulus_pallet_weight_reclaim.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/cumulus_pallet_weight_reclaim.rs new file mode 100644 index 000000000000..c8f9bb7cd56c --- /dev/null +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/cumulus_pallet_weight_reclaim.rs @@ -0,0 +1,67 @@ +// 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 . + +//! Autogenerated weights for `cumulus_pallet_weight_reclaim` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-12-30, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `runner-ys-ssygq-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("asset-hub-rococo-dev")`, DB CACHE: 1024 + +// Executed Command: +// target/production/polkadot-parachain +// benchmark +// pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --wasm-execution=compiled +// --heap-pages=4096 +// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json +// --pallet=cumulus_pallet_weight_reclaim +// --chain=asset-hub-rococo-dev +// --header=./cumulus/file_header.txt +// --output=./cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `cumulus_pallet_weight_reclaim`. +pub struct WeightInfo(PhantomData); +impl cumulus_pallet_weight_reclaim::WeightInfo for WeightInfo { + /// Storage: `System::BlockWeight` (r:1 w:1) + /// Proof: `System::BlockWeight` (`max_values`: Some(1), `max_size`: Some(48), added: 543, mode: `MaxEncodedLen`) + /// Storage: `System::ExtrinsicWeightReclaimed` (r:1 w:1) + /// Proof: `System::ExtrinsicWeightReclaimed` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) + /// Storage: `System::AllExtrinsicsLen` (r:1 w:0) + /// Proof: `System::AllExtrinsicsLen` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + fn storage_weight_reclaim() -> Weight { + // Proof Size summary in bytes: + // Measured: `24` + // Estimated: `1533` + // Minimum execution time: 7_301_000 picoseconds. + Weight::from_parts(7_536_000, 0) + .saturating_add(Weight::from_parts(0, 1533)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) + } +} diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/frame_system_extensions.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/frame_system_extensions.rs index 182410f20fff..a5c9fea3cdf5 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/frame_system_extensions.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/frame_system_extensions.rs @@ -16,28 +16,29 @@ //! Autogenerated weights for `frame_system_extensions` //! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-21, STEPS: `2`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-10-31, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `gleipnir`, CPU: `AMD Ryzen 9 7900X 12-Core Processor` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("asset-hub-rococo-dev")`, DB CACHE: 1024 +//! HOSTNAME: `697235d969a1`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: 1024 // Executed Command: -// ./target/release/polkadot-parachain +// frame-omni-bencher +// v1 // benchmark // pallet -// --wasm-execution=compiled +// --extrinsic=* +// --runtime=target/release/wbuild/asset-hub-rococo-runtime/asset_hub_rococo_runtime.wasm // --pallet=frame_system_extensions +// --header=/__w/polkadot-sdk/polkadot-sdk/cumulus/file_header.txt +// --output=./cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights +// --wasm-execution=compiled +// --steps=50 +// --repeat=20 +// --heap-pages=4096 // --no-storage-info -// --no-median-slopes // --no-min-squares -// --extrinsic=* -// --steps=2 -// --repeat=2 -// --json -// --header=./cumulus/file_header.txt -// --output=./cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/ -// --chain=asset-hub-rococo-dev +// --no-median-slopes #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -56,8 +57,8 @@ impl frame_system::ExtensionsWeightInfo for WeightInfo< // Proof Size summary in bytes: // Measured: `54` // Estimated: `3509` - // Minimum execution time: 3_637_000 picoseconds. - Weight::from_parts(6_382_000, 0) + // Minimum execution time: 8_313_000 picoseconds. + Weight::from_parts(8_528_000, 0) .saturating_add(Weight::from_parts(0, 3509)) .saturating_add(T::DbWeight::get().reads(1)) } @@ -67,8 +68,8 @@ impl frame_system::ExtensionsWeightInfo for WeightInfo< // Proof Size summary in bytes: // Measured: `92` // Estimated: `3509` - // Minimum execution time: 5_841_000 picoseconds. - Weight::from_parts(8_776_000, 0) + // Minimum execution time: 12_527_000 picoseconds. + Weight::from_parts(13_006_000, 0) .saturating_add(Weight::from_parts(0, 3509)) .saturating_add(T::DbWeight::get().reads(1)) } @@ -78,8 +79,8 @@ impl frame_system::ExtensionsWeightInfo for WeightInfo< // Proof Size summary in bytes: // Measured: `92` // Estimated: `3509` - // Minimum execution time: 5_841_000 picoseconds. - Weight::from_parts(8_776_000, 0) + // Minimum execution time: 12_380_000 picoseconds. + Weight::from_parts(12_922_000, 0) .saturating_add(Weight::from_parts(0, 3509)) .saturating_add(T::DbWeight::get().reads(1)) } @@ -87,44 +88,64 @@ impl frame_system::ExtensionsWeightInfo for WeightInfo< // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 561_000 picoseconds. - Weight::from_parts(2_705_000, 0) + // Minimum execution time: 782_000 picoseconds. + Weight::from_parts(855_000, 0) .saturating_add(Weight::from_parts(0, 0)) } + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) fn check_nonce() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 3_316_000 picoseconds. - Weight::from_parts(5_771_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Measured: `101` + // Estimated: `3593` + // Minimum execution time: 11_743_000 picoseconds. + Weight::from_parts(12_067_000, 0) + .saturating_add(Weight::from_parts(0, 3593)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } fn check_spec_version() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 511_000 picoseconds. - Weight::from_parts(2_575_000, 0) + // Minimum execution time: 644_000 picoseconds. + Weight::from_parts(697_000, 0) .saturating_add(Weight::from_parts(0, 0)) } fn check_tx_version() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 501_000 picoseconds. - Weight::from_parts(2_595_000, 0) + // Minimum execution time: 605_000 picoseconds. + Weight::from_parts(700_000, 0) .saturating_add(Weight::from_parts(0, 0)) } /// Storage: `System::AllExtrinsicsLen` (r:1 w:1) /// Proof: `System::AllExtrinsicsLen` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) /// Storage: `System::BlockWeight` (r:1 w:1) /// Proof: `System::BlockWeight` (`max_values`: Some(1), `max_size`: Some(48), added: 543, mode: `MaxEncodedLen`) + /// Storage: `System::ExtrinsicWeightReclaimed` (r:1 w:1) + /// Proof: `System::ExtrinsicWeightReclaimed` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) fn check_weight() -> Weight { // Proof Size summary in bytes: // Measured: `24` // Estimated: `1533` - // Minimum execution time: 3_687_000 picoseconds. - Weight::from_parts(6_192_000, 0) + // Minimum execution time: 9_796_000 picoseconds. + Weight::from_parts(10_365_000, 0) + .saturating_add(Weight::from_parts(0, 1533)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: `System::ExtrinsicWeightReclaimed` (r:1 w:1) + /// Proof: `System::ExtrinsicWeightReclaimed` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) + /// Storage: `System::BlockWeight` (r:1 w:1) + /// Proof: `System::BlockWeight` (`max_values`: Some(1), `max_size`: Some(48), added: 543, mode: `MaxEncodedLen`) + fn weight_reclaim() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `1533` + // Minimum execution time: 4_855_000 picoseconds. + Weight::from_parts(5_050_000, 0) .saturating_add(Weight::from_parts(0, 1533)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(2)) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/mod.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/mod.rs index 33f111009ed0..ae78a56d8b3c 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/mod.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/weights/mod.rs @@ -16,6 +16,7 @@ pub mod block_weights; pub mod cumulus_pallet_parachain_system; +pub mod cumulus_pallet_weight_reclaim; pub mod cumulus_pallet_xcmp_queue; pub mod extrinsic_weights; pub mod frame_system; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml b/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml index 7c31745d8f6e..cb10ae9a4800 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml @@ -81,11 +81,11 @@ assets-common = { workspace = true } cumulus-pallet-aura-ext = { workspace = true } cumulus-pallet-parachain-system = { workspace = true } cumulus-pallet-session-benchmarking = { workspace = true } +cumulus-pallet-weight-reclaim = { workspace = true } cumulus-pallet-xcm = { workspace = true } cumulus-pallet-xcmp-queue = { features = ["bridging"], workspace = true } cumulus-primitives-aura = { workspace = true } cumulus-primitives-core = { workspace = true } -cumulus-primitives-storage-weight-reclaim = { workspace = true } cumulus-primitives-utility = { workspace = true } pallet-collator-selection = { workspace = true } pallet-message-queue = { workspace = true } @@ -114,6 +114,7 @@ runtime-benchmarks = [ "assets-common/runtime-benchmarks", "cumulus-pallet-parachain-system/runtime-benchmarks", "cumulus-pallet-session-benchmarking/runtime-benchmarks", + "cumulus-pallet-weight-reclaim/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", "cumulus-primitives-core/runtime-benchmarks", "cumulus-primitives-utility/runtime-benchmarks", @@ -155,6 +156,7 @@ runtime-benchmarks = [ try-runtime = [ "cumulus-pallet-aura-ext/try-runtime", "cumulus-pallet-parachain-system/try-runtime", + "cumulus-pallet-weight-reclaim/try-runtime", "cumulus-pallet-xcm/try-runtime", "cumulus-pallet-xcmp-queue/try-runtime", "frame-executive/try-runtime", @@ -198,11 +200,11 @@ std = [ "cumulus-pallet-aura-ext/std", "cumulus-pallet-parachain-system/std", "cumulus-pallet-session-benchmarking/std", + "cumulus-pallet-weight-reclaim/std", "cumulus-pallet-xcm/std", "cumulus-pallet-xcmp-queue/std", "cumulus-primitives-aura/std", "cumulus-primitives-core/std", - "cumulus-primitives-storage-weight-reclaim/std", "cumulus-primitives-utility/std", "frame-benchmarking?/std", "frame-executive/std", diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index 061cbc914314..56dba8f8b7b6 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -183,6 +183,10 @@ impl frame_system::Config for Runtime { type MaxConsumers = frame_support::traits::ConstU32<16>; } +impl cumulus_pallet_weight_reclaim::Config for Runtime { + type WeightInfo = weights::cumulus_pallet_weight_reclaim::WeightInfo; +} + impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. type Moment = u64; @@ -996,6 +1000,7 @@ construct_runtime!( // RandomnessCollectiveFlip = 2 removed Timestamp: pallet_timestamp = 3, ParachainInfo: parachain_info = 4, + WeightReclaim: cumulus_pallet_weight_reclaim = 5, // Monetary stuff. Balances: pallet_balances = 10, @@ -1053,18 +1058,20 @@ pub type SignedBlock = generic::SignedBlock; /// BlockId type as expected by this runtime. pub type BlockId = generic::BlockId; /// The extension to the basic transaction logic. -pub type TxExtension = ( - frame_system::CheckNonZeroSender, - frame_system::CheckSpecVersion, - frame_system::CheckTxVersion, - frame_system::CheckGenesis, - frame_system::CheckEra, - frame_system::CheckNonce, - frame_system::CheckWeight, - pallet_asset_conversion_tx_payment::ChargeAssetTxPayment, - cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim, - frame_metadata_hash_extension::CheckMetadataHash, -); +pub type TxExtension = cumulus_pallet_weight_reclaim::StorageWeightReclaim< + Runtime, + ( + frame_system::CheckNonZeroSender, + frame_system::CheckSpecVersion, + frame_system::CheckTxVersion, + frame_system::CheckGenesis, + frame_system::CheckEra, + frame_system::CheckNonce, + frame_system::CheckWeight, + pallet_asset_conversion_tx_payment::ChargeAssetTxPayment, + frame_metadata_hash_extension::CheckMetadataHash, + ), +>; /// Default extensions applied to Ethereum transactions. #[derive(Clone, PartialEq, Eq, Debug)] @@ -1084,9 +1091,9 @@ impl EthExtra for EthExtraImpl { frame_system::CheckNonce::::from(nonce), frame_system::CheckWeight::::new(), pallet_asset_conversion_tx_payment::ChargeAssetTxPayment::::from(tip, None), - cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim::::new(), frame_metadata_hash_extension::CheckMetadataHash::::new(false), ) + .into() } } @@ -1333,6 +1340,7 @@ mod benches { // NOTE: Make sure you point to the individual modules below. [pallet_xcm_benchmarks::fungible, XcmBalances] [pallet_xcm_benchmarks::generic, XcmGeneric] + [cumulus_pallet_weight_reclaim, WeightReclaim] ); } @@ -2026,20 +2034,8 @@ impl_runtime_apis! { type ToRococo = XcmBridgeHubRouterBench; - let whitelist: Vec = vec![ - // Block Number - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(), - // Total Issuance - hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(), - // Execution Phase - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(), - // Event Count - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(), - // System Events - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(), - //TODO: use from relay_well_known_keys::ACTIVE_CONFIG - hex_literal::hex!("06de3d8a54d27e44a9d5ce189618f22db4b49d95320d9021994c850f25b8e385").to_vec().into(), - ]; + use frame_support::traits::WhitelistedStorageKeys; + let whitelist: Vec = AllPalletsWithSystem::whitelisted_storage_keys(); let mut batches = Vec::::new(); let params = (&config, &whitelist); diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/cumulus_pallet_weight_reclaim.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/cumulus_pallet_weight_reclaim.rs new file mode 100644 index 000000000000..1573a278e246 --- /dev/null +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/cumulus_pallet_weight_reclaim.rs @@ -0,0 +1,67 @@ +// 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 . + +//! Autogenerated weights for `cumulus_pallet_weight_reclaim` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-12-30, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `runner-ys-ssygq-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("asset-hub-westend-dev")`, DB CACHE: 1024 + +// Executed Command: +// target/production/polkadot-parachain +// benchmark +// pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --wasm-execution=compiled +// --heap-pages=4096 +// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json +// --pallet=cumulus_pallet_weight_reclaim +// --chain=asset-hub-westend-dev +// --header=./cumulus/file_header.txt +// --output=./cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `cumulus_pallet_weight_reclaim`. +pub struct WeightInfo(PhantomData); +impl cumulus_pallet_weight_reclaim::WeightInfo for WeightInfo { + /// Storage: `System::BlockWeight` (r:1 w:1) + /// Proof: `System::BlockWeight` (`max_values`: Some(1), `max_size`: Some(48), added: 543, mode: `MaxEncodedLen`) + /// Storage: `System::ExtrinsicWeightReclaimed` (r:1 w:1) + /// Proof: `System::ExtrinsicWeightReclaimed` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) + /// Storage: `System::AllExtrinsicsLen` (r:1 w:0) + /// Proof: `System::AllExtrinsicsLen` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + fn storage_weight_reclaim() -> Weight { + // Proof Size summary in bytes: + // Measured: `24` + // Estimated: `1533` + // Minimum execution time: 7_470_000 picoseconds. + Weight::from_parts(7_695_000, 0) + .saturating_add(Weight::from_parts(0, 1533)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) + } +} diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/frame_system_extensions.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/frame_system_extensions.rs index e8dd9763c282..a1bb92cf7008 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/frame_system_extensions.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/frame_system_extensions.rs @@ -16,28 +16,29 @@ //! Autogenerated weights for `frame_system_extensions` //! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-21, STEPS: `2`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-10-31, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `gleipnir`, CPU: `AMD Ryzen 9 7900X 12-Core Processor` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("asset-hub-westend-dev")`, DB CACHE: 1024 +//! HOSTNAME: `697235d969a1`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: 1024 // Executed Command: -// ./target/release/polkadot-parachain +// frame-omni-bencher +// v1 // benchmark // pallet -// --wasm-execution=compiled +// --extrinsic=* +// --runtime=target/release/wbuild/asset-hub-westend-runtime/asset_hub_westend_runtime.wasm // --pallet=frame_system_extensions +// --header=/__w/polkadot-sdk/polkadot-sdk/cumulus/file_header.txt +// --output=./cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights +// --wasm-execution=compiled +// --steps=50 +// --repeat=20 +// --heap-pages=4096 // --no-storage-info -// --no-median-slopes // --no-min-squares -// --extrinsic=* -// --steps=2 -// --repeat=2 -// --json -// --header=./cumulus/file_header.txt -// --output=./cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/ -// --chain=asset-hub-westend-dev +// --no-median-slopes #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -56,8 +57,8 @@ impl frame_system::ExtensionsWeightInfo for WeightInfo< // Proof Size summary in bytes: // Measured: `54` // Estimated: `3509` - // Minimum execution time: 3_206_000 picoseconds. - Weight::from_parts(6_212_000, 0) + // Minimum execution time: 6_329_000 picoseconds. + Weight::from_parts(6_665_000, 0) .saturating_add(Weight::from_parts(0, 3509)) .saturating_add(T::DbWeight::get().reads(1)) } @@ -67,8 +68,8 @@ impl frame_system::ExtensionsWeightInfo for WeightInfo< // Proof Size summary in bytes: // Measured: `92` // Estimated: `3509` - // Minimum execution time: 5_851_000 picoseconds. - Weight::from_parts(8_847_000, 0) + // Minimum execution time: 12_110_000 picoseconds. + Weight::from_parts(12_883_000, 0) .saturating_add(Weight::from_parts(0, 3509)) .saturating_add(T::DbWeight::get().reads(1)) } @@ -78,8 +79,8 @@ impl frame_system::ExtensionsWeightInfo for WeightInfo< // Proof Size summary in bytes: // Measured: `92` // Estimated: `3509` - // Minimum execution time: 5_851_000 picoseconds. - Weight::from_parts(8_847_000, 0) + // Minimum execution time: 12_241_000 picoseconds. + Weight::from_parts(12_780_000, 0) .saturating_add(Weight::from_parts(0, 3509)) .saturating_add(T::DbWeight::get().reads(1)) } @@ -87,44 +88,64 @@ impl frame_system::ExtensionsWeightInfo for WeightInfo< // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 631_000 picoseconds. - Weight::from_parts(3_086_000, 0) + // Minimum execution time: 825_000 picoseconds. + Weight::from_parts(890_000, 0) .saturating_add(Weight::from_parts(0, 0)) } + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) fn check_nonce() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 3_446_000 picoseconds. - Weight::from_parts(5_911_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Measured: `101` + // Estimated: `3593` + // Minimum execution time: 10_159_000 picoseconds. + Weight::from_parts(10_461_000, 0) + .saturating_add(Weight::from_parts(0, 3593)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } fn check_spec_version() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 481_000 picoseconds. - Weight::from_parts(2_916_000, 0) + // Minimum execution time: 578_000 picoseconds. + Weight::from_parts(660_000, 0) .saturating_add(Weight::from_parts(0, 0)) } fn check_tx_version() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 501_000 picoseconds. - Weight::from_parts(2_595_000, 0) + // Minimum execution time: 618_000 picoseconds. + Weight::from_parts(682_000, 0) .saturating_add(Weight::from_parts(0, 0)) } /// Storage: `System::AllExtrinsicsLen` (r:1 w:1) /// Proof: `System::AllExtrinsicsLen` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) /// Storage: `System::BlockWeight` (r:1 w:1) /// Proof: `System::BlockWeight` (`max_values`: Some(1), `max_size`: Some(48), added: 543, mode: `MaxEncodedLen`) + /// Storage: `System::ExtrinsicWeightReclaimed` (r:1 w:1) + /// Proof: `System::ExtrinsicWeightReclaimed` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) fn check_weight() -> Weight { // Proof Size summary in bytes: // Measured: `24` // Estimated: `1533` - // Minimum execution time: 3_927_000 picoseconds. - Weight::from_parts(6_613_000, 0) + // Minimum execution time: 9_964_000 picoseconds. + Weight::from_parts(10_419_000, 0) + .saturating_add(Weight::from_parts(0, 1533)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: `System::ExtrinsicWeightReclaimed` (r:1 w:1) + /// Proof: `System::ExtrinsicWeightReclaimed` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) + /// Storage: `System::BlockWeight` (r:1 w:1) + /// Proof: `System::BlockWeight` (`max_values`: Some(1), `max_size`: Some(48), added: 543, mode: `MaxEncodedLen`) + fn weight_reclaim() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `1533` + // Minimum execution time: 4_890_000 picoseconds. + Weight::from_parts(5_163_000, 0) .saturating_add(Weight::from_parts(0, 1533)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(2)) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/mod.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/mod.rs index b0f986768f40..442b58635f48 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/mod.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/weights/mod.rs @@ -15,6 +15,7 @@ pub mod block_weights; pub mod cumulus_pallet_parachain_system; +pub mod cumulus_pallet_weight_reclaim; pub mod cumulus_pallet_xcmp_queue; pub mod extrinsic_weights; pub mod frame_system; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml index 3fabea3b02f4..3dba65ae99f1 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml @@ -72,11 +72,11 @@ xcm-runtime-apis = { workspace = true } cumulus-pallet-aura-ext = { workspace = true } cumulus-pallet-parachain-system = { workspace = true } cumulus-pallet-session-benchmarking = { workspace = true } +cumulus-pallet-weight-reclaim = { workspace = true } cumulus-pallet-xcm = { workspace = true } cumulus-pallet-xcmp-queue = { features = ["bridging"], workspace = true } cumulus-primitives-aura = { workspace = true } cumulus-primitives-core = { workspace = true } -cumulus-primitives-storage-weight-reclaim = { workspace = true } cumulus-primitives-utility = { workspace = true } pallet-collator-selection = { workspace = true } parachain-info = { workspace = true } @@ -151,11 +151,11 @@ std = [ "cumulus-pallet-aura-ext/std", "cumulus-pallet-parachain-system/std", "cumulus-pallet-session-benchmarking/std", + "cumulus-pallet-weight-reclaim/std", "cumulus-pallet-xcm/std", "cumulus-pallet-xcmp-queue/std", "cumulus-primitives-aura/std", "cumulus-primitives-core/std", - "cumulus-primitives-storage-weight-reclaim/std", "cumulus-primitives-utility/std", "frame-benchmarking/std", "frame-executive/std", @@ -230,6 +230,7 @@ runtime-benchmarks = [ "bridge-runtime-common/runtime-benchmarks", "cumulus-pallet-parachain-system/runtime-benchmarks", "cumulus-pallet-session-benchmarking/runtime-benchmarks", + "cumulus-pallet-weight-reclaim/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", "cumulus-primitives-core/runtime-benchmarks", "cumulus-primitives-utility/runtime-benchmarks", @@ -272,6 +273,7 @@ runtime-benchmarks = [ try-runtime = [ "cumulus-pallet-aura-ext/try-runtime", "cumulus-pallet-parachain-system/try-runtime", + "cumulus-pallet-weight-reclaim/try-runtime", "cumulus-pallet-xcm/try-runtime", "cumulus-pallet-xcmp-queue/try-runtime", "frame-executive/try-runtime", diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index 492b731610ce..35af034310d9 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -124,20 +124,22 @@ pub type SignedBlock = generic::SignedBlock; pub type BlockId = generic::BlockId; /// The TransactionExtension to the basic transaction logic. -pub type TxExtension = ( - frame_system::CheckNonZeroSender, - frame_system::CheckSpecVersion, - frame_system::CheckTxVersion, - frame_system::CheckGenesis, - frame_system::CheckEra, - frame_system::CheckNonce, - frame_system::CheckWeight, - pallet_transaction_payment::ChargeTransactionPayment, - BridgeRejectObsoleteHeadersAndMessages, - (bridge_to_westend_config::OnBridgeHubRococoRefundBridgeHubWestendMessages,), - frame_metadata_hash_extension::CheckMetadataHash, - cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim, -); +pub type TxExtension = cumulus_pallet_weight_reclaim::StorageWeightReclaim< + Runtime, + ( + frame_system::CheckNonZeroSender, + frame_system::CheckSpecVersion, + frame_system::CheckTxVersion, + frame_system::CheckGenesis, + frame_system::CheckEra, + frame_system::CheckNonce, + frame_system::CheckWeight, + pallet_transaction_payment::ChargeTransactionPayment, + BridgeRejectObsoleteHeadersAndMessages, + (bridge_to_westend_config::OnBridgeHubRococoRefundBridgeHubWestendMessages,), + frame_metadata_hash_extension::CheckMetadataHash, + ), +>; /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = @@ -313,6 +315,10 @@ impl frame_system::Config for Runtime { type MaxConsumers = frame_support::traits::ConstU32<16>; } +impl cumulus_pallet_weight_reclaim::Config for Runtime { + type WeightInfo = weights::cumulus_pallet_weight_reclaim::WeightInfo; +} + impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. type Moment = u64; @@ -555,6 +561,7 @@ construct_runtime!( ParachainSystem: cumulus_pallet_parachain_system = 1, Timestamp: pallet_timestamp = 2, ParachainInfo: parachain_info = 3, + WeightReclaim: cumulus_pallet_weight_reclaim = 4, // Monetary stuff. Balances: pallet_balances = 10, @@ -667,6 +674,7 @@ mod benches { [pallet_collator_selection, CollatorSelection] [cumulus_pallet_parachain_system, ParachainSystem] [cumulus_pallet_xcmp_queue, XcmpQueue] + [cumulus_pallet_weight_reclaim, WeightReclaim] // XCM [pallet_xcm, PalletXcmExtrinsicsBenchmark::] // NOTE: Make sure you point to the individual modules below. @@ -1498,18 +1506,8 @@ impl_runtime_apis! { } } - let whitelist: Vec = vec![ - // Block Number - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(), - // Total Issuance - hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(), - // Execution Phase - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(), - // Event Count - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(), - // System Events - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(), - ]; + use frame_support::traits::WhitelistedStorageKeys; + let whitelist: Vec = AllPalletsWithSystem::whitelisted_storage_keys(); let mut batches = Vec::::new(); let params = (&config, &whitelist); @@ -1557,41 +1555,44 @@ mod tests { use bp_polkadot_core::SuffixedCommonTransactionExtensionExt; sp_io::TestExternalities::default().execute_with(|| { - frame_system::BlockHash::::insert(BlockNumber::zero(), Hash::default()); - let payload: TxExtension = ( - frame_system::CheckNonZeroSender::new(), - frame_system::CheckSpecVersion::new(), - frame_system::CheckTxVersion::new(), - frame_system::CheckGenesis::new(), - frame_system::CheckEra::from(Era::Immortal), - frame_system::CheckNonce::from(10), - frame_system::CheckWeight::new(), - pallet_transaction_payment::ChargeTransactionPayment::from(10), - BridgeRejectObsoleteHeadersAndMessages, - ( - bridge_to_westend_config::OnBridgeHubRococoRefundBridgeHubWestendMessages::default(), - ), - frame_metadata_hash_extension::CheckMetadataHash::new(false), - cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim::new(), - ); - - // for BridgeHubRococo - { - let bhr_indirect_payload = bp_bridge_hub_rococo::TransactionExtension::from_params( - VERSION.spec_version, - VERSION.transaction_version, - bp_runtime::TransactionEra::Immortal, - System::block_hash(BlockNumber::zero()), - 10, - 10, - (((), ()), ((), ())), - ); - assert_eq!(payload.encode().split_last().unwrap().1, bhr_indirect_payload.encode()); - assert_eq!( - TxExtension::implicit(&payload).unwrap().encode().split_last().unwrap().1, - sp_runtime::traits::TransactionExtension::::implicit(&bhr_indirect_payload).unwrap().encode() - ) - } - }); + frame_system::BlockHash::::insert(BlockNumber::zero(), Hash::default()); + let payload: TxExtension = ( + frame_system::CheckNonZeroSender::new(), + frame_system::CheckSpecVersion::new(), + frame_system::CheckTxVersion::new(), + frame_system::CheckGenesis::new(), + frame_system::CheckEra::from(Era::Immortal), + frame_system::CheckNonce::from(10), + frame_system::CheckWeight::new(), + pallet_transaction_payment::ChargeTransactionPayment::from(10), + BridgeRejectObsoleteHeadersAndMessages, + ( + bridge_to_westend_config::OnBridgeHubRococoRefundBridgeHubWestendMessages::default(), + ), + frame_metadata_hash_extension::CheckMetadataHash::new(false), + ).into(); + + // for BridgeHubRococo + { + let bhr_indirect_payload = bp_bridge_hub_rococo::TransactionExtension::from_params( + VERSION.spec_version, + VERSION.transaction_version, + bp_runtime::TransactionEra::Immortal, + System::block_hash(BlockNumber::zero()), + 10, + 10, + (((), ()), ((), ())), + ); + assert_eq!(payload.encode().split_last().unwrap().1, bhr_indirect_payload.encode()); + assert_eq!( + TxExtension::implicit(&payload).unwrap().encode().split_last().unwrap().1, + sp_runtime::traits::TransactionExtension::::implicit( + &bhr_indirect_payload + ) + .unwrap() + .encode() + ) + } + }); } } diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/cumulus_pallet_weight_reclaim.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/cumulus_pallet_weight_reclaim.rs new file mode 100644 index 000000000000..ca1d8dcbe567 --- /dev/null +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/cumulus_pallet_weight_reclaim.rs @@ -0,0 +1,67 @@ +// 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 . + +//! Autogenerated weights for `cumulus_pallet_weight_reclaim` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-12-30, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `runner-ys-ssygq-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("bridge-hub-rococo-dev")`, DB CACHE: 1024 + +// Executed Command: +// target/production/polkadot-parachain +// benchmark +// pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --wasm-execution=compiled +// --heap-pages=4096 +// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json +// --pallet=cumulus_pallet_weight_reclaim +// --chain=bridge-hub-rococo-dev +// --header=./cumulus/file_header.txt +// --output=./cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `cumulus_pallet_weight_reclaim`. +pub struct WeightInfo(PhantomData); +impl cumulus_pallet_weight_reclaim::WeightInfo for WeightInfo { + /// Storage: `System::BlockWeight` (r:1 w:1) + /// Proof: `System::BlockWeight` (`max_values`: Some(1), `max_size`: Some(48), added: 543, mode: `MaxEncodedLen`) + /// Storage: `System::ExtrinsicWeightReclaimed` (r:1 w:1) + /// Proof: `System::ExtrinsicWeightReclaimed` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) + /// Storage: `System::AllExtrinsicsLen` (r:1 w:0) + /// Proof: `System::AllExtrinsicsLen` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + fn storage_weight_reclaim() -> Weight { + // Proof Size summary in bytes: + // Measured: `24` + // Estimated: `1533` + // Minimum execution time: 6_988_000 picoseconds. + Weight::from_parts(7_361_000, 0) + .saturating_add(Weight::from_parts(0, 1533)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) + } +} diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/frame_system_extensions.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/frame_system_extensions.rs index 64eef1b4f740..93fb6f3bbbe3 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/frame_system_extensions.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/frame_system_extensions.rs @@ -16,28 +16,26 @@ //! Autogenerated weights for `frame_system_extensions` //! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-21, STEPS: `2`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-12-30, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `gleipnir`, CPU: `AMD Ryzen 9 7900X 12-Core Processor` +//! HOSTNAME: `runner-ys-ssygq-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("bridge-hub-rococo-dev")`, DB CACHE: 1024 // Executed Command: -// ./target/release/polkadot-parachain +// target/production/polkadot-parachain // benchmark // pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* // --wasm-execution=compiled +// --heap-pages=4096 +// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json // --pallet=frame_system_extensions -// --no-storage-info -// --no-median-slopes -// --no-min-squares -// --extrinsic=* -// --steps=2 -// --repeat=2 -// --json +// --chain=bridge-hub-rococo-dev // --header=./cumulus/file_header.txt // --output=./cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/ -// --chain=bridge-hub-rococo-dev #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -50,81 +48,92 @@ use core::marker::PhantomData; /// Weight functions for `frame_system_extensions`. pub struct WeightInfo(PhantomData); impl frame_system::ExtensionsWeightInfo for WeightInfo { - /// Storage: `System::BlockHash` (r:1 w:0) - /// Proof: `System::BlockHash` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `MaxEncodedLen`) fn check_genesis() -> Weight { // Proof Size summary in bytes: // Measured: `54` - // Estimated: `3509` - // Minimum execution time: 3_136_000 picoseconds. - Weight::from_parts(5_842_000, 0) - .saturating_add(Weight::from_parts(0, 3509)) - .saturating_add(T::DbWeight::get().reads(1)) + // Estimated: `0` + // Minimum execution time: 4_211_000 picoseconds. + Weight::from_parts(4_470_000, 0) + .saturating_add(Weight::from_parts(0, 0)) } - /// Storage: `System::BlockHash` (r:1 w:0) - /// Proof: `System::BlockHash` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `MaxEncodedLen`) fn check_mortality_mortal_transaction() -> Weight { // Proof Size summary in bytes: // Measured: `92` - // Estimated: `3509` - // Minimum execution time: 5_771_000 picoseconds. - Weight::from_parts(8_857_000, 0) - .saturating_add(Weight::from_parts(0, 3509)) - .saturating_add(T::DbWeight::get().reads(1)) + // Estimated: `0` + // Minimum execution time: 8_792_000 picoseconds. + Weight::from_parts(9_026_000, 0) + .saturating_add(Weight::from_parts(0, 0)) } - /// Storage: `System::BlockHash` (r:1 w:0) - /// Proof: `System::BlockHash` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `MaxEncodedLen`) fn check_mortality_immortal_transaction() -> Weight { // Proof Size summary in bytes: // Measured: `92` - // Estimated: `3509` - // Minimum execution time: 5_771_000 picoseconds. - Weight::from_parts(8_857_000, 0) - .saturating_add(Weight::from_parts(0, 3509)) - .saturating_add(T::DbWeight::get().reads(1)) + // Estimated: `0` + // Minimum execution time: 8_700_000 picoseconds. + Weight::from_parts(9_142_000, 0) + .saturating_add(Weight::from_parts(0, 0)) } fn check_non_zero_sender() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 732_000 picoseconds. - Weight::from_parts(2_875_000, 0) + // Minimum execution time: 487_000 picoseconds. + Weight::from_parts(534_000, 0) .saturating_add(Weight::from_parts(0, 0)) } + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) fn check_nonce() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 3_627_000 picoseconds. - Weight::from_parts(6_322_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Measured: `101` + // Estimated: `3593` + // Minimum execution time: 6_719_000 picoseconds. + Weight::from_parts(6_846_000, 0) + .saturating_add(Weight::from_parts(0, 3593)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } fn check_spec_version() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 471_000 picoseconds. - Weight::from_parts(2_455_000, 0) + // Minimum execution time: 410_000 picoseconds. + Weight::from_parts(442_000, 0) .saturating_add(Weight::from_parts(0, 0)) } fn check_tx_version() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 491_000 picoseconds. - Weight::from_parts(2_916_000, 0) + // Minimum execution time: 390_000 picoseconds. + Weight::from_parts(425_000, 0) .saturating_add(Weight::from_parts(0, 0)) } /// Storage: `System::AllExtrinsicsLen` (r:1 w:1) /// Proof: `System::AllExtrinsicsLen` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) /// Storage: `System::BlockWeight` (r:1 w:1) /// Proof: `System::BlockWeight` (`max_values`: Some(1), `max_size`: Some(48), added: 543, mode: `MaxEncodedLen`) + /// Storage: `System::ExtrinsicWeightReclaimed` (r:1 w:1) + /// Proof: `System::ExtrinsicWeightReclaimed` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) fn check_weight() -> Weight { // Proof Size summary in bytes: // Measured: `24` // Estimated: `1533` - // Minimum execution time: 3_798_000 picoseconds. - Weight::from_parts(6_272_000, 0) + // Minimum execution time: 5_965_000 picoseconds. + Weight::from_parts(6_291_000, 0) + .saturating_add(Weight::from_parts(0, 1533)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: `System::ExtrinsicWeightReclaimed` (r:1 w:1) + /// Proof: `System::ExtrinsicWeightReclaimed` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) + /// Storage: `System::BlockWeight` (r:1 w:1) + /// Proof: `System::BlockWeight` (`max_values`: Some(1), `max_size`: Some(48), added: 543, mode: `MaxEncodedLen`) + fn weight_reclaim() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `1533` + // Minimum execution time: 2_738_000 picoseconds. + Weight::from_parts(2_915_000, 0) .saturating_add(Weight::from_parts(0, 1533)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(2)) diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/mod.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/mod.rs index 74796e626a2e..7a0accf2e7a4 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/mod.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/weights/mod.rs @@ -24,6 +24,7 @@ use ::pallet_bridge_relayers::WeightInfo as _; pub mod block_weights; pub mod cumulus_pallet_parachain_system; +pub mod cumulus_pallet_weight_reclaim; pub mod cumulus_pallet_xcmp_queue; pub mod extrinsic_weights; pub mod frame_system; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/snowbridge.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/snowbridge.rs index d5baa1c71dfd..c40aae5a82a9 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/snowbridge.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/snowbridge.rs @@ -184,8 +184,8 @@ fn construct_extrinsic( BridgeRejectObsoleteHeadersAndMessages::default(), (OnBridgeHubRococoRefundBridgeHubWestendMessages::default(),), frame_metadata_hash_extension::CheckMetadataHash::::new(false), - cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim::new(), - ); + ) + .into(); let payload = SignedPayload::new(call.clone(), tx_ext.clone()).unwrap(); let signature = payload.using_encoded(|e| sender.sign(e)); UncheckedExtrinsic::new_signed(call, account_id.into(), Signature::Sr25519(signature), tx_ext) diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/tests.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/tests.rs index 8d74b221a609..b0f4366e29cf 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/tests.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/tests/tests.rs @@ -63,7 +63,6 @@ fn construct_extrinsic( BridgeRejectObsoleteHeadersAndMessages::default(), (bridge_to_westend_config::OnBridgeHubRococoRefundBridgeHubWestendMessages::default(),), frame_metadata_hash_extension::CheckMetadataHash::new(false), - cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim::new(), ) .into(); let payload = SignedPayload::new(call.clone(), tx_ext.clone()).unwrap(); diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/Cargo.toml b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/Cargo.toml index 644aa72d1311..444023eac722 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/Cargo.toml +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/Cargo.toml @@ -72,11 +72,11 @@ xcm-runtime-apis = { workspace = true } cumulus-pallet-aura-ext = { workspace = true } cumulus-pallet-parachain-system = { workspace = true } cumulus-pallet-session-benchmarking = { workspace = true } +cumulus-pallet-weight-reclaim = { workspace = true } cumulus-pallet-xcm = { workspace = true } cumulus-pallet-xcmp-queue = { features = ["bridging"], workspace = true } cumulus-primitives-aura = { workspace = true } cumulus-primitives-core = { workspace = true } -cumulus-primitives-storage-weight-reclaim = { workspace = true } cumulus-primitives-utility = { workspace = true } pallet-collator-selection = { workspace = true } @@ -148,11 +148,11 @@ std = [ "cumulus-pallet-aura-ext/std", "cumulus-pallet-parachain-system/std", "cumulus-pallet-session-benchmarking/std", + "cumulus-pallet-weight-reclaim/std", "cumulus-pallet-xcm/std", "cumulus-pallet-xcmp-queue/std", "cumulus-primitives-aura/std", "cumulus-primitives-core/std", - "cumulus-primitives-storage-weight-reclaim/std", "cumulus-primitives-utility/std", "frame-benchmarking/std", "frame-executive/std", @@ -227,6 +227,7 @@ runtime-benchmarks = [ "bridge-runtime-common/runtime-benchmarks", "cumulus-pallet-parachain-system/runtime-benchmarks", "cumulus-pallet-session-benchmarking/runtime-benchmarks", + "cumulus-pallet-weight-reclaim/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", "cumulus-primitives-core/runtime-benchmarks", "cumulus-primitives-utility/runtime-benchmarks", @@ -269,6 +270,7 @@ runtime-benchmarks = [ try-runtime = [ "cumulus-pallet-aura-ext/try-runtime", "cumulus-pallet-parachain-system/try-runtime", + "cumulus-pallet-weight-reclaim/try-runtime", "cumulus-pallet-xcm/try-runtime", "cumulus-pallet-xcmp-queue/try-runtime", "frame-executive/try-runtime", diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs index edf79ea0c315..2c2e01b4d21d 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/lib.rs @@ -120,20 +120,22 @@ pub type SignedBlock = generic::SignedBlock; pub type BlockId = generic::BlockId; /// The TransactionExtension to the basic transaction logic. -pub type TxExtension = ( - frame_system::CheckNonZeroSender, - frame_system::CheckSpecVersion, - frame_system::CheckTxVersion, - frame_system::CheckGenesis, - frame_system::CheckEra, - frame_system::CheckNonce, - frame_system::CheckWeight, - pallet_transaction_payment::ChargeTransactionPayment, - BridgeRejectObsoleteHeadersAndMessages, - (bridge_to_rococo_config::OnBridgeHubWestendRefundBridgeHubRococoMessages,), - frame_metadata_hash_extension::CheckMetadataHash, - cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim, -); +pub type TxExtension = cumulus_pallet_weight_reclaim::StorageWeightReclaim< + Runtime, + ( + frame_system::CheckNonZeroSender, + frame_system::CheckSpecVersion, + frame_system::CheckTxVersion, + frame_system::CheckGenesis, + frame_system::CheckEra, + frame_system::CheckNonce, + frame_system::CheckWeight, + pallet_transaction_payment::ChargeTransactionPayment, + BridgeRejectObsoleteHeadersAndMessages, + (bridge_to_rococo_config::OnBridgeHubWestendRefundBridgeHubRococoMessages,), + frame_metadata_hash_extension::CheckMetadataHash, + ), +>; /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = @@ -299,6 +301,10 @@ impl frame_system::Config for Runtime { type MaxConsumers = frame_support::traits::ConstU32<16>; } +impl cumulus_pallet_weight_reclaim::Config for Runtime { + type WeightInfo = weights::cumulus_pallet_weight_reclaim::WeightInfo; +} + impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. type Moment = u64; @@ -532,6 +538,7 @@ construct_runtime!( ParachainSystem: cumulus_pallet_parachain_system = 1, Timestamp: pallet_timestamp = 2, ParachainInfo: parachain_info = 3, + WeightReclaim: cumulus_pallet_weight_reclaim = 4, // Monetary stuff. Balances: pallet_balances = 10, @@ -622,6 +629,7 @@ mod benches { [snowbridge_pallet_outbound_queue, EthereumOutboundQueue] [snowbridge_pallet_system, EthereumSystem] [snowbridge_pallet_ethereum_client, EthereumBeaconClient] + [cumulus_pallet_weight_reclaim, WeightReclaim] ); } @@ -1315,18 +1323,8 @@ impl_runtime_apis! { } } - let whitelist: Vec = vec![ - // Block Number - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(), - // Total Issuance - hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(), - // Execution Phase - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(), - // Event Count - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(), - // System Events - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(), - ]; + use frame_support::traits::WhitelistedStorageKeys; + let whitelist: Vec = AllPalletsWithSystem::whitelisted_storage_keys(); let mut batches = Vec::::new(); let params = (&config, &whitelist); @@ -1379,40 +1377,43 @@ mod tests { use bp_polkadot_core::SuffixedCommonTransactionExtensionExt; sp_io::TestExternalities::default().execute_with(|| { - frame_system::BlockHash::::insert(BlockNumber::zero(), Hash::default()); - let payload: TxExtension = ( - frame_system::CheckNonZeroSender::new(), - frame_system::CheckSpecVersion::new(), - frame_system::CheckTxVersion::new(), - frame_system::CheckGenesis::new(), - frame_system::CheckEra::from(Era::Immortal), - frame_system::CheckNonce::from(10), - frame_system::CheckWeight::new(), - pallet_transaction_payment::ChargeTransactionPayment::from(10), - BridgeRejectObsoleteHeadersAndMessages, - ( - bridge_to_rococo_config::OnBridgeHubWestendRefundBridgeHubRococoMessages::default(), - ), + frame_system::BlockHash::::insert(BlockNumber::zero(), Hash::default()); + let payload: TxExtension = ( + frame_system::CheckNonZeroSender::new(), + frame_system::CheckSpecVersion::new(), + frame_system::CheckTxVersion::new(), + frame_system::CheckGenesis::new(), + frame_system::CheckEra::from(Era::Immortal), + frame_system::CheckNonce::from(10), + frame_system::CheckWeight::new(), + pallet_transaction_payment::ChargeTransactionPayment::from(10), + BridgeRejectObsoleteHeadersAndMessages, + ( + bridge_to_rococo_config::OnBridgeHubWestendRefundBridgeHubRococoMessages::default(), + ), frame_metadata_hash_extension::CheckMetadataHash::new(false), - cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim::new(), - ); - - { - let bh_indirect_payload = bp_bridge_hub_westend::TransactionExtension::from_params( - VERSION.spec_version, - VERSION.transaction_version, - bp_runtime::TransactionEra::Immortal, - System::block_hash(BlockNumber::zero()), - 10, - 10, - (((), ()), ((), ())), - ); - assert_eq!(payload.encode().split_last().unwrap().1, bh_indirect_payload.encode()); - assert_eq!( - TxExtension::implicit(&payload).unwrap().encode().split_last().unwrap().1, - sp_runtime::traits::TransactionExtension::::implicit(&bh_indirect_payload).unwrap().encode() - ) - } - }); + ).into(); + + { + let bh_indirect_payload = bp_bridge_hub_westend::TransactionExtension::from_params( + VERSION.spec_version, + VERSION.transaction_version, + bp_runtime::TransactionEra::Immortal, + System::block_hash(BlockNumber::zero()), + 10, + 10, + (((), ()), ((), ())), + ); + assert_eq!(payload.encode().split_last().unwrap().1, bh_indirect_payload.encode()); + assert_eq!( + TxExtension::implicit(&payload).unwrap().encode().split_last().unwrap().1, + sp_runtime::traits::TransactionExtension::::implicit( + &bh_indirect_payload + ) + .unwrap() + .encode() + ) + } + }); } } diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/cumulus_pallet_weight_reclaim.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/cumulus_pallet_weight_reclaim.rs new file mode 100644 index 000000000000..955b27325456 --- /dev/null +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/cumulus_pallet_weight_reclaim.rs @@ -0,0 +1,67 @@ +// 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 . + +//! Autogenerated weights for `cumulus_pallet_weight_reclaim` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-12-30, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `runner-ys-ssygq-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("bridge-hub-westend-dev")`, DB CACHE: 1024 + +// Executed Command: +// target/production/polkadot-parachain +// benchmark +// pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --wasm-execution=compiled +// --heap-pages=4096 +// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json +// --pallet=cumulus_pallet_weight_reclaim +// --chain=bridge-hub-westend-dev +// --header=./cumulus/file_header.txt +// --output=./cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `cumulus_pallet_weight_reclaim`. +pub struct WeightInfo(PhantomData); +impl cumulus_pallet_weight_reclaim::WeightInfo for WeightInfo { + /// Storage: `System::BlockWeight` (r:1 w:1) + /// Proof: `System::BlockWeight` (`max_values`: Some(1), `max_size`: Some(48), added: 543, mode: `MaxEncodedLen`) + /// Storage: `System::ExtrinsicWeightReclaimed` (r:1 w:1) + /// Proof: `System::ExtrinsicWeightReclaimed` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) + /// Storage: `System::AllExtrinsicsLen` (r:1 w:0) + /// Proof: `System::AllExtrinsicsLen` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + fn storage_weight_reclaim() -> Weight { + // Proof Size summary in bytes: + // Measured: `24` + // Estimated: `1533` + // Minimum execution time: 6_810_000 picoseconds. + Weight::from_parts(7_250_000, 0) + .saturating_add(Weight::from_parts(0, 1533)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) + } +} diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/frame_system_extensions.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/frame_system_extensions.rs index 459b137d3b84..21cadac25e16 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/frame_system_extensions.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/frame_system_extensions.rs @@ -16,28 +16,26 @@ //! Autogenerated weights for `frame_system_extensions` //! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-21, STEPS: `2`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-12-30, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `gleipnir`, CPU: `AMD Ryzen 9 7900X 12-Core Processor` +//! HOSTNAME: `runner-ys-ssygq-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("bridge-hub-westend-dev")`, DB CACHE: 1024 // Executed Command: -// ./target/release/polkadot-parachain +// target/production/polkadot-parachain // benchmark // pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* // --wasm-execution=compiled +// --heap-pages=4096 +// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json // --pallet=frame_system_extensions -// --no-storage-info -// --no-median-slopes -// --no-min-squares -// --extrinsic=* -// --steps=2 -// --repeat=2 -// --json +// --chain=bridge-hub-westend-dev // --header=./cumulus/file_header.txt // --output=./cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/ -// --chain=bridge-hub-westend-dev #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -50,81 +48,92 @@ use core::marker::PhantomData; /// Weight functions for `frame_system_extensions`. pub struct WeightInfo(PhantomData); impl frame_system::ExtensionsWeightInfo for WeightInfo { - /// Storage: `System::BlockHash` (r:1 w:0) - /// Proof: `System::BlockHash` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `MaxEncodedLen`) fn check_genesis() -> Weight { // Proof Size summary in bytes: // Measured: `54` - // Estimated: `3509` - // Minimum execution time: 3_166_000 picoseconds. - Weight::from_parts(6_021_000, 0) - .saturating_add(Weight::from_parts(0, 3509)) - .saturating_add(T::DbWeight::get().reads(1)) + // Estimated: `0` + // Minimum execution time: 4_363_000 picoseconds. + Weight::from_parts(4_521_000, 0) + .saturating_add(Weight::from_parts(0, 0)) } - /// Storage: `System::BlockHash` (r:1 w:0) - /// Proof: `System::BlockHash` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `MaxEncodedLen`) fn check_mortality_mortal_transaction() -> Weight { // Proof Size summary in bytes: // Measured: `92` - // Estimated: `3509` - // Minimum execution time: 5_651_000 picoseconds. - Weight::from_parts(9_177_000, 0) - .saturating_add(Weight::from_parts(0, 3509)) - .saturating_add(T::DbWeight::get().reads(1)) + // Estimated: `0` + // Minimum execution time: 8_522_000 picoseconds. + Weight::from_parts(8_847_000, 0) + .saturating_add(Weight::from_parts(0, 0)) } - /// Storage: `System::BlockHash` (r:1 w:0) - /// Proof: `System::BlockHash` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `MaxEncodedLen`) fn check_mortality_immortal_transaction() -> Weight { // Proof Size summary in bytes: // Measured: `92` - // Estimated: `3509` - // Minimum execution time: 5_651_000 picoseconds. - Weight::from_parts(9_177_000, 0) - .saturating_add(Weight::from_parts(0, 3509)) - .saturating_add(T::DbWeight::get().reads(1)) + // Estimated: `0` + // Minimum execution time: 8_617_000 picoseconds. + Weight::from_parts(8_789_000, 0) + .saturating_add(Weight::from_parts(0, 0)) } fn check_non_zero_sender() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 601_000 picoseconds. - Weight::from_parts(2_805_000, 0) + // Minimum execution time: 485_000 picoseconds. + Weight::from_parts(557_000, 0) .saturating_add(Weight::from_parts(0, 0)) } + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) fn check_nonce() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 3_727_000 picoseconds. - Weight::from_parts(6_051_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Measured: `101` + // Estimated: `3593` + // Minimum execution time: 6_682_000 picoseconds. + Weight::from_parts(6_821_000, 0) + .saturating_add(Weight::from_parts(0, 3593)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } fn check_spec_version() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 471_000 picoseconds. - Weight::from_parts(2_494_000, 0) + // Minimum execution time: 390_000 picoseconds. + Weight::from_parts(441_000, 0) .saturating_add(Weight::from_parts(0, 0)) } fn check_tx_version() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 521_000 picoseconds. - Weight::from_parts(2_655_000, 0) + // Minimum execution time: 395_000 picoseconds. + Weight::from_parts(455_000, 0) .saturating_add(Weight::from_parts(0, 0)) } /// Storage: `System::AllExtrinsicsLen` (r:1 w:1) /// Proof: `System::AllExtrinsicsLen` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) /// Storage: `System::BlockWeight` (r:1 w:1) /// Proof: `System::BlockWeight` (`max_values`: Some(1), `max_size`: Some(48), added: 543, mode: `MaxEncodedLen`) + /// Storage: `System::ExtrinsicWeightReclaimed` (r:1 w:1) + /// Proof: `System::ExtrinsicWeightReclaimed` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) fn check_weight() -> Weight { // Proof Size summary in bytes: // Measured: `24` // Estimated: `1533` - // Minimum execution time: 3_808_000 picoseconds. - Weight::from_parts(6_402_000, 0) + // Minimum execution time: 6_134_000 picoseconds. + Weight::from_parts(6_308_000, 0) + .saturating_add(Weight::from_parts(0, 1533)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: `System::ExtrinsicWeightReclaimed` (r:1 w:1) + /// Proof: `System::ExtrinsicWeightReclaimed` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) + /// Storage: `System::BlockWeight` (r:1 w:1) + /// Proof: `System::BlockWeight` (`max_values`: Some(1), `max_size`: Some(48), added: 543, mode: `MaxEncodedLen`) + fn weight_reclaim() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `1533` + // Minimum execution time: 2_764_000 picoseconds. + Weight::from_parts(2_893_000, 0) .saturating_add(Weight::from_parts(0, 1533)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(2)) diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/mod.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/mod.rs index c1c5c337aca8..313da55831c8 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/mod.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/src/weights/mod.rs @@ -24,6 +24,7 @@ use ::pallet_bridge_relayers::WeightInfo as _; pub mod block_weights; pub mod cumulus_pallet_parachain_system; +pub mod cumulus_pallet_weight_reclaim; pub mod cumulus_pallet_xcmp_queue; pub mod extrinsic_weights; pub mod frame_system; diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/tests/snowbridge.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/tests/snowbridge.rs index d71400fa71b6..bc570ef7f74b 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/tests/snowbridge.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/tests/snowbridge.rs @@ -185,8 +185,8 @@ fn construct_extrinsic( BridgeRejectObsoleteHeadersAndMessages::default(), (bridge_to_rococo_config::OnBridgeHubWestendRefundBridgeHubRococoMessages::default(),), frame_metadata_hash_extension::CheckMetadataHash::::new(false), - cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim::new(), - ); + ) + .into(); let payload = SignedPayload::new(call.clone(), extra.clone()).unwrap(); let signature = payload.using_encoded(|e| sender.sign(e)); UncheckedExtrinsic::new_signed(call, account_id.into(), Signature::Sr25519(signature), extra) diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/tests/tests.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/tests/tests.rs index 9d32f28f4fc6..d7e7fbe0c72e 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/tests/tests.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-westend/tests/tests.rs @@ -95,7 +95,6 @@ fn construct_extrinsic( BridgeRejectObsoleteHeadersAndMessages::default(), (bridge_to_rococo_config::OnBridgeHubWestendRefundBridgeHubRococoMessages::default(),), frame_metadata_hash_extension::CheckMetadataHash::new(false), - cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim::new(), ) .into(); let payload = SignedPayload::new(call.clone(), tx_ext.clone()).unwrap(); diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/Cargo.toml b/cumulus/parachains/runtimes/collectives/collectives-westend/Cargo.toml index 9c70b65060dd..2786321e48e2 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/Cargo.toml +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/Cargo.toml @@ -77,11 +77,11 @@ xcm-runtime-apis = { workspace = true } cumulus-pallet-aura-ext = { workspace = true } cumulus-pallet-parachain-system = { workspace = true } cumulus-pallet-session-benchmarking = { workspace = true } +cumulus-pallet-weight-reclaim = { workspace = true } cumulus-pallet-xcm = { workspace = true } cumulus-pallet-xcmp-queue = { workspace = true } cumulus-primitives-aura = { workspace = true } cumulus-primitives-core = { workspace = true } -cumulus-primitives-storage-weight-reclaim = { workspace = true } cumulus-primitives-utility = { workspace = true } pallet-message-queue = { workspace = true } @@ -103,6 +103,7 @@ default = ["std"] runtime-benchmarks = [ "cumulus-pallet-parachain-system/runtime-benchmarks", "cumulus-pallet-session-benchmarking/runtime-benchmarks", + "cumulus-pallet-weight-reclaim/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", "cumulus-primitives-core/runtime-benchmarks", "cumulus-primitives-utility/runtime-benchmarks", @@ -143,6 +144,7 @@ runtime-benchmarks = [ try-runtime = [ "cumulus-pallet-aura-ext/try-runtime", "cumulus-pallet-parachain-system/try-runtime", + "cumulus-pallet-weight-reclaim/try-runtime", "cumulus-pallet-xcm/try-runtime", "cumulus-pallet-xcmp-queue/try-runtime", "frame-executive/try-runtime", @@ -182,11 +184,11 @@ std = [ "cumulus-pallet-aura-ext/std", "cumulus-pallet-parachain-system/std", "cumulus-pallet-session-benchmarking/std", + "cumulus-pallet-weight-reclaim/std", "cumulus-pallet-xcm/std", "cumulus-pallet-xcmp-queue/std", "cumulus-primitives-aura/std", "cumulus-primitives-core/std", - "cumulus-primitives-storage-weight-reclaim/std", "cumulus-primitives-utility/std", "frame-benchmarking?/std", "frame-executive/std", diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index 5c2ba2e24c22..e9adc4d1eae7 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -191,6 +191,10 @@ impl frame_system::Config for Runtime { type MaxConsumers = frame_support::traits::ConstU32<16>; } +impl cumulus_pallet_weight_reclaim::Config for Runtime { + type WeightInfo = weights::cumulus_pallet_weight_reclaim::WeightInfo; +} + impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. type Moment = u64; @@ -669,6 +673,7 @@ construct_runtime!( ParachainSystem: cumulus_pallet_parachain_system = 1, Timestamp: pallet_timestamp = 2, ParachainInfo: parachain_info = 3, + WeightReclaim: cumulus_pallet_weight_reclaim = 4, // Monetary stuff. Balances: pallet_balances = 10, @@ -735,16 +740,19 @@ pub type SignedBlock = generic::SignedBlock; /// BlockId type as expected by this runtime. pub type BlockId = generic::BlockId; /// The extension to the basic transaction logic. -pub type TxExtension = ( - frame_system::CheckNonZeroSender, - frame_system::CheckSpecVersion, - frame_system::CheckTxVersion, - frame_system::CheckGenesis, - frame_system::CheckEra, - frame_system::CheckNonce, - frame_system::CheckWeight, - cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim, -); +pub type TxExtension = cumulus_pallet_weight_reclaim::StorageWeightReclaim< + Runtime, + ( + frame_system::CheckNonZeroSender, + frame_system::CheckSpecVersion, + frame_system::CheckTxVersion, + frame_system::CheckGenesis, + frame_system::CheckEra, + frame_system::CheckNonce, + frame_system::CheckWeight, + ), +>; + /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; @@ -806,6 +814,7 @@ mod benches { [pallet_salary, AmbassadorSalary] [pallet_treasury, FellowshipTreasury] [pallet_asset_rate, AssetRate] + [cumulus_pallet_weight_reclaim, WeightReclaim] ); } @@ -1139,18 +1148,8 @@ impl_runtime_apis! { } } - let whitelist: Vec = vec![ - // Block Number - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(), - // Total Issuance - hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(), - // Execution Phase - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(), - // Event Count - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(), - // System Events - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(), - ]; + use frame_support::traits::WhitelistedStorageKeys; + let whitelist: Vec = AllPalletsWithSystem::whitelisted_storage_keys(); let mut batches = Vec::::new(); let params = (&config, &whitelist); diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/cumulus_pallet_weight_reclaim.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/cumulus_pallet_weight_reclaim.rs new file mode 100644 index 000000000000..c286ba132022 --- /dev/null +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/cumulus_pallet_weight_reclaim.rs @@ -0,0 +1,67 @@ +// 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 . + +//! Autogenerated weights for `cumulus_pallet_weight_reclaim` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-12-30, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `runner-ys-ssygq-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("collectives-westend-dev")`, DB CACHE: 1024 + +// Executed Command: +// target/production/polkadot-parachain +// benchmark +// pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --wasm-execution=compiled +// --heap-pages=4096 +// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json +// --pallet=cumulus_pallet_weight_reclaim +// --chain=collectives-westend-dev +// --header=./cumulus/file_header.txt +// --output=./cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `cumulus_pallet_weight_reclaim`. +pub struct WeightInfo(PhantomData); +impl cumulus_pallet_weight_reclaim::WeightInfo for WeightInfo { + /// Storage: `System::BlockWeight` (r:1 w:1) + /// Proof: `System::BlockWeight` (`max_values`: Some(1), `max_size`: Some(48), added: 543, mode: `MaxEncodedLen`) + /// Storage: `System::ExtrinsicWeightReclaimed` (r:1 w:1) + /// Proof: `System::ExtrinsicWeightReclaimed` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) + /// Storage: `System::AllExtrinsicsLen` (r:1 w:0) + /// Proof: `System::AllExtrinsicsLen` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + fn storage_weight_reclaim() -> Weight { + // Proof Size summary in bytes: + // Measured: `24` + // Estimated: `1533` + // Minimum execution time: 6_745_000 picoseconds. + Weight::from_parts(6_948_000, 0) + .saturating_add(Weight::from_parts(0, 1533)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) + } +} diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/frame_system_extensions.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/frame_system_extensions.rs index f32f27303135..8c2abcd4e8c8 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/frame_system_extensions.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/frame_system_extensions.rs @@ -16,28 +16,26 @@ //! Autogenerated weights for `frame_system_extensions` //! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-21, STEPS: `2`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-12-30, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `gleipnir`, CPU: `AMD Ryzen 9 7900X 12-Core Processor` +//! HOSTNAME: `runner-ys-ssygq-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("collectives-westend-dev")`, DB CACHE: 1024 // Executed Command: -// ./target/release/polkadot-parachain +// target/production/polkadot-parachain // benchmark // pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* // --wasm-execution=compiled +// --heap-pages=4096 +// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json // --pallet=frame_system_extensions -// --no-storage-info -// --no-median-slopes -// --no-min-squares -// --extrinsic=* -// --steps=2 -// --repeat=2 -// --json +// --chain=collectives-westend-dev // --header=./cumulus/file_header.txt // --output=./cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/ -// --chain=collectives-westend-dev #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -50,81 +48,92 @@ use core::marker::PhantomData; /// Weight functions for `frame_system_extensions`. pub struct WeightInfo(PhantomData); impl frame_system::ExtensionsWeightInfo for WeightInfo { - /// Storage: `System::BlockHash` (r:1 w:0) - /// Proof: `System::BlockHash` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `MaxEncodedLen`) fn check_genesis() -> Weight { // Proof Size summary in bytes: // Measured: `54` - // Estimated: `3509` - // Minimum execution time: 3_497_000 picoseconds. - Weight::from_parts(5_961_000, 0) - .saturating_add(Weight::from_parts(0, 3509)) - .saturating_add(T::DbWeight::get().reads(1)) + // Estimated: `0` + // Minimum execution time: 4_206_000 picoseconds. + Weight::from_parts(4_485_000, 0) + .saturating_add(Weight::from_parts(0, 0)) } - /// Storage: `System::BlockHash` (r:1 w:0) - /// Proof: `System::BlockHash` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `MaxEncodedLen`) fn check_mortality_mortal_transaction() -> Weight { // Proof Size summary in bytes: // Measured: `92` - // Estimated: `3509` - // Minimum execution time: 5_240_000 picoseconds. - Weight::from_parts(8_175_000, 0) - .saturating_add(Weight::from_parts(0, 3509)) - .saturating_add(T::DbWeight::get().reads(1)) + // Estimated: `0` + // Minimum execution time: 7_537_000 picoseconds. + Weight::from_parts(7_706_000, 0) + .saturating_add(Weight::from_parts(0, 0)) } - /// Storage: `System::BlockHash` (r:1 w:0) - /// Proof: `System::BlockHash` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `MaxEncodedLen`) fn check_mortality_immortal_transaction() -> Weight { // Proof Size summary in bytes: // Measured: `92` - // Estimated: `3509` - // Minimum execution time: 5_240_000 picoseconds. - Weight::from_parts(8_175_000, 0) - .saturating_add(Weight::from_parts(0, 3509)) - .saturating_add(T::DbWeight::get().reads(1)) + // Estimated: `0` + // Minimum execution time: 7_512_000 picoseconds. + Weight::from_parts(7_655_000, 0) + .saturating_add(Weight::from_parts(0, 0)) } fn check_non_zero_sender() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 671_000 picoseconds. - Weight::from_parts(3_005_000, 0) + // Minimum execution time: 447_000 picoseconds. + Weight::from_parts(499_000, 0) .saturating_add(Weight::from_parts(0, 0)) } + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) fn check_nonce() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 3_426_000 picoseconds. - Weight::from_parts(6_131_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Measured: `101` + // Estimated: `3593` + // Minimum execution time: 6_667_000 picoseconds. + Weight::from_parts(6_868_000, 0) + .saturating_add(Weight::from_parts(0, 3593)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } fn check_spec_version() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 501_000 picoseconds. - Weight::from_parts(2_715_000, 0) + // Minimum execution time: 389_000 picoseconds. + Weight::from_parts(420_000, 0) .saturating_add(Weight::from_parts(0, 0)) } fn check_tx_version() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 491_000 picoseconds. - Weight::from_parts(2_635_000, 0) + // Minimum execution time: 379_000 picoseconds. + Weight::from_parts(420_000, 0) .saturating_add(Weight::from_parts(0, 0)) } /// Storage: `System::AllExtrinsicsLen` (r:1 w:1) /// Proof: `System::AllExtrinsicsLen` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) /// Storage: `System::BlockWeight` (r:1 w:1) /// Proof: `System::BlockWeight` (`max_values`: Some(1), `max_size`: Some(48), added: 543, mode: `MaxEncodedLen`) + /// Storage: `System::ExtrinsicWeightReclaimed` (r:1 w:1) + /// Proof: `System::ExtrinsicWeightReclaimed` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) fn check_weight() -> Weight { // Proof Size summary in bytes: // Measured: `24` // Estimated: `1533` - // Minimum execution time: 3_958_000 picoseconds. - Weight::from_parts(6_753_000, 0) + // Minimum execution time: 6_330_000 picoseconds. + Weight::from_parts(6_605_000, 0) + .saturating_add(Weight::from_parts(0, 1533)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: `System::ExtrinsicWeightReclaimed` (r:1 w:1) + /// Proof: `System::ExtrinsicWeightReclaimed` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) + /// Storage: `System::BlockWeight` (r:1 w:1) + /// Proof: `System::BlockWeight` (`max_values`: Some(1), `max_size`: Some(48), added: 543, mode: `MaxEncodedLen`) + fn weight_reclaim() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `1533` + // Minimum execution time: 2_784_000 picoseconds. + Weight::from_parts(2_960_000, 0) .saturating_add(Weight::from_parts(0, 1533)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(2)) diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/mod.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/mod.rs index 00b3bd92d5ef..a1663dc98a34 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/mod.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/mod.rs @@ -15,6 +15,7 @@ pub mod block_weights; pub mod cumulus_pallet_parachain_system; +pub mod cumulus_pallet_weight_reclaim; pub mod cumulus_pallet_xcmp_queue; pub mod extrinsic_weights; pub mod frame_system; diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/pallet_core_fellowship_ambassador_core.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/pallet_core_fellowship_ambassador_core.rs index 6bedfcc7e012..4d092ec80313 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/pallet_core_fellowship_ambassador_core.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/pallet_core_fellowship_ambassador_core.rs @@ -1,4 +1,4 @@ -// Copyright Parity Technologies (UK) Ltd. +// Copyright (C) Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Cumulus is free software: you can redistribute it and/or modify @@ -16,25 +16,29 @@ //! Autogenerated weights for `pallet_core_fellowship` //! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-08-11, STEPS: `2`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2025-01-03, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `cob`, CPU: `` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("collectives-polkadot-dev")`, DB CACHE: 1024 +//! HOSTNAME: `623e9e4b814e`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: 1024 // Executed Command: -// target/release/polkadot-parachain +// frame-omni-bencher +// v1 // benchmark // pallet -// --chain=collectives-polkadot-dev -// --wasm-execution=compiled -// --pallet=pallet_core_fellowship // --extrinsic=* -// --steps=2 -// --repeat=2 -// --json -// --header=./file_header.txt -// --output=./parachains/runtimes/collectives/collectives-polkadot/src/weights/ +// --runtime=target/production/wbuild/collectives-westend-runtime/collectives_westend_runtime.wasm +// --pallet=pallet_core_fellowship +// --header=/__w/polkadot-sdk/polkadot-sdk/cumulus/file_header.txt +// --output=./cumulus/parachains/runtimes/collectives/collectives-westend/src/weights +// --wasm-execution=compiled +// --steps=50 +// --repeat=20 +// --heap-pages=4096 +// --no-storage-info +// --no-min-squares +// --no-median-slopes #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -48,25 +52,26 @@ use core::marker::PhantomData; pub struct WeightInfo(PhantomData); impl pallet_core_fellowship::WeightInfo for WeightInfo { /// Storage: `AmbassadorCore::Params` (r:0 w:1) - /// Proof: `AmbassadorCore::Params` (`max_values`: Some(1), `max_size`: Some(364), added: 859, mode: `MaxEncodedLen`) + /// Proof: `AmbassadorCore::Params` (`max_values`: Some(1), `max_size`: Some(368), added: 863, mode: `MaxEncodedLen`) fn set_params() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 11_000_000 picoseconds. - Weight::from_parts(11_000_000, 0) + // Minimum execution time: 9_131_000 picoseconds. + Weight::from_parts(9_371_000, 0) .saturating_add(Weight::from_parts(0, 0)) .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: `AmbassadorCore::Params` (r:0 w:1) - /// Proof: `AmbassadorCore::Params` (`max_values`: Some(1), `max_size`: Some(364), added: 859, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCore::Params` (r:1 w:1) + /// Proof: `AmbassadorCore::Params` (`max_values`: Some(1), `max_size`: Some(368), added: 863, mode: `MaxEncodedLen`) fn set_partial_params() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 11_000_000 picoseconds. - Weight::from_parts(11_000_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Measured: `471` + // Estimated: `1853` + // Minimum execution time: 18_375_000 picoseconds. + Weight::from_parts(18_872_000, 0) + .saturating_add(Weight::from_parts(0, 1853)) + .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `AmbassadorCore::Member` (r:1 w:1) @@ -74,44 +79,48 @@ impl pallet_core_fellowship::WeightInfo for WeightInfo< /// Storage: `AmbassadorCollective::Members` (r:1 w:1) /// Proof: `AmbassadorCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) /// Storage: `AmbassadorCore::Params` (r:1 w:0) - /// Proof: `AmbassadorCore::Params` (`max_values`: Some(1), `max_size`: Some(364), added: 859, mode: `MaxEncodedLen`) + /// Proof: `AmbassadorCore::Params` (`max_values`: Some(1), `max_size`: Some(368), added: 863, mode: `MaxEncodedLen`) /// Storage: `AmbassadorCollective::MemberCount` (r:1 w:1) /// Proof: `AmbassadorCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) - /// Storage: `AmbassadorCollective::IdToIndex` (r:1 w:0) + /// Storage: `AmbassadorCollective::IdToIndex` (r:1 w:1) /// Proof: `AmbassadorCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) /// Storage: `AmbassadorCore::MemberEvidence` (r:1 w:1) /// Proof: `AmbassadorCore::MemberEvidence` (`max_values`: None, `max_size`: Some(65581), added: 68056, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::IndexToId` (r:0 w:1) + /// Proof: `AmbassadorCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) fn bump_offboard() -> Weight { // Proof Size summary in bytes: - // Measured: `66011` + // Measured: `66402` // Estimated: `69046` - // Minimum execution time: 96_000_000 picoseconds. - Weight::from_parts(111_000_000, 0) + // Minimum execution time: 156_752_000 picoseconds. + Weight::from_parts(164_242_000, 0) .saturating_add(Weight::from_parts(0, 69046)) .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(4)) + .saturating_add(T::DbWeight::get().writes(6)) } /// Storage: `AmbassadorCore::Member` (r:1 w:1) /// Proof: `AmbassadorCore::Member` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) /// Storage: `AmbassadorCollective::Members` (r:1 w:1) /// Proof: `AmbassadorCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) /// Storage: `AmbassadorCore::Params` (r:1 w:0) - /// Proof: `AmbassadorCore::Params` (`max_values`: Some(1), `max_size`: Some(364), added: 859, mode: `MaxEncodedLen`) + /// Proof: `AmbassadorCore::Params` (`max_values`: Some(1), `max_size`: Some(368), added: 863, mode: `MaxEncodedLen`) /// Storage: `AmbassadorCollective::MemberCount` (r:1 w:1) /// Proof: `AmbassadorCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) - /// Storage: `AmbassadorCollective::IdToIndex` (r:1 w:0) + /// Storage: `AmbassadorCollective::IdToIndex` (r:1 w:1) /// Proof: `AmbassadorCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) /// Storage: `AmbassadorCore::MemberEvidence` (r:1 w:1) /// Proof: `AmbassadorCore::MemberEvidence` (`max_values`: None, `max_size`: Some(65581), added: 68056, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::IndexToId` (r:0 w:1) + /// Proof: `AmbassadorCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) fn bump_demote() -> Weight { // Proof Size summary in bytes: - // Measured: `66121` + // Measured: `66512` // Estimated: `69046` - // Minimum execution time: 99_000_000 picoseconds. - Weight::from_parts(116_000_000, 0) + // Minimum execution time: 158_877_000 picoseconds. + Weight::from_parts(165_228_000, 0) .saturating_add(Weight::from_parts(0, 69046)) .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(4)) + .saturating_add(T::DbWeight::get().writes(6)) } /// Storage: `AmbassadorCollective::Members` (r:1 w:0) /// Proof: `AmbassadorCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) @@ -121,8 +130,8 @@ impl pallet_core_fellowship::WeightInfo for WeightInfo< // Proof Size summary in bytes: // Measured: `360` // Estimated: `3514` - // Minimum execution time: 21_000_000 picoseconds. - Weight::from_parts(22_000_000, 0) + // Minimum execution time: 25_056_000 picoseconds. + Weight::from_parts(26_028_000, 0) .saturating_add(Weight::from_parts(0, 3514)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) @@ -141,8 +150,8 @@ impl pallet_core_fellowship::WeightInfo for WeightInfo< // Proof Size summary in bytes: // Measured: `118` // Estimated: `3514` - // Minimum execution time: 36_000_000 picoseconds. - Weight::from_parts(36_000_000, 0) + // Minimum execution time: 34_784_000 picoseconds. + Weight::from_parts(35_970_000, 0) .saturating_add(Weight::from_parts(0, 3514)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(5)) @@ -152,7 +161,7 @@ impl pallet_core_fellowship::WeightInfo for WeightInfo< /// Storage: `AmbassadorCore::Member` (r:1 w:1) /// Proof: `AmbassadorCore::Member` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) /// Storage: `AmbassadorCore::Params` (r:1 w:0) - /// Proof: `AmbassadorCore::Params` (`max_values`: Some(1), `max_size`: Some(364), added: 859, mode: `MaxEncodedLen`) + /// Proof: `AmbassadorCore::Params` (`max_values`: Some(1), `max_size`: Some(368), added: 863, mode: `MaxEncodedLen`) /// Storage: `AmbassadorCollective::MemberCount` (r:1 w:1) /// Proof: `AmbassadorCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) /// Storage: `AmbassadorCore::MemberEvidence` (r:1 w:1) @@ -163,25 +172,40 @@ impl pallet_core_fellowship::WeightInfo for WeightInfo< /// Proof: `AmbassadorCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) fn promote() -> Weight { // Proof Size summary in bytes: - // Measured: `65989` + // Measured: `66055` // Estimated: `69046` - // Minimum execution time: 95_000_000 picoseconds. - Weight::from_parts(110_000_000, 0) + // Minimum execution time: 147_616_000 picoseconds. + Weight::from_parts(154_534_000, 0) .saturating_add(Weight::from_parts(0, 69046)) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(6)) } + /// Storage: `AmbassadorCollective::Members` (r:1 w:1) + /// Proof: `AmbassadorCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCore::Member` (r:1 w:1) + /// Proof: `AmbassadorCore::Member` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::MemberCount` (r:9 w:9) + /// Proof: `AmbassadorCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCore::MemberEvidence` (r:1 w:1) + /// Proof: `AmbassadorCore::MemberEvidence` (`max_values`: None, `max_size`: Some(65581), added: 68056, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::IndexToId` (r:0 w:9) + /// Proof: `AmbassadorCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::IdToIndex` (r:0 w:9) + /// Proof: `AmbassadorCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) + /// The range of component `r` is `[1, 9]`. + /// The range of component `r` is `[1, 9]`. fn promote_fast(r: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `16844` - // Estimated: `19894 + r * (2489 ±0)` - // Minimum execution time: 45_065_000 picoseconds. - Weight::from_parts(34_090_392, 19894) - // Standard Error: 18_620 - .saturating_add(Weight::from_parts(13_578_046, 0).saturating_mul(r.into())) - .saturating_add(T::DbWeight::get().reads(3_u64)) + // Measured: `65968` + // Estimated: `69046 + r * (2489 ±0)` + // Minimum execution time: 138_323_000 picoseconds. + Weight::from_parts(125_497_264, 0) + .saturating_add(Weight::from_parts(0, 69046)) + // Standard Error: 56_050 + .saturating_add(Weight::from_parts(19_863_853, 0).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(r.into()))) - .saturating_add(T::DbWeight::get().writes(3_u64)) + .saturating_add(T::DbWeight::get().writes(3)) .saturating_add(T::DbWeight::get().writes((3_u64).saturating_mul(r.into()))) .saturating_add(Weight::from_parts(0, 2489).saturating_mul(r.into())) } @@ -193,10 +217,10 @@ impl pallet_core_fellowship::WeightInfo for WeightInfo< /// Proof: `AmbassadorCore::MemberEvidence` (`max_values`: None, `max_size`: Some(65581), added: 68056, mode: `MaxEncodedLen`) fn offboard() -> Weight { // Proof Size summary in bytes: - // Measured: `331` + // Measured: `265` // Estimated: `3514` - // Minimum execution time: 21_000_000 picoseconds. - Weight::from_parts(22_000_000, 0) + // Minimum execution time: 26_903_000 picoseconds. + Weight::from_parts(27_645_000, 0) .saturating_add(Weight::from_parts(0, 3514)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(2)) @@ -209,8 +233,22 @@ impl pallet_core_fellowship::WeightInfo for WeightInfo< // Proof Size summary in bytes: // Measured: `285` // Estimated: `3514` - // Minimum execution time: 20_000_000 picoseconds. - Weight::from_parts(21_000_000, 0) + // Minimum execution time: 23_286_000 picoseconds. + Weight::from_parts(23_848_000, 0) + .saturating_add(Weight::from_parts(0, 3514)) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `AmbassadorCore::Member` (r:1 w:1) + /// Proof: `AmbassadorCore::Member` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) + /// Storage: `AmbassadorCollective::Members` (r:1 w:0) + /// Proof: `AmbassadorCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) + fn import_member() -> Weight { + // Proof Size summary in bytes: + // Measured: `285` + // Estimated: `3514` + // Minimum execution time: 23_239_000 picoseconds. + Weight::from_parts(23_684_000, 0) .saturating_add(Weight::from_parts(0, 3514)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) @@ -225,8 +263,8 @@ impl pallet_core_fellowship::WeightInfo for WeightInfo< // Proof Size summary in bytes: // Measured: `65967` // Estimated: `69046` - // Minimum execution time: 78_000_000 picoseconds. - Weight::from_parts(104_000_000, 0) + // Minimum execution time: 125_987_000 picoseconds. + Weight::from_parts(130_625_000, 0) .saturating_add(Weight::from_parts(0, 69046)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(2)) @@ -239,8 +277,8 @@ impl pallet_core_fellowship::WeightInfo for WeightInfo< // Proof Size summary in bytes: // Measured: `151` // Estimated: `69046` - // Minimum execution time: 43_000_000 picoseconds. - Weight::from_parts(44_000_000, 0) + // Minimum execution time: 104_431_000 picoseconds. + Weight::from_parts(106_646_000, 0) .saturating_add(Weight::from_parts(0, 69046)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/pallet_core_fellowship_fellowship_core.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/pallet_core_fellowship_fellowship_core.rs index 05014e273f00..acb1f82985db 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/pallet_core_fellowship_fellowship_core.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/weights/pallet_core_fellowship_fellowship_core.rs @@ -1,39 +1,44 @@ // Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 +// This file is part of Cumulus. -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// 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 . //! Autogenerated weights for `pallet_core_fellowship` //! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-08-11, STEPS: `2`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2025-01-03, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `cob`, CPU: `` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("collectives-polkadot-dev")`, DB CACHE: 1024 +//! HOSTNAME: `623e9e4b814e`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: 1024 // Executed Command: -// target/release/polkadot-parachain +// frame-omni-bencher +// v1 // benchmark // pallet -// --chain=collectives-polkadot-dev -// --wasm-execution=compiled -// --pallet=pallet_core_fellowship // --extrinsic=* -// --steps=2 -// --repeat=2 -// --json -// --header=./file_header.txt -// --output=./parachains/runtimes/collectives/collectives-polkadot/src/weights/ +// --runtime=target/production/wbuild/collectives-westend-runtime/collectives_westend_runtime.wasm +// --pallet=pallet_core_fellowship +// --header=/__w/polkadot-sdk/polkadot-sdk/cumulus/file_header.txt +// --output=./cumulus/parachains/runtimes/collectives/collectives-westend/src/weights +// --wasm-execution=compiled +// --steps=50 +// --repeat=20 +// --heap-pages=4096 +// --no-storage-info +// --no-min-squares +// --no-median-slopes #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -47,25 +52,26 @@ use core::marker::PhantomData; pub struct WeightInfo(PhantomData); impl pallet_core_fellowship::WeightInfo for WeightInfo { /// Storage: `FellowshipCore::Params` (r:0 w:1) - /// Proof: `FellowshipCore::Params` (`max_values`: Some(1), `max_size`: Some(364), added: 859, mode: `MaxEncodedLen`) + /// Proof: `FellowshipCore::Params` (`max_values`: Some(1), `max_size`: Some(368), added: 863, mode: `MaxEncodedLen`) fn set_params() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 11_000_000 picoseconds. - Weight::from_parts(12_000_000, 0) + // Minimum execution time: 9_115_000 picoseconds. + Weight::from_parts(9_523_000, 0) .saturating_add(Weight::from_parts(0, 0)) .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: `FellowshipCore::Params` (r:0 w:1) - /// Proof: `FellowshipCore::Params` (`max_values`: Some(1), `max_size`: Some(364), added: 859, mode: `MaxEncodedLen`) + /// Storage: `FellowshipCore::Params` (r:1 w:1) + /// Proof: `FellowshipCore::Params` (`max_values`: Some(1), `max_size`: Some(368), added: 863, mode: `MaxEncodedLen`) fn set_partial_params() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 11_000_000 picoseconds. - Weight::from_parts(12_000_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Measured: `504` + // Estimated: `1853` + // Minimum execution time: 18_294_000 picoseconds. + Weight::from_parts(18_942_000, 0) + .saturating_add(Weight::from_parts(0, 1853)) + .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `FellowshipCore::Member` (r:1 w:1) @@ -73,44 +79,48 @@ impl pallet_core_fellowship::WeightInfo for WeightInfo< /// Storage: `FellowshipCollective::Members` (r:1 w:1) /// Proof: `FellowshipCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) /// Storage: `FellowshipCore::Params` (r:1 w:0) - /// Proof: `FellowshipCore::Params` (`max_values`: Some(1), `max_size`: Some(364), added: 859, mode: `MaxEncodedLen`) + /// Proof: `FellowshipCore::Params` (`max_values`: Some(1), `max_size`: Some(368), added: 863, mode: `MaxEncodedLen`) /// Storage: `FellowshipCollective::MemberCount` (r:1 w:1) /// Proof: `FellowshipCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) - /// Storage: `FellowshipCollective::IdToIndex` (r:1 w:0) + /// Storage: `FellowshipCollective::IdToIndex` (r:1 w:1) /// Proof: `FellowshipCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) /// Storage: `FellowshipCore::MemberEvidence` (r:1 w:1) /// Proof: `FellowshipCore::MemberEvidence` (`max_values`: None, `max_size`: Some(65581), added: 68056, mode: `MaxEncodedLen`) + /// Storage: `FellowshipCollective::IndexToId` (r:0 w:1) + /// Proof: `FellowshipCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) fn bump_offboard() -> Weight { // Proof Size summary in bytes: - // Measured: `66144` + // Measured: `66535` // Estimated: `69046` - // Minimum execution time: 109_000_000 picoseconds. - Weight::from_parts(125_000_000, 0) + // Minimum execution time: 152_823_000 picoseconds. + Weight::from_parts(158_737_000, 0) .saturating_add(Weight::from_parts(0, 69046)) .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(4)) + .saturating_add(T::DbWeight::get().writes(6)) } /// Storage: `FellowshipCore::Member` (r:1 w:1) /// Proof: `FellowshipCore::Member` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) /// Storage: `FellowshipCollective::Members` (r:1 w:1) /// Proof: `FellowshipCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) /// Storage: `FellowshipCore::Params` (r:1 w:0) - /// Proof: `FellowshipCore::Params` (`max_values`: Some(1), `max_size`: Some(364), added: 859, mode: `MaxEncodedLen`) + /// Proof: `FellowshipCore::Params` (`max_values`: Some(1), `max_size`: Some(368), added: 863, mode: `MaxEncodedLen`) /// Storage: `FellowshipCollective::MemberCount` (r:1 w:1) /// Proof: `FellowshipCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) - /// Storage: `FellowshipCollective::IdToIndex` (r:1 w:0) + /// Storage: `FellowshipCollective::IdToIndex` (r:1 w:1) /// Proof: `FellowshipCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) /// Storage: `FellowshipCore::MemberEvidence` (r:1 w:1) /// Proof: `FellowshipCore::MemberEvidence` (`max_values`: None, `max_size`: Some(65581), added: 68056, mode: `MaxEncodedLen`) + /// Storage: `FellowshipCollective::IndexToId` (r:0 w:1) + /// Proof: `FellowshipCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) fn bump_demote() -> Weight { // Proof Size summary in bytes: - // Measured: `66254` + // Measured: `66645` // Estimated: `69046` - // Minimum execution time: 112_000_000 picoseconds. - Weight::from_parts(114_000_000, 0) + // Minimum execution time: 157_605_000 picoseconds. + Weight::from_parts(162_341_000, 0) .saturating_add(Weight::from_parts(0, 69046)) .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(4)) + .saturating_add(T::DbWeight::get().writes(6)) } /// Storage: `FellowshipCollective::Members` (r:1 w:0) /// Proof: `FellowshipCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) @@ -120,8 +130,8 @@ impl pallet_core_fellowship::WeightInfo for WeightInfo< // Proof Size summary in bytes: // Measured: `493` // Estimated: `3514` - // Minimum execution time: 22_000_000 picoseconds. - Weight::from_parts(27_000_000, 0) + // Minimum execution time: 25_194_000 picoseconds. + Weight::from_parts(26_262_000, 0) .saturating_add(Weight::from_parts(0, 3514)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) @@ -140,8 +150,8 @@ impl pallet_core_fellowship::WeightInfo for WeightInfo< // Proof Size summary in bytes: // Measured: `251` // Estimated: `3514` - // Minimum execution time: 35_000_000 picoseconds. - Weight::from_parts(36_000_000, 0) + // Minimum execution time: 35_479_000 picoseconds. + Weight::from_parts(36_360_000, 0) .saturating_add(Weight::from_parts(0, 3514)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(5)) @@ -151,7 +161,7 @@ impl pallet_core_fellowship::WeightInfo for WeightInfo< /// Storage: `FellowshipCore::Member` (r:1 w:1) /// Proof: `FellowshipCore::Member` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) /// Storage: `FellowshipCore::Params` (r:1 w:0) - /// Proof: `FellowshipCore::Params` (`max_values`: Some(1), `max_size`: Some(364), added: 859, mode: `MaxEncodedLen`) + /// Proof: `FellowshipCore::Params` (`max_values`: Some(1), `max_size`: Some(368), added: 863, mode: `MaxEncodedLen`) /// Storage: `FellowshipCollective::MemberCount` (r:1 w:1) /// Proof: `FellowshipCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) /// Storage: `FellowshipCore::MemberEvidence` (r:1 w:1) @@ -162,25 +172,40 @@ impl pallet_core_fellowship::WeightInfo for WeightInfo< /// Proof: `FellowshipCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) fn promote() -> Weight { // Proof Size summary in bytes: - // Measured: `66122` + // Measured: `66188` // Estimated: `69046` - // Minimum execution time: 97_000_000 picoseconds. - Weight::from_parts(129_000_000, 0) + // Minimum execution time: 147_993_000 picoseconds. + Weight::from_parts(153_943_000, 0) .saturating_add(Weight::from_parts(0, 69046)) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(6)) } + /// Storage: `FellowshipCollective::Members` (r:1 w:1) + /// Proof: `FellowshipCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) + /// Storage: `FellowshipCore::Member` (r:1 w:1) + /// Proof: `FellowshipCore::Member` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) + /// Storage: `FellowshipCollective::MemberCount` (r:9 w:9) + /// Proof: `FellowshipCollective::MemberCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `FellowshipCore::MemberEvidence` (r:1 w:1) + /// Proof: `FellowshipCore::MemberEvidence` (`max_values`: None, `max_size`: Some(65581), added: 68056, mode: `MaxEncodedLen`) + /// Storage: `FellowshipCollective::IndexToId` (r:0 w:9) + /// Proof: `FellowshipCollective::IndexToId` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) + /// Storage: `FellowshipCollective::IdToIndex` (r:0 w:9) + /// Proof: `FellowshipCollective::IdToIndex` (`max_values`: None, `max_size`: Some(54), added: 2529, mode: `MaxEncodedLen`) + /// The range of component `r` is `[1, 9]`. + /// The range of component `r` is `[1, 9]`. fn promote_fast(r: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `16844` - // Estimated: `19894 + r * (2489 ±0)` - // Minimum execution time: 45_065_000 picoseconds. - Weight::from_parts(34_090_392, 19894) - // Standard Error: 18_620 - .saturating_add(Weight::from_parts(13_578_046, 0).saturating_mul(r.into())) - .saturating_add(T::DbWeight::get().reads(3_u64)) + // Measured: `66101` + // Estimated: `69046 + r * (2489 ±0)` + // Minimum execution time: 138_444_000 picoseconds. + Weight::from_parts(125_440_035, 0) + .saturating_add(Weight::from_parts(0, 69046)) + // Standard Error: 55_452 + .saturating_add(Weight::from_parts(19_946_954, 0).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(r.into()))) - .saturating_add(T::DbWeight::get().writes(3_u64)) + .saturating_add(T::DbWeight::get().writes(3)) .saturating_add(T::DbWeight::get().writes((3_u64).saturating_mul(r.into()))) .saturating_add(Weight::from_parts(0, 2489).saturating_mul(r.into())) } @@ -192,10 +217,10 @@ impl pallet_core_fellowship::WeightInfo for WeightInfo< /// Proof: `FellowshipCore::MemberEvidence` (`max_values`: None, `max_size`: Some(65581), added: 68056, mode: `MaxEncodedLen`) fn offboard() -> Weight { // Proof Size summary in bytes: - // Measured: `464` + // Measured: `398` // Estimated: `3514` - // Minimum execution time: 22_000_000 picoseconds. - Weight::from_parts(22_000_000, 0) + // Minimum execution time: 27_392_000 picoseconds. + Weight::from_parts(28_134_000, 0) .saturating_add(Weight::from_parts(0, 3514)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(2)) @@ -208,8 +233,22 @@ impl pallet_core_fellowship::WeightInfo for WeightInfo< // Proof Size summary in bytes: // Measured: `418` // Estimated: `3514` - // Minimum execution time: 20_000_000 picoseconds. - Weight::from_parts(24_000_000, 0) + // Minimum execution time: 23_523_000 picoseconds. + Weight::from_parts(24_046_000, 0) + .saturating_add(Weight::from_parts(0, 3514)) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `FellowshipCore::Member` (r:1 w:1) + /// Proof: `FellowshipCore::Member` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) + /// Storage: `FellowshipCollective::Members` (r:1 w:0) + /// Proof: `FellowshipCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) + fn import_member() -> Weight { + // Proof Size summary in bytes: + // Measured: `418` + // Estimated: `3514` + // Minimum execution time: 23_369_000 picoseconds. + Weight::from_parts(24_088_000, 0) .saturating_add(Weight::from_parts(0, 3514)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) @@ -224,8 +263,8 @@ impl pallet_core_fellowship::WeightInfo for WeightInfo< // Proof Size summary in bytes: // Measured: `66100` // Estimated: `69046` - // Minimum execution time: 89_000_000 picoseconds. - Weight::from_parts(119_000_000, 0) + // Minimum execution time: 127_137_000 picoseconds. + Weight::from_parts(131_638_000, 0) .saturating_add(Weight::from_parts(0, 69046)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(2)) @@ -238,8 +277,8 @@ impl pallet_core_fellowship::WeightInfo for WeightInfo< // Proof Size summary in bytes: // Measured: `184` // Estimated: `69046` - // Minimum execution time: 43_000_000 picoseconds. - Weight::from_parts(52_000_000, 0) + // Minimum execution time: 103_212_000 picoseconds. + Weight::from_parts(105_488_000, 0) .saturating_add(Weight::from_parts(0, 69046)) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/Cargo.toml b/cumulus/parachains/runtimes/contracts/contracts-rococo/Cargo.toml index cb0655d70cf2..067c4df3b536 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/Cargo.toml @@ -70,11 +70,11 @@ xcm-runtime-apis = { workspace = true } cumulus-pallet-aura-ext = { workspace = true } cumulus-pallet-parachain-system = { workspace = true } cumulus-pallet-session-benchmarking = { workspace = true } +cumulus-pallet-weight-reclaim = { workspace = true } cumulus-pallet-xcm = { workspace = true } cumulus-pallet-xcmp-queue = { workspace = true } cumulus-primitives-aura = { workspace = true } cumulus-primitives-core = { workspace = true } -cumulus-primitives-storage-weight-reclaim = { workspace = true } cumulus-primitives-utility = { workspace = true } pallet-message-queue = { workspace = true } @@ -90,11 +90,11 @@ std = [ "cumulus-pallet-aura-ext/std", "cumulus-pallet-parachain-system/std", "cumulus-pallet-session-benchmarking/std", + "cumulus-pallet-weight-reclaim/std", "cumulus-pallet-xcm/std", "cumulus-pallet-xcmp-queue/std", "cumulus-primitives-aura/std", "cumulus-primitives-core/std", - "cumulus-primitives-storage-weight-reclaim/std", "cumulus-primitives-utility/std", "frame-benchmarking?/std", "frame-executive/std", @@ -148,6 +148,7 @@ std = [ runtime-benchmarks = [ "cumulus-pallet-parachain-system/runtime-benchmarks", "cumulus-pallet-session-benchmarking/runtime-benchmarks", + "cumulus-pallet-weight-reclaim/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", "cumulus-primitives-core/runtime-benchmarks", "cumulus-primitives-utility/runtime-benchmarks", @@ -179,6 +180,7 @@ runtime-benchmarks = [ try-runtime = [ "cumulus-pallet-aura-ext/try-runtime", "cumulus-pallet-parachain-system/try-runtime", + "cumulus-pallet-weight-reclaim/try-runtime", "cumulus-pallet-xcm/try-runtime", "cumulus-pallet-xcmp-queue/try-runtime", "frame-executive/try-runtime", diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs index 594c9b26f57e..3348a635df01 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs @@ -88,17 +88,19 @@ pub type SignedBlock = generic::SignedBlock; /// BlockId type as expected by this runtime. pub type BlockId = generic::BlockId; /// The extension to the basic transaction logic. -pub type TxExtension = ( - frame_system::CheckNonZeroSender, - frame_system::CheckSpecVersion, - frame_system::CheckTxVersion, - frame_system::CheckGenesis, - frame_system::CheckEra, - frame_system::CheckNonce, - frame_system::CheckWeight, - pallet_transaction_payment::ChargeTransactionPayment, - cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim, -); +pub type TxExtension = cumulus_pallet_weight_reclaim::StorageWeightReclaim< + Runtime, + ( + frame_system::CheckNonZeroSender, + frame_system::CheckSpecVersion, + frame_system::CheckTxVersion, + frame_system::CheckGenesis, + frame_system::CheckEra, + frame_system::CheckNonce, + frame_system::CheckWeight, + pallet_transaction_payment::ChargeTransactionPayment, + ), +>; /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; @@ -201,6 +203,10 @@ impl frame_system::Config for Runtime { type MaxConsumers = ConstU32<16>; } +impl cumulus_pallet_weight_reclaim::Config for Runtime { + type WeightInfo = (); +} + impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. type Moment = u64; @@ -402,6 +408,7 @@ construct_runtime!( RandomnessCollectiveFlip: pallet_insecure_randomness_collective_flip = 2, Timestamp: pallet_timestamp = 3, ParachainInfo: parachain_info = 4, + WeightReclaim: cumulus_pallet_weight_reclaim = 5, // Monetary stuff. Balances: pallet_balances = 10, @@ -448,6 +455,7 @@ mod benches { [cumulus_pallet_parachain_system, ParachainSystem] [pallet_contracts, Contracts] [pallet_xcm, PalletXcmExtrinsicsBenchmark::] + [cumulus_pallet_weight_reclaim, WeightReclaim] ); } @@ -849,18 +857,8 @@ impl_runtime_apis! { } } - let whitelist: Vec = vec![ - // Block Number - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(), - // Total Issuance - hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(), - // Execution Phase - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(), - // Event Count - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(), - // System Events - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(), - ]; + use frame_support::traits::WhitelistedStorageKeys; + let whitelist: Vec = AllPalletsWithSystem::whitelisted_storage_keys(); let mut batches = Vec::::new(); let params = (&config, &whitelist); diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/Cargo.toml b/cumulus/parachains/runtimes/coretime/coretime-rococo/Cargo.toml index 2b5fab329293..668b4cc6c7b9 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/Cargo.toml @@ -71,11 +71,11 @@ xcm-runtime-apis = { workspace = true } cumulus-pallet-aura-ext = { workspace = true } cumulus-pallet-parachain-system = { workspace = true } cumulus-pallet-session-benchmarking = { workspace = true } +cumulus-pallet-weight-reclaim = { workspace = true } cumulus-pallet-xcm = { workspace = true } cumulus-pallet-xcmp-queue = { workspace = true } cumulus-primitives-aura = { workspace = true } cumulus-primitives-core = { workspace = true } -cumulus-primitives-storage-weight-reclaim = { workspace = true } cumulus-primitives-utility = { workspace = true } pallet-collator-selection = { workspace = true } parachain-info = { workspace = true } @@ -92,11 +92,11 @@ std = [ "cumulus-pallet-aura-ext/std", "cumulus-pallet-parachain-system/std", "cumulus-pallet-session-benchmarking/std", + "cumulus-pallet-weight-reclaim/std", "cumulus-pallet-xcm/std", "cumulus-pallet-xcmp-queue/std", "cumulus-primitives-aura/std", "cumulus-primitives-core/std", - "cumulus-primitives-storage-weight-reclaim/std", "cumulus-primitives-utility/std", "frame-benchmarking?/std", "frame-executive/std", @@ -154,6 +154,7 @@ std = [ runtime-benchmarks = [ "cumulus-pallet-parachain-system/runtime-benchmarks", "cumulus-pallet-session-benchmarking/runtime-benchmarks", + "cumulus-pallet-weight-reclaim/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", "cumulus-primitives-core/runtime-benchmarks", "cumulus-primitives-utility/runtime-benchmarks", @@ -186,6 +187,7 @@ runtime-benchmarks = [ try-runtime = [ "cumulus-pallet-aura-ext/try-runtime", "cumulus-pallet-parachain-system/try-runtime", + "cumulus-pallet-weight-reclaim/try-runtime", "cumulus-pallet-xcm/try-runtime", "cumulus-pallet-xcmp-queue/try-runtime", "frame-executive/try-runtime", diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs index e8f6e6659e13..e9171c79afae 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs @@ -99,18 +99,20 @@ pub type SignedBlock = generic::SignedBlock; pub type BlockId = generic::BlockId; /// The TransactionExtension to the basic transaction logic. -pub type TxExtension = ( - frame_system::CheckNonZeroSender, - frame_system::CheckSpecVersion, - frame_system::CheckTxVersion, - frame_system::CheckGenesis, - frame_system::CheckEra, - frame_system::CheckNonce, - frame_system::CheckWeight, - pallet_transaction_payment::ChargeTransactionPayment, - cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim, - frame_metadata_hash_extension::CheckMetadataHash, -); +pub type TxExtension = cumulus_pallet_weight_reclaim::StorageWeightReclaim< + Runtime, + ( + frame_system::CheckNonZeroSender, + frame_system::CheckSpecVersion, + frame_system::CheckTxVersion, + frame_system::CheckGenesis, + frame_system::CheckEra, + frame_system::CheckNonce, + frame_system::CheckWeight, + pallet_transaction_payment::ChargeTransactionPayment, + frame_metadata_hash_extension::CheckMetadataHash, + ), +>; /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = @@ -221,6 +223,10 @@ impl frame_system::Config for Runtime { type MaxConsumers = ConstU32<16>; } +impl cumulus_pallet_weight_reclaim::Config for Runtime { + type WeightInfo = weights::cumulus_pallet_weight_reclaim::WeightInfo; +} + impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. type Moment = u64; @@ -622,6 +628,7 @@ construct_runtime!( ParachainSystem: cumulus_pallet_parachain_system = 1, Timestamp: pallet_timestamp = 3, ParachainInfo: parachain_info = 4, + WeightReclaim: cumulus_pallet_weight_reclaim = 5, // Monetary stuff. Balances: pallet_balances = 10, @@ -672,6 +679,7 @@ mod benches { // NOTE: Make sure you point to the individual modules below. [pallet_xcm_benchmarks::fungible, XcmBalances] [pallet_xcm_benchmarks::generic, XcmGeneric] + [cumulus_pallet_weight_reclaim, WeightReclaim] ); } @@ -1140,18 +1148,8 @@ impl_runtime_apis! { type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; - let whitelist: Vec = vec![ - // Block Number - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(), - // Total Issuance - hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(), - // Execution Phase - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(), - // Event Count - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(), - // System Events - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(), - ]; + use frame_support::traits::WhitelistedStorageKeys; + let whitelist: Vec = AllPalletsWithSystem::whitelisted_storage_keys(); let mut batches = Vec::::new(); let params = (&config, &whitelist); diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/cumulus_pallet_weight_reclaim.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/cumulus_pallet_weight_reclaim.rs new file mode 100644 index 000000000000..6298fd6e7f69 --- /dev/null +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/cumulus_pallet_weight_reclaim.rs @@ -0,0 +1,67 @@ +// 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 . + +//! Autogenerated weights for `cumulus_pallet_weight_reclaim` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-12-30, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `runner-ys-ssygq-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("coretime-rococo-dev")`, DB CACHE: 1024 + +// Executed Command: +// target/production/polkadot-parachain +// benchmark +// pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --wasm-execution=compiled +// --heap-pages=4096 +// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json +// --pallet=cumulus_pallet_weight_reclaim +// --chain=coretime-rococo-dev +// --header=./cumulus/file_header.txt +// --output=./cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `cumulus_pallet_weight_reclaim`. +pub struct WeightInfo(PhantomData); +impl cumulus_pallet_weight_reclaim::WeightInfo for WeightInfo { + /// Storage: `System::BlockWeight` (r:1 w:1) + /// Proof: `System::BlockWeight` (`max_values`: Some(1), `max_size`: Some(48), added: 543, mode: `MaxEncodedLen`) + /// Storage: `System::ExtrinsicWeightReclaimed` (r:1 w:1) + /// Proof: `System::ExtrinsicWeightReclaimed` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) + /// Storage: `System::AllExtrinsicsLen` (r:1 w:0) + /// Proof: `System::AllExtrinsicsLen` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + fn storage_weight_reclaim() -> Weight { + // Proof Size summary in bytes: + // Measured: `24` + // Estimated: `1533` + // Minimum execution time: 6_638_000 picoseconds. + Weight::from_parts(6_806_000, 0) + .saturating_add(Weight::from_parts(0, 1533)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) + } +} diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/frame_system_extensions.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/frame_system_extensions.rs index a4d09696a1a1..04b695b57693 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/frame_system_extensions.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/frame_system_extensions.rs @@ -129,4 +129,18 @@ impl frame_system::ExtensionsWeightInfo for WeightInfo< .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(2)) } + /// Storage: `System::AllExtrinsicsLen` (r:1 w:1) + /// Proof: `System::AllExtrinsicsLen` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `System::BlockWeight` (r:1 w:1) + /// Proof: `System::BlockWeight` (`max_values`: Some(1), `max_size`: Some(48), added: 543, mode: `MaxEncodedLen`) + fn weight_reclaim() -> Weight { + // Proof Size summary in bytes: + // Measured: `24` + // Estimated: `1533` + // Minimum execution time: 3_687_000 picoseconds. + Weight::from_parts(6_192_000, 0) + .saturating_add(Weight::from_parts(0, 1533)) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(2)) + } } diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/mod.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/mod.rs index 24c4f50e6ab8..7fee4a728b9e 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/mod.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/weights/mod.rs @@ -19,6 +19,7 @@ pub mod block_weights; pub mod cumulus_pallet_parachain_system; +pub mod cumulus_pallet_weight_reclaim; pub mod cumulus_pallet_xcmp_queue; pub mod extrinsic_weights; pub mod frame_system; diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/Cargo.toml b/cumulus/parachains/runtimes/coretime/coretime-westend/Cargo.toml index 03df782bc266..915926ff9894 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/Cargo.toml +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/Cargo.toml @@ -70,11 +70,11 @@ xcm-runtime-apis = { workspace = true } cumulus-pallet-aura-ext = { workspace = true } cumulus-pallet-parachain-system = { workspace = true } cumulus-pallet-session-benchmarking = { workspace = true } +cumulus-pallet-weight-reclaim = { workspace = true } cumulus-pallet-xcm = { workspace = true } cumulus-pallet-xcmp-queue = { workspace = true } cumulus-primitives-aura = { workspace = true } cumulus-primitives-core = { workspace = true } -cumulus-primitives-storage-weight-reclaim = { workspace = true } cumulus-primitives-utility = { workspace = true } pallet-collator-selection = { workspace = true } @@ -92,11 +92,11 @@ std = [ "cumulus-pallet-aura-ext/std", "cumulus-pallet-parachain-system/std", "cumulus-pallet-session-benchmarking/std", + "cumulus-pallet-weight-reclaim/std", "cumulus-pallet-xcm/std", "cumulus-pallet-xcmp-queue/std", "cumulus-primitives-aura/std", "cumulus-primitives-core/std", - "cumulus-primitives-storage-weight-reclaim/std", "cumulus-primitives-utility/std", "frame-benchmarking?/std", "frame-executive/std", @@ -152,6 +152,7 @@ std = [ runtime-benchmarks = [ "cumulus-pallet-parachain-system/runtime-benchmarks", "cumulus-pallet-session-benchmarking/runtime-benchmarks", + "cumulus-pallet-weight-reclaim/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", "cumulus-primitives-core/runtime-benchmarks", "cumulus-primitives-utility/runtime-benchmarks", @@ -183,6 +184,7 @@ runtime-benchmarks = [ try-runtime = [ "cumulus-pallet-aura-ext/try-runtime", "cumulus-pallet-parachain-system/try-runtime", + "cumulus-pallet-weight-reclaim/try-runtime", "cumulus-pallet-xcm/try-runtime", "cumulus-pallet-xcmp-queue/try-runtime", "frame-executive/try-runtime", diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs index ce965f0ad1ba..975856b3b6ff 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs @@ -99,18 +99,20 @@ pub type SignedBlock = generic::SignedBlock; pub type BlockId = generic::BlockId; /// The TransactionExtension to the basic transaction logic. -pub type TxExtension = ( - frame_system::CheckNonZeroSender, - frame_system::CheckSpecVersion, - frame_system::CheckTxVersion, - frame_system::CheckGenesis, - frame_system::CheckEra, - frame_system::CheckNonce, - frame_system::CheckWeight, - pallet_transaction_payment::ChargeTransactionPayment, - cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim, - frame_metadata_hash_extension::CheckMetadataHash, -); +pub type TxExtension = cumulus_pallet_weight_reclaim::StorageWeightReclaim< + Runtime, + ( + frame_system::CheckNonZeroSender, + frame_system::CheckSpecVersion, + frame_system::CheckTxVersion, + frame_system::CheckGenesis, + frame_system::CheckEra, + frame_system::CheckNonce, + frame_system::CheckWeight, + pallet_transaction_payment::ChargeTransactionPayment, + frame_metadata_hash_extension::CheckMetadataHash, + ), +>; /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = @@ -221,6 +223,10 @@ impl frame_system::Config for Runtime { type MaxConsumers = ConstU32<16>; } +impl cumulus_pallet_weight_reclaim::Config for Runtime { + type WeightInfo = weights::cumulus_pallet_weight_reclaim::WeightInfo; +} + impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. type Moment = u64; @@ -617,6 +623,7 @@ construct_runtime!( ParachainSystem: cumulus_pallet_parachain_system = 1, Timestamp: pallet_timestamp = 3, ParachainInfo: parachain_info = 4, + WeightReclaim: cumulus_pallet_weight_reclaim = 5, // Monetary stuff. Balances: pallet_balances = 10, @@ -664,6 +671,7 @@ mod benches { // NOTE: Make sure you point to the individual modules below. [pallet_xcm_benchmarks::fungible, XcmBalances] [pallet_xcm_benchmarks::generic, XcmGeneric] + [cumulus_pallet_weight_reclaim, WeightReclaim] ); } @@ -1135,18 +1143,8 @@ impl_runtime_apis! { type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; - let whitelist: Vec = vec![ - // Block Number - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(), - // Total Issuance - hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(), - // Execution Phase - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(), - // Event Count - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(), - // System Events - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(), - ]; + use frame_support::traits::WhitelistedStorageKeys; + let whitelist: Vec = AllPalletsWithSystem::whitelisted_storage_keys(); let mut batches = Vec::::new(); let params = (&config, &whitelist); diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/weights/cumulus_pallet_weight_reclaim.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/weights/cumulus_pallet_weight_reclaim.rs new file mode 100644 index 000000000000..55d52f4b04c8 --- /dev/null +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/weights/cumulus_pallet_weight_reclaim.rs @@ -0,0 +1,67 @@ +// 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 . + +//! Autogenerated weights for `cumulus_pallet_weight_reclaim` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-12-30, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `runner-ys-ssygq-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("coretime-westend-dev")`, DB CACHE: 1024 + +// Executed Command: +// target/production/polkadot-parachain +// benchmark +// pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --wasm-execution=compiled +// --heap-pages=4096 +// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json +// --pallet=cumulus_pallet_weight_reclaim +// --chain=coretime-westend-dev +// --header=./cumulus/file_header.txt +// --output=./cumulus/parachains/runtimes/coretime/coretime-westend/src/weights/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `cumulus_pallet_weight_reclaim`. +pub struct WeightInfo(PhantomData); +impl cumulus_pallet_weight_reclaim::WeightInfo for WeightInfo { + /// Storage: `System::BlockWeight` (r:1 w:1) + /// Proof: `System::BlockWeight` (`max_values`: Some(1), `max_size`: Some(48), added: 543, mode: `MaxEncodedLen`) + /// Storage: `System::ExtrinsicWeightReclaimed` (r:1 w:1) + /// Proof: `System::ExtrinsicWeightReclaimed` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) + /// Storage: `System::AllExtrinsicsLen` (r:1 w:0) + /// Proof: `System::AllExtrinsicsLen` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + fn storage_weight_reclaim() -> Weight { + // Proof Size summary in bytes: + // Measured: `24` + // Estimated: `1533` + // Minimum execution time: 6_658_000 picoseconds. + Weight::from_parts(6_905_000, 0) + .saturating_add(Weight::from_parts(0, 1533)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) + } +} diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/weights/frame_system_extensions.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/weights/frame_system_extensions.rs index d928b73613a3..9527e0c5549a 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/weights/frame_system_extensions.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/weights/frame_system_extensions.rs @@ -129,4 +129,18 @@ impl frame_system::ExtensionsWeightInfo for WeightInfo< .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(2)) } + /// Storage: `System::AllExtrinsicsLen` (r:1 w:1) + /// Proof: `System::AllExtrinsicsLen` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `System::BlockWeight` (r:1 w:1) + /// Proof: `System::BlockWeight` (`max_values`: Some(1), `max_size`: Some(48), added: 543, mode: `MaxEncodedLen`) + fn weight_reclaim() -> Weight { + // Proof Size summary in bytes: + // Measured: `24` + // Estimated: `1533` + // Minimum execution time: 3_687_000 picoseconds. + Weight::from_parts(6_192_000, 0) + .saturating_add(Weight::from_parts(0, 1533)) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(2)) + } } diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/weights/mod.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/weights/mod.rs index 24c4f50e6ab8..7fee4a728b9e 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/weights/mod.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/weights/mod.rs @@ -19,6 +19,7 @@ pub mod block_weights; pub mod cumulus_pallet_parachain_system; +pub mod cumulus_pallet_weight_reclaim; pub mod cumulus_pallet_xcmp_queue; pub mod extrinsic_weights; pub mod frame_system; diff --git a/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs b/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs index 763f8abea34a..75f45297fe2c 100644 --- a/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/glutton/glutton-westend/src/lib.rs @@ -300,6 +300,7 @@ pub type TxExtension = ( frame_system::CheckEra, frame_system::CheckNonce, frame_system::CheckWeight, + frame_system::WeightReclaim, ); /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = diff --git a/cumulus/parachains/runtimes/glutton/glutton-westend/src/weights/frame_system_extensions.rs b/cumulus/parachains/runtimes/glutton/glutton-westend/src/weights/frame_system_extensions.rs index 4fbbb8d6f781..db9a14e2cf24 100644 --- a/cumulus/parachains/runtimes/glutton/glutton-westend/src/weights/frame_system_extensions.rs +++ b/cumulus/parachains/runtimes/glutton/glutton-westend/src/weights/frame_system_extensions.rs @@ -16,28 +16,30 @@ //! Autogenerated weights for `frame_system_extensions` //! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-21, STEPS: `2`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-10-31, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `gleipnir`, CPU: `AMD Ryzen 9 7900X 12-Core Processor` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("glutton-westend-dev-1300")`, DB CACHE: 1024 +//! HOSTNAME: `697235d969a1`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: 1024 // Executed Command: -// ./target/release/polkadot-parachain +// frame-omni-bencher +// v1 // benchmark // pallet -// --wasm-execution=compiled +// --extrinsic=* +// --runtime=target/release/wbuild/glutton-westend-runtime/glutton_westend_runtime.wasm // --pallet=frame_system_extensions +// --header=/__w/polkadot-sdk/polkadot-sdk/cumulus/file_header.txt +// --output=./cumulus/parachains/runtimes/glutton/glutton-westend/src/weights +// --wasm-execution=compiled +// --steps=50 +// --repeat=20 +// --heap-pages=4096 // --no-storage-info -// --no-median-slopes // --no-min-squares -// --extrinsic=* -// --steps=2 -// --repeat=2 -// --json -// --header=./cumulus/file_header.txt -// --output=./cumulus/parachains/runtimes/glutton/glutton-westend/src/weights/ -// --chain=glutton-westend-dev-1300 +// --no-median-slopes +// --genesis-builder-policy=none #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -54,10 +56,10 @@ impl frame_system::ExtensionsWeightInfo for WeightInfo< /// Proof: `System::BlockHash` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `MaxEncodedLen`) fn check_genesis() -> Weight { // Proof Size summary in bytes: - // Measured: `54` + // Measured: `0` // Estimated: `3509` - // Minimum execution time: 3_908_000 picoseconds. - Weight::from_parts(4_007_000, 0) + // Minimum execution time: 2_572_000 picoseconds. + Weight::from_parts(2_680_000, 0) .saturating_add(Weight::from_parts(0, 3509)) .saturating_add(T::DbWeight::get().reads(1)) } @@ -65,10 +67,10 @@ impl frame_system::ExtensionsWeightInfo for WeightInfo< /// Proof: `System::BlockHash` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `MaxEncodedLen`) fn check_mortality_mortal_transaction() -> Weight { // Proof Size summary in bytes: - // Measured: `92` + // Measured: `0` // Estimated: `3509` - // Minimum execution time: 5_510_000 picoseconds. - Weight::from_parts(6_332_000, 0) + // Minimum execution time: 5_818_000 picoseconds. + Weight::from_parts(6_024_000, 0) .saturating_add(Weight::from_parts(0, 3509)) .saturating_add(T::DbWeight::get().reads(1)) } @@ -76,10 +78,10 @@ impl frame_system::ExtensionsWeightInfo for WeightInfo< /// Proof: `System::BlockHash` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `MaxEncodedLen`) fn check_mortality_immortal_transaction() -> Weight { // Proof Size summary in bytes: - // Measured: `92` + // Measured: `14` // Estimated: `3509` - // Minimum execution time: 5_510_000 picoseconds. - Weight::from_parts(6_332_000, 0) + // Minimum execution time: 7_364_000 picoseconds. + Weight::from_parts(7_676_000, 0) .saturating_add(Weight::from_parts(0, 3509)) .saturating_add(T::DbWeight::get().reads(1)) } @@ -87,44 +89,52 @@ impl frame_system::ExtensionsWeightInfo for WeightInfo< // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 651_000 picoseconds. - Weight::from_parts(851_000, 0) + // Minimum execution time: 657_000 picoseconds. + Weight::from_parts(686_000, 0) .saturating_add(Weight::from_parts(0, 0)) } + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(64), added: 2539, mode: `MaxEncodedLen`) fn check_nonce() -> Weight { // Proof Size summary in bytes: // Measured: `0` - // Estimated: `0` - // Minimum execution time: 3_387_000 picoseconds. - Weight::from_parts(3_646_000, 0) - .saturating_add(Weight::from_parts(0, 0)) + // Estimated: `3529` + // Minimum execution time: 6_931_000 picoseconds. + Weight::from_parts(7_096_000, 0) + .saturating_add(Weight::from_parts(0, 3529)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } fn check_spec_version() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 491_000 picoseconds. - Weight::from_parts(651_000, 0) + // Minimum execution time: 518_000 picoseconds. + Weight::from_parts(539_000, 0) .saturating_add(Weight::from_parts(0, 0)) } fn check_tx_version() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 451_000 picoseconds. - Weight::from_parts(662_000, 0) + // Minimum execution time: 530_000 picoseconds. + Weight::from_parts(550_000, 0) .saturating_add(Weight::from_parts(0, 0)) } - /// Storage: `System::AllExtrinsicsLen` (r:1 w:1) - /// Proof: `System::AllExtrinsicsLen` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) fn check_weight() -> Weight { // Proof Size summary in bytes: - // Measured: `24` - // Estimated: `1489` - // Minimum execution time: 3_537_000 picoseconds. - Weight::from_parts(4_208_000, 0) - .saturating_add(Weight::from_parts(0, 1489)) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 5_691_000 picoseconds. + Weight::from_parts(5_955_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + fn weight_reclaim() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 3_249_000 picoseconds. + Weight::from_parts(3_372_000, 0) + .saturating_add(Weight::from_parts(0, 0)) } } diff --git a/cumulus/parachains/runtimes/people/people-rococo/Cargo.toml b/cumulus/parachains/runtimes/people/people-rococo/Cargo.toml index de2898046c0d..6391f8c3eeb9 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/people/people-rococo/Cargo.toml @@ -68,11 +68,11 @@ xcm-runtime-apis = { workspace = true } cumulus-pallet-aura-ext = { workspace = true } cumulus-pallet-parachain-system = { workspace = true } cumulus-pallet-session-benchmarking = { workspace = true } +cumulus-pallet-weight-reclaim = { workspace = true } cumulus-pallet-xcm = { workspace = true } cumulus-pallet-xcmp-queue = { workspace = true } cumulus-primitives-aura = { workspace = true } cumulus-primitives-core = { workspace = true } -cumulus-primitives-storage-weight-reclaim = { workspace = true } cumulus-primitives-utility = { workspace = true } pallet-collator-selection = { workspace = true } parachain-info = { workspace = true } @@ -89,11 +89,11 @@ std = [ "cumulus-pallet-aura-ext/std", "cumulus-pallet-parachain-system/std", "cumulus-pallet-session-benchmarking/std", + "cumulus-pallet-weight-reclaim/std", "cumulus-pallet-xcm/std", "cumulus-pallet-xcmp-queue/std", "cumulus-primitives-aura/std", "cumulus-primitives-core/std", - "cumulus-primitives-storage-weight-reclaim/std", "cumulus-primitives-utility/std", "enumflags2/std", "frame-benchmarking?/std", @@ -150,6 +150,7 @@ std = [ runtime-benchmarks = [ "cumulus-pallet-parachain-system/runtime-benchmarks", "cumulus-pallet-session-benchmarking/runtime-benchmarks", + "cumulus-pallet-weight-reclaim/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", "cumulus-primitives-core/runtime-benchmarks", "cumulus-primitives-utility/runtime-benchmarks", @@ -182,6 +183,7 @@ runtime-benchmarks = [ try-runtime = [ "cumulus-pallet-aura-ext/try-runtime", "cumulus-pallet-parachain-system/try-runtime", + "cumulus-pallet-weight-reclaim/try-runtime", "cumulus-pallet-xcm/try-runtime", "cumulus-pallet-xcmp-queue/try-runtime", "frame-executive/try-runtime", diff --git a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs index b8db687da625..ffdd86c500e5 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs @@ -92,17 +92,19 @@ pub type SignedBlock = generic::SignedBlock; pub type BlockId = generic::BlockId; /// The TransactionExtension to the basic transaction logic. -pub type TxExtension = ( - frame_system::CheckNonZeroSender, - frame_system::CheckSpecVersion, - frame_system::CheckTxVersion, - frame_system::CheckGenesis, - frame_system::CheckEra, - frame_system::CheckNonce, - frame_system::CheckWeight, - pallet_transaction_payment::ChargeTransactionPayment, - cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim, -); +pub type TxExtension = cumulus_pallet_weight_reclaim::StorageWeightReclaim< + Runtime, + ( + frame_system::CheckNonZeroSender, + frame_system::CheckSpecVersion, + frame_system::CheckTxVersion, + frame_system::CheckGenesis, + frame_system::CheckEra, + frame_system::CheckNonce, + frame_system::CheckWeight, + pallet_transaction_payment::ChargeTransactionPayment, + ), +>; /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = @@ -196,6 +198,10 @@ impl frame_system::Config for Runtime { type MultiBlockMigrator = MultiBlockMigrations; } +impl cumulus_pallet_weight_reclaim::Config for Runtime { + type WeightInfo = weights::cumulus_pallet_weight_reclaim::WeightInfo; +} + impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. type Moment = u64; @@ -567,6 +573,7 @@ construct_runtime!( ParachainSystem: cumulus_pallet_parachain_system = 1, Timestamp: pallet_timestamp = 2, ParachainInfo: parachain_info = 3, + WeightReclaim: cumulus_pallet_weight_reclaim = 4, // Monetary stuff. Balances: pallet_balances = 10, @@ -626,6 +633,7 @@ mod benches { [pallet_xcm, PalletXcmExtrinsicsBenchmark::] [pallet_xcm_benchmarks::fungible, XcmBalances] [pallet_xcm_benchmarks::generic, XcmGeneric] + [cumulus_pallet_weight_reclaim, WeightReclaim] ); } @@ -1055,18 +1063,8 @@ impl_runtime_apis! { type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; - let whitelist: Vec = vec![ - // Block Number - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(), - // Total Issuance - hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(), - // Execution Phase - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(), - // Event Count - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(), - // System Events - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(), - ]; + use frame_support::traits::WhitelistedStorageKeys; + let whitelist: Vec = AllPalletsWithSystem::whitelisted_storage_keys(); let mut batches = Vec::::new(); let params = (&config, &whitelist); diff --git a/cumulus/parachains/runtimes/people/people-rococo/src/weights/cumulus_pallet_weight_reclaim.rs b/cumulus/parachains/runtimes/people/people-rococo/src/weights/cumulus_pallet_weight_reclaim.rs new file mode 100644 index 000000000000..439855f85719 --- /dev/null +++ b/cumulus/parachains/runtimes/people/people-rococo/src/weights/cumulus_pallet_weight_reclaim.rs @@ -0,0 +1,67 @@ +// 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 . + +//! Autogenerated weights for `cumulus_pallet_weight_reclaim` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-12-30, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `runner-ys-ssygq-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("people-rococo-dev")`, DB CACHE: 1024 + +// Executed Command: +// target/production/polkadot-parachain +// benchmark +// pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --wasm-execution=compiled +// --heap-pages=4096 +// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json +// --pallet=cumulus_pallet_weight_reclaim +// --chain=people-rococo-dev +// --header=./cumulus/file_header.txt +// --output=./cumulus/parachains/runtimes/people/people-rococo/src/weights/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `cumulus_pallet_weight_reclaim`. +pub struct WeightInfo(PhantomData); +impl cumulus_pallet_weight_reclaim::WeightInfo for WeightInfo { + /// Storage: `System::BlockWeight` (r:1 w:1) + /// Proof: `System::BlockWeight` (`max_values`: Some(1), `max_size`: Some(48), added: 543, mode: `MaxEncodedLen`) + /// Storage: `System::ExtrinsicWeightReclaimed` (r:1 w:1) + /// Proof: `System::ExtrinsicWeightReclaimed` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) + /// Storage: `System::AllExtrinsicsLen` (r:1 w:0) + /// Proof: `System::AllExtrinsicsLen` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + fn storage_weight_reclaim() -> Weight { + // Proof Size summary in bytes: + // Measured: `24` + // Estimated: `1533` + // Minimum execution time: 7_097_000 picoseconds. + Weight::from_parts(7_419_000, 0) + .saturating_add(Weight::from_parts(0, 1533)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) + } +} diff --git a/cumulus/parachains/runtimes/people/people-rococo/src/weights/frame_system_extensions.rs b/cumulus/parachains/runtimes/people/people-rococo/src/weights/frame_system_extensions.rs index fb2b69e23e82..3f12b25540ea 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/src/weights/frame_system_extensions.rs +++ b/cumulus/parachains/runtimes/people/people-rococo/src/weights/frame_system_extensions.rs @@ -129,4 +129,18 @@ impl frame_system::ExtensionsWeightInfo for WeightInfo< .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(2)) } + /// Storage: `System::AllExtrinsicsLen` (r:1 w:1) + /// Proof: `System::AllExtrinsicsLen` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `System::BlockWeight` (r:1 w:1) + /// Proof: `System::BlockWeight` (`max_values`: Some(1), `max_size`: Some(48), added: 543, mode: `MaxEncodedLen`) + fn weight_reclaim() -> Weight { + // Proof Size summary in bytes: + // Measured: `24` + // Estimated: `1533` + // Minimum execution time: 3_687_000 picoseconds. + Weight::from_parts(6_192_000, 0) + .saturating_add(Weight::from_parts(0, 1533)) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(2)) + } } diff --git a/cumulus/parachains/runtimes/people/people-rococo/src/weights/mod.rs b/cumulus/parachains/runtimes/people/people-rococo/src/weights/mod.rs index fab3c629ab3f..81906a11fe1c 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/src/weights/mod.rs +++ b/cumulus/parachains/runtimes/people/people-rococo/src/weights/mod.rs @@ -17,6 +17,7 @@ pub mod block_weights; pub mod cumulus_pallet_parachain_system; +pub mod cumulus_pallet_weight_reclaim; pub mod cumulus_pallet_xcmp_queue; pub mod extrinsic_weights; pub mod frame_system; diff --git a/cumulus/parachains/runtimes/people/people-westend/Cargo.toml b/cumulus/parachains/runtimes/people/people-westend/Cargo.toml index 65bc8264934f..fae0fd2e3332 100644 --- a/cumulus/parachains/runtimes/people/people-westend/Cargo.toml +++ b/cumulus/parachains/runtimes/people/people-westend/Cargo.toml @@ -68,11 +68,11 @@ xcm-runtime-apis = { workspace = true } cumulus-pallet-aura-ext = { workspace = true } cumulus-pallet-parachain-system = { workspace = true } cumulus-pallet-session-benchmarking = { workspace = true } +cumulus-pallet-weight-reclaim = { workspace = true } cumulus-pallet-xcm = { workspace = true } cumulus-pallet-xcmp-queue = { workspace = true } cumulus-primitives-aura = { workspace = true } cumulus-primitives-core = { workspace = true } -cumulus-primitives-storage-weight-reclaim = { workspace = true } cumulus-primitives-utility = { workspace = true } pallet-collator-selection = { workspace = true } parachain-info = { workspace = true } @@ -89,11 +89,11 @@ std = [ "cumulus-pallet-aura-ext/std", "cumulus-pallet-parachain-system/std", "cumulus-pallet-session-benchmarking/std", + "cumulus-pallet-weight-reclaim/std", "cumulus-pallet-xcm/std", "cumulus-pallet-xcmp-queue/std", "cumulus-primitives-aura/std", "cumulus-primitives-core/std", - "cumulus-primitives-storage-weight-reclaim/std", "cumulus-primitives-utility/std", "enumflags2/std", "frame-benchmarking?/std", @@ -150,6 +150,7 @@ std = [ runtime-benchmarks = [ "cumulus-pallet-parachain-system/runtime-benchmarks", "cumulus-pallet-session-benchmarking/runtime-benchmarks", + "cumulus-pallet-weight-reclaim/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", "cumulus-primitives-core/runtime-benchmarks", "cumulus-primitives-utility/runtime-benchmarks", @@ -182,6 +183,7 @@ runtime-benchmarks = [ try-runtime = [ "cumulus-pallet-aura-ext/try-runtime", "cumulus-pallet-parachain-system/try-runtime", + "cumulus-pallet-weight-reclaim/try-runtime", "cumulus-pallet-xcm/try-runtime", "cumulus-pallet-xcmp-queue/try-runtime", "frame-executive/try-runtime", diff --git a/cumulus/parachains/runtimes/people/people-westend/src/lib.rs b/cumulus/parachains/runtimes/people/people-westend/src/lib.rs index 620ec41c071c..ee6b0db55b91 100644 --- a/cumulus/parachains/runtimes/people/people-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/people/people-westend/src/lib.rs @@ -92,17 +92,19 @@ pub type SignedBlock = generic::SignedBlock; pub type BlockId = generic::BlockId; /// The transactionExtension to the basic transaction logic. -pub type TxExtension = ( - frame_system::CheckNonZeroSender, - frame_system::CheckSpecVersion, - frame_system::CheckTxVersion, - frame_system::CheckGenesis, - frame_system::CheckEra, - frame_system::CheckNonce, - frame_system::CheckWeight, - pallet_transaction_payment::ChargeTransactionPayment, - cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim, -); +pub type TxExtension = cumulus_pallet_weight_reclaim::StorageWeightReclaim< + Runtime, + ( + frame_system::CheckNonZeroSender, + frame_system::CheckSpecVersion, + frame_system::CheckTxVersion, + frame_system::CheckGenesis, + frame_system::CheckEra, + frame_system::CheckNonce, + frame_system::CheckWeight, + pallet_transaction_payment::ChargeTransactionPayment, + ), +>; /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = @@ -195,6 +197,10 @@ impl frame_system::Config for Runtime { type MultiBlockMigrator = MultiBlockMigrations; } +impl cumulus_pallet_weight_reclaim::Config for Runtime { + type WeightInfo = weights::cumulus_pallet_weight_reclaim::WeightInfo; +} + impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. type Moment = u64; @@ -566,6 +572,7 @@ construct_runtime!( ParachainSystem: cumulus_pallet_parachain_system = 1, Timestamp: pallet_timestamp = 2, ParachainInfo: parachain_info = 3, + WeightReclaim: cumulus_pallet_weight_reclaim = 4, // Monetary stuff. Balances: pallet_balances = 10, @@ -624,6 +631,7 @@ mod benches { [pallet_xcm, PalletXcmExtrinsicsBenchmark::] [pallet_xcm_benchmarks::fungible, XcmBalances] [pallet_xcm_benchmarks::generic, XcmGeneric] + [cumulus_pallet_weight_reclaim, WeightReclaim] ); } @@ -1055,18 +1063,8 @@ impl_runtime_apis! { type XcmBalances = pallet_xcm_benchmarks::fungible::Pallet::; type XcmGeneric = pallet_xcm_benchmarks::generic::Pallet::; - let whitelist: Vec = vec![ - // Block Number - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(), - // Total Issuance - hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(), - // Execution Phase - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(), - // Event Count - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(), - // System Events - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(), - ]; + use frame_support::traits::WhitelistedStorageKeys; + let whitelist: Vec = AllPalletsWithSystem::whitelisted_storage_keys(); let mut batches = Vec::::new(); let params = (&config, &whitelist); diff --git a/cumulus/parachains/runtimes/people/people-westend/src/weights/cumulus_pallet_weight_reclaim.rs b/cumulus/parachains/runtimes/people/people-westend/src/weights/cumulus_pallet_weight_reclaim.rs new file mode 100644 index 000000000000..fd3018ec9740 --- /dev/null +++ b/cumulus/parachains/runtimes/people/people-westend/src/weights/cumulus_pallet_weight_reclaim.rs @@ -0,0 +1,67 @@ +// 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 . + +//! Autogenerated weights for `cumulus_pallet_weight_reclaim` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-12-30, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `runner-ys-ssygq-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("people-westend-dev")`, DB CACHE: 1024 + +// Executed Command: +// target/production/polkadot-parachain +// benchmark +// pallet +// --steps=50 +// --repeat=20 +// --extrinsic=* +// --wasm-execution=compiled +// --heap-pages=4096 +// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json +// --pallet=cumulus_pallet_weight_reclaim +// --chain=people-westend-dev +// --header=./cumulus/file_header.txt +// --output=./cumulus/parachains/runtimes/people/people-westend/src/weights/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `cumulus_pallet_weight_reclaim`. +pub struct WeightInfo(PhantomData); +impl cumulus_pallet_weight_reclaim::WeightInfo for WeightInfo { + /// Storage: `System::BlockWeight` (r:1 w:1) + /// Proof: `System::BlockWeight` (`max_values`: Some(1), `max_size`: Some(48), added: 543, mode: `MaxEncodedLen`) + /// Storage: `System::ExtrinsicWeightReclaimed` (r:1 w:1) + /// Proof: `System::ExtrinsicWeightReclaimed` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) + /// Storage: `System::AllExtrinsicsLen` (r:1 w:0) + /// Proof: `System::AllExtrinsicsLen` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + fn storage_weight_reclaim() -> Weight { + // Proof Size summary in bytes: + // Measured: `24` + // Estimated: `1533` + // Minimum execution time: 7_006_000 picoseconds. + Weight::from_parts(7_269_000, 0) + .saturating_add(Weight::from_parts(0, 1533)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) + } +} diff --git a/cumulus/parachains/runtimes/people/people-westend/src/weights/frame_system_extensions.rs b/cumulus/parachains/runtimes/people/people-westend/src/weights/frame_system_extensions.rs index 0a4b9e8e2681..422b8566ad08 100644 --- a/cumulus/parachains/runtimes/people/people-westend/src/weights/frame_system_extensions.rs +++ b/cumulus/parachains/runtimes/people/people-westend/src/weights/frame_system_extensions.rs @@ -129,4 +129,18 @@ impl frame_system::ExtensionsWeightInfo for WeightInfo< .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(2)) } + /// Storage: `System::AllExtrinsicsLen` (r:1 w:1) + /// Proof: `System::AllExtrinsicsLen` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `System::BlockWeight` (r:1 w:1) + /// Proof: `System::BlockWeight` (`max_values`: Some(1), `max_size`: Some(48), added: 543, mode: `MaxEncodedLen`) + fn weight_reclaim() -> Weight { + // Proof Size summary in bytes: + // Measured: `24` + // Estimated: `1533` + // Minimum execution time: 3_687_000 picoseconds. + Weight::from_parts(6_192_000, 0) + .saturating_add(Weight::from_parts(0, 1533)) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(2)) + } } diff --git a/cumulus/parachains/runtimes/people/people-westend/src/weights/mod.rs b/cumulus/parachains/runtimes/people/people-westend/src/weights/mod.rs index fab3c629ab3f..81906a11fe1c 100644 --- a/cumulus/parachains/runtimes/people/people-westend/src/weights/mod.rs +++ b/cumulus/parachains/runtimes/people/people-westend/src/weights/mod.rs @@ -17,6 +17,7 @@ pub mod block_weights; pub mod cumulus_pallet_parachain_system; +pub mod cumulus_pallet_weight_reclaim; pub mod cumulus_pallet_xcmp_queue; pub mod extrinsic_weights; pub mod frame_system; diff --git a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs index b51670c792d6..38ddf3bc1991 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs @@ -140,6 +140,7 @@ pub type TxExtension = ( frame_system::CheckNonce, frame_system::CheckWeight, pallet_asset_tx_payment::ChargeAssetTxPayment, + frame_system::WeightReclaim, ); /// Unchecked extrinsic type as expected by this runtime. @@ -1132,18 +1133,8 @@ impl_runtime_apis! { use cumulus_pallet_session_benchmarking::Pallet as SessionBench; impl cumulus_pallet_session_benchmarking::Config for Runtime {} - let whitelist: Vec = vec![ - // Block Number - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(), - // Total Issuance - hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(), - // Execution Phase - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(), - // Event Count - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(), - // System Events - hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(), - ]; + use frame_support::traits::WhitelistedStorageKeys; + let whitelist: Vec = AllPalletsWithSystem::whitelisted_storage_keys(); let mut batches = Vec::::new(); let params = (&config, &whitelist); diff --git a/cumulus/parachains/runtimes/testing/rococo-parachain/Cargo.toml b/cumulus/parachains/runtimes/testing/rococo-parachain/Cargo.toml index e8761445f161..826a2e9764fc 100644 --- a/cumulus/parachains/runtimes/testing/rococo-parachain/Cargo.toml +++ b/cumulus/parachains/runtimes/testing/rococo-parachain/Cargo.toml @@ -51,12 +51,12 @@ xcm-executor = { workspace = true } # Cumulus cumulus-pallet-aura-ext = { workspace = true } cumulus-pallet-parachain-system = { workspace = true } +cumulus-pallet-weight-reclaim = { workspace = true } cumulus-pallet-xcm = { workspace = true } cumulus-pallet-xcmp-queue = { workspace = true } cumulus-ping = { workspace = true } cumulus-primitives-aura = { workspace = true } cumulus-primitives-core = { workspace = true } -cumulus-primitives-storage-weight-reclaim = { workspace = true } cumulus-primitives-utility = { workspace = true } pallet-message-queue = { workspace = true } parachain-info = { workspace = true } @@ -72,12 +72,12 @@ std = [ "codec/std", "cumulus-pallet-aura-ext/std", "cumulus-pallet-parachain-system/std", + "cumulus-pallet-weight-reclaim/std", "cumulus-pallet-xcm/std", "cumulus-pallet-xcmp-queue/std", "cumulus-ping/std", "cumulus-primitives-aura/std", "cumulus-primitives-core/std", - "cumulus-primitives-storage-weight-reclaim/std", "cumulus-primitives-utility/std", "frame-benchmarking?/std", "frame-executive/std", @@ -117,6 +117,7 @@ std = [ ] runtime-benchmarks = [ "cumulus-pallet-parachain-system/runtime-benchmarks", + "cumulus-pallet-weight-reclaim/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", "cumulus-primitives-core/runtime-benchmarks", "cumulus-primitives-utility/runtime-benchmarks", diff --git a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs index 42556e0b493c..89cd17d5450a 100644 --- a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs @@ -226,6 +226,10 @@ impl frame_system::Config for Runtime { type MaxConsumers = frame_support::traits::ConstU32<16>; } +impl cumulus_pallet_weight_reclaim::Config for Runtime { + type WeightInfo = (); +} + impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. type Moment = u64; @@ -617,6 +621,7 @@ construct_runtime! { Timestamp: pallet_timestamp, Sudo: pallet_sudo, TransactionPayment: pallet_transaction_payment, + WeightReclaim: cumulus_pallet_weight_reclaim, ParachainSystem: cumulus_pallet_parachain_system = 20, ParachainInfo: parachain_info = 21, @@ -657,17 +662,20 @@ pub type SignedBlock = generic::SignedBlock; /// BlockId type as expected by this runtime. pub type BlockId = generic::BlockId; /// The extension to the basic transaction logic. -pub type TxExtension = ( - frame_system::CheckNonZeroSender, - frame_system::CheckSpecVersion, - frame_system::CheckTxVersion, - frame_system::CheckGenesis, - frame_system::CheckEra, - frame_system::CheckNonce, - frame_system::CheckWeight, - pallet_transaction_payment::ChargeTransactionPayment, - cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim, -); +pub type TxExtension = cumulus_pallet_weight_reclaim::StorageWeightReclaim< + Runtime, + ( + frame_system::CheckNonZeroSender, + frame_system::CheckSpecVersion, + frame_system::CheckTxVersion, + frame_system::CheckGenesis, + frame_system::CheckEra, + frame_system::CheckNonce, + frame_system::CheckWeight, + pallet_transaction_payment::ChargeTransactionPayment, + ), +>; + /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; diff --git a/cumulus/primitives/storage-weight-reclaim/src/lib.rs b/cumulus/primitives/storage-weight-reclaim/src/lib.rs index 5cbe662e2700..62ff60811904 100644 --- a/cumulus/primitives/storage-weight-reclaim/src/lib.rs +++ b/cumulus/primitives/storage-weight-reclaim/src/lib.rs @@ -100,15 +100,30 @@ pub fn get_proof_size() -> Option { (proof_size != PROOF_RECORDING_DISABLED).then_some(proof_size) } -/// Storage weight reclaim mechanism. -/// -/// This extension checks the size of the node-side storage proof -/// before and after executing a given extrinsic. The difference between -/// benchmarked and spent weight can be reclaimed. -#[derive(Encode, Decode, Clone, Eq, PartialEq, Default, TypeInfo)] -#[scale_info(skip_type_params(T))] -pub struct StorageWeightReclaim(PhantomData); +// Encapsulate into a mod so that macro generated code doesn't trigger a warning about deprecated +// usage. +#[allow(deprecated)] +mod allow_deprecated { + use super::*; + + /// Storage weight reclaim mechanism. + /// + /// This extension checks the size of the node-side storage proof + /// before and after executing a given extrinsic. The difference between + /// benchmarked and spent weight can be reclaimed. + #[deprecated(note = "This extension doesn't provide accurate reclaim for storage intensive \ + transaction extension pipeline; it ignores the validation and preparation of extensions prior \ + to itself and ignores the post dispatch logic for extensions subsequent to itself, it also + doesn't provide weight information. \ + Use `StorageWeightReclaim` in the `cumulus-pallet-weight-reclaim` crate")] + #[derive(Encode, Decode, Clone, Eq, PartialEq, Default, TypeInfo)] + #[scale_info(skip_type_params(T))] + pub struct StorageWeightReclaim(pub(super) PhantomData); +} +#[allow(deprecated)] +pub use allow_deprecated::StorageWeightReclaim; +#[allow(deprecated)] impl StorageWeightReclaim { /// Create a new `StorageWeightReclaim` instance. pub fn new() -> Self { @@ -116,6 +131,7 @@ impl StorageWeightReclaim { } } +#[allow(deprecated)] impl core::fmt::Debug for StorageWeightReclaim { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> Result<(), core::fmt::Error> { let _ = write!(f, "StorageWeightReclaim"); @@ -123,6 +139,7 @@ impl core::fmt::Debug for StorageWeightReclaim { } } +#[allow(deprecated)] impl TransactionExtension for StorageWeightReclaim where T::RuntimeCall: Dispatchable, diff --git a/cumulus/primitives/storage-weight-reclaim/src/tests.rs b/cumulus/primitives/storage-weight-reclaim/src/tests.rs index ab83762cc0db..379b39afee0c 100644 --- a/cumulus/primitives/storage-weight-reclaim/src/tests.rs +++ b/cumulus/primitives/storage-weight-reclaim/src/tests.rs @@ -74,6 +74,7 @@ fn get_storage_weight() -> PerDispatchClass { } #[test] +#[allow(deprecated)] fn basic_refund() { // The real cost will be 100 bytes of storage size let mut test_ext = setup_test_externalities(&[0, 100]); @@ -109,6 +110,7 @@ fn basic_refund() { } #[test] +#[allow(deprecated)] fn underestimating_refund() { // We fixed a bug where `pre dispatch info weight > consumed weight > post info weight` // resulted in error. @@ -149,6 +151,7 @@ fn underestimating_refund() { } #[test] +#[allow(deprecated)] fn sets_to_node_storage_proof_if_higher() { // The storage proof reported by the proof recorder is higher than what is stored on // the runtime side. @@ -240,6 +243,7 @@ fn sets_to_node_storage_proof_if_higher() { } #[test] +#[allow(deprecated)] fn does_nothing_without_extension() { let mut test_ext = new_test_ext(); @@ -274,6 +278,7 @@ fn does_nothing_without_extension() { } #[test] +#[allow(deprecated)] fn negative_refund_is_added_to_weight() { let mut test_ext = setup_test_externalities(&[100, 300]); @@ -310,6 +315,7 @@ fn negative_refund_is_added_to_weight() { } #[test] +#[allow(deprecated)] fn test_zero_proof_size() { let mut test_ext = setup_test_externalities(&[0, 0]); @@ -340,6 +346,7 @@ fn test_zero_proof_size() { } #[test] +#[allow(deprecated)] fn test_larger_pre_dispatch_proof_size() { let mut test_ext = setup_test_externalities(&[300, 100]); @@ -374,6 +381,7 @@ fn test_larger_pre_dispatch_proof_size() { } #[test] +#[allow(deprecated)] fn test_incorporates_check_weight_unspent_weight() { let mut test_ext = setup_test_externalities(&[100, 300]); @@ -415,6 +423,7 @@ fn test_incorporates_check_weight_unspent_weight() { } #[test] +#[allow(deprecated)] fn test_incorporates_check_weight_unspent_weight_on_negative() { let mut test_ext = setup_test_externalities(&[100, 300]); @@ -456,6 +465,7 @@ fn test_incorporates_check_weight_unspent_weight_on_negative() { } #[test] +#[allow(deprecated)] fn test_nothing_relcaimed() { let mut test_ext = setup_test_externalities(&[0, 100]); @@ -505,6 +515,7 @@ fn test_nothing_relcaimed() { } #[test] +#[allow(deprecated)] fn test_incorporates_check_weight_unspent_weight_reverse_order() { let mut test_ext = setup_test_externalities(&[100, 300]); @@ -548,6 +559,7 @@ fn test_incorporates_check_weight_unspent_weight_reverse_order() { } #[test] +#[allow(deprecated)] fn test_incorporates_check_weight_unspent_weight_on_negative_reverse_order() { let mut test_ext = setup_test_externalities(&[100, 300]); @@ -616,6 +628,7 @@ fn storage_size_disabled_reported_correctly() { } #[test] +#[allow(deprecated)] fn test_reclaim_helper() { let mut test_ext = setup_test_externalities(&[1000, 1300, 1800]); @@ -635,6 +648,7 @@ fn test_reclaim_helper() { } #[test] +#[allow(deprecated)] fn test_reclaim_helper_does_not_reclaim_negative() { // Benchmarked weight does not change at all let mut test_ext = setup_test_externalities(&[1000, 1300]); @@ -669,6 +683,7 @@ fn get_benched_weight() -> Weight { /// Just here for doc purposes fn do_work() {} +#[allow(deprecated)] #[docify::export_content(simple_reclaimer_example)] fn reclaim_with_weight_meter() { let mut remaining_weight_meter = WeightMeter::with_limit(Weight::from_parts(10, 10)); diff --git a/cumulus/test/client/Cargo.toml b/cumulus/test/client/Cargo.toml index 2c72ca98f35a..f64ee832ace3 100644 --- a/cumulus/test/client/Cargo.toml +++ b/cumulus/test/client/Cargo.toml @@ -39,16 +39,17 @@ polkadot-parachain-primitives = { workspace = true, default-features = true } polkadot-primitives = { workspace = true, default-features = true } # Cumulus +cumulus-pallet-weight-reclaim = { workspace = true, default-features = true } cumulus-primitives-core = { workspace = true, default-features = true } cumulus-primitives-parachain-inherent = { workspace = true, default-features = true } cumulus-primitives-proof-size-hostfunction = { workspace = true, default-features = true } -cumulus-primitives-storage-weight-reclaim = { workspace = true, default-features = true } cumulus-test-relay-sproof-builder = { workspace = true, default-features = true } cumulus-test-runtime = { workspace = true } cumulus-test-service = { workspace = true } [features] runtime-benchmarks = [ + "cumulus-pallet-weight-reclaim/runtime-benchmarks", "cumulus-primitives-core/runtime-benchmarks", "cumulus-test-service/runtime-benchmarks", "frame-system/runtime-benchmarks", diff --git a/cumulus/test/client/src/lib.rs b/cumulus/test/client/src/lib.rs index 26cf02b3dea9..7861a42372a6 100644 --- a/cumulus/test/client/src/lib.rs +++ b/cumulus/test/client/src/lib.rs @@ -143,7 +143,6 @@ pub fn generate_extrinsic_with_pair( frame_system::CheckNonce::::from(nonce), frame_system::CheckWeight::::new(), pallet_transaction_payment::ChargeTransactionPayment::::from(tip), - cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim::::new(), ) .into(); @@ -152,7 +151,7 @@ pub fn generate_extrinsic_with_pair( let raw_payload = SignedPayload::from_raw( function.clone(), tx_ext.clone(), - ((), VERSION.spec_version, genesis_block, current_block_hash, (), (), (), ()), + ((), VERSION.spec_version, genesis_block, current_block_hash, (), (), ()), ); let signature = raw_payload.using_encoded(|e| origin.sign(e)); diff --git a/cumulus/test/runtime/Cargo.toml b/cumulus/test/runtime/Cargo.toml index 150838e5e96e..4cc4f483c028 100644 --- a/cumulus/test/runtime/Cargo.toml +++ b/cumulus/test/runtime/Cargo.toml @@ -44,9 +44,9 @@ sp-version = { workspace = true } # Cumulus cumulus-pallet-aura-ext = { workspace = true } cumulus-pallet-parachain-system = { workspace = true } +cumulus-pallet-weight-reclaim = { workspace = true } cumulus-primitives-aura = { workspace = true } cumulus-primitives-core = { workspace = true } -cumulus-primitives-storage-weight-reclaim = { workspace = true } pallet-collator-selection = { workspace = true } parachain-info = { workspace = true } @@ -59,9 +59,9 @@ std = [ "codec/std", "cumulus-pallet-aura-ext/std", "cumulus-pallet-parachain-system/std", + "cumulus-pallet-weight-reclaim/std", "cumulus-primitives-aura/std", "cumulus-primitives-core/std", - "cumulus-primitives-storage-weight-reclaim/std", "frame-executive/std", "frame-support/std", "frame-system-rpc-runtime-api/std", diff --git a/cumulus/test/runtime/src/lib.rs b/cumulus/test/runtime/src/lib.rs index 4abc10276af1..01ce3427c1f1 100644 --- a/cumulus/test/runtime/src/lib.rs +++ b/cumulus/test/runtime/src/lib.rs @@ -232,6 +232,10 @@ impl frame_system::Config for Runtime { type MaxConsumers = frame_support::traits::ConstU32<16>; } +impl cumulus_pallet_weight_reclaim::Config for Runtime { + type WeightInfo = (); +} + parameter_types! { pub const MinimumPeriod: u64 = SLOT_DURATION / 2; pub const PotId: PalletId = PalletId(*b"PotStake"); @@ -347,6 +351,7 @@ construct_runtime! { Glutton: pallet_glutton, Aura: pallet_aura, AuraExt: cumulus_pallet_aura_ext, + WeightReclaim: cumulus_pallet_weight_reclaim, } } @@ -377,16 +382,18 @@ pub type SignedBlock = generic::SignedBlock; /// BlockId type as expected by this runtime. pub type BlockId = generic::BlockId; /// The extension to the basic transaction logic. -pub type TxExtension = ( - frame_system::CheckNonZeroSender, - frame_system::CheckSpecVersion, - frame_system::CheckGenesis, - frame_system::CheckEra, - frame_system::CheckNonce, - frame_system::CheckWeight, - pallet_transaction_payment::ChargeTransactionPayment, - cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim, -); +pub type TxExtension = cumulus_pallet_weight_reclaim::StorageWeightReclaim< + Runtime, + ( + frame_system::CheckNonZeroSender, + frame_system::CheckSpecVersion, + frame_system::CheckGenesis, + frame_system::CheckEra, + frame_system::CheckNonce, + frame_system::CheckWeight, + pallet_transaction_payment::ChargeTransactionPayment, + ), +>; /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = generic::UncheckedExtrinsic; diff --git a/cumulus/test/service/Cargo.toml b/cumulus/test/service/Cargo.toml index b3d92444c7d1..794007532621 100644 --- a/cumulus/test/service/Cargo.toml +++ b/cumulus/test/service/Cargo.toml @@ -81,8 +81,8 @@ cumulus-client-parachain-inherent = { workspace = true, default-features = true cumulus-client-pov-recovery = { workspace = true, default-features = true } cumulus-client-service = { workspace = true, default-features = true } cumulus-pallet-parachain-system = { workspace = true } +cumulus-pallet-weight-reclaim = { workspace = true, default-features = true } cumulus-primitives-core = { workspace = true, default-features = true } -cumulus-primitives-storage-weight-reclaim = { workspace = true, default-features = true } cumulus-relay-chain-inprocess-interface = { workspace = true, default-features = true } cumulus-relay-chain-interface = { workspace = true, default-features = true } cumulus-relay-chain-minimal-node = { workspace = true, default-features = true } @@ -107,6 +107,7 @@ substrate-test-utils = { workspace = true } [features] runtime-benchmarks = [ "cumulus-pallet-parachain-system/runtime-benchmarks", + "cumulus-pallet-weight-reclaim/runtime-benchmarks", "cumulus-primitives-core/runtime-benchmarks", "cumulus-test-client/runtime-benchmarks", "frame-system/runtime-benchmarks", diff --git a/cumulus/test/service/src/lib.rs b/cumulus/test/service/src/lib.rs index 2c13d20333a7..f3f04cbb6383 100644 --- a/cumulus/test/service/src/lib.rs +++ b/cumulus/test/service/src/lib.rs @@ -976,13 +976,12 @@ pub fn construct_extrinsic( frame_system::CheckNonce::::from(nonce), frame_system::CheckWeight::::new(), pallet_transaction_payment::ChargeTransactionPayment::::from(tip), - cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim::::new(), ) .into(); let raw_payload = runtime::SignedPayload::from_raw( function.clone(), tx_ext.clone(), - ((), runtime::VERSION.spec_version, genesis_block, current_block_hash, (), (), (), ()), + ((), runtime::VERSION.spec_version, genesis_block, current_block_hash, (), (), ()), ); let signature = raw_payload.using_encoded(|e| caller.sign(e)); runtime::UncheckedExtrinsic::new_signed( diff --git a/docs/RELEASE.md b/docs/RELEASE.md index bea367411359..677cb5465b67 100644 --- a/docs/RELEASE.md +++ b/docs/RELEASE.md @@ -14,7 +14,11 @@ Merging to it is restricted to [Backports](#backports). We are releasing multiple different things from this repository in one release, but we don't want to use the same version for everything. Thus, in the following we explain the versioning story for the crates, node and Westend & -Rococo. To easily refer to a release, it shall be named by its date in the form `stableYYMMDD`. +Rococo. + +To easily refer to a release, it shall be named by its date in the form `stableYYMM`. Patches to stable releases are +tagged in the form of `stableYYMM-PATCH`, with `PATCH` ranging from 1 to 99. For example, the fourth patch to +`stable2409` would be `stable2409-4`. ## Crate diff --git a/docs/sdk/Cargo.toml b/docs/sdk/Cargo.toml index a856e94f42b5..f526c07796ea 100644 --- a/docs/sdk/Cargo.toml +++ b/docs/sdk/Cargo.toml @@ -68,8 +68,8 @@ substrate-wasm-builder = { workspace = true, default-features = true } cumulus-client-service = { workspace = true, default-features = true } cumulus-pallet-aura-ext = { workspace = true, default-features = true } cumulus-pallet-parachain-system = { workspace = true, default-features = true } +cumulus-pallet-weight-reclaim = { workspace = true, default-features = true } cumulus-primitives-proof-size-hostfunction = { workspace = true, default-features = true } -cumulus-primitives-storage-weight-reclaim = { workspace = true, default-features = true } parachain-info = { workspace = true, default-features = true } # Omni Node diff --git a/docs/sdk/src/guides/enable_pov_reclaim.rs b/docs/sdk/src/guides/enable_pov_reclaim.rs index cb6960b3df4e..71abeacd18c8 100644 --- a/docs/sdk/src/guides/enable_pov_reclaim.rs +++ b/docs/sdk/src/guides/enable_pov_reclaim.rs @@ -62,8 +62,10 @@ //! //! In your runtime, you will find a list of TransactionExtensions. //! To enable the reclaiming, -//! add [`StorageWeightReclaim`](cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim) -//! to that list. For maximum efficiency, make sure that `StorageWeightReclaim` is last in the list. +//! set [`StorageWeightReclaim`](cumulus_pallet_weight_reclaim::StorageWeightReclaim) +//! as a warpper of that list. +//! It is necessary that this extension wraps all the other transaction extensions in order to catch +//! the whole PoV size of the transactions. //! The extension will check the size of the storage proof before and after an extrinsic execution. //! It reclaims the difference between the calculated size and the benchmarked size. #![doc = docify::embed!("../../templates/parachain/runtime/src/lib.rs", template_signed_extra)] diff --git a/docs/sdk/src/reference_docs/transaction_extensions.rs b/docs/sdk/src/reference_docs/transaction_extensions.rs index 0f8198e8372d..fe213458b25c 100644 --- a/docs/sdk/src/reference_docs/transaction_extensions.rs +++ b/docs/sdk/src/reference_docs/transaction_extensions.rs @@ -47,9 +47,11 @@ //! to include the so-called metadata hash. This is required by chains to support the generic //! Ledger application and other similar offline wallets. //! -//! - [`StorageWeightReclaim`](cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim): A -//! transaction extension for parachains that reclaims unused storage weight after executing a -//! transaction. +//! - [`WeightReclaim`](frame_system::WeightReclaim): A transaction extension for the relay chain +//! that reclaims unused weight after executing a transaction. +//! +//! - [`StorageWeightReclaim`](cumulus_pallet_weight_reclaim::StorageWeightReclaim): A transaction +//! extension for parachains that reclaims unused storage weight after executing a transaction. //! //! For more information about these extensions, follow the link to the type documentation. //! diff --git a/polkadot/node/service/src/benchmarking.rs b/polkadot/node/service/src/benchmarking.rs index 0cf16edc03cc..5b814a22d2f8 100644 --- a/polkadot/node/service/src/benchmarking.rs +++ b/polkadot/node/service/src/benchmarking.rs @@ -155,6 +155,7 @@ fn westend_sign_call( frame_system::CheckWeight::::new(), pallet_transaction_payment::ChargeTransactionPayment::::from(0), frame_metadata_hash_extension::CheckMetadataHash::::new(false), + frame_system::WeightReclaim::::new(), ) .into(); @@ -171,6 +172,7 @@ fn westend_sign_call( (), (), None, + (), ), ); @@ -210,6 +212,7 @@ fn rococo_sign_call( frame_system::CheckWeight::::new(), pallet_transaction_payment::ChargeTransactionPayment::::from(0), frame_metadata_hash_extension::CheckMetadataHash::::new(false), + frame_system::WeightReclaim::::new(), ) .into(); @@ -226,6 +229,7 @@ fn rococo_sign_call( (), (), None, + (), ), ); diff --git a/polkadot/node/test/service/src/lib.rs b/polkadot/node/test/service/src/lib.rs index f34bb62a7cf0..75fd0d9af301 100644 --- a/polkadot/node/test/service/src/lib.rs +++ b/polkadot/node/test/service/src/lib.rs @@ -423,6 +423,7 @@ pub fn construct_extrinsic( frame_system::CheckNonce::::from(nonce), frame_system::CheckWeight::::new(), pallet_transaction_payment::ChargeTransactionPayment::::from(tip), + frame_system::WeightReclaim::::new(), ) .into(); let raw_payload = SignedPayload::from_raw( @@ -437,6 +438,7 @@ pub fn construct_extrinsic( (), (), (), + (), ), ); let signature = raw_payload.using_encoded(|e| caller.sign(e)); diff --git a/polkadot/primitives/src/v8/mod.rs b/polkadot/primitives/src/v8/mod.rs index fdcb9fe8fb7e..7fc4c5b5c3f1 100644 --- a/polkadot/primitives/src/v8/mod.rs +++ b/polkadot/primitives/src/v8/mod.rs @@ -1900,7 +1900,7 @@ pub struct SessionInfo { /// participating in parachain consensus. See /// [`max_validators`](https://github.com/paritytech/polkadot/blob/a52dca2be7840b23c19c153cf7e110b1e3e475f8/runtime/parachains/src/configuration.rs#L148). /// - /// `SessionInfo::validators` will be limited to to `max_validators` when set. + /// `SessionInfo::validators` will be limited to `max_validators` when set. pub validators: IndexedVec, /// Validators' authority discovery keys for the session in canonical ordering. /// diff --git a/polkadot/roadmap/implementers-guide/src/architecture.md b/polkadot/roadmap/implementers-guide/src/architecture.md index b75270662005..e2be92e4cddb 100644 --- a/polkadot/roadmap/implementers-guide/src/architecture.md +++ b/polkadot/roadmap/implementers-guide/src/architecture.md @@ -93,7 +93,7 @@ Runtime logic is divided up into Modules and APIs. Modules encapsulate particula consist of storage, routines, and entry-points. Routines are invoked by entry points, by other modules, upon block initialization or closing. Routines can read and alter the storage of the module. Entry-points are the means by which new information is introduced to a module and can limit the origins (user, root, parachain) that they accept being -called by. Each block in the blockchain contains a set of Extrinsics. Each extrinsic targets a a specific entry point to +called by. Each block in the blockchain contains a set of Extrinsics. Each extrinsic targets a specific entry point to trigger and which data should be passed to it. Runtime APIs provide a means for Node-side behavior to extract meaningful information from the state of a single fork. diff --git a/polkadot/roadmap/implementers-guide/src/protocol-approval.md b/polkadot/roadmap/implementers-guide/src/protocol-approval.md index b6aa16646ad2..25d4fa5dadae 100644 --- a/polkadot/roadmap/implementers-guide/src/protocol-approval.md +++ b/polkadot/roadmap/implementers-guide/src/protocol-approval.md @@ -84,7 +84,7 @@ slashing risk for validator operators. In future, we shall determine which among the several hardening techniques best benefits the network as a whole. We could provide a multi-process multi-machine architecture for validators, perhaps even reminiscent of GNUNet, or perhaps -more resembling smart HSM tooling. We might instead design a system that more resembled full systems, like like Cosmos' +more resembling smart HSM tooling. We might instead design a system that more resembled full systems, like Cosmos' sentry nodes. In either case, approval assignments might be handled by a slightly hardened machine, but not necessarily nearly as hardened as approval votes, but approval votes machines must similarly run foreign WASM code, which increases their risk, so assignments being separate sounds helpful. diff --git a/polkadot/roadmap/implementers-guide/src/protocol-validator-disabling.md b/polkadot/roadmap/implementers-guide/src/protocol-validator-disabling.md index 9fd44c00fa0a..c2861b4035e7 100644 --- a/polkadot/roadmap/implementers-guide/src/protocol-validator-disabling.md +++ b/polkadot/roadmap/implementers-guide/src/protocol-validator-disabling.md @@ -111,7 +111,7 @@ checking (% for 30-ish malicious in a row). There are also censorship or liveness issues if backing is suddenly dominated by malicious nodes but in general even if some honest blocks get backed liveness should be preserved. -> **Note:** It is worth noting that is is fundamentally a defense in depth strategy because if we assume disputes are +> **Note:** It is worth noting that is fundamentally a defense in depth strategy because if we assume disputes are > perfect it should not be a real concern. In reality disputes and determinism are difficult to get right, and > non-determinism and happen so defense in depth is crucial when handling those subsystems. diff --git a/polkadot/roadmap/implementers-guide/src/runtime/session_info.md b/polkadot/roadmap/implementers-guide/src/runtime/session_info.md index fa7f55c4f0b4..daf7e5c7fd80 100644 --- a/polkadot/roadmap/implementers-guide/src/runtime/session_info.md +++ b/polkadot/roadmap/implementers-guide/src/runtime/session_info.md @@ -16,7 +16,7 @@ struct SessionInfo { /// in parachain consensus. See /// [`max_validators`](https://github.com/paritytech/polkadot/blob/a52dca2be7840b23c19c153cf7e110b1e3e475f8/runtime/parachains/src/configuration.rs#L148). /// - /// `SessionInfo::validators` will be limited to to `max_validators` when set. + /// `SessionInfo::validators` will be limited to `max_validators` when set. validators: Vec, /// Validators' authority discovery keys for the session in canonical ordering. /// diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 4034f8bc1431..cab4394eb5a8 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -674,6 +674,7 @@ where frame_system::CheckWeight::::new(), pallet_transaction_payment::ChargeTransactionPayment::::from(tip), frame_metadata_hash_extension::CheckMetadataHash::new(true), + frame_system::WeightReclaim::::new(), ) .into(); let raw_payload = SignedPayload::new(call, tx_ext) @@ -1617,6 +1618,7 @@ pub type TxExtension = ( frame_system::CheckWeight, pallet_transaction_payment::ChargeTransactionPayment, frame_metadata_hash_extension::CheckMetadataHash, + frame_system::WeightReclaim, ); /// Unchecked extrinsic type as expected by this runtime. diff --git a/polkadot/runtime/rococo/src/weights/frame_system_extensions.rs b/polkadot/runtime/rococo/src/weights/frame_system_extensions.rs index 99dac1ba75f0..88596a37cc01 100644 --- a/polkadot/runtime/rococo/src/weights/frame_system_extensions.rs +++ b/polkadot/runtime/rococo/src/weights/frame_system_extensions.rs @@ -17,25 +17,23 @@ //! Autogenerated weights for `frame_system_extensions` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 -//! DATE: 2024-02-29, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-12-30, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner-bn-ce5rx-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! HOSTNAME: `runner-ys-ssygq-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("rococo-dev")`, DB CACHE: 1024 // Executed Command: -// ./target/production/polkadot +// target/production/polkadot // benchmark // pallet -// --chain=rococo-dev // --steps=50 // --repeat=20 -// --no-storage-info -// --no-median-slopes -// --no-min-squares -// --pallet=frame_system_extensions // --extrinsic=* -// --execution=wasm // --wasm-execution=compiled +// --heap-pages=4096 +// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json +// --pallet=frame_system_extensions +// --chain=rococo-dev // --header=./polkadot/file_header.txt // --output=./polkadot/runtime/rococo/src/weights/ @@ -50,45 +48,36 @@ use core::marker::PhantomData; /// Weight functions for `frame_system_extensions`. pub struct WeightInfo(PhantomData); impl frame_system::ExtensionsWeightInfo for WeightInfo { - /// Storage: `System::BlockHash` (r:1 w:0) - /// Proof: `System::BlockHash` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `MaxEncodedLen`) fn check_genesis() -> Weight { // Proof Size summary in bytes: - // Measured: `54` - // Estimated: `3509` - // Minimum execution time: 3_262_000 picoseconds. - Weight::from_parts(3_497_000, 0) - .saturating_add(Weight::from_parts(0, 3509)) - .saturating_add(T::DbWeight::get().reads(1)) + // Measured: `30` + // Estimated: `0` + // Minimum execution time: 3_528_000 picoseconds. + Weight::from_parts(3_657_000, 0) + .saturating_add(Weight::from_parts(0, 0)) } - /// Storage: `System::BlockHash` (r:1 w:0) - /// Proof: `System::BlockHash` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `MaxEncodedLen`) fn check_mortality_mortal_transaction() -> Weight { // Proof Size summary in bytes: - // Measured: `92` - // Estimated: `3509` - // Minimum execution time: 5_416_000 picoseconds. - Weight::from_parts(5_690_000, 0) - .saturating_add(Weight::from_parts(0, 3509)) - .saturating_add(T::DbWeight::get().reads(1)) + // Measured: `68` + // Estimated: `0` + // Minimum execution time: 6_456_000 picoseconds. + Weight::from_parts(6_706_000, 0) + .saturating_add(Weight::from_parts(0, 0)) } - /// Storage: `System::BlockHash` (r:1 w:0) - /// Proof: `System::BlockHash` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `MaxEncodedLen`) fn check_mortality_immortal_transaction() -> Weight { // Proof Size summary in bytes: - // Measured: `92` - // Estimated: `3509` - // Minimum execution time: 5_416_000 picoseconds. - Weight::from_parts(5_690_000, 0) - .saturating_add(Weight::from_parts(0, 3509)) - .saturating_add(T::DbWeight::get().reads(1)) + // Measured: `68` + // Estimated: `0` + // Minimum execution time: 6_210_000 picoseconds. + Weight::from_parts(6_581_000, 0) + .saturating_add(Weight::from_parts(0, 0)) } fn check_non_zero_sender() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 471_000 picoseconds. - Weight::from_parts(552_000, 0) + // Minimum execution time: 529_000 picoseconds. + Weight::from_parts(561_000, 0) .saturating_add(Weight::from_parts(0, 0)) } /// Storage: `System::Account` (r:1 w:1) @@ -97,8 +86,8 @@ impl frame_system::ExtensionsWeightInfo for WeightInfo< // Proof Size summary in bytes: // Measured: `101` // Estimated: `3593` - // Minimum execution time: 4_847_000 picoseconds. - Weight::from_parts(5_091_000, 0) + // Minimum execution time: 6_935_000 picoseconds. + Weight::from_parts(7_264_000, 0) .saturating_add(Weight::from_parts(0, 3593)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -107,28 +96,32 @@ impl frame_system::ExtensionsWeightInfo for WeightInfo< // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 388_000 picoseconds. - Weight::from_parts(421_000, 0) + // Minimum execution time: 452_000 picoseconds. + Weight::from_parts(474_000, 0) .saturating_add(Weight::from_parts(0, 0)) } fn check_tx_version() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 378_000 picoseconds. - Weight::from_parts(440_000, 0) + // Minimum execution time: 422_000 picoseconds. + Weight::from_parts(460_000, 0) .saturating_add(Weight::from_parts(0, 0)) } - /// Storage: `System::AllExtrinsicsLen` (r:1 w:1) - /// Proof: `System::AllExtrinsicsLen` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) fn check_weight() -> Weight { // Proof Size summary in bytes: - // Measured: `24` - // Estimated: `1489` - // Minimum execution time: 3_402_000 picoseconds. - Weight::from_parts(3_627_000, 0) - .saturating_add(Weight::from_parts(0, 1489)) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 3_632_000 picoseconds. + Weight::from_parts(3_784_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + fn weight_reclaim() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_209_000 picoseconds. + Weight::from_parts(2_335_000, 0) + .saturating_add(Weight::from_parts(0, 0)) } } diff --git a/polkadot/runtime/test-runtime/src/lib.rs b/polkadot/runtime/test-runtime/src/lib.rs index d4031f7ac57a..82564d5c278c 100644 --- a/polkadot/runtime/test-runtime/src/lib.rs +++ b/polkadot/runtime/test-runtime/src/lib.rs @@ -443,6 +443,7 @@ where frame_system::CheckNonce::::from(nonce), frame_system::CheckWeight::::new(), pallet_transaction_payment::ChargeTransactionPayment::::from(tip), + frame_system::WeightReclaim::::new(), ) .into(); let raw_payload = SignedPayload::new(call, tx_ext) @@ -834,6 +835,7 @@ pub type TxExtension = ( frame_system::CheckNonce, frame_system::CheckWeight, pallet_transaction_payment::ChargeTransactionPayment, + frame_system::WeightReclaim, ); /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index cd8eb4d2505a..166f3fc42eef 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -923,6 +923,7 @@ where frame_system::CheckWeight::::new(), pallet_transaction_payment::ChargeTransactionPayment::::from(tip), frame_metadata_hash_extension::CheckMetadataHash::::new(true), + frame_system::WeightReclaim::::new(), ) .into(); let raw_payload = SignedPayload::new(call, tx_ext) @@ -1814,6 +1815,7 @@ pub type TxExtension = ( frame_system::CheckWeight, pallet_transaction_payment::ChargeTransactionPayment, frame_metadata_hash_extension::CheckMetadataHash, + frame_system::WeightReclaim, ); parameter_types! { diff --git a/polkadot/runtime/westend/src/weights/frame_system_extensions.rs b/polkadot/runtime/westend/src/weights/frame_system_extensions.rs index 048f23fbcb91..75f4f6d00b56 100644 --- a/polkadot/runtime/westend/src/weights/frame_system_extensions.rs +++ b/polkadot/runtime/westend/src/weights/frame_system_extensions.rs @@ -17,24 +17,25 @@ //! Autogenerated weights for `frame_system_extensions` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 -//! DATE: 2024-09-12, STEPS: `2`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-12-30, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `gleipnir`, CPU: `AMD Ryzen 9 7900X 12-Core Processor` +//! HOSTNAME: `runner-ys-ssygq-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("westend-dev")`, DB CACHE: 1024 // Executed Command: -// ./target/debug/polkadot +// target/production/polkadot // benchmark // pallet -// --steps=2 -// --repeat=2 +// --steps=50 +// --repeat=20 // --extrinsic=* // --wasm-execution=compiled // --heap-pages=4096 -// --pallet=frame-system-extensions +// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json +// --pallet=frame_system_extensions // --chain=westend-dev -// --output=./polkadot/runtime/westend/src/weights/ // --header=./polkadot/file_header.txt +// --output=./polkadot/runtime/westend/src/weights/ #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -47,45 +48,36 @@ use core::marker::PhantomData; /// Weight functions for `frame_system_extensions`. pub struct WeightInfo(PhantomData); impl frame_system::ExtensionsWeightInfo for WeightInfo { - /// Storage: `System::BlockHash` (r:1 w:0) - /// Proof: `System::BlockHash` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `MaxEncodedLen`) fn check_genesis() -> Weight { // Proof Size summary in bytes: - // Measured: `54` - // Estimated: `3509` - // Minimum execution time: 75_764_000 picoseconds. - Weight::from_parts(85_402_000, 0) - .saturating_add(Weight::from_parts(0, 3509)) - .saturating_add(T::DbWeight::get().reads(1)) + // Measured: `30` + // Estimated: `0` + // Minimum execution time: 3_357_000 picoseconds. + Weight::from_parts(3_484_000, 0) + .saturating_add(Weight::from_parts(0, 0)) } - /// Storage: `System::BlockHash` (r:1 w:0) - /// Proof: `System::BlockHash` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `MaxEncodedLen`) fn check_mortality_mortal_transaction() -> Weight { // Proof Size summary in bytes: - // Measured: `92` - // Estimated: `3509` - // Minimum execution time: 118_233_000 picoseconds. - Weight::from_parts(126_539_000, 0) - .saturating_add(Weight::from_parts(0, 3509)) - .saturating_add(T::DbWeight::get().reads(1)) + // Measured: `68` + // Estimated: `0` + // Minimum execution time: 6_242_000 picoseconds. + Weight::from_parts(6_566_000, 0) + .saturating_add(Weight::from_parts(0, 0)) } - /// Storage: `System::BlockHash` (r:1 w:0) - /// Proof: `System::BlockHash` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `MaxEncodedLen`) fn check_mortality_immortal_transaction() -> Weight { // Proof Size summary in bytes: - // Measured: `92` - // Estimated: `3509` - // Minimum execution time: 118_233_000 picoseconds. - Weight::from_parts(126_539_000, 0) - .saturating_add(Weight::from_parts(0, 3509)) - .saturating_add(T::DbWeight::get().reads(1)) + // Measured: `68` + // Estimated: `0` + // Minimum execution time: 6_268_000 picoseconds. + Weight::from_parts(6_631_000, 0) + .saturating_add(Weight::from_parts(0, 0)) } fn check_non_zero_sender() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 7_885_000 picoseconds. - Weight::from_parts(12_784_000, 0) + // Minimum execution time: 567_000 picoseconds. + Weight::from_parts(617_000, 0) .saturating_add(Weight::from_parts(0, 0)) } /// Storage: `System::Account` (r:1 w:1) @@ -94,8 +86,8 @@ impl frame_system::ExtensionsWeightInfo for WeightInfo< // Proof Size summary in bytes: // Measured: `101` // Estimated: `3593` - // Minimum execution time: 104_237_000 picoseconds. - Weight::from_parts(110_910_000, 0) + // Minimum execution time: 6_990_000 picoseconds. + Weight::from_parts(7_343_000, 0) .saturating_add(Weight::from_parts(0, 3593)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) @@ -104,28 +96,32 @@ impl frame_system::ExtensionsWeightInfo for WeightInfo< // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 6_141_000 picoseconds. - Weight::from_parts(11_502_000, 0) + // Minimum execution time: 422_000 picoseconds. + Weight::from_parts(475_000, 0) .saturating_add(Weight::from_parts(0, 0)) } fn check_tx_version() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 6_192_000 picoseconds. - Weight::from_parts(11_481_000, 0) + // Minimum execution time: 434_000 picoseconds. + Weight::from_parts(519_000, 0) .saturating_add(Weight::from_parts(0, 0)) } - /// Storage: `System::AllExtrinsicsLen` (r:1 w:1) - /// Proof: `System::AllExtrinsicsLen` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) fn check_weight() -> Weight { // Proof Size summary in bytes: - // Measured: `24` - // Estimated: `1489` - // Minimum execution time: 87_616_000 picoseconds. - Weight::from_parts(93_607_000, 0) - .saturating_add(Weight::from_parts(0, 1489)) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 3_524_000 picoseconds. + Weight::from_parts(3_706_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + fn weight_reclaim() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_216_000 picoseconds. + Weight::from_parts(2_337_000, 0) + .saturating_add(Weight::from_parts(0, 0)) } } diff --git a/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs b/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs index 26ea226313f0..6ebf6476f7e5 100644 --- a/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs +++ b/polkadot/xcm/xcm-builder/src/tests/pay/mock.rs @@ -37,6 +37,7 @@ pub type TxExtension = ( frame_system::CheckMortality, frame_system::CheckNonce, frame_system::CheckWeight, + frame_system::WeightReclaim, ); pub type Address = sp_runtime::MultiAddress; pub type UncheckedExtrinsic = diff --git a/polkadot/xcm/xcm-runtime-apis/tests/mock.rs b/polkadot/xcm/xcm-runtime-apis/tests/mock.rs index fb5d1ae7c0e5..56a77094f177 100644 --- a/polkadot/xcm/xcm-runtime-apis/tests/mock.rs +++ b/polkadot/xcm/xcm-runtime-apis/tests/mock.rs @@ -60,7 +60,8 @@ construct_runtime! { } } -pub type TxExtension = (frame_system::CheckWeight,); +pub type TxExtension = + (frame_system::CheckWeight, frame_system::WeightReclaim); // we only use the hash type from this, so using the mock should be fine. pub(crate) type Extrinsic = sp_runtime::generic::UncheckedExtrinsic< diff --git a/polkadot/zombienet_tests/functional/0014-chunk-fetching-network-compatibility.toml b/polkadot/zombienet_tests/functional/0014-chunk-fetching-network-compatibility.toml index 881abab64fd0..874b8a09bb24 100644 --- a/polkadot/zombienet_tests/functional/0014-chunk-fetching-network-compatibility.toml +++ b/polkadot/zombienet_tests/functional/0014-chunk-fetching-network-compatibility.toml @@ -42,7 +42,8 @@ chain = "glutton-westend-local-{{id}}" [parachains.collator] name = "collator" - image = "{{CUMULUS_IMAGE}}" + # Use an old image that does not send out v2 receipts, as the old validators will still check the collator signatures. + image = "docker.io/paritypr/polkadot-parachain-debug:master-bde0bbe5" args = ["-lparachain=debug"] {% endfor %} diff --git a/prdoc/pr_6140.prdoc b/prdoc/pr_6140.prdoc new file mode 100644 index 000000000000..7e2bd3802cd7 --- /dev/null +++ b/prdoc/pr_6140.prdoc @@ -0,0 +1,95 @@ +title: Accurate weight reclaim with frame_system::WeightReclaim and cumulus `StorageWeightReclaim` transaction extensions + +doc: + - audience: Runtime Dev + description: | + Since the introduction of transaction extension, the transaction extension weight is no longer part of base extrinsic weight. As a consequence some weight of transaction extensions are missed when calculating post dispatch weight and reclaiming unused block weight. + + For solo chains, in order to reclaim the weight accurately `frame_system::WeightReclaim` transaction extension must be used at the end of the transaction extension pipeline. + + For para chains `StorageWeightReclaim` in `cumulus-primitives-storage-weight-reclaim` is deprecated. + A new transaction extension `StorageWeightReclaim` in `cumulus-pallet-weight-reclaim` is introduced. + `StorageWeightReclaim` is meant to be used as a wrapping of the whole transaction extension pipeline, and will take into account all proof size accurately. + + The new wrapping transaction extension is used like this: + ```rust + /// The TransactionExtension to the basic transaction logic. + pub type TxExtension = cumulus_pallet_weight_reclaim::StorageWeightReclaim< + Runtime, + ( + frame_system::CheckNonZeroSender, + frame_system::CheckSpecVersion, + frame_system::CheckTxVersion, + frame_system::CheckGenesis, + frame_system::CheckEra, + frame_system::CheckNonce, + pallet_transaction_payment::ChargeTransactionPayment, + BridgeRejectObsoleteHeadersAndMessages, + (bridge_to_rococo_config::OnBridgeHubWestendRefundBridgeHubRococoMessages,), + frame_metadata_hash_extension::CheckMetadataHash, + frame_system::CheckWeight, + ), + >; + ``` + + NOTE: prior to transaction extension, `StorageWeightReclaim` also missed the some proof size used by other transaction extension prior to itself. This is also fixed by the wrapping `StorageWeightReclaim`. + +crates: +- name: cumulus-primitives-storage-weight-reclaim + bump: minor +- name: sp-runtime + bump: patch +- name: polkadot-sdk + bump: minor +- name: asset-hub-rococo-runtime + bump: major +- name: asset-hub-westend-runtime + bump: major +- name: bridge-hub-rococo-runtime + bump: major +- name: bridge-hub-westend-runtime + bump: major +- name: collectives-westend-runtime + bump: major +- name: coretime-rococo-runtime + bump: major +- name: coretime-westend-runtime + bump: major +- name: people-rococo-runtime + bump: major +- name: people-westend-runtime + bump: major +- name: contracts-rococo-runtime + bump: major +- name: frame-support + bump: minor +- name: frame-executive + bump: patch +- name: frame-system + bump: major +- name: staging-xcm-builder + bump: patch +- name: xcm-runtime-apis + bump: patch +- name: cumulus-pallet-weight-reclaim + bump: major +- name: polkadot-service + bump: major +- name: westend-runtime + bump: major +- name: frame-metadata-hash-extension + bump: patch +- name: frame-system-benchmarking + bump: major +- name: polkadot-sdk-frame + bump: major +- name: rococo-runtime + bump: major +- name: cumulus-pov-validator + bump: patch +- name: penpal-runtime + bump: major +- name: glutton-westend-runtime + bump: major +- name: rococo-parachain-runtime + bump: major diff --git a/prdoc/pr_6988.prdoc b/prdoc/pr_6988.prdoc new file mode 100644 index 000000000000..18f70f9fd97f --- /dev/null +++ b/prdoc/pr_6988.prdoc @@ -0,0 +1,5 @@ +doc: [] + +crates: + - name: polkadot + bump: none \ No newline at end of file diff --git a/prdoc/pr_7028.prdoc b/prdoc/pr_7028.prdoc new file mode 100644 index 000000000000..ead918fc2e00 --- /dev/null +++ b/prdoc/pr_7028.prdoc @@ -0,0 +1,25 @@ +title: 'Fix implication order in implementation of `TransactionExtension` for tuple' +doc: +- audience: + - Runtime Dev + - Runtime User + description: |- + Before this PR, the implications were different in the pipeline `(A, B, C)` and `((A, B), C)`. + This PR fixes this behavior and make nested tuple transparant, the implication order of tuple of + tuple is now the same as in a single tuple. + + For runtime users this mean that the implication can be breaking depending on the pipeline used + in the runtime. + + For runtime developers this breaks usage of `TransactionExtension::validate`. + When calling `TransactionExtension::validate` the implication must now implement `Implication` + trait, you can use `TxBaseImplication` to wrap the type and use it as the base implication. + E.g. instead of `&(extension_version, call),` you can write `&TxBaseImplication((extension_version, call))`. + +crates: +- name: sp-runtime + bump: major +- name: pallet-skip-feeless-payment + bump: major +- name: frame-system + bump: major diff --git a/prdoc/pr_7030.prdoc b/prdoc/pr_7030.prdoc new file mode 100644 index 000000000000..3b1f7be558d8 --- /dev/null +++ b/prdoc/pr_7030.prdoc @@ -0,0 +1,24 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: "[core-fellowship] Add permissionless import_member" + +doc: + - audience: [Runtime Dev, Runtime User] + description: | + Changes: + - Add call `import_member` to the core-fellowship pallet. + - Move common logic between `import` and `import_member` into `do_import`. + + This is a minor change as to not impact UI and downstream integration. + + ## `import_member` + + Can be used to induct an arbitrary collective member and is callable by any signed origin. Pays no fees upon success. + This is useful in the case that members did not induct themselves and are idling on their rank. + +crates: +- name: pallet-core-fellowship + bump: major +- name: collectives-westend-runtime + bump: patch diff --git a/prdoc/pr_7050.prdoc b/prdoc/pr_7050.prdoc new file mode 100644 index 000000000000..da9dd808033d --- /dev/null +++ b/prdoc/pr_7050.prdoc @@ -0,0 +1,11 @@ +title: Avoid incomplete block import pipeline with full verifying import queue +doc: +- audience: Node Dev + description: |- + When warp syncing a node using the equivocation checking verifier, we now properly set the fork_choice rule. + Affected are mostly nodes that are derived from the parachain template. Omni-node is not affected. + + The prevents the error `ClientImport("Incomplete block import pipeline.")` after state sync. +crates: +- name: cumulus-client-consensus-aura + bump: patch diff --git a/substrate/bin/node/cli/src/service.rs b/substrate/bin/node/cli/src/service.rs index 5f6806c235f6..e531097dbb5e 100644 --- a/substrate/bin/node/cli/src/service.rs +++ b/substrate/bin/node/cli/src/service.rs @@ -138,6 +138,7 @@ pub fn create_extrinsic( >::from(tip, None), ), frame_metadata_hash_extension::CheckMetadataHash::new(false), + frame_system::WeightReclaim::::new(), ); let raw_payload = kitchensink_runtime::SignedPayload::from_raw( @@ -153,6 +154,7 @@ pub fn create_extrinsic( (), (), None, + (), ), ); let signature = raw_payload.using_encoded(|e| sender.sign(e)); @@ -1060,6 +1062,7 @@ mod tests { let tx_payment = pallet_skip_feeless_payment::SkipCheckIfFeeless::from( pallet_asset_conversion_tx_payment::ChargeAssetTxPayment::from(0, None), ); + let weight_reclaim = frame_system::WeightReclaim::new(); let metadata_hash = frame_metadata_hash_extension::CheckMetadataHash::new(false); let tx_ext: TxExtension = ( check_non_zero_sender, @@ -1071,6 +1074,7 @@ mod tests { check_weight, tx_payment, metadata_hash, + weight_reclaim, ); let raw_payload = SignedPayload::from_raw( function, @@ -1085,6 +1089,7 @@ mod tests { (), (), None, + (), ), ); let signature = raw_payload.using_encoded(|payload| signer.sign(payload)); diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 3d507cc15521..359733a0a0b6 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -1533,6 +1533,7 @@ where ), ), frame_metadata_hash_extension::CheckMetadataHash::new(false), + frame_system::WeightReclaim::::new(), ); let raw_payload = SignedPayload::new(call, tx_ext) @@ -2675,6 +2676,7 @@ pub type TxExtension = ( pallet_asset_conversion_tx_payment::ChargeAssetTxPayment, >, frame_metadata_hash_extension::CheckMetadataHash, + frame_system::WeightReclaim, ); #[derive(Clone, PartialEq, Eq, Debug)] @@ -2696,6 +2698,7 @@ impl EthExtra for EthExtraImpl { pallet_asset_conversion_tx_payment::ChargeAssetTxPayment::::from(tip, None) .into(), frame_metadata_hash_extension::CheckMetadataHash::::new(false), + frame_system::WeightReclaim::::new(), ) } } diff --git a/substrate/bin/node/testing/src/keyring.rs b/substrate/bin/node/testing/src/keyring.rs index e5b0299f01a8..08d6ad6dcc35 100644 --- a/substrate/bin/node/testing/src/keyring.rs +++ b/substrate/bin/node/testing/src/keyring.rs @@ -86,6 +86,7 @@ pub fn tx_ext(nonce: Nonce, extra_fee: Balance) -> TxExtension { pallet_asset_conversion_tx_payment::ChargeAssetTxPayment::from(extra_fee, None), ), frame_metadata_hash_extension::CheckMetadataHash::new(false), + frame_system::WeightReclaim::new(), ) } diff --git a/substrate/client/network/README.md b/substrate/client/network/README.md index f4031fbd3085..4336bb78533c 100644 --- a/substrate/client/network/README.md +++ b/substrate/client/network/README.md @@ -245,7 +245,7 @@ only downloads finalized authority set changes. GRANDPA keeps justifications for each finalized authority set change. Each change is signed by the authorities from the previous set. By downloading and verifying these signed hand-offs starting from genesis, we arrive at a recent header faster than downloading full header chain. Each `WarpSyncRequest` contains a block -hash to a to start collecting proofs from. `WarpSyncResponse` contains a sequence of block headers and +hash to start collecting proofs from. `WarpSyncResponse` contains a sequence of block headers and justifications. The proof downloader checks the justifications and continues requesting proofs from the last header hash, until it arrives at some recent header. @@ -261,7 +261,7 @@ data. I.e. it is unable to serve bock bodies and headers other than the most rec nodes have block history available, a background sync process is started that downloads all the missing blocks. It is run in parallel with the keep-up sync and does not interfere with downloading of the recent blocks. During this download we also import GRANDPA justifications for blocks with authority set changes, so that -the warp-synced node has all the data to serve for other nodes nodes that might want to sync from it with +the warp-synced node has all the data to serve for other nodes that might want to sync from it with any method. # Usage diff --git a/substrate/frame/bounties/README.md b/substrate/frame/bounties/README.md index 232334cb1edd..2293ae161e28 100644 --- a/substrate/frame/bounties/README.md +++ b/substrate/frame/bounties/README.md @@ -19,7 +19,7 @@ curator or once the bounty is active or payout is pending, resulting in the slas curator's deposit. This pallet may opt into using a [`ChildBountyManager`] that enables bounties to be split into -sub-bounties, as children of anh established bounty (called the parent in the context of it's +sub-bounties, as children of an established bounty (called the parent in the context of it's children). > NOTE: The parent bounty cannot be closed if it has a non-zero number of it has active child diff --git a/substrate/frame/bounties/src/lib.rs b/substrate/frame/bounties/src/lib.rs index d9accc5061cf..9b6e3c06e914 100644 --- a/substrate/frame/bounties/src/lib.rs +++ b/substrate/frame/bounties/src/lib.rs @@ -36,7 +36,7 @@ //! curator's deposit. //! //! This pallet may opt into using a [`ChildBountyManager`] that enables bounties to be split into -//! sub-bounties, as children of anh established bounty (called the parent in the context of it's +//! sub-bounties, as children of an established bounty (called the parent in the context of it's //! children). //! //! > NOTE: The parent bounty cannot be closed if it has a non-zero number of it has active child diff --git a/substrate/frame/core-fellowship/src/benchmarking.rs b/substrate/frame/core-fellowship/src/benchmarking.rs index adb8a4a091b8..ac0d489953c1 100644 --- a/substrate/frame/core-fellowship/src/benchmarking.rs +++ b/substrate/frame/core-fellowship/src/benchmarking.rs @@ -50,6 +50,7 @@ mod benchmarks { for _ in 0..rank { T::Members::promote(&member)?; } + #[allow(deprecated)] CoreFellowship::::import(RawOrigin::Signed(member.clone()).into())?; Ok(member) } @@ -260,6 +261,23 @@ mod benchmarks { Ok(()) } + #[benchmark] + fn import_member() -> Result<(), BenchmarkError> { + let member = account("member", 0, SEED); + let sender = account("sender", 0, SEED); + + T::Members::induct(&member)?; + T::Members::promote(&member)?; + + assert!(!Member::::contains_key(&member)); + + #[extrinsic_call] + _(RawOrigin::Signed(sender), member.clone()); + + assert!(Member::::contains_key(&member)); + Ok(()) + } + #[benchmark] fn approve() -> Result<(), BenchmarkError> { let member = make_member::(1)?; diff --git a/substrate/frame/core-fellowship/src/lib.rs b/substrate/frame/core-fellowship/src/lib.rs index c61447e36280..22ba63b26161 100644 --- a/substrate/frame/core-fellowship/src/lib.rs +++ b/substrate/frame/core-fellowship/src/lib.rs @@ -21,6 +21,7 @@ //! This only handles members of non-zero rank. //! //! # Process Flow +//! //! - Begin with a call to `induct`, where some privileged origin (perhaps a pre-existing member of //! `rank > 1`) is able to make a candidate from an account and introduce it to be tracked in this //! pallet in order to allow evidence to be submitted and promotion voted on. @@ -36,8 +37,9 @@ //! `bump` to demote the candidate by one rank. //! - If a candidate fails to be promoted to a member within the `offboard_timeout` period, then //! anyone may call `bump` to remove the account's candidacy. -//! - Pre-existing members may call `import` to have their rank recognised and be inducted into this -//! pallet (to gain a salary and allow for eventual promotion). +//! - Pre-existing members may call `import_member` on themselves (formerly `import`) to have their +//! rank recognised and be inducted into this pallet (to gain a salary and allow for eventual +//! promotion). //! - If, externally to this pallet, a member or candidate has their rank removed completely, then //! `offboard` may be called to remove them entirely from this pallet. //! @@ -585,28 +587,44 @@ pub mod pallet { Ok(if replaced { Pays::Yes } else { Pays::No }.into()) } - /// Introduce an already-ranked individual of the collective into this pallet. The rank may - /// still be zero. + /// Introduce an already-ranked individual of the collective into this pallet. /// - /// This resets `last_proof` to the current block and `last_promotion` will be set to zero, - /// thereby delaying any automatic demotion but allowing immediate promotion. + /// The rank may still be zero. This resets `last_proof` to the current block and + /// `last_promotion` will be set to zero, thereby delaying any automatic demotion but + /// allowing immediate promotion. /// /// - `origin`: A signed origin of a ranked, but not tracked, account. #[pallet::weight(T::WeightInfo::import())] #[pallet::call_index(8)] + #[deprecated = "Use `import_member` instead"] + #[allow(deprecated)] // Otherwise FRAME will complain about using something deprecated. pub fn import(origin: OriginFor) -> DispatchResultWithPostInfo { let who = ensure_signed(origin)?; - ensure!(!Member::::contains_key(&who), Error::::AlreadyInducted); - let rank = T::Members::rank_of(&who).ok_or(Error::::Unranked)?; + Self::do_import(who)?; - let now = frame_system::Pallet::::block_number(); - Member::::insert( - &who, - MemberStatus { is_active: true, last_promotion: 0u32.into(), last_proof: now }, - ); - Self::deposit_event(Event::::Imported { who, rank }); + Ok(Pays::No.into()) // Successful imports are free + } - Ok(Pays::No.into()) + /// Introduce an already-ranked individual of the collective into this pallet. + /// + /// The rank may still be zero. Can be called by anyone on any collective member - including + /// the sender. + /// + /// This resets `last_proof` to the current block and `last_promotion` will be set to zero, + /// thereby delaying any automatic demotion but allowing immediate promotion. + /// + /// - `origin`: A signed origin of a ranked, but not tracked, account. + /// - `who`: The account ID of the collective member to be inducted. + #[pallet::weight(T::WeightInfo::set_partial_params())] + #[pallet::call_index(11)] + pub fn import_member( + origin: OriginFor, + who: T::AccountId, + ) -> DispatchResultWithPostInfo { + ensure_signed(origin)?; + Self::do_import(who)?; + + Ok(Pays::No.into()) // Successful imports are free } /// Set the parameters partially. @@ -661,6 +679,24 @@ pub mod pallet { } } } + + /// Import `who` into the core-fellowship pallet. + /// + /// `who` must be a member of the collective but *not* already imported. + pub(crate) fn do_import(who: T::AccountId) -> DispatchResult { + ensure!(!Member::::contains_key(&who), Error::::AlreadyInducted); + let rank = T::Members::rank_of(&who).ok_or(Error::::Unranked)?; + + let now = frame_system::Pallet::::block_number(); + Member::::insert( + &who, + MemberStatus { is_active: true, last_promotion: 0u32.into(), last_proof: now }, + ); + Self::deposit_event(Event::::Imported { who, rank }); + + Ok(()) + } + /// Convert a rank into a `0..RANK_COUNT` index suitable for the arrays in Params. /// /// Rank 1 becomes index 0, rank `RANK_COUNT` becomes index `RANK_COUNT - 1`. Any rank not @@ -766,6 +802,7 @@ impl, I: 'static> pallet_ranked_collective::BenchmarkSetup<::AccountId> for Pallet { fn ensure_member(who: &::AccountId) { + #[allow(deprecated)] Self::import(frame_system::RawOrigin::Signed(who.clone()).into()).unwrap(); } } diff --git a/substrate/frame/core-fellowship/src/tests/integration.rs b/substrate/frame/core-fellowship/src/tests/integration.rs index 7a48ed9783e7..b2149336547d 100644 --- a/substrate/frame/core-fellowship/src/tests/integration.rs +++ b/substrate/frame/core-fellowship/src/tests/integration.rs @@ -17,8 +17,10 @@ //! Integration test together with the ranked-collective pallet. +#![allow(deprecated)] + use frame_support::{ - assert_noop, assert_ok, derive_impl, hypothetically, ord_parameter_types, + assert_noop, assert_ok, derive_impl, hypothetically, hypothetically_ok, ord_parameter_types, pallet_prelude::Weight, parameter_types, traits::{ConstU16, EitherOf, IsInVec, MapSuccess, NoOpPoll, TryMapSuccess}, @@ -170,6 +172,37 @@ fn evidence(e: u32) -> Evidence { .expect("Static length matches") } +#[test] +fn import_simple_works() { + new_test_ext().execute_with(|| { + for i in 0u16..9 { + let acc = i as u64; + + // Does not work yet + assert_noop!(CoreFellowship::import(signed(acc)), Error::::Unranked); + assert_noop!( + CoreFellowship::import_member(signed(acc + 1), acc), + Error::::Unranked + ); + + assert_ok!(Club::add_member(RuntimeOrigin::root(), acc)); + promote_n_times(acc, i); + + hypothetically_ok!(CoreFellowship::import(signed(acc))); + hypothetically_ok!(CoreFellowship::import_member(signed(acc), acc)); + // Works from other accounts + assert_ok!(CoreFellowship::import_member(signed(acc + 1), acc)); + + // Does not work again + assert_noop!(CoreFellowship::import(signed(acc)), Error::::AlreadyInducted); + assert_noop!( + CoreFellowship::import_member(signed(acc + 1), acc), + Error::::AlreadyInducted + ); + } + }); +} + #[test] fn swap_simple_works() { new_test_ext().execute_with(|| { @@ -178,7 +211,8 @@ fn swap_simple_works() { assert_ok!(Club::add_member(RuntimeOrigin::root(), acc)); promote_n_times(acc, i); - assert_ok!(CoreFellowship::import(signed(acc))); + hypothetically_ok!(CoreFellowship::import(signed(acc))); + assert_ok!(CoreFellowship::import_member(signed(acc), acc)); // Swapping normally works: assert_ok!(Club::exchange_member(RuntimeOrigin::root(), acc, acc + 10)); diff --git a/substrate/frame/core-fellowship/src/tests/unit.rs b/substrate/frame/core-fellowship/src/tests/unit.rs index 11d1ea9fe5b7..f4418ed439d0 100644 --- a/substrate/frame/core-fellowship/src/tests/unit.rs +++ b/substrate/frame/core-fellowship/src/tests/unit.rs @@ -17,6 +17,8 @@ //! The crate's tests. +#![allow(deprecated)] + use std::collections::BTreeMap; use core::cell::RefCell; @@ -222,6 +224,66 @@ fn set_partial_params_works() { }); } +#[test] +fn import_member_works() { + new_test_ext().execute_with(|| { + assert_noop!(CoreFellowship::import_member(signed(0), 0), Error::::Unranked); + assert_noop!(CoreFellowship::import(signed(0)), Error::::Unranked); + + // Make induction work: + set_rank(0, 1); + assert!(!Member::::contains_key(0), "not yet imported"); + + // `import_member` can be used to induct ourselves: + hypothetically!({ + assert_ok!(CoreFellowship::import_member(signed(0), 0)); + assert!(Member::::contains_key(0), "got imported"); + + // Twice does not work: + assert_noop!( + CoreFellowship::import_member(signed(0), 0), + Error::::AlreadyInducted + ); + assert_noop!(CoreFellowship::import(signed(0)), Error::::AlreadyInducted); + }); + + // But we could have also used `import`: + hypothetically!({ + assert_ok!(CoreFellowship::import(signed(0))); + assert!(Member::::contains_key(0), "got imported"); + + // Twice does not work: + assert_noop!( + CoreFellowship::import_member(signed(0), 0), + Error::::AlreadyInducted + ); + assert_noop!(CoreFellowship::import(signed(0)), Error::::AlreadyInducted); + }); + }); +} + +#[test] +fn import_member_same_as_import() { + new_test_ext().execute_with(|| { + for rank in 0..=9 { + set_rank(0, rank); + + let import_root = hypothetically!({ + assert_ok!(CoreFellowship::import(signed(0))); + sp_io::storage::root(sp_runtime::StateVersion::V1) + }); + + let import_member_root = hypothetically!({ + assert_ok!(CoreFellowship::import_member(signed(1), 0)); + sp_io::storage::root(sp_runtime::StateVersion::V1) + }); + + // `import` and `import_member` do exactly the same thing. + assert_eq!(import_root, import_member_root); + } + }); +} + #[test] fn induct_works() { new_test_ext().execute_with(|| { diff --git a/substrate/frame/core-fellowship/src/weights.rs b/substrate/frame/core-fellowship/src/weights.rs index 9bca8cb56094..e6381c854d34 100644 --- a/substrate/frame/core-fellowship/src/weights.rs +++ b/substrate/frame/core-fellowship/src/weights.rs @@ -61,6 +61,7 @@ pub trait WeightInfo { fn promote_fast(r: u32, ) -> Weight; fn offboard() -> Weight; fn import() -> Weight; + fn import_member() -> Weight; fn approve() -> Weight; fn submit_evidence() -> Weight; } @@ -76,7 +77,7 @@ impl WeightInfo for SubstrateWeight { // Estimated: `0` // Minimum execution time: 6_652_000 picoseconds. Weight::from_parts(7_082_000, 0) - .saturating_add(T::DbWeight::get().writes(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: `CoreFellowship::Params` (r:1 w:1) /// Proof: `CoreFellowship::Params` (`max_values`: Some(1), `max_size`: Some(368), added: 863, mode: `MaxEncodedLen`) @@ -86,8 +87,8 @@ impl WeightInfo for SubstrateWeight { // Estimated: `1853` // Minimum execution time: 12_485_000 picoseconds. Weight::from_parts(12_784_000, 1853) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: `CoreFellowship::Member` (r:1 w:1) /// Proof: `CoreFellowship::Member` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) @@ -109,8 +110,8 @@ impl WeightInfo for SubstrateWeight { // Estimated: `19894` // Minimum execution time: 61_243_000 picoseconds. Weight::from_parts(63_033_000, 19894) - .saturating_add(T::DbWeight::get().reads(6_u64)) - .saturating_add(T::DbWeight::get().writes(6_u64)) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) } /// Storage: `CoreFellowship::Member` (r:1 w:1) /// Proof: `CoreFellowship::Member` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) @@ -132,8 +133,8 @@ impl WeightInfo for SubstrateWeight { // Estimated: `19894` // Minimum execution time: 65_063_000 picoseconds. Weight::from_parts(67_047_000, 19894) - .saturating_add(T::DbWeight::get().reads(6_u64)) - .saturating_add(T::DbWeight::get().writes(6_u64)) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) } /// Storage: `RankedCollective::Members` (r:1 w:0) /// Proof: `RankedCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) @@ -145,8 +146,8 @@ impl WeightInfo for SubstrateWeight { // Estimated: `3514` // Minimum execution time: 21_924_000 picoseconds. Weight::from_parts(22_691_000, 3514) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: `CoreFellowship::Member` (r:1 w:1) /// Proof: `CoreFellowship::Member` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) @@ -164,8 +165,8 @@ impl WeightInfo for SubstrateWeight { // Estimated: `3514` // Minimum execution time: 24_720_000 picoseconds. Weight::from_parts(25_580_000, 3514) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(5_u64)) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(5_u64)) } /// Storage: `RankedCollective::Members` (r:1 w:1) /// Proof: `RankedCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) @@ -187,8 +188,8 @@ impl WeightInfo for SubstrateWeight { // Estimated: `19894` // Minimum execution time: 58_481_000 picoseconds. Weight::from_parts(59_510_000, 19894) - .saturating_add(T::DbWeight::get().reads(5_u64)) - .saturating_add(T::DbWeight::get().writes(6_u64)) + .saturating_add(RocksDbWeight::get().reads(5_u64)) + .saturating_add(RocksDbWeight::get().writes(6_u64)) } /// Storage: `RankedCollective::Members` (r:1 w:1) /// Proof: `RankedCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) @@ -211,10 +212,10 @@ impl WeightInfo for SubstrateWeight { Weight::from_parts(42_220_685, 19894) // Standard Error: 18_061 .saturating_add(Weight::from_parts(13_858_309, 0).saturating_mul(r.into())) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(r.into()))) - .saturating_add(T::DbWeight::get().writes(3_u64)) - .saturating_add(T::DbWeight::get().writes((3_u64).saturating_mul(r.into()))) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(r.into()))) + .saturating_add(RocksDbWeight::get().writes(3_u64)) + .saturating_add(RocksDbWeight::get().writes((3_u64).saturating_mul(r.into()))) .saturating_add(Weight::from_parts(0, 2489).saturating_mul(r.into())) } /// Storage: `RankedCollective::Members` (r:1 w:0) @@ -229,8 +230,8 @@ impl WeightInfo for SubstrateWeight { // Estimated: `3514` // Minimum execution time: 17_492_000 picoseconds. Weight::from_parts(18_324_000, 3514) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) } /// Storage: `CoreFellowship::Member` (r:1 w:1) /// Proof: `CoreFellowship::Member` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) @@ -242,8 +243,18 @@ impl WeightInfo for SubstrateWeight { // Estimated: `3514` // Minimum execution time: 16_534_000 picoseconds. Weight::from_parts(17_046_000, 3514) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } + fn import_member() -> Weight { + // Proof Size summary in bytes: + // Measured: `285` + // Estimated: `3514` + // Minimum execution time: 23_239_000 picoseconds. + Weight::from_parts(23_684_000, 0) + .saturating_add(Weight::from_parts(0, 3514)) + .saturating_add(RocksDbWeight::get().reads(2)) + .saturating_add(RocksDbWeight::get().writes(1)) } /// Storage: `RankedCollective::Members` (r:1 w:0) /// Proof: `RankedCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) @@ -257,8 +268,8 @@ impl WeightInfo for SubstrateWeight { // Estimated: `19894` // Minimum execution time: 42_264_000 picoseconds. Weight::from_parts(43_281_000, 19894) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) } /// Storage: `CoreFellowship::Member` (r:1 w:0) /// Proof: `CoreFellowship::Member` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) @@ -270,8 +281,8 @@ impl WeightInfo for SubstrateWeight { // Estimated: `19894` // Minimum execution time: 25_461_000 picoseconds. Weight::from_parts(26_014_000, 19894) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } } @@ -454,6 +465,16 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } + fn import_member() -> Weight { + // Proof Size summary in bytes: + // Measured: `285` + // Estimated: `3514` + // Minimum execution time: 23_239_000 picoseconds. + Weight::from_parts(23_684_000, 0) + .saturating_add(Weight::from_parts(0, 3514)) + .saturating_add(RocksDbWeight::get().reads(2)) + .saturating_add(RocksDbWeight::get().writes(1)) + } /// Storage: `RankedCollective::Members` (r:1 w:0) /// Proof: `RankedCollective::Members` (`max_values`: None, `max_size`: Some(42), added: 2517, mode: `MaxEncodedLen`) /// Storage: `CoreFellowship::Member` (r:1 w:1) diff --git a/substrate/frame/democracy/README.md b/substrate/frame/democracy/README.md index bbc5f1c65586..d9d21e624477 100644 --- a/substrate/frame/democracy/README.md +++ b/substrate/frame/democracy/README.md @@ -96,7 +96,7 @@ This call can only be made by the `CancellationOrigin`. This call can only be made by the `ExternalOrigin`. -- `external_propose` - Schedules a proposal to become a referendum once it is is legal +- `external_propose` - Schedules a proposal to become a referendum once it is legal for an externally proposed referendum. #### External Majority Origin diff --git a/substrate/frame/democracy/src/lib.rs b/substrate/frame/democracy/src/lib.rs index 27bc36a756e4..2c662fbad26a 100644 --- a/substrate/frame/democracy/src/lib.rs +++ b/substrate/frame/democracy/src/lib.rs @@ -113,7 +113,7 @@ //! //! This call can only be made by the `ExternalOrigin`. //! -//! - `external_propose` - Schedules a proposal to become a referendum once it is is legal for an +//! - `external_propose` - Schedules a proposal to become a referendum once it is legal for an //! externally proposed referendum. //! //! #### External Majority Origin diff --git a/substrate/frame/executive/src/tests.rs b/substrate/frame/executive/src/tests.rs index 3841b010325b..882d875f3d80 100644 --- a/substrate/frame/executive/src/tests.rs +++ b/substrate/frame/executive/src/tests.rs @@ -335,6 +335,9 @@ impl frame_system::ExtensionsWeightInfo for MockExtensionsWeights { fn check_weight() -> Weight { Weight::from_parts(10, 0) } + fn weight_reclaim() -> Weight { + Weight::zero() + } } #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] @@ -452,6 +455,7 @@ type TxExtension = ( frame_system::CheckNonce, frame_system::CheckWeight, pallet_transaction_payment::ChargeTransactionPayment, + frame_system::WeightReclaim, ); type UncheckedXt = sp_runtime::generic::UncheckedExtrinsic< u64, @@ -560,6 +564,7 @@ fn tx_ext(nonce: u64, fee: Balance) -> TxExtension { frame_system::CheckNonce::from(nonce), frame_system::CheckWeight::new(), pallet_transaction_payment::ChargeTransactionPayment::from(fee), + frame_system::WeightReclaim::new(), ) .into() } diff --git a/substrate/frame/metadata-hash-extension/src/tests.rs b/substrate/frame/metadata-hash-extension/src/tests.rs index 11a3345ee15c..7a6966f46290 100644 --- a/substrate/frame/metadata-hash-extension/src/tests.rs +++ b/substrate/frame/metadata-hash-extension/src/tests.rs @@ -144,6 +144,7 @@ mod docs { // Add the `CheckMetadataHash` extension. // The position in this list is not important, so we could also add it to beginning. frame_metadata_hash_extension::CheckMetadataHash, + frame_system::WeightReclaim, ); /// In your runtime this will be your real address type. diff --git a/substrate/frame/recovery/README.md b/substrate/frame/recovery/README.md index 7e2dd7a23619..fdaef5784fdb 100644 --- a/substrate/frame/recovery/README.md +++ b/substrate/frame/recovery/README.md @@ -67,7 +67,7 @@ permissionless. However, the recovery deposit is an economic deterrent that should disincentivize would-be attackers from trying to maliciously recover accounts. -The recovery deposit can always be claimed by the account which is trying to +The recovery deposit can always be claimed by the account which is trying to be recovered. In the case of a malicious recovery attempt, the account owner who still has access to their account can claim the deposit and essentially punish the malicious user. diff --git a/substrate/frame/recovery/src/lib.rs b/substrate/frame/recovery/src/lib.rs index d8f3c33fbea9..4de1919cdc33 100644 --- a/substrate/frame/recovery/src/lib.rs +++ b/substrate/frame/recovery/src/lib.rs @@ -80,7 +80,7 @@ //! should disincentivize would-be attackers from trying to maliciously recover //! accounts. //! -//! The recovery deposit can always be claimed by the account which is trying to +//! The recovery deposit can always be claimed by the account which is trying //! to be recovered. In the case of a malicious recovery attempt, the account //! owner who still has access to their account can claim the deposit and //! essentially punish the malicious user. diff --git a/substrate/frame/revive/rpc/examples/js/bun.lockb b/substrate/frame/revive/rpc/examples/js/bun.lockb index e800d6d4d2d9..6d6cb9e66998 100755 Binary files a/substrate/frame/revive/rpc/examples/js/bun.lockb and b/substrate/frame/revive/rpc/examples/js/bun.lockb differ diff --git a/substrate/frame/revive/rpc/examples/js/contracts/Flipper.sol b/substrate/frame/revive/rpc/examples/js/contracts/Flipper.sol index 36681ae1be93..51aaafcae428 100644 --- a/substrate/frame/revive/rpc/examples/js/contracts/Flipper.sol +++ b/substrate/frame/revive/rpc/examples/js/contracts/Flipper.sol @@ -14,22 +14,22 @@ contract Flipper { } } -// // FlipperCaller - Interacts with the Flipper contract -// contract FlipperCaller { -// // Address of the Flipper contract -// address public flipperAddress; -// -// // Constructor to initialize Flipper's address -// constructor(address _flipperAddress) { -// flipperAddress = _flipperAddress; -// } -// -// function callFlip() external { -// Flipper(flipperAddress).flip(); -// } -// -// function callGetValue() external view returns (bool) { -// return Flipper(flipperAddress).getValue(); -// } -// } -// +// FlipperCaller - Interacts with the Flipper contract +contract FlipperCaller { + // Address of the Flipper contract + address public flipperAddress; + + // Constructor to initialize Flipper's address + constructor(address _flipperAddress) { + flipperAddress = _flipperAddress; + } + + function callFlip() external { + Flipper(flipperAddress).flip(); + } + + function callGetValue() external view returns (bool) { + return Flipper(flipperAddress).getValue(); + } +} + diff --git a/substrate/frame/revive/rpc/examples/js/package.json b/substrate/frame/revive/rpc/examples/js/package.json index 11d742b2b978..f2c4b8d78093 100644 --- a/substrate/frame/revive/rpc/examples/js/package.json +++ b/substrate/frame/revive/rpc/examples/js/package.json @@ -9,14 +9,14 @@ "preview": "vite preview" }, "dependencies": { - "@parity/revive": "^0.0.8", - "ethers": "^6.13.4", + "@parity/revive": "^0.0.9", + "ethers": "^6.13.5", "solc": "^0.8.28", - "viem": "^2.21.55" + "viem": "^2.22.4" }, "devDependencies": { "prettier": "^3.4.2", - "@types/bun": "^1.1.14", + "@types/bun": "^1.1.15", "typescript": "^5.7.2", "vite": "^5.4.11" } diff --git a/substrate/frame/revive/rpc/examples/js/src/lib.ts b/substrate/frame/revive/rpc/examples/js/src/lib.ts index e1f0e780d95b..1470f492e34d 100644 --- a/substrate/frame/revive/rpc/examples/js/src/lib.ts +++ b/substrate/frame/revive/rpc/examples/js/src/lib.ts @@ -50,7 +50,6 @@ if (geth) { child.unref() await new Promise((resolve) => setTimeout(resolve, 500)) } - const rpcUrl = proxy ? 'http://localhost:8080' : westend diff --git a/substrate/frame/revive/rpc/examples/js/src/piggy-bank.ts b/substrate/frame/revive/rpc/examples/js/src/piggy-bank.ts index 8289ac8b76e3..4983a6f3b301 100644 --- a/substrate/frame/revive/rpc/examples/js/src/piggy-bank.ts +++ b/substrate/frame/revive/rpc/examples/js/src/piggy-bank.ts @@ -4,7 +4,7 @@ import { parseEther } from 'viem' const hash = await walletClient.deployContract({ abi: PiggyBankAbi, - bytecode: getByteCode('piggyBank'), + bytecode: getByteCode('PiggyBank'), }) const deployReceipt = await walletClient.waitForTransactionReceipt({ hash }) const contractAddress = deployReceipt.contractAddress @@ -31,9 +31,7 @@ assert(contractAddress, 'Contract address should be set') value: parseEther('10'), }) - request.nonce = 0 const hash = await walletClient.writeContract(request) - const receipt = await walletClient.waitForTransactionReceipt({ hash }) console.log(`Deposit receipt: ${receipt.status}`) } diff --git a/substrate/frame/revive/rpc/revive_chain.metadata b/substrate/frame/revive/rpc/revive_chain.metadata index 903731a245d2..402e8c2d22b2 100644 Binary files a/substrate/frame/revive/rpc/revive_chain.metadata and b/substrate/frame/revive/rpc/revive_chain.metadata differ diff --git a/substrate/frame/revive/rpc/src/client.rs b/substrate/frame/revive/rpc/src/client.rs index 1162b9c9d887..d7c42368fedd 100644 --- a/substrate/frame/revive/rpc/src/client.rs +++ b/substrate/frame/revive/rpc/src/client.rs @@ -22,12 +22,12 @@ use crate::{ subxt_client::{ revive::calls::types::EthTransact, runtime_types::pallet_revive::storage::ContractInfo, }, - BlockInfoProvider, ReceiptProvider, LOG_TARGET, + BlockInfoProvider, ReceiptProvider, TransactionInfo, LOG_TARGET, }; use jsonrpsee::types::{error::CALL_EXECUTION_FAILED_CODE, ErrorObjectOwned}; use pallet_revive::{ evm::{ - Block, BlockNumberOrTag, BlockNumberOrTagOrHash, Bytes256, GenericTransaction, ReceiptInfo, + Block, BlockNumberOrTag, BlockNumberOrTagOrHash, GenericTransaction, ReceiptInfo, SyncingProgress, SyncingStatus, TransactionSigned, H160, H256, U256, }, EthTransactError, EthTransactInfo, @@ -668,7 +668,11 @@ impl Client { } /// Get the EVM block for the given hash. - pub async fn evm_block(&self, block: Arc) -> Result { + pub async fn evm_block( + &self, + block: Arc, + hydrated_transactions: bool, + ) -> Result { let runtime_api = self.api.runtime_api().at(block.hash()); let max_fee = Self::weight_to_fee(&runtime_api, self.max_block_weight()).await?; let gas_limit = gas_from_fee(max_fee); @@ -681,6 +685,23 @@ impl Client { let state_root = header.state_root.0.into(); let extrinsics_root = header.extrinsics_root.0.into(); + let receipts = extract_receipts_from_block(&block).await?; + let gas_used = + receipts.iter().fold(U256::zero(), |acc, (_, receipt)| acc + receipt.gas_used); + let transactions = if hydrated_transactions { + receipts + .into_iter() + .map(|(signed_tx, receipt)| TransactionInfo::new(receipt, signed_tx).into()) + .collect::>() + .into() + } else { + receipts + .into_iter() + .map(|(_, receipt)| receipt.transaction_hash) + .collect::>() + .into() + }; + Ok(Block { hash: block.hash(), parent_hash, @@ -689,9 +710,11 @@ impl Client { number: header.number.into(), timestamp: timestamp.into(), difficulty: Some(0u32.into()), + base_fee_per_gas: Some(crate::GAS_PRICE.into()), gas_limit, - logs_bloom: Bytes256([0u8; 256]), + gas_used, receipts_root: extrinsics_root, + transactions, ..Default::default() }) } diff --git a/substrate/frame/revive/rpc/src/lib.rs b/substrate/frame/revive/rpc/src/lib.rs index 3e23eb41290f..96865b77a9c3 100644 --- a/substrate/frame/revive/rpc/src/lib.rs +++ b/substrate/frame/revive/rpc/src/lib.rs @@ -204,12 +204,12 @@ impl EthRpcServer for EthRpcServerImpl { async fn get_block_by_hash( &self, block_hash: H256, - _hydrated_transactions: bool, + hydrated_transactions: bool, ) -> RpcResult> { let Some(block) = self.client.block_by_hash(&block_hash).await? else { return Ok(None); }; - let block = self.client.evm_block(block).await?; + let block = self.client.evm_block(block, hydrated_transactions).await?; Ok(Some(block)) } @@ -239,12 +239,12 @@ impl EthRpcServer for EthRpcServerImpl { async fn get_block_by_number( &self, block: BlockNumberOrTag, - _hydrated_transactions: bool, + hydrated_transactions: bool, ) -> RpcResult> { let Some(block) = self.client.block_by_number_or_tag(&block).await? else { return Ok(None); }; - let block = self.client.evm_block(block).await?; + let block = self.client.evm_block(block, hydrated_transactions).await?; Ok(Some(block)) } diff --git a/substrate/frame/revive/rpc/src/rpc_health.rs b/substrate/frame/revive/rpc/src/rpc_health.rs index f94d4b82a80f..35c5a588f284 100644 --- a/substrate/frame/revive/rpc/src/rpc_health.rs +++ b/substrate/frame/revive/rpc/src/rpc_health.rs @@ -25,6 +25,10 @@ pub trait SystemHealthRpc { /// Proxy the substrate chain system_health RPC call. #[method(name = "system_health")] async fn system_health(&self) -> RpcResult; + + ///Returns the number of peers currently connected to the client. + #[method(name = "net_peerCount")] + async fn net_peer_count(&self) -> RpcResult; } pub struct SystemHealthRpcServerImpl { @@ -47,4 +51,9 @@ impl SystemHealthRpcServer for SystemHealthRpcServerImpl { should_have_peers: health.should_have_peers, }) } + + async fn net_peer_count(&self) -> RpcResult { + let health = self.client.system_health().await?; + Ok((health.peers as u64).into()) + } } diff --git a/substrate/frame/revive/src/evm/api/rpc_types.rs b/substrate/frame/revive/src/evm/api/rpc_types.rs index ed046cb4da44..b4b2c6ffcf17 100644 --- a/substrate/frame/revive/src/evm/api/rpc_types.rs +++ b/substrate/frame/revive/src/evm/api/rpc_types.rs @@ -192,7 +192,11 @@ impl GenericTransaction { value: Some(tx.value), to: Some(tx.to), gas: Some(tx.gas), - gas_price: Some(tx.max_fee_per_blob_gas), + gas_price: Some( + U256::from(crate::GAS_PRICE) + .saturating_add(tx.max_priority_fee_per_gas) + .max(tx.max_fee_per_blob_gas), + ), access_list: Some(tx.access_list), blob_versioned_hashes: tx.blob_versioned_hashes, max_fee_per_blob_gas: Some(tx.max_fee_per_blob_gas), @@ -209,7 +213,11 @@ impl GenericTransaction { value: Some(tx.value), to: tx.to, gas: Some(tx.gas), - gas_price: Some(tx.gas_price), + gas_price: Some( + U256::from(crate::GAS_PRICE) + .saturating_add(tx.max_priority_fee_per_gas) + .max(tx.max_fee_per_gas), + ), access_list: Some(tx.access_list), max_fee_per_gas: Some(tx.max_fee_per_gas), max_priority_fee_per_gas: Some(tx.max_priority_fee_per_gas), diff --git a/substrate/frame/revive/src/evm/api/rpc_types_gen.rs b/substrate/frame/revive/src/evm/api/rpc_types_gen.rs index 1d65fdefdde6..5d31613ca314 100644 --- a/substrate/frame/revive/src/evm/api/rpc_types_gen.rs +++ b/substrate/frame/revive/src/evm/api/rpc_types_gen.rs @@ -87,7 +87,7 @@ pub struct Block { /// Total difficulty #[serde(rename = "totalDifficulty", skip_serializing_if = "Option::is_none")] pub total_difficulty: Option, - pub transactions: H256OrTransactionInfo, + pub transactions: HashesOrTransactionInfos, /// Transactions root #[serde(rename = "transactionsRoot")] pub transactions_root: H256, @@ -357,15 +357,15 @@ pub enum BlockTag { Debug, Clone, Encode, Decode, TypeInfo, Serialize, Deserialize, From, TryInto, Eq, PartialEq, )] #[serde(untagged)] -pub enum H256OrTransactionInfo { +pub enum HashesOrTransactionInfos { /// Transaction hashes - H256s(Vec), + Hashes(Vec), /// Full transactions TransactionInfos(Vec), } -impl Default for H256OrTransactionInfo { +impl Default for HashesOrTransactionInfos { fn default() -> Self { - H256OrTransactionInfo::H256s(Default::default()) + HashesOrTransactionInfos::Hashes(Default::default()) } } diff --git a/substrate/frame/revive/src/evm/runtime.rs b/substrate/frame/revive/src/evm/runtime.rs index 06cb2665067a..c7b0769df0be 100644 --- a/substrate/frame/revive/src/evm/runtime.rs +++ b/substrate/frame/revive/src/evm/runtime.rs @@ -50,11 +50,11 @@ type CallOf = ::RuntimeCall; /// This let us calculate the gas estimate for a transaction with the formula: /// `estimate_gas = substrate_fee / gas_price`. /// -/// The chosen constant value is balanced to ensure: -/// - It is not too high, allowing components (ref_time, proof_size, and deposit) to be encoded in -/// the lower digits of the gas value. -/// - It is not too low, enabling users to adjust the gas price to define a tip. -pub const GAS_PRICE: u32 = 1_000u32; +/// The chosen constant value is: +/// - Not too high, ensuring the gas value is large enough (at least 7 digits) to encode the +/// ref_time, proof_size, and deposit into the less significant (6 lower) digits of the gas value. +/// - Not too low, enabling users to adjust the gas price to define a tip. +pub const GAS_PRICE: u32 = 100_000u32; /// Convert a `Balance` into a gas value, using the fixed `GAS_PRICE`. /// The gas is calculated as `balance / GAS_PRICE`, rounded up to the nearest integer. @@ -401,7 +401,7 @@ pub trait EthExtra { Default::default(), ) .into(); - log::debug!(target: LOG_TARGET, "try_into_checked_extrinsic: encoded_len: {encoded_len:?} actual_fee: {actual_fee:?} eth_fee: {eth_fee:?}"); + log::debug!(target: LOG_TARGET, "try_into_checked_extrinsic: gas_price: {gas_price:?}, encoded_len: {encoded_len:?} actual_fee: {actual_fee:?} eth_fee: {eth_fee:?}"); // The fees from the Ethereum transaction should be greater or equal to the actual fees paid // by the account. @@ -411,12 +411,12 @@ pub trait EthExtra { } if eth_fee_no_tip > actual_fee.saturating_mul(2u32.into()) { - log::debug!(target: LOG_TARGET, "actual fees {actual_fee:?} too high, base eth fees: {eth_fee_no_tip:?}"); + log::debug!(target: LOG_TARGET, "actual fees: {actual_fee:?} too high, base eth fees: {eth_fee_no_tip:?}"); return Err(InvalidTransaction::Call.into()) } let tip = eth_fee.saturating_sub(eth_fee_no_tip); - log::debug!(target: LOG_TARGET, "Created checked Ethereum transaction with nonce {nonce:?} and tip: {tip:?}"); + log::debug!(target: LOG_TARGET, "Created checked Ethereum transaction with nonce: {nonce:?} and tip: {tip:?}"); Ok(CheckedExtrinsic { format: ExtrinsicFormat::Signed(signer.into(), Self::get_eth_extension(nonce, tip)), function, diff --git a/substrate/frame/revive/src/lib.rs b/substrate/frame/revive/src/lib.rs index 0be43e77f075..b2459476ba46 100644 --- a/substrate/frame/revive/src/lib.rs +++ b/substrate/frame/revive/src/lib.rs @@ -1391,19 +1391,17 @@ where 0u32.into(), ) .into(); - let eth_gas = gas_from_fee(fee); + let raw_eth_gas = gas_from_fee(fee); let eth_gas = - T::EthGasEncoder::encode(eth_gas, result.gas_required, result.storage_deposit); + T::EthGasEncoder::encode(raw_eth_gas, result.gas_required, result.storage_deposit); if eth_gas == result.eth_gas { - log::trace!(target: LOG_TARGET, "bare_eth_call: encoded_len: {encoded_len:?} eth_gas: {eth_gas:?}"); + log::debug!(target: LOG_TARGET, "bare_eth_call: raw_eth_gas: {raw_eth_gas:?} eth_gas: {eth_gas:?}"); break; } result.eth_gas = eth_gas; tx.gas = Some(eth_gas.into()); - log::debug!(target: LOG_TARGET, "Adjusting Eth gas to: {eth_gas:?}"); } - Ok(result) } diff --git a/substrate/frame/src/lib.rs b/substrate/frame/src/lib.rs index b3e340cbcbff..b0338b682314 100644 --- a/substrate/frame/src/lib.rs +++ b/substrate/frame/src/lib.rs @@ -495,6 +495,7 @@ pub mod runtime { frame_system::CheckEra, frame_system::CheckNonce, frame_system::CheckWeight, + frame_system::WeightReclaim, ); } diff --git a/substrate/frame/support/src/dispatch.rs b/substrate/frame/support/src/dispatch.rs index 483a3dce77f6..990996830030 100644 --- a/substrate/frame/support/src/dispatch.rs +++ b/substrate/frame/support/src/dispatch.rs @@ -308,6 +308,19 @@ impl PostDispatchInfo { /// Calculate how much weight was actually spent by the `Dispatchable`. pub fn calc_actual_weight(&self, info: &DispatchInfo) -> Weight { if let Some(actual_weight) = self.actual_weight { + let info_total_weight = info.total_weight(); + if actual_weight.any_gt(info_total_weight) { + log::error!( + target: crate::LOG_TARGET, + "Post dispatch weight is greater than pre dispatch weight. \ + Pre dispatch weight may underestimating the actual weight. \ + Greater post dispatch weight components are ignored. + Pre dispatch weight: {:?}, + Post dispatch weight: {:?}", + actual_weight, + info_total_weight, + ); + } actual_weight.min(info.total_weight()) } else { info.total_weight() diff --git a/substrate/frame/system/benchmarking/src/extensions.rs b/substrate/frame/system/benchmarking/src/extensions.rs index 01e4687bc4bc..25d6ea035578 100644 --- a/substrate/frame/system/benchmarking/src/extensions.rs +++ b/substrate/frame/system/benchmarking/src/extensions.rs @@ -29,7 +29,7 @@ use frame_support::{ use frame_system::{ pallet_prelude::*, CheckGenesis, CheckMortality, CheckNonZeroSender, CheckNonce, CheckSpecVersion, CheckTxVersion, CheckWeight, Config, ExtensionsWeightInfo, Pallet as System, - RawOrigin, + RawOrigin, WeightReclaim, }; use sp_runtime::{ generic::Era, @@ -254,5 +254,49 @@ mod benchmarks { Ok(()) } + #[benchmark] + fn weight_reclaim() -> Result<(), BenchmarkError> { + let caller = account("caller", 0, 0); + let base_extrinsic = ::BlockWeights::get() + .get(DispatchClass::Normal) + .base_extrinsic; + let extension_weight = ::ExtensionsWeightInfo::weight_reclaim(); + let info = DispatchInfo { + call_weight: Weight::from_parts(base_extrinsic.ref_time() * 5, 0), + extension_weight, + class: DispatchClass::Normal, + ..Default::default() + }; + let call: T::RuntimeCall = frame_system::Call::remark { remark: vec![] }.into(); + let post_info = PostDispatchInfo { + actual_weight: Some(Weight::from_parts(base_extrinsic.ref_time() * 2, 0)), + pays_fee: Default::default(), + }; + let len = 0_usize; + let ext = WeightReclaim::::new(); + + let initial_block_weight = Weight::from_parts(base_extrinsic.ref_time() * 2, 0); + frame_system::BlockWeight::::mutate(|current_weight| { + current_weight.set(Weight::zero(), DispatchClass::Mandatory); + current_weight.set(initial_block_weight, DispatchClass::Normal); + current_weight.accrue(base_extrinsic + info.total_weight(), DispatchClass::Normal); + }); + + #[block] + { + ext.test_run(RawOrigin::Signed(caller).into(), &call, &info, len, 0, |_| Ok(post_info)) + .unwrap() + .unwrap(); + } + + assert_eq!( + System::::block_weight().total(), + initial_block_weight + + base_extrinsic + + post_info.actual_weight.unwrap().saturating_add(extension_weight), + ); + Ok(()) + } + impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test,); } diff --git a/substrate/frame/system/benchmarking/src/mock.rs b/substrate/frame/system/benchmarking/src/mock.rs index 6b126619ce5b..61b5b885ec62 100644 --- a/substrate/frame/system/benchmarking/src/mock.rs +++ b/substrate/frame/system/benchmarking/src/mock.rs @@ -65,6 +65,10 @@ impl frame_system::ExtensionsWeightInfo for MockWeights { fn check_weight() -> Weight { Weight::from_parts(10, 0) } + + fn weight_reclaim() -> Weight { + Weight::from_parts(10, 0) + } } #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] diff --git a/substrate/frame/system/src/extensions/check_non_zero_sender.rs b/substrate/frame/system/src/extensions/check_non_zero_sender.rs index 577e2b324fca..978eebaf3dac 100644 --- a/substrate/frame/system/src/extensions/check_non_zero_sender.rs +++ b/substrate/frame/system/src/extensions/check_non_zero_sender.rs @@ -86,7 +86,7 @@ mod tests { use crate::mock::{new_test_ext, Test, CALL}; use frame_support::{assert_ok, dispatch::DispatchInfo}; use sp_runtime::{ - traits::{AsTransactionAuthorizedOrigin, DispatchTransaction}, + traits::{AsTransactionAuthorizedOrigin, DispatchTransaction, TxBaseImplication}, transaction_validity::{TransactionSource::External, TransactionValidityError}, }; @@ -118,7 +118,7 @@ mod tests { let info = DispatchInfo::default(); let len = 0_usize; let (_, _, origin) = CheckNonZeroSender::::new() - .validate(None.into(), CALL, &info, len, (), CALL, External) + .validate(None.into(), CALL, &info, len, (), &TxBaseImplication(CALL), External) .unwrap(); assert!(!origin.is_transaction_authorized()); }) diff --git a/substrate/frame/system/src/extensions/check_nonce.rs b/substrate/frame/system/src/extensions/check_nonce.rs index 004ec08a26f2..bc19a09e06a9 100644 --- a/substrate/frame/system/src/extensions/check_nonce.rs +++ b/substrate/frame/system/src/extensions/check_nonce.rs @@ -186,7 +186,7 @@ mod tests { assert_ok, assert_storage_noop, dispatch::GetDispatchInfo, traits::OriginTrait, }; use sp_runtime::{ - traits::{AsTransactionAuthorizedOrigin, DispatchTransaction}, + traits::{AsTransactionAuthorizedOrigin, DispatchTransaction, TxBaseImplication}, transaction_validity::TransactionSource::External, }; @@ -335,7 +335,7 @@ mod tests { let info = DispatchInfo::default(); let len = 0_usize; let (_, val, origin) = CheckNonce::(1u64.into()) - .validate(None.into(), CALL, &info, len, (), CALL, External) + .validate(None.into(), CALL, &info, len, (), &TxBaseImplication(CALL), External) .unwrap(); assert!(!origin.is_transaction_authorized()); assert_ok!(CheckNonce::(1u64.into()).prepare(val, &origin, CALL, &info, len)); @@ -359,7 +359,7 @@ mod tests { let len = 0_usize; // run the validation step let (_, val, origin) = CheckNonce::(1u64.into()) - .validate(Some(1).into(), CALL, &info, len, (), CALL, External) + .validate(Some(1).into(), CALL, &info, len, (), &TxBaseImplication(CALL), External) .unwrap(); // mutate `AccountData` for the caller crate::Account::::mutate(1, |info| { diff --git a/substrate/frame/system/src/extensions/check_weight.rs b/substrate/frame/system/src/extensions/check_weight.rs index ee91478b90f3..de0303defd0c 100644 --- a/substrate/frame/system/src/extensions/check_weight.rs +++ b/substrate/frame/system/src/extensions/check_weight.rs @@ -135,30 +135,12 @@ where Ok(()) } + #[deprecated(note = "Use `frame_system::Pallet::reclaim_weight` instead.")] pub fn do_post_dispatch( info: &DispatchInfoOf, post_info: &PostDispatchInfoOf, ) -> Result<(), TransactionValidityError> { - let unspent = post_info.calc_unspent(info); - if unspent.any_gt(Weight::zero()) { - crate::BlockWeight::::mutate(|current_weight| { - current_weight.reduce(unspent, info.class); - }) - } - - log::trace!( - target: LOG_TARGET, - "Used block weight: {:?}", - crate::BlockWeight::::get(), - ); - - log::trace!( - target: LOG_TARGET, - "Used block length: {:?}", - Pallet::::all_extrinsics_len(), - ); - - Ok(()) + crate::Pallet::::reclaim_weight(info, post_info) } } @@ -279,8 +261,7 @@ where _len: usize, _result: &DispatchResult, ) -> Result { - Self::do_post_dispatch(info, post_info)?; - Ok(Weight::zero()) + crate::Pallet::::reclaim_weight(info, post_info).map(|()| Weight::zero()) } fn bare_validate( @@ -306,7 +287,7 @@ where _len: usize, _result: &DispatchResult, ) -> Result<(), TransactionValidityError> { - Self::do_post_dispatch(info, post_info) + crate::Pallet::::reclaim_weight(info, post_info) } } @@ -744,6 +725,121 @@ mod tests { }) } + #[test] + fn extrinsic_already_refunded_more_precisely() { + new_test_ext().execute_with(|| { + // This is half of the max block weight + let info = + DispatchInfo { call_weight: Weight::from_parts(512, 0), ..Default::default() }; + let post_info = PostDispatchInfo { + actual_weight: Some(Weight::from_parts(128, 0)), + pays_fee: Default::default(), + }; + let prior_block_weight = Weight::from_parts(64, 0); + let accurate_refund = Weight::from_parts(510, 0); + let len = 0_usize; + let base_extrinsic = block_weights().get(DispatchClass::Normal).base_extrinsic; + + // Set initial info + BlockWeight::::mutate(|current_weight| { + current_weight.set(Weight::zero(), DispatchClass::Mandatory); + current_weight.set(prior_block_weight, DispatchClass::Normal); + }); + + // Validate and prepare extrinsic + let pre = CheckWeight::(PhantomData) + .validate_and_prepare(Some(1).into(), CALL, &info, len, 0) + .unwrap() + .0; + + assert_eq!( + BlockWeight::::get().total(), + info.total_weight() + prior_block_weight + base_extrinsic + ); + + // Refund more accurately than the benchmark + BlockWeight::::mutate(|current_weight| { + current_weight.reduce(accurate_refund, DispatchClass::Normal); + }); + crate::ExtrinsicWeightReclaimed::::put(accurate_refund); + + // Do the post dispatch + assert_ok!(CheckWeight::::post_dispatch_details( + pre, + &info, + &post_info, + len, + &Ok(()) + )); + + // Ensure the accurate refund is used + assert_eq!(crate::ExtrinsicWeightReclaimed::::get(), accurate_refund); + assert_eq!( + BlockWeight::::get().total(), + info.total_weight() - accurate_refund + prior_block_weight + base_extrinsic + ); + }) + } + + #[test] + fn extrinsic_already_refunded_less_precisely() { + new_test_ext().execute_with(|| { + // This is half of the max block weight + let info = + DispatchInfo { call_weight: Weight::from_parts(512, 0), ..Default::default() }; + let post_info = PostDispatchInfo { + actual_weight: Some(Weight::from_parts(128, 0)), + pays_fee: Default::default(), + }; + let prior_block_weight = Weight::from_parts(64, 0); + let inaccurate_refund = Weight::from_parts(110, 0); + let len = 0_usize; + let base_extrinsic = block_weights().get(DispatchClass::Normal).base_extrinsic; + + // Set initial info + BlockWeight::::mutate(|current_weight| { + current_weight.set(Weight::zero(), DispatchClass::Mandatory); + current_weight.set(prior_block_weight, DispatchClass::Normal); + }); + + // Validate and prepare extrinsic + let pre = CheckWeight::(PhantomData) + .validate_and_prepare(Some(1).into(), CALL, &info, len, 0) + .unwrap() + .0; + + assert_eq!( + BlockWeight::::get().total(), + info.total_weight() + prior_block_weight + base_extrinsic + ); + + // Refund less accurately than the benchmark + BlockWeight::::mutate(|current_weight| { + current_weight.reduce(inaccurate_refund, DispatchClass::Normal); + }); + crate::ExtrinsicWeightReclaimed::::put(inaccurate_refund); + + // Do the post dispatch + assert_ok!(CheckWeight::::post_dispatch_details( + pre, + &info, + &post_info, + len, + &Ok(()) + )); + + // Ensure the accurate refund from benchmark is used + assert_eq!( + crate::ExtrinsicWeightReclaimed::::get(), + post_info.calc_unspent(&info) + ); + assert_eq!( + BlockWeight::::get().total(), + post_info.actual_weight.unwrap() + prior_block_weight + base_extrinsic + ); + }) + } + #[test] fn zero_weight_extrinsic_still_has_base_weight() { new_test_ext().execute_with(|| { diff --git a/substrate/frame/system/src/extensions/mod.rs b/substrate/frame/system/src/extensions/mod.rs index d79104d22403..66a8b17d30ae 100644 --- a/substrate/frame/system/src/extensions/mod.rs +++ b/substrate/frame/system/src/extensions/mod.rs @@ -22,6 +22,7 @@ pub mod check_nonce; pub mod check_spec_version; pub mod check_tx_version; pub mod check_weight; +pub mod weight_reclaim; pub mod weights; pub use weights::WeightInfo; diff --git a/substrate/frame/system/src/extensions/weight_reclaim.rs b/substrate/frame/system/src/extensions/weight_reclaim.rs new file mode 100644 index 000000000000..0c37422a843b --- /dev/null +++ b/substrate/frame/system/src/extensions/weight_reclaim.rs @@ -0,0 +1,401 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use crate::Config; +use codec::{Decode, Encode}; +use frame_support::dispatch::{DispatchInfo, PostDispatchInfo}; +use scale_info::TypeInfo; +use sp_runtime::{ + traits::{ + DispatchInfoOf, Dispatchable, PostDispatchInfoOf, TransactionExtension, ValidateResult, + }, + transaction_validity::{TransactionSource, TransactionValidityError, ValidTransaction}, + DispatchResult, +}; +use sp_weights::Weight; + +/// Reclaim the unused weight using the post dispatch information +/// +/// After the dispatch of the extrinsic, calculate the unused weight using the post dispatch +/// information and update the block consumed weight according to the new calculated extrinsic +/// weight. +#[derive(Encode, Decode, Clone, Eq, PartialEq, Default, TypeInfo)] +#[scale_info(skip_type_params(T))] +pub struct WeightReclaim(core::marker::PhantomData); + +impl WeightReclaim +where + T::RuntimeCall: Dispatchable, +{ + /// Creates new `TransactionExtension` to recalculate the extrinsic weight after dispatch. + pub fn new() -> Self { + Self(Default::default()) + } +} + +impl TransactionExtension for WeightReclaim +where + T::RuntimeCall: Dispatchable, +{ + const IDENTIFIER: &'static str = "WeightReclaim"; + type Implicit = (); + type Pre = (); + type Val = (); + + fn weight(&self, _: &T::RuntimeCall) -> Weight { + ::weight_reclaim() + } + + fn validate( + &self, + origin: T::RuntimeOrigin, + _call: &T::RuntimeCall, + _info: &DispatchInfoOf, + _len: usize, + _self_implicit: Self::Implicit, + _inherited_implication: &impl Encode, + _source: TransactionSource, + ) -> ValidateResult { + Ok((ValidTransaction::default(), (), origin)) + } + + fn prepare( + self, + _val: Self::Val, + _origin: &T::RuntimeOrigin, + _call: &T::RuntimeCall, + _info: &DispatchInfoOf, + _len: usize, + ) -> Result { + Ok(()) + } + + fn post_dispatch_details( + _pre: Self::Pre, + info: &DispatchInfoOf, + post_info: &PostDispatchInfoOf, + _len: usize, + _result: &DispatchResult, + ) -> Result { + crate::Pallet::::reclaim_weight(info, post_info).map(|()| Weight::zero()) + } + + fn bare_validate( + _call: &T::RuntimeCall, + _info: &DispatchInfoOf, + _len: usize, + ) -> frame_support::pallet_prelude::TransactionValidity { + Ok(ValidTransaction::default()) + } + + fn bare_validate_and_prepare( + _call: &T::RuntimeCall, + _info: &DispatchInfoOf, + _len: usize, + ) -> Result<(), TransactionValidityError> { + Ok(()) + } + + fn bare_post_dispatch( + info: &DispatchInfoOf, + post_info: &mut PostDispatchInfoOf, + _len: usize, + _result: &DispatchResult, + ) -> Result<(), TransactionValidityError> { + crate::Pallet::::reclaim_weight(info, post_info) + } +} + +impl core::fmt::Debug for WeightReclaim +where + T::RuntimeCall: Dispatchable, +{ + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "{}", Self::IDENTIFIER) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::{ + mock::{new_test_ext, Test}, + BlockWeight, DispatchClass, + }; + use frame_support::{assert_ok, weights::Weight}; + + fn block_weights() -> crate::limits::BlockWeights { + ::BlockWeights::get() + } + + #[test] + fn extrinsic_already_refunded_more_precisely() { + new_test_ext().execute_with(|| { + // This is half of the max block weight + let info = + DispatchInfo { call_weight: Weight::from_parts(512, 0), ..Default::default() }; + let post_info = PostDispatchInfo { + actual_weight: Some(Weight::from_parts(128, 0)), + pays_fee: Default::default(), + }; + let prior_block_weight = Weight::from_parts(64, 0); + let accurate_refund = Weight::from_parts(510, 0); + let len = 0_usize; + let base_extrinsic = block_weights().get(DispatchClass::Normal).base_extrinsic; + + // Set initial info + BlockWeight::::mutate(|current_weight| { + current_weight.set(prior_block_weight, DispatchClass::Normal); + current_weight.accrue( + base_extrinsic + info.total_weight() - accurate_refund, + DispatchClass::Normal, + ); + }); + crate::ExtrinsicWeightReclaimed::::put(accurate_refund); + + // Do the post dispatch + assert_ok!(WeightReclaim::::post_dispatch_details( + (), + &info, + &post_info, + len, + &Ok(()) + )); + + // Ensure the accurate refund is used + assert_eq!(crate::ExtrinsicWeightReclaimed::::get(), accurate_refund); + assert_eq!( + *BlockWeight::::get().get(DispatchClass::Normal), + info.total_weight() - accurate_refund + prior_block_weight + base_extrinsic + ); + }) + } + + #[test] + fn extrinsic_already_refunded_less_precisely() { + new_test_ext().execute_with(|| { + // This is half of the max block weight + let info = + DispatchInfo { call_weight: Weight::from_parts(512, 0), ..Default::default() }; + let post_info = PostDispatchInfo { + actual_weight: Some(Weight::from_parts(128, 0)), + pays_fee: Default::default(), + }; + let prior_block_weight = Weight::from_parts(64, 0); + let inaccurate_refund = Weight::from_parts(110, 0); + let len = 0_usize; + let base_extrinsic = block_weights().get(DispatchClass::Normal).base_extrinsic; + + // Set initial info + BlockWeight::::mutate(|current_weight| { + current_weight.set(prior_block_weight, DispatchClass::Normal); + current_weight.accrue( + base_extrinsic + info.total_weight() - inaccurate_refund, + DispatchClass::Normal, + ); + }); + crate::ExtrinsicWeightReclaimed::::put(inaccurate_refund); + + // Do the post dispatch + assert_ok!(WeightReclaim::::post_dispatch_details( + (), + &info, + &post_info, + len, + &Ok(()) + )); + + // Ensure the accurate refund from benchmark is used + assert_eq!( + crate::ExtrinsicWeightReclaimed::::get(), + post_info.calc_unspent(&info) + ); + assert_eq!( + *BlockWeight::::get().get(DispatchClass::Normal), + post_info.actual_weight.unwrap() + prior_block_weight + base_extrinsic + ); + }) + } + + #[test] + fn extrinsic_not_refunded_before() { + new_test_ext().execute_with(|| { + // This is half of the max block weight + let info = + DispatchInfo { call_weight: Weight::from_parts(512, 0), ..Default::default() }; + let post_info = PostDispatchInfo { + actual_weight: Some(Weight::from_parts(128, 0)), + pays_fee: Default::default(), + }; + let prior_block_weight = Weight::from_parts(64, 0); + let len = 0_usize; + let base_extrinsic = block_weights().get(DispatchClass::Normal).base_extrinsic; + + // Set initial info + BlockWeight::::mutate(|current_weight| { + current_weight.set(prior_block_weight, DispatchClass::Normal); + current_weight.accrue(base_extrinsic + info.total_weight(), DispatchClass::Normal); + }); + + // Do the post dispatch + assert_ok!(WeightReclaim::::post_dispatch_details( + (), + &info, + &post_info, + len, + &Ok(()) + )); + + // Ensure the accurate refund from benchmark is used + assert_eq!( + crate::ExtrinsicWeightReclaimed::::get(), + post_info.calc_unspent(&info) + ); + assert_eq!( + *BlockWeight::::get().get(DispatchClass::Normal), + post_info.actual_weight.unwrap() + prior_block_weight + base_extrinsic + ); + }) + } + + #[test] + fn no_actual_post_dispatch_weight() { + new_test_ext().execute_with(|| { + // This is half of the max block weight + let info = + DispatchInfo { call_weight: Weight::from_parts(512, 0), ..Default::default() }; + let post_info = PostDispatchInfo { actual_weight: None, pays_fee: Default::default() }; + let prior_block_weight = Weight::from_parts(64, 0); + let len = 0_usize; + let base_extrinsic = block_weights().get(DispatchClass::Normal).base_extrinsic; + + // Set initial info + BlockWeight::::mutate(|current_weight| { + current_weight.set(prior_block_weight, DispatchClass::Normal); + current_weight.accrue(base_extrinsic + info.total_weight(), DispatchClass::Normal); + }); + + // Do the post dispatch + assert_ok!(WeightReclaim::::post_dispatch_details( + (), + &info, + &post_info, + len, + &Ok(()) + )); + + // Ensure the accurate refund from benchmark is used + assert_eq!( + crate::ExtrinsicWeightReclaimed::::get(), + post_info.calc_unspent(&info) + ); + assert_eq!( + *BlockWeight::::get().get(DispatchClass::Normal), + info.total_weight() + prior_block_weight + base_extrinsic + ); + }) + } + + #[test] + fn different_dispatch_class() { + new_test_ext().execute_with(|| { + // This is half of the max block weight + let info = DispatchInfo { + call_weight: Weight::from_parts(512, 0), + class: DispatchClass::Operational, + ..Default::default() + }; + let post_info = PostDispatchInfo { + actual_weight: Some(Weight::from_parts(128, 0)), + pays_fee: Default::default(), + }; + let prior_block_weight = Weight::from_parts(64, 0); + let len = 0_usize; + let base_extrinsic = block_weights().get(DispatchClass::Operational).base_extrinsic; + + // Set initial info + BlockWeight::::mutate(|current_weight| { + current_weight.set(prior_block_weight, DispatchClass::Operational); + current_weight + .accrue(base_extrinsic + info.total_weight(), DispatchClass::Operational); + }); + + // Do the post dispatch + assert_ok!(WeightReclaim::::post_dispatch_details( + (), + &info, + &post_info, + len, + &Ok(()) + )); + + // Ensure the accurate refund from benchmark is used + assert_eq!( + crate::ExtrinsicWeightReclaimed::::get(), + post_info.calc_unspent(&info) + ); + assert_eq!( + *BlockWeight::::get().get(DispatchClass::Operational), + post_info.actual_weight.unwrap() + prior_block_weight + base_extrinsic + ); + }) + } + + #[test] + fn bare_also_works() { + new_test_ext().execute_with(|| { + // This is half of the max block weight + let info = DispatchInfo { + call_weight: Weight::from_parts(512, 0), + class: DispatchClass::Operational, + ..Default::default() + }; + let post_info = PostDispatchInfo { + actual_weight: Some(Weight::from_parts(128, 0)), + pays_fee: Default::default(), + }; + let prior_block_weight = Weight::from_parts(64, 0); + let len = 0_usize; + let base_extrinsic = block_weights().get(DispatchClass::Operational).base_extrinsic; + + // Set initial info + BlockWeight::::mutate(|current_weight| { + current_weight.set(prior_block_weight, DispatchClass::Operational); + current_weight + .accrue(base_extrinsic + info.total_weight(), DispatchClass::Operational); + }); + + // Do the bare post dispatch + assert_ok!(WeightReclaim::::bare_post_dispatch( + &info, + &mut post_info.clone(), + len, + &Ok(()) + )); + + // Ensure the accurate refund from benchmark is used + assert_eq!( + crate::ExtrinsicWeightReclaimed::::get(), + post_info.calc_unspent(&info) + ); + assert_eq!( + *BlockWeight::::get().get(DispatchClass::Operational), + post_info.actual_weight.unwrap() + prior_block_weight + base_extrinsic + ); + }) + } +} diff --git a/substrate/frame/system/src/extensions/weights.rs b/substrate/frame/system/src/extensions/weights.rs index b3c296899be5..670bb9a0e6fa 100644 --- a/substrate/frame/system/src/extensions/weights.rs +++ b/substrate/frame/system/src/extensions/weights.rs @@ -59,6 +59,7 @@ pub trait WeightInfo { fn check_spec_version() -> Weight; fn check_tx_version() -> Weight; fn check_weight() -> Weight; + fn weight_reclaim() -> Weight; } /// Weights for `frame_system_extensions` using the Substrate node and recommended hardware. @@ -133,6 +134,17 @@ impl WeightInfo for SubstrateWeight { // Minimum execution time: 2_887_000 picoseconds. Weight::from_parts(3_006_000, 0) } + /// Storage: `System::AllExtrinsicsLen` (r:1 w:1) + /// Proof: `System::AllExtrinsicsLen` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + fn weight_reclaim() -> Weight { + // Proof Size summary in bytes: + // Measured: `24` + // Estimated: `1489` + // Minimum execution time: 4_375_000 picoseconds. + Weight::from_parts(4_747_000, 1489) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } } // For backwards compatibility and tests. @@ -206,4 +218,15 @@ impl WeightInfo for () { // Minimum execution time: 2_887_000 picoseconds. Weight::from_parts(3_006_000, 0) } + /// Storage: `System::AllExtrinsicsLen` (r:1 w:1) + /// Proof: `System::AllExtrinsicsLen` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + fn weight_reclaim() -> Weight { + // Proof Size summary in bytes: + // Measured: `24` + // Estimated: `1489` + // Minimum execution time: 4_375_000 picoseconds. + Weight::from_parts(4_747_000, 1489) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } } diff --git a/substrate/frame/system/src/lib.rs b/substrate/frame/system/src/lib.rs index 862fb4cf9faf..4fc69c8755f3 100644 --- a/substrate/frame/system/src/lib.rs +++ b/substrate/frame/system/src/lib.rs @@ -146,6 +146,10 @@ use frame_support::{ }; use scale_info::TypeInfo; use sp_core::storage::well_known_keys; +use sp_runtime::{ + traits::{DispatchInfoOf, PostDispatchInfoOf}, + transaction_validity::TransactionValidityError, +}; use sp_weights::{RuntimeDbWeight, Weight}; #[cfg(any(feature = "std", test))] @@ -170,7 +174,7 @@ pub use extensions::{ check_genesis::CheckGenesis, check_mortality::CheckMortality, check_non_zero_sender::CheckNonZeroSender, check_nonce::CheckNonce, check_spec_version::CheckSpecVersion, check_tx_version::CheckTxVersion, - check_weight::CheckWeight, WeightInfo as ExtensionsWeightInfo, + check_weight::CheckWeight, weight_reclaim::WeightReclaim, WeightInfo as ExtensionsWeightInfo, }; // Backward compatible re-export. pub use extensions::check_mortality::CheckMortality as CheckEra; @@ -1039,6 +1043,17 @@ pub mod pallet { pub(super) type AuthorizedUpgrade = StorageValue<_, CodeUpgradeAuthorization, OptionQuery>; + /// The weight reclaimed for the extrinsic. + /// + /// This information is available until the end of the extrinsic execution. + /// More precisely this information is removed in `note_applied_extrinsic`. + /// + /// Logic doing some post dispatch weight reduction must update this storage to avoid duplicate + /// reduction. + #[pallet::storage] + #[pallet::whitelist_storage] + pub type ExtrinsicWeightReclaimed = StorageValue<_, Weight, ValueQuery>; + #[derive(frame_support::DefaultNoBound)] #[pallet::genesis_config] pub struct GenesisConfig { @@ -2073,10 +2088,23 @@ impl Pallet { }, }); + log::trace!( + target: LOG_TARGET, + "Used block weight: {:?}", + BlockWeight::::get(), + ); + + log::trace!( + target: LOG_TARGET, + "Used block length: {:?}", + Pallet::::all_extrinsics_len(), + ); + let next_extrinsic_index = Self::extrinsic_index().unwrap_or_default() + 1u32; storage::unhashed::put(well_known_keys::EXTRINSIC_INDEX, &next_extrinsic_index); ExecutionPhase::::put(Phase::ApplyExtrinsic(next_extrinsic_index)); + ExtrinsicWeightReclaimed::::kill(); } /// To be called immediately after `note_applied_extrinsic` of the last extrinsic of the block @@ -2174,6 +2202,32 @@ impl Pallet { } Ok(actual_hash) } + + /// Reclaim the weight for the extrinsic given info and post info. + /// + /// This function will check the already reclaimed weight, and reclaim more if the + /// difference between pre dispatch and post dispatch weight is higher. + pub fn reclaim_weight( + info: &DispatchInfoOf, + post_info: &PostDispatchInfoOf, + ) -> Result<(), TransactionValidityError> + where + T::RuntimeCall: Dispatchable, + { + let already_reclaimed = crate::ExtrinsicWeightReclaimed::::get(); + let unspent = post_info.calc_unspent(info); + let accurate_reclaim = already_reclaimed.max(unspent); + // Saturation never happens, we took the maximum above. + let to_reclaim_more = accurate_reclaim.saturating_sub(already_reclaimed); + if to_reclaim_more != Weight::zero() { + crate::BlockWeight::::mutate(|current_weight| { + current_weight.reduce(to_reclaim_more, info.class); + }); + crate::ExtrinsicWeightReclaimed::::put(accurate_reclaim); + } + + Ok(()) + } } /// Returns a 32 byte datum which is guaranteed to be universally unique. `entropy` is provided diff --git a/substrate/frame/system/src/tests.rs b/substrate/frame/system/src/tests.rs index 6b903f5b7e79..6415380b2848 100644 --- a/substrate/frame/system/src/tests.rs +++ b/substrate/frame/system/src/tests.rs @@ -892,3 +892,67 @@ fn test_default_account_nonce() { assert_eq!(System::account_nonce(&1), 5u64.into()); }); } + +#[test] +fn extrinsic_weight_refunded_is_cleaned() { + new_test_ext().execute_with(|| { + crate::ExtrinsicWeightReclaimed::::put(Weight::from_parts(1, 2)); + assert_eq!(crate::ExtrinsicWeightReclaimed::::get(), Weight::from_parts(1, 2)); + System::note_applied_extrinsic(&Ok(().into()), Default::default()); + assert_eq!(crate::ExtrinsicWeightReclaimed::::get(), Weight::zero()); + + crate::ExtrinsicWeightReclaimed::::put(Weight::from_parts(1, 2)); + assert_eq!(crate::ExtrinsicWeightReclaimed::::get(), Weight::from_parts(1, 2)); + System::note_applied_extrinsic(&Err(DispatchError::BadOrigin.into()), Default::default()); + assert_eq!(crate::ExtrinsicWeightReclaimed::::get(), Weight::zero()); + }); +} + +#[test] +fn reclaim_works() { + new_test_ext().execute_with(|| { + let info = DispatchInfo { call_weight: Weight::from_parts(100, 200), ..Default::default() }; + crate::Pallet::::reclaim_weight( + &info, + &PostDispatchInfo { + actual_weight: Some(Weight::from_parts(50, 100)), + ..Default::default() + }, + ) + .unwrap(); + assert_eq!(crate::ExtrinsicWeightReclaimed::::get(), Weight::from_parts(50, 100)); + + crate::Pallet::::reclaim_weight( + &info, + &PostDispatchInfo { + actual_weight: Some(Weight::from_parts(25, 200)), + ..Default::default() + }, + ) + .unwrap(); + assert_eq!(crate::ExtrinsicWeightReclaimed::::get(), Weight::from_parts(75, 100)); + + crate::Pallet::::reclaim_weight( + &info, + &PostDispatchInfo { + actual_weight: Some(Weight::from_parts(300, 50)), + ..Default::default() + }, + ) + .unwrap(); + assert_eq!(crate::ExtrinsicWeightReclaimed::::get(), Weight::from_parts(75, 150)); + + crate::Pallet::::reclaim_weight( + &info, + &PostDispatchInfo { + actual_weight: Some(Weight::from_parts(300, 300)), + ..Default::default() + }, + ) + .unwrap(); + assert_eq!(crate::ExtrinsicWeightReclaimed::::get(), Weight::from_parts(75, 150)); + + System::note_applied_extrinsic(&Ok(().into()), Default::default()); + assert_eq!(crate::ExtrinsicWeightReclaimed::::get(), Weight::zero()); + }); +} diff --git a/substrate/frame/transaction-payment/skip-feeless-payment/src/lib.rs b/substrate/frame/transaction-payment/skip-feeless-payment/src/lib.rs index dd907f6fcbb7..5ba1d1297679 100644 --- a/substrate/frame/transaction-payment/skip-feeless-payment/src/lib.rs +++ b/substrate/frame/transaction-payment/skip-feeless-payment/src/lib.rs @@ -46,7 +46,8 @@ use frame_support::{ use scale_info::{StaticTypeInfo, TypeInfo}; use sp_runtime::{ traits::{ - DispatchInfoOf, DispatchOriginOf, PostDispatchInfoOf, TransactionExtension, ValidateResult, + DispatchInfoOf, DispatchOriginOf, Implication, PostDispatchInfoOf, TransactionExtension, + ValidateResult, }, transaction_validity::TransactionValidityError, }; @@ -147,7 +148,7 @@ where info: &DispatchInfoOf, len: usize, self_implicit: S::Implicit, - inherited_implication: &impl Encode, + inherited_implication: &impl Implication, source: TransactionSource, ) -> ValidateResult { if call.is_feeless(&origin) { diff --git a/substrate/primitives/runtime/src/generic/checked_extrinsic.rs b/substrate/primitives/runtime/src/generic/checked_extrinsic.rs index 1842b1631621..dec818598472 100644 --- a/substrate/primitives/runtime/src/generic/checked_extrinsic.rs +++ b/substrate/primitives/runtime/src/generic/checked_extrinsic.rs @@ -85,7 +85,6 @@ where match self.format { ExtrinsicFormat::Bare => { let inherent_validation = I::validate_unsigned(source, &self.function)?; - #[allow(deprecated)] let legacy_validation = Extension::bare_validate(&self.function, info, len)?; Ok(legacy_validation.combine_with(inherent_validation)) }, diff --git a/substrate/primitives/runtime/src/traits/mod.rs b/substrate/primitives/runtime/src/traits/mod.rs index cfcc3e5a354d..d371152dc40a 100644 --- a/substrate/primitives/runtime/src/traits/mod.rs +++ b/substrate/primitives/runtime/src/traits/mod.rs @@ -55,7 +55,8 @@ use std::str::FromStr; pub mod transaction_extension; pub use transaction_extension::{ - DispatchTransaction, TransactionExtension, TransactionExtensionMetadata, ValidateResult, + DispatchTransaction, Implication, ImplicationParts, TransactionExtension, + TransactionExtensionMetadata, TxBaseImplication, ValidateResult, }; /// A lazy value. diff --git a/substrate/primitives/runtime/src/traits/transaction_extension/dispatch_transaction.rs b/substrate/primitives/runtime/src/traits/transaction_extension/dispatch_transaction.rs index 28030d12fc9f..1fbaab0d45ac 100644 --- a/substrate/primitives/runtime/src/traits/transaction_extension/dispatch_transaction.rs +++ b/substrate/primitives/runtime/src/traits/transaction_extension/dispatch_transaction.rs @@ -111,7 +111,7 @@ where info, len, self.implicit()?, - &(extension_version, call), + &TxBaseImplication((extension_version, call)), source, ) { // After validation, some origin must have been authorized. diff --git a/substrate/primitives/runtime/src/traits/transaction_extension/mod.rs b/substrate/primitives/runtime/src/traits/transaction_extension/mod.rs index f8c5dc6a724e..4d95e5e6f3a4 100644 --- a/substrate/primitives/runtime/src/traits/transaction_extension/mod.rs +++ b/substrate/primitives/runtime/src/traits/transaction_extension/mod.rs @@ -43,6 +43,72 @@ mod dispatch_transaction; pub use as_transaction_extension::AsTransactionExtension; pub use dispatch_transaction::DispatchTransaction; +/// Provides `Sealed` trait. +mod private { + /// Special trait that prevents the implementation of some traits outside of this crate. + pub trait Sealed {} +} + +/// The base implication in a transaction. +/// +/// This struct is used to represent the base implication in the transaction, that is +/// the implication not part of any transaction extensions. It usually comprises of the call and +/// the transaction extension version. +/// +/// The concept of implication in the transaction extension pipeline is explained in the trait +/// documentation: [`TransactionExtension`]. +#[derive(Encode)] +pub struct TxBaseImplication(pub T); + +impl Implication for TxBaseImplication { + fn parts(&self) -> ImplicationParts<&impl Encode, &impl Encode, &impl Encode> { + ImplicationParts { base: self, explicit: &(), implicit: &() } + } +} + +impl private::Sealed for TxBaseImplication {} + +/// The implication in a transaction. +/// +/// The concept of implication in the transaction extension pipeline is explained in the trait +/// documentation: [`TransactionExtension`]. +#[derive(Encode)] +pub struct ImplicationParts { + /// The base implication, that is implication not part of any transaction extension, usually + /// the call and the transaction extension version. + pub base: Base, + /// The explicit implication in transaction extensions. + pub explicit: Explicit, + /// The implicit implication in transaction extensions. + pub implicit: Implicit, +} + +impl Implication + for ImplicationParts +{ + fn parts(&self) -> ImplicationParts<&impl Encode, &impl Encode, &impl Encode> { + ImplicationParts { base: &self.base, explicit: &self.explicit, implicit: &self.implicit } + } +} + +impl private::Sealed for ImplicationParts {} + +/// Interface of implications in the transaction extension pipeline. +/// +/// Implications can be encoded, this is useful for checking signature on the implications. +/// Implications can be split into parts, this allow to destructure and restructure the +/// implications, this is useful for nested pipeline. +/// +/// This trait is sealed, consider using [`TxBaseImplication`] and [`ImplicationParts`] +/// implementations. +/// +/// The concept of implication in the transaction extension pipeline is explained in the trait +/// documentation: [`TransactionExtension`]. +pub trait Implication: Encode + private::Sealed { + /// Destructure the implication into its parts. + fn parts(&self) -> ImplicationParts<&impl Encode, &impl Encode, &impl Encode>; +} + /// Shortcut for the result value of the `validate` function. pub type ValidateResult = Result<(ValidTransaction, Val, DispatchOriginOf), TransactionValidityError>; @@ -244,7 +310,7 @@ pub trait TransactionExtension: info: &DispatchInfoOf, len: usize, self_implicit: Self::Implicit, - inherited_implication: &impl Encode, + inherited_implication: &impl Implication, source: TransactionSource, ) -> ValidateResult; @@ -421,7 +487,7 @@ pub trait TransactionExtension: #[macro_export] macro_rules! impl_tx_ext_default { ($call:ty ; , $( $rest:tt )*) => { - impl_tx_ext_default!{$call ; $( $rest )*} + $crate::impl_tx_ext_default!{$call ; $( $rest )*} }; ($call:ty ; validate $( $rest:tt )*) => { fn validate( @@ -436,7 +502,7 @@ macro_rules! impl_tx_ext_default { ) -> $crate::traits::ValidateResult { Ok((Default::default(), Default::default(), origin)) } - impl_tx_ext_default!{$call ; $( $rest )*} + $crate::impl_tx_ext_default!{$call ; $( $rest )*} }; ($call:ty ; prepare $( $rest:tt )*) => { fn prepare( @@ -449,13 +515,13 @@ macro_rules! impl_tx_ext_default { ) -> Result { Ok(Default::default()) } - impl_tx_ext_default!{$call ; $( $rest )*} + $crate::impl_tx_ext_default!{$call ; $( $rest )*} }; ($call:ty ; weight $( $rest:tt )*) => { fn weight(&self, _call: &$call) -> $crate::Weight { $crate::Weight::zero() } - impl_tx_ext_default!{$call ; $( $rest )*} + $crate::impl_tx_ext_default!{$call ; $( $rest )*} }; ($call:ty ;) => {}; } @@ -499,7 +565,7 @@ impl TransactionExtension for Tuple { info: &DispatchInfoOf, len: usize, self_implicit: Self::Implicit, - inherited_implication: &impl Encode, + inherited_implication: &impl Implication, source: TransactionSource, ) -> Result< (ValidTransaction, Self::Val, ::RuntimeOrigin), @@ -510,23 +576,20 @@ impl TransactionExtension for Tuple { let following_explicit_implications = for_tuples!( ( #( &self.Tuple ),* ) ); let following_implicit_implications = self_implicit; + let implication_parts = inherited_implication.parts(); + for_tuples!(#( // Implication of this pipeline element not relevant for later items, so we pop it. let (_item, following_explicit_implications) = following_explicit_implications.pop_front(); let (item_implicit, following_implicit_implications) = following_implicit_implications.pop_front(); let (item_valid, item_val, origin) = { - let implications = ( - // The first is the implications born of the fact we return the mutated - // origin. - inherited_implication, - // This is the explicitly made implication born of the fact the new origin is - // passed into the next items in this pipeline-tuple. - &following_explicit_implications, - // This is the implicitly made implication born of the fact the new origin is - // passed into the next items in this pipeline-tuple. - &following_implicit_implications, - ); - Tuple.validate(origin, call, info, len, item_implicit, &implications, source)? + Tuple.validate(origin, call, info, len, item_implicit, + &ImplicationParts { + base: implication_parts.base, + explicit: (&following_explicit_implications, implication_parts.explicit), + implicit: (&following_implicit_implications, implication_parts.implicit), + }, + source)? }; let valid = valid.combine_with(item_valid); let val = val.push_back(item_val); @@ -620,7 +683,7 @@ impl TransactionExtension for () { _info: &DispatchInfoOf, _len: usize, _self_implicit: Self::Implicit, - _inherited_implication: &impl Encode, + _inherited_implication: &impl Implication, _source: TransactionSource, ) -> Result< (ValidTransaction, (), ::RuntimeOrigin), @@ -639,3 +702,168 @@ impl TransactionExtension for () { Ok(()) } } + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn test_implications_on_nested_structure() { + use scale_info::TypeInfo; + use std::cell::RefCell; + + #[derive(Clone, Debug, Eq, PartialEq, Encode, Decode, TypeInfo)] + struct MockExtension { + also_implicit: u8, + explicit: u8, + } + + const CALL_IMPLICIT: u8 = 23; + + thread_local! { + static COUNTER: RefCell = RefCell::new(1); + } + + impl TransactionExtension<()> for MockExtension { + const IDENTIFIER: &'static str = "MockExtension"; + type Implicit = u8; + fn implicit(&self) -> Result { + Ok(self.also_implicit) + } + type Val = (); + type Pre = (); + fn weight(&self, _call: &()) -> Weight { + Weight::zero() + } + fn prepare( + self, + _val: Self::Val, + _origin: &DispatchOriginOf<()>, + _call: &(), + _info: &DispatchInfoOf<()>, + _len: usize, + ) -> Result { + Ok(()) + } + fn validate( + &self, + origin: DispatchOriginOf<()>, + _call: &(), + _info: &DispatchInfoOf<()>, + _len: usize, + self_implicit: Self::Implicit, + inherited_implication: &impl Implication, + _source: TransactionSource, + ) -> ValidateResult { + COUNTER.with(|c| { + let mut counter = c.borrow_mut(); + + assert_eq!(self_implicit, *counter); + assert_eq!( + self, + &MockExtension { also_implicit: *counter, explicit: *counter + 1 } + ); + + // Implications must be call then 1 to 22 then 1 to 22 odd. + let mut assert_implications = Vec::new(); + assert_implications.push(CALL_IMPLICIT); + for i in *counter + 2..23 { + assert_implications.push(i); + } + for i in *counter + 2..23 { + if i % 2 == 1 { + assert_implications.push(i); + } + } + assert_eq!(inherited_implication.encode(), assert_implications); + + *counter += 2; + }); + Ok((ValidTransaction::default(), (), origin)) + } + fn post_dispatch_details( + _pre: Self::Pre, + _info: &DispatchInfoOf<()>, + _post_info: &PostDispatchInfoOf<()>, + _len: usize, + _result: &DispatchResult, + ) -> Result { + Ok(Weight::zero()) + } + } + + // Test for one nested structure + + let ext = ( + MockExtension { also_implicit: 1, explicit: 2 }, + MockExtension { also_implicit: 3, explicit: 4 }, + ( + MockExtension { also_implicit: 5, explicit: 6 }, + MockExtension { also_implicit: 7, explicit: 8 }, + ( + MockExtension { also_implicit: 9, explicit: 10 }, + MockExtension { also_implicit: 11, explicit: 12 }, + ), + MockExtension { also_implicit: 13, explicit: 14 }, + MockExtension { also_implicit: 15, explicit: 16 }, + ), + MockExtension { also_implicit: 17, explicit: 18 }, + (MockExtension { also_implicit: 19, explicit: 20 },), + MockExtension { also_implicit: 21, explicit: 22 }, + ); + + let implicit = ext.implicit().unwrap(); + + let res = ext + .validate( + (), + &(), + &DispatchInfoOf::<()>::default(), + 0, + implicit, + &TxBaseImplication(CALL_IMPLICIT), + TransactionSource::Local, + ) + .expect("valid"); + + assert_eq!(res.0, ValidTransaction::default()); + + // Test for another nested structure + + COUNTER.with(|c| { + *c.borrow_mut() = 1; + }); + + let ext = ( + MockExtension { also_implicit: 1, explicit: 2 }, + MockExtension { also_implicit: 3, explicit: 4 }, + MockExtension { also_implicit: 5, explicit: 6 }, + MockExtension { also_implicit: 7, explicit: 8 }, + MockExtension { also_implicit: 9, explicit: 10 }, + MockExtension { also_implicit: 11, explicit: 12 }, + ( + MockExtension { also_implicit: 13, explicit: 14 }, + MockExtension { also_implicit: 15, explicit: 16 }, + MockExtension { also_implicit: 17, explicit: 18 }, + MockExtension { also_implicit: 19, explicit: 20 }, + MockExtension { also_implicit: 21, explicit: 22 }, + ), + ); + + let implicit = ext.implicit().unwrap(); + + let res = ext + .validate( + (), + &(), + &DispatchInfoOf::<()>::default(), + 0, + implicit, + &TxBaseImplication(CALL_IMPLICIT), + TransactionSource::Local, + ) + .expect("valid"); + + assert_eq!(res.0, ValidTransaction::default()); + } +} diff --git a/substrate/test-utils/runtime/src/extrinsic.rs b/substrate/test-utils/runtime/src/extrinsic.rs index 491086bef497..49dc6ba035c9 100644 --- a/substrate/test-utils/runtime/src/extrinsic.rs +++ b/substrate/test-utils/runtime/src/extrinsic.rs @@ -212,6 +212,7 @@ impl ExtrinsicBuilder { self.metadata_hash .map(CheckMetadataHash::new_with_custom_hash) .unwrap_or_else(|| CheckMetadataHash::new(false)), + frame_system::WeightReclaim::new(), ); let raw_payload = SignedPayload::from_raw( self.function.clone(), diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index 666776865316..4d24354f99a7 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -155,6 +155,7 @@ pub type TxExtension = ( (CheckNonce, CheckWeight), CheckSubstrateCall, frame_metadata_hash_extension::CheckMetadataHash, + frame_system::WeightReclaim, ); /// The payload being signed in transactions. pub type SignedPayload = sp_runtime::generic::SignedPayload; diff --git a/templates/minimal/runtime/src/lib.rs b/templates/minimal/runtime/src/lib.rs index 72eded5bfd13..972c7500f399 100644 --- a/templates/minimal/runtime/src/lib.rs +++ b/templates/minimal/runtime/src/lib.rs @@ -118,6 +118,10 @@ type TxExtension = ( // Ensures that the sender has enough funds to pay for the transaction // and deducts the fee from the sender's account. pallet_transaction_payment::ChargeTransactionPayment, + // Reclaim the unused weight from the block using post dispatch information. + // It must be last in the pipeline in order to catch the refund in previous transaction + // extensions + frame_system::WeightReclaim, ); // Composes the runtime by adding all the used pallets and deriving necessary types. diff --git a/templates/parachain/runtime/Cargo.toml b/templates/parachain/runtime/Cargo.toml index 9a0548106ed7..83d7bf4c9b72 100644 --- a/templates/parachain/runtime/Cargo.toml +++ b/templates/parachain/runtime/Cargo.toml @@ -48,11 +48,11 @@ polkadot-sdk = { workspace = true, default-features = false, features = [ "cumulus-pallet-aura-ext", "cumulus-pallet-session-benchmarking", + "cumulus-pallet-weight-reclaim", "cumulus-pallet-xcm", "cumulus-pallet-xcmp-queue", "cumulus-primitives-aura", "cumulus-primitives-core", - "cumulus-primitives-storage-weight-reclaim", "cumulus-primitives-utility", "pallet-collator-selection", "parachains-common", diff --git a/templates/parachain/runtime/src/benchmarks.rs b/templates/parachain/runtime/src/benchmarks.rs index aae50e7258c0..ca9d423bf856 100644 --- a/templates/parachain/runtime/src/benchmarks.rs +++ b/templates/parachain/runtime/src/benchmarks.rs @@ -33,4 +33,5 @@ polkadot_sdk::frame_benchmarking::define_benchmarks!( [pallet_collator_selection, CollatorSelection] [cumulus_pallet_parachain_system, ParachainSystem] [cumulus_pallet_xcmp_queue, XcmpQueue] + [cumulus_pallet_weight_reclaim, WeightReclaim] ); diff --git a/templates/parachain/runtime/src/configs/mod.rs b/templates/parachain/runtime/src/configs/mod.rs index ba4c71c7f218..1e9155f59a57 100644 --- a/templates/parachain/runtime/src/configs/mod.rs +++ b/templates/parachain/runtime/src/configs/mod.rs @@ -129,6 +129,11 @@ impl frame_system::Config for Runtime { type MaxConsumers = frame_support::traits::ConstU32<16>; } +/// Configure the palelt weight reclaim tx. +impl cumulus_pallet_weight_reclaim::Config for Runtime { + type WeightInfo = (); +} + impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. type Moment = u64; diff --git a/templates/parachain/runtime/src/lib.rs b/templates/parachain/runtime/src/lib.rs index 9669237af785..0be27ecce739 100644 --- a/templates/parachain/runtime/src/lib.rs +++ b/templates/parachain/runtime/src/lib.rs @@ -75,18 +75,20 @@ pub type BlockId = generic::BlockId; /// The extension to the basic transaction logic. #[docify::export(template_signed_extra)] -pub type TxExtension = ( - frame_system::CheckNonZeroSender, - frame_system::CheckSpecVersion, - frame_system::CheckTxVersion, - frame_system::CheckGenesis, - frame_system::CheckEra, - frame_system::CheckNonce, - frame_system::CheckWeight, - pallet_transaction_payment::ChargeTransactionPayment, - cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim, - frame_metadata_hash_extension::CheckMetadataHash, -); +pub type TxExtension = cumulus_pallet_weight_reclaim::StorageWeightReclaim< + Runtime, + ( + frame_system::CheckNonZeroSender, + frame_system::CheckSpecVersion, + frame_system::CheckTxVersion, + frame_system::CheckGenesis, + frame_system::CheckEra, + frame_system::CheckNonce, + frame_system::CheckWeight, + pallet_transaction_payment::ChargeTransactionPayment, + frame_metadata_hash_extension::CheckMetadataHash, + ), +>; /// Unchecked extrinsic type as expected by this runtime. pub type UncheckedExtrinsic = @@ -272,6 +274,8 @@ mod runtime { pub type Timestamp = pallet_timestamp; #[runtime::pallet_index(3)] pub type ParachainInfo = parachain_info; + #[runtime::pallet_index(4)] + pub type WeightReclaim = cumulus_pallet_weight_reclaim; // Monetary stuff. #[runtime::pallet_index(10)] diff --git a/templates/solochain/node/src/benchmarking.rs b/templates/solochain/node/src/benchmarking.rs index 0d60230cd19c..467cad4c0aaa 100644 --- a/templates/solochain/node/src/benchmarking.rs +++ b/templates/solochain/node/src/benchmarking.rs @@ -122,6 +122,7 @@ pub fn create_benchmark_extrinsic( frame_system::CheckWeight::::new(), pallet_transaction_payment::ChargeTransactionPayment::::from(0), frame_metadata_hash_extension::CheckMetadataHash::::new(false), + frame_system::WeightReclaim::::new(), ); let raw_payload = runtime::SignedPayload::from_raw( @@ -137,6 +138,7 @@ pub fn create_benchmark_extrinsic( (), (), None, + (), ), ); let signature = raw_payload.using_encoded(|e| sender.sign(e)); diff --git a/templates/solochain/runtime/src/lib.rs b/templates/solochain/runtime/src/lib.rs index ae0ea16ae42e..6a2149ec8b63 100644 --- a/templates/solochain/runtime/src/lib.rs +++ b/templates/solochain/runtime/src/lib.rs @@ -157,6 +157,7 @@ pub type TxExtension = ( frame_system::CheckWeight, pallet_transaction_payment::ChargeTransactionPayment, frame_metadata_hash_extension::CheckMetadataHash, + frame_system::WeightReclaim, ); /// Unchecked extrinsic type as expected by this runtime. diff --git a/umbrella/Cargo.toml b/umbrella/Cargo.toml index d2a47ade7f87..17a7c02e8259 100644 --- a/umbrella/Cargo.toml +++ b/umbrella/Cargo.toml @@ -29,6 +29,7 @@ std = [ "cumulus-pallet-parachain-system?/std", "cumulus-pallet-session-benchmarking?/std", "cumulus-pallet-solo-to-para?/std", + "cumulus-pallet-weight-reclaim?/std", "cumulus-pallet-xcm?/std", "cumulus-pallet-xcmp-queue?/std", "cumulus-ping?/std", @@ -239,6 +240,7 @@ runtime-benchmarks = [ "cumulus-pallet-dmp-queue?/runtime-benchmarks", "cumulus-pallet-parachain-system?/runtime-benchmarks", "cumulus-pallet-session-benchmarking?/runtime-benchmarks", + "cumulus-pallet-weight-reclaim?/runtime-benchmarks", "cumulus-pallet-xcmp-queue?/runtime-benchmarks", "cumulus-primitives-core?/runtime-benchmarks", "cumulus-primitives-utility?/runtime-benchmarks", @@ -369,6 +371,7 @@ try-runtime = [ "cumulus-pallet-dmp-queue?/try-runtime", "cumulus-pallet-parachain-system?/try-runtime", "cumulus-pallet-solo-to-para?/try-runtime", + "cumulus-pallet-weight-reclaim?/try-runtime", "cumulus-pallet-xcm?/try-runtime", "cumulus-pallet-xcmp-queue?/try-runtime", "cumulus-ping?/try-runtime", @@ -540,7 +543,7 @@ with-tracing = [ "sp-tracing?/with-tracing", "sp-tracing?/with-tracing", ] -runtime-full = ["assets-common", "binary-merkle-tree", "bp-header-chain", "bp-messages", "bp-parachains", "bp-polkadot", "bp-polkadot-core", "bp-relayers", "bp-runtime", "bp-test-utils", "bp-xcm-bridge-hub", "bp-xcm-bridge-hub-router", "bridge-hub-common", "bridge-runtime-common", "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", "cumulus-pallet-parachain-system", "cumulus-pallet-parachain-system-proc-macro", "cumulus-pallet-session-benchmarking", "cumulus-pallet-solo-to-para", "cumulus-pallet-xcm", "cumulus-pallet-xcmp-queue", "cumulus-ping", "cumulus-primitives-aura", "cumulus-primitives-core", "cumulus-primitives-parachain-inherent", "cumulus-primitives-proof-size-hostfunction", "cumulus-primitives-storage-weight-reclaim", "cumulus-primitives-timestamp", "cumulus-primitives-utility", "frame-benchmarking", "frame-benchmarking-pallet-pov", "frame-election-provider-solution-type", "frame-election-provider-support", "frame-executive", "frame-metadata-hash-extension", "frame-support", "frame-support-procedural", "frame-support-procedural-tools-derive", "frame-system", "frame-system-benchmarking", "frame-system-rpc-runtime-api", "frame-try-runtime", "pallet-alliance", "pallet-asset-conversion", "pallet-asset-conversion-ops", "pallet-asset-conversion-tx-payment", "pallet-asset-rate", "pallet-asset-tx-payment", "pallet-assets", "pallet-assets-freezer", "pallet-atomic-swap", "pallet-aura", "pallet-authority-discovery", "pallet-authorship", "pallet-babe", "pallet-bags-list", "pallet-balances", "pallet-beefy", "pallet-beefy-mmr", "pallet-bounties", "pallet-bridge-grandpa", "pallet-bridge-messages", "pallet-bridge-parachains", "pallet-bridge-relayers", "pallet-broker", "pallet-child-bounties", "pallet-collator-selection", "pallet-collective", "pallet-collective-content", "pallet-contracts", "pallet-contracts-proc-macro", "pallet-contracts-uapi", "pallet-conviction-voting", "pallet-core-fellowship", "pallet-delegated-staking", "pallet-democracy", "pallet-dev-mode", "pallet-election-provider-multi-phase", "pallet-election-provider-support-benchmarking", "pallet-elections-phragmen", "pallet-fast-unstake", "pallet-glutton", "pallet-grandpa", "pallet-identity", "pallet-im-online", "pallet-indices", "pallet-insecure-randomness-collective-flip", "pallet-lottery", "pallet-membership", "pallet-message-queue", "pallet-migrations", "pallet-mixnet", "pallet-mmr", "pallet-multisig", "pallet-nft-fractionalization", "pallet-nfts", "pallet-nfts-runtime-api", "pallet-nis", "pallet-node-authorization", "pallet-nomination-pools", "pallet-nomination-pools-benchmarking", "pallet-nomination-pools-runtime-api", "pallet-offences", "pallet-offences-benchmarking", "pallet-paged-list", "pallet-parameters", "pallet-preimage", "pallet-proxy", "pallet-ranked-collective", "pallet-recovery", "pallet-referenda", "pallet-remark", "pallet-revive", "pallet-revive-proc-macro", "pallet-revive-uapi", "pallet-root-offences", "pallet-root-testing", "pallet-safe-mode", "pallet-salary", "pallet-scheduler", "pallet-scored-pool", "pallet-session", "pallet-session-benchmarking", "pallet-skip-feeless-payment", "pallet-society", "pallet-staking", "pallet-staking-reward-curve", "pallet-staking-reward-fn", "pallet-staking-runtime-api", "pallet-state-trie-migration", "pallet-statement", "pallet-sudo", "pallet-timestamp", "pallet-tips", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", "pallet-transaction-storage", "pallet-treasury", "pallet-tx-pause", "pallet-uniques", "pallet-utility", "pallet-verify-signature", "pallet-vesting", "pallet-whitelist", "pallet-xcm", "pallet-xcm-benchmarks", "pallet-xcm-bridge-hub", "pallet-xcm-bridge-hub-router", "parachains-common", "polkadot-core-primitives", "polkadot-parachain-primitives", "polkadot-primitives", "polkadot-runtime-common", "polkadot-runtime-metrics", "polkadot-runtime-parachains", "polkadot-sdk-frame", "sc-chain-spec-derive", "sc-tracing-proc-macro", "slot-range-helper", "snowbridge-beacon-primitives", "snowbridge-core", "snowbridge-ethereum", "snowbridge-outbound-queue-merkle-tree", "snowbridge-outbound-queue-runtime-api", "snowbridge-pallet-ethereum-client", "snowbridge-pallet-ethereum-client-fixtures", "snowbridge-pallet-inbound-queue", "snowbridge-pallet-inbound-queue-fixtures", "snowbridge-pallet-outbound-queue", "snowbridge-pallet-system", "snowbridge-router-primitives", "snowbridge-runtime-common", "snowbridge-system-runtime-api", "sp-api", "sp-api-proc-macro", "sp-application-crypto", "sp-arithmetic", "sp-authority-discovery", "sp-block-builder", "sp-consensus-aura", "sp-consensus-babe", "sp-consensus-beefy", "sp-consensus-grandpa", "sp-consensus-pow", "sp-consensus-slots", "sp-core", "sp-crypto-ec-utils", "sp-crypto-hashing", "sp-crypto-hashing-proc-macro", "sp-debug-derive", "sp-externalities", "sp-genesis-builder", "sp-inherents", "sp-io", "sp-keyring", "sp-keystore", "sp-metadata-ir", "sp-mixnet", "sp-mmr-primitives", "sp-npos-elections", "sp-offchain", "sp-runtime", "sp-runtime-interface", "sp-runtime-interface-proc-macro", "sp-session", "sp-staking", "sp-state-machine", "sp-statement-store", "sp-std", "sp-storage", "sp-timestamp", "sp-tracing", "sp-transaction-pool", "sp-transaction-storage-proof", "sp-trie", "sp-version", "sp-version-proc-macro", "sp-wasm-interface", "sp-weights", "staging-parachain-info", "staging-xcm", "staging-xcm-builder", "staging-xcm-executor", "substrate-bip39", "testnet-parachains-constants", "tracing-gum-proc-macro", "xcm-procedural", "xcm-runtime-apis"] +runtime-full = ["assets-common", "binary-merkle-tree", "bp-header-chain", "bp-messages", "bp-parachains", "bp-polkadot", "bp-polkadot-core", "bp-relayers", "bp-runtime", "bp-test-utils", "bp-xcm-bridge-hub", "bp-xcm-bridge-hub-router", "bridge-hub-common", "bridge-runtime-common", "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", "cumulus-pallet-parachain-system", "cumulus-pallet-parachain-system-proc-macro", "cumulus-pallet-session-benchmarking", "cumulus-pallet-solo-to-para", "cumulus-pallet-weight-reclaim", "cumulus-pallet-xcm", "cumulus-pallet-xcmp-queue", "cumulus-ping", "cumulus-primitives-aura", "cumulus-primitives-core", "cumulus-primitives-parachain-inherent", "cumulus-primitives-proof-size-hostfunction", "cumulus-primitives-storage-weight-reclaim", "cumulus-primitives-timestamp", "cumulus-primitives-utility", "frame-benchmarking", "frame-benchmarking-pallet-pov", "frame-election-provider-solution-type", "frame-election-provider-support", "frame-executive", "frame-metadata-hash-extension", "frame-support", "frame-support-procedural", "frame-support-procedural-tools-derive", "frame-system", "frame-system-benchmarking", "frame-system-rpc-runtime-api", "frame-try-runtime", "pallet-alliance", "pallet-asset-conversion", "pallet-asset-conversion-ops", "pallet-asset-conversion-tx-payment", "pallet-asset-rate", "pallet-asset-tx-payment", "pallet-assets", "pallet-assets-freezer", "pallet-atomic-swap", "pallet-aura", "pallet-authority-discovery", "pallet-authorship", "pallet-babe", "pallet-bags-list", "pallet-balances", "pallet-beefy", "pallet-beefy-mmr", "pallet-bounties", "pallet-bridge-grandpa", "pallet-bridge-messages", "pallet-bridge-parachains", "pallet-bridge-relayers", "pallet-broker", "pallet-child-bounties", "pallet-collator-selection", "pallet-collective", "pallet-collective-content", "pallet-contracts", "pallet-contracts-proc-macro", "pallet-contracts-uapi", "pallet-conviction-voting", "pallet-core-fellowship", "pallet-delegated-staking", "pallet-democracy", "pallet-dev-mode", "pallet-election-provider-multi-phase", "pallet-election-provider-support-benchmarking", "pallet-elections-phragmen", "pallet-fast-unstake", "pallet-glutton", "pallet-grandpa", "pallet-identity", "pallet-im-online", "pallet-indices", "pallet-insecure-randomness-collective-flip", "pallet-lottery", "pallet-membership", "pallet-message-queue", "pallet-migrations", "pallet-mixnet", "pallet-mmr", "pallet-multisig", "pallet-nft-fractionalization", "pallet-nfts", "pallet-nfts-runtime-api", "pallet-nis", "pallet-node-authorization", "pallet-nomination-pools", "pallet-nomination-pools-benchmarking", "pallet-nomination-pools-runtime-api", "pallet-offences", "pallet-offences-benchmarking", "pallet-paged-list", "pallet-parameters", "pallet-preimage", "pallet-proxy", "pallet-ranked-collective", "pallet-recovery", "pallet-referenda", "pallet-remark", "pallet-revive", "pallet-revive-proc-macro", "pallet-revive-uapi", "pallet-root-offences", "pallet-root-testing", "pallet-safe-mode", "pallet-salary", "pallet-scheduler", "pallet-scored-pool", "pallet-session", "pallet-session-benchmarking", "pallet-skip-feeless-payment", "pallet-society", "pallet-staking", "pallet-staking-reward-curve", "pallet-staking-reward-fn", "pallet-staking-runtime-api", "pallet-state-trie-migration", "pallet-statement", "pallet-sudo", "pallet-timestamp", "pallet-tips", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", "pallet-transaction-storage", "pallet-treasury", "pallet-tx-pause", "pallet-uniques", "pallet-utility", "pallet-verify-signature", "pallet-vesting", "pallet-whitelist", "pallet-xcm", "pallet-xcm-benchmarks", "pallet-xcm-bridge-hub", "pallet-xcm-bridge-hub-router", "parachains-common", "polkadot-core-primitives", "polkadot-parachain-primitives", "polkadot-primitives", "polkadot-runtime-common", "polkadot-runtime-metrics", "polkadot-runtime-parachains", "polkadot-sdk-frame", "sc-chain-spec-derive", "sc-tracing-proc-macro", "slot-range-helper", "snowbridge-beacon-primitives", "snowbridge-core", "snowbridge-ethereum", "snowbridge-outbound-queue-merkle-tree", "snowbridge-outbound-queue-runtime-api", "snowbridge-pallet-ethereum-client", "snowbridge-pallet-ethereum-client-fixtures", "snowbridge-pallet-inbound-queue", "snowbridge-pallet-inbound-queue-fixtures", "snowbridge-pallet-outbound-queue", "snowbridge-pallet-system", "snowbridge-router-primitives", "snowbridge-runtime-common", "snowbridge-system-runtime-api", "sp-api", "sp-api-proc-macro", "sp-application-crypto", "sp-arithmetic", "sp-authority-discovery", "sp-block-builder", "sp-consensus-aura", "sp-consensus-babe", "sp-consensus-beefy", "sp-consensus-grandpa", "sp-consensus-pow", "sp-consensus-slots", "sp-core", "sp-crypto-ec-utils", "sp-crypto-hashing", "sp-crypto-hashing-proc-macro", "sp-debug-derive", "sp-externalities", "sp-genesis-builder", "sp-inherents", "sp-io", "sp-keyring", "sp-keystore", "sp-metadata-ir", "sp-mixnet", "sp-mmr-primitives", "sp-npos-elections", "sp-offchain", "sp-runtime", "sp-runtime-interface", "sp-runtime-interface-proc-macro", "sp-session", "sp-staking", "sp-state-machine", "sp-statement-store", "sp-std", "sp-storage", "sp-timestamp", "sp-tracing", "sp-transaction-pool", "sp-transaction-storage-proof", "sp-trie", "sp-version", "sp-version-proc-macro", "sp-wasm-interface", "sp-weights", "staging-parachain-info", "staging-xcm", "staging-xcm-builder", "staging-xcm-executor", "substrate-bip39", "testnet-parachains-constants", "tracing-gum-proc-macro", "xcm-procedural", "xcm-runtime-apis"] runtime = [ "frame-benchmarking", "frame-benchmarking-pallet-pov", @@ -722,6 +725,11 @@ default-features = false optional = true path = "../cumulus/pallets/solo-to-para" +[dependencies.cumulus-pallet-weight-reclaim] +default-features = false +optional = true +path = "../cumulus/pallets/weight-reclaim" + [dependencies.cumulus-pallet-xcm] default-features = false optional = true diff --git a/umbrella/src/lib.rs b/umbrella/src/lib.rs index 7b3c869588f0..3504f081f295 100644 --- a/umbrella/src/lib.rs +++ b/umbrella/src/lib.rs @@ -141,6 +141,10 @@ pub use cumulus_pallet_session_benchmarking; #[cfg(feature = "cumulus-pallet-solo-to-para")] pub use cumulus_pallet_solo_to_para; +/// pallet and transaction extensions for accurate proof size reclaim. +#[cfg(feature = "cumulus-pallet-weight-reclaim")] +pub use cumulus_pallet_weight_reclaim; + /// Pallet for stuff specific to parachains' usage of XCM. #[cfg(feature = "cumulus-pallet-xcm")] pub use cumulus_pallet_xcm;