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: clean up the params keeper #3105

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

Conversation

zivkovicmilos
Copy link
Member

@zivkovicmilos zivkovicmilos commented Nov 10, 2024

Description

This PR cleans up a bit the params keeper, and starts a discussion on some functionality that seems sketchy. It moves some testing code outside the binary, and into test files.

Additionally, I've updated some parsing methods so they're quicker now, by ~40ns:

goos: darwin
goarch: arm64
pkg: github.com/gnolang/gno/tm2/pkg/sdk/params
cpu: Apple M3 Max
BenchmarkParamsHandler_Query
BenchmarkParamsHandler_Query-14    	15104251	        79.11 ns/op
PASS

Before:

goos: darwin
goarch: arm64
pkg: github.com/gnolang/gno/tm2/pkg/sdk/params
cpu: Apple M3 Max
BenchmarkParamsHandler_Query
BenchmarkParamsHandler_Query-14    	 6789453	       156.6 ns/op
PASS

The keeper could probably be fully made generic, but for the sake of readability, this was not pursued.

cc @gfanton @moul

Topics that need discussing:

Internal funky returns

func (pk ParamsKeeper) getIfExists(ctx sdk.Context, key string, ptr interface{}) {
stor := ctx.Store(pk.key)
bz := stor.Get([]byte(key))
if bz == nil {
return
}
err := amino.UnmarshalJSON(bz, ptr)
if err != nil {
panic(err)
}
}

The method is called GetXXX, but it doesn't alter the pointer value internally if the value is missing.

Keeper (store) not being thread safe

The params keeper can be concurrently called, but it's not thread safe, actually. The underlying store is not thread safe

What if different modules concurrently call the keeper to store params?

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

@zivkovicmilos zivkovicmilos added the 📦 ⛰️ gno.land Issues or PRs gno.land package related label Nov 10, 2024
@zivkovicmilos zivkovicmilos self-assigned this Nov 10, 2024
@github-actions github-actions bot added the 📦 🌐 tendermint v2 Issues or PRs tm2 related label Nov 10, 2024
Copy link

codecov bot commented Nov 10, 2024

tm2/pkg/sdk/params/handler_test.go Outdated Show resolved Hide resolved
tm2/pkg/sdk/params/handler.go Outdated Show resolved Hide resolved
@zivkovicmilos zivkovicmilos marked this pull request as ready for review November 15, 2024 02:55
@zivkovicmilos
Copy link
Member Author

@moul @gfanton
Ready for your eyes, I needed to get the expected functionality down after changes in #3003

Copy link
Member

@gfanton gfanton left a comment

Choose a reason for hiding this comment

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

Looking good 👍

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

Successfully merging this pull request may close these issues.

4 participants