From 6a58f46c94ad2e8a0038e57379babe987a243359 Mon Sep 17 00:00:00 2001 From: Shaun Wang Date: Fri, 13 Oct 2023 01:04:55 +1100 Subject: [PATCH] To H160 DB read. --- chain-extensions/xvm/src/lib.rs | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/chain-extensions/xvm/src/lib.rs b/chain-extensions/xvm/src/lib.rs index ba1ebcedda..e86ea687ce 100644 --- a/chain-extensions/xvm/src/lib.rs +++ b/chain-extensions/xvm/src/lib.rs @@ -25,7 +25,7 @@ use astar_primitives::{ evm::UnifiedAddressMapper, xvm::{Context, VmId, XvmCall}, }; -use frame_support::{dispatch::Encode, weights::Weight}; +use frame_support::{dispatch::Encode, traits::Get, weights::Weight}; use frame_system::RawOrigin; use pallet_contracts::chain_extension::{ ChainExtension, Environment, Ext, InitState, RetVal, ReturnFlags, @@ -97,19 +97,24 @@ where // Claim the default evm address if needed. let mut actual_weight = Weight::zero(); - if value > 0 && UA::to_h160(&source).is_none() { - let weight_of_claim = ::WeightInfo::claim_default_evm_address(); - actual_weight.saturating_accrue(weight_of_claim); - - let claim_result = - pallet_unified_accounts::Pallet::::claim_default_evm_address( - RawOrigin::Signed(source.clone()).into(), - ); - if claim_result.is_err() { - return Ok(RetVal::Diverging { - flags: ReturnFlags::REVERT, - data: format!("{:?}", claim_result.err()).into(), - }); + if value > 0 { + // `UA::to_h160` 1 DB read. + actual_weight.saturating_accrue(T::DbWeight::get().reads(1)); + + if UA::to_h160(&source).is_none() { + let weight_of_claim = ::WeightInfo::claim_default_evm_address(); + actual_weight.saturating_accrue(weight_of_claim); + + let claim_result = + pallet_unified_accounts::Pallet::::claim_default_evm_address( + RawOrigin::Signed(source.clone()).into(), + ); + if claim_result.is_err() { + return Ok(RetVal::Diverging { + flags: ReturnFlags::REVERT, + data: format!("{:?}", claim_result.err()).into(), + }); + } } }