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

bug(tm2/gnovm): multi-msg call overwrites previous event #2028

Closed
r3v4s opened this issue May 3, 2024 · 1 comment · Fixed by #2030
Closed

bug(tm2/gnovm): multi-msg call overwrites previous event #2028

r3v4s opened this issue May 3, 2024 · 1 comment · Fixed by #2030
Assignees
Labels
🐞 bug Something isn't working investigating This behavior is still being tested out 📦 🤖 gnovm Issues or PRs gnovm related

Comments

@r3v4s
Copy link
Contributor

r3v4s commented May 3, 2024

Bug: multi-msg call overwrites previous event

related pr #1653

Description

event gets overwrite in multi-msg transaction call

Steps to reproduce


deploy first contract

package event2

import (
	"std"
)

func Hello() {
	inner()
	std.Emit("t", "k", "v")
}

func inner() {
	std.Emit("t", "k", "v")
}

deploy second contract

package event

import (
	"std"

	e2 "gno.land/r/demo/event2"
)

func Hello() {
	inner()
	std.Emit("t", "k", "v")
}

func inner() {
	e2.Hello()
	std.Emit("t", "k", "v")
}

func Other() {
	std.Emit("other", "k", "v")
}

call with multi-msg like below (with adena)

await adena.DoContract({
    messages: [{
        "type": "/vm.m_call",
        "value": {
          "caller": "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5",
          "send": "",
          "pkg_path": "gno.land/r/demo/event",
          "func": "Hello",
          "args": []
        }
      },{
        "type": "/vm.m_call",
        "value": {
          "caller": "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5",
          "send": "",
          "pkg_path": "gno.land/r/demo/event",
          "func": "Other",
          "args": []
        }
      }],
    gasFee: 1, 
    gasWanted: 2000000
  });

Expected behaviour

should print each function's events

Actual behaviour

{
  "jsonrpc": "2.0",
  "id": "",
  "result": {
    "height": "43",
    "results": {
      "deliver_tx": [
        {
          "ResponseBase": {
            "Error": null,
            "Data": null,
            "Events": [
              {
                "@type": "/tm.gnoEvent",
                "pkg_path": "gno.land/r/demo/event",
                "type": "other",
                "func": "Other",
                "attrs": [
                  {
                    "key": "k",
                    "value": "v"
                  }
                ]
              },
              {
                "@type": "/tm.gnoEvent",
                "pkg_path": "gno.land/r/demo/event",
                "type": "other",
                "func": "Other",
                "attrs": [
                  {
                    "key": "k",
                    "value": "v"
                  }
                ]
              }
            ],
            "Log": "msg:0,success:true,log:,events:[]\nmsg:1,success:true,log:,events:[]",
            "Info": ""
          },
          "GasWanted": "2000000",
          "GasUsed": "270168"
        }
      ],
      "end_block": {
        "ResponseBase": {
          "Error": null,
          "Data": null,
          "Events": null,
          "Log": "",
          "Info": ""
        },
        "ValidatorUpdates": null,
        "ConsensusParams": null,
        "Events": null
      },
      "begin_block": {
        "ResponseBase": {
          "Error": null,
          "Data": null,
          "Events": null,
          "Log": "",
          "Info": ""
        }
      }
    }
  }
}

number of event looks good, but contents are being over-write by last called function's event

@r3v4s r3v4s added 🐞 bug Something isn't working 📦 🤖 gnovm Issues or PRs gnovm related labels May 3, 2024
@r3v4s r3v4s added help wanted investigating This behavior is still being tested out labels May 3, 2024
@r3v4s r3v4s moved this from Todo to Blocked by / Wishlist / Issues in 🤝🏻 Partner: Onbloc May 3, 2024
@notJoon
Copy link
Member

notJoon commented May 3, 2024

I'll investigate on this weekend

Maybe fixed

@r3v4s r3v4s moved this from Blocked by / Wishlist / Issues to In Review in 🤝🏻 Partner: Onbloc May 3, 2024
@leohhhn leohhhn changed the title bug: multi-msg call overwrites previous event bug(tm2/gnovm): multi-msg call overwrites previous event May 3, 2024
@Kouteki Kouteki moved this from Triage to In Progress in 🧙‍♂️gno.land core team May 10, 2024
@Kouteki Kouteki added this to the 🏗4️⃣ test4.gno.land milestone May 10, 2024
zivkovicmilos pushed a commit that referenced this issue May 24, 2024
Closes #2028 

root cause: `defer` was used inside of loop that handles multi-msg. It
was causing vm to use only last appended event value

