fixed migrations
This commit is contained in:
parent
61b608f4bc
commit
04e483dd69
|
@ -17,5 +17,5 @@ func NewMigrator(keeper Keeper) Migrator {
|
|||
|
||||
// Migrate1to2 migrates from version 1 to 2.
|
||||
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
|
||||
return v043.MigrateStore(ctx, m.keeper.storeKey)
|
||||
return v043.MigrateStore(ctx, m.keeper.storeKey, m.keeper.paramstore)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,945 @@
|
|||
// Package v040 is taken from:
|
||||
// https://github.com/cosmos/cosmos-sdk/blob/v0.40.1/x/staking/types/genesis.pb.go
|
||||
// by copy-pasted only the relevants parts for Genesis.
|
||||
//nolint
|
||||
|
||||
package v040
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
io "io"
|
||||
math "math"
|
||||
math_bits "math/bits"
|
||||
|
||||
github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types"
|
||||
_ "github.com/gogo/protobuf/gogoproto"
|
||||
proto "github.com/gogo/protobuf/proto"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
|
||||
|
||||
// GenesisState defines the staking module's genesis state.
|
||||
type GenesisState struct {
|
||||
// params defines all the paramaters of related to deposit.
|
||||
Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"`
|
||||
// last_total_power tracks the total amounts of bonded tokens recorded during
|
||||
// the previous end block.
|
||||
LastTotalPower github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,2,opt,name=last_total_power,json=lastTotalPower,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"last_total_power" yaml:"last_total_power"`
|
||||
// last_validator_powers is a special index that provides a historical list
|
||||
// of the last-block's bonded validators.
|
||||
LastValidatorPowers []LastValidatorPower `protobuf:"bytes,3,rep,name=last_validator_powers,json=lastValidatorPowers,proto3" json:"last_validator_powers" yaml:"last_validator_powers"`
|
||||
// delegations defines the validator set at genesis.
|
||||
Validators []Validator `protobuf:"bytes,4,rep,name=validators,proto3" json:"validators"`
|
||||
// delegations defines the delegations active at genesis.
|
||||
Delegations []Delegation `protobuf:"bytes,5,rep,name=delegations,proto3" json:"delegations"`
|
||||
// unbonding_delegations defines the unbonding delegations active at genesis.
|
||||
UnbondingDelegations []UnbondingDelegation `protobuf:"bytes,6,rep,name=unbonding_delegations,json=unbondingDelegations,proto3" json:"unbonding_delegations" yaml:"unbonding_delegations"`
|
||||
// redelegations defines the redelegations active at genesis.
|
||||
Redelegations []Redelegation `protobuf:"bytes,7,rep,name=redelegations,proto3" json:"redelegations"`
|
||||
Exported bool `protobuf:"varint,8,opt,name=exported,proto3" json:"exported,omitempty"`
|
||||
}
|
||||
|
||||
func (m *GenesisState) Reset() { *m = GenesisState{} }
|
||||
func (m *GenesisState) String() string { return proto.CompactTextString(m) }
|
||||
func (*GenesisState) ProtoMessage() {}
|
||||
func (*GenesisState) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_9b3dec8894f2831b, []int{0}
|
||||
}
|
||||
func (m *GenesisState) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
if deterministic {
|
||||
return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalToSizedBuffer(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b[:n], nil
|
||||
}
|
||||
}
|
||||
func (m *GenesisState) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_GenesisState.Merge(m, src)
|
||||
}
|
||||
func (m *GenesisState) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *GenesisState) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_GenesisState.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_GenesisState proto.InternalMessageInfo
|
||||
|
||||
func (m *GenesisState) GetParams() Params {
|
||||
if m != nil {
|
||||
return m.Params
|
||||
}
|
||||
return Params{}
|
||||
}
|
||||
|
||||
func (m *GenesisState) GetLastValidatorPowers() []LastValidatorPower {
|
||||
if m != nil {
|
||||
return m.LastValidatorPowers
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *GenesisState) GetValidators() []Validator {
|
||||
if m != nil {
|
||||
return m.Validators
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *GenesisState) GetDelegations() []Delegation {
|
||||
if m != nil {
|
||||
return m.Delegations
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *GenesisState) GetUnbondingDelegations() []UnbondingDelegation {
|
||||
if m != nil {
|
||||
return m.UnbondingDelegations
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *GenesisState) GetRedelegations() []Redelegation {
|
||||
if m != nil {
|
||||
return m.Redelegations
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *GenesisState) GetExported() bool {
|
||||
if m != nil {
|
||||
return m.Exported
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// LastValidatorPower required for validator set update logic.
|
||||
type LastValidatorPower struct {
|
||||
// address is the address of the validator.
|
||||
Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"`
|
||||
// power defines the power of the validator.
|
||||
Power int64 `protobuf:"varint,2,opt,name=power,proto3" json:"power,omitempty"`
|
||||
}
|
||||
|
||||
func (m *LastValidatorPower) Reset() { *m = LastValidatorPower{} }
|
||||
func (m *LastValidatorPower) String() string { return proto.CompactTextString(m) }
|
||||
func (*LastValidatorPower) ProtoMessage() {}
|
||||
func (*LastValidatorPower) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_9b3dec8894f2831b, []int{1}
|
||||
}
|
||||
func (m *LastValidatorPower) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *LastValidatorPower) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
if deterministic {
|
||||
return xxx_messageInfo_LastValidatorPower.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalToSizedBuffer(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b[:n], nil
|
||||
}
|
||||
}
|
||||
func (m *LastValidatorPower) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_LastValidatorPower.Merge(m, src)
|
||||
}
|
||||
func (m *LastValidatorPower) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *LastValidatorPower) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_LastValidatorPower.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_LastValidatorPower proto.InternalMessageInfo
|
||||
|
||||
func init() {
|
||||
// proto.RegisterType((*GenesisState)(nil), "cosmos.staking.v1beta1.GenesisState")
|
||||
// proto.RegisterType((*LastValidatorPower)(nil), "cosmos.staking.v1beta1.LastValidatorPower")
|
||||
}
|
||||
|
||||
func init() {
|
||||
// proto.RegisterFile("cosmos/staking/v1beta1/genesis.proto", fileDescriptor_9b3dec8894f2831b)
|
||||
}
|
||||
|
||||
var fileDescriptor_9b3dec8894f2831b = []byte{
|
||||
// 493 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x93, 0x3d, 0x6f, 0xd3, 0x40,
|
||||
0x18, 0xc7, 0x7d, 0xa4, 0x49, 0xc3, 0xa5, 0x20, 0x74, 0xa4, 0x60, 0x45, 0xc8, 0x0e, 0x56, 0x84,
|
||||
0x22, 0x5e, 0x6c, 0xb5, 0x6c, 0x15, 0x53, 0x84, 0xa8, 0x8a, 0x10, 0x8a, 0x8e, 0x97, 0x81, 0x25,
|
||||
0xba, 0xd4, 0x27, 0x63, 0xd5, 0xf1, 0x59, 0x7e, 0x2e, 0xa5, 0xdd, 0x11, 0x62, 0xe4, 0x23, 0xf4,
|
||||
0xe3, 0x74, 0xec, 0xc0, 0x80, 0x18, 0x2c, 0x94, 0x2c, 0xcc, 0xfd, 0x04, 0xc8, 0xe7, 0x17, 0x4c,
|
||||
0x52, 0x33, 0x25, 0x77, 0xfa, 0xfd, 0x7f, 0x7f, 0xfb, 0xfc, 0x1c, 0x1e, 0x1c, 0x0a, 0x98, 0x09,
|
||||
0x70, 0x40, 0xb2, 0x23, 0x3f, 0xf4, 0x9c, 0xe3, 0x9d, 0x29, 0x97, 0x6c, 0xc7, 0xf1, 0x78, 0xc8,
|
||||
0xc1, 0x07, 0x3b, 0x8a, 0x85, 0x14, 0xe4, 0x4e, 0x46, 0xd9, 0x39, 0x65, 0xe7, 0x54, 0xaf, 0xeb,
|
||||
0x09, 0x4f, 0x28, 0xc4, 0x49, 0xff, 0x65, 0x74, 0xaf, 0xce, 0x59, 0xa4, 0x15, 0x65, 0x7d, 0x6f,
|
||||
0xe2, 0xad, 0xfd, 0xac, 0xe5, 0x8d, 0x64, 0x92, 0x93, 0x67, 0xb8, 0x15, 0xb1, 0x98, 0xcd, 0x40,
|
||||
0x47, 0x7d, 0x34, 0xec, 0xec, 0x1a, 0xf6, 0xd5, 0xad, 0xf6, 0x58, 0x51, 0xa3, 0x8d, 0xf3, 0xc4,
|
||||
0xd4, 0x68, 0x9e, 0x21, 0x80, 0x6f, 0x05, 0x0c, 0xe4, 0x44, 0x0a, 0xc9, 0x82, 0x49, 0x24, 0x3e,
|
||||
0xf1, 0x58, 0xbf, 0xd6, 0x47, 0xc3, 0xad, 0xd1, 0x41, 0xca, 0xfd, 0x4c, 0xcc, 0x07, 0x9e, 0x2f,
|
||||
0x3f, 0xce, 0xa7, 0xf6, 0xa1, 0x98, 0x39, 0xf9, 0x13, 0x66, 0x3f, 0x4f, 0xc0, 0x3d, 0x72, 0xe4,
|
||||
0x69, 0xc4, 0xc1, 0x3e, 0x08, 0xe5, 0x65, 0x62, 0xde, 0x3d, 0x65, 0xb3, 0x60, 0xcf, 0x5a, 0xf5,
|
||||
0x59, 0xf4, 0x66, 0xba, 0xf5, 0x36, 0xdd, 0x19, 0xa7, 0x1b, 0xe4, 0x33, 0xc2, 0xdb, 0x8a, 0x3a,
|
||||
0x66, 0x81, 0xef, 0x32, 0x29, 0xe2, 0x8c, 0x04, 0xbd, 0xd1, 0x6f, 0x0c, 0x3b, 0xbb, 0x0f, 0xeb,
|
||||
0x5e, 0xe1, 0x15, 0x03, 0xf9, 0xbe, 0xc8, 0x28, 0xd7, 0x68, 0x90, 0x3e, 0xe6, 0x65, 0x62, 0xde,
|
||||
0xab, 0x94, 0xaf, 0x6a, 0x2d, 0x7a, 0x3b, 0x58, 0x4b, 0x02, 0xd9, 0xc7, 0xb8, 0x24, 0x41, 0xdf,
|
||||
0x50, 0xd5, 0xf7, 0xeb, 0xaa, 0xcb, 0x70, 0x7e, 0x80, 0x95, 0x28, 0x79, 0x89, 0x3b, 0x2e, 0x0f,
|
||||
0xb8, 0xc7, 0xa4, 0x2f, 0x42, 0xd0, 0x9b, 0xca, 0x64, 0xd5, 0x99, 0x9e, 0x97, 0x68, 0xae, 0xaa,
|
||||
0x86, 0xc9, 0x17, 0x84, 0xb7, 0xe7, 0xe1, 0x54, 0x84, 0xae, 0x1f, 0x7a, 0x93, 0xaa, 0xb6, 0xa5,
|
||||
0xb4, 0x8f, 0xea, 0xb4, 0xef, 0x8a, 0x50, 0xc5, 0xbf, 0x72, 0x38, 0x57, 0x7a, 0x2d, 0xda, 0x9d,
|
||||
0xaf, 0x47, 0x81, 0x8c, 0xf1, 0x8d, 0x98, 0x57, 0xfb, 0x37, 0x55, 0xff, 0xa0, 0xae, 0x9f, 0x56,
|
||||
0xe0, 0xfc, 0xc5, 0xfe, 0x15, 0x90, 0x1e, 0x6e, 0xf3, 0x93, 0x48, 0xc4, 0x92, 0xbb, 0x7a, 0xbb,
|
||||
0x8f, 0x86, 0x6d, 0x5a, 0xae, 0xad, 0xd7, 0x98, 0xac, 0x7f, 0x5c, 0xa2, 0xe3, 0x4d, 0xe6, 0xba,
|
||||
0x31, 0x87, 0x6c, 0xb8, 0xaf, 0xd3, 0x62, 0x49, 0xba, 0xb8, 0xf9, 0x77, 0x58, 0x1b, 0x34, 0x5b,
|
||||
0xec, 0xb5, 0xbf, 0x9e, 0x99, 0xda, 0xef, 0x33, 0x53, 0x1b, 0xbd, 0x38, 0x5f, 0x18, 0xe8, 0x62,
|
||||
0x61, 0xa0, 0x5f, 0x0b, 0x03, 0x7d, 0x5b, 0x1a, 0xda, 0xc5, 0xd2, 0xd0, 0x7e, 0x2c, 0x0d, 0xed,
|
||||
0xc3, 0xe3, 0xff, 0xce, 0xf3, 0x49, 0x79, 0xfd, 0xd4, 0x64, 0x4f, 0x5b, 0xea, 0xd6, 0x3d, 0xfd,
|
||||
0x13, 0x00, 0x00, 0xff, 0xff, 0xff, 0x85, 0xad, 0xc8, 0xf1, 0x03, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func (m *GenesisState) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dAtA[:n], nil
|
||||
}
|
||||
|
||||
func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if m.Exported {
|
||||
i--
|
||||
if m.Exported {
|
||||
dAtA[i] = 1
|
||||
} else {
|
||||
dAtA[i] = 0
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0x40
|
||||
}
|
||||
if len(m.Redelegations) > 0 {
|
||||
for iNdEx := len(m.Redelegations) - 1; iNdEx >= 0; iNdEx-- {
|
||||
{
|
||||
size, err := m.Redelegations[iNdEx].MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(size))
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0x3a
|
||||
}
|
||||
}
|
||||
if len(m.UnbondingDelegations) > 0 {
|
||||
for iNdEx := len(m.UnbondingDelegations) - 1; iNdEx >= 0; iNdEx-- {
|
||||
{
|
||||
size, err := m.UnbondingDelegations[iNdEx].MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(size))
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0x32
|
||||
}
|
||||
}
|
||||
if len(m.Delegations) > 0 {
|
||||
for iNdEx := len(m.Delegations) - 1; iNdEx >= 0; iNdEx-- {
|
||||
{
|
||||
size, err := m.Delegations[iNdEx].MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(size))
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0x2a
|
||||
}
|
||||
}
|
||||
if len(m.Validators) > 0 {
|
||||
for iNdEx := len(m.Validators) - 1; iNdEx >= 0; iNdEx-- {
|
||||
{
|
||||
size, err := m.Validators[iNdEx].MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(size))
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0x22
|
||||
}
|
||||
}
|
||||
if len(m.LastValidatorPowers) > 0 {
|
||||
for iNdEx := len(m.LastValidatorPowers) - 1; iNdEx >= 0; iNdEx-- {
|
||||
{
|
||||
size, err := m.LastValidatorPowers[iNdEx].MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(size))
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0x1a
|
||||
}
|
||||
}
|
||||
{
|
||||
size := m.LastTotalPower.Size()
|
||||
i -= size
|
||||
if _, err := m.LastTotalPower.MarshalTo(dAtA[i:]); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(size))
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0x12
|
||||
{
|
||||
size, err := m.Params.MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(size))
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0xa
|
||||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func (m *LastValidatorPower) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dAtA[:n], nil
|
||||
}
|
||||
|
||||
func (m *LastValidatorPower) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *LastValidatorPower) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if m.Power != 0 {
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(m.Power))
|
||||
i--
|
||||
dAtA[i] = 0x10
|
||||
}
|
||||
if len(m.Address) > 0 {
|
||||
i -= len(m.Address)
|
||||
copy(dAtA[i:], m.Address)
|
||||
i = encodeVarintGenesis(dAtA, i, uint64(len(m.Address)))
|
||||
i--
|
||||
dAtA[i] = 0xa
|
||||
}
|
||||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int {
|
||||
offset -= sovGenesis(v)
|
||||
base := offset
|
||||
for v >= 1<<7 {
|
||||
dAtA[offset] = uint8(v&0x7f | 0x80)
|
||||
v >>= 7
|
||||
offset++
|
||||
}
|
||||
dAtA[offset] = uint8(v)
|
||||
return base
|
||||
}
|
||||
func (m *GenesisState) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
l = m.Params.Size()
|
||||
n += 1 + l + sovGenesis(uint64(l))
|
||||
l = m.LastTotalPower.Size()
|
||||
n += 1 + l + sovGenesis(uint64(l))
|
||||
if len(m.LastValidatorPowers) > 0 {
|
||||
for _, e := range m.LastValidatorPowers {
|
||||
l = e.Size()
|
||||
n += 1 + l + sovGenesis(uint64(l))
|
||||
}
|
||||
}
|
||||
if len(m.Validators) > 0 {
|
||||
for _, e := range m.Validators {
|
||||
l = e.Size()
|
||||
n += 1 + l + sovGenesis(uint64(l))
|
||||
}
|
||||
}
|
||||
if len(m.Delegations) > 0 {
|
||||
for _, e := range m.Delegations {
|
||||
l = e.Size()
|
||||
n += 1 + l + sovGenesis(uint64(l))
|
||||
}
|
||||
}
|
||||
if len(m.UnbondingDelegations) > 0 {
|
||||
for _, e := range m.UnbondingDelegations {
|
||||
l = e.Size()
|
||||
n += 1 + l + sovGenesis(uint64(l))
|
||||
}
|
||||
}
|
||||
if len(m.Redelegations) > 0 {
|
||||
for _, e := range m.Redelegations {
|
||||
l = e.Size()
|
||||
n += 1 + l + sovGenesis(uint64(l))
|
||||
}
|
||||
}
|
||||
if m.Exported {
|
||||
n += 2
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (m *LastValidatorPower) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
l = len(m.Address)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovGenesis(uint64(l))
|
||||
}
|
||||
if m.Power != 0 {
|
||||
n += 1 + sovGenesis(uint64(m.Power))
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func sovGenesis(x uint64) (n int) {
|
||||
return (math_bits.Len64(x|1) + 6) / 7
|
||||
}
|
||||
func sozGenesis(x uint64) (n int) {
|
||||
return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63))))
|
||||
}
|
||||
func (m *GenesisState) Unmarshal(dAtA []byte) error {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
preIndex := iNdEx
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
fieldNum := int32(wire >> 3)
|
||||
wireType := int(wire & 0x7)
|
||||
if wireType == 4 {
|
||||
return fmt.Errorf("proto: GenesisState: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType)
|
||||
}
|
||||
var msglen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
msglen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if msglen < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
postIndex := iNdEx + msglen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
iNdEx = postIndex
|
||||
case 2:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field LastTotalPower", wireType)
|
||||
}
|
||||
var byteLen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
byteLen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if byteLen < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
postIndex := iNdEx + byteLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
if err := m.LastTotalPower.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
iNdEx = postIndex
|
||||
case 3:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field LastValidatorPowers", wireType)
|
||||
}
|
||||
var msglen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
msglen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if msglen < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
postIndex := iNdEx + msglen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.LastValidatorPowers = append(m.LastValidatorPowers, LastValidatorPower{})
|
||||
if err := m.LastValidatorPowers[len(m.LastValidatorPowers)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
iNdEx = postIndex
|
||||
case 4:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Validators", wireType)
|
||||
}
|
||||
var msglen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
msglen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if msglen < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
postIndex := iNdEx + msglen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Validators = append(m.Validators, Validator{})
|
||||
if err := m.Validators[len(m.Validators)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
iNdEx = postIndex
|
||||
case 5:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Delegations", wireType)
|
||||
}
|
||||
var msglen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
msglen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if msglen < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
postIndex := iNdEx + msglen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Delegations = append(m.Delegations, Delegation{})
|
||||
if err := m.Delegations[len(m.Delegations)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
iNdEx = postIndex
|
||||
case 6:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field UnbondingDelegations", wireType)
|
||||
}
|
||||
var msglen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
msglen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if msglen < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
postIndex := iNdEx + msglen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.UnbondingDelegations = append(m.UnbondingDelegations, UnbondingDelegation{})
|
||||
if err := m.UnbondingDelegations[len(m.UnbondingDelegations)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
iNdEx = postIndex
|
||||
case 7:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Redelegations", wireType)
|
||||
}
|
||||
var msglen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
msglen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if msglen < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
postIndex := iNdEx + msglen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Redelegations = append(m.Redelegations, Redelegation{})
|
||||
if err := m.Redelegations[len(m.Redelegations)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
iNdEx = postIndex
|
||||
case 8:
|
||||
if wireType != 0 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Exported", wireType)
|
||||
}
|
||||
var v int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
v |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
m.Exported = bool(v != 0)
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := skipGenesis(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if (skippy < 0) || (iNdEx+skippy) < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (m *LastValidatorPower) Unmarshal(dAtA []byte) error {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
preIndex := iNdEx
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
fieldNum := int32(wire >> 3)
|
||||
wireType := int(wire & 0x7)
|
||||
if wireType == 4 {
|
||||
return fmt.Errorf("proto: LastValidatorPower: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return fmt.Errorf("proto: LastValidatorPower: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType)
|
||||
}
|
||||
var stringLen uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
stringLen |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
intStringLen := int(stringLen)
|
||||
if intStringLen < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
postIndex := iNdEx + intStringLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Address = string(dAtA[iNdEx:postIndex])
|
||||
iNdEx = postIndex
|
||||
case 2:
|
||||
if wireType != 0 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Power", wireType)
|
||||
}
|
||||
m.Power = 0
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
m.Power |= int64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := skipGenesis(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if (skippy < 0) || (iNdEx+skippy) < 0 {
|
||||
return ErrInvalidLengthGenesis
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func skipGenesis(dAtA []byte) (n int, err error) {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
depth := 0
|
||||
for iNdEx < l {
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= (uint64(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
wireType := int(wire & 0x7)
|
||||
switch wireType {
|
||||
case 0:
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx++
|
||||
if dAtA[iNdEx-1] < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
case 1:
|
||||
iNdEx += 8
|
||||
case 2:
|
||||
var length int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return 0, ErrIntOverflowGenesis
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
length |= (int(b) & 0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if length < 0 {
|
||||
return 0, ErrInvalidLengthGenesis
|
||||
}
|
||||
iNdEx += length
|
||||
case 3:
|
||||
depth++
|
||||
case 4:
|
||||
if depth == 0 {
|
||||
return 0, ErrUnexpectedEndOfGroupGenesis
|
||||
}
|
||||
depth--
|
||||
case 5:
|
||||
iNdEx += 4
|
||||
default:
|
||||
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
|
||||
}
|
||||
if iNdEx < 0 {
|
||||
return 0, ErrInvalidLengthGenesis
|
||||
}
|
||||
if depth == 0 {
|
||||
return iNdEx, nil
|
||||
}
|
||||
}
|
||||
return 0, io.ErrUnexpectedEOF
|
||||
}
|
||||
|
||||
var (
|
||||
ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling")
|
||||
ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow")
|
||||
ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group")
|
||||
)
|
|
@ -6,19 +6,18 @@ import (
|
|||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v034"
|
||||
v038staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v038"
|
||||
v040staking "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
func migrateBondStatus(oldStatus v034staking.BondStatus) v040staking.BondStatus {
|
||||
func migrateBondStatus(oldStatus v034staking.BondStatus) BondStatus {
|
||||
switch oldStatus {
|
||||
case v034staking.Unbonded:
|
||||
return v040staking.Unbonded
|
||||
return Unbonded
|
||||
|
||||
case v034staking.Unbonding:
|
||||
return v040staking.Unbonding
|
||||
return Unbonding
|
||||
|
||||
case v034staking.Bonded:
|
||||
return v040staking.Bonded
|
||||
return Bonded
|
||||
|
||||
default:
|
||||
panic(fmt.Errorf("invalid bond status %d", oldStatus))
|
||||
|
@ -31,29 +30,29 @@ func migrateBondStatus(oldStatus v034staking.BondStatus) v040staking.BondStatus
|
|||
// - Convert addresses from bytes to bech32 strings.
|
||||
// - Update BondStatus staking constants.
|
||||
// - Re-encode in v0.40 GenesisState.
|
||||
func Migrate(stakingState v038staking.GenesisState) *v040staking.GenesisState {
|
||||
newLastValidatorPowers := make([]v040staking.LastValidatorPower, len(stakingState.LastValidatorPowers))
|
||||
func Migrate(stakingState v038staking.GenesisState) *GenesisState {
|
||||
newLastValidatorPowers := make([]LastValidatorPower, len(stakingState.LastValidatorPowers))
|
||||
for i, oldLastValidatorPower := range stakingState.LastValidatorPowers {
|
||||
newLastValidatorPowers[i] = v040staking.LastValidatorPower{
|
||||
newLastValidatorPowers[i] = LastValidatorPower{
|
||||
Address: oldLastValidatorPower.Address.String(),
|
||||
Power: oldLastValidatorPower.Power,
|
||||
}
|
||||
}
|
||||
|
||||
newValidators := make([]v040staking.Validator, len(stakingState.Validators))
|
||||
newValidators := make([]Validator, len(stakingState.Validators))
|
||||
for i, oldValidator := range stakingState.Validators {
|
||||
pkAny, err := codectypes.NewAnyWithValue(oldValidator.ConsPubKey)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Can't pack validator consensus PK as Any: %s", err))
|
||||
}
|
||||
newValidators[i] = v040staking.Validator{
|
||||
newValidators[i] = Validator{
|
||||
OperatorAddress: oldValidator.OperatorAddress.String(),
|
||||
ConsensusPubkey: pkAny,
|
||||
Jailed: oldValidator.Jailed,
|
||||
Status: migrateBondStatus(oldValidator.Status),
|
||||
Tokens: oldValidator.Tokens,
|
||||
DelegatorShares: oldValidator.DelegatorShares,
|
||||
Description: v040staking.Description{
|
||||
Description: Description{
|
||||
Moniker: oldValidator.Description.Moniker,
|
||||
Identity: oldValidator.Description.Identity,
|
||||
Website: oldValidator.Description.Website,
|
||||
|
@ -62,8 +61,8 @@ func Migrate(stakingState v038staking.GenesisState) *v040staking.GenesisState {
|
|||
},
|
||||
UnbondingHeight: oldValidator.UnbondingHeight,
|
||||
UnbondingTime: oldValidator.UnbondingCompletionTime,
|
||||
Commission: v040staking.Commission{
|
||||
CommissionRates: v040staking.CommissionRates{
|
||||
Commission: Commission{
|
||||
CommissionRates: CommissionRates{
|
||||
Rate: oldValidator.Commission.Rate,
|
||||
MaxRate: oldValidator.Commission.MaxRate,
|
||||
MaxChangeRate: oldValidator.Commission.MaxChangeRate,
|
||||
|
@ -74,20 +73,20 @@ func Migrate(stakingState v038staking.GenesisState) *v040staking.GenesisState {
|
|||
}
|
||||
}
|
||||
|
||||
newDelegations := make([]v040staking.Delegation, len(stakingState.Delegations))
|
||||
newDelegations := make([]Delegation, len(stakingState.Delegations))
|
||||
for i, oldDelegation := range stakingState.Delegations {
|
||||
newDelegations[i] = v040staking.Delegation{
|
||||
newDelegations[i] = Delegation{
|
||||
DelegatorAddress: oldDelegation.DelegatorAddress.String(),
|
||||
ValidatorAddress: oldDelegation.ValidatorAddress.String(),
|
||||
Shares: oldDelegation.Shares,
|
||||
}
|
||||
}
|
||||
|
||||
newUnbondingDelegations := make([]v040staking.UnbondingDelegation, len(stakingState.UnbondingDelegations))
|
||||
newUnbondingDelegations := make([]UnbondingDelegation, len(stakingState.UnbondingDelegations))
|
||||
for i, oldUnbondingDelegation := range stakingState.UnbondingDelegations {
|
||||
newEntries := make([]v040staking.UnbondingDelegationEntry, len(oldUnbondingDelegation.Entries))
|
||||
newEntries := make([]UnbondingDelegationEntry, len(oldUnbondingDelegation.Entries))
|
||||
for j, oldEntry := range oldUnbondingDelegation.Entries {
|
||||
newEntries[j] = v040staking.UnbondingDelegationEntry{
|
||||
newEntries[j] = UnbondingDelegationEntry{
|
||||
CreationHeight: oldEntry.CreationHeight,
|
||||
CompletionTime: oldEntry.CompletionTime,
|
||||
InitialBalance: oldEntry.InitialBalance,
|
||||
|
@ -95,18 +94,18 @@ func Migrate(stakingState v038staking.GenesisState) *v040staking.GenesisState {
|
|||
}
|
||||
}
|
||||
|
||||
newUnbondingDelegations[i] = v040staking.UnbondingDelegation{
|
||||
newUnbondingDelegations[i] = UnbondingDelegation{
|
||||
DelegatorAddress: oldUnbondingDelegation.DelegatorAddress.String(),
|
||||
ValidatorAddress: oldUnbondingDelegation.ValidatorAddress.String(),
|
||||
Entries: newEntries,
|
||||
}
|
||||
}
|
||||
|
||||
newRedelegations := make([]v040staking.Redelegation, len(stakingState.Redelegations))
|
||||
newRedelegations := make([]Redelegation, len(stakingState.Redelegations))
|
||||
for i, oldRedelegation := range stakingState.Redelegations {
|
||||
newEntries := make([]v040staking.RedelegationEntry, len(oldRedelegation.Entries))
|
||||
newEntries := make([]RedelegationEntry, len(oldRedelegation.Entries))
|
||||
for j, oldEntry := range oldRedelegation.Entries {
|
||||
newEntries[j] = v040staking.RedelegationEntry{
|
||||
newEntries[j] = RedelegationEntry{
|
||||
CreationHeight: oldEntry.CreationHeight,
|
||||
CompletionTime: oldEntry.CompletionTime,
|
||||
InitialBalance: oldEntry.InitialBalance,
|
||||
|
@ -114,7 +113,7 @@ func Migrate(stakingState v038staking.GenesisState) *v040staking.GenesisState {
|
|||
}
|
||||
}
|
||||
|
||||
newRedelegations[i] = v040staking.Redelegation{
|
||||
newRedelegations[i] = Redelegation{
|
||||
DelegatorAddress: oldRedelegation.DelegatorAddress.String(),
|
||||
ValidatorSrcAddress: oldRedelegation.ValidatorSrcAddress.String(),
|
||||
ValidatorDstAddress: oldRedelegation.ValidatorDstAddress.String(),
|
||||
|
@ -122,14 +121,13 @@ func Migrate(stakingState v038staking.GenesisState) *v040staking.GenesisState {
|
|||
}
|
||||
}
|
||||
|
||||
return &v040staking.GenesisState{
|
||||
Params: v040staking.Params{
|
||||
return &GenesisState{
|
||||
Params: Params{
|
||||
UnbondingTime: stakingState.Params.UnbondingTime,
|
||||
MaxValidators: uint32(stakingState.Params.MaxValidators),
|
||||
MaxEntries: uint32(stakingState.Params.MaxEntries),
|
||||
HistoricalEntries: uint32(stakingState.Params.HistoricalEntries),
|
||||
BondDenom: stakingState.Params.BondDenom,
|
||||
PowerReduction: v040staking.DefaultParams().PowerReduction,
|
||||
},
|
||||
LastTotalPower: stakingState.LastTotalPower,
|
||||
LastValidatorPowers: newLastValidatorPowers,
|
||||
|
|
|
@ -55,7 +55,6 @@ func TestMigrate(t *testing.T) {
|
|||
"historical_entries": 0,
|
||||
"max_entries": 0,
|
||||
"max_validators": 0,
|
||||
"power_reduction": "1000000",
|
||||
"unbonding_time": "0s"
|
||||
},
|
||||
"redelegations": [],
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,201 @@
|
|||
package v040
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// Staking params default values
|
||||
const (
|
||||
// DefaultUnbondingTime reflects three weeks in seconds as the default
|
||||
// unbonding time.
|
||||
// TODO: Justify our choice of default here.
|
||||
DefaultUnbondingTime time.Duration = time.Hour * 24 * 7 * 3
|
||||
|
||||
// Default maximum number of bonded validators
|
||||
DefaultMaxValidators uint32 = 100
|
||||
|
||||
// Default maximum entries in a UBD/RED pair
|
||||
DefaultMaxEntries uint32 = 7
|
||||
|
||||
// DefaultHistorical entries is 10000. Apps that don't use IBC can ignore this
|
||||
// value by not adding the staking module to the application module manager's
|
||||
// SetOrderBeginBlockers.
|
||||
DefaultHistoricalEntries uint32 = 10000
|
||||
)
|
||||
|
||||
// NewParams creates a new Params instance
|
||||
func NewParams(unbondingTime time.Duration, maxValidators, maxEntries, historicalEntries uint32, bondDenom string) Params {
|
||||
return Params{
|
||||
UnbondingTime: unbondingTime,
|
||||
MaxValidators: maxValidators,
|
||||
MaxEntries: maxEntries,
|
||||
HistoricalEntries: historicalEntries,
|
||||
BondDenom: bondDenom,
|
||||
}
|
||||
}
|
||||
|
||||
// String returns a human readable string representation of the parameters.
|
||||
func (p Params) String() string {
|
||||
out, _ := yaml.Marshal(p)
|
||||
return string(out)
|
||||
}
|
||||
|
||||
func DefaultParams() Params {
|
||||
return NewParams(
|
||||
DefaultUnbondingTime,
|
||||
DefaultMaxValidators,
|
||||
DefaultMaxEntries,
|
||||
DefaultHistoricalEntries,
|
||||
sdk.DefaultBondDenom,
|
||||
)
|
||||
}
|
||||
|
||||
// String implements the Stringer interface for a Commission object.
|
||||
func (c Commission) String() string {
|
||||
out, _ := yaml.Marshal(c)
|
||||
return string(out)
|
||||
}
|
||||
|
||||
// String implements the Stringer interface for a CommissionRates object.
|
||||
func (cr CommissionRates) String() string {
|
||||
out, _ := yaml.Marshal(cr)
|
||||
return string(out)
|
||||
}
|
||||
|
||||
// String implements the Stringer interface for a DVPair object.
|
||||
func (dv DVPair) String() string {
|
||||
out, _ := yaml.Marshal(dv)
|
||||
return string(out)
|
||||
}
|
||||
|
||||
// String implements the Stringer interface for a DVVTriplet object.
|
||||
func (dvv DVVTriplet) String() string {
|
||||
out, _ := yaml.Marshal(dvv)
|
||||
return string(out)
|
||||
}
|
||||
|
||||
// String returns a human readable string representation of a Delegation.
|
||||
func (d Delegation) String() string {
|
||||
out, _ := yaml.Marshal(d)
|
||||
return string(out)
|
||||
}
|
||||
|
||||
// Delegations is a collection of delegations
|
||||
type Delegations []Delegation
|
||||
|
||||
func (d Delegations) String() (out string) {
|
||||
for _, del := range d {
|
||||
out += del.String() + "\n"
|
||||
}
|
||||
|
||||
return strings.TrimSpace(out)
|
||||
}
|
||||
|
||||
// String implements the stringer interface for a UnbondingDelegationEntry.
|
||||
func (e UnbondingDelegationEntry) String() string {
|
||||
out, _ := yaml.Marshal(e)
|
||||
return string(out)
|
||||
}
|
||||
|
||||
// String returns a human readable string representation of an UnbondingDelegation.
|
||||
func (ubd UnbondingDelegation) String() string {
|
||||
out := fmt.Sprintf(`Unbonding Delegations between:
|
||||
Delegator: %s
|
||||
Validator: %s
|
||||
Entries:`, ubd.DelegatorAddress, ubd.ValidatorAddress)
|
||||
for i, entry := range ubd.Entries {
|
||||
out += fmt.Sprintf(` Unbonding Delegation %d:
|
||||
Creation Height: %v
|
||||
Min time to unbond (unix): %v
|
||||
Expected balance: %s`, i, entry.CreationHeight,
|
||||
entry.CompletionTime, entry.Balance)
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
// UnbondingDelegations is a collection of UnbondingDelegation
|
||||
type UnbondingDelegations []UnbondingDelegation
|
||||
|
||||
func (ubds UnbondingDelegations) String() (out string) {
|
||||
for _, u := range ubds {
|
||||
out += u.String() + "\n"
|
||||
}
|
||||
|
||||
return strings.TrimSpace(out)
|
||||
}
|
||||
|
||||
// String implements the Stringer interface for a RedelegationEntry object.
|
||||
func (e RedelegationEntry) String() string {
|
||||
out, _ := yaml.Marshal(e)
|
||||
return string(out)
|
||||
}
|
||||
|
||||
// String returns a human readable string representation of a Redelegation.
|
||||
func (red Redelegation) String() string {
|
||||
out := fmt.Sprintf(`Redelegations between:
|
||||
Delegator: %s
|
||||
Source Validator: %s
|
||||
Destination Validator: %s
|
||||
Entries:
|
||||
`,
|
||||
red.DelegatorAddress, red.ValidatorSrcAddress, red.ValidatorDstAddress,
|
||||
)
|
||||
|
||||
for i, entry := range red.Entries {
|
||||
out += fmt.Sprintf(` Redelegation Entry #%d:
|
||||
Creation height: %v
|
||||
Min time to unbond (unix): %v
|
||||
Dest Shares: %s
|
||||
`,
|
||||
i, entry.CreationHeight, entry.CompletionTime, entry.SharesDst,
|
||||
)
|
||||
}
|
||||
|
||||
return strings.TrimRight(out, "\n")
|
||||
}
|
||||
|
||||
// Redelegations are a collection of Redelegation
|
||||
type Redelegations []Redelegation
|
||||
|
||||
func (d Redelegations) String() (out string) {
|
||||
for _, red := range d {
|
||||
out += red.String() + "\n"
|
||||
}
|
||||
|
||||
return strings.TrimSpace(out)
|
||||
}
|
||||
|
||||
// String implements the Stringer interface for DelegationResponse.
|
||||
func (d DelegationResponse) String() string {
|
||||
return fmt.Sprintf("%s\n Balance: %s", d.Delegation.String(), d.Balance)
|
||||
}
|
||||
|
||||
// String implements the Stringer interface for a Validator object.
|
||||
func (v Validator) String() string {
|
||||
out, _ := yaml.Marshal(v)
|
||||
return string(out)
|
||||
}
|
||||
|
||||
// Validators is a collection of Validator
|
||||
type Validators []Validator
|
||||
|
||||
func (v Validators) String() (out string) {
|
||||
for _, val := range v {
|
||||
out += val.String() + "\n"
|
||||
}
|
||||
|
||||
return strings.TrimSpace(out)
|
||||
}
|
||||
|
||||
// String implements the Stringer interface for a Description object.
|
||||
func (d Description) String() string {
|
||||
out, _ := yaml.Marshal(d)
|
||||
return string(out)
|
||||
}
|
|
@ -0,0 +1,138 @@
|
|||
package v043
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
v040staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v040"
|
||||
v043staking "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
// MigrateJSON accepts exported v0.40 x/gov genesis state and migrates it to
|
||||
// v0.43 x/gov genesis state. The migration includes:
|
||||
//
|
||||
// - Gov weighted votes.
|
||||
func MigrateJSON(oldState *v040staking.GenesisState) *v043staking.GenesisState {
|
||||
return &v043staking.GenesisState{
|
||||
Params: migrateParams(oldState.Params),
|
||||
LastTotalPower: oldState.LastTotalPower,
|
||||
LastValidatorPowers: migrateLastValidatorPowers(oldState.LastValidatorPowers),
|
||||
Validators: migrateValidators(oldState.Validators),
|
||||
Delegations: migrateDelegations(oldState.Delegations),
|
||||
UnbondingDelegations: migrateUnbondingDelegations(oldState.UnbondingDelegations),
|
||||
Redelegations: migrateRedelegations(oldState.Redelegations),
|
||||
Exported: oldState.Exported,
|
||||
}
|
||||
}
|
||||
|
||||
func migrateParams(oldParams v040staking.Params) v043staking.Params {
|
||||
return v043staking.NewParams(
|
||||
oldParams.UnbondingTime,
|
||||
oldParams.MaxValidators,
|
||||
oldParams.MaxEntries,
|
||||
oldParams.HistoricalEntries,
|
||||
oldParams.BondDenom,
|
||||
sdk.DefaultPowerReduction,
|
||||
)
|
||||
}
|
||||
|
||||
func migrateLastValidatorPowers(oldLastValidatorPowers []v040staking.LastValidatorPower) []v043staking.LastValidatorPower {
|
||||
newLastValidatorPowers := make([]v043staking.LastValidatorPower, len(oldLastValidatorPowers))
|
||||
for i, oldLastValidatorPower := range oldLastValidatorPowers {
|
||||
newLastValidatorPowers[i] = v043staking.LastValidatorPower{
|
||||
Address: oldLastValidatorPower.Address,
|
||||
Power: oldLastValidatorPower.Power,
|
||||
}
|
||||
}
|
||||
return newLastValidatorPowers
|
||||
}
|
||||
|
||||
func migrateValidators(oldValidators []v040staking.Validator) []v043staking.Validator {
|
||||
newValidators := make([]v043staking.Validator, len(oldValidators))
|
||||
|
||||
for i, oldValidator := range oldValidators {
|
||||
newValidators[i] = v043staking.Validator{
|
||||
OperatorAddress: oldValidator.OperatorAddress,
|
||||
ConsensusPubkey: oldValidator.ConsensusPubkey,
|
||||
Jailed: oldValidator.Jailed,
|
||||
Status: v043staking.BondStatus(oldValidator.Status),
|
||||
Tokens: oldValidator.Tokens,
|
||||
DelegatorShares: oldValidator.DelegatorShares,
|
||||
Description: v043staking.Description{
|
||||
Moniker: oldValidator.Description.Moniker,
|
||||
Identity: oldValidator.Description.Identity,
|
||||
Website: oldValidator.Description.Website,
|
||||
SecurityContact: oldValidator.Description.SecurityContact,
|
||||
Details: oldValidator.Description.Details,
|
||||
},
|
||||
UnbondingHeight: oldValidator.UnbondingHeight,
|
||||
UnbondingTime: oldValidator.UnbondingTime,
|
||||
Commission: v043staking.Commission{
|
||||
CommissionRates: v043staking.CommissionRates{
|
||||
Rate: oldValidator.Commission.CommissionRates.Rate,
|
||||
MaxRate: oldValidator.Commission.CommissionRates.MaxRate,
|
||||
MaxChangeRate: oldValidator.Commission.CommissionRates.MaxChangeRate,
|
||||
},
|
||||
UpdateTime: oldValidator.Commission.UpdateTime,
|
||||
},
|
||||
MinSelfDelegation: oldValidator.MinSelfDelegation,
|
||||
}
|
||||
}
|
||||
|
||||
return newValidators
|
||||
}
|
||||
|
||||
func migrateDelegations(oldDelegations []v040staking.Delegation) []v043staking.Delegation {
|
||||
newDelegations := make([]v043staking.Delegation, len(oldDelegations))
|
||||
for i, oldDelegation := range oldDelegations {
|
||||
newDelegations[i] = v043staking.Delegation{
|
||||
DelegatorAddress: oldDelegation.DelegatorAddress,
|
||||
ValidatorAddress: oldDelegation.ValidatorAddress,
|
||||
Shares: oldDelegation.Shares,
|
||||
}
|
||||
}
|
||||
return newDelegations
|
||||
}
|
||||
|
||||
func migrateUnbondingDelegations(oldUnbondingDelegations []v040staking.UnbondingDelegation) []v043staking.UnbondingDelegation {
|
||||
newUnbondingDelegations := make([]v043staking.UnbondingDelegation, len(oldUnbondingDelegations))
|
||||
for i, oldUnbondingDelegation := range oldUnbondingDelegations {
|
||||
newEntries := make([]v043staking.UnbondingDelegationEntry, len(oldUnbondingDelegation.Entries))
|
||||
for j, oldEntry := range oldUnbondingDelegation.Entries {
|
||||
newEntries[j] = v043staking.UnbondingDelegationEntry{
|
||||
CreationHeight: oldEntry.CreationHeight,
|
||||
CompletionTime: oldEntry.CompletionTime,
|
||||
InitialBalance: oldEntry.InitialBalance,
|
||||
Balance: oldEntry.Balance,
|
||||
}
|
||||
}
|
||||
|
||||
newUnbondingDelegations[i] = v043staking.UnbondingDelegation{
|
||||
DelegatorAddress: oldUnbondingDelegation.DelegatorAddress,
|
||||
ValidatorAddress: oldUnbondingDelegation.ValidatorAddress,
|
||||
Entries: newEntries,
|
||||
}
|
||||
}
|
||||
return newUnbondingDelegations
|
||||
}
|
||||
|
||||
func migrateRedelegations(oldRedelegations []v040staking.Redelegation) []v043staking.Redelegation {
|
||||
newRedelegations := make([]v043staking.Redelegation, len(oldRedelegations))
|
||||
for i, oldRedelegation := range oldRedelegations {
|
||||
newEntries := make([]v043staking.RedelegationEntry, len(oldRedelegation.Entries))
|
||||
for j, oldEntry := range oldRedelegation.Entries {
|
||||
newEntries[j] = v043staking.RedelegationEntry{
|
||||
CreationHeight: oldEntry.CreationHeight,
|
||||
CompletionTime: oldEntry.CompletionTime,
|
||||
InitialBalance: oldEntry.InitialBalance,
|
||||
SharesDst: oldEntry.SharesDst,
|
||||
}
|
||||
}
|
||||
|
||||
newRedelegations[i] = v043staking.Redelegation{
|
||||
DelegatorAddress: oldRedelegation.DelegatorAddress,
|
||||
ValidatorSrcAddress: oldRedelegation.ValidatorSrcAddress,
|
||||
ValidatorDstAddress: oldRedelegation.ValidatorDstAddress,
|
||||
Entries: newEntries,
|
||||
}
|
||||
}
|
||||
return newRedelegations
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package v043_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
v040staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v040"
|
||||
v043staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v043"
|
||||
)
|
||||
|
||||
func TestMigrateJSON(t *testing.T) {
|
||||
encodingConfig := simapp.MakeTestEncodingConfig()
|
||||
clientCtx := client.Context{}.
|
||||
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
|
||||
WithTxConfig(encodingConfig.TxConfig).
|
||||
WithJSONMarshaler(encodingConfig.Marshaler)
|
||||
|
||||
// voter, err := sdk.AccAddressFromBech32("cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh")
|
||||
// require.NoError(t, err)
|
||||
stakingGenState := &v040staking.GenesisState{
|
||||
Params: v040staking.DefaultParams(),
|
||||
}
|
||||
|
||||
migrated := v043staking.MigrateJSON(stakingGenState)
|
||||
|
||||
require.True(t, migrated.Params.PowerReduction.Equal(sdk.DefaultPowerReduction))
|
||||
|
||||
bz, err := clientCtx.JSONMarshaler.MarshalJSON(migrated)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Indent the JSON bz correctly.
|
||||
var jsonObj map[string]interface{}
|
||||
err = json.Unmarshal(bz, &jsonObj)
|
||||
require.NoError(t, err)
|
||||
indentedBz, err := json.MarshalIndent(jsonObj, "", "\t")
|
||||
require.NoError(t, err)
|
||||
|
||||
// Make sure about:
|
||||
// - Votes are all ADR-037 weighted votes with weight 1.
|
||||
expected := `{
|
||||
"delegations": [],
|
||||
"exported": false,
|
||||
"last_total_power": "0",
|
||||
"last_validator_powers": [],
|
||||
"params": {
|
||||
"bond_denom": "stake",
|
||||
"historical_entries": 10000,
|
||||
"max_entries": 7,
|
||||
"max_validators": 100,
|
||||
"power_reduction": "1000000",
|
||||
"unbonding_time": "1814400s"
|
||||
},
|
||||
"redelegations": [],
|
||||
"unbonding_delegations": [],
|
||||
"validators": []
|
||||
}`
|
||||
|
||||
fmt.Println(string(indentedBz))
|
||||
|
||||
require.Equal(t, expected, string(indentedBz))
|
||||
}
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/cosmos/cosmos-sdk/types/address"
|
||||
v040auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v040"
|
||||
v043distribution "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v043"
|
||||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
||||
v040staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v040"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
@ -54,11 +55,16 @@ func migrateValidatorsByPowerIndexKey(store sdk.KVStore) {
|
|||
}
|
||||
}
|
||||
|
||||
// MigrateStore performs in-place store migrations from v0.40 to v0.42. The
|
||||
func migrateParamsStore(ctx sdk.Context, paramstore paramtypes.Subspace) {
|
||||
paramstore.WithKeyTable(types.ParamKeyTable())
|
||||
paramstore.Set(ctx, types.KeyPowerReduction, sdk.DefaultPowerReduction)
|
||||
}
|
||||
|
||||
// MigrateStore performs in-place store migrations from v0.40 to v0.43. The
|
||||
// migration includes:
|
||||
//
|
||||
// - Change addresses to be length-prefixed.
|
||||
func MigrateStore(ctx sdk.Context, storeKey sdk.StoreKey) error {
|
||||
// - Setting the Power Reduction param in the paramstore
|
||||
func MigrateStore(ctx sdk.Context, storeKey sdk.StoreKey, paramstore paramtypes.Subspace) error {
|
||||
store := ctx.KVStore(storeKey)
|
||||
|
||||
v043distribution.MigratePrefixAddress(store, v040staking.LastValidatorPowerKey)
|
||||
|
@ -74,5 +80,7 @@ func MigrateStore(ctx sdk.Context, storeKey sdk.StoreKey) error {
|
|||
migratePrefixAddressAddressAddress(store, v040staking.RedelegationByValSrcIndexKey)
|
||||
migratePrefixAddressAddressAddress(store, v040staking.RedelegationByValDstIndexKey)
|
||||
|
||||
migrateParamsStore(ctx, paramstore)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -7,9 +7,11 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/testdata"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
||||
v040staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v040"
|
||||
v043staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v043"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/teststaking"
|
||||
|
@ -17,10 +19,14 @@ import (
|
|||
)
|
||||
|
||||
func TestStoreMigration(t *testing.T) {
|
||||
encCfg := simapp.MakeTestEncodingConfig()
|
||||
stakingKey := sdk.NewKVStoreKey("staking")
|
||||
ctx := testutil.DefaultContext(stakingKey, sdk.NewTransientStoreKey("transient_test"))
|
||||
tStakingKey := sdk.NewTransientStoreKey("transient_test")
|
||||
ctx := testutil.DefaultContext(stakingKey, tStakingKey)
|
||||
store := ctx.KVStore(stakingKey)
|
||||
|
||||
paramSubspace := paramtypes.NewSubspace(encCfg.Marshaler, encCfg.Amino, stakingKey, tStakingKey, types.ModuleName)
|
||||
|
||||
_, pk1, addr1 := testdata.KeyTestPubAddr()
|
||||
valAddr1 := sdk.ValAddress(addr1)
|
||||
val := teststaking.NewValidator(t, valAddr1, pk1)
|
||||
|
@ -121,7 +127,7 @@ func TestStoreMigration(t *testing.T) {
|
|||
}
|
||||
|
||||
// Run migrations.
|
||||
err := v043staking.MigrateStore(ctx, stakingKey)
|
||||
err := v043staking.MigrateStore(ctx, stakingKey, paramSubspace)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Make sure the new keys are set and old keys are deleted.
|
||||
|
@ -134,4 +140,8 @@ func TestStoreMigration(t *testing.T) {
|
|||
require.Equal(t, value, store.Get(tc.newKey))
|
||||
})
|
||||
}
|
||||
|
||||
powerReduction := sdk.NewInt(0)
|
||||
paramSubspace.Get(ctx, types.KeyPowerReduction, &powerReduction)
|
||||
require.True(t, powerReduction.Equal(sdk.DefaultPowerReduction))
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
|
|||
paramtypes.NewParamSetPair(KeyMaxEntries, &p.MaxEntries, validateMaxEntries),
|
||||
paramtypes.NewParamSetPair(KeyHistoricalEntries, &p.HistoricalEntries, validateHistoricalEntries),
|
||||
paramtypes.NewParamSetPair(KeyBondDenom, &p.BondDenom, validateBondDenom),
|
||||
paramtypes.NewParamSetPair(KeyPowerReduction, &p.PowerReduction, validatePowerReduction),
|
||||
paramtypes.NewParamSetPair(KeyPowerReduction, &p.PowerReduction, ValidatePowerReduction),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -196,7 +196,7 @@ func validateBondDenom(i interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func validatePowerReduction(i interface{}) error {
|
||||
func ValidatePowerReduction(i interface{}) error {
|
||||
v, ok := i.(sdk.Int)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid parameter type: %T", i)
|
||||
|
|
Loading…
Reference in New Issue