difftreelog
fix eth weights
in: master
3 files changed
pallets/balances-adapter/src/erc.rsdiffbeforeafterboth--- a/pallets/balances-adapter/src/erc.rs
+++ b/pallets/balances-adapter/src/erc.rs
@@ -3,6 +3,7 @@
use frame_support::traits::{Currency, ExistenceRequirement};
use pallet_balances::WeightInfo;
use pallet_common::{
+ consume_store_reads,
erc::{CommonEvmHandler, CrossAccountId, PrecompileHandle, PrecompileResult},
eth::CrossAddress,
};
@@ -43,7 +44,7 @@
}
fn balance_of(&self, owner: Address) -> Result<U256> {
- // self.consume_store_reads(1)?;
+ consume_store_reads(self, 1)?;
let owner = T::CrossAccountId::from_eth(owner);
let balance = <T as Config>::Currency::free_balance(owner.as_sub());
Ok(balance.into())
@@ -62,7 +63,7 @@
}
fn total_supply(&self) -> Result<U256> {
- // self.consume_store_reads(1)?;
+ consume_store_reads(self, 1)?;
let total = <T as Config>::Currency::total_issuance();
Ok(total.into())
}
@@ -126,7 +127,7 @@
T::AccountId: From<[u8; 32]>,
{
fn balance_of_cross(&self, owner: CrossAddress) -> Result<U256> {
- // self.consume_store_reads(1)?;
+ consume_store_reads(self, 1)?;
let owner = owner.into_sub_cross_account::<T>()?;
let balance = <T as Config>::Currency::free_balance(owner.as_sub());
Ok(balance.into())
pallets/balances-adapter/src/lib.rsdiffbeforeafterboth2#![cfg_attr(not(feature = "std"), no_std)]2#![cfg_attr(not(feature = "std"), no_std)]334extern crate alloc;4extern crate alloc;5use core::ops::Deref;65use frame_support::sp_runtime::DispatchResult;7use frame_support::sp_runtime::DispatchResult;6pub use pallet::*;8pub use pallet::*;34 }36 }35}37}3839impl<T: Config> Deref for NativeFungibleHandle<T> {40 type Target = SubstrateRecorder<T>;4142 fn deref(&self) -> &Self::Target {43 &self.044 }45}36#[frame_support::pallet]46#[frame_support::pallet]37pub mod pallet {47pub mod pallet {38 use alloc::string::String;48 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,
+ )))
+}