Skip to content

fix(gnovm): various post interrealm fixes#4192

Merged
jaekwon merged 41 commits intomasterfrom
post_interrealm_fixes
Apr 22, 2025
Merged

fix(gnovm): various post interrealm fixes#4192
jaekwon merged 41 commits intomasterfrom
post_interrealm_fixes

Conversation

@jaekwon
Copy link
Contributor

@jaekwon jaekwon commented Apr 20, 2025

  • When you are MsgAddPackage, nothing is run, but the machine does run for initialization during declarations and init() calls. In this stage of running, CurrentRealm() returns the package path even if you're initing a p package. Which is a little strange but it's a realm for a moment because it's mutating? :) And PreviousRealm() returns g1user, "" because the end user isn't a realm himself.

  • When calling main() or any other function after init it then runs in StageRun, and CurrentRealm() would be g1user and realm path "" while PreviousRealm() would panic, BUT, since MsgCall always crosses into a crossing function, in practice CurrentRealm() becomes the called external realm (e.g. gno.land/r/boards/boardsv1), and PreviousRealm() becomes g1user and "".

When MsgRun runs, during init CurrentRealm() is gno.land/r/g1user/run, but the addr is not hash derived from that path, but instead the g1user is extracted from it, while PreviousRealm() has the same g1user but the realm path is "" indicating the end user (who uses the temporary run-realm but discards it after).

switch m.Stage {
case gno.StageAdd:
switch height {
case crosses:
fr := m.Frames[0]
path := fr.LastPackage.PkgPath
return string(gno.DerivePkgBech32Addr(path)), path
case crosses + 1:
return string(ctx.OriginCaller), ""
default:
m.Panic(typedString("frame not found"))
return "", ""
}
case gno.StageRun:
switch height {
case crosses:
return string(ctx.OriginCaller), ""
default:
m.Panic(typedString("frame not found"))
return "", ""
}
default:
panic("exec kind unspecified")
btw solved it using two different modes for machine .Run(). During package init "add" or any other post-init "run".
2m

  • Machine is either in StageAdd or StageRun state, and its value may determine the behavior of std.CurrentRealm() and std.PreviousRealmI().

@Gno2D2
Copy link
Collaborator

Gno2D2 commented Apr 20, 2025

🛠 PR Checks Summary

All Automated Checks passed. ✅

Manual Checks (for Reviewers):
  • IGNORE the bot requirements for this PR (force green CI check)
  • Determine if infra needs to be updated before merging
Read More

🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers.

✅ Automated Checks (for Contributors):

No automated checks match this pull request.

☑️ Contributor Actions:
  1. Fix any issues flagged by automated checks.
  2. Follow the Contributor Checklist to ensure your PR is ready for review.
    • Add new tests, or document why they are unnecessary.
    • Provide clear examples/screenshots, if necessary.
    • Update documentation, if required.
    • Ensure no breaking changes, or include BREAKING CHANGE notes.
    • Link related issues/PRs, where applicable.
☑️ Reviewer Actions:
  1. Complete manual checks for the PR, including the guidelines and additional checks if applicable.
📚 Resources:
Debug
Manual Checks
**IGNORE** the bot requirements for this PR (force green CI check)

If

🟢 Condition met
└── 🟢 On every pull request

Can be checked by

  • Any user with comment edit permission
Determine if infra needs to be updated before merging

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 Or
        ├── 🔴 A changed file matches this pattern: Dockerfile
        ├── 🟢 A changed file matches this pattern: ^misc/deployments (filename: misc/deployments/test4.gno.land/genesis.json)
        ├── 🔴 A changed file matches this pattern: ^misc/docker-
        ├── 🔴 A changed file matches this pattern: ^.github/workflows/releaser.*\.yml$
        └── 🔴 A changed file matches this pattern: ^.github/workflows/portal-loop\.yml$

Can be checked by

  • team devops

@codecov
Copy link

codecov bot commented Apr 20, 2025

@github-actions github-actions bot added the 📦 ⛰️ gno.land Issues or PRs gno.land package related label Apr 21, 2025
@github-actions github-actions bot added the 🧾 package/realm Tag used for new Realms or Packages. label Apr 21, 2025
Column: 0, // fake column
})
line++
fv := &gno.FuncValue{Name: name, PkgPath: m.Package.PkgPath, Source: fd}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

