Skip to content

Commit d95fa93

Browse files
authored
rpcdaeomon: static call in gas cost for debug API endpoints (#2167)
1 parent af990fc commit d95fa93

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

.github/workflows/rpc-integration-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
rm -rf ./mainnet/results/
6969
7070
# Run RPC integration test runner via http
71-
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
71+
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
7272
7373
# Capture test runner script exit status
7474
test_exit_status=$?

silkworm/rpc/core/evm_debug.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -157,38 +157,33 @@ void DebugTracer::on_instruction_start(uint32_t pc, const intx::uint256* stack_t
157157

158158
if (!logs_.empty()) {
159159
auto& log = logs_[logs_.size() - 1];
160-
const auto depth = log.depth;
161-
if (depth == execution_state.msg->depth + 1) {
162-
if (gas_on_precompiled_) {
163-
log.gas_cost = log.gas - gas_on_precompiled_;
164-
gas_on_precompiled_ = 0;
165-
} else {
166-
log.gas_cost = log.gas - gas;
167-
}
168-
} else if (depth == execution_state.msg->depth) {
169-
log.gas_cost = log.gas - gas;
170-
}
171-
if (call_fixes_) {
160+
if (call_fixes_) { // previuos opcodw was a CALL*
172161
if (execution_state.msg->depth == call_fixes_->depth) {
173162
if (call_fixes_->gas_cost) {
174163
log.gas_cost = call_fixes_->gas_cost;
175164
} else {
176-
log.gas_cost = log.gas_cost + call_fixes_->stipend;
165+
log.gas_cost = log.gas - gas + call_fixes_->stipend;
177166
}
178167
} else {
179168
log.gas_cost = gas + call_fixes_->stipend + call_fixes_->code_cost;
180169
}
181170

182171
call_fixes_.reset();
172+
} else {
173+
const auto depth = log.depth;
174+
if (depth == execution_state.msg->depth + 1 || depth == execution_state.msg->depth) {
175+
log.gas_cost = log.gas - gas;
176+
}
183177
}
184178
}
179+
185180
if (logs_.size() > 1) {
186181
auto& log = logs_.front();
187182
write_log(log);
188183
logs_.erase(logs_.begin());
189184
}
190185

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

229-
gas_on_precompiled_ = gas;
230224
if (call_fixes_) {
231225
call_fixes_->gas_cost = gas + call_fixes_->code_cost;
232226
}

silkworm/rpc/core/evm_debug.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ class DebugTracer : public EvmTracer {
105105
const char* const* opcode_names_ = nullptr;
106106
const evmc_instruction_metrics* metrics_ = nullptr;
107107
std::stack<std::int64_t> start_gas_;
108-
std::int64_t gas_on_precompiled_{0};
109108
std::unique_ptr<CallFixes> call_fixes_;
110109
};
111110

0 commit comments

Comments
 (0)