Skip to content

Commit

Permalink
Refactor tracers notification in EVM::call
Browse files Browse the repository at this point in the history
  • Loading branch information
elmato committed Feb 29, 2024
1 parent 50b724d commit 0fe3520
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions silkworm/core/execution/evm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,24 @@ evmc::Result EVM::call(const evmc_message& message) noexcept {

const evmc_revision rev{revision()};

if (precompile::is_precompile(message.code_address, rev)) {
bool should_notify_tracers = true;
bool is_precompile = precompile::is_precompile(message.code_address, rev);

auto notify_tracers = gsl::finally([&] {
if(should_notify_tracers) {
// Explicitly notify registered tracers (if any)
for (auto tracer : tracers_) {
const ByteView code{}; // precompile code is empty.
tracer.get().on_execution_start(rev, message, {});
if(is_precompile) {
tracer.get().on_precompiled_run(res.raw(), message.gas, state_);
}
tracer.get().on_execution_end(res.raw(),state_);
}
}
});

if (is_precompile) {
static_assert(std::size(precompile::kContracts) < 256);
const uint8_t num{message.code_address.bytes[kAddressLength - 1]};
const precompile::Contract& contract{precompile::kContracts[num]->contract};
Expand All @@ -246,26 +263,16 @@ evmc::Result EVM::call(const evmc_message& message) noexcept {
res.status_code = EVMC_PRECOMPILE_FAILURE;
}
}
// Explicitly notify registered tracers (if any)
for (auto tracer : tracers_) {
const ByteView code{}; // precompile code is empty.
tracer.get().on_execution_start(rev, message, code);
tracer.get().on_precompiled_run(res.raw(), message.gas, state_);
tracer.get().on_execution_end(res.raw(),state_);
}
} else {

if(eos_evm_version_ > 0 && message.depth == 0 && state_.is_dead(message.recipient)) {
if ((res.gas_left -= static_cast<int64_t>(gas_params_.G_txnewaccount)) < 0)
res.status_code = EVMC_OUT_OF_GAS;
}

if(res.status_code == EVMC_SUCCESS) {
const ByteView code{state_.get_code(message.code_address)};
if (code.empty() && tracers_.empty()) { // Do not skip execution if there are any tracers
return res;
}

const ByteView code{state_.get_code(message.code_address)};
if (!code.empty()) {
should_notify_tracers = false;
const evmc::bytes32 code_hash{state_.get_code_hash(message.code_address)};
res = evmc::Result{execute(message, code, &code_hash)};
}
Expand Down

0 comments on commit 0fe3520

Please sign in to comment.