Skip to content

Commit

Permalink
Merge branch 'main' into fi/swap-events
Browse files Browse the repository at this point in the history
  • Loading branch information
wischli authored Mar 11, 2024
2 parents 44e962e + 878db0c commit 4ccdf67
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion pallets/loans/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn migrate_from_v2_to_v3<T: Config>() -> Weight {
T::DbWeight::get().reads_writes(count + 1, count + 1)
} else {
// wrong storage version
log::info!("Loans: Migration did not execute. This probably should be removed");
log::warn!("Loans: Migration did not execute. This probably should be removed");
T::DbWeight::get().reads_writes(1, 0)
}
}
51 changes: 51 additions & 0 deletions runtime/common/src/migrations/increase_storage_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,54 @@ where
Ok(())
}
}

/// Simply bumps the storage version of a pallet
///
/// NOTE: Use with extreme caution! Must ensure beforehand that a migration is
/// not necessary
pub struct ForceMigration<P, const FROM_VERSION: u16, const TO_VERSION: u16>(
sp_std::marker::PhantomData<P>,
);
impl<P, const FROM_VERSION: u16, const TO_VERSION: u16> OnRuntimeUpgrade
for ForceMigration<P, FROM_VERSION, TO_VERSION>
where
P: GetStorageVersion<CurrentStorageVersion = StorageVersion> + PalletInfoAccess,
{
fn on_runtime_upgrade() -> Weight {
if P::on_chain_storage_version() == FROM_VERSION {
log::warn!("Double-check you really want this migration!!!!",);
log::info!(
"{LOG_PREFIX} Increasing storage version of {:?} from {:?} to {TO_VERSION:?}",
P::name(),
P::on_chain_storage_version(),
);
StorageVersion::new(TO_VERSION).put::<P>();

RocksDbWeight::get().writes(1)
} else {
log::error!(
"{LOG_PREFIX} Mismatching versions. Wanted to upgrade from \
{FROM_VERSION} but on-chain version is {:?}",
P::on_chain_storage_version(),
);
Zero::zero()
}
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<sp_std::vec::Vec<u8>, sp_runtime::DispatchError> {
assert_eq!(
P::on_chain_storage_version(),
FROM_VERSION,
"Unexpected onchain version: Expected {FROM_VERSION:?}, received {:?}",
P::on_chain_storage_version(),
);
Ok(sp_std::vec![])
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_: sp_std::vec::Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
assert_eq!(P::on_chain_storage_version(), TO_VERSION);
Ok(())
}
}
2 changes: 1 addition & 1 deletion runtime/development/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "development-runtime"
version = "0.10.42"
version = "0.10.43"
build = "build.rs"
authors.workspace = true
edition.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions runtime/development/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("centrifuge-devel"),
impl_name: create_runtime_str!("centrifuge-devel"),
authoring_version: 1,
spec_version: 1042,
spec_version: 1043,
impl_version: 1,
#[cfg(not(feature = "disable-runtime-api"))]
apis: RUNTIME_API_VERSIONS,
Expand Down Expand Up @@ -2043,7 +2043,7 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
crate::migrations::UpgradeDevelopment1042,
crate::migrations::UpgradeDevelopment1043,
>;

// Frame Order in this block dictates the index of each one in the metadata
Expand Down
35 changes: 2 additions & 33 deletions runtime/development/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,5 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

use cfg_types::tokens::{
usdc::{CURRENCY_ID_DOT_NATIVE, CURRENCY_ID_LOCAL, CURRENCY_ID_LP_ETH, LOCAL_ASSET_ID},
CurrencyId, LocalAssetId,
};

frame_support::parameter_types! {
pub const UsdcVariants: [CurrencyId; 1] = [CURRENCY_ID_LP_ETH];
pub const LocalAssetIdUsdc: LocalAssetId = LOCAL_ASSET_ID;
pub const LocalCurrencyIdUsdc: CurrencyId = CURRENCY_ID_LOCAL;
pub const PoolCurrencyAnemoy: CurrencyId = CURRENCY_ID_DOT_NATIVE;
pub const AnnualTreasuryInflationPercent: u32 = 3;
}

pub type UpgradeDevelopment1042 = (
// Reset pallets
runtime_common::migrations::nuke::ResetPallet<crate::OrderBook, crate::RocksDbWeight, 0>,
runtime_common::migrations::nuke::ResetPallet<
crate::TransferAllowList,
crate::RocksDbWeight,
0,
>,
// Apply relative treasury inflation
pallet_block_rewards::migrations::v2::RelativeTreasuryInflationMigration<
crate::Runtime,
AnnualTreasuryInflationPercent,
>,
// Apply version bump to 1 (storage already reset)
runtime_common::migrations::increase_storage_version::Migration<
crate::ForeignInvestments,
0,
1,
>,
);
pub type UpgradeDevelopment1043 =
(runtime_common::migrations::increase_storage_version::ForceMigration<crate::Loans, 0, 2>,);

0 comments on commit 4ccdf67

Please sign in to comment.