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

[chain] Add prev_realm to emitted events #2002

Closed
zivkovicmilos opened this issue Apr 30, 2024 · 1 comment · Fixed by #2160
Closed

[chain] Add prev_realm to emitted events #2002

zivkovicmilos opened this issue Apr 30, 2024 · 1 comment · Fixed by #2160
Assignees
Labels
📦 ⛰️ gno.land Issues or PRs gno.land package related

Comments

@zivkovicmilos
Copy link
Member

Description

This task concerns adding a prev_realm field to the emitted events following #1653.

Copied over from the PR:

@moul:

Consider adding a default field prev_realm to indicate the caller. This helps differentiate it from pkg_path and func, which pertain to the code defining the std.Emit implementation (great). The purpose is similar to assigning assets and bankers to prevRealm instead of origCall or the called contract in synchronous calls.

@notJoon:

For the last third case, it seems that it can be handled by creating a getPrevRealm function, similar to the function name searcher. It can be done in a way like this:

// Pseudo code for previous realm name getter
func getPrevRealm(m *gno.Machine, height int) (address string, pkgPath string) {
    var (
        ctx           = m.Context.(ExecContext)
        currentCaller crypto.Bech32Address
        // Keeps track of the number of times currentCaller has changed.
        changes int
    )

    for i := m.NumFrames() - 1; i > 0; i-- {
        fr := m.Frames[i]
        if fr.LastPackage == nil || !fr.LastPackage.IsRealm() {
            continue
        }

        // LastPackage is a realm. Get caller and pkgPath, and compare against
        // current* values.
        caller := fr.LastPackage.GetPkgAddr().Bech32()
        pkgPath := fr.LastPackage.PkgPath
        if caller != currentCaller {
            currentCaller = caller
            changes++
            if changes == height + 1 {
                return string(caller), pkgPath
            }
        }
    }

    // Fallback case: return OrigCaller.
    return string(ctx.OrigCaller), ""
}

receiving height as an argument and returning the (height + 1)th change. I think it would be good to gather people's opinions and include the necessary data.

cc @Kouteki

@r3v4s
Copy link
Contributor

r3v4s commented May 15, 2024

We should also add 'std.GetOrigCaller' to differentiate it.

@r3v4s r3v4s self-assigned this May 15, 2024
@r3v4s r3v4s moved this to Backlog in 🤝🏻 Partner: Onbloc May 15, 2024
@zivkovicmilos zivkovicmilos moved this from Todo to In Progress in 🧙‍♂️gno.land core team May 23, 2024
@thehowl thehowl closed this as completed in 981f3fa Jul 2, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in 🧙‍♂️gno.land core team Jul 2, 2024
@github-project-automation github-project-automation bot moved this from Backlog to Done in 🤝🏻 Partner: Onbloc Jul 2, 2024
gfanton pushed a commit to gfanton/gno that referenced this issue Jul 23, 2024
<!-- please provide a detailed description of the changes made in this
pull request. -->

Closes gnolang#2002

Also related to gnolang#2001 




<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [x] Updated the official documentation or not needed
- [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [x] Added references to related issues and PRs
- [] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 ⛰️ gno.land Issues or PRs gno.land package related
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants