-
Notifications
You must be signed in to change notification settings - Fork 293
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
Add tracing output for t8n #616
Conversation
43a4038
to
1ff1bdc
Compare
e252e52
to
4c5e4dd
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #616 +/- ##
==========================================
- Coverage 97.53% 97.51% -0.02%
==========================================
Files 86 86
Lines 8236 8223 -13
==========================================
- Hits 8033 8019 -14
- Misses 203 204 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
|
b2cb2b5
to
74e9d0d
Compare
lib/evmone/tracing.cpp
Outdated
@@ -149,6 +150,60 @@ class InstructionTracer : public Tracer | |||
m_out << std::dec; // Set number formatting to dec, JSON does not support other forms. | |||
} | |||
}; | |||
|
|||
|
|||
class StandardTracer : public InstructionTracer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Standard according to what? Is this matching some other EIP? Please add a description to clarify.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a doc comment
const auto computed_tx_hash = keccak256(rlp::encode(tx)); | ||
const auto computed_tx_hash_str = hex0x(computed_tx_hash); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a refactoring, perhaps merge it separately?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about separated commit within this PR and merge without squashing?
test/t8n/t8n.cpp
Outdated
fs::path(output_dir / ("trace-" + std::to_string(i) + "-" + | ||
computed_tx_hash_str + ".jsonl")); | ||
// Add 'to file' tracer. Casting required by windows build. | ||
vm.set_option("stdtrace", (const char*)(output_filename.c_str())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to this c_str
returns const char*
so no need to typecast?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately this is required by MSVC https://app.circleci.com/pipelines/github/ethereum/evmone/4313/workflows/9e36645f-85db-4644-b7e3-1efdef3e6553/jobs/46959
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, you definitely cannot do it like this. You cast wchar_t*
to char* what is totally wrong.
std::pathhas a method to convert to
std::string` from "native" string.
test/t8n/t8n.cpp
Outdated
{ | ||
// Remove old tracers | ||
vm.set_option("stdtrace", "no"); | ||
auto output_filename = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use some tmpfile feature so it gets deleted afterwards?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use std::tmpfile().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This returns a file and opens it. We need only a file name here. Moreover we cannot delete it because retesteth needs to read it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tracer management seems wrong. Why are you adding multiple standard tracers? You should have one with option to change its output file.
test/t8n/t8n.cpp
Outdated
fs::path(output_dir / ("trace-" + std::to_string(i) + "-" + | ||
computed_tx_hash_str + ".jsonl")); | ||
// Add 'to file' tracer. Casting required by windows build. | ||
vm.set_option("stdtrace", (const char*)(output_filename.c_str())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, you definitely cannot do it like this. You cast wchar_t*
to char* what is totally wrong.
std::pathhas a method to convert to
std::string` from "native" string.
|
c103c66
to
034240f
Compare
2828815
to
6c8fa22
Compare
{"error":null,"gas":0xf4240,"gasUsed":0x0,"output":""} | ||
)"); | ||
} | ||
// TEST_F(tracing, trace_create) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think better to remove them. Tracing return empty string now.
lib/evmone/tracing.cpp
Outdated
}; | ||
|
||
std::stack<Context> m_contexts; | ||
std::ostream& m_out; ///< Output stream. | ||
std::ostringstream m_buf; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This improved performance ~2x but I'm not sure if this is the best option. Maybe there is an option to tune clog
itself. I'm thinking of omitting this change for now.
@gumb0 do you have any hints about iostream performance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chfast What are we going to do with this? Omitting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We change the default clog
buffer to std::ofstream
in t8n
implementation to redirect the output to file (to satisfy retesteth requirements). No sure then how the suggested change with clog
tuning will work here. We probably would have to tune std::ofstream
buffer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, omit this change for now.
test/t8n/t8n.cpp
Outdated
@@ -156,6 +176,9 @@ int main(int argc, const char* argv[]) | |||
transactions.emplace_back(std::move(tx)); | |||
receipts.emplace_back(std::move(receipt)); | |||
} | |||
// Set original std::clob buffer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo.
Also this is not exception safe and probably not needed. I'd go with just leaving a comment when rdbuf is modified that we will not restore the original.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When don't do it the program is crashing randomly.
if (holds_alternative<std::error_code>(res)) | ||
{ | ||
const auto ec = std::get<std::error_code>(res); | ||
json::json j_rejected_tx; | ||
j_rejected_tx["hash"] = hex0x(computed_tx_hash); | ||
j_rejected_tx["hash"] = computed_tx_hash_str; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should go to prev commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
test/t8n/t8n.cpp
Outdated
if (tracing_enabled) | ||
{ | ||
auto output_filename = | ||
fs::path(output_dir / ("trace-" + std::to_string(i) + "-" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need fs::path
explicitly as operator /
produces a path.
test/t8n/t8n.cpp
Outdated
const auto tmp_clog_buf = std::clog.rdbuf(); | ||
if (tracing_enabled) | ||
{ | ||
auto output_filename = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const auto
.
lib/evmone/tracing.cpp
Outdated
const auto& ctx = m_contexts.top(); | ||
output_stack(stack_top, stack_height); | ||
if (!state.return_data.empty()) | ||
m_buf << R"("returnData":"0x)" << evmc::hex(state.return_data) << '"'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m_buf << R"("returnData":"0x)" << evmc::hex(state.return_data) << '"'; | |
m_buf << R"(,"returnData":"0x)" << evmc::hex(state.return_data) << '"'; |
This line is not covered by tests and in the same time there is a bug in JSON syntax.
lib/evmone/tracing.cpp
Outdated
if (!state.return_data.empty()) | ||
m_buf << R"("returnData":"0x)" << evmc::hex(state.return_data) << '"'; | ||
m_buf << R"(,"depth":)" << std::dec << (ctx.depth + 1); | ||
m_buf << R"(,"refund":)" << std::dec << state.gas_refund; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
goevmlab complains about this because the value can go negative, not sure what they expect to get, but they try to fit it into uint64
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This field is required be retesteth
for every test as far as I understand.
26c2bc2
to
e3a6c70
Compare
96393d5
to
f5eecf9
Compare
Modify the tracing format to follow closer the specification at EIP-3155: EVM trace specification. Co-authored-by: Paweł Bylica <pawel@ethereum.org>
Co-authored-by: Paweł Bylica <pawel@ethereum.org>
Co-authored-by: Paweł Bylica <pawel@ethereum.org>
Add --trace command line option for evmone-t8n and output the trace to a file named by the transaction hash. Co-authored-by: Paweł Bylica <pawel@ethereum.org>
Add
--trace
option forevmone-t8n
to output traces to specific files compatible withretesteth
.Modify the tracing format to follow closer the specification at EIP-3155: EVM trace specification.