From 9e186398fb354618e23ab144e38b714a602b6b36 Mon Sep 17 00:00:00 2001 From: Sergej Sakac Date: Fri, 17 Apr 2026 10:10:16 +0200 Subject: [PATCH 1/3] PSM init: remove assert check --- substrate/frame/psm/src/migrations/init.rs | 73 ++++++++++++++++++++-- 1 file changed, 67 insertions(+), 6 deletions(-) diff --git a/substrate/frame/psm/src/migrations/init.rs b/substrate/frame/psm/src/migrations/init.rs index 690823fabeebe..f3680133388b0 100644 --- a/substrate/frame/psm/src/migrations/init.rs +++ b/substrate/frame/psm/src/migrations/init.rs @@ -121,11 +121,14 @@ impl> frame_support::traits::OnRuntimeUpgrade continue; } - assert!( - T::Fungibles::decimals(*asset_id) == stable_decimals, - "PSM migration: asset {:?} decimals do not match stable asset decimals", - asset_id, - ); + if T::Fungibles::decimals(*asset_id) != stable_decimals { + log::error!( + target: LOG_TARGET, + "Asset {:?} decimals do not match stable asset decimals, skipping", + asset_id, + ); + continue; + } ExternalAssets::::insert(asset_id, CircuitBreakerLevel::AllEnabled); MintingFee::::insert(asset_id, minting_fee); RedemptionFee::::insert(asset_id, redemption_fee); @@ -195,7 +198,8 @@ impl> frame_support::traits::OnRuntimeUpgrade #[cfg(test)] mod tests { use super::*; - use crate::mock::{new_test_ext, Test, USDC_ASSET_ID, USDT_ASSET_ID}; + use crate::mock::{new_test_ext, Assets, Test, ALICE, USDC_ASSET_ID, USDT_ASSET_ID}; + use frame_support::assert_ok; struct TestPsmConfig; @@ -301,6 +305,63 @@ mod tests { }); } + #[test] + fn initialize_psm_skips_assets_with_wrong_decimals() { + use frame_support::traits::{ + fungibles::{Create as FungiblesCreate, metadata::Mutate as MetadataMutate}, + OnRuntimeUpgrade, + }; + + const WRONG_DECIMALS_ID: u32 = 99; + + new_test_ext().execute_with(|| { + // Create an asset with 8 decimals (stable asset has 6). + assert_ok!(>::create(WRONG_DECIMALS_ID, ALICE, true, 1)); + assert_ok!(>::set( + WRONG_DECIMALS_ID, + &ALICE, + b"Wrong".to_vec(), + b"WRG".to_vec(), + 8, // mismatched decimals + )); + + struct MixedDecimalsConfig; + impl InitialPsmConfig for MixedDecimalsConfig { + fn max_psm_debt_of_total() -> Permill { + Permill::from_percent(50) + } + fn asset_configs() -> BTreeMap { + [ + ( + WRONG_DECIMALS_ID, + (Permill::zero(), Permill::zero(), Permill::from_percent(50)), + ), + ( + USDC_ASSET_ID, // 6 decimals — matches stable asset + (Permill::zero(), Permill::zero(), Permill::from_percent(50)), + ), + ] + .into_iter() + .collect() + } + } + + ExternalAssets::::remove(WRONG_DECIMALS_ID); + ExternalAssets::::remove(USDC_ASSET_ID); + + InitializePsm::::on_runtime_upgrade(); + + // Wrong decimals asset was skipped. + assert_eq!(ExternalAssets::::get(WRONG_DECIMALS_ID), None); + + // Matching decimals asset was configured. + assert_eq!( + ExternalAssets::::get(USDC_ASSET_ID), + Some(CircuitBreakerLevel::AllEnabled) + ); + }); + } + #[test] fn initialize_psm_is_idempotent() { use frame_support::traits::OnRuntimeUpgrade; From 23a7c0193a3b316f33fadcdd5960d7908d24adeb Mon Sep 17 00:00:00 2001 From: Sergej Sakac Date: Fri, 17 Apr 2026 10:15:10 +0200 Subject: [PATCH 2/3] prdoc --- prdoc/pr_11807.prdoc | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 prdoc/pr_11807.prdoc diff --git a/prdoc/pr_11807.prdoc b/prdoc/pr_11807.prdoc new file mode 100644 index 0000000000000..fe7653fbda0d4 --- /dev/null +++ b/prdoc/pr_11807.prdoc @@ -0,0 +1,11 @@ +title: 'PSM init: skip assets with mismatched decimals instead of panicking' +doc: +- audience: Runtime Dev + description: |- + Replaces the `assert!` in the PSM `InitializePsm` migration with a log and skip + when an asset's decimals don't match the stable asset. Panicking in a runtime + upgrade bricks the chain. Migrations must be infallible. + +crates: +- name: pallet-psm + bump: patch From b26333129af8ded8ca7613a81c7645d59dbd746e Mon Sep 17 00:00:00 2001 From: Sergej Sakac Date: Fri, 17 Apr 2026 10:25:51 +0200 Subject: [PATCH 3/3] fmt --- substrate/frame/psm/src/migrations/init.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/psm/src/migrations/init.rs b/substrate/frame/psm/src/migrations/init.rs index f3680133388b0..3a43dc623bee7 100644 --- a/substrate/frame/psm/src/migrations/init.rs +++ b/substrate/frame/psm/src/migrations/init.rs @@ -308,7 +308,7 @@ mod tests { #[test] fn initialize_psm_skips_assets_with_wrong_decimals() { use frame_support::traits::{ - fungibles::{Create as FungiblesCreate, metadata::Mutate as MetadataMutate}, + fungibles::{metadata::Mutate as MetadataMutate, Create as FungiblesCreate}, OnRuntimeUpgrade, };