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

Add tracing output for t8n #616

Merged
merged 4 commits into from
Aug 22, 2023
Merged

Add tracing output for t8n #616

merged 4 commits into from
Aug 22, 2023

Conversation

rodiazet
Copy link
Collaborator

@rodiazet rodiazet commented Apr 13, 2023

Add --trace option for evmone-t8n to output traces to specific files compatible with retesteth.

Modify the tracing format to follow closer the specification at EIP-3155: EVM trace specification.

@rodiazet rodiazet force-pushed the t8n-tracing branch 3 times, most recently from 43a4038 to 1ff1bdc Compare April 13, 2023 13:10
@rodiazet rodiazet requested a review from chfast April 13, 2023 13:19
@rodiazet rodiazet marked this pull request as ready for review April 13, 2023 13:41
@rodiazet rodiazet force-pushed the t8n-tracing branch 6 times, most recently from e252e52 to 4c5e4dd Compare April 14, 2023 10:21
@codecov
Copy link

codecov bot commented Apr 14, 2023

Codecov Report

Merging #616 (69bc40f) into master (35f4141) will decrease coverage by 0.02%.
The diff coverage is 100.00%.

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     
Flag Coverage Δ
blockchaintests 63.19% <0.00%> (+0.48%) ⬆️
statetests 74.26% <0.00%> (+0.32%) ⬆️
statetests-silkpre 23.22% <0.00%> (+0.03%) ⬆️
unittests 95.11% <100.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
lib/evmone/tracing.cpp 100.00% <100.00%> (ø)
lib/evmone/vm.cpp 100.00% <100.00%> (ø)
test/unittests/tracing_test.cpp 99.25% <100.00%> (-0.75%) ⬇️

@rodiazet rodiazet force-pushed the t8n-tracing branch 6 times, most recently from b2cb2b5 to 74e9d0d Compare April 14, 2023 14:10
@@ -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
Copy link
Member

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.

Copy link
Collaborator Author

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);
Copy link
Member

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?

Copy link
Collaborator Author

@rodiazet rodiazet Apr 18, 2023

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()));
Copy link
Member

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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 tostd::string` from "native" string.

test/t8n/t8n.cpp Outdated
{
// Remove old tracers
vm.set_option("stdtrace", "no");
auto output_filename =
Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use std::tmpfile().

Copy link
Collaborator Author

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.

Copy link
Member

@chfast chfast left a 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()));
Copy link
Member

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 tostd::string` from "native" string.

@rodiazet
Copy link
Collaborator Author

rodiazet commented Apr 18, 2023

The tracer management seems wrong. Why are you adding multiple standard tracers? You should have one with option to change its output file.

trace flag adds multiple tracers. I wanted to keep the same convention for stdtrace. Do you want to make it differently for stdtrace or add separated flag to handle changing the file? This will require also some additional changes in the Tracer class.

@rodiazet rodiazet force-pushed the t8n-tracing branch 2 times, most recently from c103c66 to 034240f Compare August 7, 2023 15:44
@rodiazet rodiazet linked an issue Aug 7, 2023 that may be closed by this pull request
@rodiazet rodiazet force-pushed the t8n-tracing branch 9 times, most recently from 2828815 to 6c8fa22 Compare August 8, 2023 15:54
{"error":null,"gas":0xf4240,"gasUsed":0x0,"output":""}
)");
}
// TEST_F(tracing, trace_create)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update test.

Copy link
Collaborator Author

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.

};

std::stack<Context> m_contexts;
std::ostream& m_out; ///< Output stream.
std::ostringstream m_buf;
Copy link
Member

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?

Copy link
Collaborator Author

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?

Copy link
Collaborator Author

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

Copy link
Member

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
Copy link
Member

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.

Copy link
Collaborator Author

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;
Copy link
Member

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?

Copy link
Collaborator Author

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) + "-" +
Copy link
Member

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 =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const auto.

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) << '"';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

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;
Copy link
Member

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.

Copy link
Collaborator Author

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.

@rodiazet rodiazet force-pushed the t8n-tracing branch 2 times, most recently from 26c2bc2 to e3a6c70 Compare August 10, 2023 14:05
@rodiazet rodiazet requested a review from chfast August 10, 2023 14:05
@rodiazet rodiazet force-pushed the t8n-tracing branch 2 times, most recently from 96393d5 to f5eecf9 Compare August 22, 2023 09:06
rodiazet and others added 4 commits August 22, 2023 12:28
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>
@chfast chfast merged commit 6608cf3 into master Aug 22, 2023
@chfast chfast deleted the t8n-tracing branch August 22, 2023 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

evm t8n: Support evm trace
3 participants