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

refactor: r/demo/users #3166

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

refactor: r/demo/users #3166

wants to merge 219 commits into from

Conversation

leohhhn
Copy link
Contributor

@leohhhn leohhhn commented Nov 20, 2024

Description

Addresses: #2827

This PR refactors the current r/demo/users & r/sys/users system in accordance to the issue mentioned above. Below is the high-level overview of the new system.

It also makes a small change to the p/demo/releases lib.

r/gnoland/users/v1

  • Fully replaces r/demo/users
  • Is the main entry point for users looking to register a name, create an alias (rename themselves), or delete their username
  • Implements allowed username pattern checks as per the issue r/sys/users Mainnet v1 (mvp) & v2 #2827
  • Is pausable by GovDAO, contains no other administration functionality
  • Contains a nice UI/render for users (please suggest improvements) - see bottom
  • Uses r/demo/profile for displaying extra information about a user (to be moved to r/nt/profiles or r/gnoland/profiles)

r/sys/users

  • Namespace check moved to r/sys/names
  • Contains the address/name <> user stores, to which only whitelisted realms can write
  • Contains resolver functions & other useful getters
  • Is callable only by whitelisted realms, such as r/gnoland/users/v1, etc.
  • Whitelist is fully managed by GovDAO (after chore: remove govdao dependency in r/gov/dao/bridge #3523 was resolved)

r/sys/names

  • Namespace checking functionality moved here (from r/sys/users), added tests, as discussed with @moul
  • Verify function now only upgradeable with a GovDAO prop instead of previously being ownable
  • Verify functionality is now not pausable and on by default, as per discussions with @moul. This means Portal Loop will need to be patched upon merging this PR, as many txs will fail due to not having proper namespace permissions. The namespace verify functionality is off by default, but should be enabled in genesis via r/sys/names.Enable(). The Portal Loop will indeed need to be patched if we enable this functionality.

Keeper & genesis params

  • Updated the VM keeper to call r/sys/names for the namespace check instead of r/sys/users
  • Updated params to load r/sys/names, which the keeper will call

r/gnoland/users/v1

Screenshot 2025-01-17 at 01 10 56

r/gnoland/users

Currently this is the "releases" page for the user registration systems (example data):

Screenshot 2025-02-03 at 12 19 28
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 20, 2024
Copy link

codecov bot commented Nov 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@zivkovicmilos zivkovicmilos self-requested a review November 21, 2024 06:03
@leohhhn leohhhn changed the title refactor: r/demo/users refactor: r/demo/users Nov 21, 2024
@github-actions github-actions bot added 📦 🤖 gnovm Issues or PRs gnovm related 📦 🌐 tendermint v2 Issues or PRs tm2 related 📦 ⛰️ gno.land Issues or PRs gno.land package related labels Nov 25, 2024
# Conflicts:
#	examples/gno.land/r/demo/users/users.gno
#	examples/gno.land/r/demo/users/z_10_filetest.gno
#	examples/gno.land/r/demo/users/z_11_filetest.gno
#	examples/gno.land/r/demo/users/z_11b_filetest.gno
#	examples/gno.land/r/demo/users/z_2_filetest.gno
#	examples/gno.land/r/demo/users/z_3_filetest.gno
#	examples/gno.land/r/demo/users/z_4_filetest.gno
#	examples/gno.land/r/demo/users/z_5_filetest.gno
#	examples/gno.land/r/demo/users/z_6_filetest.gno
#	examples/gno.land/r/demo/users/z_7_filetest.gno
#	examples/gno.land/r/demo/users/z_7b_filetest.gno
#	examples/gno.land/r/demo/users/z_8_filetest.gno
#	examples/gno.land/r/demo/users/z_9_filetest.gno
#	examples/gno.land/r/sys/users/verify.gno
Comment on lines 50 to 52
u := *(data.(*UserData))
if u.deleted {
return nil
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
u := *(data.(*UserData))
if u.deleted {
return nil
var u *UserData
*u = *(data.(*UserData))
if u.deleted {
return nil

should be better (please, verify in a test)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

a5a84af -> not good; should be a copy; did you try my snippet above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed it: a5b8f43

Comment on lines 48 to 65
out += md.H2("User list")

p := pager.NewPager(users.GetReadOnlyNameStore(), 20, false)
page := p.MustGetPageByPath(path)
for _, item := range page.Items {
if item.Value == nil {
continue
}

data := item.Value.(*users.UserData)

// Skip previous names
if item.Key != data.Name() {
continue
}

out += ufmt.Sprintf("- User [%s](/r/gnoland/users/v1:%s)\n", md.Bold(item.Key), item.Key)
}
Copy link
Member

Choose a reason for hiding this comment

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

Even though I'm glad you're using this pattern that I was proud of (thank you, @leohhhn), I believe this realm will quickly become unusable because it will contain:

  • aaa000
  • aaa001
  • aaa002
  • etc.

It makes more sense to either print statistics or eventually set up an efficient ring buffer for the last N entries (we don't have a good data structure yet, so let's create a p/ for this :p). In the meantime, just store the last created *UserData entry.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

@moul moul left a comment

Choose a reason for hiding this comment

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

I finally went over with this review; it looks good; ping me when you've addressed the last feedback 👍

@@ -30,7 +30,7 @@ func init() {
// add pre-registered users
for _, res := range preRegisteredUsers {
if err := users.RegisterUser(res.Name, res.Address); err != nil {
panic(err)
Copy link
Member

Choose a reason for hiding this comment

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

_ users.RegisterUser(... seems better than a if { continue }; or maybe keep the if and emit/log something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -3,14 +3,9 @@ package users
import (
"std"

"gno.land/p/demo/users"
"gno.land/r/sys/users"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"gno.land/r/sys/users"
susers "gno.land/r/sys/users"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🌐 tendermint v2 Issues or PRs tm2 related 📦 ⛰️ 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: 📥 Inbox
Status: In Review
Development

Successfully merging this pull request may close these issues.

r/sys/users Mainnet v1 (mvp) & v2
8 participants