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 8 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

Codecov Report

Attention: Patch coverage is 84.66667% with 23 lines in your changes missing coverage. Please review.

Project coverage is 63.77%. Comparing base (38736e7) to head (1a5b33b).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
gno.land/pkg/sdk/vm/builtins.go 21.42% 8 Missing and 3 partials ⚠️
tm2/pkg/sdk/params/keeper.go 94.87% 3 Missing and 1 partial ⚠️
gno.land/pkg/gnoland/param.go 81.25% 2 Missing and 1 partial ⚠️
gno.land/pkg/sdk/vm/keeper.go 50.00% 2 Missing and 1 partial ⚠️
gno.land/pkg/gnoland/app.go 0.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3105      +/-   ##
==========================================
- Coverage   63.78%   63.77%   -0.02%     
==========================================
  Files         549      548       -1     
  Lines       78819    78839      +20     
==========================================
+ Hits        50275    50276       +1     
- Misses      25153    25167      +14     
- Partials     3391     3396       +5     
Flag Coverage Δ
contribs/gnodev 60.54% <ø> (-0.63%) ⬇️
contribs/gnofaucet 15.77% <ø> (+0.94%) ⬆️
gno.land 73.48% <50.00%> (-0.23%) ⬇️
gnovm 67.93% <ø> (ø)
misc/genstd 79.72% <ø> (ø)
tm2 62.40% <96.42%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

tm2/pkg/sdk/params/handler_test.go Outdated Show resolved Hide resolved
tm2/pkg/sdk/params/handler.go Outdated Show resolved Hide resolved
zivkovicmilos and others added 2 commits November 15, 2024 03:04
Co-authored-by: Guilhem Fanton <8671905+gfanton@users.noreply.github.com>
@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

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

Successfully merging this pull request may close these issues.

3 participants