Skip to content
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

Merged
merged 24 commits into from
Jul 26, 2023

Conversation

tac0turtle
Copy link
Member

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...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • run make lint and make test
  • confirmed all CI checks have passed

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...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

Co-authored-by: marbar3778 <marbar3778@yahoo.com>
Co-authored-by: Marko <marko@baricevic.me>
Co-authored-by: Julien Robert <julien@rbrt.fr>
@github-actions github-actions bot added C:CLI C:x/genutil genutil module issues labels Jul 24, 2023
@tac0turtle tac0turtle changed the title refactor: remove global bech32 codec calls refactor: remove global valaddress bech32 codec calls Jul 24, 2023
@github-actions github-actions bot added the C:x/distribution distribution module related label Jul 24, 2023
@tac0turtle
Copy link
Member Author

while there are not many lines changed i think its worth opening this for review and ill do another pr to follow up further

@tac0turtle tac0turtle marked this pull request as ready for review July 24, 2023 16:01
@tac0turtle tac0turtle requested a review from a team as a code owner July 24, 2023 16:01
@tac0turtle tac0turtle changed the title refactor: remove global valaddress bech32 codec calls refactor: remove global valaddress bech32 codec calls (1/2) Jul 24, 2023
Copy link
Member

@julienrbrt julienrbrt left a 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:

valSrcAddr, err := sdk.ValAddressFromBech32(redelegation.ValidatorSrcAddress)
and at a few other places. However, I noticed the 1/2, so I guess it comes later :)

x/distribution/types/msg.go Show resolved Hide resolved
x/genutil/client/cli/collect.go Show resolved Hide resolved
x/genutil/client/cli/genaccount.go Show resolved Hide resolved
x/genutil/client/cli/gentx.go Show resolved Hide resolved
x/slashing/types/msg.go Show resolved Hide resolved
x/staking/client/cli/tx.go Outdated Show resolved Hide resolved
x/staking/client/cli/tx.go Outdated Show resolved Hide resolved
x/staking/types/msg.go Show resolved Hide resolved
@julienrbrt julienrbrt added the backport/v0.50.x PR scheduled for inclusion in the v0.50's next stable release label Jul 24, 2023
@@ -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

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
@@ -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

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
@@ -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(),
Copy link
Contributor

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

Copy link
Member Author

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", "", "", "", ""))
Copy link
Contributor

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(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Contributor

@itsdevbear itsdevbear left a 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 {
Copy link
Member

@kocubinski kocubinski Jul 25, 2023

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.

Copy link
Contributor

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…

Copy link
Member Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup agreed

@tac0turtle tac0turtle added this pull request to the merge queue Jul 26, 2023
Merged via the queue into main with commit 58855c6 Jul 26, 2023
@tac0turtle tac0turtle deleted the marko/valAddress branch July 26, 2023 19:03
mergify bot pushed a commit that referenced this pull request Jul 26, 2023
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
julienrbrt added a commit that referenced this pull request Jul 26, 2023
…17098) (#17149)

Co-authored-by: Marko <marbar3778@yahoo.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
@faddat faddat mentioned this pull request Nov 8, 2024
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.50.x PR scheduled for inclusion in the v0.50's next stable release C:CLI C:Simulations C:x/distribution distribution module related C:x/genutil genutil module issues C:x/gov C:x/slashing C:x/staking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants