git.delta.rocks / unique-network / refs/commits / 3293186a48b2

difftreelog

fix eth weights

Trubnikov Sergey2023-05-02parent: #12dc7eb.patch.diff
in: master

3 files changed

modifiedpallets/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())
modifiedpallets/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;
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
153 &self,153 &self,
154 reads: u64,154 reads: u64,
155 ) -> pallet_evm_coder_substrate::execution::Result<()> {155 ) -> pallet_evm_coder_substrate::execution::Result<()> {
156 self.recorder156 consume_store_reads(self.recorder(), reads)
157 .consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_parts(
158 <T as frame_system::Config>::DbWeight::get()
159 .read
160 .saturating_mul(reads),
161 // TODO: measure proof
162 0,
163 )))
164 }157 }
165158
166 /// Consume gas for writing.159 /// Consume gas for writing.
167 pub fn consume_store_writes(160 pub fn consume_store_writes(
168 &self,161 &self,
169 writes: u64,162 writes: u64,
170 ) -> pallet_evm_coder_substrate::execution::Result<()> {163 ) -> pallet_evm_coder_substrate::execution::Result<()> {
171 self.recorder164 consume_store_writes(self.recorder(), writes)
172 .consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_parts(
173 <T as frame_system::Config>::DbWeight::get()
174 .write
175 .saturating_mul(writes),
176 // TODO: measure proof
177 0,
178 )))
179 }165 }
180166
181 /// Consume gas for reading and writing.167 /// Consume gas for reading and writing.
184 reads: u64,170 reads: u64,
185 writes: u64,171 writes: u64,
186 ) -> pallet_evm_coder_substrate::execution::Result<()> {172 ) -> pallet_evm_coder_substrate::execution::Result<()> {
187 let weight = <T as frame_system::Config>::DbWeight::get();
188 let reads = weight.read.saturating_mul(reads);
189 let writes = weight.read.saturating_mul(writes);
190 self.recorder173 consume_store_reads_and_writes(self.recorder(), reads, writes)
191 .consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_parts(
192 reads.saturating_add(writes),
193 // TODO: measure proof
194 0,
195 )))
196 }174 }
197175
198 /// Save collection to storage.176 /// Save collection to storage.
2346 }2324 }
2347}2325}
2326
2327/// Consume gas for reading.
2328pub fn consume_store_reads<T: Config>(
2329 recorder: &SubstrateRecorder<T>,
2330 reads: u64,
2331) -> pallet_evm_coder_substrate::execution::Result<()> {
2332 recorder.consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_parts(
2333 <T as frame_system::Config>::DbWeight::get()
2334 .read
2335 .saturating_mul(reads),
2336 // TODO: measure proof
2337 0,
2338 )))
2339}
2340
2341/// Consume gas for writing.
2342pub fn consume_store_writes<T: Config>(
2343 recorder: &SubstrateRecorder<T>,
2344 writes: u64,
2345) -> pallet_evm_coder_substrate::execution::Result<()> {
2346 recorder.consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_parts(
2347 <T as frame_system::Config>::DbWeight::get()
2348 .write
2349 .saturating_mul(writes),
2350 // TODO: measure proof
2351 0,
2352 )))
2353}
2354
2355/// Consume gas for reading and writing.
2356pub fn consume_store_reads_and_writes<T: Config>(
2357 recorder: &SubstrateRecorder<T>,
2358 reads: u64,
2359 writes: u64,
2360) -> pallet_evm_coder_substrate::execution::Result<()> {
2361 let weight = <T as frame_system::Config>::DbWeight::get();
2362 let reads = weight.read.saturating_mul(reads);
2363 let writes = weight.read.saturating_mul(writes);
2364 recorder.consume_gas(T::GasWeightMapping::weight_to_gas(Weight::from_parts(
2365 reads.saturating_add(writes),
2366 // TODO: measure proof
2367 0,
2368 )))
2369}
23482370