From 801ffdd4321b66e9efd68de2b5341fe1dd66c044 Mon Sep 17 00:00:00 2001 From: Rahul Subramaniyam Date: Sat, 9 Dec 2023 09:43:31 -0800 Subject: [PATCH] Debug --- Cargo.lock | 1 + frame/ethereum/Cargo.toml | 2 ++ frame/ethereum/src/lib.rs | 51 ++++++++++++++++++++++++++++++++++----- frame/evm/src/lib.rs | 7 ++++++ 4 files changed, 55 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e6b6a90b30..5eb4a18f8b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5819,6 +5819,7 @@ dependencies = [ "frame-system", "hex", "libsecp256k1", + "log", "pallet-balances", "pallet-evm", "pallet-timestamp", diff --git a/frame/ethereum/Cargo.toml b/frame/ethereum/Cargo.toml index 634be1081d..6797ec4e40 100644 --- a/frame/ethereum/Cargo.toml +++ b/frame/ethereum/Cargo.toml @@ -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 @@ -47,6 +48,7 @@ std = [ "ethereum/std", "evm/std", "ethereum-types/std", + "log/std", "rlp/std", "scale-codec/std", "scale-info/std", diff --git a/frame/ethereum/src/lib.rs b/frame/ethereum/src/lib.rs index 9a70b99a20..477d50bbc4 100644 --- a/frame/ethereum/src/lib.rs +++ b/frame/ethereum/src/lib.rs @@ -358,10 +358,16 @@ pub mod pallet { impl Pallet { pub fn transaction_weight(transaction_data: &TransactionData) -> (Option, Option) { - match ::GasWeightMapping::gas_to_weight( + let ret = ::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()), @@ -723,6 +729,7 @@ impl Pallet { let is_transactional = true; let validate = false; + let ( input, value, @@ -785,6 +792,13 @@ impl Pallet { 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, @@ -803,19 +817,35 @@ impl Pallet { ) { 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, @@ -833,15 +863,24 @@ impl Pallet { ) { 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))) } diff --git a/frame/evm/src/lib.rs b/frame/evm/src/lib.rs index 7f6ff34356..b4b38bd55b 100644 --- a/frame/evm/src/lib.rs +++ b/frame/evm/src/lib.rs @@ -796,8 +796,15 @@ impl GasWeightMapping for FixedGasWeightMapping { // 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