func A() string {
crossing()

return myrlm.A()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did this work? hmm... should have failed because myrlm.A is crossing so it should have to be called with cross(myrlm.A)().

# | 1 | MsgCall | wallet direct | myrlm.A() | user address |
# | 2 | | | myrlm.B() | user address |
# | 3 | | through /r/foo | myrlm.A() | user address |
# | 4 | | | myrlm.B() | user address |
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if /r/foo calls cross(myrlm.A)() then it should be r/foo...

@Kouteki Kouteki requested review from ltzmaxwell and thehowl April 21, 2025 11:26
@jaekwon jaekwon force-pushed the post_interrealm_fixes branch from e7537ce to 8b73c94 Compare April 21, 2025 12:51
@jaekwon jaekwon merged commit 1de9aab into master Apr 22, 2025
57 of 67 checks passed
@jaekwon jaekwon deleted the post_interrealm_fixes branch April 22, 2025 06:30
jaekwon added a commit that referenced this pull request May 1, 2025
* When you are MsgAddPackage, nothing is run, but the machine does run
for initialization during declarations and init() calls. In this stage
of running, CurrentRealm() returns the *package path* even if you're
initing a p package. Which is a little strange but it's a realm for a
moment because it's mutating? :) And PreviousRealm() returns g1user, ""
because the end user isn't a realm himself.

* When calling main() or any other function after init it then runs in
StageRun, and CurrentRealm() would be g1user and realm path "" while
PreviousRealm() would panic, BUT, since MsgCall always crosses into a
crossing function, in practice CurrentRealm() becomes the called
external realm (e.g. gno.land/r/boards/boardsv1), and PreviousRealm()
becomes g1user and "".

When MsgRun runs, during init CurrentRealm() is gno.land/r/g1user/run,
but the addr is not hash derived from that path, but instead the g1user
is extracted from it, while PreviousRealm() has the same g1user but the
realm path is "" indicating the end user (who uses the temporary
run-realm but discards it after).

https://github.com/gnolang/gno/blob/fcc6e1033139b1707688ef1aa8aebb9861419790/gnovm/stdlibs/std/native.go#L109-L131
btw solved it using two different modes for machine .Run(). During
package init "add" or any other post-init "run".
2m

* Machine is either in StageAdd or StageRun state, and its value may
determine the behavior of std.CurrentRealm() and std.PreviousRealmI().

---------

Co-authored-by: gfanton <8671905+gfanton@users.noreply.github.com>
stefann-01 pushed a commit to stefann-01/gno that referenced this pull request Jul 14, 2025
* When you are MsgAddPackage, nothing is run, but the machine does run
for initialization during declarations and init() calls. In this stage
of running, CurrentRealm() returns the *package path* even if you're
initing a p package. Which is a little strange but it's a realm for a
moment because it's mutating? :) And PreviousRealm() returns g1user, ""
because the end user isn't a realm himself.

* When calling main() or any other function after init it then runs in
StageRun, and CurrentRealm() would be g1user and realm path "" while
PreviousRealm() would panic, BUT, since MsgCall always crosses into a
crossing function, in practice CurrentRealm() becomes the called
external realm (e.g. gno.land/r/boards/boardsv1), and PreviousRealm()
becomes g1user and "".

When MsgRun runs, during init CurrentRealm() is gno.land/r/g1user/run,
but the addr is not hash derived from that path, but instead the g1user
is extracted from it, while PreviousRealm() has the same g1user but the
realm path is "" indicating the end user (who uses the temporary
run-realm but discards it after).

https://github.com/gnolang/gno/blob/fcc6e1033139b1707688ef1aa8aebb9861419790/gnovm/stdlibs/std/native.go#L109-L131
btw solved it using two different modes for machine .Run(). During
package init "add" or any other post-init "run".
2m

* Machine is either in StageAdd or StageRun state, and its value may
determine the behavior of std.CurrentRealm() and std.PreviousRealmI().

---------

Co-authored-by: gfanton <8671905+gfanton@users.noreply.github.com>
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 📦 🤖 gnovm Issues or PRs gnovm related 🧾 package/realm Tag used for new Realms or Packages.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants