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

Draft
wants to merge 6 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 82.85714% with 24 lines in your changes missing coverage. Please review.

Project coverage is 63.75%. Comparing base (4f27a57) to head (f5cdea3).

Files with missing lines Patch % Lines
gno.land/pkg/sdk/vm/builtins.go 21.42% 8 Missing and 3 partials ⚠️
gno.land/pkg/sdk/vm/keeper.go 35.71% 7 Missing and 2 partials ⚠️
tm2/pkg/sdk/params/keeper.go 94.87% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3105      +/-   ##
==========================================
- Coverage   63.77%   63.75%   -0.03%     
==========================================
  Files         548      547       -1     
  Lines       78681    78701      +20     
==========================================
- Hits        50180    50175       -5     
- Misses      25117    25141      +24     
- Partials     3384     3385       +1     
Flag Coverage Δ
contribs/gnodev 61.16% <ø> (+0.62%) ⬆️
contribs/gnofaucet 14.82% <ø> (ø)
gno.land 73.37% <28.57%> (-0.25%) ⬇️
gnovm 67.92% <ø> (ø)
misc/genstd 79.72% <ø> (ø)
tm2 62.35% <96.42%> (-0.12%) ⬇️

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 Show resolved Hide resolved
}
}
// findSlashPositions finds the positions of the first and second slashes in a path.
// Returns the positions of the slashes and a boolean indicating if both slashes were found
Copy link
Member

@gfanton gfanton Nov 12, 2024

Choose a reason for hiding this comment

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

Suggested change
// Returns the positions of the slashes and a boolean indicating if both slashes were found
// Returns the positions of the slashes or (-1, -1) if less than two slashes are found.

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: Triage
Development

Successfully merging this pull request may close these issues.

3 participants