-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Cross-contract calling: simple debugger #14678
Cross-contract calling: simple debugger #14678
Conversation
I think this is a good idea. One thing that is important to me is that all this debugging code doesn't clutter the production code too much. What I mean by that is that we don't end up with a lot of compile time features and associated types added to I expect that over time you come up with more things you want to add to this debugging interface. Therefore I think we should make sure that we always only have a single feature and associated type. Concretely:
trait Debug: ExecutionObserver + ExecutionTrace + ...
{
} The downside is that all traits need to be implemented but we can just have sensible default implementations. |
In order to provide some reasonable usecase, I prepared an example scenario of cross contract calling and debugged it using drink library (after necessary on-spot enrichments). The code is available on a branch: https://github.com/Cardinal-Cryptography/drink/tree/pallet-breakpoint. In the example we have 3 simple contacts: Note: since it was faster to use call builder pattern in the contracts, I also passed the addresses of After running
The hardest part is to enable arbitrary handler. Why the hardest? Because the handler is invoked by the runtime. And since it is passed as an associated type to the pallet configuration, it must be fixed - we cannot have e.g. generic runtime. The way I chose to solve the problem (and actually there's the only one I know) is to outsource handler via runtime interface to a specially registered externalities extension. That way we can pass to the drink's |
…racts-debugger # Conflicts: # frame/contracts/src/tests.rs
now I'm getting:
after adding the type declaration (previously it was complaining about not including this member). I guess that this kitchen-sink thing is compiled in multiple configurations, but I don't know how to get it right :( at least test passes correctly (at least locally for me 😛 ) |
…racts-debugger # Conflicts: # frame/contracts/Cargo.toml
bot rebase |
Error: Response error (status 404 Not Found):
|
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 you move the tests for the debugging feature to its own sub module of tests? Then we don't have to sprinkle the conditional compilation that much. Basically having:
tests.rs
tests/unsafe_debug.rs
We need approval from CI team then we can merge. |
bot merge |
Description
Motivation
While full, true contract debugging is currently not achievable, we still can try to get some insights from an outside client to the contracts pallet's internals. Since it is the pallet that owns and maintains call stack, we can take an advantage of this direct access.
Intended usage
Target environment/client
Surely, when we work in a full-stack setting (i.e. including node layer), there's no point in introducing breakpoints. In the case of an RPC call, we could try returning some trace, similarly to a debug buffer. However, my intention is to achieve more interactive experience.
Suppose that we own/hold the whole runtime (embedded within externalities) and have direct (synchronous) access to it. Then, we can establish a simple callback-based communication with the contracts pallet. This is exactly the case when working with tools like https://github.com/Cardinal-Cryptography/drink, but also for pallet's unit tests, or even
try-runtime
suite.Workflow
For now, we add just two simple breakpoints: just before and after an
Executable
object is invoked. Hence, we can debug complex multi-contract execution traces. Since the whole runtime is synchronous, naturally the callbacks will stop execution and progress when the handling is done.Plan
In the near future we plan to add more such breakpoints, providing further information, but firstly we want to check the approach and define what things would be useful.
Checklist
A
,B
,C
andD
required)