x/authz module suggestions for minor code improvements #11569
Labels
C:x/authz
Type: Code Hygiene
General cleanup and restructuring of code to provide clarity, flexibility, and modularity.
As a part of model based testing audit of the authz module, code inspection has been done in order to find issues or possible improvements in code.
The following are recommendations for slightly neater and maybe better organized code (as far as recommended module structure). from a perspective of someone who is just getting introduced to authz implementation and Cosmos SDK itself.
Version:
master (commit: 8800d2e)
auditing is performed for tag: v0.46.0-alpha4 (commit: 354faa8)
Code improvement suggestions:
validateAndBech32fy – possibly validateAllowAndDenyValidators as the name of the function or something similar would be more appropriate taking into account the logic of the func?
cosmos-sdk/x/staking/types/authz.go
Line 119 in 8800d2e
Move the line outside of /bellow of the switch statement, in order not to duplicate code:
cosmos-sdk/x/staking/types/authz.go
Line 68 in 8800d2e
This line here finished here probably by merge mistake, this comment should be on top of this
cosmos-sdk/x/staking/types/authz.go
Line 144 in 8800d2e
Define variable for cached value
av := g.Authorization.GetCachedValue()
incosmos-sdk/x/authz/authorization_grant.go
Line 50 in 6d1525f
And return this value in
cosmos-sdk/x/authz/authorization_grant.go
Line 52 in 6d1525f
Adding some comments for query Grants function in order to help understanding since there are two return branches and different logics in one method - depending on MsgTypeUrl - as stated in
cosmos-sdk/proto/cosmos/authz/v1beta1/query.proto
Lines 38 to 39 in 8800d2e
var authorizations []*authz.Grant
and paginationvar pageRes *query.PageResponse
variables, assign them values in both cases (grants for certain MsgType and in case of querying all MsgTypes grants) and have only one return from Grants func.Even though this is happening in tx - and no store changes will be committed in the end if err is returned, I think it is cleaner to move store.deletion: after the successful deletion of grant queue value and before emitting event.
cosmos-sdk/x/authz/keeper/keeper.go
Lines 199 to 208 in fdd3d07
if you wish to follow the guide for building modules and recommended module structure, since there is genesis_test.go with unit tests for these functions, I suggest you create keeper/genesis.go file with InitGenesis and ExportGenesis functions (move them from keeper.go file .
Note all Grant Queue key parts in comments that should explain key format here and/or here.
NewCmdGrantAuthorization() improvements:
cosmos-sdk/x/authz/client/cli/tx.go
Line 173 in ea8b0f7
cosmos-sdk/x/authz/client/cli/tx.go
Line 129 in ea8b0f7
so, only first limit would be considered.
The text was updated successfully, but these errors were encountered: