Merge PR #4770: Migrate Validators v0.36

This commit is contained in:
Alexander Bezobchuk 2019-07-23 19:14:36 -04:00 committed by GitHub
parent 309dacc637
commit c71eaf77b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 70 additions and 15 deletions

View File

@ -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"`
MaxRate sdk.Dec `json:"max_rate"`
MaxChangeRate sdk.Dec `json:"max_change_rate"`
UpdateTime time.Time `json:"update_time"`
}
bechValidator struct {

View File

@ -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
}

View File

@ -3,9 +3,12 @@
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 (
@ -13,11 +16,38 @@ const (
)
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"`
@ -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 {

View File

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

View File

@ -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"