Skip to content

Commit

Permalink
rpcdaemon: debug_traceCall with txIndex (#2659)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sixtysixter authored Jan 23, 2025
1 parent 5dfedae commit d4c52cd
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rpc-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Checkout RPC Tests Repository & Install Requirements
run: |
rm -rf ${{runner.workspace}}/rpc-tests
git -c advice.detachedHead=false clone --depth 1 --branch v1.35.0 https://github.com/erigontech/rpc-tests ${{runner.workspace}}/rpc-tests
git -c advice.detachedHead=false clone --depth 1 --branch v1.36.1 https://github.com/erigontech/rpc-tests ${{runner.workspace}}/rpc-tests
cd ${{runner.workspace}}/rpc-tests
pip3 install -r requirements.txt --break-system-packages
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/run_integration_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ debug_traceBlockByNumber/test_10,\
debug_traceBlockByNumber/test_11,\
debug_traceBlockByNumber/test_12,\
debug_traceBlockByNumber/test_29,\
debug_traceCall/test_16,\
debug_traceCall/test_17,\
debug_traceCall/test_20,\
debug_traceCall/test_21,\
debug_traceTransaction/test_25.json,\
debug_traceTransaction/test_36.json,\
debug_traceTransaction/test_43.json,\
Expand Down
29 changes: 26 additions & 3 deletions silkworm/rpc/core/evm_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,24 @@ void from_json(const nlohmann::json& json, DebugConfig& tc) {
if (json.count("NoRefunds") != 0) {
json.at("NoRefunds").get_to(tc.no_refunds);
}
if (json.count("TxIndex") != 0) {
const auto& json_idx = json.at("TxIndex");
if (json_idx.is_string()) {
tc.tx_index = std::stol(json_idx.get<std::string>(), nullptr, 16);
} else {
tc.tx_index = json_idx.get<uint32_t>();
}
}
}

std::ostream& operator<<(std::ostream& out, const DebugConfig& tc) {
out << "disableStorage: " << std::boolalpha << tc.disable_storage;
out << " disableMemory: " << std::boolalpha << tc.disable_memory;
out << " disableStack: " << std::boolalpha << tc.disable_stack;
out << " NoRefunds: " << std::boolalpha << tc.no_refunds;
if (tc.tx_index) {
out << " TxIndex: " << std::dec << tc.tx_index.value();
}

return out;
}
Expand Down Expand Up @@ -379,13 +390,25 @@ Task<void> DebugExecutor::trace_call(json::Stream& stream, const BlockNumOrHash&
}
rpc::Transaction transaction{call.to_transaction()};

const auto& block = block_with_hash->block;
const auto block_num = block.header.number + 1;
if (config_.tx_index) {
const auto tx_index = static_cast<size_t>(config_.tx_index.value());
if (tx_index > block_with_hash->block.transactions.size()) {
std::ostringstream oss;
oss << "TxIndex " << tx_index << " greater than #tnx in block " << block_num_or_hash;
const Error error{-32000, oss.str()};
stream.write_json_field("error", error);

co_return;
}
}
stream.write_field("result");
stream.open_object();

const auto& block = block_with_hash->block;
const auto block_num = block.header.number + (config_.tx_index ? 0 : 1);
const auto index = config_.tx_index ? config_.tx_index.value() : 0;
// trace_call semantics: we must execute the call from the state at the end of the given block, so we pass block.header.number + 1
co_await execute(stream, storage, block_num, block, transaction, /* index */ 0);
co_await execute(stream, storage, block_num, block, transaction, index);
stream.close_object();

co_return;
Expand Down
1 change: 1 addition & 0 deletions silkworm/rpc/core/evm_debug.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct DebugConfig {
bool disable_memory{false};
bool disable_stack{false};
bool no_refunds{false};
std::optional<int32_t> tx_index;
};

std::string uint256_to_hex(const evmone::uint256& x);
Expand Down

0 comments on commit d4c52cd

Please sign in to comment.