From 9d372840e31860f0cf17a9b6f33b1e3125d9db50 Mon Sep 17 00:00:00 2001 From: toints Date: Wed, 31 Jul 2024 16:42:04 +0800 Subject: [PATCH 1/7] Fixed: excessive deductions When transferring money to an EVM account, a portion will be deducted to create a new account. --- runtime/src/lib.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index a81f988..3db5a9c 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -13,6 +13,7 @@ pub mod xcms; use codec::{Decode, Encode, MaxEncodedLen}; use core::ops::Div; +use pallet_evm::AddressMapping; use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; @@ -362,7 +363,7 @@ pub const GRAND: Balance = QUID * 1_000; pub const MILLICENTS: Balance = CENTS / 1_000; /// The existential deposit. Set to 1/10 of the Connected Relay Chain. -pub const EXISTENTIAL_DEPOSIT: Balance = MILLIUNIT; +pub const EXISTENTIAL_DEPOSIT: Balance = 1; /// We assume that ~5% of the block weight is consumed by `on_initialize` handlers. This is /// used to limit the maximal weight of a single extrinsic. @@ -1416,7 +1417,21 @@ impl_runtime_apis! { } fn account_basic(address: H160) -> EVMAccount { - let (account, _) = pallet_evm::Pallet::::account_basic(&address); + let account_id = ::AddressMapping::into_account_id(address); + + let nonce = frame_system::Pallet::::account_nonce(&account_id); + + let balance_free = + ::Currency::free_balance(account_id.clone()); + let balance_reserved = + ::Currency::reserved_balance(account_id); + let balance = balance_free.saturating_add(balance_reserved); + + + let account = EVMAccount { + nonce: U256::from(UniqueSaturatedInto::::unique_saturated_into(nonce)), + balance: U256::from(UniqueSaturatedInto::::unique_saturated_into(balance)), + }; account } From 83e175a59d22dce3f96af108bc2b38a9819b1ef8 Mon Sep 17 00:00:00 2001 From: toints Date: Wed, 31 Jul 2024 17:39:43 +0800 Subject: [PATCH 2/7] Update rust.yml --- .github/workflows/rust.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 532f3d6..14d4827 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -66,12 +66,6 @@ jobs: - name: Cargo Clean run: cargo clean - - name: Remove Cargo.lock - run: rm Cargo.lock - - - name: Cargo Update - run: cargo update - - name: Build run: cargo check --release From 529cf8ba5fadcdd2449af32beedc697cb12eddf0 Mon Sep 17 00:00:00 2001 From: Acaishiba Date: Thu, 1 Aug 2024 23:36:42 +0800 Subject: [PATCH 3/7] optimism the asset-bridge Extract the logic to improve construct --- pallets/assets-bridge/src/lib.rs | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/pallets/assets-bridge/src/lib.rs b/pallets/assets-bridge/src/lib.rs index df53215..c66ac03 100644 --- a/pallets/assets-bridge/src/lib.rs +++ b/pallets/assets-bridge/src/lib.rs @@ -213,7 +213,25 @@ pub mod pallet { #[pallet::constant] type ClaimBond: Get>; } - + impl Pallet { + fn ensure_admin(who: &T::AccountId) -> Result<(), Error> { + if Some(who.clone()) != Self::admin_key() { + Err(Error::::RequireAdmin) + } else { + Ok(()) + } + } + + fn is_in_emergency(asset_id: T::AssetId) -> bool { + Self::emergencies() + .iter() + .any(|emergency| emergency.clone() == asset_id.clone()) + } + + fn is_in_back_foreign(asset_id: T::AssetId) -> bool { + Self::back_foreign_assets().iter().any(|id| id.clone() == asset_id.clone()) + } + } /// The Substrate Account for Evm Addresses /// /// SubAccounts: map H160 => Option @@ -379,8 +397,7 @@ pub mod pallet { force: LocalFortitude, ) -> DispatchResultWithPostInfo { let who = ensure_signed(origin)?; - ensure!(!Self::is_in_emergency(asset_id.clone()), Error::::InEmergency); - ensure!(!amount.is_zero(), Error::::ZeroBalance); + Self::ensure_admin(&who)?; // 1. check evm account //let evm_account = Self::evm_accounts(&who).ok_or(Error::::EthAddressHasNotMapped)?; @@ -711,13 +728,5 @@ where } } - fn is_in_emergency(asset_id: T::AssetId) -> bool { - Self::emergencies() - .iter() - .any(|emergency| emergency.clone() == asset_id.clone()) - } - fn is_in_back_foreign(asset_id: T::AssetId) -> bool { - Self::back_foreign_assets().iter().any(|id| id.clone() == asset_id.clone()) - } } From 6b439f11b2a95876e1ed9963cb1fdc2869acfb3c Mon Sep 17 00:00:00 2001 From: Acaishiba Date: Thu, 1 Aug 2024 23:56:05 +0800 Subject: [PATCH 4/7] Revert "optimism the asset-bridge" This reverts commit 529cf8ba5fadcdd2449af32beedc697cb12eddf0. --- pallets/assets-bridge/src/lib.rs | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/pallets/assets-bridge/src/lib.rs b/pallets/assets-bridge/src/lib.rs index c66ac03..df53215 100644 --- a/pallets/assets-bridge/src/lib.rs +++ b/pallets/assets-bridge/src/lib.rs @@ -213,25 +213,7 @@ pub mod pallet { #[pallet::constant] type ClaimBond: Get>; } - impl Pallet { - fn ensure_admin(who: &T::AccountId) -> Result<(), Error> { - if Some(who.clone()) != Self::admin_key() { - Err(Error::::RequireAdmin) - } else { - Ok(()) - } - } - - fn is_in_emergency(asset_id: T::AssetId) -> bool { - Self::emergencies() - .iter() - .any(|emergency| emergency.clone() == asset_id.clone()) - } - - fn is_in_back_foreign(asset_id: T::AssetId) -> bool { - Self::back_foreign_assets().iter().any(|id| id.clone() == asset_id.clone()) - } - } + /// The Substrate Account for Evm Addresses /// /// SubAccounts: map H160 => Option @@ -397,7 +379,8 @@ pub mod pallet { force: LocalFortitude, ) -> DispatchResultWithPostInfo { let who = ensure_signed(origin)?; - Self::ensure_admin(&who)?; + ensure!(!Self::is_in_emergency(asset_id.clone()), Error::::InEmergency); + ensure!(!amount.is_zero(), Error::::ZeroBalance); // 1. check evm account //let evm_account = Self::evm_accounts(&who).ok_or(Error::::EthAddressHasNotMapped)?; @@ -728,5 +711,13 @@ where } } + fn is_in_emergency(asset_id: T::AssetId) -> bool { + Self::emergencies() + .iter() + .any(|emergency| emergency.clone() == asset_id.clone()) + } + fn is_in_back_foreign(asset_id: T::AssetId) -> bool { + Self::back_foreign_assets().iter().any(|id| id.clone() == asset_id.clone()) + } } From fa8a543117325a445941b8828a892a68e160f8b9 Mon Sep 17 00:00:00 2001 From: zachary0809 <139736437+zachary0809@users.noreply.github.com> Date: Fri, 2 Aug 2024 00:26:13 +0800 Subject: [PATCH 5/7] Update rust.yml Delete cargo update and undelete cargo.lock. --- .github/workflows/rust.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 532f3d6..14d4827 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -66,12 +66,6 @@ jobs: - name: Cargo Clean run: cargo clean - - name: Remove Cargo.lock - run: rm Cargo.lock - - - name: Cargo Update - run: cargo update - - name: Build run: cargo check --release From 896b4a104683918fd5930703a673ec425774faba Mon Sep 17 00:00:00 2001 From: toints Date: Thu, 5 Sep 2024 14:15:00 +0800 Subject: [PATCH 6/7] fix: fixed relychain and parachain has different token decimals --- pallets/liquidation/src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pallets/liquidation/src/lib.rs b/pallets/liquidation/src/lib.rs index 53fc3dc..772e6c5 100644 --- a/pallets/liquidation/src/lib.rs +++ b/pallets/liquidation/src/lib.rs @@ -288,7 +288,10 @@ pub mod pallet { let (collator, real_gas_cost) = match T::OrderGasCost::gas_cost(n) { Ok(cost) => match cost { - Some((collator, real_gas_cost)) => (collator, real_gas_cost), + Some((collator, real_gas_cost)) => { + let adjusted_gas_cost = real_gas_cost * PARACHAIN_TO_RELAYCHAIN_UNIT; + (collator, adjusted_gas_cost) + }, None => return, }, Err(_) => { From ba0f70c14c947a7ea365b0b4a2716075f88bf222 Mon Sep 17 00:00:00 2001 From: toints Date: Tue, 10 Sep 2024 15:47:15 +0800 Subject: [PATCH 7/7] style: format code with rustc-1.81.0 --- client/coretime/bulk/src/lib.rs | 13 +++++++------ pallets/liquidation/src/lib.rs | 3 ++- runtime/src/xcms/xcm_weight.rs | 3 ++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/client/coretime/bulk/src/lib.rs b/client/coretime/bulk/src/lib.rs index 76acf33..cac6112 100644 --- a/client/coretime/bulk/src/lib.rs +++ b/client/coretime/bulk/src/lib.rs @@ -198,12 +198,13 @@ where let constant_query = subxt::dynamic::constant("Broker", "TimeslicePeriod"); - let time_slice = - api.constants() - .at(&constant_query)? - .to_value()? - .as_u128() - .expect("coretime parachain time slice none") as u32; + let time_slice = api + .constants() + .at(&constant_query)? + .to_value()? + .as_u128() + .expect("coretime parachain time slice none") + as u32; item.end_relaychain_height = ev.when + item.duration * time_slice; diff --git a/pallets/liquidation/src/lib.rs b/pallets/liquidation/src/lib.rs index 772e6c5..a55fcfd 100644 --- a/pallets/liquidation/src/lib.rs +++ b/pallets/liquidation/src/lib.rs @@ -673,7 +673,8 @@ pub mod pallet { let total_existing_operation_ratio: u32 = OperationRatios::::iter().map(|(_, r)| r).sum(); let total_ratio = system_ratio - + treasury_ratio + collator_ratio + + treasury_ratio + + collator_ratio + total_existing_operation_ratio + ratio; log::info!("3 -+-+-+-+-+ set operation ratio, total ratio:{:?}, system_ratio:{:?}, treasury_ratio:{:?}, collator_ratio:{:?}, operation account:{:?}, op_ratio:{:?}", diff --git a/runtime/src/xcms/xcm_weight.rs b/runtime/src/xcms/xcm_weight.rs index 12a2b7f..0977a19 100644 --- a/runtime/src/xcms/xcm_weight.rs +++ b/runtime/src/xcms/xcm_weight.rs @@ -285,7 +285,8 @@ impl< AccountId, Currency: CurrencyT, OnUnbalanced: OnUnbalancedT, - > WeightTrader for UsingComponentsEx + > WeightTrader + for UsingComponentsEx { fn new() -> Self { Self(Weight::zero(), Zero::zero(), PhantomData)