refactor: remove global valaddress bech32 codec calls (1/2)#17098
Conversation
Co-authored-by: marbar3778 <marbar3778@yahoo.com> Co-authored-by: Marko <marko@baricevic.me> Co-authored-by: Julien Robert <julien@rbrt.fr>
|
while there are not many lines changed i think its worth opening this for review and ill do another pr to follow up further |
There was a problem hiding this comment.
lgtm! Some nits.
It should still be updated here too:
cosmos-sdk/x/staking/keeper/query_utils.go
Line 134 in 158ce7c
1/2, so I guess it comes later :)
| // Log the slash attempt for future reference (maybe we should tag it too) | ||
| conStr, err := k.consensusAddressCodec.BytesToString(consAddr) | ||
| if err != nil { | ||
| panic(err) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods
|
|
||
| valAddr, err := k.validatorAddressCodec.BytesToString(validator.GetOperator()) | ||
| if err != nil { | ||
| panic(err) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods
| for i := range validators { | ||
| validators[i], err = types.NewValidator( | ||
| sdk.ValAddress(addrs[i]), | ||
| sdk.ValAddress(addrs[i]).String(), |
There was a problem hiding this comment.
although this is fine, feels dirty / bad practice
There was a problem hiding this comment.
oh this is 100% ugly, mainly didnt want to rewrite all these tests to use the codec as we will be rewriting this module in the near future
|
|
||
| // setup a new validator with bonded status | ||
| validator, err := types.NewValidator(valAddr, PKs[0], types.NewDescription("Validator", "", "", "", "")) | ||
| validator, err := types.NewValidator(valAddr.String(), PKs[0], types.NewDescription("Validator", "", "", "", "")) |
There was a problem hiding this comment.
same here, is just showing bad practice.
| // Produce the create validator message. | ||
| msg, err := stakingtypes.NewMsgCreateValidator( | ||
| privVal.PubKey().Address().Bytes(), | ||
| sdk.ValAddress(privVal.PubKey().Address()).String(), |
itsdevbear
left a comment
There was a problem hiding this comment.
overall utACK
but one thing is that a lot of the tests still use .string() which is fine, but overall is an antipattern that is being promoted in the tests.
|
|
||
| // NewTxCmd returns a root CLI command handler for all x/staking transaction commands. | ||
| func NewTxCmd() *cobra.Command { | ||
| func NewTxCmd(valAddrCodec, ac address.Codec) *cobra.Command { |
There was a problem hiding this comment.
did you explore any other ways to provide these codecs as dependencies beside constructor injection? another approach which comes to mind is packing them into the command context.
There was a problem hiding this comment.
@tac0turtle this actually brings a good point…
There was a problem hiding this comment.
well the reason i went this approach is they will be removed in the near future in favour of autocli. I can look at adding it into the context but then they could be removed later on, so it would be two breaking changes instead of one then removal
Co-authored-by: Devon Bear <itsdevbear@berachain.com> Co-authored-by: Julien Robert <julien@rbrt.fr> (cherry picked from commit 58855c6) # Conflicts: # CHANGELOG.md # tests/integration/staking/keeper/validator_test.go # testutil/testnet/genesis.go # x/distribution/keeper/genesis.go # x/gov/keeper/tally_test.go # x/staking/simulation/decoder_test.go # x/staking/testutil/validator.go # x/staking/types/validator_test.go
Description
remove calls to valAddressCodec global
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!to the type prefix if API or client breaking changeCHANGELOG.mdmake lintandmake testReviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!in the type prefix if API or client breaking change