diff --git a/Cargo.lock b/Cargo.lock index 62f6e87982..b71b1f59dd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -792,7 +792,7 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "basilisk" -version = "11.0.0" +version = "11.1.0" dependencies = [ "basilisk-runtime", "clap", @@ -861,17 +861,20 @@ dependencies = [ "sp-offchain", "sp-runtime", "sp-session", + "sp-state-machine", "sp-storage", "sp-timestamp", "sp-transaction-pool", "sp-trie", "substrate-frame-rpc-system", "substrate-prometheus-endpoint", + "substrate-state-trie-migration-rpc", + "trie-db 0.28.0", ] [[package]] name = "basilisk-runtime" -version = "111.0.0" +version = "112.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", @@ -926,6 +929,7 @@ dependencies = [ "pallet-route-executor", "pallet-scheduler", "pallet-session", + "pallet-state-trie-migration", "pallet-timestamp", "pallet-tips", "pallet-transaction-multi-payment", @@ -2128,7 +2132,7 @@ dependencies = [ "sp-trie", "sp-version", "staging-xcm", - "trie-db", + "trie-db 0.27.1", ] [[package]] @@ -12842,7 +12846,7 @@ dependencies = [ "sp-trie", "thiserror", "tracing", - "trie-db", + "trie-db 0.27.1", ] [[package]] @@ -12967,7 +12971,7 @@ dependencies = [ "sp-std", "thiserror", "tracing", - "trie-db", + "trie-db 0.27.1", "trie-root", ] @@ -13416,7 +13420,7 @@ dependencies = [ "sp-runtime", "sp-state-machine", "sp-trie", - "trie-db", + "trie-db 0.27.1", ] [[package]] @@ -14059,6 +14063,19 @@ dependencies = [ "smallvec", ] +[[package]] +name = "trie-db" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff28e0f815c2fea41ebddf148e008b077d2faddb026c9555b29696114d602642" +dependencies = [ + "hash-db 0.16.0", + "hashbrown 0.13.2", + "log", + "rustc-hex", + "smallvec", +] + [[package]] name = "trie-root" version = "0.18.0" diff --git a/Cargo.toml b/Cargo.toml index 14ef6374fa..d0d34b6bb3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -72,6 +72,7 @@ pallet-society = { git = "https://github.com/paritytech/polkadot-sdk", rev = "c8 pallet-staking = { git = "https://github.com/paritytech/polkadot-sdk", rev = "c8d2251cafadc108ba2f1f8a3208dc547ff38901", default-features = false } pallet-staking-reward-curve = { git = "https://github.com/paritytech/polkadot-sdk", rev = "c8d2251cafadc108ba2f1f8a3208dc547ff38901", default-features = false } pallet-staking-reward-fn = { git = "https://github.com/paritytech/polkadot-sdk", rev = "c8d2251cafadc108ba2f1f8a3208dc547ff38901", default-features = false } +pallet-state-trie-migration = { git = "https://github.com/paritytech/polkadot-sdk", rev = "c8d2251cafadc108ba2f1f8a3208dc547ff38901", default-features = false } pallet-sudo = { git = "https://github.com/paritytech/polkadot-sdk", rev = "c8d2251cafadc108ba2f1f8a3208dc547ff38901", default-features = false } pallet-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", rev = "c8d2251cafadc108ba2f1f8a3208dc547ff38901", default-features = false } pallet-tips = { git = "https://github.com/paritytech/polkadot-sdk", rev = "c8d2251cafadc108ba2f1f8a3208dc547ff38901", default-features = false } @@ -161,6 +162,7 @@ substrate-prometheus-endpoint = { git = "https://github.com/paritytech/polkadot- substrate-wasm-builder = { git = "https://github.com/paritytech/polkadot-sdk", rev = "c8d2251cafadc108ba2f1f8a3208dc547ff38901", default-features = false } pallet-mmr = { git = "https://github.com/paritytech/polkadot-sdk", rev = "c8d2251cafadc108ba2f1f8a3208dc547ff38901", default-features = false } sp-mmr-primitives = { git = "https://github.com/paritytech/polkadot-sdk", rev = "c8d2251cafadc108ba2f1f8a3208dc547ff38901", default-features = false } +substrate-state-trie-migration-rpc = { git = "https://github.com/paritytech/polkadot-sdk", rev = "c8d2251cafadc108ba2f1f8a3208dc547ff38901" } kusama-runtime = { package = "staging-kusama-runtime", git = "https://github.com/paritytech/polkadot-sdk", rev = "c8d2251cafadc108ba2f1f8a3208dc547ff38901", default-features = false } pallet-xcm = { git = "https://github.com/paritytech/polkadot-sdk", rev = "c8d2251cafadc108ba2f1f8a3208dc547ff38901", default-features = false } @@ -263,6 +265,7 @@ pallet-society = { git = "https://github.com/galacticcouncil/polkadot-sdk", rev pallet-staking = { git = "https://github.com/galacticcouncil/polkadot-sdk", rev = "062d92eae0f3bb9908faf2d4e241eef17368b9d3" } pallet-staking-reward-curve = { git = "https://github.com/galacticcouncil/polkadot-sdk", rev = "062d92eae0f3bb9908faf2d4e241eef17368b9d3" } pallet-staking-reward-fn = { git = "https://github.com/galacticcouncil/polkadot-sdk", rev = "062d92eae0f3bb9908faf2d4e241eef17368b9d3" } +pallet-state-trie-migration = { git = "https://github.com/galacticcouncil/polkadot-sdk", rev = "062d92eae0f3bb9908faf2d4e241eef17368b9d3" } pallet-sudo = { git = "https://github.com/galacticcouncil/polkadot-sdk", rev = "062d92eae0f3bb9908faf2d4e241eef17368b9d3" } pallet-timestamp = { git = "https://github.com/galacticcouncil/polkadot-sdk", rev = "062d92eae0f3bb9908faf2d4e241eef17368b9d3" } pallet-tips = { git = "https://github.com/galacticcouncil/polkadot-sdk", rev = "062d92eae0f3bb9908faf2d4e241eef17368b9d3" } @@ -352,6 +355,7 @@ substrate-prometheus-endpoint = { git = "https://github.com/galacticcouncil/polk substrate-wasm-builder = { git = "https://github.com/galacticcouncil/polkadot-sdk", rev = "062d92eae0f3bb9908faf2d4e241eef17368b9d3" } pallet-mmr = { git = "https://github.com/galacticcouncil/polkadot-sdk", rev = "062d92eae0f3bb9908faf2d4e241eef17368b9d3" } sp-mmr-primitives = { git = "https://github.com/galacticcouncil/polkadot-sdk", rev = "062d92eae0f3bb9908faf2d4e241eef17368b9d3" } +substrate-state-trie-migration-rpc = { git = "https://github.com/galacticcouncil/polkadot-sdk", rev = "062d92eae0f3bb9908faf2d4e241eef17368b9d3" } kusama-runtime = { package = "staging-kusama-runtime", git = "https://github.com/galacticcouncil/polkadot-sdk", rev = "062d92eae0f3bb9908faf2d4e241eef17368b9d3" } pallet-xcm = { git = "https://github.com/galacticcouncil/polkadot-sdk", rev = "062d92eae0f3bb9908faf2d4e241eef17368b9d3" } diff --git a/node/Cargo.toml b/node/Cargo.toml index b1d7d5b18b..018181bfba 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "basilisk" -version = "11.0.0" +version = "11.1.0" description = "Basilisk node" authors = ["GalacticCouncil"] edition = "2021" @@ -79,6 +79,10 @@ frame-system-rpc-runtime-api = { workspace = true } pallet-transaction-payment-rpc-runtime-api = { workspace = true } sp-authority-discovery = { workspace = true } frame-try-runtime = { workspace = true, optional = true } +substrate-state-trie-migration-rpc = { workspace = true } + +trie-db = "0.28.0" +sp-state-machine = { workspace = true } # Cumulus dependencies cumulus-client-cli = { workspace = true } diff --git a/node/src/rpc.rs b/node/src/rpc.rs index eee5633482..35f3a3bec7 100644 --- a/node/src/rpc.rs +++ b/node/src/rpc.rs @@ -16,20 +16,22 @@ use sp_block_builder::BlockBuilder; use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; /// Full client dependencies. -pub struct FullDeps { +pub struct FullDeps { /// The client instance to use. pub client: Arc, /// Transaction pool instance. pub pool: Arc

, /// Whether to deny unsafe calls pub deny_unsafe: DenyUnsafe, + /// Backend used by the node. + pub backend: Arc, } /// RPC Extension Builder pub type RpcExtension = jsonrpsee::RpcModule<()>; /// Instantiate all full RPC extensions. -pub fn create_full(deps: FullDeps) -> Result> +pub fn create_full(deps: FullDeps) -> Result> where C: ProvideRuntimeApi + sc_client_api::BlockBackend, C: HeaderBackend + HeaderMetadata, @@ -38,19 +40,24 @@ where C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi, C::Api: BlockBuilder, P: TransactionPool + Sync + Send + 'static, + B: sc_client_api::Backend + Send + Sync + 'static, + B::State: sc_client_api::StateBackend>, { use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer}; use substrate_frame_rpc_system::{System, SystemApiServer}; + use substrate_state_trie_migration_rpc::{StateMigration, StateMigrationApiServer}; let mut module = RpcExtension::new(()); let FullDeps { client, pool, deny_unsafe, + backend, } = deps; module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?; - module.merge(TransactionPayment::new(client).into_rpc())?; + module.merge(TransactionPayment::new(client.clone()).into_rpc())?; + module.merge(StateMigration::new(client, backend, deny_unsafe).into_rpc())?; // Extend this RPC with a custom API by using the following syntax. // `YourRpcStruct` should have a reference to a client, which is needed diff --git a/node/src/service.rs b/node/src/service.rs index 9716ba1cd9..2e5fe6ee07 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -238,12 +238,14 @@ async fn start_node_impl( let rpc_builder = { let client = client.clone(); let transaction_pool = transaction_pool.clone(); + let backend = backend.clone(); Box::new(move |deny_unsafe, _| { let deps = crate::rpc::FullDeps { client: client.clone(), pool: transaction_pool.clone(), deny_unsafe, + backend: backend.clone(), }; crate::rpc::create_full(deps).map_err(Into::into) diff --git a/runtime/basilisk/Cargo.toml b/runtime/basilisk/Cargo.toml index 70eda5f940..625b84cd2c 100644 --- a/runtime/basilisk/Cargo.toml +++ b/runtime/basilisk/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "basilisk-runtime" -version = "111.0.0" +version = "112.0.0" authors = ["GalacticCouncil"] edition = "2021" homepage = "https://github.com/galacticcouncil/Basilisk-node" @@ -33,6 +33,7 @@ pallet-scheduler = { workspace = true } pallet-elections-phragmen = { workspace = true } pallet-tips = { workspace = true } pallet-identity = { workspace = true } +pallet-state-trie-migration = { workspace = true } # HydraDX dependencies hydradx-traits = { workspace = true } @@ -161,6 +162,7 @@ runtime-benchmarks = [ "cumulus-pallet-parachain-system/runtime-benchmarks", "pallet-xcm-rate-limiter/runtime-benchmarks", "pallet-elections-phragmen/runtime-benchmarks", + "pallet-state-trie-migration/runtime-benchmarks", ] std = [ "codec/std", @@ -238,6 +240,7 @@ std = [ "pallet-identity/std", "pallet-ema-oracle/std", "pallet-xcm-rate-limiter/std", + "pallet-state-trie-migration/std", ] try-runtime= [ "frame-try-runtime", @@ -290,4 +293,5 @@ try-runtime= [ "pallet-ema-oracle/try-runtime", "pallet-collator-rewards/try-runtime", "pallet-xcm-rate-limiter/try-runtime", + "pallet-state-trie-migration/try-runtime", ] diff --git a/runtime/basilisk/src/lib.rs b/runtime/basilisk/src/lib.rs index df468dacc0..4069ba9b17 100644 --- a/runtime/basilisk/src/lib.rs +++ b/runtime/basilisk/src/lib.rs @@ -16,8 +16,8 @@ // limitations under the License. #![cfg_attr(not(feature = "std"), no_std)] -// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256. -#![recursion_limit = "256"] +// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 512. +#![recursion_limit = "512"] #![allow(clippy::upper_case_acronyms)] #![allow(clippy::type_complexity)] #![allow(clippy::large_enum_variant)] @@ -102,11 +102,11 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("basilisk"), impl_name: create_runtime_str!("basilisk"), authoring_version: 1, - spec_version: 111, + spec_version: 112, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, - state_version: 0, + state_version: 1, }; /// The version information used to identify this runtime when compiled natively. @@ -188,6 +188,7 @@ construct_runtime!( Uniques: pallet_uniques = 20, Identity: pallet_identity = 21, Multisig: pallet_multisig = 22, + StateTrieMigration: pallet_state_trie_migration = 23, // Parachain and XCM - starts at index 50 ParachainSystem: cumulus_pallet_parachain_system exclude_parts { Config } = 50, @@ -444,6 +445,7 @@ impl_runtime_apis! { list_benchmark!(list, extra, pallet_utility, Utility); list_benchmark!(list, extra, pallet_tips, Tips); list_benchmark!(list, extra, pallet_collective, TechnicalCommittee); + list_benchmark!(list, extra, pallet_state_trie_migration, StateTrieMigration); list_benchmark!(list, extra, cumulus_pallet_xcmp_queue, XcmpQueue); list_benchmark!(list, extra, pallet_xcm, PolkadotXcm); @@ -523,6 +525,7 @@ impl_runtime_apis! { add_benchmark!(params, batches, pallet_utility, Utility); add_benchmark!(params, batches, pallet_tips, Tips); add_benchmark!(params, batches, pallet_collective, TechnicalCommittee); + add_benchmark!(params, batches, pallet_state_trie_migration, StateTrieMigration); add_benchmark!(params, batches, cumulus_pallet_xcmp_queue, XcmpQueue); add_benchmark!(params, batches, pallet_xcm, PolkadotXcm); diff --git a/runtime/basilisk/src/system.rs b/runtime/basilisk/src/system.rs index 878ef3d05b..0f6cc4bac8 100644 --- a/runtime/basilisk/src/system.rs +++ b/runtime/basilisk/src/system.rs @@ -31,13 +31,14 @@ use frame_support::{ dispatch::DispatchClass, parameter_types, sp_runtime::{traits::IdentityLookup, FixedPointNumber, Perbill, Perquintill, RuntimeDebug}, - traits::{ConstBool, Contains, InstanceFilter}, + traits::{ConstBool, Contains, InstanceFilter, SortedMembers}, weights::{ constants::{BlockExecutionWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_MICROS}, ConstantMultiplier, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial, }, PalletId, }; +use frame_system::EnsureSignedBy; use hydradx_adapters::RelayChainBlockNumberProvider; use scale_info::TypeInfo; @@ -468,3 +469,28 @@ impl pallet_multisig::Config for Runtime { type MaxSignatories = MaxSignatories; type WeightInfo = (); } + +pub struct TechCommAccounts; +impl SortedMembers for TechCommAccounts { + fn sorted_members() -> Vec { + TechnicalCommittee::members() + } +} + +parameter_types! { + // The deposit configuration for the singed migration. Specially if you want to allow any signed account to do the migration (see `SignedFilter`, these deposits should be high) + pub const MigrationSignedDepositPerItem: Balance = CENTS; + pub const MigrationSignedDepositBase: Balance = 20 * DOLLARS; + pub const MaxKeyLen: u32 = 512; // 144, but use the default value +} + +impl pallet_state_trie_migration::Config for Runtime { + type ControlOrigin = SuperMajorityTechCommitteeOrRoot; + type SignedFilter = EnsureSignedBy; + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type MaxKeyLen = MaxKeyLen; + type SignedDepositPerItem = MigrationSignedDepositPerItem; + type SignedDepositBase = MigrationSignedDepositBase; + type WeightInfo = weights::state_trie::BasiliskWeight; +} diff --git a/runtime/basilisk/src/weights/mod.rs b/runtime/basilisk/src/weights/mod.rs index 7a7a4bac46..a7ed2c3331 100644 --- a/runtime/basilisk/src/weights/mod.rs +++ b/runtime/basilisk/src/weights/mod.rs @@ -13,6 +13,7 @@ pub mod nft; pub mod payment; pub mod route_executor; pub mod scheduler; +pub mod state_trie; pub mod system; pub mod timestamp; pub mod tips; diff --git a/runtime/basilisk/src/weights/state_trie.rs b/runtime/basilisk/src/weights/state_trie.rs new file mode 100644 index 0000000000..863068a8ce --- /dev/null +++ b/runtime/basilisk/src/weights/state_trie.rs @@ -0,0 +1,125 @@ +// This file is part of Basilisk. + +// Copyright (C) 2020-2023 Intergalactic, Limited (GIB). +// 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. + +//! Autogenerated weights for `pallet_state_trie_migration` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2024-01-26, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` + +// Executed Command: +// target/release/basilisk +// benchmark +// pallet +// --chain=dev +// --steps=10 +// --repeat=30 +// --wasm-execution=compiled +// --heap-pages=4096 +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet-state-trie-migration +// --output=weights-1.1.0/state_trie.rs +// --extrinsic=* + +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(clippy::unnecessary_cast)] + +use frame_support::{traits::Get, weights::Weight}; +use sp_std::marker::PhantomData; + +use pallet_state_trie_migration::weights::WeightInfo; + +/// Weights for `pallet_state_trie_migration` using the Basilisk node and recommended hardware. +pub struct BasiliskWeight(PhantomData); +impl WeightInfo for BasiliskWeight { + /// Storage: `StateTrieMigration::SignedMigrationMaxLimits` (r:1 w:0) + /// Proof: `StateTrieMigration::SignedMigrationMaxLimits` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `StateTrieMigration::MigrationProcess` (r:1 w:1) + /// Proof: `StateTrieMigration::MigrationProcess` (`max_values`: Some(1), `max_size`: Some(1042), added: 1537, mode: `MaxEncodedLen`) + fn continue_migrate() -> Weight { + // Proof Size summary in bytes: + // Measured: `141` + // Estimated: `2527` + // Minimum execution time: 23_654_000 picoseconds. + Weight::from_parts(24_101_000, 2527) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `StateTrieMigration::SignedMigrationMaxLimits` (r:1 w:0) + /// Proof: `StateTrieMigration::SignedMigrationMaxLimits` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + fn continue_migrate_wrong_witness() -> Weight { + // Proof Size summary in bytes: + // Measured: `109` + // Estimated: `1493` + // Minimum execution time: 7_170_000 picoseconds. + Weight::from_parts(7_487_000, 1493).saturating_add(T::DbWeight::get().reads(1_u64)) + } + fn migrate_custom_top_success() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 13_335_000 picoseconds. + Weight::from_parts(13_596_000, 0) + } + /// Storage: UNKNOWN KEY `0x666f6f` (r:1 w:1) + /// Proof: UNKNOWN KEY `0x666f6f` (r:1 w:1) + fn migrate_custom_top_fail() -> Weight { + // Proof Size summary in bytes: + // Measured: `146` + // Estimated: `3611` + // Minimum execution time: 40_202_000 picoseconds. + Weight::from_parts(40_793_000, 3611) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + fn migrate_custom_child_success() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 13_441_000 picoseconds. + Weight::from_parts(13_910_000, 0) + } + /// Storage: UNKNOWN KEY `0x666f6f` (r:1 w:1) + /// Proof: UNKNOWN KEY `0x666f6f` (r:1 w:1) + fn migrate_custom_child_fail() -> Weight { + // Proof Size summary in bytes: + // Measured: `106` + // Estimated: `3571` + // Minimum execution time: 39_284_000 picoseconds. + Weight::from_parts(39_823_000, 3571) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: UNKNOWN KEY `0x6b6579` (r:1 w:1) + /// Proof: UNKNOWN KEY `0x6b6579` (r:1 w:1) + /// The range of component `v` is `[1, 4194304]`. + fn process_top_key(v: u32) -> Weight { + // Proof Size summary in bytes: + // Measured: `262 + v * (1 ±0)` + // Estimated: `3725 + v * (1 ±0)` + // Minimum execution time: 6_940_000 picoseconds. + Weight::from_parts(7_084_000, 3725) + // Standard Error: 2 + .saturating_add(Weight::from_parts(1_372, 0).saturating_mul(v.into())) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + .saturating_add(Weight::from_parts(0, 1).saturating_mul(v.into())) + } +}