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
841 stars 342 forks source link

Track and identify emitted events #2437

Open jinoosss opened 5 days ago

jinoosss commented 5 days ago

Description

We're planning to introduce a new feature in GnoScan which traces and displays events that occured within a transaction. Below is the preview of the UI.

image

Unfortunately, we've come across an issue in the progress. There isn't a clear way to guarantee (1) the "depth" of each event within the function call stack, and (2) the function from which the event was emitted.

Here’s a simple contract example.

Two functions(EmitEventMain, EmitEventMainWithSub) in a Realm(emit_main) emit the same event "EVENT_MAIN".

PR #2061, was an attempt to provide such a way by adding an index to each event, but was closed due to some concerns.

Are there any suggestions on how we should approach this issue? If not, it seems like it's worth re-exploring the msg_idx idea or something similar.

This event support in GnoScan will be useful for users and developers to track events in-depth, especially for contracts that require connected events, such as DAOs, DEXes, etc.

dongwon8247 commented 5 days ago

@zivkovicmilos @thehowl Can you take a look, please?

thehowl commented 4 days ago

There is an assumption in this OP, and that is that having the information on where the event was called is useful information to begin with. I tend to disagree. If in the event we have information on where an event was emitted, then a consumer of the event will use this information to discriminate between different events.

Personally, I actually think we should remove more functionality from the current event implementation; ie. the Func field, for the same reason I described. A consumer of the event should not have this information, as it can be used to conditionally handle an event, where really only the event pkgpath, type and attributes should be used to make that work. If I'm reorganizing my realm's code and decide to move a function with a different name, or to also emit the event somewhere else, the consumer application should not break because of this.

In light of this, here's what I think:

Does this sound like something which could fit your use case?

notJoon commented 2 hours ago

I agree with that we shouldn't include too much information in std.Emit like @thehowl suggested. However, there's also a need for detailed information to advancing the Gnoscan. But, using the line numbers seems impractical as it wouldn't provide enough context and would require complex tasks like drawing call graphs. Also, we cannot retreive enough state/data from a given blocks.

So instead of showing metadata like previous function or realm through the Emit, what if create a new function like Ethereum's getLog function to send only logging information via RPC, allowing data exchange with tools like tx-indexer?

In this case, I think we can use Emit purely for messages, which allows to remove unneccesary metadata while still being able to utilize this information throught the log. What do you think?

cc @dongwon8247 @jinoosss @r3v4s