Skip to content

Commit

Permalink
Debug
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulksnv committed Dec 10, 2023
1 parent 06922dc commit 801ffdd
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions frame/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ targets = ["x86_64-unknown-linux-gnu"]
ethereum = { workspace = true, features = ["with-codec"] }
ethereum-types = { workspace = true }
evm = { workspace = true, features = ["with-codec"] }
log = { workspace = true }
scale-codec = { package = "parity-scale-codec", workspace = true }
scale-info = { workspace = true }
# Substrate
Expand Down Expand Up @@ -47,6 +48,7 @@ std = [
"ethereum/std",
"evm/std",
"ethereum-types/std",
"log/std",
"rlp/std",
"scale-codec/std",
"scale-info/std",
Expand Down
51 changes: 45 additions & 6 deletions frame/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,16 @@ pub mod pallet {

impl<T: Config> Pallet<T> {
pub fn transaction_weight(transaction_data: &TransactionData) -> (Option<Weight>, Option<u64>) {
match <T as pallet_evm::Config>::GasWeightMapping::gas_to_weight(
let ret = <T as pallet_evm::Config>::GasWeightMapping::gas_to_weight(
transaction_data.gas_limit.unique_saturated_into(),
true,
) {
);
log::debug!(
target: "evm",
"EthereumPallet::transaction_weight(): gas_limit = {}, weight_limit = {}, proof_size_base_cost = {:?}",
transaction_data.gas_limit, ret.proof_size(), transaction_data.proof_size_base_cost
);
match ret {
weight_limit if weight_limit.proof_size() > 0 => (
Some(weight_limit),
Some(transaction_data.proof_size_base_cost.unwrap_or_default()),
Expand Down Expand Up @@ -723,6 +729,7 @@ impl<T: Config> Pallet<T> {
let is_transactional = true;
let validate = false;


let (
input,
value,
Expand Down Expand Up @@ -785,6 +792,13 @@ impl<T: Config> Pallet<T> {

match action {
ethereum::TransactionAction::Call(target) => {
log::debug!(
target: "evm",
"PalletEthereum::execute()::call: value={}, gas_limit={}, max_fee_per_gas={:?} \
max_priority_fee_per_gas={:?}, nonce={:?}, is_transactional={}, weight_limit={:?}, proof_size_base_cost={:?}",
value, gas_limit, max_fee_per_gas, max_priority_fee_per_gas, nonce,
is_transactional, weight_limit, proof_size_base_cost
);
let res = match T::Runner::call(
from,
target,
Expand All @@ -803,19 +817,35 @@ impl<T: Config> Pallet<T> {
) {
Ok(res) => res,
Err(e) => {
return Err(DispatchErrorWithPostInfo {
let ret = Err(DispatchErrorWithPostInfo {
post_info: PostDispatchInfo {
actual_weight: Some(e.weight),
pays_fee: Pays::Yes,
},
error: e.error.into(),
})
});
log::debug!(
target: "evm",
"PalletEthereum::execute()::call: err = {ret:?}"
);
return ret;
}
};
log::debug!(
target: "evm",
"PalletEthereum::execute()::call: res = {res:?}"
);

Ok((Some(target), None, CallOrCreateInfo::Call(res)))
}
ethereum::TransactionAction::Create => {
log::debug!(
target: "evm",
"PalletEthereum::execute()::create: value={}, gas_limit={}, max_fee_per_gas={:?} \
max_priority_fee_per_gas={:?}, nonce={:?}, is_transactional={}, weight_limit={:?}, proof_size_base_cost={:?}",
value, gas_limit, max_fee_per_gas, max_priority_fee_per_gas, nonce,
is_transactional, weight_limit, proof_size_base_cost
);
let res = match T::Runner::create(
from,
input,
Expand All @@ -833,15 +863,24 @@ impl<T: Config> Pallet<T> {
) {
Ok(res) => res,
Err(e) => {
return Err(DispatchErrorWithPostInfo {
let ret = Err(DispatchErrorWithPostInfo {
post_info: PostDispatchInfo {
actual_weight: Some(e.weight),
pays_fee: Pays::Yes,
},
error: e.error.into(),
})
});
log::debug!(
target: "evm",
"PalletEthereum::execute()::create: err = {ret:?}"
);
return ret;
}
};
log::debug!(
target: "evm",
"PalletEthereum::execute()::create = {res:?}"
);

Ok((None, Some(res.value), CallOrCreateInfo::Create(res)))
}
Expand Down
7 changes: 7 additions & 0 deletions frame/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,8 +796,15 @@ impl<T: Config> GasWeightMapping for FixedGasWeightMapping<T> {
// Apply a gas to proof size ratio based on BlockGasLimit
let ratio = T::GasLimitPovSizeRatio::get();
if ratio > 0 {
let prev = weight.proof_size();
let proof_size = gas.saturating_div(ratio);
*weight.proof_size_mut() = proof_size;
log::debug!(
target: "evm",
"FixedGasWeightMapping::gas_to_weight(): gas = {}, without_base_weight = {}, WeightPerGas = {}, \
ratio = {}, proof_size = {}/{}",
gas, without_base_weight, T::WeightPerGas::get().proof_size(), ratio, prev, weight.proof_size()
);
}

weight
Expand Down

0 comments on commit 801ffdd

Please sign in to comment.