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
3use 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 }
4445
45 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 }
6364
64 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())
modifiedpallets/balances-adapter/src/lib.rsdiffbeforeafterboth
2#![cfg_attr(not(feature = "std"), no_std)]2#![cfg_attr(not(feature = "std"), no_std)]
33
4extern crate alloc;4extern crate alloc;
5use core::ops::Deref;
6
5use frame_support::sp_runtime::DispatchResult;7use frame_support::sp_runtime::DispatchResult;
6pub use pallet::*;8pub use pallet::*;
34 }36 }
35}37}
38
39impl<T: Config> Deref for NativeFungibleHandle<T> {
40 type Target = SubstrateRecorder<T>;
41
42 fn deref(&self) -> &Self::Target {
43 &self.0
44 }
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;
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