Skip to content

Commit bc26308

Browse files
Fix benchmark code
1 parent 93bf186 commit bc26308

File tree

2 files changed

+48
-40
lines changed

2 files changed

+48
-40
lines changed

substrate/frame/revive/src/benchmarking.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::{
2424
block_hash::EthereumBlockBuilder, block_storage, TransactionLegacyUnsigned,
2525
TransactionSigned, TransactionUnsigned,
2626
},
27-
exec::{Key, PrecompileExt},
27+
exec::{Key, Origin as ExecOrigin, PrecompileExt},
2828
limits,
2929
precompiles::{
3030
self,
@@ -1229,14 +1229,31 @@ mod benchmarks {
12291229

12301230
T::Currency::set_balance(&instance.account_id, Pallet::<T>::min_balance() * 10u32.into());
12311231

1232+
let mut transaction_meter = TransactionMeter::new(TransactionLimits::WeightAndDeposit {
1233+
weight_limit: Default::default(),
1234+
deposit_limit: BalanceOf::<T>::max_value(),
1235+
})
1236+
.unwrap();
1237+
let exec_config = ExecConfig::new_substrate_tx();
1238+
let contract_account = &instance.account_id;
1239+
let origin = &ExecOrigin::from_account_id(caller);
1240+
let beneficiary_clone = beneficiary.clone();
1241+
let trie_id = instance.info()?.trie_id.clone();
1242+
let code_hash = instance.info()?.code_hash;
1243+
let only_if_same_tx = false;
1244+
12321245
let result;
12331246
#[block]
12341247
{
1235-
result = crate::exec::terminate_contract_for_benchmark::<T>(
1236-
caller,
1237-
&instance.account_id,
1238-
&instance.info()?,
1239-
beneficiary.clone(),
1248+
result = crate::exec::bench_do_terminate::<T>(
1249+
&mut transaction_meter,
1250+
&exec_config,
1251+
contract_account,
1252+
&origin,
1253+
beneficiary_clone,
1254+
trie_id,
1255+
code_hash,
1256+
only_if_same_tx,
12401257
);
12411258
}
12421259
result.unwrap();

substrate/frame/revive/src/exec.rs

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,18 @@ impl<T: Config> Default for CallResources<T> {
249249
}
250250
}
251251

252+
/// Stored inside the `Stack` for each contract that is scheduled for termination.
253+
struct TerminateArgs<T: Config> {
254+
/// Where to send the free balance of the terminated contract.
255+
beneficiary: T::AccountId,
256+
/// The storage child trie of the contract that needs to be deleted.
257+
trie_id: TrieId,
258+
/// The code referenced by the contract. Will be deleted if refcount drops to zero.
259+
code_hash: H256,
260+
/// Triggered by the EVM opcode.
261+
only_if_same_tx: bool,
262+
}
263+
252264
/// Environment functions only available to host functions.
253265
pub trait Ext: PrecompileWithInfoExt {
254266
/// Execute code in the current frame.
@@ -2490,44 +2502,23 @@ pub fn is_precompile<T: Config, E: Executable<T>>(address: &H160) -> bool {
24902502
}
24912503

24922504
#[cfg(feature = "runtime-benchmarks")]
2493-
pub fn terminate_contract_for_benchmark<T: Config>(
2494-
origin: T::AccountId,
2495-
contract: &T::AccountId,
2496-
info: &ContractInfo<T>,
2505+
pub fn bench_do_terminate<T: Config>(
2506+
transaction_meter: &mut TransactionMeter<T>,
2507+
exec_config: &ExecConfig<T>,
2508+
contract_account: &T::AccountId,
2509+
origin: &Origin<T>,
24972510
beneficiary: T::AccountId,
2498-
) -> Result<(), DispatchError> {
2499-
use crate::TransactionLimits;
2500-
use num_traits::Bounded;
2501-
2502-
let mut transaction_meter = TransactionMeter::new(TransactionLimits::WeightAndDeposit {
2503-
weight_limit: Default::default(),
2504-
deposit_limit: BalanceOf::<T>::max_value(),
2505-
})
2506-
.unwrap();
2507-
Stack::<T, crate::ContractBlob<T>>::do_terminate(
2508-
&mut transaction_meter,
2509-
&ExecConfig::new_substrate_tx(),
2510-
contract,
2511-
&Origin::from_account_id(origin),
2512-
&TerminateArgs {
2513-
beneficiary,
2514-
trie_id: info.trie_id.clone(),
2515-
code_hash: info.code_hash,
2516-
only_if_same_tx: false,
2517-
},
2518-
)
2519-
}
2520-
2521-
/// Stored inside the `Stack` for each contract that is scheduled for termination.
2522-
struct TerminateArgs<T: Config> {
2523-
/// Where to send the free balance of the terminated contract.
2524-
beneficiary: T::AccountId,
2525-
/// The storage child trie of the contract that needs to be deleted.
25262511
trie_id: TrieId,
2527-
/// The code referenced by the contract. Will be deleted if refcount drops to zero.
25282512
code_hash: H256,
2529-
/// Triggered by the EVM opcode.
25302513
only_if_same_tx: bool,
2514+
) -> Result<(), DispatchError> {
2515+
Stack::<T, crate::ContractBlob<T>>::do_terminate(
2516+
transaction_meter,
2517+
exec_config,
2518+
contract_account,
2519+
origin,
2520+
&TerminateArgs { beneficiary, trie_id, code_hash, only_if_same_tx },
2521+
)
25312522
}
25322523

25332524
mod sealing {

0 commit comments

Comments
 (0)