Skip to content

Commit

Permalink
Adapt for weightv2
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinonard committed Jul 19, 2023
1 parent f750615 commit 01b3f6e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion chain-extensions/xvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#![cfg_attr(not(feature = "std"), no_std)]

use frame_support::{dispatch::Encode, weights::Weight};
use frame_support::dispatch::Encode;
use pallet_contracts::{
chain_extension::{ChainExtension, Environment, Ext, InitState, RetVal},
Origin,
Expand Down
25 changes: 20 additions & 5 deletions pallets/ethereum-checked/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,19 @@ impl<T: Config> Pallet<T> {
let tx = checked_tx.into_ethereum_tx(Nonce::<T>::get(), chain_id);
let tx_data: TransactionData = (&tx).into();

let (weight_limit, proof_size_base_cost) =
match <T as pallet_evm::Config>::GasWeightMapping::gas_to_weight(
tx_data.gas_limit.unique_saturated_into(),
true,
) {
weight_limit if weight_limit.proof_size() > 0 => (
Some(weight_limit),
// measured PoV should be correct to use here
Some(WeightInfoOf::<T>::transact_without_apply().proof_size()),
),
_ => (None, None),
};

// Validate the tx.
let _ = CheckEvmTransaction::<T::InvalidEvmTransactionError>::new(
CheckEvmTransactionConfig {
Expand All @@ -203,10 +216,8 @@ impl<T: Config> Pallet<T> {
is_transactional: true,
},
tx_data.into(),
// TODO: solve this prior to the merge
None,
// TODO: solve this prior to the merge
None,
weight_limit,
proof_size_base_cost,
)
// Gas limit validation. The fee payment has been validated as the tx is `checked`.
.validate_common()
Expand All @@ -233,7 +244,11 @@ impl<T: Config> Pallet<T> {
CallInfo {
exit_reason: ExitReason::Succeed(ExitSucceed::Returned),
value: Default::default(),
used_gas: checked_tx.gas_limit,
used_gas: fp_evm::UsedGas {
standard: checked_tx.gas_limit,
effective: checked_tx.gas_limit,
},
weight_info: None,
logs: Default::default(),
},
));
Expand Down
2 changes: 0 additions & 2 deletions pallets/pallet-xvm/src/pallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ pub mod pallet {

let result = T::SyncVM::xvm_call(context, from, to, input);
let consumed_weight = consumed_weight(&result);
// TODO: solve this before merging the uplift PR - XVM should work with 2D weights!!!
let consumed_weight = Weight::from_parts(consumed_weight, 0);

log::trace!(
target: "xvm::pallet::xvm_call",
Expand Down

0 comments on commit 01b3f6e

Please sign in to comment.