[TECHDEBT] Change the PersistenceRWContext interface to pass paramName when getting a parameter - (Issue #286)#422
Conversation
|
@Olshansk I cannot assign myself to this, I don't think I have permissions to do that sort of thing. I am also aware that in this implementation there will never be an instance where |
…ent parameter name constants
I couldn't think of any other way. I found the
@Olshansk I would be up for taking this on - I am about to go back to uni and have a couple exams but after those I would be happy to jump in and continue this work 😄 So in around 2 weeks time, I could start on it. |
Olshansk
left a comment
There was a problem hiding this comment.
@h5law Can you create a new issue explaining that we should apply this business logic in other parts of the codebase and add a TODO(#XXX): Replace all gov parameter accessors with GetParameter. No rush though, exams come first :)
Also, I've added you as an external contributor to https://github.com/orgs/pokt-network/teams/external-contributors/members
|
@Olshansk I have removed those old comments. And updated the unit tests in I did make one change to the logic of However if this usage is incorrect I can change it back. I do believe this to be the case from looking through the code, and this would be useful as we move towards fully generalising these parameter accessors. I couldn't grok the types from the Maybe it would be better to leave the Also, before I create the issue can I just confirm the task:
Change: func (u *UtilityContext) GetAppMinimumStake() (*big.Int, typesUtil.Error) {
return u.getBigIntParam(typesUtil.AppMinimumStakeParamName)
}
...
func (u *UtilityContext) GetValidatorMaxMissedBlocks() (maxMissedBlocks int, err typesUtil.Error) {
return u.getIntParam(typesUtil.ValidatorMaximumMissedBlocksParamName)
}
...
func (u *UtilityContext) getIntParam(paramName string) (int, typesUtil.Error) {
store, height, er := u.GetStoreAndHeight()
if er != nil {
return 0, er
}
value, err := store.GetIntParam(paramName, height)
if err != nil {
return typesUtil.ZeroInt, typesUtil.ErrGetParam(paramName, err)
}
return value, nil
}
...
func (u *UtilityContext) getBigIntParam(paramName string) (*big.Int, typesUtil.Error) {
store, height, er := u.GetStoreAndHeight()
if er != nil {
return nil, er
}
value, err := store.GetStringParam(paramName, height)
if err != nil {
log.Printf("err: %v\n", err)
return nil, typesUtil.ErrGetParam(paramName, err)
}
return typesUtil.StringToBigInt(value)
}To func (u *UtilityContext) GetAppMinimumStake() (*big.Int, typesUtil.Error) {
return u.getBigIntParam(typesUtil.AppMinimumStakeParamName)
}
...
func (u *UtilityContext) GetValidatorMaxMissedBlocks() (maxMissedBlocks int, err typesUtil.Error) {
return u.getIntParam(typesUtil.ValidatorMaximumMissedBlocksParamName)
}
...
func (u *UtilityContext) getIntParam(paramName string) (int, typesUtil.Error) {
store, height, er := u.GetStoreAndHeight()
if er != nil {
return 0, er
}
value, err := store.GetParameter(paramName, height)
if err != nil {
return typesUtil.ZeroInt, typesUtil.ErrGetParam(paramName, err)
}
return value.(int), nil
}
...
func (u *UtilityContext) getBigIntParam(paramName string) (*big.Int, typesUtil.Error) {
store, height, er := u.GetStoreAndHeight()
if er != nil {
return nil, er
}
value, err := store.GetParameter(paramName, height)
if err != nil {
log.Printf("err: %v\n", err)
return nil, typesUtil.ErrGetParam(paramName, err)
}
return value.(*big.Int), nil
}Or? func (u *UtilityContext) GetAppMinimumStake() (*big.Int, typesUtil.Error) {
store, height, err := u.GetStoreAndHeight()
if err != nil {
return nil, err
}
stake, err := u.GetParameter(typesUtil.AppMinimumStakeParamName, height)
if err != nil {
return nil, err
}
return stake.(*big.Int), nil
} |
…h regex string outside of loop
Olshansk
left a comment
There was a problem hiding this comment.
Need a bit more time to think through the followup issue, but wanted to post a couple questions/commnets I had here in the meantime.
|
@Olshansk What do you think about storing the |
This might make parsing easier, but creating the protobufs (reading, viewing, editing) will create a much worse developer experience since we wouldn't be able to just use strings anywhere, so I'm not a big fan of the idea at the moment. SIde note: the PR looks pretty good to me so could you merge with main and just re-run the tests when you have a chance. |
Yeah I understand that, no worries will continue to think on it!
On it now 🫡 All tests passing, cannot merge myself but the branch is synced with main now - all ready to merge. |
|
@h5law I added you to https://github.com/orgs/pokt-network/teams/external-contributors. I'm curious to know if this allows you to merge this in yourself, given that you have approval from someone on the core team. If so, do a "squash & merge" and use the body of the GH description as the commit message. Also, can you create the follow-up issue and add in the details we've already discussed here? We can narrow down the requirements and scope out the solution in that thread before continuing to the implementation. |


Description
This PR is in response to issue #286. A general function to retrieve parameters from their
paramNamestring 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
ParameterNameTypeMapbuilt by theinit()function inpersistence/gov.goto find the correct return type from the parameter name string. The map is built by:Paramsstruct as defined inpersistence/types/persistence_genesis.pb.go{paramName},omitemptyand the parameter name can easily be foundBuilding the map with the
init()function and storing it in memory allows for quick access each timeGetParameteris called removing the need to parse theParamsstruct 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.goand works as follows:paramNameargument find the parameter return type from theParameterNameTypeMapgetParamOrFlag[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.gowhere theGetBlocksPerSessiontest now uses theGetParameterfunction - passing successfully. TheGetSetIntParamandGetSetStringParamunit tests inpersistence/test/gov_test.gohave also been updated to useGetParameteralso passing successfully.Issue
Fixes #286
Type of change
Please mark the relevant option(s):
List of changes
GetBlocksPerSessionandGetServiceNodesPerSessionAt) in favour of using the more generalGetParameterinshared/modules/persistence_module.goinit()function inpersistence/gov.goto buildParameterNameTypeMapof parameter names and their return typesGetParameterinpersistence/gov.goGetParameterinutility/gov.goGetBlocksPerSessioninutility/test/gov_test.goto use the new functionpersistence/test/gov_test.goto use theGetParameter()function instead of theGetIntParam, andGetStringParamfunctionsTesting
make develop_testREADMERequired Checklist
If Applicable Checklist
shared/docs/*if I updatedshared/*README(s)