difftreelog
fix eth weights
in: master
3 files changed
pallets/balances-adapter/src/erc.rsdiffbeforeafterboth3use frame_support::traits::{Currency, ExistenceRequirement};3use frame_support::traits::{Currency, ExistenceRequirement};4use pallet_balances::WeightInfo;4use pallet_balances::WeightInfo;5use pallet_common::{5use pallet_common::{6 consume_store_reads,6 erc::{CommonEvmHandler, CrossAccountId, PrecompileHandle, PrecompileResult},7 erc::{CommonEvmHandler, CrossAccountId, PrecompileHandle, PrecompileResult},7 eth::CrossAddress,8 eth::CrossAddress,8};9};43 }44 }444545 fn balance_of(&self, owner: Address) -> Result<U256> {46 fn balance_of(&self, owner: Address) -> Result<U256> {46 // self.consume_store_reads(1)?;47 consume_store_reads(self, 1)?;47 let owner = T::CrossAccountId::from_eth(owner);48 let owner = T::CrossAccountId::from_eth(owner);48 let balance = <T as Config>::Currency::free_balance(owner.as_sub());49 let balance = <T as Config>::Currency::free_balance(owner.as_sub());49 Ok(balance.into())50 Ok(balance.into())62 }63 }636464 fn total_supply(&self) -> Result<U256> {65 fn total_supply(&self) -> Result<U256> {65 // self.consume_store_reads(1)?;66 consume_store_reads(self, 1)?;66 let total = <T as Config>::Currency::total_issuance();67 let total = <T as Config>::Currency::total_issuance();67 Ok(total.into())68 Ok(total.into())68 }69 }126 T::AccountId: From<[u8; 32]>,127 T::AccountId: From<[u8; 32]>,127{128{128 fn balance_of_cross(&self, owner: CrossAddress) -> Result<U256> {129 fn balance_of_cross(&self, owner: CrossAddress) -> Result<U256> {129 // self.consume_store_reads(1)?;130 consume_store_reads(self, 1)?;130 let owner = owner.into_sub_cross_account::<T>()?;131 let owner = owner.into_sub_cross_account::<T>()?;131 let balance = <T as Config>::Currency::free_balance(owner.as_sub());132 let balance = <T as Config>::Currency::free_balance(owner.as_sub());132 Ok(balance.into())133 Ok(balance.into())pallets/balances-adapter/src/lib.rsdiffbeforeafterboth--- a/pallets/balances-adapter/src/lib.rs
+++ b/pallets/balances-adapter/src/lib.rs
@@ -2,6 +2,8 @@
#![cfg_attr(not(feature = "std"), no_std)]
extern crate alloc;
+use core::ops::Deref;
+
use frame_support::sp_runtime::DispatchResult;
pub use pallet::*;
use pallet_evm_coder_substrate::{WithRecorder, SubstrateRecorder};
@@ -33,6 +35,14 @@
self.0
}
}
+
+impl<T: Config> Deref for NativeFungibleHandle<T> {
+ type Target = SubstrateRecorder<T>;
+
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+}
#[frame_support::pallet]
pub mod pallet {
use alloc::string::String;
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -153,14 +153,7 @@
&self,
reads: u64,
) -> pallet_evm_coder_substrate::execution::Result<()> {
- self.recorder
- .consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_parts(
- <T as frame_system::Config>::DbWeight::get()
- .read
- .saturating_mul(reads),
- // TODO: measure proof
- 0,
- )))
+ consume_store_reads(self.recorder(), reads)
}
/// Consume gas for writing.
@@ -168,14 +161,7 @@
&self,
writes: u64,
) -> pallet_evm_coder_substrate::execution::Result<()> {
- self.recorder
- .consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_parts(
- <T as frame_system::Config>::DbWeight::get()
- .write
- .saturating_mul(writes),
- // TODO: measure proof
- 0,
- )))
+ consume_store_writes(self.recorder(), writes)
}
/// Consume gas for reading and writing.
@@ -184,15 +170,7 @@
reads: u64,
writes: u64,
) -> pallet_evm_coder_substrate::execution::Result<()> {
- let weight = <T as frame_system::Config>::DbWeight::get();
- let reads = weight.read.saturating_mul(reads);
- let writes = weight.read.saturating_mul(writes);
- self.recorder
- .consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_parts(
- reads.saturating_add(writes),
- // TODO: measure proof
- 0,
- )))
+ consume_store_reads_and_writes(self.recorder(), reads, writes)
}
/// Save collection to storage.
@@ -2345,3 +2323,47 @@
}
}
}
+
+/// Consume gas for reading.
+pub fn consume_store_reads<T: Config>(
+ recorder: &SubstrateRecorder<T>,
+ reads: u64,
+) -> pallet_evm_coder_substrate::execution::Result<()> {
+ recorder.consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_parts(
+ <T as frame_system::Config>::DbWeight::get()
+ .read
+ .saturating_mul(reads),
+ // TODO: measure proof
+ 0,
+ )))
+}
+
+/// Consume gas for writing.
+pub fn consume_store_writes<T: Config>(
+ recorder: &SubstrateRecorder<T>,
+ writes: u64,
+) -> pallet_evm_coder_substrate::execution::Result<()> {
+ recorder.consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_parts(
+ <T as frame_system::Config>::DbWeight::get()
+ .write
+ .saturating_mul(writes),
+ // TODO: measure proof
+ 0,
+ )))
+}
+
+/// Consume gas for reading and writing.
+pub fn consume_store_reads_and_writes<T: Config>(
+ recorder: &SubstrateRecorder<T>,
+ reads: u64,
+ writes: u64,
+) -> pallet_evm_coder_substrate::execution::Result<()> {
+ let weight = <T as frame_system::Config>::DbWeight::get();
+ let reads = weight.read.saturating_mul(reads);
+ let writes = weight.read.saturating_mul(writes);
+ recorder.consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_parts(
+ reads.saturating_add(writes),
+ // TODO: measure proof
+ 0,
+ )))
+}