-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm! Some nits.
It should still be updated here too:
cosmos-sdk/x/staking/keeper/query_utils.go
Line 134 in 158ce7c
valSrcAddr, err := sdk.ValAddressFromBech32(redelegation.ValidatorSrcAddress) |
1/2
, so I guess it comes later :)
@@ -53,9 +53,14 @@ | |||
// NOTE: Correctness dependent on invariant that unbonding delegations / redelegations must also have been completely | |||
// slashed in this case - which we don't explicitly check, but should be true. | |||
// 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
@@ -170,9 +175,13 @@ | |||
panic("invalid validator status") | |||
} | |||
|
|||
valAddr, err := k.validatorAddressCodec.BytesToString(validator.GetOperator()) | |||
if err != nil { | |||
panic(err) |
Check warning
Code scanning / CodeQL
Panic in BeginBock or EndBlock consensus methods
@@ -196,7 +196,7 @@ func TestInitGenesisLargeValidatorSet(t *testing.T) { | |||
bondedPoolAmt := math.ZeroInt() | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
although this is fine, feels dirty / bad practice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -40,7 +41,7 @@ func TestCancelUnbondingDelegation(t *testing.T) { | |||
delegatorAddr := addrs[1] | |||
|
|||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, is just showing bad practice.
@@ -97,7 +98,7 @@ func (b *GenesisBuilder) GenTx(privVal secp256k1.PrivKey, val cmttypes.GenesisVa | |||
|
|||
// Produce the create validator message. | |||
msg, err := stakingtypes.NewMsgCreateValidator( | |||
privVal.PubKey().Address().Bytes(), | |||
sdk.ValAddress(privVal.PubKey().Address()).String(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -33,7 +34,7 @@ var ( | |||
) | |||
|
|||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tac0turtle this actually brings a good point…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup agreed
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.md
make lint
andmake test
Reviewers 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