---
## AS-IS
```json
{
  "jsonrpc": "2.0",
  "id": "",
  "result": {
    "height": "43",
    "results": {
      "deliver_tx": [
        {
          "ResponseBase": {
            "Error": null,
            "Data": null,
            "Events": [
              {
                "@type": "/tm.gnoEvent",
                "pkg_path": "gno.land/r/demo/event",
                "type": "other",
                "func": "Other",
                "attrs": [
                  {
                    "key": "k",
                    "value": "v"
                  }
                ]
              },
              {
                "@type": "/tm.gnoEvent",
                "pkg_path": "gno.land/r/demo/event",
                "type": "other",
                "func": "Other",
                "attrs": [
                  {
                    "key": "k",
                    "value": "v"
                  }
                ]
              }
            ],
            "Log": "msg:0,success:true,log:,events:[]\nmsg:1,success:true,log:,events:[]",
            "Info": ""
          },
          "GasWanted": "2000000",
          "GasUsed": "270168"
        }
      ],
      "end_block": {
        "ResponseBase": {
          "Error": null,
          "Data": null,
          "Events": null,
          "Log": "",
          "Info": ""
        },
        "ValidatorUpdates": null,
        "ConsensusParams": null,
        "Events": null
      },
      "begin_block": {
        "ResponseBase": {
          "Error": null,
          "Data": null,
          "Events": null,
          "Log": "",
          "Info": ""
        }
      }
    }
  }
}
```
---

## TO-BE (in this PR)
```json
{
  "jsonrpc": "2.0",
  "id": "",
  "result": {
    "height": "6",
    "results": {
      "deliver_tx": [
        {
          "ResponseBase": {
            "Error": null,
            "Data": null,
            "Events": [
              {
                "@type": "/tm.gnoEvent",
                "pkg_path": "gno.land/r/demo/event2",
                "type": "t",
                "func": "inner",
                "attrs": [
                  {
                    "key": "k",
                    "value": "v"
                  }
                ]
              },
              {
                "@type": "/tm.gnoEvent",
                "pkg_path": "gno.land/r/demo/event2",
                "type": "t",
                "func": "Hello",
                "attrs": [
                  {
                    "key": "k",
                    "value": "v"
                  }
                ]
              },
              {
                "@type": "/tm.gnoEvent",
                "pkg_path": "gno.land/r/demo/event",
                "type": "t",
                "func": "inner",
                "attrs": [
                  {
                    "key": "k",
                    "value": "v"
                  }
                ]
              },
              {
                "@type": "/tm.gnoEvent",
                "pkg_path": "gno.land/r/demo/event",
                "type": "t",
                "func": "Hello",
                "attrs": [
                  {
                    "key": "k",
                    "value": "v"
                  }
                ]
              },
              {
                "@type": "/tm.gnoEvent",
                "pkg_path": "gno.land/r/demo/event",
                "type": "other",
                "func": "Other",
                "attrs": [
                  {
                    "key": "k",
                    "value": "v"
                  }
                ]
              }
            ],
            "Log": "msg:0,success:true,log:,events:[{gno.land/r/demo/event2 t inner [{k v}] \u003cnil\u003e} {gno.land/r/demo/event2 t Hello [{k v}] \u003cnil\u003e} {gno.land/r/demo/event t inner [{k v}] \u003cnil\u003e} {gno.land/r/demo/event t Hello [{k v}] \u003cnil\u003e}]\nmsg:1,success:true,log:,events:[{gno.land/r/demo/event2 t inner [{k v}] \u003cnil\u003e} {gno.land/r/demo/event2 t Hello [{k v}] \u003cnil\u003e} {gno.land/r/demo/event t inner [{k v}] \u003cnil\u003e} {gno.land/r/demo/event t Hello [{k v}] \u003cnil\u003e} {gno.land/r/demo/event other Other [{k v}] \u003cnil\u003e}]",
            "Info": ""
          },
          "GasWanted": "2000000",
          "GasUsed": "270168"
        }
      ],
      "end_block": {
        "ResponseBase": {
          "Error": null,
          "Data": null,
          "Events": null,
          "Log": "",
          "Info": ""
        },
        "ValidatorUpdates": null,
        "ConsensusParams": null,
        "Events": null
      },
      "begin_block": {
        "ResponseBase": {
          "Error": null,
          "Data": null,
          "Events": null,
          "Log": "",
          "Info": ""
        }
      }
    }
  }
}
```

FYI, unable to provide any test cases(unit test, integration test or
txtar) due to lack of multi-msg testing.

---




<!-- please provide a detailed description of the changes made in this
pull request. -->

<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>
@github-project-automation github-project-automation bot moved this from In Progress to Done in 🧙‍♂️gno.land core team May 24, 2024
@github-project-automation github-project-automation bot moved this from In Review to Done in 🤝🏻 Partner: Onbloc May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working investigating This behavior is still being tested out 📦 🤖 gnovm Issues or PRs gnovm related
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants