Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpcdaeomon: static call in gas cost for debug API endpoints #2167

Merged
merged 4 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/rpc-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
rm -rf ./mainnet/results/

# Run RPC integration test runner via http
python3 ./run_tests.py --continue --blockchain mainnet --jwt ${{runner.workspace}}/silkworm/build/cmd/jwt.hex --display-only-fail --port 8545 -x admin_,eth_mining,eth_getWork,eth_coinbase,eth_createAccessList/test_16.json,engine_,net_,web3_,txpool_,eth_submitWork,eth_submitHashrate,eth_protocolVersion,erigon_nodeInfo --transport_type http,websocket
python3 ./run_tests.py --continue --blockchain mainnet --jwt ${{runner.workspace}}/silkworm/build/cmd/jwt.hex --display-only-fail --port 8545 -x admin_,eth_mining,eth_getWork,eth_coinbase,eth_createAccessList/test_16.json,engine_,net_,web3_,txpool_,eth_submitWork,eth_submitHashrate,eth_protocolVersion,erigon_nodeInfo,debug_trace --transport_type http,websocket

# Capture test runner script exit status
test_exit_status=$?
Expand Down
24 changes: 9 additions & 15 deletions silkworm/rpc/core/evm_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,38 +157,33 @@ void DebugTracer::on_instruction_start(uint32_t pc, const intx::uint256* stack_t

if (!logs_.empty()) {
auto& log = logs_[logs_.size() - 1];
const auto depth = log.depth;
if (depth == execution_state.msg->depth + 1) {
if (gas_on_precompiled_) {
log.gas_cost = log.gas - gas_on_precompiled_;
gas_on_precompiled_ = 0;
} else {
log.gas_cost = log.gas - gas;
}
} else if (depth == execution_state.msg->depth) {
log.gas_cost = log.gas - gas;
}
if (call_fixes_) {
if (call_fixes_) { // previuos opcodw was a CALL*
if (execution_state.msg->depth == call_fixes_->depth) {
if (call_fixes_->gas_cost) {
log.gas_cost = call_fixes_->gas_cost;
} else {
log.gas_cost = log.gas_cost + call_fixes_->stipend;
log.gas_cost = log.gas - gas + call_fixes_->stipend;
}
} else {
log.gas_cost = gas + call_fixes_->stipend + call_fixes_->code_cost;
}

call_fixes_.reset();
} else {
const auto depth = log.depth;
if (depth == execution_state.msg->depth + 1 || depth == execution_state.msg->depth) {
log.gas_cost = log.gas - gas;
}
}
}

if (logs_.size() > 1) {
auto& log = logs_.front();
write_log(log);
logs_.erase(logs_.begin());
}

if (opcode == OP_CALL || opcode == OP_CALLCODE || opcode == OP_DELEGATECALL || opcode == OP_CREATE || opcode == OP_CREATE2) {
if (opcode == OP_CALL || opcode == OP_CALLCODE || opcode == OP_STATICCALL || opcode == OP_DELEGATECALL || opcode == OP_CREATE || opcode == OP_CREATE2) {
call_fixes_ = std::make_unique<CallFixes>(CallFixes{execution_state.msg->depth, 0, metrics_[opcode].gas_cost});
if (opcode == OP_CALL && stack_height >= 7 && stack_top[-2] != 0) {
call_fixes_->stipend = 2300; // for CALLs with value, include stipend
Expand Down Expand Up @@ -226,7 +221,6 @@ void DebugTracer::on_precompiled_run(const evmc_result& result, int64_t gas, con
<< " status: " << result.status_code
<< ", gas: " << std::dec << gas;

gas_on_precompiled_ = gas;
if (call_fixes_) {
call_fixes_->gas_cost = gas + call_fixes_->code_cost;
}
Expand Down
1 change: 0 additions & 1 deletion silkworm/rpc/core/evm_debug.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ class DebugTracer : public EvmTracer {
const char* const* opcode_names_ = nullptr;
const evmc_instruction_metrics* metrics_ = nullptr;
std::stack<std::int64_t> start_gas_;
std::int64_t gas_on_precompiled_{0};
std::unique_ptr<CallFixes> call_fixes_;
};

Expand Down
Loading