From fc457973a0e19aea13efbeb2ac54fe9628f00d79 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Mon, 2 Sep 2024 12:17:04 +0800 Subject: [PATCH 1/7] Allow performing migration for others --- pallet/deposit/src/lib.rs | 7 ++++--- precompile/deposit/src/lib.rs | 6 +++--- runtime/crab/src/migration.rs | 4 ++-- runtime/darwinia/src/migration.rs | 4 ++-- runtime/koi/src/migration.rs | 25 +------------------------ 5 files changed, 12 insertions(+), 34 deletions(-) diff --git a/pallet/deposit/src/lib.rs b/pallet/deposit/src/lib.rs index 9278475df..006542232 100644 --- a/pallet/deposit/src/lib.rs +++ b/pallet/deposit/src/lib.rs @@ -312,11 +312,12 @@ pub mod pallet { Ok(()) } - /// Migration data to deposit contract. + /// Migrate the specified account's data to deposit contract. #[pallet::call_index(3)] #[pallet::weight(::WeightInfo::migrate())] - pub fn migrate(origin: OriginFor) -> DispatchResult { - let who = ensure_signed(origin)?; + pub fn migrate(origin: OriginFor, who: T::AccountId) -> DispatchResult { + ensure_signed(origin)?; + let Some(ds) = >::take(&who) else { return Ok(()) }; let now = Self::now(); let mut ds = ds.into_iter(); diff --git a/precompile/deposit/src/lib.rs b/precompile/deposit/src/lib.rs index 8906e0837..09135936d 100644 --- a/precompile/deposit/src/lib.rs +++ b/precompile/deposit/src/lib.rs @@ -89,13 +89,13 @@ where Ok(true) } - #[precompile::public("migrate()")] - fn migrate(handle: &mut impl PrecompileHandle) -> EvmResult { + #[precompile::public("migrate(address)")] + fn migrate(handle: &mut impl PrecompileHandle, who: Address) -> EvmResult { let origin: AccountIdOf = handle.context().caller.into(); RuntimeHelper::::try_dispatch( handle, Some(origin).into(), - darwinia_deposit::Call::::migrate {}, + darwinia_deposit::Call::::migrate { who: who.into() }, )?; Ok(true) } diff --git a/runtime/crab/src/migration.rs b/runtime/crab/src/migration.rs index 34335bb0e..1f126308e 100644 --- a/runtime/crab/src/migration.rs +++ b/runtime/crab/src/migration.rs @@ -56,7 +56,7 @@ fn migrate() -> frame_support::weights::Weight { } if let Ok(dao) = - array_bytes::hex_n_into::<_, AccountId, 20>("0x7FAcDaFB282028E4B3264fB08cd633A9142514df") + array_bytes::hex_n_into::<_, AccountId, 20>("0x08837De0Ae21C270383D9F2de4DB03c7b1314632") { let _ = >::transfer_ownership( RuntimeOrigin::signed(ROOT), @@ -65,7 +65,7 @@ fn migrate() -> frame_support::weights::Weight { ); if let Ok(deposit) = array_bytes::hex_n_into::<_, AccountId, 20>( - "0x08837De0Ae21C270383D9F2de4DB03c7b1314632", + "0x7FAcDaFB282028E4B3264fB08cd633A9142514df", ) { let _ = >::set_team( RuntimeOrigin::signed(dao), diff --git a/runtime/darwinia/src/migration.rs b/runtime/darwinia/src/migration.rs index 0bda7b7cc..853e497cb 100644 --- a/runtime/darwinia/src/migration.rs +++ b/runtime/darwinia/src/migration.rs @@ -64,7 +64,7 @@ fn migrate() -> frame_support::weights::Weight { } if let Ok(dao) = - array_bytes::hex_n_into::<_, AccountId, 20>("0x7FAcDaFB282028E4B3264fB08cd633A9142514df") + array_bytes::hex_n_into::<_, AccountId, 20>("0x08837De0Ae21C270383D9F2de4DB03c7b1314632") { let _ = >::transfer_ownership( RuntimeOrigin::signed(ROOT), @@ -73,7 +73,7 @@ fn migrate() -> frame_support::weights::Weight { ); if let Ok(deposit) = array_bytes::hex_n_into::<_, AccountId, 20>( - "0x08837De0Ae21C270383D9F2de4DB03c7b1314632", + "0x7FAcDaFB282028E4B3264fB08cd633A9142514df", ) { let _ = >::set_team( RuntimeOrigin::signed(dao), diff --git a/runtime/koi/src/migration.rs b/runtime/koi/src/migration.rs index 15e9e442f..d6045cb0e 100644 --- a/runtime/koi/src/migration.rs +++ b/runtime/koi/src/migration.rs @@ -45,28 +45,5 @@ impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade { } fn migrate() -> frame_support::weights::Weight { - if let Ok(dao) = - array_bytes::hex_n_into::<_, AccountId, 20>("0x7FAcDaFB282028E4B3264fB08cd633A9142514df") - { - let _ = >::transfer_ownership( - RuntimeOrigin::signed(ROOT), - codec::Compact(AssetIds::KKton as AssetId), - dao, - ); - - if let Ok(deposit) = array_bytes::hex_n_into::<_, AccountId, 20>( - "0x08837De0Ae21C270383D9F2de4DB03c7b1314632", - ) { - let _ = >::set_team( - RuntimeOrigin::signed(dao), - codec::Compact(AssetIds::KKton as AssetId), - deposit, - deposit, - dao, - ); - } - } - - // frame_support::weights::Weight::zero() - ::DbWeight::get().reads_writes(5, 5) + frame_support::weights::Weight::zero() } From 41e09da090d084f390fdfcc9df9cee43109c5b25 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Mon, 2 Sep 2024 18:29:43 +0800 Subject: [PATCH 2/7] Update contract addrs --- runtime/crab/src/migration.rs | 12 +++++++++++- runtime/darwinia/src/migration.rs | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/runtime/crab/src/migration.rs b/runtime/crab/src/migration.rs index 1f126308e..f89cf2d2a 100644 --- a/runtime/crab/src/migration.rs +++ b/runtime/crab/src/migration.rs @@ -65,7 +65,7 @@ fn migrate() -> frame_support::weights::Weight { ); if let Ok(deposit) = array_bytes::hex_n_into::<_, AccountId, 20>( - "0x7FAcDaFB282028E4B3264fB08cd633A9142514df", + "0xDeC9cD45e921F2AedE72f694743265af37d47Fa7", ) { let _ = >::set_team( RuntimeOrigin::signed(dao), @@ -76,6 +76,16 @@ fn migrate() -> frame_support::weights::Weight { ); } } + if let Ok(who) = + aray_bytes::hex_n_into::<_, AccountId, 20>("0xDeC9cD45e921F2AedE72f694743265af37d47Fa7") + { + >::put(who); + } + if let Ok(who) = + array_bytes::hex_n_into::<_, AccountId, 20>("0xb037E75fE2BFA42DdDC17BB90963Dafe10A5Dd11") + { + >::put(who); + } // frame_support::weights::Weight::zero() ::DbWeight::get().reads_writes(7, 7) diff --git a/runtime/darwinia/src/migration.rs b/runtime/darwinia/src/migration.rs index 853e497cb..a7dcb86a0 100644 --- a/runtime/darwinia/src/migration.rs +++ b/runtime/darwinia/src/migration.rs @@ -73,7 +73,7 @@ fn migrate() -> frame_support::weights::Weight { ); if let Ok(deposit) = array_bytes::hex_n_into::<_, AccountId, 20>( - "0x7FAcDaFB282028E4B3264fB08cd633A9142514df", + "0xDeC9cD45e921F2AedE72f694743265af37d47Fa7", ) { let _ = >::set_team( RuntimeOrigin::signed(dao), @@ -84,6 +84,16 @@ fn migrate() -> frame_support::weights::Weight { ); } } + if let Ok(who) = + aray_bytes::hex_n_into::<_, AccountId, 20>("0xDeC9cD45e921F2AedE72f694743265af37d47Fa7") + { + >::put(who); + } + if let Ok(who) = + array_bytes::hex_n_into::<_, AccountId, 20>("0xb037E75fE2BFA42DdDC17BB90963Dafe10A5Dd11") + { + >::put(who); + } // frame_support::weights::Weight::zero() ::DbWeight::get().reads_writes(7, 107) From ab7fb07f3637a6ca9763c648a6b9ace665619e58 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Mon, 2 Sep 2024 18:36:30 +0800 Subject: [PATCH 3/7] Update abi --- precompile/metadata/abi-creator.sh | 9 +++++++-- precompile/metadata/abi/asset.json | 2 +- precompile/metadata/abi/bls12-381.json | 2 +- precompile/metadata/abi/conviction-voting.json | 2 +- precompile/metadata/abi/deposit.json | 2 +- precompile/metadata/abi/staking.json | 2 +- precompile/metadata/abi/state-storage.json | 2 +- 7 files changed, 13 insertions(+), 8 deletions(-) diff --git a/precompile/metadata/abi-creator.sh b/precompile/metadata/abi-creator.sh index 142b73587..f8ce41e25 100755 --- a/precompile/metadata/abi-creator.sh +++ b/precompile/metadata/abi-creator.sh @@ -1,6 +1,11 @@ -#!/bin/bash +#!/bin/sh -# Usage: Run `bash abi-creator.sh` in the root of the metadata folder. +# ## Usage +# +# ```sh +# brew install solidity # macOS only +# cd precompile/metadata && ./abi-generator.sh +# ``` sol_directory="sol" abi_directory="abi" diff --git a/precompile/metadata/abi/asset.json b/precompile/metadata/abi/asset.json index c5dcbb5ad..38583bb3f 100644 --- a/precompile/metadata/abi/asset.json +++ b/precompile/metadata/abi/asset.json @@ -371,5 +371,5 @@ } } }, - "version": "0.8.17+commit.8df45f5f.Linux.g++" + "version": "0.8.25+commit.b61c2a91.Darwin.appleclang" } diff --git a/precompile/metadata/abi/bls12-381.json b/precompile/metadata/abi/bls12-381.json index 7ffb88e96..c5e2f225a 100644 --- a/precompile/metadata/abi/bls12-381.json +++ b/precompile/metadata/abi/bls12-381.json @@ -66,5 +66,5 @@ } } }, - "version": "0.8.17+commit.8df45f5f.Linux.g++" + "version": "0.8.25+commit.b61c2a91.Darwin.appleclang" } diff --git a/precompile/metadata/abi/conviction-voting.json b/precompile/metadata/abi/conviction-voting.json index 8154dbee7..337c14625 100644 --- a/precompile/metadata/abi/conviction-voting.json +++ b/precompile/metadata/abi/conviction-voting.json @@ -1021,5 +1021,5 @@ } } }, - "version": "0.8.17+commit.8df45f5f.Linux.g++" + "version": "0.8.25+commit.b61c2a91.Darwin.appleclang" } diff --git a/precompile/metadata/abi/deposit.json b/precompile/metadata/abi/deposit.json index 011ed1a80..8f8168e78 100644 --- a/precompile/metadata/abi/deposit.json +++ b/precompile/metadata/abi/deposit.json @@ -136,5 +136,5 @@ } } }, - "version": "0.8.17+commit.8df45f5f.Linux.g++" + "version": "0.8.25+commit.b61c2a91.Darwin.appleclang" } diff --git a/precompile/metadata/abi/staking.json b/precompile/metadata/abi/staking.json index 47febcf44..9844573f3 100644 --- a/precompile/metadata/abi/staking.json +++ b/precompile/metadata/abi/staking.json @@ -225,5 +225,5 @@ } } }, - "version": "0.8.17+commit.8df45f5f.Linux.g++" + "version": "0.8.25+commit.b61c2a91.Darwin.appleclang" } diff --git a/precompile/metadata/abi/state-storage.json b/precompile/metadata/abi/state-storage.json index e3a59bd54..45bfc441f 100644 --- a/precompile/metadata/abi/state-storage.json +++ b/precompile/metadata/abi/state-storage.json @@ -54,5 +54,5 @@ } } }, - "version": "0.8.17+commit.8df45f5f.Linux.g++" + "version": "0.8.25+commit.b61c2a91.Darwin.appleclang" } From ae3eddd92ca4d74a7ff6e5f625474c85d909a955 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Mon, 2 Sep 2024 18:38:40 +0800 Subject: [PATCH 4/7] Update sol --- precompile/metadata/abi/deposit.json | 13 ++++++++++--- precompile/metadata/sol/deposit.sol | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/precompile/metadata/abi/deposit.json b/precompile/metadata/abi/deposit.json index 8f8168e78..686f1b80f 100644 --- a/precompile/metadata/abi/deposit.json +++ b/precompile/metadata/abi/deposit.json @@ -67,7 +67,14 @@ "type": "function" }, { - "inputs": [], + "inputs": + [ + { + "internalType": "address", + "name": "who", + "type": "address" + } + ], "name": "migrate", "outputs": [ @@ -119,7 +126,7 @@ "_0": "returns true on success, false otherwise." } }, - "migrate()": + "migrate(address)": { "details": "Migrate data to deposit contract" } @@ -132,7 +139,7 @@ "claim()": "4e71d92d", "claim_with_penalty(uint8)": "fa04a9bf", "lock(uint256,uint8)": "998e4242", - "migrate()": "8fd3ab80" + "migrate(address)": "ce5494bb" } } }, diff --git a/precompile/metadata/sol/deposit.sol b/precompile/metadata/sol/deposit.sol index 59e44a498..1e508f992 100644 --- a/precompile/metadata/sol/deposit.sol +++ b/precompile/metadata/sol/deposit.sol @@ -43,5 +43,5 @@ interface Deposit { function claim_with_penalty(uint8 depositId) external returns (bool); /// @dev Migrate data to deposit contract - function migrate() external returns (bool); + function migrate(address who) external returns (bool); } From 1c4c2939fb09c46b11d44dc8478c8bc6f63de583 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Mon, 2 Sep 2024 18:45:56 +0800 Subject: [PATCH 5/7] Fix tests --- pallet/deposit/src/benchmarking.rs | 3 ++- pallet/deposit/src/tests.rs | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pallet/deposit/src/benchmarking.rs b/pallet/deposit/src/benchmarking.rs index 6cebd619a..34fb0165b 100644 --- a/pallet/deposit/src/benchmarking.rs +++ b/pallet/deposit/src/benchmarking.rs @@ -117,6 +117,7 @@ mod benchmarks { #[benchmark] fn migrate() { let a = frame_benchmarking::whitelisted_caller::(); + let a_ = a.clone(); let max_deposits = T::MaxDeposits::get(); >::set_deposit_contract(RawOrigin::Root.into(), a.clone()).unwrap(); @@ -133,7 +134,7 @@ mod benchmarks { }); #[extrinsic_call] - _(RawOrigin::Signed(a)); + _(RawOrigin::Signed(a), a_); } #[benchmark] diff --git a/pallet/deposit/src/tests.rs b/pallet/deposit/src/tests.rs index f6e71714c..765073e23 100644 --- a/pallet/deposit/src/tests.rs +++ b/pallet/deposit/src/tests.rs @@ -365,11 +365,11 @@ fn migrate_should_work() { mock::set_in_use(1, true); - assert_noop!(Deposit::migrate(RuntimeOrigin::signed(1)), >::DepositInUse); + assert_noop!(Deposit::migrate(RuntimeOrigin::signed(1), 1), >::DepositInUse); mock::set_in_use(1, false); - assert_ok!(Deposit::migrate(RuntimeOrigin::signed(1))); + assert_ok!(Deposit::migrate(RuntimeOrigin::signed(1), 1)); assert!(Deposit::deposit_of(1).is_none()); }); } From 6a757ccf7410a0cfbb26589cf7a8d4fd502e9539 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Tue, 3 Sep 2024 12:04:16 +0800 Subject: [PATCH 6/7] Fix --- precompile/deposit/src/lib.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/precompile/deposit/src/lib.rs b/precompile/deposit/src/lib.rs index 09135936d..f4af92b66 100644 --- a/precompile/deposit/src/lib.rs +++ b/precompile/deposit/src/lib.rs @@ -44,8 +44,10 @@ pub struct Deposit(PhantomData); impl Deposit where Runtime: darwinia_deposit::Config + pallet_evm::Config, - Runtime::RuntimeCall: Dispatchable + GetDispatchInfo, - Runtime::RuntimeCall: From>, + Runtime::RuntimeCall: From> + + Dispatchable + + GetDispatchInfo, + ::AccountId: From, <::RuntimeCall as Dispatchable>::RuntimeOrigin: OriginTrait, ::RuntimeOrigin: From>, AccountIdOf: From, @@ -95,7 +97,7 @@ where RuntimeHelper::::try_dispatch( handle, Some(origin).into(), - darwinia_deposit::Call::::migrate { who: who.into() }, + darwinia_deposit::Call::::migrate { who: H160::from(who).into() }, )?; Ok(true) } From 0c28d3634a11f9934aa8809ebc8d7e93cb33d123 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Tue, 3 Sep 2024 13:36:01 +0800 Subject: [PATCH 7/7] Fix Signed-off-by: Xavier Lau --- precompile/deposit/src/tests.rs | 2 +- runtime/crab/src/migration.rs | 2 +- runtime/darwinia/src/migration.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/precompile/deposit/src/tests.rs b/precompile/deposit/src/tests.rs index 0ee1c4dfd..2e79a2858 100644 --- a/precompile/deposit/src/tests.rs +++ b/precompile/deposit/src/tests.rs @@ -36,7 +36,7 @@ fn selectors() { assert!(PCall::lock_selectors().contains(&0x998e4242)); assert!(PCall::claim_selectors().contains(&0x4e71d92d)); assert!(PCall::claim_with_penalty_selectors().contains(&0xfa04a9bf)); - assert!(PCall::migrate_selectors().contains(&0x8fd3ab80)); + assert!(PCall::migrate_selectors().contains(&0xce5494bb)); } #[test] diff --git a/runtime/crab/src/migration.rs b/runtime/crab/src/migration.rs index f89cf2d2a..1c89863ce 100644 --- a/runtime/crab/src/migration.rs +++ b/runtime/crab/src/migration.rs @@ -77,7 +77,7 @@ fn migrate() -> frame_support::weights::Weight { } } if let Ok(who) = - aray_bytes::hex_n_into::<_, AccountId, 20>("0xDeC9cD45e921F2AedE72f694743265af37d47Fa7") + array_bytes::hex_n_into::<_, AccountId, 20>("0xDeC9cD45e921F2AedE72f694743265af37d47Fa7") { >::put(who); } diff --git a/runtime/darwinia/src/migration.rs b/runtime/darwinia/src/migration.rs index a7dcb86a0..640b455fa 100644 --- a/runtime/darwinia/src/migration.rs +++ b/runtime/darwinia/src/migration.rs @@ -85,7 +85,7 @@ fn migrate() -> frame_support::weights::Weight { } } if let Ok(who) = - aray_bytes::hex_n_into::<_, AccountId, 20>("0xDeC9cD45e921F2AedE72f694743265af37d47Fa7") + array_bytes::hex_n_into::<_, AccountId, 20>("0xDeC9cD45e921F2AedE72f694743265af37d47Fa7") { >::put(who); }