Skip to content

Commit

Permalink
Adds debug logs to EVM frame (paritytech#6887)
Browse files Browse the repository at this point in the history
  • Loading branch information
crystalin authored Aug 14, 2020
1 parent f16cbc1 commit 0e703a5
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
35 changes: 34 additions & 1 deletion frame/evm/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use codec::{Encode, Decode};
use sp_core::{U256, H256, H160};
use sp_runtime::traits::UniqueSaturatedInto;
use frame_support::traits::Get;
use frame_support::storage::{StorageMap, StorageDoubleMap};
use frame_support::{debug, storage::{StorageMap, StorageDoubleMap}};
use sha3::{Keccak256, Digest};
use evm::backend::{Backend as BackendT, ApplyBackend, Apply};
use crate::{Trait, AccountStorages, AccountCodes, Module, Event};
Expand Down Expand Up @@ -147,6 +147,12 @@ impl<'vicinity, T: Trait> ApplyBackend for Backend<'vicinity, T> {
});

if let Some(code) = code {
debug::debug!(
target: "evm",
"Inserting code ({} bytes) at {:?}",
code.len(),
address
);
AccountCodes::insert(address, code);
}

Expand All @@ -156,8 +162,21 @@ impl<'vicinity, T: Trait> ApplyBackend for Backend<'vicinity, T> {

for (index, value) in storage {
if value == H256::default() {
debug::debug!(
target: "evm",
"Removing storage for {:?} [index: {:?}]",
address,
index
);
AccountStorages::remove(address, index);
} else {
debug::debug!(
target: "evm",
"Updating storage for {:?} [index: {:?}, value: {:?}]",
address,
index,
value
);
AccountStorages::insert(address, index, value);
}
}
Expand All @@ -167,12 +186,26 @@ impl<'vicinity, T: Trait> ApplyBackend for Backend<'vicinity, T> {
}
},
Apply::Delete { address } => {
debug::debug!(
target: "evm",
"Deleting account at {:?}",
address
);
Module::<T>::remove_account(&address)
},
}
}

for log in logs {
debug::trace!(
target: "evm",
"Inserting log for {:?}, topics ({}) {:?}, data ({}): {:?}]",
log.address,
log.topics.len(),
log.topics,
log.data.len(),
log.data
);
Module::<T>::deposit_event(Event::<T>::Log(Log {
address: log.address,
topics: log.topics,
Expand Down
12 changes: 11 additions & 1 deletion frame/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use sp_std::vec::Vec;
use codec::{Encode, Decode};
#[cfg(feature = "std")]
use serde::{Serialize, Deserialize};
use frame_support::{ensure, decl_module, decl_storage, decl_event, decl_error};
use frame_support::{debug, ensure, decl_module, decl_storage, decl_event, decl_error};
use frame_support::weights::{Weight, Pays};
use frame_support::traits::{Currency, ExistenceRequirement, Get};
use frame_support::dispatch::DispatchResultWithPostInfo;
Expand Down Expand Up @@ -617,6 +617,16 @@ impl<T: Trait> Module<T> {

let used_gas = U256::from(executor.used_gas());
let actual_fee = executor.fee(gas_price);
debug::debug!(
target: "evm",
"Execution {:?} [source: {:?}, value: {}, gas_limit: {}, used_gas: {}, actual_fee: {}]",
retv,
source,
value,
gas_limit,
used_gas,
actual_fee
);
executor.deposit(source, total_fee.saturating_sub(actual_fee));

if apply_state {
Expand Down

0 comments on commit 0e703a5

Please sign in to comment.