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

Migrate Validators v0.36 #4770

Merged
merged 5 commits into from
Jul 23, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions x/staking/legacy/v0_34/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,10 @@ type (
}

Commission struct {
CommissionRates CommissionRates `json:"commission_rates"`
UpdateTime time.Time `json:"update_time"`
}

CommissionRates struct {
Rate sdk.Dec `json:"rate"`
MaxRate sdk.Dec `json:"max_rate"`
MaxChangeRate sdk.Dec `json:"max_change_rate"`
Rate sdk.Dec `json:"rate"`
Copy link
Member

Choose a reason for hiding this comment

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

This is what the struct actually looks like 👌

MaxRate sdk.Dec `json:"max_rate"`
MaxChangeRate sdk.Dec `json:"max_change_rate"`
UpdateTime time.Time `json:"update_time"`
}

bechValidator struct {
Expand Down
31 changes: 30 additions & 1 deletion x/staking/legacy/v0_36/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,39 @@ func Migrate(oldGenState v034staking.GenesisState) GenesisState {
oldGenState.Params,
oldGenState.LastTotalPower,
oldGenState.LastValidatorPowers,
oldGenState.Validators,
migrateValidators(oldGenState.Validators),
oldGenState.Delegations,
oldGenState.UnbondingDelegations,
oldGenState.Redelegations,
oldGenState.Exported,
)
}

func migrateValidators(oldValidators v034staking.Validators) Validators {
validators := make(Validators, len(oldValidators))

for i, val := range oldValidators {
validators[i] = Validator{
OperatorAddress: val.OperatorAddress,
ConsPubKey: val.ConsPubKey,
Jailed: val.Jailed,
Status: val.Status,
Tokens: val.Tokens,
DelegatorShares: val.DelegatorShares,
Description: val.Description,
UnbondingHeight: val.UnbondingHeight,
UnbondingCompletionTime: val.UnbondingCompletionTime,
Commission: Commission{
CommissionRates: CommissionRates{
Rate: val.Commission.Rate,
MaxRate: val.Commission.MaxRate,
MaxChangeRate: val.Commission.MaxChangeRate,
},
UpdateTime: val.Commission.UpdateTime,
},
MinSelfDelegation: val.MinSelfDelegation,
}
}

return validators
}
36 changes: 33 additions & 3 deletions x/staking/legacy/v0_36/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,51 @@
package v0_36

import (
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_34"
"time"

"github.com/tendermint/tendermint/crypto"

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

const (
ModuleName = "staking"
)

type (
Commission struct {
CommissionRates `json:"commission_rates" yaml:"commission_rates"`
UpdateTime time.Time `json:"update_time" yaml:"update_time"`
}

CommissionRates struct {
Rate sdk.Dec `json:"rate" yaml:"rate"`
MaxRate sdk.Dec `json:"max_rate" yaml:"max_rate"`
MaxChangeRate sdk.Dec `json:"max_change_rate" yaml:"max_change_rate"`
}

Validator struct {
OperatorAddress sdk.ValAddress `json:"operator_address" yaml:"operator_address"`
ConsPubKey crypto.PubKey `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 {
Params v034staking.Params `json:"params"`
LastTotalPower sdk.Int `json:"last_total_power"`
LastValidatorPowers []v034staking.LastValidatorPower `json:"last_validator_powers"`
Validators v034staking.Validators `json:"validators"`
Validators Validators `json:"validators"`
Delegations v034staking.Delegations `json:"delegations"`
UnbondingDelegations []v034staking.UnbondingDelegation `json:"unbonding_delegations"`
Redelegations []v034staking.Redelegation `json:"redelegations"`
Expand All @@ -27,7 +57,7 @@ type (

func NewGenesisState(
params v034staking.Params, lastTotalPower sdk.Int, lastValPowers []v034staking.LastValidatorPower,
validators v034staking.Validators, delegations v034staking.Delegations,
validators Validators, delegations v034staking.Delegations,
ubds []v034staking.UnbondingDelegation, reds []v034staking.Redelegation, exported bool,
) GenesisState {

Expand Down
4 changes: 2 additions & 2 deletions x/staking/types/commission.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
type (
// Commission defines a commission parameters for a given validator.
Commission struct {
CommissionRates
UpdateTime time.Time `json:"update_time" yaml:"update_time"` // the last time the commission rate was changed
CommissionRates `json:"commission_rates" yaml:"commission_rates"`
UpdateTime time.Time `json:"update_time" yaml:"update_time"` // the last time the commission rate was changed
}

// CommissionRates defines the initial commission rates to be used for creating a
Expand Down
2 changes: 1 addition & 1 deletion x/staking/types/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func TestValidatorMarshalYAML(t *testing.T) {
unbondingheight: 0
unbondingcompletiontime: 1970-01-01T00:00:00Z
commission:
commissionrates:
commission_rates:
rate: "0.000000000000000000"
max_rate: "0.000000000000000000"
max_change_rate: "0.000000000000000000"
Expand Down