legacy genesis migration test and feedbacks
This commit is contained in:
parent
86844b24d9
commit
60c6c0a3c0
|
@ -35,6 +35,7 @@ var (
|
|||
multiPermAcc = authtypes.NewEmptyModuleAccount(multiPerm, authtypes.Burner, authtypes.Minter, authtypes.Staking)
|
||||
randomPermAcc = authtypes.NewEmptyModuleAccount(randomPerm, "random")
|
||||
|
||||
// The default power validators are initialized to have within tests
|
||||
initTokens = sdk.TokensFromConsensusPower(initialPower, sdk.DefaultPowerReduction)
|
||||
initCoins = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initTokens))
|
||||
)
|
||||
|
|
|
@ -34,6 +34,7 @@ var (
|
|||
sdk.ValAddress(pubkeys[2].Address()),
|
||||
}
|
||||
|
||||
// The default power validators are initialized to have within tests
|
||||
initAmt = sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction)
|
||||
initCoins = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, initAmt))
|
||||
)
|
||||
|
|
|
@ -5,5 +5,6 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
// The default power validators are initialized to have within tests
|
||||
InitTokens = sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction)
|
||||
)
|
||||
|
|
|
@ -3,5 +3,6 @@ package keeper_test
|
|||
import sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
var (
|
||||
// The default power validators are initialized to have within tests
|
||||
InitTokens = sdk.TokensFromConsensusPower(200, sdk.DefaultPowerReduction)
|
||||
)
|
||||
|
|
|
@ -110,7 +110,9 @@ func (k Keeper) BlockValidatorUpdates(ctx sdk.Context) []abci.ValidatorUpdate {
|
|||
// at the previous block height or were removed from the validator set entirely
|
||||
// are returned to Tendermint.
|
||||
func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []abci.ValidatorUpdate, err error) {
|
||||
maxValidators := k.GetParams(ctx).MaxValidators
|
||||
params := k.GetParams(ctx)
|
||||
maxValidators := params.MaxValidators
|
||||
powerReduction := params.PowerReduction
|
||||
totalPower := sdk.ZeroInt()
|
||||
amtFromBondedToNotBonded, amtFromNotBondedToBonded := sdk.ZeroInt(), sdk.ZeroInt()
|
||||
|
||||
|
@ -164,12 +166,12 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab
|
|||
|
||||
copy(valAddrBytes[:], valAddr[:])
|
||||
oldPowerBytes, found := last[valAddrBytes]
|
||||
newPower := validator.ConsensusPower(k.PowerReduction(ctx))
|
||||
newPower := validator.ConsensusPower(powerReduction)
|
||||
newPowerBytes := k.cdc.MustMarshalBinaryBare(&gogotypes.Int64Value{Value: newPower})
|
||||
|
||||
// update the validator set if power has changed
|
||||
if !found || !bytes.Equal(oldPowerBytes, newPowerBytes) {
|
||||
updates = append(updates, validator.ABCIValidatorUpdate(k.PowerReduction(ctx)))
|
||||
updates = append(updates, validator.ABCIValidatorUpdate(powerReduction))
|
||||
|
||||
k.SetLastValidatorPower(ctx, valAddr, newPower)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package v040
|
||||
|
||||
import (
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// 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)
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
package v040
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// 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)
|
||||
}
|
|
@ -0,0 +1,777 @@
|
|||
package v040
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
io "io"
|
||||
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"
|
||||
)
|
||||
|
||||
// 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() {}
|
||||
|
||||
// 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 (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")
|
||||
)
|
|
@ -4,22 +4,20 @@ import (
|
|||
"fmt"
|
||||
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/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))
|
||||
|
@ -32,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,
|
||||
|
@ -63,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,
|
||||
|
@ -75,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,
|
||||
|
@ -96,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,
|
||||
|
@ -115,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(),
|
||||
|
@ -123,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: sdk.DefaultPowerReduction,
|
||||
},
|
||||
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": [],
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package v040
|
||||
|
||||
import (
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// String returns a human readable string representation of the parameters.
|
||||
func (p Params) String() string {
|
||||
out, _ := yaml.Marshal(p)
|
||||
return string(out)
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,43 @@
|
|||
package v040
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
var (
|
||||
BondStatusUnspecified = BondStatus_name[int32(Unspecified)]
|
||||
BondStatusUnbonded = BondStatus_name[int32(Unbonded)]
|
||||
BondStatusUnbonding = BondStatus_name[int32(Unbonding)]
|
||||
BondStatusBonded = BondStatus_name[int32(Bonded)]
|
||||
)
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
// ValidatorsByVotingPower implements sort.Interface for []Validator based on
|
||||
// the VotingPower and Address fields.
|
||||
// The validators are sorted first by their voting power (descending). Secondary index - Address (ascending).
|
||||
// Copied from tendermint/types/validator_set.go
|
||||
type ValidatorsByVotingPower []Validator
|
||||
|
||||
// String implements the Stringer interface for a Description object.
|
||||
func (d Description) String() string {
|
||||
out, _ := yaml.Marshal(d)
|
||||
return string(out)
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
package v042
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
v040staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v040"
|
||||
v042staking "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
// Migrate accepts exported v0.40 x/staking genesis state and migrates it to
|
||||
// v0.42 x/staking genesis state. The migration includes:
|
||||
//
|
||||
// - Adding power reduction on-chain param
|
||||
func Migrate(stakingState v040staking.GenesisState) *v042staking.GenesisState {
|
||||
newLastValidatorPowers := make([]v042staking.LastValidatorPower, len(stakingState.LastValidatorPowers))
|
||||
for i, oldLastValidatorPower := range stakingState.LastValidatorPowers {
|
||||
newLastValidatorPowers[i] = v042staking.LastValidatorPower{
|
||||
Address: oldLastValidatorPower.Address,
|
||||
Power: oldLastValidatorPower.Power,
|
||||
}
|
||||
}
|
||||
|
||||
newValidators := make([]v042staking.Validator, len(stakingState.Validators))
|
||||
for i, oldValidator := range stakingState.Validators {
|
||||
newValidators[i] = v042staking.Validator{
|
||||
OperatorAddress: oldValidator.OperatorAddress,
|
||||
ConsensusPubkey: oldValidator.ConsensusPubkey,
|
||||
Jailed: oldValidator.Jailed,
|
||||
Status: v042staking.BondStatus(oldValidator.Status),
|
||||
Tokens: oldValidator.Tokens,
|
||||
DelegatorShares: oldValidator.DelegatorShares,
|
||||
Description: v042staking.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: v042staking.Commission{
|
||||
CommissionRates: v042staking.CommissionRates{
|
||||
Rate: oldValidator.Commission.Rate,
|
||||
MaxRate: oldValidator.Commission.MaxRate,
|
||||
MaxChangeRate: oldValidator.Commission.MaxChangeRate,
|
||||
},
|
||||
UpdateTime: oldValidator.Commission.UpdateTime,
|
||||
},
|
||||
MinSelfDelegation: oldValidator.MinSelfDelegation,
|
||||
}
|
||||
}
|
||||
|
||||
newDelegations := make([]v042staking.Delegation, len(stakingState.Delegations))
|
||||
for i, oldDelegation := range stakingState.Delegations {
|
||||
newDelegations[i] = v042staking.Delegation{
|
||||
DelegatorAddress: oldDelegation.DelegatorAddress,
|
||||
ValidatorAddress: oldDelegation.ValidatorAddress,
|
||||
Shares: oldDelegation.Shares,
|
||||
}
|
||||
}
|
||||
|
||||
newUnbondingDelegations := make([]v042staking.UnbondingDelegation, len(stakingState.UnbondingDelegations))
|
||||
for i, oldUnbondingDelegation := range stakingState.UnbondingDelegations {
|
||||
newEntries := make([]v042staking.UnbondingDelegationEntry, len(oldUnbondingDelegation.Entries))
|
||||
for j, oldEntry := range oldUnbondingDelegation.Entries {
|
||||
newEntries[j] = v042staking.UnbondingDelegationEntry{
|
||||
CreationHeight: oldEntry.CreationHeight,
|
||||
CompletionTime: oldEntry.CompletionTime,
|
||||
InitialBalance: oldEntry.InitialBalance,
|
||||
Balance: oldEntry.Balance,
|
||||
}
|
||||
}
|
||||
|
||||
newUnbondingDelegations[i] = v042staking.UnbondingDelegation{
|
||||
DelegatorAddress: oldUnbondingDelegation.DelegatorAddress,
|
||||
ValidatorAddress: oldUnbondingDelegation.ValidatorAddress,
|
||||
Entries: newEntries,
|
||||
}
|
||||
}
|
||||
|
||||
newRedelegations := make([]v042staking.Redelegation, len(stakingState.Redelegations))
|
||||
for i, oldRedelegation := range stakingState.Redelegations {
|
||||
newEntries := make([]v042staking.RedelegationEntry, len(oldRedelegation.Entries))
|
||||
for j, oldEntry := range oldRedelegation.Entries {
|
||||
newEntries[j] = v042staking.RedelegationEntry{
|
||||
CreationHeight: oldEntry.CreationHeight,
|
||||
CompletionTime: oldEntry.CompletionTime,
|
||||
InitialBalance: oldEntry.InitialBalance,
|
||||
SharesDst: oldEntry.SharesDst,
|
||||
}
|
||||
}
|
||||
|
||||
newRedelegations[i] = v042staking.Redelegation{
|
||||
DelegatorAddress: oldRedelegation.DelegatorAddress,
|
||||
ValidatorSrcAddress: oldRedelegation.ValidatorSrcAddress,
|
||||
ValidatorDstAddress: oldRedelegation.ValidatorDstAddress,
|
||||
Entries: newEntries,
|
||||
}
|
||||
}
|
||||
|
||||
return &v042staking.GenesisState{
|
||||
Params: v042staking.Params{
|
||||
UnbondingTime: stakingState.Params.UnbondingTime,
|
||||
MaxValidators: stakingState.Params.MaxValidators,
|
||||
MaxEntries: stakingState.Params.MaxEntries,
|
||||
HistoricalEntries: stakingState.Params.HistoricalEntries,
|
||||
BondDenom: stakingState.Params.BondDenom,
|
||||
PowerReduction: sdk.DefaultPowerReduction,
|
||||
},
|
||||
LastTotalPower: stakingState.LastTotalPower,
|
||||
LastValidatorPowers: newLastValidatorPowers,
|
||||
Validators: newValidators,
|
||||
Delegations: newDelegations,
|
||||
UnbondingDelegations: newUnbondingDelegations,
|
||||
Redelegations: newRedelegations,
|
||||
Exported: stakingState.Exported,
|
||||
}
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
package v042_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
v040staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v040"
|
||||
v042staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v042"
|
||||
)
|
||||
|
||||
func TestMigrate(t *testing.T) {
|
||||
encodingConfig := simapp.MakeTestEncodingConfig()
|
||||
clientCtx := client.Context{}.
|
||||
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
|
||||
WithTxConfig(encodingConfig.TxConfig).
|
||||
WithLegacyAmino(encodingConfig.Amino).
|
||||
WithJSONMarshaler(encodingConfig.Marshaler)
|
||||
|
||||
consPubKey := ed25519.GenPrivKeyFromSecret([]byte("val0")).PubKey()
|
||||
pkAny, err := codectypes.NewAnyWithValue(consPubKey)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Can't pack validator consensus PK as Any: %s", err))
|
||||
}
|
||||
stakingGenState := v040staking.GenesisState{
|
||||
Validators: v040staking.Validators{v040staking.Validator{
|
||||
ConsensusPubkey: pkAny,
|
||||
Status: v040staking.Unbonded,
|
||||
}},
|
||||
}
|
||||
|
||||
migrated := v042staking.Migrate(stakingGenState)
|
||||
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, "", " ")
|
||||
require.NoError(t, err)
|
||||
|
||||
// Make sure about:
|
||||
// - consensus_pubkey: should be an any
|
||||
// - validator's status should be 1 (new unbonded)
|
||||
expected := `{
|
||||
"delegations": [],
|
||||
"exported": false,
|
||||
"last_total_power": "0",
|
||||
"last_validator_powers": [],
|
||||
"params": {
|
||||
"bond_denom": "",
|
||||
"historical_entries": 0,
|
||||
"max_entries": 0,
|
||||
"max_validators": 0,
|
||||
"power_reduction": "1000000",
|
||||
"unbonding_time": "0s"
|
||||
},
|
||||
"redelegations": [],
|
||||
"unbonding_delegations": [],
|
||||
"validators": [
|
||||
{
|
||||
"commission": {
|
||||
"commission_rates": {
|
||||
"max_change_rate": "0",
|
||||
"max_rate": "0",
|
||||
"rate": "0"
|
||||
},
|
||||
"update_time": "0001-01-01T00:00:00Z"
|
||||
},
|
||||
"consensus_pubkey": {
|
||||
"@type": "/cosmos.crypto.ed25519.PubKey",
|
||||
"key": "KTeVrjP7NJIufvgMJsQRxZjfFyD+Exda6O7x+oxIvmA="
|
||||
},
|
||||
"delegator_shares": "0",
|
||||
"description": {
|
||||
"details": "",
|
||||
"identity": "",
|
||||
"moniker": "",
|
||||
"security_contact": "",
|
||||
"website": ""
|
||||
},
|
||||
"jailed": false,
|
||||
"min_self_delegation": "0",
|
||||
"operator_address": "",
|
||||
"status": "BOND_STATUS_UNBONDED",
|
||||
"tokens": "0",
|
||||
"unbonding_height": "0",
|
||||
"unbonding_time": "0001-01-01T00:00:00Z"
|
||||
}
|
||||
]
|
||||
}`
|
||||
|
||||
require.Equal(t, expected, string(indentedBz))
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package v042
|
||||
|
||||
const (
|
||||
ModuleName = "staking"
|
||||
)
|
|
@ -16,7 +16,6 @@ import (
|
|||
// it will first sort valset before inclusion into historical info
|
||||
func NewHistoricalInfo(header tmproto.Header, valSet Validators, powerReduction sdk.Int) HistoricalInfo {
|
||||
// Must sort in the same way that tendermint does
|
||||
// TODO: check with sort.Sort(ValidatorsByVotingPower(valSet))
|
||||
sort.SliceStable(valSet, func(i, j int) bool {
|
||||
return ValidatorsByVotingPower(valSet).LessAfterPowerReductionApply(i, j, powerReduction)
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue