Skip to content

Commit

Permalink
Clean issues (#1607)
Browse files Browse the repository at this point in the history
* Improve migration

* Kill storage key

* Filter call

Signed-off-by: Xavier Lau <[email protected]>

---------

Signed-off-by: Xavier Lau <[email protected]>
  • Loading branch information
AurevoirXavier authored Oct 10, 2024
1 parent 1ac5283 commit 61cdb96
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 58 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: 3 additions & 41 deletions runtime/crab/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,47 +45,9 @@ 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(k) = array_bytes::hex2bytes("0x1da53b775b270400e7e61ed5cbc5a146ab1160471b1418779239ba8e2b847e42d53de13b56da115d3342f0588bc3614108837de0ae21c270383d9f2de4db03c7b1314632314d8c74970d627c9b4f4c42e06688a9f7a2866905a810c4b1a49b8cb0dca3f1bc953905609869b6e9d4fb794cd36c5f") {
let _ = System::kill_storage(RuntimeOrigin::root(), vec![k]);
}

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, 1)
}
35 changes: 22 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,32 @@ 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");
}

if let Ok(k) = array_bytes::hex2bytes("0x1da53b775b270400e7e61ed5cbc5a146ab1160471b1418779239ba8e2b847e42d53de13b56da115d3342f0588bc3614108837de0ae21c270383d9f2de4db03c7b1314632314d8c74970d627c9b4f4c42e06688a9f7a2866905a810c4b1a49b8cb0dca3f1bc953905609869b6e9d4fb794cd36c5f") {
let _ = System::kill_storage(RuntimeOrigin::root(), vec![k]);
}

<Runtime as frame_system::Config>::DbWeight::get().reads_writes(7, 10)
}
13 changes: 12 additions & 1 deletion runtime/darwinia/src/pallets/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,22 @@ frame_support::parameter_types! {
pub const Version: sp_version::RuntimeVersion = VERSION;
}

pub enum LockAndStake {}
impl frame_support::traits::Contains<RuntimeCall> 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<Balance>;
type AccountId = AccountId;
type BaseCallFilter = frame_support::traits::Everything;
type BaseCallFilter = frame_support::traits::EverythingBut<LockAndStake>;
type Block = Block;
type BlockLength = pallet_config::RuntimeBlockLength;
type BlockWeights = pallet_config::RuntimeBlockWeights;
Expand Down
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 61cdb96

Please sign in to comment.