diff --git a/Cargo.lock b/Cargo.lock index 2566264fa42..55531fe76da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3413,6 +3413,7 @@ dependencies = [ "frame-benchmarking", "frame-election-provider-support", "frame-executive", + "frame-remote-externalities", "frame-support", "frame-system", "frame-system-benchmarking", @@ -3454,6 +3455,7 @@ dependencies = [ "pallet-staking", "pallet-staking-handler", "pallet-staking-reward-curve", + "pallet-staking-runtime-api", "pallet-storage", "pallet-timestamp", "pallet-transaction-payment", @@ -3479,12 +3481,14 @@ dependencies = [ "sp-session", "sp-staking", "sp-std", + "sp-tracing", "sp-transaction-pool", "sp-version", "sp-weights", "static_assertions", "strum 0.19.5", "substrate-wasm-builder", + "tokio", ] [[package]] @@ -5702,6 +5706,15 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "pallet-staking-runtime-api" +version = "4.0.0-dev" +source = "git+https://github.com/joystream/substrate.git?rev=50cf239147a6f569e563bcadec6c7a1c5ad5c67e#50cf239147a6f569e563bcadec6c7a1c5ad5c67e" +dependencies = [ + "parity-scale-codec", + "sp-api", +] + [[package]] name = "pallet-storage" version = "5.0.0" diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 435c78af611..7f0d966156a 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -65,6 +65,7 @@ pallet-im-online = { package = 'pallet-im-online', default-features = false, git substrate-utility = { package = 'pallet-utility', version = "4.0.0-dev", default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '50cf239147a6f569e563bcadec6c7a1c5ad5c67e'} pallet-vesting = { package = 'pallet-vesting', default-features = false, git = 'https://github.com/joystream/substrate', rev = '50cf239147a6f569e563bcadec6c7a1c5ad5c67e' } pallet-multisig = { package = 'pallet-multisig', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '50cf239147a6f569e563bcadec6c7a1c5ad5c67e'} +pallet-staking-runtime-api = { package = 'pallet-staking-runtime-api', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '50cf239147a6f569e563bcadec6c7a1c5ad5c67e'} # Benchmarking frame-benchmarking = { git = 'https://github.com/joystream/substrate.git', rev = '50cf239147a6f569e563bcadec6c7a1c5ad5c67e', default-features = false, optional = true } @@ -95,6 +96,9 @@ project-token = { package = 'pallet-project-token', default-features = false, pa [dev-dependencies] sp-io = { package = 'sp-io', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '50cf239147a6f569e563bcadec6c7a1c5ad5c67e'} strum = {version = "0.19", default-features = false} +remote-externalities = { package = "frame-remote-externalities", git = 'https://github.com/joystream/substrate.git', rev = '50cf239147a6f569e563bcadec6c7a1c5ad5c67e'} +tokio = { version = "1.24.2", features = ["macros"] } +sp-tracing = { package = 'sp-tracing', git = 'https://github.com/joystream/substrate.git', rev = '50cf239147a6f569e563bcadec6c7a1c5ad5c67e'} [build-dependencies] substrate-wasm-builder = { git = "https://github.com/joystream/substrate", rev = '50cf239147a6f569e563bcadec6c7a1c5ad5c67e' } @@ -158,6 +162,7 @@ std = [ 'pallet-bags-list/std', 'pallet-election-provider-multi-phase/std', 'pallet-election-provider-support-benchmarking?/std', + 'pallet-staking-runtime-api/std', # Joystream 'common/std', diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 3d63e1919d2..95419af05ea 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -591,7 +591,8 @@ impl pallet_staking::Config for Runtime { type OffendingValidatorsThreshold = OffendingValidatorsThreshold; type ElectionProvider = ElectionProviderMultiPhase; type GenesisElectionProvider = onchain::OnChainExecution; - type VoterList = VoterList; + type VoterList = BagsList; + // type VoterList = VoterList; // not renaming for now type TargetList = pallet_staking::UseValidatorsMap; type MaxUnlockingChunks = ConstU32<32>; type HistoryDepth = HistoryDepth; @@ -1848,7 +1849,9 @@ construct_runtime!( ImOnline: pallet_im_online, Offences: pallet_offences, RandomnessCollectiveFlip: pallet_insecure_randomness_collective_flip, - VoterList: pallet_bags_list::::{Pallet, Call, Storage, Event}, + BagsList: pallet_bags_list::::{Pallet, Call, Storage, Event}, + // Not renaming BagsList to VoterList until migration test failing can be fixed + // VoterList: pallet_bags_list::::{Pallet, Call, Storage, Event}, Vesting: pallet_vesting, Multisig: pallet_multisig, // Joystream @@ -1878,3 +1881,48 @@ construct_runtime!( DistributionWorkingGroup: working_group::::{Pallet, Call, Storage, Event}, } ); + +#[cfg(all(test, feature = "try-runtime"))] +mod remote_tests { + use super::*; + use frame_try_runtime::{runtime_decl_for_TryRuntime::TryRuntime, UpgradeCheckSelect}; + use remote_externalities::{ + Builder, Mode, OfflineConfig, OnlineConfig, SnapshotConfig, Transport, + }; + use std::env::var; + + #[tokio::test] + async fn run_migrations() { + if var("RUN_MIGRATION_TESTS").is_err() { + return; + } + + sp_tracing::try_init_simple(); + let transport: Transport = var("WS") + .unwrap_or("wss://rpc.joystream.org:443".to_string()) + .into(); + let maybe_state_snapshot: Option = var("SNAP").map(|s| s.into()).ok(); + let mut ext = Builder::::default() + .mode(if let Some(state_snapshot) = maybe_state_snapshot { + Mode::OfflineOrElseOnline( + OfflineConfig { + state_snapshot: state_snapshot.clone(), + }, + OnlineConfig { + transport, + state_snapshot: Some(state_snapshot), + ..Default::default() + }, + ) + } else { + Mode::Online(OnlineConfig { + transport, + ..Default::default() + }) + }) + .build() + .await + .unwrap(); + ext.execute_with(|| Runtime::on_runtime_upgrade(UpgradeCheckSelect::PreAndPost)); + } +} diff --git a/runtime/src/runtime_api.rs b/runtime/src/runtime_api.rs index 93671e54c2e..0a6148c40d5 100644 --- a/runtime/src/runtime_api.rs +++ b/runtime/src/runtime_api.rs @@ -12,13 +12,15 @@ use sp_runtime::{generic, ApplyExtrinsicResult}; use sp_std::vec::Vec; use crate::{ - AccountId, AllPalletsWithSystem, AuthorityDiscovery, AuthorityDiscoveryId, Babe, Balance, - BlockNumber, EpochDuration, Grandpa, GrandpaAuthorityList, GrandpaId, Historical, Index, - InherentDataExt, ProposalsEngine, Runtime, RuntimeBlockWeights, RuntimeCall, RuntimeVersion, - SessionKeys, Signature, System, TransactionPayment, VoterList, BABE_GENESIS_EPOCH_CONFIG, - VERSION, + AccountId, AllPalletsWithSystem, AuthorityDiscovery, AuthorityDiscoveryId, Babe, BagsList, + Balance, BlockNumber, EpochDuration, Grandpa, GrandpaAuthorityList, GrandpaId, Historical, + Index, InherentDataExt, ProposalsEngine, Runtime, RuntimeCall, RuntimeVersion, SessionKeys, + Signature, Staking, System, TransactionPayment, BABE_GENESIS_EPOCH_CONFIG, VERSION, }; +#[cfg(feature = "try-runtime")] +use crate::RuntimeBlockWeights; + use frame_support::weights::Weight; /// The SignedExtension to the basic transaction logic. @@ -98,8 +100,10 @@ pub type Migrations = ( pallet_staking::migrations::v9::InjectValidatorsIntoVoterList, // slash all pending slashes correctly pallet_staking::migrations::v10::MigrateToV10, - // Rename BagsList to VoterList - pallet_staking::migrations::v11::MigrateToV11, + // Rename BagsList to VoterList - SKIPPING FOR NOW BY KEEPING SAME NAME + // Post-Upgrade check is failing -> 'old pallet data hasn't been removed' + // Only storage version will be bumped. Is this a problem? + pallet_staking::migrations::v11::MigrateToV11, // Kill HistoryDepth storage pallet_staking::migrations::v12::MigrateToV12, // Migrate to new storage versioning