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 cad952e
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 7 deletions.
2 changes: 2 additions & 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
2 changes: 2 additions & 0 deletions primitives/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
evm = { workspace = true, features = ["with-codec"] }
log = { workspace = true }
num_enum = { version = "0.6.1", default-features = false }
scale-codec = { package = "parity-scale-codec", workspace = true }
scale-info = { workspace = true }
Expand All @@ -27,6 +28,7 @@ default = ["std"]
std = [
"evm/std",
"evm/with-serde",
"log/std",
"num_enum/std",
"serde/std",
"scale-codec/std",
Expand Down
17 changes: 16 additions & 1 deletion primitives/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,23 @@ impl WeightInfo {
if let (Some(proof_size_usage), Some(proof_size_limit)) =
(self.proof_size_usage, self.proof_size_limit)
{
let proof_size_usage = self.try_consume(cost, proof_size_limit, proof_size_usage)?;
let proof_size_usage = match self.try_consume(cost, proof_size_limit, proof_size_usage) {
Ok(val) => val,
Err(err) => {
log::warn!(
target: "evm",
"try_record_proof_size_or_fail(1): cost={}, proof_size_limit={}, proof_size_usage={}: err={:?}",
cost, proof_size_limit, proof_size_usage, err
);
return Err(err);
}
};
if proof_size_usage > proof_size_limit {
log::warn!(
target: "evm",
"try_record_proof_size_or_fail(2): cost={}, proof_size_limit={}, proof_size_usage={}",
cost, proof_size_limit, proof_size_usage
);
return Err(ExitError::OutOfGas);
}
self.proof_size_usage = Some(proof_size_usage);
Expand Down

0 comments on commit cad952e

Please sign in to comment.