gnolang / gno

Gno: An interpreted, stack-based Go virtual machine to build succinct and composable apps + Gno.land: a blockchain for timeless code and fair open-source
https://gno.land/
Other
842 stars 343 forks source link

`Machine.String()` hangs the VM on error when printing large structure #1981

Closed jefft0 closed 1 day ago

jefft0 commented 2 months ago

Description

If a transaction fails, for example running out of gas, the VM prints the state with Machine.String() . If the state has a large recursive structure, like an avl.Tree(), this can hang the VM as it constructs the string. Please see the analysis here.

Your environment

Steps to reproduce

Please see PR #1736 which has a txtar to reproduce the bug and has analysis of the root cause.

Expected behaviour

On error, the VM should print a useful error message.

Actual behaviour

The VM attempts to dump the entire machine state, even if there is a large recursive data structure.

Proposed solution

This comment proposes to "switch from doing Machine.String() to printing a stacktrace. (This is likely to be more useful and parseable information by the programmer anyway.)"

petar-dambovaliev commented 2 months ago

I agree with the solution from @thehowl. Since he is working on it already, i'll take this opportunity to improve the String() method on the Machine struct because it looks very rugged.

thehowl commented 1 month ago

@petar-dambovaliev BTW I haven't taken up on it, I troubleshot the issue because I was pointed at it, but the actual implementation of the stacktraces will take quite some work

You're welcome to take up on this if you want to

jefft0 commented 1 month ago

In a dev call, it was suggested that https://github.com/gnolang/gno/pull/1994 could fix this issue. It does not. The test still hangs in the txtar of https://github.com/gnolang/gno/pull/1736 .

jefft0 commented 1 day ago

Closing this tracking issue to focus on the PR with the txtar that demonstrates the bug. https://github.com/gnolang/gno/pull/1736