Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix try-runtime feature (#899) #162

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ jobs:
uses: arduino/setup-protoc@v1
- name: Run tests
run: cargo test --locked --verbose --all
- name: Ensure benchmarking compiles
run: cargo check --release --features=runtime-benchmarks
- name: Ensure runtime-benchmarks and try-runtime features compiles
run: cargo check --release --features=runtime-benchmarks,try-runtime

integration:
name: 'Run integration tests'
Expand Down Expand Up @@ -85,4 +85,4 @@ jobs:
- name: Rustfmt
run: cargo fmt --all -- --check
- name: Clippy
run: cargo clippy --all --features runtime-benchmarks -- -D warnings
run: cargo clippy --all --features runtime-benchmarks,try-runtime -- -D warnings
4 changes: 4 additions & 0 deletions frame/base-fee/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ std = [
# Frontier
"fp-evm/std",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
]
4 changes: 4 additions & 0 deletions frame/dynamic-fee/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@ std = [
"fp-dynamic-fee/std",
"fp-evm/std",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
]
7 changes: 6 additions & 1 deletion frame/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,10 @@ runtime-benchmarks = [
"pallet-timestamp/runtime-benchmarks",
"pallet-evm/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-evm/try-runtime",
]
forbid-evm-reentrancy = ["pallet-evm/forbid-evm-reentrancy"]
29 changes: 14 additions & 15 deletions frame/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ use fp_evm::{
CallOrCreateInfo, CheckEvmTransaction, CheckEvmTransactionConfig, InvalidEvmTransactionError,
};
use fp_storage::{EthereumStorageSchema, PALLET_ETHEREUM_SCHEMA};
#[cfg(feature = "try-runtime")]
use frame_support::traits::OnRuntimeUpgradeHelpersExt;
use frame_support::{
codec::{Decode, Encode, MaxEncodedLen},
dispatch::{DispatchInfo, DispatchResultWithPostInfo, Pays, PostDispatchInfo},
Expand Down Expand Up @@ -814,30 +812,31 @@ impl<T: Config> Pallet<T> {
}

#[cfg(feature = "try-runtime")]
pub fn pre_migrate_block_v2() -> Result<(), &'static str> {
pub fn pre_migrate_block_v2() -> Result<Vec<u8>, &'static str> {
let item = b"CurrentBlock";
let block_v0 = frame_support::storage::migration::get_storage_value::<ethereum::BlockV0>(
Self::name().as_bytes(),
item,
&[],
);
if let Some(block_v0) = block_v0 {
Self::set_temp_storage(block_v0.header.number, "number");
Self::set_temp_storage(block_v0.header.parent_hash, "parent_hash");
Self::set_temp_storage(block_v0.transactions.len() as u64, "transaction_len");
Ok((
block_v0.header.number,
block_v0.header.parent_hash,
block_v0.transactions.len() as u64,
)
.encode())
} else {
Ok(Vec::new())
}
Ok(())
}

#[cfg(feature = "try-runtime")]
pub fn post_migrate_block_v2() -> Result<(), &'static str> {
let v0_number =
Self::get_temp_storage("number").expect("We stored a number; it should be there; qed");
let v0_parent_hash = Self::get_temp_storage("parent_hash")
.expect("We stored a parent hash; it should be there; qed");
let v0_transaction_len: u64 = Self::get_temp_storage("transaction_len")
.expect("We stored a transaction count; it should be there; qed");

pub fn post_migrate_block_v2(v0_data: Vec<u8>) -> Result<(), &'static str> {
let (v0_number, v0_parent_hash, v0_transaction_len): (U256, H256, u64) = Decode::decode(
&mut v0_data.as_slice(),
)
.expect("the state parameter should be something that was generated by pre_upgrade");
let item = b"CurrentBlock";
let block_v2 = frame_support::storage::migration::get_storage_value::<ethereum::BlockV2>(
Self::name().as_bytes(),
Expand Down
5 changes: 4 additions & 1 deletion frame/evm-chain-id/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ std = [
"frame-support/std",
"frame-system/std",
]
try-runtime = ["frame-support/try-runtime"]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
]
5 changes: 5 additions & 0 deletions frame/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,9 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-timestamp/try-runtime",
]
forbid-evm-reentrancy = ["dep:environmental"]
5 changes: 5 additions & 0 deletions frame/hotfix-sufficients/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,8 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"pallet-evm/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-evm/try-runtime",
]