From c242ebc2e97add5fc8e8811288c770b78a3b35db Mon Sep 17 00:00:00 2001 From: Ivan Cholakov Date: Wed, 21 Feb 2024 12:42:42 +0200 Subject: [PATCH] fix: upgrade node, runtime and services (#349) --- .github/workflows/cargo-build.yml | 2 +- .github/workflows/cargo-check.yml | 2 +- .github/workflows/cargo-test.yml | 6 +- .maintain/frame-weight-template.hbs | 62 +-- Cargo.toml | 3 +- node/Cargo.toml | 128 +++--- node/avn-lower-rpc/Cargo.toml | 16 +- node/avn-service/Cargo.toml | 47 ++- node/avn-service/src/extrinsic_utils.rs | 31 +- node/src/chain_spec/stable/mod.rs | 17 +- node/src/cli.rs | 2 +- node/src/command.rs | 192 ++++----- node/src/common.rs | 6 +- node/src/key/insert_avn_key.rs | 17 +- node/src/rpc.rs | 2 +- node/src/service.rs | 105 ++--- runtime/avn/Cargo.toml | 129 +++--- runtime/avn/build.rs | 14 +- runtime/avn/src/lib.rs | 371 +++++++----------- runtime/avn/src/xcm_config.rs | 310 +++++++-------- runtime/common/Cargo.toml | 14 +- runtime/common/src/weights/block_weights.rs | 2 +- .../common/src/weights/extrinsic_weights.rs | 2 +- runtime/test/Cargo.toml | 135 ++++--- runtime/test/build.rs | 14 +- runtime/test/src/lib.rs | 207 +++------- runtime/test/src/xcm_config.rs | 152 +++---- 27 files changed, 883 insertions(+), 1105 deletions(-) diff --git a/.github/workflows/cargo-build.yml b/.github/workflows/cargo-build.yml index 2a92d7e0e..d50c976ba 100644 --- a/.github/workflows/cargo-build.yml +++ b/.github/workflows/cargo-build.yml @@ -22,7 +22,7 @@ jobs: uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: nightly-2022-10-18 + toolchain: nightly-2023-05-22 components: rustfmt, clippy target: wasm32-unknown-unknown override: true diff --git a/.github/workflows/cargo-check.yml b/.github/workflows/cargo-check.yml index 8cb4e0db3..4e27c970b 100644 --- a/.github/workflows/cargo-check.yml +++ b/.github/workflows/cargo-check.yml @@ -32,7 +32,7 @@ jobs: uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: nightly-2022-10-18 + toolchain: nightly-2023-05-22 components: rustfmt, clippy target: wasm32-unknown-unknown override: true diff --git a/.github/workflows/cargo-test.yml b/.github/workflows/cargo-test.yml index b1d4e5d63..7f4207b94 100644 --- a/.github/workflows/cargo-test.yml +++ b/.github/workflows/cargo-test.yml @@ -33,7 +33,7 @@ jobs: uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: nightly-2022-10-18 + toolchain: nightly-2023-05-22 components: rustfmt, clippy target: wasm32-unknown-unknown override: true @@ -68,7 +68,7 @@ jobs: uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: nightly-2022-10-18 + toolchain: nightly-2023-05-22 components: rustfmt, clippy target: wasm32-unknown-unknown override: true @@ -110,7 +110,7 @@ jobs: uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: nightly-2022-10-18 + toolchain: nightly-2023-05-22 components: rustfmt, clippy target: wasm32-unknown-unknown override: true diff --git a/.maintain/frame-weight-template.hbs b/.maintain/frame-weight-template.hbs index d9bf4222a..22860d53e 100644 --- a/.maintain/frame-weight-template.hbs +++ b/.maintain/frame-weight-template.hbs @@ -1,26 +1,11 @@ -// This file is part of Substrate. - -// Copyright (C) 2022 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. - +{{header}} //! Autogenerated weights for {{pallet}} //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION {{version}} -//! DATE: {{date}}, STEPS: `{{cmd.steps}}`, REPEAT: {{cmd.repeat}}, LOW RANGE: `{{cmd.lowest_range_values}}`, HIGH RANGE: `{{cmd.highest_range_values}}` +//! DATE: {{date}}, STEPS: `{{cmd.steps}}`, REPEAT: `{{cmd.repeat}}`, LOW RANGE: `{{cmd.lowest_range_values}}`, HIGH RANGE: `{{cmd.highest_range_values}}` +//! WORST CASE MAP SIZE: `{{cmd.worst_case_map_values}}` //! HOSTNAME: `{{hostname}}`, CPU: `{{cpuname}}` -//! EXECUTION: {{cmd.execution}}, WASM-EXECUTION: {{cmd.wasm_execution}}, CHAIN: {{cmd.chain}}, DB CACHE: {{cmd.db_cache}} +//! EXECUTION: `{{cmd.execution}}`, WASM-EXECUTION: `{{cmd.wasm_execution}}`, CHAIN: `{{cmd.chain}}`, DB CACHE: `{{cmd.db_cache}}` // Executed Command: {{#each args as |arg|}} @@ -30,9 +15,10 @@ #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] +#![allow(missing_docs)] use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; -use sp_std::marker::PhantomData; +use core::marker::PhantomData; /// Weight functions needed for {{pallet}}. pub trait WeightInfo { @@ -54,7 +40,7 @@ impl WeightInfo for SubstrateWeight { {{/if}} {{#each benchmarks as |benchmark|}} {{#each benchmark.comments as |comment|}} - // {{comment}} + /// {{comment}} {{/each}} {{#each benchmark.component_ranges as |range|}} /// The range of component `{{range.name}}` is `[{{range.min}}, {{range.max}}]`. @@ -64,32 +50,39 @@ impl WeightInfo for SubstrateWeight { {{~#each benchmark.components as |c| ~}} {{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}} ) -> Weight { - Weight::from_ref_time({{underscore benchmark.base_weight}}) + // Proof Size summary in bytes: + // Measured: `{{benchmark.base_recorded_proof_size}}{{#each benchmark.component_recorded_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}` + // Estimated: `{{benchmark.base_calculated_proof_size}}{{#each benchmark.component_calculated_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}` + // Minimum execution time: {{underscore benchmark.min_execution_time}}_000 picoseconds. + Weight::from_parts({{underscore benchmark.base_weight}}, {{benchmark.base_calculated_proof_size}}) {{#each benchmark.component_weight as |cw|}} // Standard Error: {{underscore cw.error}} - .saturating_add(Weight::from_ref_time({{underscore cw.slope}}).saturating_mul({{cw.name}}.into())) + .saturating_add(Weight::from_parts({{underscore cw.slope}}, 0).saturating_mul({{cw.name}}.into())) {{/each}} {{#if (ne benchmark.base_reads "0")}} - .saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}})) + .saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}}_u64)) {{/if}} {{#each benchmark.component_reads as |cr|}} .saturating_add(T::DbWeight::get().reads(({{cr.slope}}_u64).saturating_mul({{cr.name}}.into()))) {{/each}} {{#if (ne benchmark.base_writes "0")}} - .saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}})) + .saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}}_u64)) {{/if}} {{#each benchmark.component_writes as |cw|}} .saturating_add(T::DbWeight::get().writes(({{cw.slope}}_u64).saturating_mul({{cw.name}}.into()))) {{/each}} + {{#each benchmark.component_calculated_proof_size as |cp|}} + .saturating_add(Weight::from_parts(0, {{cp.slope}}).saturating_mul({{cp.name}}.into())) + {{/each}} } {{/each}} } -// For backwards compatibility and tests +// For backwards compatibility and tests. impl WeightInfo for () { {{#each benchmarks as |benchmark|}} {{#each benchmark.comments as |comment|}} - // {{comment}} + /// {{comment}} {{/each}} {{#each benchmark.component_ranges as |range|}} /// The range of component `{{range.name}}` is `[{{range.min}}, {{range.max}}]`. @@ -99,23 +92,30 @@ impl WeightInfo for () { {{~#each benchmark.components as |c| ~}} {{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}} ) -> Weight { - Weight::from_ref_time({{underscore benchmark.base_weight}}) + // Proof Size summary in bytes: + // Measured: `{{benchmark.base_recorded_proof_size}}{{#each benchmark.component_recorded_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}` + // Estimated: `{{benchmark.base_calculated_proof_size}}{{#each benchmark.component_calculated_proof_size as |cp|}} + {{cp.name}} * ({{cp.slope}} ±{{underscore cp.error}}){{/each}}` + // Minimum execution time: {{underscore benchmark.min_execution_time}}_000 picoseconds. + Weight::from_parts({{underscore benchmark.base_weight}}, {{benchmark.base_calculated_proof_size}}) {{#each benchmark.component_weight as |cw|}} // Standard Error: {{underscore cw.error}} - .saturating_add(Weight::from_ref_time({{underscore cw.slope}}).saturating_mul({{cw.name}}.into())) + .saturating_add(Weight::from_parts({{underscore cw.slope}}, 0).saturating_mul({{cw.name}}.into())) {{/each}} {{#if (ne benchmark.base_reads "0")}} - .saturating_add(RocksDbWeight::get().reads({{benchmark.base_reads}})) + .saturating_add(RocksDbWeight::get().reads({{benchmark.base_reads}}_u64)) {{/if}} {{#each benchmark.component_reads as |cr|}} .saturating_add(RocksDbWeight::get().reads(({{cr.slope}}_u64).saturating_mul({{cr.name}}.into()))) {{/each}} {{#if (ne benchmark.base_writes "0")}} - .saturating_add(RocksDbWeight::get().writes({{benchmark.base_writes}})) + .saturating_add(RocksDbWeight::get().writes({{benchmark.base_writes}}_u64)) {{/if}} {{#each benchmark.component_writes as |cw|}} .saturating_add(RocksDbWeight::get().writes(({{cw.slope}}_u64).saturating_mul({{cw.name}}.into()))) {{/each}} + {{#each benchmark.component_calculated_proof_size as |cp|}} + .saturating_add(Weight::from_parts(0, {{cp.slope}}).saturating_mul({{cp.name}}.into())) + {{/each}} } {{/each}} } \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index dd481d823..e02ce4634 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,9 +17,10 @@ authors = ["Aventus systems team"] homepage = "https://www.aventus.io/" repository = "https://github.com/Aventus-Network-Services/avn-node-parachain/" edition = "2021" -rust-version = "1.64.0" +rust-version = "1.70.0" [workspace] +resolver = "2" members = [ "node", "node/avn-service", diff --git a/node/Cargo.toml b/node/Cargo.toml index d44370759..41cc8a52f 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -16,15 +16,15 @@ name = "avn-parachain-collator" path = "src/main.rs" [dependencies] -clap = { version = "4.0.29", features = ["derive"] } +clap = { version = "4.2.5", features = ["derive"] } log = "0.4.17" -codec = { package = "parity-scale-codec", version = "3.0.0" } -serde = { version = "1.0.151", features = ["derive"] } +codec = { package = "parity-scale-codec", version = "3.6.1" } +serde = { version = "1.0.163", features = ["derive"] } jsonrpsee = { version = "0.16.2", features = ["server"] } -hex-literal = "0.3.4" +hex-literal = "0.4.1" hex = "0.4" -serde_json = "1.0" -futures = "0.3.24" +serde_json = "1.0.85" +futures = "0.3.21" cfg-if = "0.1" # Local @@ -33,74 +33,76 @@ avn-parachain-runtime = { path = "../runtime/avn", optional = true } avn-test-runtime = { package = "avn-parachain-test-runtime", path = "../runtime/test", optional = true } # Substrate -frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sc-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sc-executor = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sc-keystore = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sc-network = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sc-network-common = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sc-service = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sc-sysinfo = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sc-telemetry = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sc-tracing = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sc-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-block-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-offchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-session = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -substrate-frame-rpc-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -try-runtime-cli = { git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.36" } -node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sc-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sc-offchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sc-executor = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sc-keystore = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sc-network = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sc-network-sync = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sc-network-common = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sc-service = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sc-sysinfo = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sc-telemetry = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sc-tracing = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sc-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sp-block-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sp-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sp-offchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sp-session = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +substrate-frame-rpc-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +try-runtime-cli = { git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v1.0.0" } +node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } # AvN dependencies -sp-authority-discovery = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } -pallet-im-online = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } +sp-authority-discovery = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } +pallet-im-online = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } sp-avn-common = { path = "../primitives/avn-common", default-features = false } # Polkadot -polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.36" } -polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.36" } -polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.36" } -xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.36" } +polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "release-v1.0.0" } +polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v1.0.0" } +polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "release-v1.0.0" } +xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v1.0.0" } # Cumulus -cumulus-client-cli = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.36" } -cumulus-client-consensus-aura = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.36" } -cumulus-client-consensus-common = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.36" } -cumulus-client-network = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.36" } -cumulus-client-service = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.36" } -cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.36" } -cumulus-primitives-parachain-inherent = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.36" } -cumulus-relay-chain-interface = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.36" } +cumulus-client-cli = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0" } +cumulus-client-consensus-aura = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0" } +cumulus-client-consensus-common = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0" } +cumulus-client-network = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0" } +cumulus-client-service = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0" } +cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0" } +cumulus-primitives-parachain-inherent = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0" } +cumulus-relay-chain-interface = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0" } # AvN -avn-service = { path = "avn-service"} -avn-lower-rpc = { path = "avn-lower-rpc"} +avn-service = { path = "avn-service" } +avn-lower-rpc = { path = "avn-lower-rpc" } pallet-avn = { path = "../pallets/avn", default-features = false } tiny-bip39 = "0.8.2" -libp2p = "0.46.1" -web3 = { version = "0.18.0", default-features = false, features = ["signing"]} +libp2p = { version = "0.51.3", default-features = false} +web3 = { version = "0.18.0", default-features = false, features = ["signing"] } [build-dependencies] -substrate-build-script-utils = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +substrate-build-script-utils = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } [features] default = ["avn-native-runtime"] @@ -117,9 +119,9 @@ try-runtime = [ ] rococo-spec-build = [] -avn-native-runtime= ["avn-parachain-runtime"] -test-native-runtime= ["avn-test-runtime"] +avn-native-runtime = ["avn-parachain-runtime"] +test-native-runtime = ["avn-test-runtime"] [dev-dependencies] tempfile = "3.1.0" -sp-version = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +sp-version = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } diff --git a/node/avn-lower-rpc/Cargo.toml b/node/avn-lower-rpc/Cargo.toml index 96341478e..45c9978f1 100644 --- a/node/avn-lower-rpc/Cargo.toml +++ b/node/avn-lower-rpc/Cargo.toml @@ -14,21 +14,21 @@ rust-version = { workspace = true } targets = ["x86_64-unknown-linux-gnu"] [dependencies] -codec = { package = "parity-scale-codec", version = "3.0.0" } +codec = { package = "parity-scale-codec", version = "3.6.1" } futures = "0.3.21" log = "0.4.17" parking_lot = "0.12.1" -scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -serde = { version = "1.0.136", features = ["derive"] } +scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } +serde = { version = "1.0.163", features = ["derive"], default-features = false} serde_json = "1.0.85" thiserror = "1.0" hex = "0.4" jsonrpsee = { version = "0.16.2", features = ["server"] } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } avn-service = { path = "../avn-service"} diff --git a/node/avn-service/Cargo.toml b/node/avn-service/Cargo.toml index fb91f182e..80018deeb 100644 --- a/node/avn-service/Cargo.toml +++ b/node/avn-service/Cargo.toml @@ -10,15 +10,18 @@ repository = { workspace = true } [dependencies] # third-party dependencies -codec = { package = "parity-scale-codec", version = "3.0.0" } +codec = { package = "parity-scale-codec", version = "3.6.1" } structopt = "0.3.8" -log = "0.4.8" -serde_json = "1.0" -serde = "1.0.143" -tide = { version = "0.16.0"} -web3 = { version = "0.18.0", default-features = false, features = ["http-tls", "signing"]} # implies tls feature +log = "0.4.17" +serde_json = "1.0.85" +serde = "1.0.163" +tide = { version = "0.16.0" } +web3 = { version = "0.18.0", default-features = false, features = [ + "http-tls", + "signing", +] } # implies tls feature jsonrpsee = { version = "0.16.2", features = ["server"] } -futures = "0.3.24" +futures = "0.3.21" anyhow = "1.0.64" jsonrpc-core = "18.0.0" @@ -26,23 +29,29 @@ jsonrpc-core = "18.0.0" tokio = { version = "1.19", features = ["sync"] } hex = "0.4" -secp256k1 = { version = "0.24.0", default-features = false, features = ["recovery", "alloc"]} -web3Secp256k1 = { package = "secp256k1", version = "0.21.2", default-features = false, features = ["recovery", "alloc"]} +secp256k1 = { version = "0.24.0", default-features = false, features = [ + "recovery", + "alloc", +] } +web3Secp256k1 = { package = "secp256k1", version = "0.21.2", default-features = false, features = [ + "recovery", + "alloc", +] } # This needs to be the same version as the one used in web3, parity-scale-codec and ethereum-transactions pallet ethereum-types = "0.11.0" # primitives -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } sp-avn-common = { path = "../../primitives/avn-common", default-features = false } -sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } # client dependencies -sc-keystore = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sc-service = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } -sc-client-db = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +sc-keystore = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sc-service = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } +sc-client-db = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } \ No newline at end of file +frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } diff --git a/node/avn-service/src/extrinsic_utils.rs b/node/avn-service/src/extrinsic_utils.rs index cce8166a1..30f420194 100644 --- a/node/avn-service/src/extrinsic_utils.rs +++ b/node/avn-service/src/extrinsic_utils.rs @@ -9,7 +9,7 @@ use log::{debug, error}; use sc_client_api::{client::BlockBackend, UsageProvider}; use serde::{Deserialize, Serialize}; use sp_runtime::{ - generic::{BlockId, SignedBlock}, + generic::{SignedBlock}, traits::{Block as BlockT, SaturatedConversion}, }; pub use std::sync::Arc; @@ -95,7 +95,33 @@ fn get_signed_block( where ClientT: BlockBackend + UsageProvider + Send + Sync + 'static, { - let maybe_block = client.block(&BlockId::Number(block_number.into())).map_err(|e| { + let block_hash_result = client.block_hash(block_number.into()); + + let block_hash = match block_hash_result { + Ok(Some(hash)) => hash, + Ok(None) => { + // Handle the case where no hash was found + let error_message = "No hash found for the given block number"; + error!("[RPC] {}", error_message); + return Err(JsonRpseeError::Call(CallError::Custom(ErrorObject::owned( + ErrorCode::ServerError(Error::ResponseError.into()).code(), + error_message.to_string(), + None::<()>, + )))); + }, + Err(e) => { + // Handle the error case + let error_message = "Error getting block hash"; + error!("[RPC] {}", error_message); + return Err(JsonRpseeError::Call(CallError::Custom(ErrorObject::owned( + ErrorCode::ServerError(Error::ResponseError.into()).code(), + error_message.to_string(), + Some(format!("{:?}", e)), + )))); + } + }; + + let maybe_block = client.block(block_hash).map_err(|e| { const ERROR_MESSAGE: &str = "Error getting block data"; error!("[RPC] {}", ERROR_MESSAGE); JsonRpseeError::Call(CallError::Custom(ErrorObject::owned( @@ -104,7 +130,6 @@ where Some(format!("{:?}", e)), ))) })?; - if maybe_block.is_none() { let error_message = format!("Data for block #{:?} is not found", block_number); error!("[RPC] {}", error_message); diff --git a/node/src/chain_spec/stable/mod.rs b/node/src/chain_spec/stable/mod.rs index 145500e33..4ca0e6ec5 100644 --- a/node/src/chain_spec/stable/mod.rs +++ b/node/src/chain_spec/stable/mod.rs @@ -20,7 +20,7 @@ use sp_core::{H160, H256}; use hex_literal::hex; /// Specialized `ChainSpec` for the normal parachain runtime. -pub type ChainSpec = sc_service::GenericChainSpec; +pub type ChainSpec = sc_service::GenericChainSpec; /// Generate the session keys from individual elements. /// @@ -52,8 +52,8 @@ pub(crate) fn testnet_genesis( event_challenge_period: BlockNumber, schedule_period: BlockNumber, voting_period: BlockNumber, -) -> avn_runtime::GenesisConfig { - avn_runtime::GenesisConfig { +) -> avn_runtime::RuntimeGenesisConfig { + avn_runtime::RuntimeGenesisConfig { avn: pallet_avn::GenesisConfig { _phantom: Default::default(), bridge_contract_address: avn_eth_contract.clone(), @@ -62,11 +62,12 @@ pub(crate) fn testnet_genesis( code: avn_runtime::WASM_BINARY .expect("WASM binary was not build, please build it!") .to_vec(), + ..Default::default() }, balances: avn_runtime::BalancesConfig { balances: endowed_accounts.iter().cloned().map(|(k, a)| (k, a)).collect(), }, - parachain_info: avn_runtime::ParachainInfoConfig { parachain_id: id }, + parachain_info: avn_runtime::ParachainInfoConfig { parachain_id: id, ..Default::default() }, session: avn_runtime::SessionConfig { keys: candidates .iter() @@ -79,6 +80,7 @@ pub(crate) fn testnet_genesis( ) }) .collect(), + ..Default::default() }, // no need to pass anything to aura, in fact it will panic if we do. Session will take care // of this. @@ -102,7 +104,7 @@ pub(crate) fn testnet_genesis( .zip(eth_public_keys.iter().map(|pk| pk.clone())) .collect::>(), }, - authority_discovery: AuthorityDiscoveryConfig { keys: vec![] }, + authority_discovery: AuthorityDiscoveryConfig { keys: vec![], ..Default::default() }, aura: Default::default(), aura_ext: Default::default(), im_online: ImOnlineConfig { keys: vec![] }, @@ -119,7 +121,10 @@ pub(crate) fn testnet_genesis( min_total_nominator_stake: 10 * AVT, delay: 2, }, - polkadot_xcm: avn_runtime::PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) }, + polkadot_xcm: avn_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + ..Default::default() + }, sudo: SudoConfig { key: Some(sudo_account) }, summary: SummaryConfig { schedule_period, voting_period }, token_manager: TokenManagerConfig { diff --git a/node/src/cli.rs b/node/src/cli.rs index de61a70d9..be3973761 100644 --- a/node/src/cli.rs +++ b/node/src/cli.rs @@ -122,7 +122,7 @@ impl RelayChainCli { ) -> Self { let extension = crate::chain_spec::Extensions::try_get(&*para_config.chain_spec); let chain_id = extension.map(|e| e.relay_chain.clone()); - let base_path = para_config.base_path.as_ref().map(|x| x.path().join("polkadot")); + let base_path = Some(para_config.base_path.path().join("polkadot")); Self { base_path, chain_id, base: clap::Parser::parse_from(relay_chain_args) } } } diff --git a/node/src/command.rs b/node/src/command.rs index 539d23964..f7780b94d 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -1,22 +1,19 @@ -use codec::Encode; -use cumulus_client_cli::generate_genesis_block; use cumulus_primitives_core::ParaId; use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE}; use log::{info, warn}; use sc_cli::{ ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, - NetworkParams, Result, RuntimeVersion, SharedParams, SubstrateCli, + NetworkParams, Result, SharedParams, SubstrateCli, }; use sc_service::config::{BasePath, PrometheusConfig}; -use sp_core::hexdisplay::HexDisplay; -use sp_runtime::traits::{AccountIdConversion, Block as BlockT}; +use sp_runtime::traits::{AccountIdConversion}; use std::net::SocketAddr; use crate::{ avn_config::*, chain_spec, cli::{Cli, RelayChainCli, Subcommand}, - common::{AvnRuntimeIdentity, Block, ParachainExecutor, RuntimeApi}, + common::{Block, ParachainExecutor, RuntimeApi}, service::new_partial, }; @@ -68,26 +65,6 @@ impl SubstrateCli for Cli { fn load_spec(&self, id: &str) -> std::result::Result, String> { load_spec(id) } - - fn native_runtime_version(chain_spec: &Box) -> &'static RuntimeVersion { - #[cfg(feature = "test-native-runtime")] - if chain_spec.is_test_runtime() { - return &avn_test_runtime::VERSION - } - - #[cfg(feature = "avn-parachain-runtime")] - if chain_spec.is_production() { - return &avn_parachain_runtime::VERSION - } - - #[cfg(feature = "avn-native-runtime")] - { - return &avn_parachain_runtime::VERSION - } - - #[cfg(not(feature = "avn-native-runtime"))] - panic!("Chain spec name/runtime mismatch with native runtime.") - } } impl SubstrateCli for RelayChainCli { @@ -124,10 +101,6 @@ impl SubstrateCli for RelayChainCli { fn load_spec(&self, id: &str) -> std::result::Result, String> { polkadot_cli::Cli::from_iter([RelayChainCli::executable_name()].iter()).load_spec(id) } - - fn native_runtime_version(chain_spec: &Box) -> &'static RuntimeVersion { - polkadot_cli::Cli::native_runtime_version(chain_spec) - } } macro_rules! construct_async_run { @@ -196,10 +169,10 @@ pub fn run() -> Result<()> { }, Some(Subcommand::ExportGenesisState(cmd)) => { let runner = cli.create_runner(cmd)?; - runner.sync_run(|_config| { - let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?; - let state_version = Cli::native_runtime_version(&spec).state_version(); - cmd.run::(&*spec, state_version) + runner.sync_run(|config| { + let partials = new_partial::(&config)?; + + cmd.run(&*config.chain_spec, &*partials.client) }) }, Some(Subcommand::ExportGenesisWasm(cmd)) => { @@ -215,7 +188,17 @@ pub fn run() -> Result<()> { match cmd { BenchmarkCmd::Pallet(cmd) => if cfg!(feature = "runtime-benchmarks") { - runner.sync_run(|config| cmd.run::(config)) + use sc_executor::{ + sp_wasm_interface::ExtendedHostFunctions, NativeExecutionDispatch, + }; + type HostFunctionsOf = ExtendedHostFunctions< + sp_io::SubstrateHostFunctions, + ::ExtendHostFunctions, + >; + + runner.sync_run(|config| { + cmd.run::>(config) + }) } else { Err("Benchmarking wasn't enabled when building the node. \ You can enable it with `--features runtime-benchmarks`." @@ -278,65 +261,64 @@ pub fn run() -> Result<()> { let collator_options = cli.run.collator_options(); runner.run_node_until_exit(|config| async move { - let hwbench = if !cli.no_hardware_benchmarks { - config.database.path().map(|database_path| { - let _ = std::fs::create_dir_all(&database_path); - sc_sysinfo::gather_hwbench(Some(database_path)) - }) - } else { - None - }; - - let para_id = chain_spec::Extensions::try_get(&*config.chain_spec) - .map(|e| e.para_id) - .ok_or_else(|| "Could not find parachain ID in chain-spec.")?; - - let polkadot_cli = RelayChainCli::new( - &config, - [RelayChainCli::executable_name()].iter().chain(cli.relay_chain_args.iter()), - ); - - let id = ParaId::from(para_id); - - let parachain_account = - AccountIdConversion::::into_account_truncating(&id); - - let state_version = Cli::native_runtime_version(&config.chain_spec).state_version(); - let block: Block = generate_genesis_block(&*config.chain_spec, state_version) - .map_err(|e| format!("{:?}", e))?; - let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode())); - - let tokio_handle = config.tokio_handle.clone(); - let polkadot_config = - SubstrateCli::create_configuration(&polkadot_cli, &polkadot_cli, tokio_handle) - .map_err(|err| format!("Relay chain argument error: {}", err))?; - - let avn_config = AvnCliConfiguration { - avn_port: cli.run.avn_port, - ethereum_node_url: cli.run.eth_node_url, - }; - - info!("Parachain id: {:?}", id); - info!("Parachain Account: {}", parachain_account); - info!("Parachain genesis state: {}", genesis_state); - info!("Is collating: {}", if config.role.is_authority() { "yes" } else { "no" }); - - if !collator_options.relay_chain_rpc_urls.is_empty() && cli.relay_chain_args.len() > 0 { - warn!("Detected relay chain node arguments together with --relay-chain-rpc-url. This command starts a minimal Polkadot node that only uses a network-related subset of all relay chain CLI options."); - } - - crate::service::start_parachain_node::( - config, - polkadot_config, - avn_config, - collator_options, - id, - hwbench, - ) - .await - .map(|r| r.0) - .map_err(Into::into) - }) + let hwbench = (!cli.no_hardware_benchmarks) + .then_some(config.database.path().map(|database_path| { + let _ = std::fs::create_dir_all(database_path); + sc_sysinfo::gather_hwbench(Some(database_path)) + })) + .flatten(); + + let para_id = chain_spec::Extensions::try_get(&*config.chain_spec) + .map(|e| e.para_id) + .ok_or("Could not find parachain ID in chain-spec.")?; + + let polkadot_cli = RelayChainCli::new( + &config, + [RelayChainCli::executable_name()].iter().chain(cli.relay_chain_args.iter()), + ); + + let id = ParaId::from(para_id); + + let parachain_account = + AccountIdConversion::::into_account_truncating( + &id, + ); + + let tokio_handle = config.tokio_handle.clone(); + let polkadot_config = + SubstrateCli::create_configuration(&polkadot_cli, &polkadot_cli, tokio_handle) + .map_err(|err| format!("Relay chain argument error: {}", err))?; + + let avn_config = AvnCliConfiguration { + avn_port: cli.run.avn_port, + ethereum_node_url: cli.run.eth_node_url, + }; + + info!("Parachain Account: {parachain_account}"); + info!("Is collating: {}", if config.role.is_authority() { "yes" } else { "no" }); + + if !collator_options.relay_chain_rpc_urls.is_empty() && + !cli.relay_chain_args.is_empty() + { + warn!( + "Detected relay chain node arguments together with --relay-chain-rpc-url. \ + This command starts a minimal Polkadot node that only uses a \ + network-related subset of all relay chain CLI options." + ); + } + + crate::service::start_parachain_node::( + config, + polkadot_config, + avn_config, + collator_options, + id, + hwbench, + ) + .await + .map(|r| r.0) + .map_err(Into::into) + }) }, } } @@ -346,14 +328,10 @@ impl DefaultConfigurationValues for RelayChainCli { 30334 } - fn rpc_ws_listen_port() -> u16 { + fn rpc_listen_port() -> u16 { 9945 } - fn rpc_http_listen_port() -> u16 { - 9934 - } - fn prometheus_listen_port() -> u16 { 9616 } @@ -383,16 +361,8 @@ impl CliConfiguration for RelayChainCli { .or_else(|| self.base_path.clone().map(Into::into))) } - fn rpc_http(&self, default_listen_port: u16) -> Result> { - self.base.base.rpc_http(default_listen_port) - } - - fn rpc_ipc(&self) -> Result> { - self.base.base.rpc_ipc() - } - - fn rpc_ws(&self, default_listen_port: u16) -> Result> { - self.base.base.rpc_ws(default_listen_port) + fn rpc_addr(&self, default_listen_port: u16) -> Result> { + self.base.base.rpc_addr(default_listen_port) } fn prometheus_config( @@ -438,8 +408,8 @@ impl CliConfiguration for RelayChainCli { self.base.base.rpc_methods() } - fn rpc_ws_max_connections(&self) -> Result> { - self.base.base.rpc_ws_max_connections() + fn rpc_max_connections(&self) -> Result { + self.base.base.rpc_max_connections() } fn rpc_cors(&self, is_dev: bool) -> Result>> { diff --git a/node/src/common.rs b/node/src/common.rs index 9c0e81a3d..a1eb28f8a 100644 --- a/node/src/common.rs +++ b/node/src/common.rs @@ -1,4 +1,4 @@ -use node_primitives::{AccountId, Balance, Block as BlockT, Index}; +use node_primitives::{AccountId, Balance, Block as BlockT, Nonce}; use polkadot_service::BlakeTwo256; use sp_consensus_aura::sr25519::AuthorityId as AuraId; @@ -20,7 +20,7 @@ pub trait AvnRuntimeApiCollection: sp_transaction_pool::runtime_api::TaggedTransactionQueue + sp_api::ApiExt + sp_block_builder::BlockBuilder - + substrate_frame_rpc_system::AccountNonceApi + + substrate_frame_rpc_system::AccountNonceApi + pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi + sp_api::Metadata + sp_offchain::OffchainWorkerApi @@ -37,7 +37,7 @@ where Api: sp_transaction_pool::runtime_api::TaggedTransactionQueue + sp_api::ApiExt + sp_block_builder::BlockBuilder - + substrate_frame_rpc_system::AccountNonceApi + + substrate_frame_rpc_system::AccountNonceApi + pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi + sp_api::Metadata + sp_offchain::OffchainWorkerApi diff --git a/node/src/key/insert_avn_key.rs b/node/src/key/insert_avn_key.rs index 2299af723..656483a6d 100644 --- a/node/src/key/insert_avn_key.rs +++ b/node/src/key/insert_avn_key.rs @@ -29,7 +29,7 @@ use sc_cli::{ use sc_keystore::LocalKeystore; use sc_service::config::{BasePath, KeystoreConfig}; use sp_core::crypto::{KeyTypeId, SecretString}; -use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr}; +use sp_keystore::{Keystore, KeystorePtr}; use std::sync::Arc; use web3::types::H160; @@ -97,8 +97,9 @@ impl InsertAvNKeyCmd { let chain_spec = cli.load_spec(&chain_id)?; let config_dir = base_path.config_dir(chain_spec.id()); - let (keystore, public) = match self.keystore_params.keystore_config(&config_dir)? { - (_, KeystoreConfig::Path { path, password }) => { + let keystore_config = self.keystore_params.keystore_config(&config_dir)?; + let (keystore, public) = match keystore_config { + KeystoreConfig::Path { path, password } => { let public: Vec = match self.scheme { AvNCryptoScheme::EcdsaSeed => get_public_key_string_bytes_from_private_key(suri.as_str())?, @@ -107,7 +108,7 @@ impl InsertAvNKeyCmd { to_vec(&suri, password.clone()) )?, }; - let keystore: SyncCryptoStorePtr = Arc::new(LocalKeystore::open(path, password)?); + let keystore: KeystorePtr = Arc::new(LocalKeystore::open(path, password)?); (keystore, public) }, _ => unreachable!("keystore_config always returns path and password; qed"), @@ -116,8 +117,8 @@ impl InsertAvNKeyCmd { let key_type = KeyTypeId::try_from(self.key_type.as_str()).map_err(|_| Error::KeyTypeInvalid)?; - SyncCryptoStore::insert_unknown(&*keystore, key_type, &suri, &public[..]) - .map_err(|_| Error::KeyStoreOperation)?; + Keystore::insert(&*keystore, key_type, &suri, &public[..]) + .map_err(|_| Error::KeystoreOperation)?; Ok(()) } @@ -179,10 +180,6 @@ mod tests { "test".into() } - fn native_runtime_version(_: &Box) -> &'static sp_version::RuntimeVersion { - unimplemented!("Not required in tests") - } - fn load_spec(&self, _: &str) -> std::result::Result, String> { Ok(Box::new(GenericChainSpec::from_genesis( "test", diff --git a/node/src/rpc.rs b/node/src/rpc.rs index be0e2e3a4..3a58be828 100644 --- a/node/src/rpc.rs +++ b/node/src/rpc.rs @@ -7,7 +7,7 @@ use std::sync::Arc; -use node_primitives::{AccountId, Balance, Index as Nonce}; +use node_primitives::{AccountId, Balance, Nonce}; use runtime_common::opaque::Block; use sc_client_api::{client::BlockBackend, AuxStore, UsageProvider}; diff --git a/node/src/service.rs b/node/src/service.rs index 749e73b96..066e31a01 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -2,13 +2,13 @@ // std use futures::lock::Mutex; +use sc_network_sync::SyncingService; use sp_api::ConstructRuntimeApi; use std::{sync::Arc, time::Duration}; use cumulus_client_cli::CollatorOptions; use runtime_common::opaque::Block; -use node_primitives::Hash; use sc_client_api::Backend; // Cumulus Imports @@ -16,31 +16,29 @@ use cumulus_client_consensus_aura::{AuraConsensus, BuildAuraConsensusParams, Slo use cumulus_client_consensus_common::{ ParachainBlockImport as TParachainBlockImport, ParachainConsensus, }; -use cumulus_client_network::BlockAnnounceValidator; use cumulus_client_service::{ - build_relay_chain_interface, prepare_node_config, start_collator, start_full_node, - StartCollatorParams, StartFullNodeParams, + build_relay_chain_interface, prepare_node_config, start_collator, + start_full_node, StartCollatorParams, StartFullNodeParams, }; use cumulus_primitives_core::ParaId; -use cumulus_relay_chain_interface::{RelayChainError, RelayChainInterface}; +use cumulus_relay_chain_interface::{RelayChainInterface}; // Substrate Imports use sc_consensus::ImportQueue; use sc_executor::NativeElseWasmExecutor; -use sc_network::NetworkService; -use sc_network_common::service::NetworkBlock; +use sc_network::{NetworkBlock}; use sc_service::{ config::KeystoreConfig, Configuration, PartialComponents, TFullBackend, TFullClient, TaskManager, }; use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle}; -use sp_avn_common::{DEFAULT_EXTERNAL_SERVICE_PORT_NUMBER, EXTERNAL_SERVICE_PORT_NUMBER_KEY}; -use sp_core::{offchain::OffchainStorage, Encode}; -use sp_keystore::SyncCryptoStorePtr; + +use sp_keystore::KeystorePtr; use substrate_prometheus_endpoint::Registry; use crate::{avn_config::*, common::AvnRuntimeApiCollection}; use avn_service::{self, web3_utils::Web3Data}; +use sc_transaction_pool_api::OffchainTransactionPoolFactory; type ParachainClient = TFullClient>; @@ -173,6 +171,7 @@ where let params = new_partial(¶chain_config)?; let (block_import, mut telemetry, telemetry_worker_handle) = params.other; + let net_config = sc_network::config::FullNetworkConfiguration::new(¶chain_config.network); let client = params.client.clone(); let backend = params.backend.clone(); @@ -187,13 +186,7 @@ where hwbench.clone(), ) .await - .map_err(|e| match e { - RelayChainError::ServiceError(polkadot_service::Error::Sub(x)) => x, - s => s.to_string().into(), - })?; - - let block_announce_validator = - BlockAnnounceValidator::new(relay_chain_interface.clone(), para_id); + .map_err(|e| sc_service::Error::Application(Box::new(e) as Box<_>))?; let force_authoring = parachain_config.force_authoring; let validator = parachain_config.role.is_authority(); @@ -204,36 +197,39 @@ where let avn_port = avn_cli_config.avn_port.clone(); let eth_node_url: String = avn_cli_config.ethereum_node_url.clone().unwrap_or_default(); - let (network, system_rpc_tx, tx_handler_controller, start_network) = - sc_service::build_network(sc_service::BuildNetworkParams { - config: ¶chain_config, + let (network, system_rpc_tx, tx_handler_controller, start_network, sync_service) = + cumulus_client_service::build_network(cumulus_client_service::BuildNetworkParams { + parachain_config: ¶chain_config, + net_config, client: client.clone(), transaction_pool: transaction_pool.clone(), + para_id, spawn_handle: task_manager.spawn_handle(), + relay_chain_interface: relay_chain_interface.clone(), import_queue: params.import_queue, - block_announce_validator_builder: Some(Box::new(|_| { - Box::new(block_announce_validator) - })), - warp_sync: None, - })?; + }) + .await?; if parachain_config.offchain_worker.enabled { - let port_number = avn_port - .clone() - .unwrap_or_else(|| DEFAULT_EXTERNAL_SERVICE_PORT_NUMBER.to_string()); - if let Some(mut local_db) = backend.offchain_storage() { - local_db.set( - sp_core::offchain::STORAGE_PREFIX, - EXTERNAL_SERVICE_PORT_NUMBER_KEY, - &port_number.encode(), - ); - } - - sc_service::build_offchain_workers( - ¶chain_config, - task_manager.spawn_handle(), - client.clone(), - network.clone(), + use futures::FutureExt; + + task_manager.spawn_handle().spawn( + "offchain-workers-runner", + "offchain-work", + sc_offchain::OffchainWorkers::new(sc_offchain::OffchainWorkerOptions { + runtime_api_provider: client.clone(), + keystore: Some(params.keystore_container.keystore()), + offchain_db: backend.offchain_storage(), + transaction_pool: Some(OffchainTransactionPoolFactory::new( + transaction_pool.clone(), + )), + network_provider: network.clone(), + is_validator: parachain_config.role.is_authority(), + enable_http_requests: false, + custom_extensions: move |_| vec![], + }) + .run(client.clone(), task_manager.spawn_handle()) + .boxed(), ); } @@ -261,9 +257,10 @@ where transaction_pool: transaction_pool.clone(), task_manager: &mut task_manager, config: parachain_config, - keystore: params.keystore_container.sync_keystore(), + keystore: params.keystore_container.keystore(), backend, network: network.clone(), + sync_service: sync_service.clone(), system_rpc_tx, tx_handler_controller, telemetry: telemetry.as_mut(), @@ -283,12 +280,16 @@ where } let announce_block = { - let network = network.clone(); - Arc::new(move |hash, data| network.announce_block(hash, data)) + let sync_service = sync_service.clone(); + Arc::new(move |hash, data| sync_service.announce_block(hash, data)) }; let relay_chain_slot_duration = Duration::from_secs(6); + let overseer_handle = relay_chain_interface + .overseer_handle() + .map_err(|e| sc_service::Error::Application(Box::new(e)))?; + if validator { let keystore_path = match parachain_config_keystore { KeystoreConfig::Path { path, password: _ } => Ok(path.clone()), @@ -296,9 +297,7 @@ where }?; let avn_config = avn_service::Config:: { - keystore: params.keystore_container.local_keystore().ok_or_else(|| { - sc_service::Error::Application(Box::from(format!("Failed to get local keystore"))) - })?, + keystore: params.keystore_container.local_keystore(), keystore_path, avn_port, eth_node_url, @@ -320,8 +319,8 @@ where &task_manager, relay_chain_interface.clone(), transaction_pool, - network, - params.keystore_container.sync_keystore(), + sync_service.clone(), + params.keystore_container.keystore(), force_authoring, para_id, )?; @@ -339,6 +338,8 @@ where import_queue: import_queue_service, collator_key: collator_key.expect("Command line arguments do not allow this. qed"), relay_chain_slot_duration, + recovery_handle: Box::new(overseer_handle), + sync_service, }; start_collator(params).await?; @@ -351,6 +352,8 @@ where relay_chain_interface, relay_chain_slot_duration, import_queue: import_queue_service, + recovery_handle: Box::new(overseer_handle), + sync_service, }; start_full_node(params)?; @@ -422,8 +425,8 @@ fn build_consensus( transaction_pool: Arc< sc_transaction_pool::FullPool>, >, - sync_oracle: Arc>, - keystore: SyncCryptoStorePtr, + sync_oracle: Arc>, + keystore: KeystorePtr, force_authoring: bool, para_id: ParaId, ) -> Result>, sc_service::Error> diff --git a/runtime/avn/Cargo.toml b/runtime/avn/Cargo.toml index 83f625bbd..37b8b8a37 100644 --- a/runtime/avn/Cargo.toml +++ b/runtime/avn/Cargo.toml @@ -14,75 +14,74 @@ rust-version = { workspace = true } targets = ["x86_64-unknown-linux-gnu"] [build-dependencies] -substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0", optional = true} [dependencies] -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } -hex-literal = { version = "0.3.4", optional = true } +codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive"] } +hex-literal = { version = "0.4.1", optional = true } log = { version = "0.4.17", default-features = false } -scale-info = { version = "2.3.1", default-features = false, features = ["derive"] } -smallvec = "1.10.0" +scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } +smallvec = "1.11.0" # Substrate -frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.36" } -frame-executive = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -frame-system-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.36" } -frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -frame-try-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.36" } -pallet-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -pallet-authorship = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -pallet-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -pallet-sudo = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-block-builder = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-consensus-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-inherents = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-offchain = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-transaction-pool = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-version = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } -pallet-assets = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } -sp-authority-discovery = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } -pallet-authority-discovery = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } -pallet-offences = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } -pallet-im-online = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } -pallet-utility = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } -pallet-referenda = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -pallet-conviction-voting = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -pallet-whitelist = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -pallet-scheduler = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -pallet-preimage = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v1.0.0" } +frame-executive = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +frame-system-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v1.0.0" } +frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +frame-try-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v1.0.0" } +pallet-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +pallet-authorship = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0", features=["insecure_zero_ed"] } +pallet-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +pallet-sudo = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +sp-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +sp-block-builder = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +sp-consensus-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +sp-inherents = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +sp-offchain = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +sp-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +sp-transaction-pool = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +sp-version = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } +pallet-assets = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } +sp-authority-discovery = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } +pallet-authority-discovery = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } +pallet-offences = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } +pallet-im-online = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } +pallet-utility = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } +pallet-referenda = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +pallet-conviction-voting = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +pallet-whitelist = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +pallet-scheduler = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +pallet-preimage = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } # Polkadot -pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.36" } -polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.36" } -polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.36" } -xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.36" } -xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.36" } -xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.36" } +pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v1.0.0" } +polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v1.0.0" } +polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v1.0.0" } +xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v1.0.0" } +xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v1.0.0" } +xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v1.0.0" } # Cumulus -cumulus-pallet-aura-ext = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.36", default-features = false } -cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.36", default-features = false } -cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.36", default-features = false } -cumulus-pallet-session-benchmarking = {git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.36", default-features = false, version = "3.0.0"} -cumulus-pallet-xcm = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.36", default-features = false } -cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.36", default-features = false } -cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.36", default-features = false } -cumulus-primitives-timestamp = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.36", default-features = false } -cumulus-primitives-utility = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.36", default-features = false } -pallet-collator-selection = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.36", default-features = false } -parachain-info = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.36", default-features = false } +cumulus-pallet-aura-ext = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0", default-features = false } +cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0", default-features = false } +cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0", default-features = false } +cumulus-pallet-session-benchmarking = {git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0", default-features = false, version = "3.0.0"} +cumulus-pallet-xcm = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0", default-features = false } +cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0", default-features = false } +cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0", default-features = false } +cumulus-primitives-timestamp = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0", default-features = false } +cumulus-primitives-utility = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0", default-features = false } +parachain-info = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0", default-features = false } # AvN pallets sp-avn-common = { path = "../../primitives/avn-common", default-features = false } @@ -96,7 +95,6 @@ pallet-nft-manager = { path = "../../pallets/nft-manager", default-features = fa pallet-avn-proxy = { path = "../../pallets/avn-proxy", default-features = false } pallet-avn-transaction-payment = { path = "../../pallets/avn-transaction-payment", default-features = false } pallet-eth-bridge = { path = "../../pallets/eth-bridge", default-features = false } - pallet-parachain-staking = { path = "../../pallets/parachain-staking", default-features = false } # Common Runtime @@ -129,11 +127,13 @@ std = [ "pallet-session/std", "pallet-sudo/std", "pallet-offences/std", + "pallet-im-online/std", "pallet-timestamp/std", "pallet-transaction-payment-rpc-runtime-api/std", "pallet-transaction-payment/std", "pallet-utility/std", "pallet-xcm/std", + "pallet-authority-discovery/std", "parachain-info/std", "polkadot-parachain/std", "polkadot-runtime-common/std", @@ -149,12 +149,14 @@ std = [ "sp-std/std", "sp-transaction-pool/std", "sp-version/std", + "sp-authority-discovery/std", "xcm-builder/std", "xcm-executor/std", "xcm/std", # AvN pallets "sp-avn-common/std", "pallet-avn/std", + "pallet-avn-proxy/std", "pallet-avn-offence-handler/std", "pallet-eth-bridge/std", "pallet-ethereum-events/std", @@ -163,7 +165,6 @@ std = [ "pallet-token-manager/std", "pallet-validators-manager/std", "pallet-avn-transaction-payment/std", - # Staking "pallet-parachain-staking/std", # Avn Common Runtime "runtime-common/std", @@ -173,6 +174,7 @@ std = [ "pallet-whitelist/std", "pallet-scheduler/std", "pallet-preimage/std", + "substrate-wasm-builder" ] runtime-benchmarks = [ @@ -190,6 +192,8 @@ runtime-benchmarks = [ "xcm-builder/runtime-benchmarks", "cumulus-pallet-session-benchmarking/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", + "cumulus-pallet-parachain-system/runtime-benchmarks", + "pallet-sudo/runtime-benchmarks", # AvN pallets "pallet-avn-proxy/runtime-benchmarks", "pallet-avn-offence-handler/runtime-benchmarks", @@ -225,7 +229,6 @@ try-runtime = [ "pallet-aura/try-runtime", "pallet-authorship/try-runtime", "pallet-balances/try-runtime", - "pallet-collator-selection/try-runtime", "pallet-session/try-runtime", "pallet-sudo/try-runtime", "pallet-timestamp/try-runtime", diff --git a/runtime/avn/build.rs b/runtime/avn/build.rs index 18a76f789..f328419f4 100644 --- a/runtime/avn/build.rs +++ b/runtime/avn/build.rs @@ -1,9 +1,11 @@ -use substrate_wasm_builder::WasmBuilder; fn main() { - WasmBuilder::new() - .with_current_project() - .export_heap_base() - .import_memory() - .build() + #[cfg(feature = "std")] + { + substrate_wasm_builder::WasmBuilder::new() + .with_current_project() + .export_heap_base() + .import_memory() + .build(); + } } diff --git a/runtime/avn/src/lib.rs b/runtime/avn/src/lib.rs index 9cf8b54ad..f1fe4a256 100644 --- a/runtime/avn/src/lib.rs +++ b/runtime/avn/src/lib.rs @@ -32,16 +32,16 @@ use sp_version::RuntimeVersion; use frame_support::{ construct_runtime, - dispatch::{DispatchClass, GetStorageVersion}, - pallet_prelude::StorageVersion, + dispatch::{DispatchClass}, parameter_types, traits::{ - AsEnsureOriginWithArg, ConstU32, ConstU64, Contains, Currency, Defensive, Imbalance, + AsEnsureOriginWithArg, ConstBool, ConstU32, ConstU64, Contains, Currency, Imbalance, OnUnbalanced, PrivilegeCmp, }, weights::{constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, Weight}, PalletId, RuntimeDebug, }; +use xcm_config::{XcmConfig, XcmOriginToTransactDispatchOrigin}; pub use frame_system::{ limits::{BlockLength, BlockWeights}, EnsureRoot, EnsureSigned, Event as SystemEvent, EventRecord, Phase, @@ -50,7 +50,6 @@ use governance::pallet_custom_origins; use proxy_config::AvnProxyConfig; pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; pub use sp_runtime::{MultiAddress, Perbill, Permill}; -use xcm_config::{XcmConfig, XcmOriginToTransactDispatchOrigin}; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; @@ -69,7 +68,7 @@ use pallet_avn::sr25519::AuthorityId as AvnId; pub use pallet_avn_proxy::{Event as AvnProxyEvent, ProvableProxy}; use pallet_avn_transaction_payment::AvnCurrencyAdapter; -pub use pallet_ethereum_events::Event as EthEvent; +// pub use pallet_ethereum_events::Event as EthEvent; use sp_avn_common::{InnerCallValidator, Proof}; use pallet_parachain_staking; @@ -112,11 +111,11 @@ where } pub use node_primitives::{AccountId, Hash, Signature}; -use node_primitives::{Balance, BlockNumber, Index}; +use node_primitives::{Balance, BlockNumber, Nonce}; use runtime_common::{ constants::{currency::*, time::*}, - opaque, weights, Address, Header, OperationalFeeMultiplier, TransactionByteFee, WeightToFee, + weights, Address, Header, OperationalFeeMultiplier, TransactionByteFee, WeightToFee, }; use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; @@ -157,129 +156,11 @@ pub type Executive = frame_executive::Executive< AllPalletsWithSystem, ( pallet_parachain_staking::migration::EnableEthBridgeWireUp, - SeedBridgeTransactionAndDropEthTransactions, pallet_validators_manager::migration::RemovePalletVoting, pallet_summary::migration::MigrateSummaryRootData, ), >; -const ETHEREUM_TRANSACTIONS_PREFIX: &[u8] = b"EthereumTransactions"; -const STORAGE_ITEM_NAMES: &[&'static str] = &[ - "Repository", - "DispatchedAvnTxIds", - "ReservedTransactions", - "PublishRootContract", - "Nonce", - "StorageVersion", -]; - -pub struct SeedBridgeTransactionAndDropEthTransactions; - -impl frame_support::traits::OnRuntimeUpgrade for SeedBridgeTransactionAndDropEthTransactions { - fn on_runtime_upgrade() -> frame_support::weights::Weight { - let migration_version = StorageVersion::new(1); - let current = pallet_eth_bridge::Pallet::::current_storage_version(); - let onchain = pallet_eth_bridge::Pallet::::on_chain_storage_version(); - - if onchain < 1 { - log::info!( - "🚧 Running eth bridge migration. Current storage version: {:?}, on-chain version: {:?}", - current, - onchain - ); - - let mut total_weight = Weight::zero(); - - match try_seed_next_tx_id() { - Ok(weight) => total_weight += weight, - Err(_) => log::info!("💔 Failed to seed transaction Id"), - } - - total_weight += set_expiry(); - total_weight += clear_ethereum_transactions_storage(); - - migration_version.put::>(); - - log::info!("🚧 Migration successfull"); - - return total_weight - } - Weight::zero() - } - - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, &'static str> { - let onchain = pallet_eth_bridge::Pallet::::on_chain_storage_version(); - - if onchain < 1 { - let pre_upgrade_transaction_id: u64 = get_nonce_seed().unwrap(); - return Ok((pre_upgrade_transaction_id + 1u64).encode()) - } - - Ok(vec![]) - } - - #[cfg(feature = "try-runtime")] - fn post_upgrade(new_transaction_id_bytes: Vec) -> Result<(), &'static str> { - let current = pallet_eth_bridge::Pallet::::current_storage_version(); - - if current == 1 { - let next_tx_id: u32 = pallet_eth_bridge::Pallet::::get_next_tx_id(); - let expiry = as pallet_eth_bridge::Store>::EthTxLifetimeSecs::get(); - assert_eq!((next_tx_id as u64).encode(), new_transaction_id_bytes); - assert_eq!(expiry, 7200); - } - Ok(()) - } -} - -fn try_seed_next_tx_id() -> Result { - let nonce_seed = get_nonce_seed()?; - let tx_id: u32 = nonce_seed.try_into().map_err(|_| ())?; - as pallet_eth_bridge::Store>::NextTxId::put(tx_id + 1); - log::info!("✅ Transaction Id seeded to {}", tx_id + 1); - - Ok(::DbWeight::get().reads_writes(1, 1)) -} - -fn set_expiry() -> Weight { - as pallet_eth_bridge::Store>::EthTxLifetimeSecs::put( - 7200u64, - ); - log::info!("✅ Transaction expiry set to 7200 seconds"); - - ::DbWeight::get().reads_writes(0, 1) -} - -fn get_nonce_seed() -> Result { - let nonce_prefix = - frame_support::storage::storage_prefix(ETHEREUM_TRANSACTIONS_PREFIX, b"Nonce"); - frame_support::storage::unhashed::get::(&nonce_prefix).ok_or(()) -} - -fn clear_ethereum_transactions_storage() -> Weight { - STORAGE_ITEM_NAMES.iter().fold(Weight::zero(), |acc, &item_name| { - let storage_prefix = frame_support::storage::storage_prefix( - ETHEREUM_TRANSACTIONS_PREFIX, - item_name.as_bytes(), - ); - let mut storage_key = [0u8; 32]; - storage_key[0..32].copy_from_slice(&storage_prefix); - - match item_name { - "PublishRootContract" | "Nonce" | "StorageVersion" => { - frame_support::storage::unhashed::kill(&storage_key); - log::info!("🚧 Successfully migrated {}", item_name); - acc + ::DbWeight::get().writes(1) - }, - _ => { - frame_support::storage::unhashed::clear_prefix(&storage_key, None, None); - log::info!("🚧 Successfully migrated {}", item_name); - acc + ::DbWeight::get().writes(1) - }, - } - }) -} impl_opaque_keys! { pub struct SessionKeys { @@ -295,7 +176,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("avn-parachain"), impl_name: create_runtime_str!("avn-parachain"), authoring_version: 1, - spec_version: 59, + spec_version: 60, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, @@ -325,7 +206,7 @@ const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); /// We allow for 0.5 of a second of compute with a 12 second average block time. const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts( WEIGHT_REF_TIME_PER_SECOND.saturating_div(2), - cumulus_primitives_core::relay_chain::v2::MAX_POV_SIZE as u64, + cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64, ); /// The version information used to identify this runtime when compiled natively. @@ -394,15 +275,13 @@ impl frame_system::Config for Runtime { /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = AccountIdLookup; /// The index type for storing how many extrinsics an account has signed. - type Index = Index; - /// The index type for blocks. - type BlockNumber = BlockNumber; + type Nonce = Nonce; /// The type for hashing blocks and tries. type Hash = Hash; /// The hashing algorithm used. type Hashing = BlakeTwo256; /// The header type. - type Header = generic::Header; + type Block = Block; /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; // type Call = Call; @@ -447,8 +326,6 @@ impl pallet_timestamp::Config for Runtime { impl pallet_authorship::Config for Runtime { type FindAuthor = pallet_session::FindAccountFromAuthorIndex; - type UncleGenerations = ConstU32<0>; - type FilterUncle = (); type EventHandler = (ParachainStaking,); } @@ -468,6 +345,10 @@ impl pallet_balances::Config for Runtime { type WeightInfo = pallet_balances::weights::SubstrateWeight; type MaxReserves = ConstU32<50>; type ReserveIdentifier = [u8; 8]; + type RuntimeHoldReason = RuntimeHoldReason; + type FreezeIdentifier = (); + type MaxHolds = ConstU32<0>; + type MaxFreezes = ConstU32<0>; } impl pallet_transaction_payment::Config for Runtime { @@ -501,14 +382,15 @@ impl parachain_info::Config for Runtime {} impl cumulus_pallet_aura_ext::Config for Runtime {} impl cumulus_pallet_xcmp_queue::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type XcmExecutor = XcmExecutor; - type ChannelInfo = ParachainSystem; - type VersionWrapper = (); - type ExecuteOverweightOrigin = EnsureRoot; - type ControllerOrigin = EnsureRoot; - type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; - type WeightInfo = (); + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; + type ChannelInfo = ParachainSystem; + type VersionWrapper = (); + type ExecuteOverweightOrigin = EnsureRoot; + type ControllerOrigin = EnsureRoot; + type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; + type WeightInfo = (); + type PriceForSiblingDelivery = (); } impl cumulus_pallet_dmp_queue::Config for Runtime { @@ -540,6 +422,7 @@ impl pallet_aura::Config for Runtime { type AuthorityId = AuraId; type DisabledValidators = (); type MaxAuthorities = ConstU32<100_000>; + type AllowMultipleBlocksPerSlot = ConstBool; } parameter_types! { @@ -607,7 +490,6 @@ parameter_types! { pub const ImOnlineUnsignedPriority: TransactionPriority = TransactionPriority::max_value(); pub const MaxKeys: u16 = 100; pub const MaxPeerInHeartbeats: u32 = 10_000; - pub const MaxPeerDataEncodingSize: u32 = 1_000; } impl pallet_im_online::Config for Runtime { @@ -620,12 +502,12 @@ impl pallet_im_online::Config for Runtime { type WeightInfo = pallet_im_online::weights::SubstrateWeight; type MaxKeys = MaxKeys; type MaxPeerInHeartbeats = MaxPeerInHeartbeats; - type MaxPeerDataEncodingSize = MaxPeerDataEncodingSize; } impl pallet_sudo::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; + type WeightInfo = (); } impl pallet_utility::Config for Runtime { @@ -785,6 +667,7 @@ impl pallet_assets::Config for Runtime { type StringLimit = StringLimit; type Freezer = (); type Extra = (); + type CallbackHandle = (); type WeightInfo = pallet_assets::weights::SubstrateWeight; #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = (); @@ -838,38 +721,33 @@ impl pallet_preimage::Config for Runtime { // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( - pub enum Runtime where - Block = Block, - NodeBlock = opaque::Block, - UncheckedExtrinsic = UncheckedExtrinsic, + pub enum Runtime { // System support stuff. - System: frame_system::{Pallet, Call, Config, Storage, Event} = 0, - ParachainSystem: cumulus_pallet_parachain_system::{ - Pallet, Call, Config, Storage, Inherent, Event, ValidateUnsigned, - } = 1, - Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 2, - ParachainInfo: parachain_info::{Pallet, Storage, Config} = 3, + System: frame_system = 0, + ParachainSystem: cumulus_pallet_parachain_system = 1, + Timestamp: pallet_timestamp = 2, + ParachainInfo: parachain_info = 3, // Monetary stuff. Balances: pallet_balances::{Pallet, Call, Storage, Config, Event} = 10, TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event} = 11, // Collator support. The order of these 4 are important and shall not change. - Authorship: pallet_authorship::{Pallet, Call, Storage} = 20, - Session: pallet_session::{Pallet, Call, Storage, Event, Config} = 22, - Aura: pallet_aura::{Pallet, Storage, Config} = 23, - AuraExt: cumulus_pallet_aura_ext::{Pallet, Storage, Config} = 24, - ParachainStaking: pallet_parachain_staking::{Pallet, Call, Storage, Event, Config} = 96, + Authorship: pallet_authorship = 20, + Session: pallet_session = 22, + Aura: pallet_aura = 23, + AuraExt: cumulus_pallet_aura_ext = 24, + ParachainStaking: pallet_parachain_staking = 96, // Since the ValidatorsManager integrates with the ParachainStaking pallet, we want to initialise after it. ValidatorsManager: pallet_validators_manager = 18, // XCM helpers. - XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event} = 30, - PolkadotXcm: pallet_xcm::{Pallet, Call, Event, Origin, Config} = 31, - CumulusXcm: cumulus_pallet_xcm::{Pallet, Event, Origin} = 32, - DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event} = 33, + XcmpQueue: cumulus_pallet_xcmp_queue = 30, + PolkadotXcm: pallet_xcm = 31, + CumulusXcm: cumulus_pallet_xcm = 32, + DmpQueue: cumulus_pallet_dmp_queue = 33, // Substrate pallets Assets: pallet_assets = 60, @@ -901,13 +779,9 @@ construct_runtime!( } ); -#[cfg(feature = "runtime-benchmarks")] -#[macro_use] -extern crate frame_benchmarking; - #[cfg(feature = "runtime-benchmarks")] mod benches { - define_benchmarks!( + frame_benchmarking::define_benchmarks!( [frame_system, SystemBench::] [pallet_assets, Assets] [pallet_balances, Balances] @@ -958,7 +832,15 @@ impl_runtime_apis! { fn metadata() -> OpaqueMetadata { OpaqueMetadata::new(Runtime::metadata().into()) } - } + + fn metadata_at_version(version: u32) -> Option { + Runtime::metadata_at_version(version) + } + + fn metadata_versions() -> sp_std::vec::Vec { + Runtime::metadata_versions() + } + } impl sp_block_builder::BlockBuilder for Runtime { fn apply_extrinsic(extrinsic: ::Extrinsic) -> ApplyExtrinsicResult { @@ -1009,8 +891,8 @@ impl_runtime_apis! { } } - impl frame_system_rpc_runtime_api::AccountNonceApi for Runtime { - fn account_nonce(account: AccountId) -> Index { + impl frame_system_rpc_runtime_api::AccountNonceApi for Runtime { + fn account_nonce(account: AccountId) -> Nonce { System::account_nonce(account) } } @@ -1028,6 +910,13 @@ impl_runtime_apis! { ) -> pallet_transaction_payment::FeeDetails { TransactionPayment::query_fee_details(uxt, len) } + + fn query_weight_to_fee(weight: Weight) -> Balance { + TransactionPayment::weight_to_fee(weight) + } + fn query_length_to_fee(length: u32) -> Balance { + TransactionPayment::length_to_fee(length) + } } impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentCallApi @@ -1045,16 +934,23 @@ impl_runtime_apis! { ) -> pallet_transaction_payment::FeeDetails { TransactionPayment::query_call_fee_details(call, len) } + + fn query_weight_to_fee(weight: Weight) -> Balance { + TransactionPayment::weight_to_fee(weight) + } + fn query_length_to_fee(length: u32) -> Balance { + TransactionPayment::length_to_fee(length) + } } impl cumulus_primitives_core::CollectCollationInfo for Runtime { - fn collect_collation_info(header: &::Header) -> cumulus_primitives_core::CollationInfo { - ParachainSystem::collect_collation_info(header) - } - } + fn collect_collation_info(header: &::Header) -> cumulus_primitives_core::CollationInfo { + ParachainSystem::collect_collation_info(header) + } + } #[cfg(feature = "try-runtime")] impl frame_try_runtime::TryRuntime for Runtime { - fn on_runtime_upgrade(checks: bool) -> (Weight, Weight) { + fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) { log::info!("try-runtime::on_runtime_upgrade avn-parachain."); let weight = Executive::try_runtime_upgrade(checks).unwrap(); (weight, RuntimeBlockWeights::get().max_block) @@ -1075,53 +971,52 @@ impl_runtime_apis! { #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { fn benchmark_metadata(extra: bool) -> ( - Vec, - Vec, - ) { - use frame_benchmarking::{Benchmarking, BenchmarkList}; - use frame_support::traits::StorageInfoTrait; - use frame_system_benchmarking::Pallet as SystemBench; - use cumulus_pallet_session_benchmarking::Pallet as SessionBench; - - let mut list = Vec::::new(); - list_benchmarks!(list, extra); - - let storage_info = AllPalletsWithSystem::storage_info(); - return (list, storage_info) - } + Vec, + Vec, + ) { + use frame_benchmarking::{Benchmarking, BenchmarkList}; + use frame_support::traits::StorageInfoTrait; + use frame_system_benchmarking::Pallet as SystemBench; + use cumulus_pallet_session_benchmarking::Pallet as SessionBench; + + let mut list = Vec::::new(); + list_benchmarks!(list, extra); + + let storage_info = AllPalletsWithSystem::storage_info(); + (list, storage_info) + } fn dispatch_benchmark( - config: frame_benchmarking::BenchmarkConfig - ) -> Result, sp_runtime::RuntimeString> { - use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey}; - - use frame_system_benchmarking::Pallet as SystemBench; - impl frame_system_benchmarking::Config for Runtime {} - - 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(), - ]; - - let mut batches = Vec::::new(); - let params = (&config, &whitelist); - add_benchmarks!(params, batches); - - if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } - Ok(batches) - } - } + config: frame_benchmarking::BenchmarkConfig + ) -> Result, sp_runtime::RuntimeString> { + use frame_benchmarking::{BenchmarkError, Benchmarking, BenchmarkBatch}; + + use frame_system_benchmarking::Pallet as SystemBench; + impl frame_system_benchmarking::Config for Runtime { + fn setup_set_code_requirements(code: &sp_std::vec::Vec) -> Result<(), BenchmarkError> { + ParachainSystem::initialize_for_set_code_benchmark(code.len() as u32); + Ok(()) + } + + fn verify_set_code() { + System::assert_last_event(cumulus_pallet_parachain_system::Event::::ValidationFunctionStored.into()); + } + } + + use cumulus_pallet_session_benchmarking::Pallet as SessionBench; + impl cumulus_pallet_session_benchmarking::Config for Runtime {} + + use frame_support::traits::WhitelistedStorageKeys; + let whitelist = AllPalletsWithSystem::whitelisted_storage_keys(); + + let mut batches = Vec::::new(); + let params = (&config, &whitelist); + add_benchmarks!(params, batches); + + if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } + Ok(batches) + } + } impl sp_authority_discovery::AuthorityDiscoveryApi for Runtime { fn authorities() -> Vec { @@ -1133,24 +1028,24 @@ impl_runtime_apis! { struct CheckInherents; impl cumulus_pallet_parachain_system::CheckInherents for CheckInherents { - fn check_inherents( - block: &Block, - relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof, - ) -> sp_inherents::CheckInherentsResult { - let relay_chain_slot = relay_state_proof - .read_slot() - .expect("Could not read the relay chain slot from the proof"); - - let inherent_data = - cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration( - relay_chain_slot, - sp_std::time::Duration::from_secs(6), - ) - .create_inherent_data() - .expect("Could not create the timestamp inherent data"); - - inherent_data.check_extrinsics(block) - } + fn check_inherents( + block: &Block, + relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof, + ) -> sp_inherents::CheckInherentsResult { + let relay_chain_slot = relay_state_proof + .read_slot() + .expect("Could not read the relay chain slot from the proof"); + + let inherent_data = + cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration( + relay_chain_slot, + sp_std::time::Duration::from_secs(6), + ) + .create_inherent_data() + .expect("Could not create the timestamp inherent data"); + + inherent_data.check_extrinsics(block) + } } cumulus_pallet_parachain_system::register_validate_block! { diff --git a/runtime/avn/src/xcm_config.rs b/runtime/avn/src/xcm_config.rs index 7e04e52a8..ff996d4dd 100644 --- a/runtime/avn/src/xcm_config.rs +++ b/runtime/avn/src/xcm_config.rs @@ -1,185 +1,141 @@ use super::{ - AccountId, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, - RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, + AccountId, AllPalletsWithSystem, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, + Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, }; -use core::marker::PhantomData; use frame_support::{ - log, match_types, parameter_types, - traits::{Everything, Nothing}, + match_types, parameter_types, + traits::{ConstU32, Everything, Nothing}, + weights::Weight, }; +use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; use polkadot_parachain::primitives::Sibling; use polkadot_runtime_common::impls::ToAuthor; -use xcm::latest::{prelude::*, Weight as XCMWeight}; +use xcm::latest::prelude::*; use xcm_builder::{ - AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter, - EnsureXcmOrigin, FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset, ParentIsPreset, - RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, - SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, - UsingComponents, + AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, + CurrencyAdapter, DenyReserveTransferToRelayChain, DenyThenTry, EnsureXcmOrigin, + FixedWeightBounds, IsConcrete, NativeAsset, ParentIsPreset, RelayChainAsNative, + SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, + SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, + UsingComponents, WithComputedOrigin, WithUniqueTopic, }; -use xcm_executor::{traits::ShouldExecute, XcmExecutor}; +use xcm_executor::XcmExecutor; parameter_types! { - pub const RelayLocation: MultiLocation = MultiLocation::parent(); - pub const RelayNetwork: NetworkId = NetworkId::Any; - pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); - pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); + pub const RelayLocation: MultiLocation = MultiLocation::parent(); + pub const RelayNetwork: Option = None; + pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); + pub UniversalLocation: InteriorMultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); } /// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used /// when determining ownership of accounts for asset transacting and when attempting to use XCM /// `Transact` in order to determine the dispatch Origin. pub type LocationToAccountId = ( - // The parent (Relay-chain) origin converts to the parent `AccountId`. - ParentIsPreset, - // Sibling parachain origins convert to AccountId via the `ParaId::into`. - SiblingParachainConvertsVia, - // Straight up local `AccountId32` origins just alias directly to `AccountId`. - AccountId32Aliases, + // The parent (Relay-chain) origin converts to the parent `AccountId`. + ParentIsPreset, + // Sibling parachain origins convert to AccountId via the `ParaId::into`. + SiblingParachainConvertsVia, + // Straight up local `AccountId32` origins just alias directly to `AccountId`. + AccountId32Aliases, ); /// Means for transacting assets on this chain. pub type LocalAssetTransactor = CurrencyAdapter< - // Use this currency: - Balances, - // Use this currency when it is a fungible asset matching the given location or name: - IsConcrete, - // Do a simple punn to convert an AccountId32 MultiLocation into a native chain account ID: - LocationToAccountId, - // Our chain's account ID type (we can't get away without mentioning it explicitly): - AccountId, - // We don't track any teleports. - (), + // Use this currency: + Balances, + // Use this currency when it is a fungible asset matching the given location or name: + IsConcrete, + // Do a simple punn to convert an AccountId32 MultiLocation into a native chain account ID: + LocationToAccountId, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, + // We don't track any teleports. + (), >; /// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, /// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can /// biases the kind of local `Origin` it will become. pub type XcmOriginToTransactDispatchOrigin = ( - // Sovereign account converter; this attempts to derive an `AccountId` from the origin location - // using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for - // foreign chains who want to have a local sovereign account on this chain which they control. - SovereignSignedViaLocation, - // Native converter for Relay-chain (Parent) location; will converts to a `Relay` origin when - // recognized. - RelayChainAsNative, - // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when - // recognized. - SiblingParachainAsNative, - // Native signed account converter; this just converts an `AccountId32` origin into a normal - // `RuntimeOrigin::Signed` origin of the same 32-byte value. - SignedAccountId32AsNative, - // Xcm origins can be represented natively under the Xcm pallet's Xcm origin. - XcmPassthrough, + // Sovereign account converter; this attempts to derive an `AccountId` from the origin location + // using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for + // foreign chains who want to have a local sovereign account on this chain which they control. + SovereignSignedViaLocation, + // Native converter for Relay-chain (Parent) location; will convert to a `Relay` origin when + // recognized. + RelayChainAsNative, + // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when + // recognized. + SiblingParachainAsNative, + // Native signed account converter; this just converts an `AccountId32` origin into a normal + // `RuntimeOrigin::Signed` origin of the same 32-byte value. + SignedAccountId32AsNative, + // Xcm origins can be represented natively under the Xcm pallet's Xcm origin. + XcmPassthrough, ); parameter_types! { - // One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate. - pub UnitWeightCost: u64 = 1_000_000_000; - pub const MaxInstructions: u32 = 100; + // One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate. + pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 64 * 1024); + pub const MaxInstructions: u32 = 100; + pub const MaxAssetsIntoHolding: u32 = 64; } match_types! { - pub type ParentOrParentsExecutivePlurality: impl Contains = { - MultiLocation { parents: 1, interior: Here } | - MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Executive, .. }) } - }; + pub type ParentOrParentsExecutivePlurality: impl Contains = { + MultiLocation { parents: 1, interior: Here } | + MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Executive, .. }) } + }; } -//TODO: move DenyThenTry to polkadot's xcm module. -/// Deny executing the xcm message if it matches any of the Deny filter regardless of anything else. -/// If it passes the Deny, and matches one of the Allow cases then it is let through. -pub struct DenyThenTry(PhantomData, PhantomData) -where - Deny: ShouldExecute, - Allow: ShouldExecute; - -impl ShouldExecute for DenyThenTry -where - Deny: ShouldExecute, - Allow: ShouldExecute, -{ - fn should_execute( - origin: &MultiLocation, - message: &mut Xcm, - max_weight: XCMWeight, - weight_credit: &mut XCMWeight, - ) -> Result<(), ()> { - Deny::should_execute(origin, message, max_weight, weight_credit)?; - Allow::should_execute(origin, message, max_weight, weight_credit) - } -} - -// See issue -pub struct DenyReserveTransferToRelayChain; -impl ShouldExecute for DenyReserveTransferToRelayChain { - fn should_execute( - origin: &MultiLocation, - - message: &mut Xcm, - _max_weight: XCMWeight, - _weight_credit: &mut XCMWeight, - ) -> Result<(), ()> { - if message.0.iter().any(|inst| { - matches!( - inst, - InitiateReserveWithdraw { - reserve: MultiLocation { parents: 1, interior: Here }, - .. - } | DepositReserveAsset { dest: MultiLocation { parents: 1, interior: Here }, .. } | - TransferReserveAsset { - dest: MultiLocation { parents: 1, interior: Here }, - .. - } - ) - }) { - return Err(()) // Deny - } - - // An unexpected reserve transfer has arrived from the Relay Chain. Generally, `IsReserve` - // should not allow this, but we just log it here. - if matches!(origin, MultiLocation { parents: 1, interior: Here }) && - message.0.iter().any(|inst| matches!(inst, ReserveAssetDeposited { .. })) - { - log::warn!( - target: "xcm::barriers", - "Unexpected ReserveAssetDeposited from the Relay Chain", - ); - } - // Permit everything else - Ok(()) - } -} - -pub type Barrier = DenyThenTry< - DenyReserveTransferToRelayChain, - ( - TakeWeightCredit, - AllowTopLevelPaidExecutionFrom, - AllowUnpaidExecutionFrom, - // ^^^ Parent and its exec plurality get free execution - ), +pub type Barrier = TrailingSetTopicAsId< + DenyThenTry< + DenyReserveTransferToRelayChain, + ( + TakeWeightCredit, + WithComputedOrigin< + ( + AllowTopLevelPaidExecutionFrom, + AllowExplicitUnpaidExecutionFrom, + // ^^^ Parent and its exec plurality get free execution + ), + UniversalLocation, + ConstU32<8>, + >, + ), + >, >; pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { - type RuntimeCall = RuntimeCall; - type XcmSender = XcmRouter; - // How to withdraw and deposit an asset. - type AssetTransactor = LocalAssetTransactor; - type OriginConverter = XcmOriginToTransactDispatchOrigin; - type IsReserve = NativeAsset; - type IsTeleporter = (); // Teleporting is disabled. - type LocationInverter = LocationInverter; - type Barrier = Barrier; - type Weigher = FixedWeightBounds; - type Trader = - UsingComponents>; - type ResponseHandler = PolkadotXcm; - type AssetTrap = PolkadotXcm; - type AssetClaims = PolkadotXcm; - type SubscriptionService = PolkadotXcm; + type RuntimeCall = RuntimeCall; + type XcmSender = XcmRouter; + // How to withdraw and deposit an asset. + type AssetTransactor = LocalAssetTransactor; + type OriginConverter = XcmOriginToTransactDispatchOrigin; + type IsReserve = NativeAsset; + type IsTeleporter = (); // Teleporting is disabled. + type UniversalLocation = UniversalLocation; + type Barrier = Barrier; + type Weigher = FixedWeightBounds; + type Trader = + UsingComponents>; + type ResponseHandler = PolkadotXcm; + type AssetTrap = PolkadotXcm; + type AssetClaims = PolkadotXcm; + type SubscriptionService = PolkadotXcm; + type PalletInstancesInfo = AllPalletsWithSystem; + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type AssetLocker = (); + type AssetExchanger = (); + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; + type CallDispatcher = RuntimeCall; + type SafeCallFilter = Everything; + type Aliasers = Nothing; } /// No local origins on this chain are allowed to dispatch XCM sends/executions. @@ -187,35 +143,51 @@ pub type LocalOriginToLocation = SignedToAccountId32, - // ..and XCMP to communicate with the sibling chains. - XcmpQueue, -); +pub type XcmRouter = WithUniqueTopic<( + // Two routers - use UMP to communicate with the relay chain: + cumulus_primitives_utility::ParentAsUmp, + // ..and XCMP to communicate with the sibling chains. + XcmpQueue, +)>; + +#[cfg(feature = "runtime-benchmarks")] +parameter_types! { + pub ReachableDest: Option = Some(Parent.into()); +} impl pallet_xcm::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type SendXcmOrigin = EnsureXcmOrigin; - type XcmRouter = XcmRouter; - type ExecuteXcmOrigin = EnsureXcmOrigin; - type XcmExecuteFilter = Nothing; - // ^ Disable dispatchable execute on the XCM pallet. - // Needs to be `Everything` for local testing. - type XcmExecutor = XcmExecutor; - type XcmTeleportFilter = Everything; - type XcmReserveTransferFilter = Nothing; - type Weigher = FixedWeightBounds; - type LocationInverter = LocationInverter; - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - - const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; - // ^ Override for AdvertisedXcmVersion default - type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; + type RuntimeEvent = RuntimeEvent; + type SendXcmOrigin = EnsureXcmOrigin; + type XcmRouter = XcmRouter; + type ExecuteXcmOrigin = EnsureXcmOrigin; + type XcmExecuteFilter = Nothing; + // ^ Disable dispatchable execute on the XCM pallet. + // Needs to be `Everything` for local testing. + type XcmExecutor = XcmExecutor; + type XcmTeleportFilter = Everything; + type XcmReserveTransferFilter = Nothing; + type Weigher = FixedWeightBounds; + type UniversalLocation = UniversalLocation; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + + const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; + // ^ Override for AdvertisedXcmVersion default + type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; + type Currency = Balances; + type CurrencyMatcher = (); + type TrustedLockers = (); + type SovereignAccountOf = LocationToAccountId; + type MaxLockers = ConstU32<8>; + type WeightInfo = pallet_xcm::TestWeightInfo; + #[cfg(feature = "runtime-benchmarks")] + type ReachableDest = ReachableDest; + type AdminOrigin = EnsureRoot; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); } impl cumulus_pallet_xcm::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type XcmExecutor = XcmExecutor; + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; } diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 6be99ec84..99103f6a8 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -11,16 +11,16 @@ repository = { workspace = true } [dependencies] -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } -hex-literal = { version = "0.3.4", optional = true } +codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive"] } +hex-literal = { version = "0.4.1", optional = true } log = { version = "0.4.17", default-features = false } -scale-info = { version = "2.3.1", default-features = false, features = ["derive"] } -smallvec = "1.10.0" +scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } +smallvec = "1.11.0" # Substrate -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } [features] diff --git a/runtime/common/src/weights/block_weights.rs b/runtime/common/src/weights/block_weights.rs index e62140c20..16c3739b3 100644 --- a/runtime/common/src/weights/block_weights.rs +++ b/runtime/common/src/weights/block_weights.rs @@ -24,7 +24,7 @@ pub mod constants { parameter_types! { /// Importing a block with 0 Extrinsics. pub const BlockExecutionWeight: Weight = - Weight::from_ref_time(constants::WEIGHT_REF_TIME_PER_NANOS.saturating_mul(5_000_000)); + Weight::from_parts(constants::WEIGHT_REF_TIME_PER_NANOS.saturating_mul(5_000_000), 0); } #[cfg(test)] diff --git a/runtime/common/src/weights/extrinsic_weights.rs b/runtime/common/src/weights/extrinsic_weights.rs index e008ee2ef..edd4b9e72 100644 --- a/runtime/common/src/weights/extrinsic_weights.rs +++ b/runtime/common/src/weights/extrinsic_weights.rs @@ -24,7 +24,7 @@ pub mod constants { parameter_types! { /// Executing a NO-OP `System::remarks` Extrinsic. pub const ExtrinsicBaseWeight: Weight = - Weight::from_ref_time(constants::WEIGHT_REF_TIME_PER_NANOS.saturating_mul(125_000)); + Weight::from_parts(constants::WEIGHT_REF_TIME_PER_NANOS.saturating_mul(125_000) as u64, 0); } #[cfg(test)] diff --git a/runtime/test/Cargo.toml b/runtime/test/Cargo.toml index b37074b1a..ab03503ff 100644 --- a/runtime/test/Cargo.toml +++ b/runtime/test/Cargo.toml @@ -14,78 +14,77 @@ rust-version = { workspace = true } targets = ["x86_64-unknown-linux-gnu"] [build-dependencies] -substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" } +substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0", optional = true} [dependencies] -codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] } -hex-literal = { version = "0.3.4", optional = true } +codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive"] } +hex-literal = { version = "0.4.1", optional = true } log = { version = "0.4.17", default-features = false } -scale-info = { version = "2.3.1", default-features = false, features = ["derive"] } -smallvec = "1.10.0" +scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } +smallvec = "1.11.0" # Substrate -frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.36" } -frame-executive = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -frame-system-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.36" } -frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -frame-try-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v0.9.36" } -pallet-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -pallet-authorship = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -pallet-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -pallet-sudo = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-block-builder = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-consensus-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-inherents = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-offchain = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-transaction-pool = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -sp-version = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } -pallet-assets = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } -sp-authority-discovery = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } -pallet-authority-discovery = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } -pallet-offences = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } -pallet-im-online = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } -pallet-utility = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.36" } -pallet-referenda = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -pallet-conviction-voting = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -pallet-whitelist = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -pallet-scheduler = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } -pallet-preimage = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.36" } +frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v1.0.0" } +frame-executive = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +frame-system-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v1.0.0" } +frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +frame-try-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true, branch = "polkadot-v1.0.0" } +pallet-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +pallet-authorship = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0", features=["insecure_zero_ed"] } +pallet-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +pallet-sudo = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +sp-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +sp-block-builder = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +sp-consensus-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +sp-inherents = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +sp-offchain = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +sp-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +sp-transaction-pool = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +sp-version = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } +pallet-assets = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } +sp-authority-discovery = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } +pallet-authority-discovery = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } +pallet-offences = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } +pallet-im-online = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } +pallet-utility = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } +pallet-referenda = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +pallet-conviction-voting = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +pallet-whitelist = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +pallet-scheduler = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } +pallet-preimage = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" } # Polkadot -pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.36" } -polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.36" } -polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.36" } -xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.36" } -xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.36" } -xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.36" } +pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v1.0.0" } +polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v1.0.0" } +polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v1.0.0" } +xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v1.0.0" } +xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v1.0.0" } +xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v1.0.0" } # Cumulus -cumulus-pallet-aura-ext = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.36", default-features = false } -cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.36", default-features = false } -cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.36", default-features = false } -cumulus-pallet-session-benchmarking = {git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.36", default-features = false, version = "3.0.0"} -cumulus-pallet-xcm = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.36", default-features = false } -cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.36", default-features = false } -cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.36", default-features = false } -cumulus-primitives-timestamp = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.36", default-features = false } -cumulus-primitives-utility = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.36", default-features = false } -pallet-collator-selection = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.36", default-features = false } -parachain-info = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v0.9.36", default-features = false } +cumulus-pallet-aura-ext = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0", default-features = false } +cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0", default-features = false } +cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0", default-features = false } +cumulus-pallet-session-benchmarking = {git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0", default-features = false, version = "3.0.0"} +cumulus-pallet-xcm = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0", default-features = false } +cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0", default-features = false } +cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0", default-features = false } +cumulus-primitives-timestamp = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0", default-features = false } +cumulus-primitives-utility = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0", default-features = false } +parachain-info = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0", default-features = false } # AvN pallets -sp-avn-common = { path = "../../primitives/avn-common", default-features = false } +sp-avn-common = { path = "../../primitives/avn-common", default-features = false } pallet-avn-offence-handler = { path = "../../pallets/avn-offence-handler", default-features = false } pallet-validators-manager = { path = "../../pallets/validators-manager", default-features = false } pallet-ethereum-events = { path = "../../pallets/ethereum-events", default-features = false } @@ -94,8 +93,8 @@ pallet-summary = { path = "../../pallets/summary", default-features = false } pallet-token-manager = { path = "../../pallets/token-manager", default-features = false } pallet-nft-manager = { path = "../../pallets/nft-manager", default-features = false } pallet-avn-proxy = { path = "../../pallets/avn-proxy", default-features = false } +pallet-avn-transaction-payment = { path = "../../pallets/avn-transaction-payment", default-features = false } pallet-eth-bridge = { path = "../../pallets/eth-bridge", default-features = false } - pallet-parachain-staking = { path = "../../pallets/parachain-staking", default-features = false } # Common Runtime @@ -128,11 +127,13 @@ std = [ "pallet-session/std", "pallet-sudo/std", "pallet-offences/std", + "pallet-im-online/std", "pallet-timestamp/std", "pallet-transaction-payment-rpc-runtime-api/std", "pallet-transaction-payment/std", "pallet-utility/std", "pallet-xcm/std", + "pallet-authority-discovery/std", "parachain-info/std", "polkadot-parachain/std", "polkadot-runtime-common/std", @@ -148,12 +149,14 @@ std = [ "sp-std/std", "sp-transaction-pool/std", "sp-version/std", + "sp-authority-discovery/std", "xcm-builder/std", "xcm-executor/std", "xcm/std", # AvN pallets "sp-avn-common/std", "pallet-avn/std", + "pallet-avn-proxy/std", "pallet-avn-offence-handler/std", "pallet-eth-bridge/std", "pallet-ethereum-events/std", @@ -161,15 +164,17 @@ std = [ "pallet-summary/std", "pallet-token-manager/std", "pallet-validators-manager/std", - # Staking + "pallet-avn-transaction-payment/std", "pallet-parachain-staking/std", # Avn Common Runtime "runtime-common/std", + # OpenGov "pallet-referenda/std", "pallet-conviction-voting/std", "pallet-whitelist/std", "pallet-scheduler/std", "pallet-preimage/std", + "substrate-wasm-builder" ] runtime-benchmarks = [ @@ -187,6 +192,7 @@ runtime-benchmarks = [ "xcm-builder/runtime-benchmarks", "cumulus-pallet-session-benchmarking/runtime-benchmarks", "cumulus-pallet-xcmp-queue/runtime-benchmarks", + "pallet-sudo/runtime-benchmarks", # AvN pallets "pallet-avn-proxy/runtime-benchmarks", "pallet-avn-offence-handler/runtime-benchmarks", @@ -197,6 +203,7 @@ runtime-benchmarks = [ "pallet-summary/runtime-benchmarks", "pallet-token-manager/runtime-benchmarks", "pallet-validators-manager/runtime-benchmarks", + "pallet-avn-transaction-payment/runtime-benchmarks", # Staking "pallet-parachain-staking/runtime-benchmarks", # Avn Common Runtime @@ -221,7 +228,6 @@ try-runtime = [ "pallet-aura/try-runtime", "pallet-authorship/try-runtime", "pallet-balances/try-runtime", - "pallet-collator-selection/try-runtime", "pallet-session/try-runtime", "pallet-sudo/try-runtime", "pallet-timestamp/try-runtime", @@ -237,6 +243,7 @@ try-runtime = [ "pallet-token-manager/try-runtime", "pallet-nft-manager/try-runtime", "pallet-avn-proxy/try-runtime", + "pallet-avn-transaction-payment/try-runtime", "pallet-parachain-staking/try-runtime", "pallet-eth-bridge/try-runtime", "pallet-assets/try-runtime", diff --git a/runtime/test/build.rs b/runtime/test/build.rs index 18a76f789..f328419f4 100644 --- a/runtime/test/build.rs +++ b/runtime/test/build.rs @@ -1,9 +1,11 @@ -use substrate_wasm_builder::WasmBuilder; fn main() { - WasmBuilder::new() - .with_current_project() - .export_heap_base() - .import_memory() - .build() + #[cfg(feature = "std")] + { + substrate_wasm_builder::WasmBuilder::new() + .with_current_project() + .export_heap_base() + .import_memory() + .build(); + } } diff --git a/runtime/test/src/lib.rs b/runtime/test/src/lib.rs index f55a6ce51..43615237f 100644 --- a/runtime/test/src/lib.rs +++ b/runtime/test/src/lib.rs @@ -17,7 +17,7 @@ use scale_info::TypeInfo; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; use sp_api::impl_runtime_apis; -use sp_core::{crypto::KeyTypeId, ConstU128, OpaqueMetadata, H160}; +use sp_core::{ConstU128, OpaqueMetadata, H160}; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, ConvertInto}, @@ -32,12 +32,11 @@ use sp_version::RuntimeVersion; use frame_support::{ construct_runtime, - dispatch::{DispatchClass, GetStorageVersion}, - pallet_prelude::StorageVersion, + dispatch::{DispatchClass}, parameter_types, traits::{ - AsEnsureOriginWithArg, ConstU32, ConstU64, Contains, Currency, Imbalance, OnUnbalanced, - PrivilegeCmp, + AsEnsureOriginWithArg, ConstBool, ConstU32, ConstU64, Contains, Currency, Imbalance, + OnUnbalanced, PrivilegeCmp, }, weights::{constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, Weight}, PalletId, RuntimeDebug, @@ -110,11 +109,11 @@ where } pub use node_primitives::{AccountId, Signature}; -use node_primitives::{Balance, BlockNumber, Hash, Index}; +use node_primitives::{Balance, BlockNumber, Hash, Nonce}; use runtime_common::{ constants::{currency::*, time::*}, - opaque, weights, Address, Header, OperationalFeeMultiplier, TransactionByteFee, WeightToFee, + weights, Address, Header, OperationalFeeMultiplier, TransactionByteFee, WeightToFee, }; use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; @@ -155,104 +154,10 @@ pub type Executive = frame_executive::Executive< AllPalletsWithSystem, ( pallet_parachain_staking::migration::EnableEthBridgeWireUp, - SeedBridgeTransactionAndDropEthTransactions, ), >; -const ETHEREUM_TRANSACTIONS_PREFIX: &[u8] = b"EthereumTransactions"; -const STORAGE_ITEM_NAMES: &[&'static str] = &[ - "Repository", - "DispatchedAvnTxIds", - "ReservedTransactions", - "PublishRootContract", - "Nonce", - "StorageVersion", -]; -pub struct SeedBridgeTransactionAndDropEthTransactions; - -impl frame_support::traits::OnRuntimeUpgrade for SeedBridgeTransactionAndDropEthTransactions { - fn on_runtime_upgrade() -> frame_support::weights::Weight { - let migration_version = StorageVersion::new(1); - let current = pallet_eth_bridge::Pallet::::current_storage_version(); - let onchain = pallet_eth_bridge::Pallet::::on_chain_storage_version(); - - if onchain < 1 { - log::info!( - "🚧 Running migration. Current storage version: {:?}, on-chain version: {:?}", - current, - onchain - ); - - let mut total_weight = Weight::zero(); - - match try_seed_next_tx_id() { - Ok(weight) => total_weight += weight, - Err(_) => log::info!("💔 Failed to seed transaction Id"), - } - - total_weight += clear_ethereum_transactions_storage(); - - migration_version.put::>(); - - log::info!("🚧 Migration successfull"); - - return total_weight - } - Weight::zero() - } - - #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, &'static str> { - let pre_upgrade_transaction_id: u64 = get_nonce_seed().unwrap(); - Ok((pre_upgrade_transaction_id + 1u64).encode()) - } - - #[cfg(feature = "try-runtime")] - fn post_upgrade(new_transaction_id_bytes: Vec) -> Result<(), &'static str> { - let next_tx_id: u32 = pallet_eth_bridge::Pallet::::get_next_tx_id(); - assert_eq!((next_tx_id as u64).encode(), new_transaction_id_bytes); - Ok(()) - } -} - -fn try_seed_next_tx_id() -> Result { - let nonce_seed = get_nonce_seed()?; - let tx_id: u32 = nonce_seed.try_into().map_err(|_| ())?; - as pallet_eth_bridge::Store>::NextTxId::put(tx_id + 1); - log::info!("✅ Transaction Id seeded to {}", tx_id + 1); - Ok(::DbWeight::get().reads_writes(1, 1)) -} - -fn get_nonce_seed() -> Result { - let nonce_prefix = - frame_support::storage::storage_prefix(ETHEREUM_TRANSACTIONS_PREFIX, b"Nonce"); - frame_support::storage::unhashed::get::(&nonce_prefix).ok_or(()) -} - -fn clear_ethereum_transactions_storage() -> Weight { - STORAGE_ITEM_NAMES.iter().fold(Weight::zero(), |acc, &item_name| { - let storage_prefix = frame_support::storage::storage_prefix( - ETHEREUM_TRANSACTIONS_PREFIX, - item_name.as_bytes(), - ); - let mut storage_key = [0u8; 32]; - storage_key[0..32].copy_from_slice(&storage_prefix); - - match item_name { - "PublishRootContract" | "Nonce" | "StorageVersion" => { - frame_support::storage::unhashed::kill(&storage_key); - log::info!("🚧 Successfully migrated {}", item_name); - acc + ::DbWeight::get().writes(1) - }, - _ => { - frame_support::storage::unhashed::clear_prefix(&storage_key, None, None); - log::info!("🚧 Successfully migrated {}", item_name); - acc + ::DbWeight::get().writes(1) - }, - } - }) -} impl_opaque_keys! { pub struct SessionKeys { @@ -298,7 +203,7 @@ const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); /// We allow for 0.5 of a second of compute with a 12 second average block time. const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts( WEIGHT_REF_TIME_PER_SECOND.saturating_div(2), - cumulus_primitives_core::relay_chain::v2::MAX_POV_SIZE as u64, + cumulus_primitives_core::relay_chain::MAX_POV_SIZE as u64, ); /// The version information used to identify this runtime when compiled natively. @@ -385,15 +290,13 @@ impl frame_system::Config for Runtime { /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = AccountIdLookup; /// The index type for storing how many extrinsics an account has signed. - type Index = Index; - /// The index type for blocks. - type BlockNumber = BlockNumber; + type Nonce = Nonce; /// The type for hashing blocks and tries. type Hash = Hash; /// The hashing algorithm used. type Hashing = BlakeTwo256; /// The header type. - type Header = generic::Header; + type Block = Block; /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; // type Call = Call; @@ -438,8 +341,6 @@ impl pallet_timestamp::Config for Runtime { impl pallet_authorship::Config for Runtime { type FindAuthor = pallet_session::FindAccountFromAuthorIndex; - type UncleGenerations = ConstU32<0>; - type FilterUncle = (); type EventHandler = (ParachainStaking,); } @@ -459,6 +360,10 @@ impl pallet_balances::Config for Runtime { type WeightInfo = pallet_balances::weights::SubstrateWeight; type MaxReserves = ConstU32<50>; type ReserveIdentifier = [u8; 8]; + type RuntimeHoldReason = RuntimeHoldReason; + type FreezeIdentifier = (); + type MaxHolds = ConstU32<0>; + type MaxFreezes = ConstU32<0>; } impl pallet_transaction_payment::Config for Runtime { @@ -501,6 +406,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type ControllerOrigin = EnsureRoot; type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; type WeightInfo = (); + type PriceForSiblingDelivery = (); } impl cumulus_pallet_dmp_queue::Config for Runtime { @@ -532,6 +438,7 @@ impl pallet_aura::Config for Runtime { type AuthorityId = AuraId; type DisabledValidators = (); type MaxAuthorities = ConstU32<100_000>; + type AllowMultipleBlocksPerSlot = ConstBool; } parameter_types! { @@ -612,12 +519,12 @@ impl pallet_im_online::Config for Runtime { type WeightInfo = pallet_im_online::weights::SubstrateWeight; type MaxKeys = MaxKeys; type MaxPeerInHeartbeats = MaxPeerInHeartbeats; - type MaxPeerDataEncodingSize = MaxPeerDataEncodingSize; } impl pallet_sudo::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; + type WeightInfo = (); } impl pallet_utility::Config for Runtime { @@ -771,6 +678,7 @@ impl pallet_assets::Config for Runtime { type StringLimit = StringLimit; type Freezer = (); type Extra = (); + type CallbackHandle = (); type WeightInfo = pallet_assets::weights::SubstrateWeight; #[cfg(feature = "runtime-benchmarks")] type BenchmarkHelper = (); @@ -824,38 +732,33 @@ impl pallet_preimage::Config for Runtime { // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( - pub enum Runtime where - Block = Block, - NodeBlock = opaque::Block, - UncheckedExtrinsic = UncheckedExtrinsic, + pub enum Runtime { // System support stuff. - System: frame_system::{Pallet, Call, Config, Storage, Event} = 0, - ParachainSystem: cumulus_pallet_parachain_system::{ - Pallet, Call, Config, Storage, Inherent, Event, ValidateUnsigned, - } = 1, - Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 2, - ParachainInfo: parachain_info::{Pallet, Storage, Config} = 3, + System: frame_system = 0, + ParachainSystem: cumulus_pallet_parachain_system = 1, + Timestamp: pallet_timestamp = 2, + ParachainInfo: parachain_info = 3, // Monetary stuff. Balances: pallet_balances::{Pallet, Call, Storage, Config, Event} = 10, TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event} = 11, // Collator support. The order of these 4 are important and shall not change. - Authorship: pallet_authorship::{Pallet, Call, Storage} = 20, - Session: pallet_session::{Pallet, Call, Storage, Event, Config} = 22, - Aura: pallet_aura::{Pallet, Storage, Config} = 23, - AuraExt: cumulus_pallet_aura_ext::{Pallet, Storage, Config} = 24, - ParachainStaking: pallet_parachain_staking::{Pallet, Call, Storage, Event, Config} = 96, + Authorship: pallet_authorship = 20, + Session: pallet_session = 22, + Aura: pallet_aura = 23, + AuraExt: cumulus_pallet_aura_ext = 24, + ParachainStaking: pallet_parachain_staking = 96, // Since the ValidatorsManager integrates with the ParachainStaking pallet, we want to initialise after it. ValidatorsManager: pallet_validators_manager = 18, // XCM helpers. - XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event} = 30, - PolkadotXcm: pallet_xcm::{Pallet, Call, Event, Origin, Config} = 31, - CumulusXcm: cumulus_pallet_xcm::{Pallet, Event, Origin} = 32, - DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event} = 33, + XcmpQueue: cumulus_pallet_xcmp_queue = 30, + PolkadotXcm: pallet_xcm = 31, + CumulusXcm: cumulus_pallet_xcm = 32, + DmpQueue: cumulus_pallet_dmp_queue = 33, // Substrate pallets Assets: pallet_assets = 60, @@ -942,6 +845,14 @@ impl_runtime_apis! { fn metadata() -> OpaqueMetadata { OpaqueMetadata::new(Runtime::metadata().into()) } + + fn metadata_at_version(version: u32) -> Option { + Runtime::metadata_at_version(version) + } + + fn metadata_versions() -> sp_std::vec::Vec { + Runtime::metadata_versions() + } } impl sp_block_builder::BlockBuilder for Runtime { @@ -981,24 +892,6 @@ impl_runtime_apis! { } } - impl sp_session::SessionKeys for Runtime { - fn generate_session_keys(seed: Option>) -> Vec { - SessionKeys::generate(seed) - } - - fn decode_session_keys( - encoded: Vec, - ) -> Option, KeyTypeId)>> { - SessionKeys::decode_into_raw_public_keys(&encoded) - } - } - - impl frame_system_rpc_runtime_api::AccountNonceApi for Runtime { - fn account_nonce(account: AccountId) -> Index { - System::account_nonce(account) - } - } - impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi for Runtime { fn query_info( uxt: ::Extrinsic, @@ -1012,9 +905,22 @@ impl_runtime_apis! { ) -> pallet_transaction_payment::FeeDetails { TransactionPayment::query_fee_details(uxt, len) } + + fn query_weight_to_fee(weight: Weight) -> Balance { + TransactionPayment::weight_to_fee(weight) + } + fn query_length_to_fee(length: u32) -> Balance { + TransactionPayment::length_to_fee(length) + } + } + + impl frame_system_rpc_runtime_api::AccountNonceApi for Runtime { + fn account_nonce(account: AccountId) -> Nonce { + System::account_nonce(account) + } } - impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentCallApi + impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentCallApi for Runtime { fn query_call_info( @@ -1029,6 +935,13 @@ impl_runtime_apis! { ) -> pallet_transaction_payment::FeeDetails { TransactionPayment::query_call_fee_details(call, len) } + + fn query_weight_to_fee(weight: Weight) -> Balance { + TransactionPayment::weight_to_fee(weight) + } + fn query_length_to_fee(length: u32) -> Balance { + TransactionPayment::length_to_fee(length) + } } impl cumulus_primitives_core::CollectCollationInfo for Runtime { fn collect_collation_info(header: &::Header) -> cumulus_primitives_core::CollationInfo { diff --git a/runtime/test/src/xcm_config.rs b/runtime/test/src/xcm_config.rs index 7e04e52a8..1cf59bfc7 100644 --- a/runtime/test/src/xcm_config.rs +++ b/runtime/test/src/xcm_config.rs @@ -1,30 +1,32 @@ use super::{ - AccountId, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, - RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, + AccountId, AllPalletsWithSystem, Balances, ParachainInfo, ParachainSystem, PolkadotXcm, + Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, WeightToFee, XcmpQueue, }; -use core::marker::PhantomData; use frame_support::{ - log, match_types, parameter_types, - traits::{Everything, Nothing}, + match_types, parameter_types, + traits::{ConstU32, Everything, Nothing}, }; +use frame_system::EnsureRoot; use pallet_xcm::XcmPassthrough; use polkadot_parachain::primitives::Sibling; use polkadot_runtime_common::impls::ToAuthor; -use xcm::latest::{prelude::*, Weight as XCMWeight}; +use xcm::latest::{prelude::*}; use xcm_builder::{ - AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, CurrencyAdapter, - EnsureXcmOrigin, FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset, ParentIsPreset, + AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowTopLevelPaidExecutionFrom, + CurrencyAdapter, DenyReserveTransferToRelayChain, DenyThenTry, + EnsureXcmOrigin, FixedWeightBounds, IsConcrete, NativeAsset, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, - UsingComponents, + TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, WithUniqueTopic, }; -use xcm_executor::{traits::ShouldExecute, XcmExecutor}; +use xcm_executor::{XcmExecutor}; parameter_types! { pub const RelayLocation: MultiLocation = MultiLocation::parent(); - pub const RelayNetwork: NetworkId = NetworkId::Any; + pub const RelayNetwork: Option = None; pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub Ancestry: MultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); + pub UniversalLocation: InteriorMultiLocation = Parachain(ParachainInfo::parachain_id().into()).into(); } /// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used @@ -76,8 +78,9 @@ pub type XcmOriginToTransactDispatchOrigin = ( parameter_types! { // One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate. - pub UnitWeightCost: u64 = 1_000_000_000; + pub UnitWeightCost: Weight = Weight::from_parts(1_000_000_000, 64 * 1024); pub const MaxInstructions: u32 = 100; + pub const MaxAssetsIntoHolding: u32 = 64; } match_types! { @@ -87,79 +90,22 @@ match_types! { }; } -//TODO: move DenyThenTry to polkadot's xcm module. -/// Deny executing the xcm message if it matches any of the Deny filter regardless of anything else. -/// If it passes the Deny, and matches one of the Allow cases then it is let through. -pub struct DenyThenTry(PhantomData, PhantomData) -where - Deny: ShouldExecute, - Allow: ShouldExecute; - -impl ShouldExecute for DenyThenTry -where - Deny: ShouldExecute, - Allow: ShouldExecute, -{ - fn should_execute( - origin: &MultiLocation, - message: &mut Xcm, - max_weight: XCMWeight, - weight_credit: &mut XCMWeight, - ) -> Result<(), ()> { - Deny::should_execute(origin, message, max_weight, weight_credit)?; - Allow::should_execute(origin, message, max_weight, weight_credit) - } -} - -// See issue -pub struct DenyReserveTransferToRelayChain; -impl ShouldExecute for DenyReserveTransferToRelayChain { - fn should_execute( - origin: &MultiLocation, - - message: &mut Xcm, - _max_weight: XCMWeight, - _weight_credit: &mut XCMWeight, - ) -> Result<(), ()> { - if message.0.iter().any(|inst| { - matches!( - inst, - InitiateReserveWithdraw { - reserve: MultiLocation { parents: 1, interior: Here }, - .. - } | DepositReserveAsset { dest: MultiLocation { parents: 1, interior: Here }, .. } | - TransferReserveAsset { - dest: MultiLocation { parents: 1, interior: Here }, - .. - } - ) - }) { - return Err(()) // Deny - } - - // An unexpected reserve transfer has arrived from the Relay Chain. Generally, `IsReserve` - // should not allow this, but we just log it here. - if matches!(origin, MultiLocation { parents: 1, interior: Here }) && - message.0.iter().any(|inst| matches!(inst, ReserveAssetDeposited { .. })) - { - log::warn!( - target: "xcm::barriers", - "Unexpected ReserveAssetDeposited from the Relay Chain", - ); - } - // Permit everything else - Ok(()) - } -} - -pub type Barrier = DenyThenTry< - DenyReserveTransferToRelayChain, - ( - TakeWeightCredit, - AllowTopLevelPaidExecutionFrom, - AllowUnpaidExecutionFrom, - // ^^^ Parent and its exec plurality get free execution - ), +pub type Barrier = TrailingSetTopicAsId< + DenyThenTry< + DenyReserveTransferToRelayChain, + ( + TakeWeightCredit, + WithComputedOrigin< + ( + AllowTopLevelPaidExecutionFrom, + AllowExplicitUnpaidExecutionFrom, + // ^^^ Parent and its exec plurality get free execution + ), + UniversalLocation, + ConstU32<8>, + >, + ), + >, >; pub struct XcmConfig; @@ -171,7 +117,7 @@ impl xcm_executor::Config for XcmConfig { type OriginConverter = XcmOriginToTransactDispatchOrigin; type IsReserve = NativeAsset; type IsTeleporter = (); // Teleporting is disabled. - type LocationInverter = LocationInverter; + type UniversalLocation = UniversalLocation; type Barrier = Barrier; type Weigher = FixedWeightBounds; type Trader = @@ -180,6 +126,16 @@ impl xcm_executor::Config for XcmConfig { type AssetTrap = PolkadotXcm; type AssetClaims = PolkadotXcm; type SubscriptionService = PolkadotXcm; + type PalletInstancesInfo = AllPalletsWithSystem; + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type AssetLocker = (); + type AssetExchanger = (); + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; + type CallDispatcher = RuntimeCall; + type SafeCallFilter = Everything; + type Aliasers = Nothing; } /// No local origins on this chain are allowed to dispatch XCM sends/executions. @@ -187,12 +143,17 @@ pub type LocalOriginToLocation = SignedToAccountId32, + cumulus_primitives_utility::ParentAsUmp, // ..and XCMP to communicate with the sibling chains. XcmpQueue, -); +)>; + +#[cfg(feature = "runtime-benchmarks")] +parameter_types! { + pub ReachableDest: Option = Some(Parent.into()); +} impl pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; @@ -206,13 +167,24 @@ impl pallet_xcm::Config for Runtime { type XcmTeleportFilter = Everything; type XcmReserveTransferFilter = Nothing; type Weigher = FixedWeightBounds; - type LocationInverter = LocationInverter; + type UniversalLocation = UniversalLocation; type RuntimeOrigin = RuntimeOrigin; type RuntimeCall = RuntimeCall; const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; // ^ Override for AdvertisedXcmVersion default type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; + type Currency = Balances; + type CurrencyMatcher = (); + type TrustedLockers = (); + type SovereignAccountOf = LocationToAccountId; + type MaxLockers = ConstU32<8>; + type WeightInfo = pallet_xcm::TestWeightInfo; + #[cfg(feature = "runtime-benchmarks")] + type ReachableDest = ReachableDest; + type AdminOrigin = EnsureRoot; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); } impl cumulus_pallet_xcm::Config for Runtime {