Skip to content

Commit

Permalink
Improve XVM call benchmarking.
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunxw committed Jul 27, 2023
1 parent 3fa315e commit 931117c
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions pallets/xvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,23 +157,25 @@ impl<T: Config> Pallet<T> {
.saturating_sub(WeightInfoOf::<T>::evm_call_overheads());
let gas_limit = U256::from(T::GasWeightMapping::weight_to_gas(weight_limit));

let source = T::AccountMapping::into_h160(source);
let tx = CheckedEthereumTx {
gas_limit,
target: target_decoded,
value,
input: bounded_input,
maybe_access_list: None,
};

// Note the skip execution check should be exactly before `T::EthereumTransact::xvm_transact`
// to benchmark the correct overheads.
if skip_execution {
return Ok(CallInfo {
output: vec![],
used_weight: WeightInfoOf::<T>::evm_call_overheads(),
});
}

let transact_result = T::EthereumTransact::xvm_transact(
T::AccountMapping::into_h160(source),
CheckedEthereumTx {
gas_limit,
target: target_decoded,
value,
input: bounded_input,
maybe_access_list: None,
},
);
let transact_result = T::EthereumTransact::xvm_transact(source, tx);
log::trace!(
target: "xvm::evm_call",
"EVM call result: {:?}", transact_result,
Expand Down Expand Up @@ -225,22 +227,25 @@ impl<T: Config> Pallet<T> {
T::Lookup::lookup(decoded).map_err(|_| error)
}?;

// With overheads, less weight is available.
let weight_limit = context
.weight_limit
.saturating_sub(WeightInfoOf::<T>::wasm_call_overheads());
let value = Default::default();

// Note the skip execution check should be exactly before `pallet_contracts::bare_call`
// to benchmark the correct overheads.
if skip_execution {
return Ok(CallInfo {
output: vec![],
used_weight: WeightInfoOf::<T>::wasm_call_overheads(),
});
}

// With overheads, less weight is available.
let weight_limit = context
.weight_limit
.saturating_sub(WeightInfoOf::<T>::wasm_call_overheads());

let call_result = pallet_contracts::Pallet::<T>::bare_call(
source,
dest,
Default::default(),
value,
weight_limit,
None,
input,
Expand Down

0 comments on commit 931117c

Please sign in to comment.