Skip to content

Commit

Permalink
Merge pull request #654 from galacticcouncil/state_trie_migration
Browse files Browse the repository at this point in the history
feat: state trie migration
  • Loading branch information
Roznovjak authored Mar 28, 2024
2 parents 48e2486 + 97bec6f commit 46c13fa
Show file tree
Hide file tree
Showing 10 changed files with 209 additions and 16 deletions.
29 changes: 23 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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" }
Expand Down Expand Up @@ -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" }
Expand Down
6 changes: 5 additions & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "basilisk"
version = "11.0.0"
version = "11.1.0"
description = "Basilisk node"
authors = ["GalacticCouncil"]
edition = "2021"
Expand Down Expand Up @@ -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 }
Expand Down
13 changes: 10 additions & 3 deletions node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@ use sp_block_builder::BlockBuilder;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};

/// Full client dependencies.
pub struct FullDeps<C, P> {
pub struct FullDeps<C, P, B> {
/// The client instance to use.
pub client: Arc<C>,
/// Transaction pool instance.
pub pool: Arc<P>,
/// Whether to deny unsafe calls
pub deny_unsafe: DenyUnsafe,
/// Backend used by the node.
pub backend: Arc<B>,
}

/// RPC Extension Builder
pub type RpcExtension = jsonrpsee::RpcModule<()>;

/// Instantiate all full RPC extensions.
pub fn create_full<C, P>(deps: FullDeps<C, P>) -> Result<RpcExtension, Box<dyn std::error::Error + Send + Sync>>
pub fn create_full<C, P, B>(deps: FullDeps<C, P, B>) -> Result<RpcExtension, Box<dyn std::error::Error + Send + Sync>>
where
C: ProvideRuntimeApi<Block> + sc_client_api::BlockBackend<Block>,
C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError>,
Expand All @@ -38,19 +40,24 @@ where
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: BlockBuilder<Block>,
P: TransactionPool + Sync + Send + 'static,
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
B::State: sc_client_api::StateBackend<sp_runtime::traits::HashingFor<Block>>,
{
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
Expand Down
2 changes: 2 additions & 0 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion runtime/basilisk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
]
11 changes: 7 additions & 4 deletions runtime/basilisk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
28 changes: 27 additions & 1 deletion runtime/basilisk/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -468,3 +469,28 @@ impl pallet_multisig::Config for Runtime {
type MaxSignatories = MaxSignatories;
type WeightInfo = ();
}

pub struct TechCommAccounts;
impl SortedMembers<AccountId> for TechCommAccounts {
fn sorted_members() -> Vec<AccountId> {
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<TechCommAccounts, AccountId>;
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type MaxKeyLen = MaxKeyLen;
type SignedDepositPerItem = MigrationSignedDepositPerItem;
type SignedDepositBase = MigrationSignedDepositBase;
type WeightInfo = weights::state_trie::BasiliskWeight<Runtime>;
}
1 change: 1 addition & 0 deletions runtime/basilisk/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 46c13fa

Please sign in to comment.