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

chore(demo): upgradable realm demo #3147

Closed

Conversation

mconcat
Copy link

@mconcat mconcat commented Nov 18, 2024

Added upgradable realm demo.

  • admin: main entrypoint for users and controller contract for store and logic
  • store: persistent storage layer across migration steps
  • logic: switchable logic implementation
Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests

@github-actions github-actions bot added the 🧾 package/realm Tag used for new Realms or Packages. label Nov 18, 2024
@mconcat mconcat changed the title Upgradable realm demo chore(demo): upgradable realm demo Nov 18, 2024
@dongwon8247
Copy link
Member

It's our initial approach to tackle to the upgradable realm feature. Please have a look. @moul @zivkovicmilos @Kouteki

Copy link

codecov bot commented Nov 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

Copy link
Contributor

@ltzmaxwell ltzmaxwell left a comment

Choose a reason for hiding this comment

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

LGTM. will approve after this implementation integrated with other ones.

@mconcat
Copy link
Author

mconcat commented Nov 24, 2024

Moved to manfred_upgrade_patterns folder!

@Kouteki Kouteki requested review from ltzmaxwell and moul November 24, 2024 10:29
Copy link
Member

@zivkovicmilos zivkovicmilos left a comment

Choose a reason for hiding this comment

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

Clever :)

We should definitely document these approaches in Efficient Gno, they are too valuable to be buried in our code READMEs (@Kouteki @moul)

@@ -0,0 +1,5 @@
module gno.land/r/x/manfred_upgrade_patterns/upgrade_g/admin

require (
Copy link
Member

Choose a reason for hiding this comment

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

Leftover?

Copy link
Member

Choose a reason for hiding this comment

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

gno mod tidy


var store admin.Store = nil

func Init() {
Copy link
Member

Choose a reason for hiding this comment

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

Is this uppercase on purpose?

Copy link
Member

Choose a reason for hiding this comment

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

It needs to be lowercase if this is supposed to be a realm constructor

Copy link
Author

Choose a reason for hiding this comment

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

Not a constructor, meant to be called by the testing code as an emulated deployment

"gno.land/r/x/manfred_upgrade_patterns/upgrade_g/admin"
)

var store admin.Store = nil
Copy link
Member

Choose a reason for hiding this comment

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

Why does store need to be the global, and not an instance of logic?

Copy link
Member

Choose a reason for hiding this comment

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

The main question is why doesn't this store instance live in the logic instance?

Copy link
Author

Choose a reason for hiding this comment

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

The logic is simply a set of functions to be registered to the admin. It is a workaround with interfaces as they are not able to cross the realm boundary. Store, in this case, needs to be accessed by any functions in the realm, entrypoint or not. By having store as a top level variable it could have the similar coding style with having state variables.


var store admin.Store = nil

func Init() {
Copy link
Member

Choose a reason for hiding this comment

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

Same question, why uppercase?


func (s *store) GetCounter() uint64 {
if s != currentStore {
panic("Revoked store")
Copy link
Member

Choose a reason for hiding this comment

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

When is this possible?

Copy link
Author

Choose a reason for hiding this comment

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

The user tries to call the public function in a old version logics without going through the admin interface. In this case, any outer-world call would fail because the prevRealm will return the logic's address, not the admin's. However, the old logics still holds the store reference, thus need to be deprecated when a new store struct is instantiated.

return currentStore
}

func Init() {
Copy link
Member

Choose a reason for hiding this comment

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

👀

std.TestSetRealm(std.NewUserRealm(alice))
std.TestSetOrigCaller(alice) // XXX: should not need this

store.Init()
Copy link
Member

Choose a reason for hiding this comment

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

I understand now, you want to manually trigger the init :)

store.Init()

v1.Init()
urequire.Equal(t, admin.ReadCounter(), uint64(0))
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick, but the order of urequire.Equal is expected, then actual (swap the last 2 values)

- Diamond pattern of admin <-> (multiple version of logics) <-> store
- The admin provides persistent interface for the interaction for the other contracts and users
- The store acts as the persistent storage independent from the migration
= Logics could be replaced, registering the entrypoint functions as function variables to the admin and taking the store access(while revoking the previous one)
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: this is an =, not a -

@mconcat
Copy link
Author

mconcat commented Nov 28, 2024

Run go mod tidy, fix README.md, fix testing, replied to comments

@leohhhn
Copy link
Contributor

leohhhn commented Nov 28, 2024

The x/ folder is for experimentation; you can create your own namespace, or an onbloc namespace in it; no need to keep it under "manfred_upgrade_patterns" :)

Also, please check why the CI is failing.

@thehowl
Copy link
Member

thehowl commented Jan 16, 2025

@mconcat, can you address the latest comment?

@Gno2D2
Copy link
Collaborator

Gno2D2 commented Jan 16, 2025

🛠 PR Checks Summary

🔴 Maintainers must be able to edit this pull request (more info)

Manual Checks (for Reviewers):
  • IGNORE the bot requirements for this PR (force green CI check)
  • The pull request description provides enough details (checked by @thehowl)
Read More

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

✅ Automated Checks (for Contributors):

🔴 Maintainers must be able to edit this pull request (more info)
🟢 Pending initial approval by a review team member, or review from tech-staff

☑️ 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
Automated Checks
Maintainers must be able to edit this pull request (more info)

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 The pull request was created from a fork (head branch repo: gnoswap-labs/gno)

Then

🔴 Requirement not satisfied
└── 🔴 Maintainer can modify this pull request

Pending initial approval by a review team member, or review from tech-staff

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 Not (🔴 Pull request author is a member of the team: tech-staff)

Then

🟢 Requirement satisfied
└── 🟢 If
    ├── 🟢 Condition
    │   └── 🟢 Or
    │       ├── 🟢 At least 1 user(s) of the organization reviewed the pull request (with state "APPROVED")
    │       ├── 🟢 At least 1 user(s) of the team tech-staff reviewed pull request
    │       └── 🔴 This pull request is a draft
    └── 🟢 Then
        └── 🟢 Not (🔴 This label is applied to pull request: review/triage-pending)

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
The pull request description provides enough details

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 Not (🔴 Pull request author is a member of the team: core-contributors)
    └── 🟢 Not (🔴 Pull request author is user: dependabot[bot])

Can be checked by

  • team core-contributors

@thehowl
Copy link
Member

thehowl commented Feb 11, 2025

@mconcat, please re-create this PR from your personal account, so we can merge in master when needed.

Also, please make sure the PR passes the CI. I think in general it's looking good, so if you re-create it and fix it up, it should be merged rather quickly

@thehowl thehowl closed this Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧾 package/realm Tag used for new Realms or Packages.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

9 participants