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

fixes migrate bug #5095 #5099

Merged
merged 3 commits into from Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -113,6 +113,7 @@ to detail this new feature and how state transitions occur.

* (cli) [\#4763](https://github.com/cosmos/cosmos-sdk/issues/4763) Fix flag `--min-self-delegation` for staking `EditValidator`
* (keys) Fix ledger custom coin type support bug
* (genesis) [\#5095](https://github.com/cosmos/cosmos-sdk/issues/5095) Fix genesis file migration from v0.34 to v0.36 not converting validator consensus pubkey to bech32 format

## [v0.37.1] - 2019-09-19

Expand Down
64 changes: 62 additions & 2 deletions x/staking/legacy/v0_36/types.go
Expand Up @@ -5,10 +5,10 @@ package v0_36
import (
"time"

"github.com/tendermint/tendermint/crypto"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_34"
"github.com/tendermint/tendermint/crypto"
)

const (
Expand Down Expand Up @@ -41,6 +41,20 @@ type (
MinSelfDelegation sdk.Int `json:"min_self_delegation" yaml:"min_self_delegation"`
}

bechValidator struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

@kwunyeung can we also do the same change for 0.37 in staking?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alexanderbez updated for 0.37 as well.

OperatorAddress sdk.ValAddress `json:"operator_address" yaml:"operator_address"`
ConsPubKey string `json:"consensus_pubkey" yaml:"consensus_pubkey"`
Jailed bool `json:"jailed" yaml:"jailed"`
Status sdk.BondStatus `json:"status" yaml:"status"`
Tokens sdk.Int `json:"tokens" yaml:"tokens"`
DelegatorShares sdk.Dec `json:"delegator_shares" yaml:"delegator_shares"`
Description v034staking.Description `json:"description" yaml:"description"`
UnbondingHeight int64 `json:"unbonding_height" yaml:"unbonding_height"`
UnbondingCompletionTime time.Time `json:"unbonding_time" yaml:"unbonding_time"`
Commission Commission `json:"commission" yaml:"commission"`
MinSelfDelegation sdk.Int `json:"min_self_delegation" yaml:"min_self_delegation"`
}

Validators []Validator

GenesisState struct {
Expand Down Expand Up @@ -72,3 +86,49 @@ func NewGenesisState(
Exported: exported,
}
}

func (v Validator) MarshalJSON() ([]byte, error) {
bechConsPubKey, err := sdk.Bech32ifyConsPub(v.ConsPubKey)
if err != nil {
return nil, err
}

return codec.Cdc.MarshalJSON(bechValidator{
OperatorAddress: v.OperatorAddress,
ConsPubKey: bechConsPubKey,
Jailed: v.Jailed,
Status: v.Status,
Tokens: v.Tokens,
DelegatorShares: v.DelegatorShares,
Description: v.Description,
UnbondingHeight: v.UnbondingHeight,
UnbondingCompletionTime: v.UnbondingCompletionTime,
MinSelfDelegation: v.MinSelfDelegation,
Commission: v.Commission,
})
}

func (v *Validator) UnmarshalJSON(data []byte) error {
bv := &bechValidator{}
if err := codec.Cdc.UnmarshalJSON(data, bv); err != nil {
return err
}
consPubKey, err := sdk.GetConsPubKeyBech32(bv.ConsPubKey)
if err != nil {
return err
}
*v = Validator{
OperatorAddress: bv.OperatorAddress,
ConsPubKey: consPubKey,
Jailed: bv.Jailed,
Tokens: bv.Tokens,
Status: bv.Status,
DelegatorShares: bv.DelegatorShares,
Description: bv.Description,
UnbondingHeight: bv.UnbondingHeight,
UnbondingCompletionTime: bv.UnbondingCompletionTime,
Commission: bv.Commission,
MinSelfDelegation: bv.MinSelfDelegation,
}
return nil
}
63 changes: 63 additions & 0 deletions x/staking/legacy/v0_37/types.go
Expand Up @@ -5,6 +5,7 @@ package v0_37
import (
"time"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/tendermint/tendermint/crypto"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -39,6 +40,20 @@ type (
MinSelfDelegation sdk.Int `json:"min_self_delegation" yaml:"min_self_delegation"`
}

bechValidator struct {
OperatorAddress sdk.ValAddress `json:"operator_address" yaml:"operator_address"`
ConsPubKey string `json:"consensus_pubkey" yaml:"consensus_pubkey"`
Jailed bool `json:"jailed" yaml:"jailed"`
Status sdk.BondStatus `json:"status" yaml:"status"`
Tokens sdk.Int `json:"tokens" yaml:"tokens"`
DelegatorShares sdk.Dec `json:"delegator_shares" yaml:"delegator_shares"`
Description Description `json:"description" yaml:"description"`
UnbondingHeight int64 `json:"unbonding_height" yaml:"unbonding_height"`
UnbondingCompletionTime time.Time `json:"unbonding_time" yaml:"unbonding_time"`
Commission v036staking.Commission `json:"commission" yaml:"commission"`
MinSelfDelegation sdk.Int `json:"min_self_delegation" yaml:"min_self_delegation"`
}

Validators []Validator

GenesisState struct {
Expand Down Expand Up @@ -84,3 +99,51 @@ func NewGenesisState(
Exported: exported,
}
}

// MarshalJSON marshals the validator to JSON using Bech32
func (v Validator) MarshalJSON() ([]byte, error) {
bechConsPubKey, err := sdk.Bech32ifyConsPub(v.ConsPubKey)
if err != nil {
return nil, err
}

return codec.Cdc.MarshalJSON(bechValidator{
OperatorAddress: v.OperatorAddress,
ConsPubKey: bechConsPubKey,
Jailed: v.Jailed,
Status: v.Status,
Tokens: v.Tokens,
DelegatorShares: v.DelegatorShares,
Description: v.Description,
UnbondingHeight: v.UnbondingHeight,
UnbondingCompletionTime: v.UnbondingCompletionTime,
MinSelfDelegation: v.MinSelfDelegation,
Commission: v.Commission,
})
}

// UnmarshalJSON unmarshals the validator from JSON using Bech32
func (v *Validator) UnmarshalJSON(data []byte) error {
bv := &bechValidator{}
if err := codec.Cdc.UnmarshalJSON(data, bv); err != nil {
return err
}
consPubKey, err := sdk.GetConsPubKeyBech32(bv.ConsPubKey)
if err != nil {
return err
}
*v = Validator{
OperatorAddress: bv.OperatorAddress,
ConsPubKey: consPubKey,
Jailed: bv.Jailed,
Tokens: bv.Tokens,
Status: bv.Status,
DelegatorShares: bv.DelegatorShares,
Description: bv.Description,
UnbondingHeight: bv.UnbondingHeight,
UnbondingCompletionTime: bv.UnbondingCompletionTime,
Commission: bv.Commission,
MinSelfDelegation: bv.MinSelfDelegation,
}
return nil
}