-
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
Handle unmarshalling failures gracefully in x/stake commands #1997
Handle unmarshalling failures gracefully in x/stake commands #1997
Conversation
x/stake/client/cli/query.go
Outdated
delegation := types.MustUnmarshalDelegation(cdc, key, res) | ||
delegation, err := types.UnmarshalDelegation(cdc, key, res) | ||
if err != nil { | ||
return errors.Errorf("cannot unmarshal delegation: %v", err) |
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.
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
x/stake/client/cli/tx.go
Outdated
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) |
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
UnmarshalValidator() checks the address length first; it does not make sense to attempt unmarshalling if the address is wrong.
@fedekunze addressed your comments, please review |
Nice work @alessio. Did you notice any other places this kind of thing could happen as well? |
@alexanderbez @alessio I believe there are some in the |
@alexanderbez @fedekunze Chances are that there are some more. I'll have a look and amend the PR accordingly. |
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 👍
…to replace errors.New() calls
@alexanderbez @fedekunze removed all |
Will test these changes in the internal testnet 👍 |
x/stake/types/errors.go
Outdated
@@ -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 { |
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.
I see no difference between this and ErrBadDelegationAddr err messages.
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.
++
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.
True that, will amend it.
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.
Addressed - @melekes please review
x/stake/types/validator.go
Outdated
@@ -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 { |
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.
magic number
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.
Addressed, please review
…oid duplication Thanks: @melekes for pointing this out
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.
@alessio changes LGTM -- just left minor remarks 👍
x/stake/types/errors.go
Outdated
@@ -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") |
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.
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. |
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.
Let's reference the PR here 👍
Thanks @alexanderbez, amended. Please review |
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.
utACK 👍
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.
awesome code looks good!
@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 |
Will do, thanks!
…On Wed, 15 Aug 2018, 21:50 Rigel, ***@***.***> wrote:
@alessio <https://github.com/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
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1997 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAN_7Jn8vmbsVcc6Be8XifoUhePYJ-j8ks5uRHuDgaJpZM4V6HOk>
.
|
Err{NoDelegation,Bad{Redelegation,UnbondingDelegation,Validator}Addr}
functions in stake's types.stake/types.Unmarshal{Validator,UBD,RED}()
:stake/types.UnmarshalValidator()
:MustUnmarshalDelegation()
withUnmarshalDelegation()
calls and handle errors gracefully rather than panicking to fix Invoking a "unbond begin" twice causes CLI to panic #1831 and Querying delegation with non-existent validator address causes CLI to panic #1907.