From 9fcc5a6c75da9fe8f1be9dd1ab2da8b5065126d1 Mon Sep 17 00:00:00 2001 From: Ashutosh Varma Date: Tue, 26 Sep 2023 20:29:33 +0530 Subject: [PATCH] feat: apply benchmarks weights & code suggestions --- pallets/unified-accounts/src/benchmarking.rs | 2 +- pallets/unified-accounts/src/lib.rs | 16 +++--- pallets/unified-accounts/src/mock.rs | 4 +- pallets/unified-accounts/src/tests.rs | 4 +- pallets/unified-accounts/src/weights.rs | 54 ++++++++++---------- runtime/local/src/lib.rs | 4 +- runtime/shibuya/src/lib.rs | 4 +- 7 files changed, 44 insertions(+), 44 deletions(-) diff --git a/pallets/unified-accounts/src/benchmarking.rs b/pallets/unified-accounts/src/benchmarking.rs index b86e3ad425..a4291e63c3 100644 --- a/pallets/unified-accounts/src/benchmarking.rs +++ b/pallets/unified-accounts/src/benchmarking.rs @@ -60,7 +60,7 @@ mod benchmarks { fn claim_default_evm_address() { let caller: T::AccountId = whitelisted_caller(); let caller_clone = caller.clone(); - let evm_address = T::DefaultAccountMapping::into_h160(caller.clone()); + let evm_address = T::DefaultNativeToEvm::into_h160(caller.clone()); #[extrinsic_call] _(RawOrigin::Signed(caller)); diff --git a/pallets/unified-accounts/src/lib.rs b/pallets/unified-accounts/src/lib.rs index 102c87c881..c2c53643e8 100644 --- a/pallets/unified-accounts/src/lib.rs +++ b/pallets/unified-accounts/src/lib.rs @@ -111,9 +111,9 @@ pub mod pallet { /// The Currency for managing evm address assets type Currency: Mutate; /// Default evm address to account id conversion - type DefaultAddressMapping: AddressMapping; + type DefaultEvmToNative: AddressMapping; /// Default account id to evm address conversion - type DefaultAccountMapping: AccountMapping; + type DefaultNativeToEvm: AccountMapping; /// EVM chain id type ChainId: Get; /// Weight information for the extrinsics in this module @@ -191,7 +191,7 @@ pub mod pallet { ensure!(evm_address == address, Error::::InvalidSignature); // Check if the default account id already exists for this evm address - let default_account_id = T::DefaultAddressMapping::into_account_id(evm_address.clone()); + let default_account_id = T::DefaultEvmToNative::into_account_id(evm_address.clone()); if frame_system::Pallet::::account_exists(&default_account_id) { // Transfer all the free native balance from old account id to the newly // since this `default_account_id` will no longer be connected to evm address @@ -239,7 +239,7 @@ impl Pallet { Error::::AlreadyMapped ); // get the default evm address - let evm_address = T::DefaultAccountMapping::into_h160(account_id.clone()); + let evm_address = T::DefaultNativeToEvm::into_h160(account_id.clone()); // make sure default address is not already mapped, this should not // happen but for sanity check. ensure!( @@ -332,12 +332,12 @@ impl UnifiedAddressMapper for Pallet { fn to_account_id_or_default(evm_address: &EvmAddress) -> T::AccountId { NativeToEvm::::get(evm_address).unwrap_or_else(|| { // fallback to default account_id - T::DefaultAddressMapping::into_account_id(evm_address.clone()) + T::DefaultEvmToNative::into_account_id(evm_address.clone()) }) } fn to_default_account_id(evm_address: &EvmAddress) -> T::AccountId { - T::DefaultAddressMapping::into_account_id(evm_address.clone()) + T::DefaultEvmToNative::into_account_id(evm_address.clone()) } fn to_h160(account_id: &T::AccountId) -> Option { @@ -347,12 +347,12 @@ impl UnifiedAddressMapper for Pallet { fn to_h160_or_default(account_id: &T::AccountId) -> EvmAddress { EvmToNative::::get(account_id).unwrap_or_else(|| { // fallback to default account_id - T::DefaultAccountMapping::into_h160(account_id.clone()) + T::DefaultNativeToEvm::into_h160(account_id.clone()) }) } fn to_default_h160(account_id: &T::AccountId) -> EvmAddress { - T::DefaultAccountMapping::into_h160(account_id.clone()) + T::DefaultNativeToEvm::into_h160(account_id.clone()) } } diff --git a/pallets/unified-accounts/src/mock.rs b/pallets/unified-accounts/src/mock.rs index 60e81015ff..1b0f4a4851 100644 --- a/pallets/unified-accounts/src/mock.rs +++ b/pallets/unified-accounts/src/mock.rs @@ -155,8 +155,8 @@ parameter_types! { impl pallet_unified_accounts::Config for TestRuntime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; - type DefaultAddressMapping = HashedAddressMapping; - type DefaultAccountMapping = HashedAccountMapping; + type DefaultEvmToNative = HashedAddressMapping; + type DefaultNativeToEvm = HashedAccountMapping; type ChainId = ChainId; type WeightInfo = (); } diff --git a/pallets/unified-accounts/src/tests.rs b/pallets/unified-accounts/src/tests.rs index dfb96efc4e..93dd97937a 100644 --- a/pallets/unified-accounts/src/tests.rs +++ b/pallets/unified-accounts/src/tests.rs @@ -144,7 +144,7 @@ fn account_claim_should_work() { ExtBuilder::default().build().execute_with(|| { let alice_eth = UnifiedAccounts::eth_address(&alice_secret()); // default ss58 account associated with eth address - let alice_eth_old_account = ::DefaultAddressMapping::into_account_id(alice_eth.clone()); + let alice_eth_old_account = ::DefaultEvmToNative::into_account_id(alice_eth.clone()); let signature = get_evm_signature(&ALICE, &alice_secret()); // transfer some funds to alice_eth (H160) @@ -187,7 +187,7 @@ fn account_claim_should_work() { fn account_default_claim_works() { ExtBuilder::default().build().execute_with(|| { let alice_default_evm = - ::DefaultAccountMapping::into_h160(ALICE.into()); + ::DefaultNativeToEvm::into_h160(ALICE.into()); // claim default account assert_ok!(UnifiedAccounts::claim_default_evm_address( diff --git a/pallets/unified-accounts/src/weights.rs b/pallets/unified-accounts/src/weights.rs index c0967f5b8a..81ea31fd29 100644 --- a/pallets/unified-accounts/src/weights.rs +++ b/pallets/unified-accounts/src/weights.rs @@ -20,9 +20,9 @@ //! Autogenerated weights for pallet_unified_accounts //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-09-25, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-09-26, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `Ashutoshs-MacBook-Pro.local`, CPU: `` +//! HOSTNAME: `devserver-01`, CPU: `Intel(R) Xeon(R) E-2236 CPU @ 3.40GHz` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("shibuya-dev"), DB CACHE: 1024 // Executed Command: @@ -37,7 +37,7 @@ // --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 -// --output=./pallets/unified-accounts/src/weights.rs +// --output=./benchmark-results/unified_accounts_weights.rs // --template=./scripts/templates/weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] @@ -57,9 +57,9 @@ pub trait WeightInfo { pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { /// Storage: UnifiedAccounts EvmToNative (r:1 w:1) - /// Proof Skipped: UnifiedAccounts EvmToNative (max_values: None, max_size: None, mode: Measured) + /// Proof: UnifiedAccounts EvmToNative (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) /// Storage: UnifiedAccounts NativeToEvm (r:1 w:1) - /// Proof Skipped: UnifiedAccounts NativeToEvm (max_values: None, max_size: None, mode: Measured) + /// Proof: UnifiedAccounts NativeToEvm (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) /// Storage: EVMChainId ChainId (r:1 w:0) /// Proof: EVMChainId ChainId (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) /// Storage: System BlockHash (r:1 w:0) @@ -69,23 +69,23 @@ impl WeightInfo for SubstrateWeight { fn claim_evm_address() -> Weight { // Proof Size summary in bytes: // Measured: `256` - // Estimated: `3721` - // Minimum execution time: 58_000_000 picoseconds. - Weight::from_parts(59_000_000, 3721) + // Estimated: `3593` + // Minimum execution time: 64_843_000 picoseconds. + Weight::from_parts(65_508_000, 3593) .saturating_add(T::DbWeight::get().reads(5_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } /// Storage: UnifiedAccounts EvmToNative (r:1 w:1) - /// Proof Skipped: UnifiedAccounts EvmToNative (max_values: None, max_size: None, mode: Measured) - /// Storage: UnifiedAccounts NativeToEvm (r:0 w:1) - /// Proof Skipped: UnifiedAccounts NativeToEvm (max_values: None, max_size: None, mode: Measured) + /// Proof: UnifiedAccounts EvmToNative (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) + /// Storage: UnifiedAccounts NativeToEvm (r:1 w:1) + /// Proof: UnifiedAccounts NativeToEvm (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) fn claim_default_evm_address() -> Weight { // Proof Size summary in bytes: // Measured: `42` - // Estimated: `3507` - // Minimum execution time: 14_000_000 picoseconds. - Weight::from_parts(15_000_000, 3507) - .saturating_add(T::DbWeight::get().reads(1_u64)) + // Estimated: `3533` + // Minimum execution time: 16_399_000 picoseconds. + Weight::from_parts(16_806_000, 3533) + .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } } @@ -93,9 +93,9 @@ impl WeightInfo for SubstrateWeight { // For backwards compatibility and tests impl WeightInfo for () { /// Storage: UnifiedAccounts EvmToNative (r:1 w:1) - /// Proof Skipped: UnifiedAccounts EvmToNative (max_values: None, max_size: None, mode: Measured) + /// Proof: UnifiedAccounts EvmToNative (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) /// Storage: UnifiedAccounts NativeToEvm (r:1 w:1) - /// Proof Skipped: UnifiedAccounts NativeToEvm (max_values: None, max_size: None, mode: Measured) + /// Proof: UnifiedAccounts NativeToEvm (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) /// Storage: EVMChainId ChainId (r:1 w:0) /// Proof: EVMChainId ChainId (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) /// Storage: System BlockHash (r:1 w:0) @@ -105,23 +105,23 @@ impl WeightInfo for () { fn claim_evm_address() -> Weight { // Proof Size summary in bytes: // Measured: `256` - // Estimated: `3721` - // Minimum execution time: 58_000_000 picoseconds. - Weight::from_parts(59_000_000, 3721) + // Estimated: `3593` + // Minimum execution time: 64_843_000 picoseconds. + Weight::from_parts(65_508_000, 3593) .saturating_add(RocksDbWeight::get().reads(5_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } /// Storage: UnifiedAccounts EvmToNative (r:1 w:1) - /// Proof Skipped: UnifiedAccounts EvmToNative (max_values: None, max_size: None, mode: Measured) - /// Storage: UnifiedAccounts NativeToEvm (r:0 w:1) - /// Proof Skipped: UnifiedAccounts NativeToEvm (max_values: None, max_size: None, mode: Measured) + /// Proof: UnifiedAccounts EvmToNative (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) + /// Storage: UnifiedAccounts NativeToEvm (r:1 w:1) + /// Proof: UnifiedAccounts NativeToEvm (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) fn claim_default_evm_address() -> Weight { // Proof Size summary in bytes: // Measured: `42` - // Estimated: `3507` - // Minimum execution time: 14_000_000 picoseconds. - Weight::from_parts(15_000_000, 3507) - .saturating_add(RocksDbWeight::get().reads(1_u64)) + // Estimated: `3533` + // Minimum execution time: 16_399_000 picoseconds. + Weight::from_parts(16_806_000, 3533) + .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } } diff --git a/runtime/local/src/lib.rs b/runtime/local/src/lib.rs index 9b3e86ad60..8bc54786ff 100644 --- a/runtime/local/src/lib.rs +++ b/runtime/local/src/lib.rs @@ -447,8 +447,8 @@ impl pallet_utility::Config for Runtime { impl pallet_unified_accounts::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; - type DefaultAddressMapping = pallet_evm::HashedAddressMapping; - type DefaultAccountMapping = HashedAccountMapping; + type DefaultEvmToNative = pallet_evm::HashedAddressMapping; + type DefaultNativeToEvm = HashedAccountMapping; type ChainId = ChainId; type WeightInfo = pallet_unified_accounts::weights::SubstrateWeight; } diff --git a/runtime/shibuya/src/lib.rs b/runtime/shibuya/src/lib.rs index 30092900e7..70ac9fff64 100644 --- a/runtime/shibuya/src/lib.rs +++ b/runtime/shibuya/src/lib.rs @@ -1206,8 +1206,8 @@ impl pallet_xc_asset_config::Config for Runtime { impl pallet_unified_accounts::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; - type DefaultAddressMapping = pallet_evm::HashedAddressMapping; - type DefaultAccountMapping = HashedAccountMapping; + type DefaultEvmToNative = pallet_evm::HashedAddressMapping; + type DefaultNativeToEvm = HashedAccountMapping; type ChainId = EVMChainId; type WeightInfo = pallet_unified_accounts::weights::SubstrateWeight; }