Skip to content

Commit

Permalink
Merge pull request #365 from sora-xor/fix-try-runtime-build
Browse files Browse the repository at this point in the history
Fix try-runtime build
  • Loading branch information
vovac12 committed Apr 5, 2023
2 parents 9f52e5f + 115c71a commit 9fcc5f8
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 29 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,6 @@ runtime-benchmarks = [

try-runtime = [
"try-runtime-cli",
"try-runtime-cli/try-runtime",
"framenode-runtime/try-runtime",
]
9 changes: 7 additions & 2 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ pub fn run() -> sc_cli::Result<()> {
}
#[cfg(feature = "try-runtime")]
Some(Subcommand::TryRuntime(cmd)) => {
use sc_executor::{sp_wasm_interface::ExtendedHostFunctions, NativeExecutionDispatch};
type HostFunctionsOf<E> = ExtendedHostFunctions<
sp_io::SubstrateHostFunctions,
<E as NativeExecutionDispatch>::ExtendHostFunctions,
>;
let runner = cli.create_runner(cmd)?;
set_default_ss58_version();

Expand All @@ -226,9 +231,9 @@ pub fn run() -> sc_cli::Result<()> {
let task_manager = TaskManager::new(runner.config().tokio_handle.clone(), *registry)
.map_err(|e| sc_cli::Error::Service(sc_service::Error::Prometheus(e)))?;

runner.async_run(|config| {
runner.async_run(|_config| {
Ok((
cmd.run::<framenode_runtime::Block, service::ExecutorDispatch>(config),
cmd.run::<framenode_runtime::Block, HostFunctionsOf<service::ExecutorDispatch>>(),
task_manager,
))
})
Expand Down
10 changes: 5 additions & 5 deletions pallets/farming/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ pub mod v2 {
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
ensure!(
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
frame_support::ensure!(
StorageVersion::get::<Pallet<T>>() == StorageVersion::new(1),
"Wrong storage version before upgrade"
);
Ok(())
Ok(Vec::new())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
ensure!(
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
frame_support::ensure!(
StorageVersion::get::<Pallet<T>>() == StorageVersion::new(2),
"Wrong storage version after upgrade"
);
Expand Down
4 changes: 4 additions & 0 deletions pallets/hermes-governance-platform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"frame-support/runtime-benchmarks",
]

try-runtime = [
"frame-support/try-runtime"
]
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use frame_support::{
pallet_prelude::StorageVersion,
traits::GetStorageVersion as _,
};
#[cfg(feature = "try-runtime")]
use sp_std::prelude::*;

pub struct InitializeXSTPool<T>(core::marker::PhantomData<T>);

Expand Down Expand Up @@ -36,16 +38,16 @@ where
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
frame_support::ensure!(
Pallet::<T>::on_chain_storage_version() == 0,
"must upgrade linearly"
);
Ok(())
Ok(Vec::new())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
frame_support::ensure!(
Pallet::<T>::on_chain_storage_version() == 1,
"should be upgraded to version 1"
Expand Down
15 changes: 8 additions & 7 deletions pallets/multicollateral-bonding-curve-pool/src/migrations/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use frame_support::{
traits::GetStorageVersion as _,
};
use sp_runtime::traits::Zero;
use sp_std::prelude::*;

pub const SORAMITSU_PAYMENT_ACCOUNT: [u8; 32] =
hex_literal::hex!("34b9a44a2d3f681d8191815a6de986bf163d15f6d6b58d56aa1ab887313e1723");
Expand Down Expand Up @@ -92,27 +93,27 @@ where
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
frame_support::ensure!(
assets::Pallet::<T>::ensure_asset_exists(TBCD.into()).is_err(),
assets::Pallet::<T>::ensure_asset_exists(&TBCD.into()).is_err(),
"TBCD asset already registered"
);
frame_support::ensure!(
!crate::EnabledTargets::get().contains(&TBCD.into()),
!crate::EnabledTargets::<T>::get().contains(&TBCD.into()),
"TBCD pool already initialized"
);
frame_support::ensure!(
Pallet::<T>::on_chain_storage_version() == 1,
"must upgrade linearly"
);
Ok(())
Ok(Vec::new())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
assets::Pallet::<T>::ensure_asset_exists(TBCD.into())?;
fn post_upgrade(_state: Vec<u8>) -> Result<(), &'static str> {
assets::Pallet::<T>::ensure_asset_exists(&TBCD.into())?;
frame_support::ensure!(
crate::EnabledTargets::get().contains(&TBCD.into()),
crate::EnabledTargets::<T>::get().contains(&TBCD.into()),
"TBCD pool is not initialized"
);
frame_support::ensure!(
Expand Down
1 change: 1 addition & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ try-runtime = [
"ceres-staking/try-runtime",
"ceres-token-locker/try-runtime",
"demeter-farming-platform/try-runtime",
"hermes-governance-platform/try-runtime",
"dex-api/try-runtime",
"dex-manager/try-runtime",
"eth-bridge/try-runtime",
Expand Down
24 changes: 12 additions & 12 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3087,21 +3087,21 @@ impl_runtime_apis! {

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade() -> (Weight, Weight) {
log::info!("try-runtime::on_runtime_upgrade.");
let weight = Executive::try_runtime_upgrade().unwrap();
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
log::info!("try-runtime::on_runtime_upgrade");
let weight = Executive::try_runtime_upgrade(checks).unwrap();
(weight, BlockWeights::get().max_block)
}

fn execute_block(block: Block, state_root_check: bool, select: frame_try_runtime::TryStateSelect) -> Weight {
log::info!(
target: "runtime", "try-runtime: executing block #{} ({:?}) / root checks: {:?} / sanity-checks: {:?}",
block.header.number,
block.header.hash(),
state_root_check,
select,
);
Executive::try_execute_block(block, state_root_check, select).expect("try_execute_block failed")
fn execute_block(
block: Block,
state_root_check: bool,
signature_check: bool,
select: frame_try_runtime::TryStateSelect,
) -> Weight {
// NOTE: intentional unwrap: we don't want to propagate the error backwards, and want to
// have a backtrace here.
Executive::try_execute_block(block, state_root_check, signature_check, select).unwrap()
}
}
}

0 comments on commit 9fcc5f8

Please sign in to comment.