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

Handle unmarshalling failures gracefully in x/stake commands #1997

Merged
merged 10 commits into from
Aug 15, 2018
Merged

Handle unmarshalling failures gracefully in x/stake commands #1997

merged 10 commits into from
Aug 15, 2018

Conversation

alessio
Copy link
Contributor

@alessio alessio commented Aug 13, 2018

delegation := types.MustUnmarshalDelegation(cdc, key, res)
delegation, err := types.UnmarshalDelegation(cdc, key, res)
if err != nil {
return errors.Errorf("cannot unmarshal delegation: %v", err)
Copy link
Collaborator

@fedekunze fedekunze Aug 13, 2018

Choose a reason for hiding this comment

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

Wouldn't it be better to add a new error function in stake/types/errors.go and use that instead ? you can use the CodeInternal as the CodeType

delegation := types.MustUnmarshalDelegation(cdc, key, resQuery)
delegation, err := types.UnmarshalDelegation(cdc, key, resQuery)
if err != nil {
return sdk.ZeroRat(), errors.Errorf("cannot unmarshal delegation: %v", err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same

Alessio Treglia added 3 commits August 13, 2018 11:07
UnmarshalValidator() checks the address length first;
it does not make sense to attempt unmarshalling if the
address is wrong.
@alessio
Copy link
Contributor Author

alessio commented Aug 13, 2018

@fedekunze addressed your comments, please review

@alexanderbez
Copy link
Contributor

Nice work @alessio. Did you notice any other places this kind of thing could happen as well?

@fedekunze
Copy link
Collaborator

@alexanderbez @alessio I believe there are some in the client/rest/ folder as well

@alessio
Copy link
Contributor Author

alessio commented Aug 13, 2018

@alexanderbez @fedekunze Chances are that there are some more. I'll have a look and amend the PR accordingly.

Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@alessio
Copy link
Contributor Author

alessio commented Aug 13, 2018

@alexanderbez @fedekunze removed all errors.New() calls. Please review.

@alexanderbez
Copy link
Contributor

Will test these changes in the internal testnet 👍

@@ -117,6 +126,10 @@ func ErrNotMature(codespace sdk.CodespaceType, operation, descriptor string, got
return sdk.NewError(codespace, CodeUnauthorized, msg)
}

func ErrBadUnbondingDelegationAddr(codespace sdk.CodespaceType) sdk.Error {
Copy link
Contributor

Choose a reason for hiding this comment

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

I see no difference between this and ErrBadDelegationAddr err messages.

Copy link
Contributor

Choose a reason for hiding this comment

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

++

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True that, will amend it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed - @melekes please review

@@ -115,17 +114,16 @@ func MustUnmarshalValidator(cdc *wire.Codec, ownerAddr, value []byte) Validator

// unmarshal a redelegation from a store key and value
func UnmarshalValidator(cdc *wire.Codec, ownerAddr, value []byte) (validator Validator, err error) {
if len(ownerAddr) != 20 {
Copy link
Contributor

Choose a reason for hiding this comment

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

magic number

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed, please review

Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

@alessio changes LGTM -- just left minor remarks 👍

@@ -125,6 +134,10 @@ func ErrExistingUnbondingDelegation(codespace sdk.CodespaceType) sdk.Error {
return sdk.NewError(codespace, CodeInvalidDelegation, "existing unbonding delegation found")
}

func ErrBadRedelegationAddr(codespace sdk.CodespaceType) sdk.Error {
return sdk.NewError(codespace, CodeInvalidInput, "unexpected address length for this (address, srcValidator, dstValidator) triple")
Copy link
Contributor

Choose a reason for hiding this comment

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

tuple 🤷‍♂️ ?

PENDING.md Outdated
@@ -95,3 +95,4 @@ BUG FIXES
* \#1787 Fixed bug where Tally fails due to revoked/unbonding validator
* \#1787 Fixed bug where Tally fails due to revoked/unbonding validator
* [basecoin] Fixes coin transaction failure and account query [discussion](https://forum.cosmos.network/t/unmarshalbinarybare-expected-to-read-prefix-bytes-75fbfab8-since-it-is-registered-concrete-but-got-0a141dfa/664/6)
* [cli] Handle panics gracefully when `gaiacli stake {delegation,unbond}` fail to unmarshal delegation.
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's reference the PR here 👍

@alessio
Copy link
Contributor Author

alessio commented Aug 15, 2018

Thanks @alexanderbez, amended. Please review

Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

utACK 👍

Copy link
Contributor

@rigelrozanski rigelrozanski left a comment

Choose a reason for hiding this comment

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

awesome code looks good!

@rigelrozanski rigelrozanski merged commit 4fbaee2 into cosmos:develop Aug 15, 2018
@rigelrozanski
Copy link
Contributor

@alessio - thanks for the PR - in the future it would be great to leave the default template PR checkboxes/bullets in the PR - it's a good reminder for reviewers as to what needs to be done

@alessio
Copy link
Contributor Author

alessio commented Aug 16, 2018 via email

@alessio alessio deleted the alessio/1831-avoid-panic-on-unbond-begin branch September 6, 2018 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invoking a "unbond begin" twice causes CLI to panic
5 participants