-
Notifications
You must be signed in to change notification settings - Fork 33
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
[TECHDEBT] Change the PersistenceRWContext
interface to pass paramName
when getting a parameter
#286
Comments
Great |
I might need some help to get started (some super basic questions):
Thank you! |
Yes.
Yes.
Yes.
For this change, since it's small. The changelog is enough. |
I would be interested in taking up this task if its still relevant. The only question I have is around determining the type from the If the function is solely to replace the two ones listed why not use this function which is already defined? As both the functions are int32 types if I am correct. func (p PostgresContext) GetIntParam(paramName string, height int64) (int, error) {
v, _, err := getParamOrFlag[int](p, types.ParamsTableName, paramName, height)
return v, err
} However, if you are aiming to really generalise the 3 wrappers for the I think this involves editing the following files: shared/modules/persistence_module.go <-- comment out old functions define new function in interface
persistence/gov.go <-- comment out old functions add new GetParameter function logic
utility/gov.go <-- Comment out GetBlocksPerSession replace with GetParameter
utility/test/gov_test.go <-- Comment out GetBlocksPerSession test replace with new GetParameter test In addition to the Let me know the situation I am happy to get to work. The main question is about knowing the type the One way this could work is by having the function signature like: |
@Olshansk what do you think about this? |
Yup, still relevant!
This is the first step of this task and what I would call the "first commit" as you start working on it locally. It is to simply make these two functions follow the same pattern as the rest of the codebase by using
Similar to how we have In terms of files that'll be affected, you're on the right track. Disclaimer: I haven't tried implementing the suggestion above so there may be some hurdles I'm unaware of. cc @deblasis for context. I know you're planning on making some other changes to the persistence interface and curious what you think about this change. |
@Olshansk I have actually wrote the code for this PR and update the unit test in |
Hi @h5law !
In order to determine the type of the params we can leverage the struct tags These are parsed in Oh as I was writing I saw your message and it seems you already found your way :) well done! |
…e when getting a parameter - (Issue #286) (#422) ## Description This PR is in response to issue #286. A general function to retrieve parameters from their `paramName` string will help to address the goals laid out in the issue. Namely a lower code footprint, the removal of placeholder constants and it allows for a pattern to be used from now on regarding retrieval of parameters - similar to the pattern for setting parameters. The function uses the `ParameterNameTypeMap` built by the `init()` function in `persistence/gov.go` to find the correct return type from the parameter name string. The map is built by: - Initialising an empty `Params` struct as defined in `persistence/types/persistence_genesis.pb.go` - Loop through the fields of this stuct: - Extracting the parameter name from the json tag of each field - Match the json tag as it is in the format of `{paramName},omitempty` and the parameter name can easily be found - Setting ParameterNameTypeMap[paramName] = stringified type of field in struct Building the map with the `init()` function and storing it in memory allows for quick access each time `GetParameter` is called removing the need to parse the `Params` struct each time it is called. The function's signature is `GetParameter(paramName string, height int64) (any, error)` The function's logic is defined in the file `persistence/gov.go` and works as follows: - Using the `paramName` argument find the parameter return type from the `ParameterNameTypeMap` - Using this stringified parameter type, call the proper getter function `getParamOrFlag[int | string | []byte]` and the values from this call are returned. The old functions have been removed and replaced with the new generic function. This includes the unit test in `utility/test/gov.go` where the `GetBlocksPerSession` test now uses the `GetParameter` function - passing successfully. The `GetSetIntParam` and `GetSetStringParam` unit tests in `persistence/test/gov_test.go` have also been updated to use `GetParameter` also passing successfully. ``` ok github.com/pokt-network/pocket/persistence/test 20.742s ok github.com/pokt-network/pocket/utility/test 17.468s ``` ## Issue Fixes #286 ## Type of change Please mark the relevant option(s): - [x] New feature, functionality or library - [ ] Bug fix - [x] Code health or cleanup - [ ] Major breaking change - [ ] Documentation - [ ] Other <!-- add details here if it a different type of change --> ## List of changes - Deprecate old functions (`GetBlocksPerSession` and `GetServiceNodesPerSessionAt`) in favour of using the more general `GetParameter` in `shared/modules/persistence_module.go` - Add `init()` function in `persistence/gov.go` to build `ParameterNameTypeMap` of parameter names and their return types - Define the logic for the `GetParameter` in `persistence/gov.go` - Replace old function with `GetParameter` in `utility/gov.go` - Change unit test for `GetBlocksPerSession` in `utility/test/gov_test.go` to use the new function - Change unit tests in `persistence/test/gov_test.go` to use the `GetParameter()` function instead of the `GetIntParam`, and `GetStringParam` functions ## Testing - [x] `make develop_test` - [x] [LocalNet](https://github.com/pokt-network/pocket/blob/main/docs/development/README.md) w/ all of the steps outlined in the `README` ## Required Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have tested my changes using the available tooling - [x] I have updated the corresponding CHANGELOG ### If Applicable Checklist - [ ] I have updated the corresponding README(s); local and/or global - [x] I have added tests that prove my fix is effective or that my feature works - [ ] I have added, or updated, [mermaid.js](https://mermaid-js.github.io) diagrams in the corresponding README(s) - [ ] I have added, or updated, documentation and [mermaid.js](https://mermaid-js.github.io) diagrams in `shared/docs/*` if I updated `shared/*`README(s)
Objective
Deprecate
GetBlocksPerSession(height int64) (int, error)
and
GetServiceNodesPerSessionAt(height int64) (int, error)
for
GetParameter(paramName string, height int64) (interface, error)
Origin Document
We genericized the param setters like:
SetParam(paramName string, value interface{}) error
We need a similar pattern for getters
Goals
Deliverable
General issue deliverables
Creator: @andrewnguyen22
The text was updated successfully, but these errors were encountered: