Skip to content

Commit cce6cc5

Browse files
Implement general resource metering
1 parent d963d6e commit cce6cc5

File tree

31 files changed

+1002
-561
lines changed

31 files changed

+1002
-561
lines changed

substrate/frame/revive/proc-macro/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,7 @@ fn expand_functions(def: &EnvDef) -> TokenStream2 {
443443

444444
quote! {
445445
// Write gas from polkavm into pallet-revive before entering the host function.
446-
let __gas_left_before__ = self
447-
.ext
446+
self.ext
448447
.gas_meter_mut()
449448
.sync_from_executor(memory.gas())
450449
.map_err(TrapReason::from)?;
@@ -462,7 +461,7 @@ fn expand_functions(def: &EnvDef) -> TokenStream2 {
462461
})();
463462

464463
// Write gas from pallet-revive into polkavm after leaving the host function.
465-
let gas = self.ext.gas_meter_mut().sync_to_executor(__gas_left_before__).map_err(TrapReason::from)?;
464+
let gas = self.ext.gas_meter_mut().sync_to_executor();
466465
memory.set_gas(gas.into());
467466
result
468467
}

substrate/frame/revive/src/call_builder.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,10 @@ where
258258
let outcome = Contracts::<T>::bare_instantiate(
259259
origin,
260260
U256::zero(),
261-
Weight::MAX,
262-
default_deposit_limit::<T>(),
261+
TransactionLimits::WeightAndDeposit {
262+
weight_limit: Weight::MAX,
263+
deposit_limit: default_deposit_limit::<T>(),
264+
},
263265
Code::Upload(module.code),
264266
data,
265267
salt,

substrate/frame/revive/src/evm/call.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::{
2424
};
2525
use codec::DecodeLimit;
2626
use frame_support::MAX_EXTRINSIC_DEPTH;
27-
use sp_core::Get;
27+
use sp_core::{Get, U256};
2828
use sp_runtime::{transaction_validity::InvalidTransaction, FixedPointNumber, SaturatedConversion};
2929

3030
/// Result of decoding an eth transaction into a dispatchable call.
@@ -41,6 +41,8 @@ pub struct CallInfo<T: Config> {
4141
pub tx_fee: BalanceOf<T>,
4242
/// The additional storage deposit to be deposited into the txhold.
4343
pub storage_deposit: BalanceOf<T>,
44+
/// The ethereum gas limit of the transaction.
45+
pub eth_gas_limit: U256,
4446
}
4547

4648
/// Decode `tx` into a dispatchable call.
@@ -114,6 +116,7 @@ where
114116
dest,
115117
value,
116118
weight_limit: Zero::zero(),
119+
eth_gas_limit: gas,
117120
data,
118121
effective_gas_price,
119122
encoded_len,
@@ -135,6 +138,7 @@ where
135138
let call = crate::Call::eth_instantiate_with_code::<T> {
136139
value,
137140
weight_limit: Zero::zero(),
141+
eth_gas_limit: gas,
138142
code,
139143
data,
140144
effective_gas_price,
@@ -186,5 +190,5 @@ where
186190
InvalidTransaction::Payment
187191
})?.saturated_into();
188192

189-
Ok(CallInfo { call, weight_limit, encoded_len, tx_fee, storage_deposit })
193+
Ok(CallInfo { call, weight_limit, encoded_len, tx_fee, storage_deposit, eth_gas_limit: gas })
190194
}

substrate/frame/revive/src/evm/runtime.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ mod test {
514514
value,
515515
data,
516516
weight_limit,
517+
eth_gas_limit,
517518
effective_gas_price,
518519
encoded_len,
519520
}) if dest == tx.to.unwrap() &&
@@ -549,6 +550,7 @@ mod test {
549550
code,
550551
data,
551552
weight_limit,
553+
eth_gas_limit,
552554
effective_gas_price,
553555
encoded_len,
554556
}) if value == expected_value &&

0 commit comments

Comments
 (0)