From 901669b6f79d4219a7de8df2eb1b7cec0188b0fe Mon Sep 17 00:00:00 2001 From: Dmitry Lavrenov Date: Fri, 7 Feb 2025 13:30:04 +0300 Subject: [PATCH 01/18] Fix toml files --- Cargo.lock | 54 ++++++++++++++++++++++----- crates/pallet-evm-balances/Cargo.toml | 47 ++++++++++------------- crates/pallet-evm-system/Cargo.toml | 41 ++++++++------------ 3 files changed, 78 insertions(+), 64 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a8eafe2c5..da08f01dc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4132,13 +4132,13 @@ dependencies = [ "pallet-ethereum-chain-id", "pallet-evm", "pallet-evm-accounts-mapping", - "pallet-evm-balances", + "pallet-evm-balances 1.0.0-dev", "pallet-evm-precompile-blake2", "pallet-evm-precompile-bn128", "pallet-evm-precompile-modexp", "pallet-evm-precompile-sha3fips", "pallet-evm-precompile-simple", - "pallet-evm-system", + "pallet-evm-system 1.0.0-dev", "pallet-grandpa", "pallet-humanode-offences", "pallet-humanode-session", @@ -6446,8 +6446,8 @@ dependencies = [ "frame-system", "mockall", "pallet-balances", - "pallet-evm-balances", - "pallet-evm-system", + "pallet-evm-balances 1.0.0-dev", + "pallet-evm-system 1.0.0-dev", "parity-scale-codec", "primitives-currency-swap", "scale-info", @@ -6466,8 +6466,8 @@ dependencies = [ "hex-literal", "pallet-balances", "pallet-evm", - "pallet-evm-balances", - "pallet-evm-system", + "pallet-evm-balances 1.0.0-dev", + "pallet-evm-system 1.0.0-dev", "pallet-timestamp", "parity-scale-codec", "scale-info", @@ -6563,6 +6563,24 @@ dependencies = [ "sp-runtime", ] +[[package]] +name = "pallet-evm-balances" +version = "0.1.0" +dependencies = [ + "fp-evm", + "frame-support", + "frame-system", + "pallet-evm", + "pallet-evm-system 0.1.0", + "pallet-timestamp", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-evm-balances" version = "1.0.0-dev" @@ -6623,6 +6641,22 @@ dependencies = [ "sp-io", ] +[[package]] +name = "pallet-evm-system" +version = "0.1.0" +dependencies = [ + "fp-evm", + "frame-support", + "frame-system", + "mockall", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-evm-system" version = "1.0.0-dev" @@ -7309,8 +7343,8 @@ dependencies = [ "num_enum 0.7.3", "pallet-balances", "pallet-evm", - "pallet-evm-balances", - "pallet-evm-system", + "pallet-evm-balances 1.0.0-dev", + "pallet-evm-system 1.0.0-dev", "pallet-timestamp", "parity-scale-codec", "precompile-utils", @@ -7350,8 +7384,8 @@ dependencies = [ "pallet-balances", "pallet-erc20-support", "pallet-evm", - "pallet-evm-balances", - "pallet-evm-system", + "pallet-evm-balances 1.0.0-dev", + "pallet-evm-system 1.0.0-dev", "pallet-timestamp", "parity-scale-codec", "precompile-utils", diff --git a/crates/pallet-evm-balances/Cargo.toml b/crates/pallet-evm-balances/Cargo.toml index a0b49cb61..7428691ba 100644 --- a/crates/pallet-evm-balances/Cargo.toml +++ b/crates/pallet-evm-balances/Cargo.toml @@ -1,28 +1,22 @@ [package] name = "pallet-evm-balances" -version = "1.0.0-dev" -license = "Apache-2.0" -description = "FRAME EVM BALANCES pallet." -edition = { workspace = true } -repository = { workspace = true } - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] +version = "0.1.0" +edition = "2021" +publish = false [dependencies] -log = { workspace = true, default-features = false } -scale-codec = { package = "parity-scale-codec", workspace = true } -scale-info = { workspace = true } -# Substrate +codec = { workspace = true } frame-support = { workspace = true } frame-system = { workspace = true } +scale-info = { workspace = true } sp-runtime = { workspace = true } sp-std = { workspace = true } [dev-dependencies] +pallet-evm-system = { path = "../pallet-evm-system", features = ["default"] } + fp-evm = { workspace = true } pallet-evm = { workspace = true } -pallet-evm-system = { workspace = true } pallet-timestamp = { workspace = true } sp-core = { workspace = true } sp-io = { workspace = true } @@ -30,21 +24,18 @@ sp-io = { workspace = true } [features] default = ["std"] std = [ - "log/std", - "scale-codec/std", - "scale-info/std", - # Substrate - "frame-support/std", - "frame-system/std", - "pallet-timestamp/std", - "sp-runtime/std", - "sp-std/std", - # Frontier - "fp-evm/std", - "pallet-evm/std", - "pallet-evm-system/std", + "codec/std", + "fp-evm/std", + "frame-support/std", + "frame-system/std", + "pallet-evm-system/std", + "pallet-evm/std", + "pallet-timestamp/std", + "scale-info/std", + "sp-runtime/std", + "sp-std/std", ] try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", + "frame-support/try-runtime", + "frame-system/try-runtime", ] diff --git a/crates/pallet-evm-system/Cargo.toml b/crates/pallet-evm-system/Cargo.toml index 1a114304f..d462304d9 100644 --- a/crates/pallet-evm-system/Cargo.toml +++ b/crates/pallet-evm-system/Cargo.toml @@ -1,25 +1,17 @@ [package] name = "pallet-evm-system" -version = "1.0.0-dev" -license = "Apache-2.0" -description = "FRAME EVM SYSTEM pallet." -edition = { workspace = true } -repository = { workspace = true } - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] +version = "0.1.0" +edition = "2021" +publish = false [dependencies] -log = { workspace = true, default-features = false } -scale-codec = { package = "parity-scale-codec", workspace = true } -scale-info = { workspace = true } -# Substrate +codec = { workspace = true } +fp-evm = { workspace = true } frame-support = { workspace = true } frame-system = { workspace = true } +scale-info = { workspace = true } sp-runtime = { workspace = true } sp-std = { workspace = true } -# Frontier -fp-evm = { workspace = true } [dev-dependencies] mockall = { workspace = true } @@ -29,18 +21,15 @@ sp-io = { workspace = true } [features] default = ["std"] std = [ - "log/std", - "scale-codec/std", - "scale-info/std", - # Substrate - "frame-support/std", - "frame-system/std", - "sp-runtime/std", - "sp-std/std", - # Frontier - "fp-evm/std", + "codec/std", + "fp-evm/std", + "frame-support/std", + "frame-system/std", + "scale-info/std", + "sp-runtime/std", + "sp-std/std", ] try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", + "frame-support/try-runtime", + "frame-system/try-runtime", ] From 4d4fe7354429f583fb92dbef3b11ee51ec1eebac Mon Sep 17 00:00:00 2001 From: Dmitry Lavrenov Date: Fri, 7 Feb 2025 13:36:20 +0300 Subject: [PATCH 02/18] Properly use codec --- crates/pallet-evm-balances/src/lib.rs | 2 +- crates/pallet-evm-system/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/pallet-evm-balances/src/lib.rs b/crates/pallet-evm-balances/src/lib.rs index 58b8f8c02..2126c4ddf 100644 --- a/crates/pallet-evm-balances/src/lib.rs +++ b/crates/pallet-evm-balances/src/lib.rs @@ -5,6 +5,7 @@ // Ensure we're `no_std` when compiling for Wasm. #![cfg_attr(not(feature = "std"), no_std)] +use codec::{Codec, Decode, Encode, MaxEncodedLen}; use frame_support::{ ensure, traits::{ @@ -14,7 +15,6 @@ use frame_support::{ StoredMap, WithdrawReasons, }, }; -use scale_codec::{Codec, Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; use sp_runtime::{ traits::{Bounded, CheckedAdd, CheckedSub, MaybeSerializeDeserialize, Zero}, diff --git a/crates/pallet-evm-system/src/lib.rs b/crates/pallet-evm-system/src/lib.rs index 7322b7874..ceb586201 100644 --- a/crates/pallet-evm-system/src/lib.rs +++ b/crates/pallet-evm-system/src/lib.rs @@ -3,8 +3,8 @@ // Ensure we're `no_std` when compiling for Wasm. #![cfg_attr(not(feature = "std"), no_std)] +use codec::{Decode, Encode, FullCodec, MaxEncodedLen}; use frame_support::traits::StoredMap; -use scale_codec::{Decode, Encode, FullCodec, MaxEncodedLen}; use scale_info::TypeInfo; use sp_runtime::{ traits::{One, Zero}, From 8034784acf5eca283dc0bd14b4918d4205651fb3 Mon Sep 17 00:00:00 2001 From: Dmitry Lavrenov Date: Fri, 7 Feb 2025 13:37:04 +0300 Subject: [PATCH 03/18] Edit libs docs --- crates/pallet-evm-balances/src/lib.rs | 3 --- crates/pallet-evm-system/src/lib.rs | 1 - 2 files changed, 4 deletions(-) diff --git a/crates/pallet-evm-balances/src/lib.rs b/crates/pallet-evm-balances/src/lib.rs index 2126c4ddf..d59509faa 100644 --- a/crates/pallet-evm-balances/src/lib.rs +++ b/crates/pallet-evm-balances/src/lib.rs @@ -1,8 +1,5 @@ -// SPDX-License-Identifier: Apache-2.0 - //! # EVM Balances Pallet. -// Ensure we're `no_std` when compiling for Wasm. #![cfg_attr(not(feature = "std"), no_std)] use codec::{Codec, Decode, Encode, MaxEncodedLen}; diff --git a/crates/pallet-evm-system/src/lib.rs b/crates/pallet-evm-system/src/lib.rs index ceb586201..fae7cae4e 100644 --- a/crates/pallet-evm-system/src/lib.rs +++ b/crates/pallet-evm-system/src/lib.rs @@ -1,6 +1,5 @@ //! # EVM System Pallet. -// Ensure we're `no_std` when compiling for Wasm. #![cfg_attr(not(feature = "std"), no_std)] use codec::{Decode, Encode, FullCodec, MaxEncodedLen}; From 07a9ea6c1c82f4061ca6a448d9959fcb7c38083e Mon Sep 17 00:00:00 2001 From: Dmitry Lavrenov Date: Fri, 7 Feb 2025 13:40:08 +0300 Subject: [PATCH 04/18] Fix features --- crates/pallet-evm-balances/Cargo.toml | 6 ++++++ crates/pallet-evm-system/Cargo.toml | 3 +++ 2 files changed, 9 insertions(+) diff --git a/crates/pallet-evm-balances/Cargo.toml b/crates/pallet-evm-balances/Cargo.toml index 7428691ba..2fac8aaa1 100644 --- a/crates/pallet-evm-balances/Cargo.toml +++ b/crates/pallet-evm-balances/Cargo.toml @@ -32,10 +32,16 @@ std = [ "pallet-evm/std", "pallet-timestamp/std", "scale-info/std", + "sp-core/std", + "sp-io/std", "sp-runtime/std", "sp-std/std", ] try-runtime = [ "frame-support/try-runtime", "frame-system/try-runtime", + "pallet-evm-system/try-runtime", + "pallet-evm/try-runtime", + "pallet-timestamp/try-runtime", + "sp-runtime/try-runtime", ] diff --git a/crates/pallet-evm-system/Cargo.toml b/crates/pallet-evm-system/Cargo.toml index d462304d9..2e00f444f 100644 --- a/crates/pallet-evm-system/Cargo.toml +++ b/crates/pallet-evm-system/Cargo.toml @@ -26,10 +26,13 @@ std = [ "frame-support/std", "frame-system/std", "scale-info/std", + "sp-core/std", + "sp-io/std", "sp-runtime/std", "sp-std/std", ] try-runtime = [ "frame-support/try-runtime", "frame-system/try-runtime", + "sp-runtime/try-runtime", ] From 5404f45e325a28ed2fbd3602846b07105f707bbd Mon Sep 17 00:00:00 2001 From: Dmitry Lavrenov Date: Fri, 7 Feb 2025 13:40:47 +0300 Subject: [PATCH 05/18] Update features snapshot --- utils/checks/snapshots/features.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/checks/snapshots/features.yaml b/utils/checks/snapshots/features.yaml index 252f44bcb..de6e263a3 100644 --- a/utils/checks/snapshots/features.yaml +++ b/utils/checks/snapshots/features.yaml @@ -2176,7 +2176,7 @@ - default - frame-benchmarking - std -- name: pallet-evm-balances 1.0.0-dev +- name: pallet-evm-balances 0.1.0 features: - default - std @@ -2195,7 +2195,7 @@ - name: pallet-evm-precompile-simple 2.0.0-dev features: - std -- name: pallet-evm-system 1.0.0-dev +- name: pallet-evm-system 0.1.0 features: - default - std From cffbf53cf53c7e98b9e9f7062244a8d2920b1aeb Mon Sep 17 00:00:00 2001 From: Dmitry Lavrenov Date: Fri, 7 Feb 2025 13:41:43 +0300 Subject: [PATCH 06/18] Fix typo --- .../pallet-evm-balances/src/tests/currency.rs | 28 +++++++++---------- .../pallet-evm-balances/src/tests/fungible.rs | 28 +++++++++---------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/crates/pallet-evm-balances/src/tests/currency.rs b/crates/pallet-evm-balances/src/tests/currency.rs index a9496d927..5870e9ca1 100644 --- a/crates/pallet-evm-balances/src/tests/currency.rs +++ b/crates/pallet-evm-balances/src/tests/currency.rs @@ -123,7 +123,7 @@ fn transfer_works() { // Check test preconditions. assert_eq!(EvmBalances::total_balance(&alice()), INIT_BALANCE); - let transfered_amount = 100; + let transferred_amount = 100; // Set block number to enable events. System::set_block_number(1); @@ -132,23 +132,23 @@ fn transfer_works() { assert_ok!(EvmBalances::transfer( &alice(), &bob(), - transfered_amount, + transferred_amount, ExistenceRequirement::KeepAlive )); // Assert state changes. assert_eq!( EvmBalances::total_balance(&alice()), - INIT_BALANCE - transfered_amount + INIT_BALANCE - transferred_amount ); assert_eq!( EvmBalances::total_balance(&bob()), - INIT_BALANCE + transfered_amount + INIT_BALANCE + transferred_amount ); System::assert_has_event(RuntimeEvent::EvmBalances(crate::Event::Transfer { from: alice(), to: bob(), - amount: transfered_amount, + amount: transferred_amount, })); assert_total_issuance_invariant(); @@ -161,7 +161,7 @@ fn transfer_works_full_balance() { // Check test preconditions. assert_eq!(EvmBalances::total_balance(&alice()), INIT_BALANCE); - let transfered_amount = INIT_BALANCE; + let transferred_amount = INIT_BALANCE; // Set block number to enable events. System::set_block_number(1); @@ -170,23 +170,23 @@ fn transfer_works_full_balance() { assert_ok!(EvmBalances::transfer( &alice(), &bob(), - transfered_amount, + transferred_amount, ExistenceRequirement::AllowDeath )); // Assert state changes. assert_eq!( EvmBalances::total_balance(&alice()), - INIT_BALANCE - transfered_amount + INIT_BALANCE - transferred_amount ); assert_eq!( EvmBalances::total_balance(&bob()), - INIT_BALANCE + transfered_amount + INIT_BALANCE + transferred_amount ); System::assert_has_event(RuntimeEvent::EvmBalances(crate::Event::Transfer { from: alice(), to: bob(), - amount: transfered_amount, + amount: transferred_amount, })); assert!(!EvmSystem::account_exists(&alice())); System::assert_has_event(RuntimeEvent::EvmSystem( @@ -203,7 +203,7 @@ fn transfer_fails_funds_unavailable() { // Check test preconditions. assert_eq!(EvmBalances::total_balance(&alice()), INIT_BALANCE); - let transfered_amount = INIT_BALANCE + 1; + let transferred_amount = INIT_BALANCE + 1; // Set block number to enable events. System::set_block_number(1); @@ -213,7 +213,7 @@ fn transfer_fails_funds_unavailable() { EvmBalances::transfer( &alice(), &bob(), - transfered_amount, + transferred_amount, ExistenceRequirement::KeepAlive ), TokenError::FundsUnavailable @@ -227,7 +227,7 @@ fn transfer_fails_not_expendable() { // Check test preconditions. assert_eq!(EvmBalances::total_balance(&alice()), INIT_BALANCE); - let transfered_amount = INIT_BALANCE; + let transferred_amount = INIT_BALANCE; // Set block number to enable events. System::set_block_number(1); @@ -237,7 +237,7 @@ fn transfer_fails_not_expendable() { EvmBalances::transfer( &alice(), &bob(), - transfered_amount, + transferred_amount, ExistenceRequirement::KeepAlive ), TokenError::NotExpendable diff --git a/crates/pallet-evm-balances/src/tests/fungible.rs b/crates/pallet-evm-balances/src/tests/fungible.rs index 562c6c5a0..55fb2642c 100644 --- a/crates/pallet-evm-balances/src/tests/fungible.rs +++ b/crates/pallet-evm-balances/src/tests/fungible.rs @@ -683,7 +683,7 @@ fn transfer_works() { // Check test preconditions. assert_eq!(EvmBalances::total_balance(&alice()), INIT_BALANCE); - let transfered_amount = 100; + let transferred_amount = 100; // Set block number to enable events. System::set_block_number(1); @@ -692,23 +692,23 @@ fn transfer_works() { assert_ok!(EvmBalances::transfer( &alice(), &bob(), - transfered_amount, + transferred_amount, Preservation::Preserve )); // Assert state changes. assert_eq!( EvmBalances::total_balance(&alice()), - INIT_BALANCE - transfered_amount + INIT_BALANCE - transferred_amount ); assert_eq!( EvmBalances::total_balance(&bob()), - INIT_BALANCE + transfered_amount + INIT_BALANCE + transferred_amount ); System::assert_has_event(RuntimeEvent::EvmBalances(Event::Transfer { from: alice(), to: bob(), - amount: transfered_amount, + amount: transferred_amount, })); assert_total_issuance_invariant(); @@ -721,7 +721,7 @@ fn transfer_works_full_balance() { // Check test preconditions. assert_eq!(EvmBalances::total_balance(&alice()), INIT_BALANCE); - let transfered_amount = INIT_BALANCE; + let transferred_amount = INIT_BALANCE; // Set block number to enable events. System::set_block_number(1); @@ -730,23 +730,23 @@ fn transfer_works_full_balance() { assert_ok!(EvmBalances::transfer( &alice(), &bob(), - transfered_amount, + transferred_amount, Preservation::Expendable )); // Assert state changes. assert_eq!( EvmBalances::total_balance(&alice()), - INIT_BALANCE - transfered_amount + INIT_BALANCE - transferred_amount ); assert_eq!( EvmBalances::total_balance(&bob()), - INIT_BALANCE + transfered_amount + INIT_BALANCE + transferred_amount ); System::assert_has_event(RuntimeEvent::EvmBalances(Event::Transfer { from: alice(), to: bob(), - amount: transfered_amount, + amount: transferred_amount, })); assert!(!EvmSystem::account_exists(&alice())); System::assert_has_event(RuntimeEvent::EvmSystem( @@ -763,14 +763,14 @@ fn transfer_fails_funds_unavailable() { // Check test preconditions. assert_eq!(EvmBalances::total_balance(&alice()), INIT_BALANCE); - let transfered_amount = INIT_BALANCE + 1; + let transferred_amount = INIT_BALANCE + 1; // Set block number to enable events. System::set_block_number(1); // Invoke the function under test. assert_noop!( - EvmBalances::transfer(&alice(), &bob(), transfered_amount, Preservation::Preserve), + EvmBalances::transfer(&alice(), &bob(), transferred_amount, Preservation::Preserve), TokenError::FundsUnavailable ); }); @@ -782,14 +782,14 @@ fn transfer_fails_not_expendable() { // Check test preconditions. assert_eq!(EvmBalances::total_balance(&alice()), INIT_BALANCE); - let transfered_amount = INIT_BALANCE; + let transferred_amount = INIT_BALANCE; // Set block number to enable events. System::set_block_number(1); // Invoke the function under test. assert_noop!( - EvmBalances::transfer(&alice(), &bob(), transfered_amount, Preservation::Preserve), + EvmBalances::transfer(&alice(), &bob(), transferred_amount, Preservation::Preserve), TokenError::NotExpendable ); }); From 033873d682e1783723934bcb7caace487dcb1cb5 Mon Sep 17 00:00:00 2001 From: Dmitry Lavrenov Date: Fri, 7 Feb 2025 13:43:37 +0300 Subject: [PATCH 07/18] Allow missing_docs_in_private_items for pallets --- crates/pallet-evm-balances/src/lib.rs | 3 +++ crates/pallet-evm-system/src/lib.rs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/crates/pallet-evm-balances/src/lib.rs b/crates/pallet-evm-balances/src/lib.rs index d59509faa..6b0e4e172 100644 --- a/crates/pallet-evm-balances/src/lib.rs +++ b/crates/pallet-evm-balances/src/lib.rs @@ -38,6 +38,9 @@ pub use pallet::*; /// The current storage version. const STORAGE_VERSION: StorageVersion = StorageVersion::new(0); +// We have to temporarily allow some clippy lints. Later on we'll send patches to substrate to +// fix them at their end. +#[allow(clippy::missing_docs_in_private_items)] #[frame_support::pallet] pub mod pallet { use frame_support::pallet_prelude::*; diff --git a/crates/pallet-evm-system/src/lib.rs b/crates/pallet-evm-system/src/lib.rs index fae7cae4e..7f869da5a 100644 --- a/crates/pallet-evm-system/src/lib.rs +++ b/crates/pallet-evm-system/src/lib.rs @@ -27,6 +27,9 @@ pub struct AccountInfo { pub data: AccountData, } +// We have to temporarily allow some clippy lints. Later on we'll send patches to substrate to +// fix them at their end. +#[allow(clippy::missing_docs_in_private_items)] #[frame_support::pallet] pub mod pallet { use frame_support::pallet_prelude::*; From 106819f58f1e97e0a241135b432f9aa450618295 Mon Sep 17 00:00:00 2001 From: Dmitry Lavrenov Date: Fri, 7 Feb 2025 13:44:24 +0300 Subject: [PATCH 08/18] Fix missing docs at pallet-evm-system --- crates/pallet-evm-system/src/lib.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/pallet-evm-system/src/lib.rs b/crates/pallet-evm-system/src/lib.rs index 7f869da5a..3c5e1c6e1 100644 --- a/crates/pallet-evm-system/src/lib.rs +++ b/crates/pallet-evm-system/src/lib.rs @@ -95,9 +95,15 @@ pub mod pallet { #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { /// A new account was created. - NewAccount { account: ::AccountId }, + NewAccount { + /// The associated account id. + account: ::AccountId, + }, /// An account was reaped. - KilledAccount { account: ::AccountId }, + KilledAccount { + /// The associated account id. + account: ::AccountId, + }, } } From a33fa3b61fcdd56a6f20002211f3572a1245db9e Mon Sep 17 00:00:00 2001 From: Dmitry Lavrenov Date: Fri, 7 Feb 2025 13:47:59 +0300 Subject: [PATCH 09/18] Fix math side affect at pallet-evm-system --- crates/pallet-evm-system/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/pallet-evm-system/src/lib.rs b/crates/pallet-evm-system/src/lib.rs index 3c5e1c6e1..5531a43ce 100644 --- a/crates/pallet-evm-system/src/lib.rs +++ b/crates/pallet-evm-system/src/lib.rs @@ -7,7 +7,7 @@ use frame_support::traits::StoredMap; use scale_info::TypeInfo; use sp_runtime::{ traits::{One, Zero}, - DispatchError, RuntimeDebug, + DispatchError, RuntimeDebug, Saturating, }; #[cfg(test)] @@ -145,7 +145,8 @@ impl Pallet { let is_new_account = maybe_account.is_none(); let account = maybe_account.get_or_insert_with(Default::default); - account.nonce += ::Index::one(); + // `AtLeast32Bit` is big enough for this overflow to be practically impossible. + account.nonce = account.nonce.saturating_add(::Index::one()); is_new_account }); From 74407f052bf5177b4fd664c510a71f883b95173d Mon Sep 17 00:00:00 2001 From: Dmitry Lavrenov Date: Fri, 7 Feb 2025 13:49:21 +0300 Subject: [PATCH 10/18] Fix clippy in tests at pallet-evm-system --- crates/pallet-evm-system/src/tests.rs | 32 +++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/crates/pallet-evm-system/src/tests.rs b/crates/pallet-evm-system/src/tests.rs index bedef9b8b..16bec6312 100644 --- a/crates/pallet-evm-system/src/tests.rs +++ b/crates/pallet-evm-system/src/tests.rs @@ -38,7 +38,7 @@ fn create_account_created() { // Assert state changes. assert!(EvmSystem::account_exists(&account_id)); assert_eq!( - >::get(&account_id), + >::get(account_id), AccountInfo::<_, _>::default() ); System::assert_has_event(RuntimeEvent::EvmSystem(Event::NewAccount { @@ -57,7 +57,7 @@ fn create_account_already_exists() { new_test_ext().execute_with_ext(|_| { // Prepare test data. let account_id = H160::from_str("1000000000000000000000000000000000000001").unwrap(); - >::insert(account_id.clone(), AccountInfo::<_, _>::default()); + >::insert(account_id, AccountInfo::<_, _>::default()); // Invoke the function under test. assert_storage_noop!(assert_eq!( @@ -119,7 +119,7 @@ fn inc_account_nonce_account_exists() { new_test_ext().execute_with_ext(|_| { // Prepare test data. let account_id = H160::from_str("1000000000000000000000000000000000000001").unwrap(); - >::insert(account_id.clone(), AccountInfo::<_, _>::default()); + >::insert(account_id, AccountInfo::<_, _>::default()); // Check test preconditions. assert!(EvmSystem::account_exists(&account_id)); @@ -135,7 +135,7 @@ fn inc_account_nonce_account_exists() { }); } -/// This test verifies that try_mutate_exists works as expected in case data wasn't providing +/// This test verifies that `try_mutate_exists` works as expected in case data wasn't providing /// and returned data is `Some`. As a result, a new account has been created. #[test] fn try_mutate_exists_account_created() { @@ -167,7 +167,7 @@ fn try_mutate_exists_account_created() { // Assert state changes. assert!(EvmSystem::account_exists(&account_id)); assert_eq!( - >::get(&account_id), + >::get(account_id), AccountInfo { data: 1, ..Default::default() @@ -182,7 +182,7 @@ fn try_mutate_exists_account_created() { }); } -/// This test verifies that try_mutate_exists works as expected in case data was providing +/// This test verifies that `try_mutate_exists` works as expected in case data was providing /// and returned data is `Some`. As a result, the account has been updated. #[test] fn try_mutate_exists_account_updated() { @@ -191,7 +191,7 @@ fn try_mutate_exists_account_updated() { let account_id = H160::from_str("1000000000000000000000000000000000000001").unwrap(); let nonce = 1; let data = 1; - >::insert(account_id.clone(), AccountInfo { nonce, data }); + >::insert(account_id, AccountInfo { nonce, data }); // Check test preconditions. assert!(EvmSystem::account_exists(&account_id)); @@ -211,7 +211,7 @@ fn try_mutate_exists_account_updated() { // Assert state changes. assert!(EvmSystem::account_exists(&account_id)); assert_eq!( - >::get(&account_id), + >::get(account_id), AccountInfo { nonce, data: data + 1, @@ -220,14 +220,14 @@ fn try_mutate_exists_account_updated() { }); } -/// This test verifies that try_mutate_exists works as expected in case data was providing +/// This test verifies that `try_mutate_exists` works as expected in case data was providing /// and returned data is `None`, account has zero nonce. As a result, the account has been removed. #[test] fn try_mutate_exists_account_removed() { new_test_ext().execute_with_ext(|_| { // Prepare test data. let account_id = H160::from_str("1000000000000000000000000000000000000001").unwrap(); - >::insert(account_id.clone(), AccountInfo::<_, _>::default()); + >::insert(account_id, AccountInfo::<_, _>::default()); // Check test preconditions. assert!(EvmSystem::account_exists(&account_id)); @@ -261,7 +261,7 @@ fn try_mutate_exists_account_removed() { }); } -/// This test verifies that try_mutate_exists works as expected in case data was providing +/// This test verifies that `try_mutate_exists` works as expected in case data was providing /// and returned data is `None`, account has non zero nonce. As a result, the account has been retained. #[test] fn try_mutate_exists_account_retained() { @@ -272,7 +272,7 @@ fn try_mutate_exists_account_retained() { let data = 100; let account_info = AccountInfo { nonce, data }; - >::insert(account_id.clone(), account_info); + >::insert(account_id, account_info); // Check test preconditions. assert!(EvmSystem::account_exists(&account_id)); @@ -287,7 +287,7 @@ fn try_mutate_exists_account_retained() { // Assert state changes. assert!(EvmSystem::account_exists(&account_id)); assert_eq!( - >::get(&account_id), + >::get(account_id), AccountInfo { nonce, ..Default::default() @@ -296,7 +296,7 @@ fn try_mutate_exists_account_retained() { }); } -/// This test verifies that try_mutate_exists works as expected in case data wasn't providing +/// This test verifies that `try_mutate_exists` works as expected in case data wasn't providing /// and returned data is `None`. As a result, the account hasn't been created. #[test] fn try_mutate_exists_account_not_created() { @@ -322,14 +322,14 @@ fn try_mutate_exists_account_not_created() { }); } -/// This test verifies that try_mutate_exists works as expected in case getting error +/// This test verifies that `try_mutate_exists` works as expected in case getting error /// during data mutation. #[test] fn try_mutate_exists_without_changes() { new_test_ext().execute_with_ext(|_| { // Prepare test data. let account_id = H160::from_str("1000000000000000000000000000000000000001").unwrap(); - >::insert(account_id.clone(), AccountInfo::<_, _>::default()); + >::insert(account_id, AccountInfo::<_, _>::default()); // Check test preconditions. assert!(EvmSystem::account_exists(&account_id)); From 1cdef3a9bc94bb7776508148e4cc7a1068be2f44 Mon Sep 17 00:00:00 2001 From: Dmitry Lavrenov Date: Fri, 7 Feb 2025 17:01:21 +0300 Subject: [PATCH 11/18] Edit tests related docs --- crates/pallet-evm-balances/src/mock.rs | 19 ------------------- crates/pallet-evm-balances/src/tests/mod.rs | 2 +- crates/pallet-evm-system/src/mock.rs | 19 ------------------- crates/pallet-evm-system/src/tests.rs | 2 +- 4 files changed, 2 insertions(+), 40 deletions(-) diff --git a/crates/pallet-evm-balances/src/mock.rs b/crates/pallet-evm-balances/src/mock.rs index fc808139e..bbe264559 100644 --- a/crates/pallet-evm-balances/src/mock.rs +++ b/crates/pallet-evm-balances/src/mock.rs @@ -1,22 +1,3 @@ -// SPDX-License-Identifier: Apache-2.0 -// This file is part of Frontier. -// -// Copyright (c) 2020-2022 Parity Technologies (UK) Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! Test mock for unit tests. - use std::collections::BTreeMap; use frame_support::{ diff --git a/crates/pallet-evm-balances/src/tests/mod.rs b/crates/pallet-evm-balances/src/tests/mod.rs index f46a562eb..a3ca14673 100644 --- a/crates/pallet-evm-balances/src/tests/mod.rs +++ b/crates/pallet-evm-balances/src/tests/mod.rs @@ -1,4 +1,4 @@ -//! Unit tests. +//! The tests for the pallet. use frame_support::{assert_ok, traits::Currency, weights::Weight}; use pallet_evm::{FeeCalculator, FixedGasWeightMapping, GasWeightMapping, Runner}; diff --git a/crates/pallet-evm-system/src/mock.rs b/crates/pallet-evm-system/src/mock.rs index b05b5298d..8beb62295 100644 --- a/crates/pallet-evm-system/src/mock.rs +++ b/crates/pallet-evm-system/src/mock.rs @@ -1,22 +1,3 @@ -// SPDX-License-Identifier: Apache-2.0 -// This file is part of Frontier. -// -// Copyright (c) 2020-2022 Parity Technologies (UK) Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! Test mock for unit tests. - use frame_support::traits::{ConstU32, ConstU64}; use mockall::mock; use sp_core::{H160, H256}; diff --git a/crates/pallet-evm-system/src/tests.rs b/crates/pallet-evm-system/src/tests.rs index 16bec6312..c8d6c51fd 100644 --- a/crates/pallet-evm-system/src/tests.rs +++ b/crates/pallet-evm-system/src/tests.rs @@ -1,4 +1,4 @@ -//! Unit tests. +//! The tests for the pallet. use frame_support::{assert_noop, assert_storage_noop}; use mockall::predicate; From 7a66a88846e9ef3fab5a0ee02fa1b07402927404 Mon Sep 17 00:00:00 2001 From: Dmitry Lavrenov Date: Fri, 7 Feb 2025 17:02:48 +0300 Subject: [PATCH 12/18] Fix clippy in tests at pallet-evm-balances --- crates/pallet-evm-balances/src/tests/currency.rs | 4 ++-- crates/pallet-evm-balances/src/tests/mod.rs | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/pallet-evm-balances/src/tests/currency.rs b/crates/pallet-evm-balances/src/tests/currency.rs index 5870e9ca1..810f59428 100644 --- a/crates/pallet-evm-balances/src/tests/currency.rs +++ b/crates/pallet-evm-balances/src/tests/currency.rs @@ -27,7 +27,7 @@ fn total_balance_works() { fn free_balance_works() { new_test_ext().execute_with_ext(|_| { // Check the free balance value. - assert_eq!(EvmBalances::free_balance(&alice()), INIT_BALANCE); + assert_eq!(EvmBalances::free_balance(alice()), INIT_BALANCE); }); } @@ -551,7 +551,7 @@ fn evm_system_account_should_be_reaped() { )); // Assert state changes. - assert_eq!(EvmBalances::free_balance(&bob()), 0); + assert_eq!(EvmBalances::free_balance(bob()), 0); assert!(!EvmSystem::account_exists(&bob())); System::assert_has_event(RuntimeEvent::EvmSystem( pallet_evm_system::Event::KilledAccount { account: bob() }, diff --git a/crates/pallet-evm-balances/src/tests/mod.rs b/crates/pallet-evm-balances/src/tests/mod.rs index a3ca14673..ec798e26e 100644 --- a/crates/pallet-evm-balances/src/tests/mod.rs +++ b/crates/pallet-evm-balances/src/tests/mod.rs @@ -53,13 +53,13 @@ fn evm_system_removing_account_non_zero_balance() { ExistenceRequirement::KeepAlive )); - assert_eq!(EvmBalances::free_balance(&contract), 1000); + assert_eq!(EvmBalances::free_balance(contract), 1000); // Invoke the function under test. EVM::remove_account(&contract); // Assert state changes. - assert_eq!(EvmBalances::free_balance(&contract), 1000); + assert_eq!(EvmBalances::free_balance(contract), 1000); assert!(EvmSystem::account_exists(&contract)); assert_total_issuance_invariant(); @@ -73,7 +73,7 @@ fn evm_fee_deduction() { // Seed account let _ = ::Currency::deposit_creating(&charlie, 100); - assert_eq!(EvmBalances::free_balance(&charlie), 100); + assert_eq!(EvmBalances::free_balance(charlie), 100); // Deduct fees as 10 units let imbalance = @@ -82,11 +82,11 @@ fn evm_fee_deduction() { U256::from(10), ) .unwrap(); - assert_eq!(EvmBalances::free_balance(&charlie), 90); + assert_eq!(EvmBalances::free_balance(charlie), 90); // Refund fees as 5 units <::OnChargeTransaction as pallet_evm::OnChargeEVMTransaction>::correct_and_deposit_fee(&charlie, U256::from(5), U256::from(5), imbalance); - assert_eq!(EvmBalances::free_balance(&charlie), 95); + assert_eq!(EvmBalances::free_balance(charlie), 95); assert_total_issuance_invariant(); }); @@ -202,7 +202,7 @@ fn evm_refunds_and_priority_should_work() { let (base_fee, _) = ::FeeCalculator::min_gas_price(); let actual_tip = (max_fee_per_gas - base_fee).min(tip) * used_gas; - let total_cost = (used_gas * base_fee) + U256::from(actual_tip) + U256::from(1); + let total_cost = (used_gas * base_fee) + actual_tip + U256::from(1); let after_call = EVM::account_basic(&alice()).0.balance; // The tip is deducted but never refunded to the caller. assert_eq!(after_call, before_call - total_cost); From 422d97dc70ff1b529b5c660f350cbfa9fabb3397 Mon Sep 17 00:00:00 2001 From: Dmitry Lavrenov Date: Fri, 7 Feb 2025 17:05:01 +0300 Subject: [PATCH 13/18] Fix missing docs at pallet-evm-balances --- crates/pallet-evm-balances/src/lib.rs | 33 +++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/crates/pallet-evm-balances/src/lib.rs b/crates/pallet-evm-balances/src/lib.rs index 6b0e4e172..ca5786ba9 100644 --- a/crates/pallet-evm-balances/src/lib.rs +++ b/crates/pallet-evm-balances/src/lib.rs @@ -111,65 +111,94 @@ pub mod pallet { pub enum Event, I: 'static = ()> { /// An account was created with some free balance. Endowed { + /// The associated account id. account: >::AccountId, + /// The `free_balance` balance value. free_balance: T::Balance, }, /// An account was removed whose balance was non-zero but below ExistentialDeposit, /// resulting in an outright loss. DustLost { + /// The associated account id. account: >::AccountId, + /// The `amount` balance value. amount: T::Balance, }, /// Transfer succeeded. Transfer { + /// The associated account id transferred from. from: >::AccountId, + /// The associated account id transferred to. to: >::AccountId, + /// The `amount` balance value. amount: T::Balance, }, /// A balance was set by root. BalanceSet { + /// The associated account id. who: >::AccountId, + /// The `free` balance value. free: T::Balance, }, /// Some amount was deposited (e.g. for transaction fees). Deposit { + /// The associated account id. who: >::AccountId, + /// The `amount` balance value. amount: T::Balance, }, /// Some amount was withdrawn from the account (e.g. for transaction fees). Withdraw { + /// The associated account id. who: >::AccountId, + /// The `amount` balance value. amount: T::Balance, }, /// Some amount was removed from the account (e.g. for misbehavior). Slashed { + /// The associated account id. who: >::AccountId, + /// The `amount` balance value. amount: T::Balance, }, /// Some amount was minted into an account. Minted { + /// The associated account id. who: >::AccountId, + /// The `amount` balance value. amount: T::Balance, }, /// Some amount was burned from an account. Burned { + /// The associated account id. who: >::AccountId, + /// The `amount` balance value. amount: T::Balance, }, /// Some amount was suspended from an account (it can be restored later). Suspended { + /// The associated account id. who: >::AccountId, + /// The `amount` balance value. amount: T::Balance, }, /// Some amount was restored into an account. Restored { + /// The associated account id. who: >::AccountId, + /// The `amount` balance value. amount: T::Balance, }, /// Total issuance was increased by `amount`, creating a credit to be balanced. - Issued { amount: T::Balance }, + Issued { + /// The `amount` balance value. + amount: T::Balance, + }, /// Total issuance was decreased by `amount`, creating a debt to be balanced. - Rescinded { amount: T::Balance }, + Rescinded { + /// The `amount` balance value. + amount: T::Balance, + }, } #[pallet::error] From e3aa9486c0aacb2804583168174fe8f06cf59d13 Mon Sep 17 00:00:00 2001 From: Dmitry Lavrenov Date: Fri, 7 Feb 2025 17:11:16 +0300 Subject: [PATCH 14/18] Fix math side affect at pallet-evm-balances --- crates/pallet-evm-balances/src/imbalances.rs | 26 ++++++++++++++----- .../pallet-evm-balances/src/impl_currency.rs | 16 +++++++++--- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/crates/pallet-evm-balances/src/imbalances.rs b/crates/pallet-evm-balances/src/imbalances.rs index 77529d439..8d5014157 100644 --- a/crates/pallet-evm-balances/src/imbalances.rs +++ b/crates/pallet-evm-balances/src/imbalances.rs @@ -60,7 +60,10 @@ impl, I: 'static> Imbalance for PositiveImbalance fn split(self, amount: T::Balance) -> (Self, Self) { let first = self.0.min(amount); - let second = self.0 - first; + let second = self + .0 + .checked_sub(&first) + .expect("valid operation due to the check before; qed."); mem::forget(self); (Self(first), Self(second)) @@ -83,8 +86,12 @@ impl, I: 'static> Imbalance for PositiveImbalance mem::forget((self, other)); match a.cmp(&b) { - Ordering::Greater => SameOrOther::Same(Self(a - b)), - Ordering::Less => SameOrOther::Other(NegativeImbalance::new(b - a)), + Ordering::Greater => { + SameOrOther::Same(Self(a.checked_sub(&b).expect("a is greater than b; qed."))) + } + Ordering::Less => SameOrOther::Other(NegativeImbalance::new( + b.checked_sub(&a).expect("b is greater than a; qed."), + )), Ordering::Equal => SameOrOther::None, } } @@ -123,7 +130,10 @@ impl, I: 'static> Imbalance for NegativeImbalance fn split(self, amount: T::Balance) -> (Self, Self) { let first = self.0.min(amount); - let second = self.0 - first; + let second = self + .0 + .checked_sub(&first) + .expect("valid operation due to the check before; qed."); mem::forget(self); (Self(first), Self(second)) @@ -146,8 +156,12 @@ impl, I: 'static> Imbalance for NegativeImbalance mem::forget((self, other)); match a.cmp(&b) { - Ordering::Greater => SameOrOther::Same(Self(a - b)), - Ordering::Less => SameOrOther::Other(PositiveImbalance::new(b - a)), + Ordering::Greater => { + SameOrOther::Same(Self(a.checked_sub(&b).expect("a is greater than b; qed."))) + } + Ordering::Less => SameOrOther::Other(PositiveImbalance::new( + b.checked_sub(&a).expect("b is greater than a; qed."), + )), Ordering::Equal => SameOrOther::None, } } diff --git a/crates/pallet-evm-balances/src/impl_currency.rs b/crates/pallet-evm-balances/src/impl_currency.rs index 1fd978a94..cee8c9681 100644 --- a/crates/pallet-evm-balances/src/impl_currency.rs +++ b/crates/pallet-evm-balances/src/impl_currency.rs @@ -67,7 +67,9 @@ where } >::mutate(|issued| { *issued = issued.checked_add(&amount).unwrap_or_else(|| { - amount = Self::Balance::max_value() - *issued; + amount = Self::Balance::max_value() + .checked_sub(issued) + .expect("valid operation; qed."); Self::Balance::max_value() }) }); @@ -283,9 +285,17 @@ where ensure!(value >= ed || !is_new, Error::::ExistentialDeposit); let imbalance = if account.free <= value { - SignedImbalance::Positive(PositiveImbalance::new(value - account.free)) + SignedImbalance::Positive(PositiveImbalance::new( + value + .checked_sub(&account.free) + .expect("valid operation due to the check before; qed.") + )) } else { - SignedImbalance::Negative(NegativeImbalance::new(account.free - value)) + SignedImbalance::Negative(NegativeImbalance::new( + account.free + .checked_sub(&value) + .expect("valid operation due to the check before; qed.") + )) }; account.free = value; Self::deposit_event(Event::BalanceSet { From 7f80ad679e6d3849b9cc57d18a855e2cbfd87a95 Mon Sep 17 00:00:00 2001 From: Dmitry Lavrenov Date: Fri, 7 Feb 2025 17:21:37 +0300 Subject: [PATCH 15/18] Fix clippy --- .../pallet-evm-balances/src/impl_currency.rs | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/crates/pallet-evm-balances/src/impl_currency.rs b/crates/pallet-evm-balances/src/impl_currency.rs index cee8c9681..aba752018 100644 --- a/crates/pallet-evm-balances/src/impl_currency.rs +++ b/crates/pallet-evm-balances/src/impl_currency.rs @@ -131,14 +131,21 @@ where return (NegativeImbalance::zero(), value); } - let result = match Self::try_mutate_account_handling_dust( + let mutate_closure = |account: &mut AccountData<>::Balance>| -> Result< + (Self::NegativeImbalance, Self::Balance), + DispatchError, + > { + // Best value is the most amount we can slash following liveness rules. + let actual = value.min(account.free); + account.free.saturating_reduce(actual); + let remaining = value.saturating_sub(actual); + Ok((NegativeImbalance::new(actual), remaining)) + }; + + match Self::try_mutate_account_handling_dust( who, |account, _is_new| -> Result<(Self::NegativeImbalance, Self::Balance), DispatchError> { - // Best value is the most amount we can slash following liveness rules. - let actual = value.min(account.free); - account.free.saturating_reduce(actual); - let remaining = value.saturating_sub(actual); - Ok((NegativeImbalance::new(actual), remaining)) + mutate_closure(account) }, ) { Ok((imbalance, remaining)) => { @@ -149,8 +156,7 @@ where (imbalance, remaining) } Err(_) => (Self::NegativeImbalance::zero(), value), - }; - result + } } /// Deposit some `value` into the free balance of an existing target account `who`. From e4be7528cb51c31370236f746674e106974ca3e4 Mon Sep 17 00:00:00 2001 From: Dmitry Lavrenov Date: Sat, 8 Feb 2025 13:03:10 +0300 Subject: [PATCH 16/18] Switch to local pallet-evm-balances and pallet-evm-system --- Cargo.lock | 51 ++++--------------- Cargo.toml | 2 - crates/humanode-runtime/Cargo.toml | 4 +- crates/pallet-currency-swap/Cargo.toml | 5 +- .../pallet-dummy-precompiles-code/Cargo.toml | 5 +- crates/precompile-currency-swap/Cargo.toml | 5 +- crates/precompile-native-currency/Cargo.toml | 4 +- 7 files changed, 24 insertions(+), 52 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index da08f01dc..f800dc79a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4132,13 +4132,13 @@ dependencies = [ "pallet-ethereum-chain-id", "pallet-evm", "pallet-evm-accounts-mapping", - "pallet-evm-balances 1.0.0-dev", + "pallet-evm-balances", "pallet-evm-precompile-blake2", "pallet-evm-precompile-bn128", "pallet-evm-precompile-modexp", "pallet-evm-precompile-sha3fips", "pallet-evm-precompile-simple", - "pallet-evm-system 1.0.0-dev", + "pallet-evm-system", "pallet-grandpa", "pallet-humanode-offences", "pallet-humanode-session", @@ -6446,8 +6446,8 @@ dependencies = [ "frame-system", "mockall", "pallet-balances", - "pallet-evm-balances 1.0.0-dev", - "pallet-evm-system 1.0.0-dev", + "pallet-evm-balances", + "pallet-evm-system", "parity-scale-codec", "primitives-currency-swap", "scale-info", @@ -6466,8 +6466,8 @@ dependencies = [ "hex-literal", "pallet-balances", "pallet-evm", - "pallet-evm-balances 1.0.0-dev", - "pallet-evm-system 1.0.0-dev", + "pallet-evm-balances", + "pallet-evm-system", "pallet-timestamp", "parity-scale-codec", "scale-info", @@ -6571,7 +6571,7 @@ dependencies = [ "frame-support", "frame-system", "pallet-evm", - "pallet-evm-system 0.1.0", + "pallet-evm-system", "pallet-timestamp", "parity-scale-codec", "scale-info", @@ -6581,20 +6581,6 @@ dependencies = [ "sp-std", ] -[[package]] -name = "pallet-evm-balances" -version = "1.0.0-dev" -source = "git+https://github.com/humanode-network/frontier?tag=locked/polkadot-v0.9.42-2025-02-08#174c0227af00dbc26485c1eac68738e1d01980e8" -dependencies = [ - "frame-support", - "frame-system", - "log", - "parity-scale-codec", - "scale-info", - "sp-runtime", - "sp-std", -] - [[package]] name = "pallet-evm-precompile-blake2" version = "2.0.0-dev" @@ -6657,21 +6643,6 @@ dependencies = [ "sp-std", ] -[[package]] -name = "pallet-evm-system" -version = "1.0.0-dev" -source = "git+https://github.com/humanode-network/frontier?tag=locked/polkadot-v0.9.42-2025-02-08#174c0227af00dbc26485c1eac68738e1d01980e8" -dependencies = [ - "fp-evm", - "frame-support", - "frame-system", - "log", - "parity-scale-codec", - "scale-info", - "sp-runtime", - "sp-std", -] - [[package]] name = "pallet-evm-test-vector-support" version = "1.0.0-dev" @@ -7343,8 +7314,8 @@ dependencies = [ "num_enum 0.7.3", "pallet-balances", "pallet-evm", - "pallet-evm-balances 1.0.0-dev", - "pallet-evm-system 1.0.0-dev", + "pallet-evm-balances", + "pallet-evm-system", "pallet-timestamp", "parity-scale-codec", "precompile-utils", @@ -7384,8 +7355,8 @@ dependencies = [ "pallet-balances", "pallet-erc20-support", "pallet-evm", - "pallet-evm-balances 1.0.0-dev", - "pallet-evm-system 1.0.0-dev", + "pallet-evm-balances", + "pallet-evm-system", "pallet-timestamp", "parity-scale-codec", "precompile-utils", diff --git a/Cargo.toml b/Cargo.toml index d33fd04a0..148e04d77 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -155,13 +155,11 @@ fp-self-contained = { git = "https://github.com/humanode-network/frontier", tag fp-storage = { git = "https://github.com/humanode-network/frontier", tag = "locked/polkadot-v0.9.42-2025-02-08", default-features = false } pallet-ethereum = { git = "https://github.com/humanode-network/frontier", tag = "locked/polkadot-v0.9.42-2025-02-08", default-features = false } pallet-evm = { git = "https://github.com/humanode-network/frontier", tag = "locked/polkadot-v0.9.42-2025-02-08", default-features = false } -pallet-evm-balances = { git = "https://github.com/humanode-network/frontier", tag = "locked/polkadot-v0.9.42-2025-02-08", default-features = false } pallet-evm-precompile-blake2 = { git = "https://github.com/humanode-network/frontier", tag = "locked/polkadot-v0.9.42-2025-02-08", default-features = false } pallet-evm-precompile-bn128 = { git = "https://github.com/humanode-network/frontier", tag = "locked/polkadot-v0.9.42-2025-02-08", default-features = false } pallet-evm-precompile-modexp = { git = "https://github.com/humanode-network/frontier", tag = "locked/polkadot-v0.9.42-2025-02-08", default-features = false } pallet-evm-precompile-sha3fips = { git = "https://github.com/humanode-network/frontier", tag = "locked/polkadot-v0.9.42-2025-02-08", default-features = false } pallet-evm-precompile-simple = { git = "https://github.com/humanode-network/frontier", tag = "locked/polkadot-v0.9.42-2025-02-08", default-features = false } -pallet-evm-system = { git = "https://github.com/humanode-network/frontier", tag = "locked/polkadot-v0.9.42-2025-02-08", default-features = false } pallet-evm-test-vector-support = { git = "https://github.com/humanode-network/frontier", tag = "locked/polkadot-v0.9.42-2025-02-08", default-features = false } [profile.release] diff --git a/crates/humanode-runtime/Cargo.toml b/crates/humanode-runtime/Cargo.toml index 311c31f55..1e4c8083e 100644 --- a/crates/humanode-runtime/Cargo.toml +++ b/crates/humanode-runtime/Cargo.toml @@ -27,6 +27,8 @@ pallet-dummy-precompiles-code = { path = "../pallet-dummy-precompiles-code", def pallet-erc20-support = { path = "../pallet-erc20-support", default-features = false } pallet-ethereum-chain-id = { path = "../pallet-ethereum-chain-id", default-features = false } pallet-evm-accounts-mapping = { path = "../pallet-evm-accounts-mapping", default-features = false } +pallet-evm-balances = { path = "../pallet-evm-balances", default-features = false } +pallet-evm-system = { path = "../pallet-evm-system", default-features = false } pallet-humanode-offences = { path = "../pallet-humanode-offences", default-features = false } pallet-humanode-session = { path = "../pallet-humanode-session", default-features = false } pallet-pot = { path = "../pallet-pot", default-features = false } @@ -64,13 +66,11 @@ pallet-babe = { workspace = true } pallet-balances = { workspace = true } pallet-ethereum = { workspace = true } pallet-evm = { workspace = true } -pallet-evm-balances = { workspace = true } pallet-evm-precompile-blake2 = { workspace = true } pallet-evm-precompile-bn128 = { workspace = true } pallet-evm-precompile-modexp = { workspace = true } pallet-evm-precompile-sha3fips = { workspace = true } pallet-evm-precompile-simple = { workspace = true } -pallet-evm-system = { workspace = true } pallet-grandpa = { workspace = true } pallet-im-online = { workspace = true } pallet-multisig = { workspace = true } diff --git a/crates/pallet-currency-swap/Cargo.toml b/crates/pallet-currency-swap/Cargo.toml index 41fc9a231..8849f6006 100644 --- a/crates/pallet-currency-swap/Cargo.toml +++ b/crates/pallet-currency-swap/Cargo.toml @@ -16,10 +16,11 @@ sp-runtime = { workspace = true } sp-std = { workspace = true } [dev-dependencies] +pallet-evm-balances = { path = "../pallet-evm-balances", features = ["default"] } +pallet-evm-system = { path = "../pallet-evm-system", features = ["default"] } + mockall = { workspace = true } pallet-balances = { workspace = true, features = ["default"] } -pallet-evm-balances = { workspace = true, features = ["default"] } -pallet-evm-system = { workspace = true, features = ["default"] } sp-core = { workspace = true } [features] diff --git a/crates/pallet-dummy-precompiles-code/Cargo.toml b/crates/pallet-dummy-precompiles-code/Cargo.toml index a5fc5ab3d..bbe2b4462 100644 --- a/crates/pallet-dummy-precompiles-code/Cargo.toml +++ b/crates/pallet-dummy-precompiles-code/Cargo.toml @@ -14,11 +14,12 @@ sp-core = { workspace = true } sp-std = { workspace = true } [dev-dependencies] +pallet-evm-balances = { path = "../pallet-evm-balances", features = ["default"] } +pallet-evm-system = { path = "../pallet-evm-system", features = ["default"] } + fp-evm = { workspace = true } hex-literal = { workspace = true } pallet-balances = { workspace = true, features = ["default"] } -pallet-evm-balances = { workspace = true, features = ["default"] } -pallet-evm-system = { workspace = true, features = ["default"] } pallet-timestamp = { workspace = true, features = ["default"] } [features] diff --git a/crates/precompile-currency-swap/Cargo.toml b/crates/precompile-currency-swap/Cargo.toml index 45951c673..a81ea63bf 100644 --- a/crates/precompile-currency-swap/Cargo.toml +++ b/crates/precompile-currency-swap/Cargo.toml @@ -17,13 +17,14 @@ scale-info = { workspace = true, features = ["derive"] } sp-core = { workspace = true } [dev-dependencies] +pallet-evm-balances = { path = "../pallet-evm-balances", features = ["default"] } +pallet-evm-system = { path = "../pallet-evm-system", features = ["default"] } + frame-system = { workspace = true } hex-literal = { workspace = true } mockall = { workspace = true } pallet-balances = { workspace = true, features = ["default"] } pallet-evm = { workspace = true } -pallet-evm-balances = { workspace = true, features = ["default"] } -pallet-evm-system = { workspace = true, features = ["default"] } pallet-timestamp = { workspace = true, features = ["default"] } [features] diff --git a/crates/precompile-native-currency/Cargo.toml b/crates/precompile-native-currency/Cargo.toml index 741e55be6..4b55eb1b1 100644 --- a/crates/precompile-native-currency/Cargo.toml +++ b/crates/precompile-native-currency/Cargo.toml @@ -6,6 +6,7 @@ publish = false [dependencies] pallet-erc20-support = { path = "../pallet-erc20-support", default-features = false } +pallet-evm-balances = { path = "../pallet-evm-balances", default-features = false } precompile-utils = { path = "../precompile-utils", default-features = false } codec = { workspace = true, features = ["derive"] } @@ -13,18 +14,17 @@ fp-evm = { workspace = true } frame-support = { workspace = true } num_enum = { workspace = true } pallet-evm = { workspace = true } -pallet-evm-balances = { workspace = true } scale-info = { workspace = true, features = ["derive"] } sp-core = { workspace = true } [dev-dependencies] +pallet-evm-system = { path = "../pallet-evm-system", features = ["default"] } precompile-utils = { path = "../precompile-utils", features = ["testing"] } frame-system = { workspace = true } hex-literal = { workspace = true } pallet-balances = { workspace = true, features = ["default"] } pallet-evm = { workspace = true } -pallet-evm-system = { workspace = true, features = ["default"] } pallet-timestamp = { workspace = true, features = ["default"] } [features] From 0c81cc9ef73e82186d1349f68f8cfbfdbf7917bc Mon Sep 17 00:00:00 2001 From: Dmitry Lavrenov Date: Sat, 8 Feb 2025 13:04:53 +0300 Subject: [PATCH 17/18] Fix fmt --- crates/pallet-evm-system/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/pallet-evm-system/src/lib.rs b/crates/pallet-evm-system/src/lib.rs index 5531a43ce..172e651c5 100644 --- a/crates/pallet-evm-system/src/lib.rs +++ b/crates/pallet-evm-system/src/lib.rs @@ -144,8 +144,8 @@ impl Pallet { let is_new_account = Account::::mutate_exists(who, |maybe_account| { let is_new_account = maybe_account.is_none(); - let account = maybe_account.get_or_insert_with(Default::default); - // `AtLeast32Bit` is big enough for this overflow to be practically impossible. + let account = maybe_account.get_or_insert_with(Default::default); + // `AtLeast32Bit` is big enough for this overflow to be practically impossible. account.nonce = account.nonce.saturating_add(::Index::one()); is_new_account From d3767c86bae7b2914aac1a77d86239eeb812528a Mon Sep 17 00:00:00 2001 From: Dmitry Lavrenov Date: Sun, 9 Feb 2025 21:12:33 +0300 Subject: [PATCH 18/18] Prettify try_mutate_account_handling_dust usage --- .../pallet-evm-balances/src/impl_currency.rs | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/crates/pallet-evm-balances/src/impl_currency.rs b/crates/pallet-evm-balances/src/impl_currency.rs index aba752018..d1edaf5c4 100644 --- a/crates/pallet-evm-balances/src/impl_currency.rs +++ b/crates/pallet-evm-balances/src/impl_currency.rs @@ -131,23 +131,18 @@ where return (NegativeImbalance::zero(), value); } - let mutate_closure = |account: &mut AccountData<>::Balance>| -> Result< - (Self::NegativeImbalance, Self::Balance), - DispatchError, - > { - // Best value is the most amount we can slash following liveness rules. - let actual = value.min(account.free); - account.free.saturating_reduce(actual); - let remaining = value.saturating_sub(actual); - Ok((NegativeImbalance::new(actual), remaining)) - }; - - match Self::try_mutate_account_handling_dust( + let result = Self::try_mutate_account_handling_dust( who, |account, _is_new| -> Result<(Self::NegativeImbalance, Self::Balance), DispatchError> { - mutate_closure(account) + // Best value is the most amount we can slash following liveness rules. + let actual = value.min(account.free); + account.free.saturating_reduce(actual); + let remaining = value.saturating_sub(actual); + Ok((NegativeImbalance::new(actual), remaining)) }, - ) { + ); + + match result { Ok((imbalance, remaining)) => { Self::deposit_event(Event::Slashed { who: who.clone(),