-
Notifications
You must be signed in to change notification settings - Fork 2.6k
contracts: Add host function tracing #13593
Comments
In solang we implemented this feature in the contract directly (opt-in) via the debug buffer. What are the benefits of emitting this information on the host only? I can see unified format and behavior regardless of the programming language / compiler being used as a plus. But then why not adding it into the debug buffer too, and emitting the debug buffer as structured data JSON (for example), so that it can be parsed by frontend, debuggers and other tools? Emitting valid JSON structure into the debug buffer from the contract is not possible, as it might trap or run out of gas and can't finish the formatting. Downside of doing it on the host is that it's missing information about the contract source code |
I just forgot about the debug buffer to be honest. You are right. We should write the information into the debug buffer instead of using |
Nice will look into this, after I wrap up #13600 |
There is no structure to the debug buffer except that it is UTF-8 encoded. So just adding lines to it is the way to go. |
For contract (language) authors it can be a helpful debugging tool to see which host functions (functions exposed by pallet-contracts) are called with which arguments and what was the result. It is of similar use as the popular
strace
tool on linux.This can be implemented within the
define_env
macro. We should use thelog
create to emit a log line after each host function was called. We do it after because then we can also display the result on the same line. All code is panic free and can't divert. So there is no way that we miss a host function call on error.Example of how it might look in the macro:
We use the
trace
log level and a sub target of contracts. In general, all log levels are compiled into a node (substrate as a library does not supply any features tolog
). At runtimetrace
is disabled by default. Having it disabled/enabled at runtime is fine for our use case. It just adds some code and data to the runtime binary but the expensive string formatting isn't performed.Size conscious runtimes can always supply a feature to
log
in their build to remove those logs.Assign to @pgherveou as soon as he is added to paritytech.
cc @xermicus @cmichi
The text was updated successfully, but these errors were encountered: