From 48f537a954b7e2c11ef9409f408afffe53303798 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Wed, 9 Oct 2024 10:26:56 +0800 Subject: [PATCH 1/3] Improve migration --- node/src/command.rs | 2 +- pallet/staking/src/lib.rs | 2 +- runtime/crab/src/migration.rs | 44 +------------------------------ runtime/darwinia/src/migration.rs | 31 +++++++++++++--------- runtime/koi/src/migration.rs | 2 +- 5 files changed, 22 insertions(+), 59 deletions(-) diff --git a/node/src/command.rs b/node/src/command.rs index fc7b4f00a..96a019e18 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -234,7 +234,7 @@ impl CliConfiguration for RelayChainCli { /// Parse command line arguments into service configuration. pub fn run() -> Result<()> { #[cfg(feature = "runtime-benchmarks")] - /// Creates partial components for the runtimes that are supported by the benchmarks. + /// Creates partial components for the runtime that are supported by the benchmarks. macro_rules! construct_benchmark_partials { ($config:expr, $cli:ident, |$partials:ident| $code:expr) => {{ #[cfg(feature = "crab-runtime")] diff --git a/pallet/staking/src/lib.rs b/pallet/staking/src/lib.rs index 9bc28850b..be6b32a8d 100644 --- a/pallet/staking/src/lib.rs +++ b/pallet/staking/src/lib.rs @@ -134,7 +134,7 @@ pub mod pallet { /// Override the [`frame_system::Config::RuntimeEvent`]. type RuntimeEvent: From> + IsType<::RuntimeEvent>; - /// Weight information for extrinsics in this pallet. + /// Weight information for extrinsic in this pallet. type WeightInfo: WeightInfo; /// Unix time interface. diff --git a/runtime/crab/src/migration.rs b/runtime/crab/src/migration.rs index 75e85b19b..198778bb6 100644 --- a/runtime/crab/src/migration.rs +++ b/runtime/crab/src/migration.rs @@ -45,47 +45,5 @@ impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade { } fn migrate() -> frame_support::weights::Weight { - // dawinia - use darwinia_staking::CacheState; - if let Some(s) = migration::get_storage_value::<(CacheState, CacheState, CacheState)>( - b"DarwinaStaking", - b"ExposureCacheStates", - &[], - ) { - migration::put_storage_value(b"DarwinaStaking", b"CacheStates", &[], s); - } - - if let Ok(dao) = - array_bytes::hex_n_into::<_, AccountId, 20>("0x08837De0Ae21C270383D9F2de4DB03c7b1314632") - { - let _ = >::transfer_ownership( - RuntimeOrigin::signed(ROOT), - codec::Compact(AssetIds::CKton as AssetId), - dao, - ); - - if let Ok(deposit) = array_bytes::hex_n_into::<_, AccountId, 20>( - "0x46275d29113f065c2aac262f34C7a3d8a8B7377D", - ) { - let _ = >::set_team( - RuntimeOrigin::signed(dao), - codec::Compact(AssetIds::CKton as AssetId), - deposit, - deposit, - dao, - ); - - >::put(deposit); - } - } - if let Ok(who) = - array_bytes::hex_n_into::<_, AccountId, 20>("0xa4fFAC7A5Da311D724eD47393848f694Baee7930") - { - >::put(who); - } - - >::put(darwinia_staking::now::()); - - // frame_support::weights::Weight::zero() - ::DbWeight::get().reads_writes(7, 7) + ::DbWeight::get().reads_writes(0, 0) } diff --git a/runtime/darwinia/src/migration.rs b/runtime/darwinia/src/migration.rs index cd8108886..73d54c66a 100644 --- a/runtime/darwinia/src/migration.rs +++ b/runtime/darwinia/src/migration.rs @@ -45,22 +45,14 @@ impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade { } fn migrate() -> frame_support::weights::Weight { - let _ = migration::clear_storage_prefix( - b"BridgeKusamaGrandpa", - b"ImportedHeaders", - &[], - Some(100), - None, - ); - - // dawinia + // darwinia use darwinia_staking::CacheState; if let Some(s) = migration::get_storage_value::<(CacheState, CacheState, CacheState)>( - b"DarwinaStaking", + b"DarwiniaStaking", b"ExposureCacheStates", &[], ) { - migration::put_storage_value(b"DarwinaStaking", b"CacheStates", &[], s); + migration::put_storage_value(b"DarwiniaStaking", b"CacheStates", &[], s); } if let Ok(dao) = @@ -85,15 +77,28 @@ fn migrate() -> frame_support::weights::Weight { >::put(deposit); } + + log::info!("successfully transfer ownership of KTON to KTON DAO"); } if let Ok(who) = array_bytes::hex_n_into::<_, AccountId, 20>("0xa4fFAC7A5Da311D724eD47393848f694Baee7930") { >::put(who); + + log::info!("successfully set RING staking contract"); } >::put(darwinia_staking::now::()); - // frame_support::weights::Weight::zero() - ::DbWeight::get().reads_writes(7, 107) + if let Some(k) = migration::take_storage_value::( + b"DarwiniaStaking", + b"KtonRewardDistributionContract", + &[], + ) { + >::put(k); + + log::info!("successfully set KTON staking contract"); + } + + ::DbWeight::get().reads_writes(7, 9) } diff --git a/runtime/koi/src/migration.rs b/runtime/koi/src/migration.rs index d6045cb0e..198778bb6 100644 --- a/runtime/koi/src/migration.rs +++ b/runtime/koi/src/migration.rs @@ -45,5 +45,5 @@ impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade { } fn migrate() -> frame_support::weights::Weight { - frame_support::weights::Weight::zero() + ::DbWeight::get().reads_writes(0, 0) } From c2cc1d928940552380fbc9dc59d01559732b1683 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Wed, 9 Oct 2024 11:06:12 +0800 Subject: [PATCH 2/3] Kill storage key --- runtime/crab/src/migration.rs | 6 +++++- runtime/darwinia/src/migration.rs | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/runtime/crab/src/migration.rs b/runtime/crab/src/migration.rs index 198778bb6..9e056162c 100644 --- a/runtime/crab/src/migration.rs +++ b/runtime/crab/src/migration.rs @@ -45,5 +45,9 @@ impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade { } fn migrate() -> frame_support::weights::Weight { - ::DbWeight::get().reads_writes(0, 0) + if let Ok(k) = array_bytes::hex2bytes("0x1da53b775b270400e7e61ed5cbc5a146ab1160471b1418779239ba8e2b847e42d53de13b56da115d3342f0588bc3614108837de0ae21c270383d9f2de4db03c7b1314632314d8c74970d627c9b4f4c42e06688a9f7a2866905a810c4b1a49b8cb0dca3f1bc953905609869b6e9d4fb794cd36c5f") { + System::kill_storage(RuntimeOrigin::root(), vec![k]); + } + + ::DbWeight::get().reads_writes(0, 1) } diff --git a/runtime/darwinia/src/migration.rs b/runtime/darwinia/src/migration.rs index 73d54c66a..b787c18fa 100644 --- a/runtime/darwinia/src/migration.rs +++ b/runtime/darwinia/src/migration.rs @@ -100,5 +100,9 @@ fn migrate() -> frame_support::weights::Weight { log::info!("successfully set KTON staking contract"); } - ::DbWeight::get().reads_writes(7, 9) + if let Ok(k) = array_bytes::hex2bytes("0x1da53b775b270400e7e61ed5cbc5a146ab1160471b1418779239ba8e2b847e42d53de13b56da115d3342f0588bc3614108837de0ae21c270383d9f2de4db03c7b1314632314d8c74970d627c9b4f4c42e06688a9f7a2866905a810c4b1a49b8cb0dca3f1bc953905609869b6e9d4fb794cd36c5f") { + System::kill_storage(RuntimeOrigin::root(), vec![k]); + } + + ::DbWeight::get().reads_writes(7, 10) } From ace8f37c1562b4f8da0f766d9451c1dbfefc1d18 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Wed, 9 Oct 2024 11:24:18 +0800 Subject: [PATCH 3/3] Filter call Signed-off-by: Xavier Lau --- runtime/crab/src/migration.rs | 2 +- runtime/darwinia/src/migration.rs | 2 +- runtime/darwinia/src/pallets/system.rs | 13 ++++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/runtime/crab/src/migration.rs b/runtime/crab/src/migration.rs index 9e056162c..bf373a08e 100644 --- a/runtime/crab/src/migration.rs +++ b/runtime/crab/src/migration.rs @@ -46,7 +46,7 @@ impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade { fn migrate() -> frame_support::weights::Weight { if let Ok(k) = array_bytes::hex2bytes("0x1da53b775b270400e7e61ed5cbc5a146ab1160471b1418779239ba8e2b847e42d53de13b56da115d3342f0588bc3614108837de0ae21c270383d9f2de4db03c7b1314632314d8c74970d627c9b4f4c42e06688a9f7a2866905a810c4b1a49b8cb0dca3f1bc953905609869b6e9d4fb794cd36c5f") { - System::kill_storage(RuntimeOrigin::root(), vec![k]); + let _ = System::kill_storage(RuntimeOrigin::root(), vec![k]); } ::DbWeight::get().reads_writes(0, 1) diff --git a/runtime/darwinia/src/migration.rs b/runtime/darwinia/src/migration.rs index b787c18fa..ad8fd8fe8 100644 --- a/runtime/darwinia/src/migration.rs +++ b/runtime/darwinia/src/migration.rs @@ -101,7 +101,7 @@ fn migrate() -> frame_support::weights::Weight { } if let Ok(k) = array_bytes::hex2bytes("0x1da53b775b270400e7e61ed5cbc5a146ab1160471b1418779239ba8e2b847e42d53de13b56da115d3342f0588bc3614108837de0ae21c270383d9f2de4db03c7b1314632314d8c74970d627c9b4f4c42e06688a9f7a2866905a810c4b1a49b8cb0dca3f1bc953905609869b6e9d4fb794cd36c5f") { - System::kill_storage(RuntimeOrigin::root(), vec![k]); + let _ = System::kill_storage(RuntimeOrigin::root(), vec![k]); } ::DbWeight::get().reads_writes(7, 10) diff --git a/runtime/darwinia/src/pallets/system.rs b/runtime/darwinia/src/pallets/system.rs index 7825ab56a..f00b1c9e5 100644 --- a/runtime/darwinia/src/pallets/system.rs +++ b/runtime/darwinia/src/pallets/system.rs @@ -25,11 +25,22 @@ frame_support::parameter_types! { pub const Version: sp_version::RuntimeVersion = VERSION; } +pub enum LockAndStake {} +impl frame_support::traits::Contains for LockAndStake { + fn contains(c: &RuntimeCall) -> bool { + matches!( + c, + RuntimeCall::DarwiniaStaking(darwinia_staking::Call::stake { .. }) + | RuntimeCall::Deposit(darwinia_deposit::Call::lock { .. }) + ) + } +} + #[derive_impl(frame_system::config_preludes::ParaChainDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Runtime { type AccountData = pallet_balances::AccountData; type AccountId = AccountId; - type BaseCallFilter = frame_support::traits::Everything; + type BaseCallFilter = frame_support::traits::EverythingBut; type Block = Block; type BlockLength = pallet_config::RuntimeBlockLength; type BlockWeights = pallet_config::RuntimeBlockWeights;