diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1c9f86d40..c19c57ab8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -35,7 +35,7 @@ jobs: - name: Upload to codecov.io uses: codecov/codecov-action@v1 with: - fail_ci_if_error: true + fail_ci_if_error: false - name: Build release run: time cargo build --release --quiet --locked - name: Version info diff --git a/Cargo.lock b/Cargo.lock index 7141a8436..8cdaccd64 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3815,7 +3815,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "167.0.0" +version = "168.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", @@ -6761,12 +6761,12 @@ dependencies = [ [[package]] name = "pallet-genesis-history" -version = "2.0.1" +version = "2.1.0" dependencies = [ "derive_more", "frame-support", "frame-system", - "hex-literal 0.3.4", + "hex-literal 0.4.1", "parity-scale-codec", "scale-info", "serde", diff --git a/pallets/genesis-history/Cargo.toml b/pallets/genesis-history/Cargo.toml index 6d756c37c..f0075ce1a 100644 --- a/pallets/genesis-history/Cargo.toml +++ b/pallets/genesis-history/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-genesis-history" -version = "2.0.1" +version = "2.1.0" description = "Keeping track of the past chain generations." authors = ["GalacticCouncil "] edition = "2021" @@ -23,9 +23,7 @@ sp-io = { workspace = true } sp-runtime = { workspace = true } sp-std = { workspace = true } sp-core = { workspace = true } - -[dev-dependencies] -hex-literal = '0.3.4' +hex-literal = "0.4.1" [features] default = ['std'] diff --git a/pallets/genesis-history/src/lib.rs b/pallets/genesis-history/src/lib.rs index 7bb206a1c..636c340c9 100644 --- a/pallets/genesis-history/src/lib.rs +++ b/pallets/genesis-history/src/lib.rs @@ -21,12 +21,10 @@ use codec::{Decode, Encode}; use frame_support::traits::GenesisBuild; #[cfg(feature = "std")] use serde::{Deserialize, Serialize}; -#[cfg(feature = "std")] -use sp_core::bytes; use sp_core::RuntimeDebug; -use sp_std::vec::Vec; use scale_info::TypeInfo; +use sp_core::{MaxEncodedLen, H256}; #[cfg(test)] mod mock; @@ -34,15 +32,13 @@ mod mock; #[cfg(test)] mod tests; -#[derive(PartialEq, Eq, Clone, PartialOrd, Ord, Default, Encode, Decode, RuntimeDebug, derive_more::From, TypeInfo)] -#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Hash))] -pub struct BlockHash(#[cfg_attr(feature = "std", serde(with = "bytes"))] pub Vec); +pub mod migration; -#[derive(Debug, Encode, Decode, Clone, Default, PartialEq, Eq, TypeInfo)] +#[derive(Encode, Decode, Clone, Default, PartialEq, Eq, RuntimeDebug, MaxEncodedLen, TypeInfo)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub struct Chain { - pub genesis_hash: BlockHash, - pub last_block_hash: BlockHash, + pub genesis_hash: H256, + pub last_block_hash: H256, } // Re-export pallet items so that they can be accessed from the crate namespace. @@ -58,7 +54,6 @@ pub mod pallet { pub trait Config: frame_system::Config {} #[pallet::pallet] - #[pallet::without_storage_info] #[pallet::generate_store(pub(super) trait Store)] pub struct Pallet(_); @@ -90,11 +85,11 @@ pub mod pallet { #[cfg(feature = "std")] impl GenesisConfig { pub fn build_storage(&self) -> Result { - >::build_storage(self) + >::build_storage(self) } pub fn assimilate_storage(&self, storage: &mut sp_runtime::Storage) -> Result<(), String> { - >::assimilate_storage(self, storage) + >::assimilate_storage(self, storage) } } diff --git a/pallets/genesis-history/src/migration.rs b/pallets/genesis-history/src/migration.rs new file mode 100644 index 000000000..b2e563694 --- /dev/null +++ b/pallets/genesis-history/src/migration.rs @@ -0,0 +1,71 @@ +// This file is part of pallet-genesis-history + +// 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.. + +pub use crate::*; +pub use frame_support::{ + log, + traits::{Get, StorageVersion}, + weights::Weight, +}; + +// This migration fixes the corrupted value in the storage and fixes it +pub mod v1 { + use super::*; + use hex_literal::hex; + + pub fn pre_migrate() { + assert_eq!(StorageVersion::get::>(), 0, "Storage version too high."); + + log::info!( + target: "runtime::genesis-history", + "Genesis history migration: PRE checks successful!" + ); + } + + pub fn migrate() -> Weight { + log::info!( + target: "runtime::genesis-history", + "Running migration to v1 for Genesis history" + ); + + PreviousChain::::put(Chain { + genesis_hash: H256::from(hex!("d2a620c27ec5cbc5621ff9a522689895074f7cca0d08e7134a7804e1a3ba86fc")), + last_block_hash: H256::from(hex!("1c83220b0d0c0c252dddd6a98c9b643e34625419b646c4a6447583c92c01dbcc")), + }); + + StorageVersion::new(1).put::>(); + + T::DbWeight::get().reads_writes(0, 2) + } + + pub fn post_migrate() { + assert_eq!(StorageVersion::get::>(), 1, "Unexpected storage version."); + assert_eq!( + PreviousChain::::get(), + Chain { + genesis_hash: H256::from(hex!("d2a620c27ec5cbc5621ff9a522689895074f7cca0d08e7134a7804e1a3ba86fc")), + last_block_hash: H256::from(hex!("1c83220b0d0c0c252dddd6a98c9b643e34625419b646c4a6447583c92c01dbcc")), + }, + "Unexpected storage version." + ); + + log::info!( + target: "runtime::genesis-history", + "Genesis history migration: POST checks successful!" + ); + } +} diff --git a/pallets/genesis-history/src/tests.rs b/pallets/genesis-history/src/tests.rs index a8bee79b8..fca967d8c 100644 --- a/pallets/genesis-history/src/tests.rs +++ b/pallets/genesis-history/src/tests.rs @@ -17,7 +17,6 @@ use super::*; use crate::mock::*; - use hex_literal::hex; #[test] @@ -30,34 +29,8 @@ fn no_previous_chain() { #[test] fn some_previous_chain() { let chain = Chain { - genesis_hash: vec![1, 2, 3].into(), - last_block_hash: vec![6, 6, 6].into(), - }; - ExtBuilder { chain: chain.clone() }.build().execute_with(|| { - assert_eq!(GenesisHistory::previous_chain(), chain.clone()); - }) -} - -#[test] -fn construct_using_hex() { - let chain = Chain { - genesis_hash: hex!["aa"].to_vec().into(), - last_block_hash: hex!["bb"].to_vec().into(), - }; - ExtBuilder { chain: chain.clone() }.build().execute_with(|| { - assert_eq!(GenesisHistory::previous_chain(), chain.clone()); - }) -} - -#[test] -fn sample_data() { - let chain = Chain { - genesis_hash: hex!["0ed32bfcab4a83517fac88f2aa7cbc2f88d3ab93be9a12b6188a036bf8a943c2"] - .to_vec() - .into(), - last_block_hash: hex!["5800478f2cac4166d40c1ebe80dddbec47275d4b102f228b8a3af54d86d64837"] - .to_vec() - .into(), + genesis_hash: H256::from(hex!("0ed32bfcab4a83517fac88f2aa7cbc2f88d3ab93be9a12b6188a036bf8a943c2")), + last_block_hash: H256::from(hex!("5800478f2cac4166d40c1ebe80dddbec47275d4b102f228b8a3af54d86d64837")), }; ExtBuilder { chain: chain.clone() }.build().execute_with(|| { assert_eq!(GenesisHistory::previous_chain(), chain.clone()); diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index 8aff00d07..00b823e57 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "167.0.0" +version = "168.0.0" authors = ["GalacticCouncil"] edition = "2021" license = "Apache 2.0" diff --git a/runtime/hydradx/src/lib.rs b/runtime/hydradx/src/lib.rs index 8bcf9a6e3..76f3450d1 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -95,7 +95,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("hydradx"), impl_name: create_runtime_str!("hydradx"), authoring_version: 1, - spec_version: 167, + spec_version: 168, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, @@ -232,17 +232,7 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsReversedWithSystemFirst, - ( - pallet_preimage::migration::v1::Migration, - pallet_democracy::migrations::v1::Migration, - pallet_multisig::migrations::v1::MigrateToV1, - DmpQueue, - XcmpQueue, - ParachainSystem, - migrations::OnRuntimeUpgradeMigration, - migrations::MigrateRegistryLocationToV3, - migrations::XcmRateLimitMigration, - ), + (migrations::OnRuntimeUpgradeMigration,), >; impl_runtime_apis! { diff --git a/runtime/hydradx/src/migrations.rs b/runtime/hydradx/src/migrations.rs index 09e5c676f..7af7c63e4 100644 --- a/runtime/hydradx/src/migrations.rs +++ b/runtime/hydradx/src/migrations.rs @@ -11,9 +11,9 @@ pub struct OnRuntimeUpgradeMigration; impl OnRuntimeUpgrade for OnRuntimeUpgradeMigration { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, &'static str> { - frame_support::log::info!("PreMigrate Duster Pallet start"); - pallet_duster::migration::v1::pre_migrate::(); - frame_support::log::info!("PreMigrate Duster Pallet end"); + log::info!("PreMigrate Genesis History Pallet start"); + pallet_genesis_history::migration::v1::pre_migrate::(); + log::info!("PreMigrate Genesis History Pallet end"); Ok(vec![]) } @@ -21,26 +21,19 @@ impl OnRuntimeUpgrade for OnRuntimeUpgradeMigration { fn on_runtime_upgrade() -> Weight { let mut weight: Weight = Weight::zero(); - frame_support::log::info!("Migrate Scheduler Pallet to v4 start"); - weight = weight.saturating_add(Scheduler::migrate_v1_to_v4()); - frame_support::log::info!("Migrate Scheduler Pallet to v4 end"); - - frame_support::log::info!("Migrate Duster Pallet to v1 start"); - weight = weight.saturating_add(pallet_duster::migration::v1::migrate::( - get_all_module_accounts(), - TreasuryAccount::get(), - TreasuryAccount::get(), - )); - frame_support::log::info!("Migrate Duster Pallet to v1 end"); + log::info!("Migrate Genesis History Pallet to v1 start"); + weight = weight.saturating_add(pallet_genesis_history::migration::v1::migrate::()); + log::info!("Migrate Genesis History Pallet to v1 end"); weight } #[cfg(feature = "try-runtime")] fn post_upgrade(_state: Vec) -> Result<(), &'static str> { - frame_support::log::info!("PostMigrate Duster Pallet start"); - pallet_duster::migration::v1::post_migrate::(); - frame_support::log::info!("PostMigrate Duster Pallet end"); + log::info!("PostMigrate Genesis History Pallet start"); + pallet_genesis_history::migration::v1::post_migrate::(); + log::info!("PostMigrate Genesis History Pallet end"); + Ok(()) } }