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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

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.

examples/gno.land/r/demo/upgradable/admin/logic.gno Outdated Show resolved Hide resolved
@mconcat
Copy link
Author

mconcat commented Nov 24, 2024

Moved to manfred_upgrade_patterns folder!

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.

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: In Progress
Status: In Review
Development

Successfully merging this pull request may close these issues.

7 participants