Skip to content

Commit

Permalink
Improve migration
Browse files Browse the repository at this point in the history
  • Loading branch information
aurexav committed Oct 9, 2024
1 parent e9c5fad commit 48f537a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 59 deletions.
2 changes: 1 addition & 1 deletion node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl CliConfiguration<Self> 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")]
Expand Down
2 changes: 1 addition & 1 deletion pallet/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub mod pallet {
/// Override the [`frame_system::Config::RuntimeEvent`].
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;

/// Weight information for extrinsics in this pallet.
/// Weight information for extrinsic in this pallet.
type WeightInfo: WeightInfo;

/// Unix time interface.
Expand Down
44 changes: 1 addition & 43 deletions runtime/crab/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _ = <pallet_assets::Pallet<Runtime>>::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 _ = <pallet_assets::Pallet<Runtime>>::set_team(
RuntimeOrigin::signed(dao),
codec::Compact(AssetIds::CKton as AssetId),
deposit,
deposit,
dao,
);

<darwinia_deposit::DepositContract<Runtime>>::put(deposit);
}
}
if let Ok(who) =
array_bytes::hex_n_into::<_, AccountId, 20>("0xa4fFAC7A5Da311D724eD47393848f694Baee7930")
{
<darwinia_staking::RingStakingContract<Runtime>>::put(who);
}

<darwinia_staking::MigrationStartPoint<Runtime>>::put(darwinia_staking::now::<Runtime>());

// frame_support::weights::Weight::zero()
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(7, 7)
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(0, 0)
}
31 changes: 18 additions & 13 deletions runtime/darwinia/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand All @@ -85,15 +77,28 @@ fn migrate() -> frame_support::weights::Weight {

<darwinia_deposit::DepositContract<Runtime>>::put(deposit);
}

log::info!("successfully transfer ownership of KTON to KTON DAO");
}
if let Ok(who) =
array_bytes::hex_n_into::<_, AccountId, 20>("0xa4fFAC7A5Da311D724eD47393848f694Baee7930")
{
<darwinia_staking::RingStakingContract<Runtime>>::put(who);

log::info!("successfully set RING staking contract");
}

<darwinia_staking::MigrationStartPoint<Runtime>>::put(darwinia_staking::now::<Runtime>());

// frame_support::weights::Weight::zero()
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(7, 107)
if let Some(k) = migration::take_storage_value::<AccountId>(
b"DarwiniaStaking",
b"KtonRewardDistributionContract",
&[],
) {
<darwinia_staking::KtonStakingContract<Runtime>>::put(k);

log::info!("successfully set KTON staking contract");
}

<Runtime as frame_system::Config>::DbWeight::get().reads_writes(7, 9)
}
2 changes: 1 addition & 1 deletion runtime/koi/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade {
}

fn migrate() -> frame_support::weights::Weight {
frame_support::weights::Weight::zero()
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(0, 0)
}

0 comments on commit 48f537a

Please sign in to comment.