From 78d1509eac58222734d135fae7f17dca3b0cab64 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 17 Feb 2020 14:34:57 -0500 Subject: [PATCH 01/11] Initial migration of upgrade to proto --- simapp/app.go | 2 +- x/upgrade/internal/keeper/keeper.go | 6 +- x/upgrade/internal/types/plan.go | 22 - x/upgrade/internal/types/proposal.go | 13 - x/upgrade/internal/types/types.pb.go | 922 +++++++++++++++++++++++++++ x/upgrade/internal/types/types.proto | 42 ++ 6 files changed, 968 insertions(+), 39 deletions(-) create mode 100644 x/upgrade/internal/types/types.pb.go create mode 100644 x/upgrade/internal/types/types.proto diff --git a/simapp/app.go b/simapp/app.go index fd8bfbb4029e..8a9269912b3f 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -189,7 +189,7 @@ func NewSimApp( app.CrisisKeeper = crisis.NewKeeper( app.subspaces[crisis.ModuleName], invCheckPeriod, app.SupplyKeeper, auth.FeeCollectorName, ) - app.UpgradeKeeper = upgrade.NewKeeper(skipUpgradeHeights, keys[upgrade.StoreKey], app.cdc) + app.UpgradeKeeper = upgrade.NewKeeper(skipUpgradeHeights, keys[upgrade.StoreKey], codec.NewHybridCodec(app.cdc)) // create evidence keeper with router evidenceKeeper := evidence.NewKeeper( diff --git a/x/upgrade/internal/keeper/keeper.go b/x/upgrade/internal/keeper/keeper.go index 7a33d7e4b66c..35738e1f7a22 100644 --- a/x/upgrade/internal/keeper/keeper.go +++ b/x/upgrade/internal/keeper/keeper.go @@ -16,12 +16,12 @@ import ( type Keeper struct { skipUpgradeHeights map[int64]bool storeKey sdk.StoreKey - cdc *codec.Codec + cdc codec.Marshaler upgradeHandlers map[string]types.UpgradeHandler } // NewKeeper constructs an upgrade Keeper -func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey sdk.StoreKey, cdc *codec.Codec) Keeper { +func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey sdk.StoreKey, cdc codec.Marshaler) Keeper { return Keeper{ skipUpgradeHeights: skipUpgradeHeights, storeKey: storeKey, @@ -57,7 +57,7 @@ func (k Keeper) ScheduleUpgrade(ctx sdk.Context, plan types.Plan) error { return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "upgrade with name %s has already been completed", plan.Name) } - bz := k.cdc.MustMarshalBinaryBare(plan) + bz := k.cdc.MustMarshalBinaryBare(&plan) store := ctx.KVStore(k.storeKey) store.Set(types.PlanKey(), bz) diff --git a/x/upgrade/internal/types/plan.go b/x/upgrade/internal/types/plan.go index c2b88171e218..4f31063bc7bb 100644 --- a/x/upgrade/internal/types/plan.go +++ b/x/upgrade/internal/types/plan.go @@ -9,28 +9,6 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) -// Plan specifies information about a planned upgrade and when it should occur -type Plan struct { - // Sets the name for the upgrade. This name will be used by the upgraded version of the software to apply any - // special "on-upgrade" commands during the first BeginBlock method after the upgrade is applied. It is also used - // to detect whether a software version can handle a given upgrade. If no upgrade handler with this name has been - // set in the software, it will be assumed that the software is out-of-date when the upgrade Time or Height - // is reached and the software will exit. - Name string `json:"name,omitempty"` - - // The time after which the upgrade must be performed. - // Leave set to its zero value to use a pre-defined Height instead. - Time time.Time `json:"time,omitempty"` - - // The height at which the upgrade must be performed. - // Only used if Time is not set. - Height int64 `json:"height,omitempty"` - - // Any application specific upgrade info to be included on-chain - // such as a git commit that validators could automatically upgrade to - Info string `json:"info,omitempty"` -} - func (p Plan) String() string { due := p.DueAt() dueUp := strings.ToUpper(due[0:1]) + due[1:] diff --git a/x/upgrade/internal/types/proposal.go b/x/upgrade/internal/types/proposal.go index 958c10674645..2067110e74e1 100644 --- a/x/upgrade/internal/types/proposal.go +++ b/x/upgrade/internal/types/proposal.go @@ -11,13 +11,6 @@ const ( ProposalTypeCancelSoftwareUpgrade string = "CancelSoftwareUpgrade" ) -// Software Upgrade Proposals -type SoftwareUpgradeProposal struct { - Title string `json:"title" yaml:"title"` - Description string `json:"description" yaml:"description"` - Plan Plan `json:"plan" yaml:"plan"` -} - func NewSoftwareUpgradeProposal(title, description string, plan Plan) gov.Content { return SoftwareUpgradeProposal{title, description, plan} } @@ -51,12 +44,6 @@ func (sup SoftwareUpgradeProposal) String() string { `, sup.Title, sup.Description) } -// Cancel Software Upgrade Proposals -type CancelSoftwareUpgradeProposal struct { - Title string `json:"title" yaml:"title"` - Description string `json:"description" yaml:"description"` -} - func NewCancelSoftwareUpgradeProposal(title, description string) gov.Content { return CancelSoftwareUpgradeProposal{title, description} } diff --git a/x/upgrade/internal/types/types.pb.go b/x/upgrade/internal/types/types.pb.go new file mode 100644 index 000000000000..4e8f7cbb9895 --- /dev/null +++ b/x/upgrade/internal/types/types.pb.go @@ -0,0 +1,922 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: x/upgrade/internal/types/types.proto + +package types + +import ( + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/proto" + github_com_gogo_protobuf_types "github.com/gogo/protobuf/types" + _ "github.com/golang/protobuf/ptypes/timestamp" + io "io" + math "math" + math_bits "math/bits" + time "time" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf +var _ = time.Kitchen + +// 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 + +// Plan specifies information about a planned upgrade and when it should occur +type Plan struct { + // Sets the name for the upgrade. This name will be used by the upgraded version of the software to apply any + // special "on-upgrade" commands during the first BeginBlock method after the upgrade is applied. It is also used + // to detect whether a software version can handle a given upgrade. If no upgrade handler with this name has been + // set in the software, it will be assumed that the software is out-of-date when the upgrade Time or Height + // is reached and the software will exit. + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + // The time after which the upgrade must be performed. + // Leave set to its zero value to use a pre-defined Height instead. + Time time.Time `protobuf:"bytes,2,opt,name=time,proto3,stdtime" json:"time"` + // The height at which the upgrade must be performed. + // Only used if Time is not set. + Height int64 `protobuf:"varint,3,opt,name=height,proto3" json:"height,omitempty"` + // Any application specific upgrade info to be included on-chain + // such as a git commit that validators could automatically upgrade to + Info string `protobuf:"bytes,4,opt,name=info,proto3" json:"info,omitempty"` +} + +func (m *Plan) Reset() { *m = Plan{} } +func (*Plan) ProtoMessage() {} +func (*Plan) Descriptor() ([]byte, []int) { + return fileDescriptor_6199ecc2c05edfcb, []int{0} +} +func (m *Plan) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Plan) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Plan.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 *Plan) XXX_Merge(src proto.Message) { + xxx_messageInfo_Plan.Merge(m, src) +} +func (m *Plan) XXX_Size() int { + return m.Size() +} +func (m *Plan) XXX_DiscardUnknown() { + xxx_messageInfo_Plan.DiscardUnknown(m) +} + +var xxx_messageInfo_Plan proto.InternalMessageInfo + +type SoftwareUpgradeProposal struct { + Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` + Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` + Plan Plan `protobuf:"bytes,3,opt,name=plan,proto3" json:"plan"` +} + +func (m *SoftwareUpgradeProposal) Reset() { *m = SoftwareUpgradeProposal{} } +func (*SoftwareUpgradeProposal) ProtoMessage() {} +func (*SoftwareUpgradeProposal) Descriptor() ([]byte, []int) { + return fileDescriptor_6199ecc2c05edfcb, []int{1} +} +func (m *SoftwareUpgradeProposal) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SoftwareUpgradeProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SoftwareUpgradeProposal.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 *SoftwareUpgradeProposal) XXX_Merge(src proto.Message) { + xxx_messageInfo_SoftwareUpgradeProposal.Merge(m, src) +} +func (m *SoftwareUpgradeProposal) XXX_Size() int { + return m.Size() +} +func (m *SoftwareUpgradeProposal) XXX_DiscardUnknown() { + xxx_messageInfo_SoftwareUpgradeProposal.DiscardUnknown(m) +} + +var xxx_messageInfo_SoftwareUpgradeProposal proto.InternalMessageInfo + +type CancelSoftwareUpgradeProposal struct { + Title string `protobuf:"bytes,1,opt,name=title,proto3" json:"title,omitempty"` + Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"` +} + +func (m *CancelSoftwareUpgradeProposal) Reset() { *m = CancelSoftwareUpgradeProposal{} } +func (*CancelSoftwareUpgradeProposal) ProtoMessage() {} +func (*CancelSoftwareUpgradeProposal) Descriptor() ([]byte, []int) { + return fileDescriptor_6199ecc2c05edfcb, []int{2} +} +func (m *CancelSoftwareUpgradeProposal) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *CancelSoftwareUpgradeProposal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CancelSoftwareUpgradeProposal.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 *CancelSoftwareUpgradeProposal) XXX_Merge(src proto.Message) { + xxx_messageInfo_CancelSoftwareUpgradeProposal.Merge(m, src) +} +func (m *CancelSoftwareUpgradeProposal) XXX_Size() int { + return m.Size() +} +func (m *CancelSoftwareUpgradeProposal) XXX_DiscardUnknown() { + xxx_messageInfo_CancelSoftwareUpgradeProposal.DiscardUnknown(m) +} + +var xxx_messageInfo_CancelSoftwareUpgradeProposal proto.InternalMessageInfo + +func init() { + proto.RegisterType((*Plan)(nil), "cosmos_sdk.x.upgrade.v1.Plan") + proto.RegisterType((*SoftwareUpgradeProposal)(nil), "cosmos_sdk.x.upgrade.v1.SoftwareUpgradeProposal") + proto.RegisterType((*CancelSoftwareUpgradeProposal)(nil), "cosmos_sdk.x.upgrade.v1.CancelSoftwareUpgradeProposal") +} + +func init() { + proto.RegisterFile("x/upgrade/internal/types/types.proto", fileDescriptor_6199ecc2c05edfcb) +} + +var fileDescriptor_6199ecc2c05edfcb = []byte{ + // 371 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x52, 0x3f, 0x0f, 0x12, 0x31, + 0x14, 0xbf, 0xca, 0x49, 0xa4, 0x6c, 0x8d, 0x91, 0x0b, 0x09, 0xe5, 0x42, 0x8c, 0x21, 0x31, 0xb6, + 0x11, 0x07, 0x9d, 0x71, 0x36, 0x21, 0xa7, 0xc6, 0xc4, 0x85, 0x94, 0xbb, 0x72, 0xd7, 0x70, 0xd7, + 0x36, 0x6d, 0x51, 0xd8, 0x9c, 0x9d, 0xf8, 0x58, 0x8c, 0x8c, 0x4c, 0x2a, 0xf0, 0x45, 0xcc, 0x5d, + 0x8f, 0xe8, 0xe2, 0xe6, 0xd2, 0xbe, 0xd7, 0xfc, 0xfe, 0xbd, 0xb6, 0xf0, 0xe9, 0x8e, 0x6e, 0x75, + 0x6e, 0x58, 0xc6, 0xa9, 0x90, 0x8e, 0x1b, 0xc9, 0x4a, 0xea, 0xf6, 0x9a, 0x5b, 0xbf, 0x12, 0x6d, + 0x94, 0x53, 0x68, 0x90, 0x2a, 0x5b, 0x29, 0xbb, 0xb4, 0xd9, 0x86, 0xec, 0x48, 0x4b, 0x20, 0x5f, + 0x5e, 0x0e, 0x9f, 0xb9, 0x42, 0x98, 0x6c, 0xa9, 0x99, 0x71, 0x7b, 0xda, 0x60, 0x69, 0xae, 0x72, + 0xf5, 0xa7, 0xf2, 0x02, 0xc3, 0x71, 0xae, 0x54, 0x5e, 0x72, 0x0f, 0x59, 0x6d, 0xd7, 0xd4, 0x89, + 0x8a, 0x5b, 0xc7, 0x2a, 0xed, 0x01, 0x93, 0x6f, 0x00, 0x86, 0x8b, 0x92, 0x49, 0x84, 0x60, 0x28, + 0x59, 0xc5, 0x23, 0x10, 0x83, 0x69, 0x2f, 0x69, 0x6a, 0xf4, 0x06, 0x86, 0x35, 0x3e, 0x7a, 0x10, + 0x83, 0x69, 0x7f, 0x36, 0x24, 0x5e, 0x8c, 0xdc, 0xc5, 0xc8, 0x87, 0xbb, 0xd8, 0xfc, 0xd1, 0xf1, + 0xc7, 0x38, 0x38, 0xfc, 0x1c, 0x83, 0xa4, 0x61, 0xa0, 0x27, 0xb0, 0x5b, 0x70, 0x91, 0x17, 0x2e, + 0xea, 0xc4, 0x60, 0xda, 0x49, 0xda, 0xae, 0x76, 0x11, 0x72, 0xad, 0xa2, 0xd0, 0xbb, 0xd4, 0xf5, + 0xe4, 0x3b, 0x80, 0x83, 0xf7, 0x6a, 0xed, 0xbe, 0x32, 0xc3, 0x3f, 0xfa, 0x11, 0x17, 0x46, 0x69, + 0x65, 0x59, 0x89, 0x1e, 0xc3, 0x87, 0x4e, 0xb8, 0xf2, 0x1e, 0xcb, 0x37, 0x28, 0x86, 0xfd, 0x8c, + 0xdb, 0xd4, 0x08, 0xed, 0x84, 0x92, 0x4d, 0xbc, 0x5e, 0xf2, 0xf7, 0x11, 0x7a, 0x0d, 0x43, 0x5d, + 0x32, 0xd9, 0xb8, 0xf7, 0x67, 0x23, 0xf2, 0x8f, 0x7b, 0x24, 0xf5, 0xe8, 0xf3, 0xb0, 0x0e, 0x9f, + 0x34, 0x84, 0xc9, 0x27, 0x38, 0x7a, 0xcb, 0x64, 0xca, 0xcb, 0xff, 0x9c, 0x68, 0xfe, 0xee, 0x78, + 0xc1, 0xc1, 0xf9, 0x82, 0x83, 0xe3, 0x15, 0x83, 0xd3, 0x15, 0x83, 0x5f, 0x57, 0x0c, 0x0e, 0x37, + 0x1c, 0x9c, 0x6e, 0x38, 0x38, 0xdf, 0x70, 0xf0, 0xf9, 0x79, 0x2e, 0x5c, 0xb1, 0x5d, 0x91, 0x54, + 0x55, 0xd4, 0xe7, 0x6d, 0xb7, 0x17, 0x36, 0xdb, 0xd0, 0x1d, 0xd5, 0xcc, 0xb0, 0xaa, 0xfd, 0x1f, + 0xab, 0x6e, 0xf3, 0x08, 0xaf, 0x7e, 0x07, 0x00, 0x00, 0xff, 0xff, 0xad, 0x67, 0xed, 0x35, 0x48, + 0x02, 0x00, 0x00, +} + +func (m *Plan) 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 *Plan) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Plan) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Info) > 0 { + i -= len(m.Info) + copy(dAtA[i:], m.Info) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Info))) + i-- + dAtA[i] = 0x22 + } + if m.Height != 0 { + i = encodeVarintTypes(dAtA, i, uint64(m.Height)) + i-- + dAtA[i] = 0x18 + } + n1, err1 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.Time, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.Time):]) + if err1 != nil { + return 0, err1 + } + i -= n1 + i = encodeVarintTypes(dAtA, i, uint64(n1)) + i-- + dAtA[i] = 0x12 + if len(m.Name) > 0 { + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *SoftwareUpgradeProposal) 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 *SoftwareUpgradeProposal) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SoftwareUpgradeProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Plan.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTypes(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.Description) > 0 { + i -= len(m.Description) + copy(dAtA[i:], m.Description) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Description))) + i-- + dAtA[i] = 0x12 + } + if len(m.Title) > 0 { + i -= len(m.Title) + copy(dAtA[i:], m.Title) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Title))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *CancelSoftwareUpgradeProposal) 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 *CancelSoftwareUpgradeProposal) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *CancelSoftwareUpgradeProposal) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Description) > 0 { + i -= len(m.Description) + copy(dAtA[i:], m.Description) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Description))) + i-- + dAtA[i] = 0x12 + } + if len(m.Title) > 0 { + i -= len(m.Title) + copy(dAtA[i:], m.Title) + i = encodeVarintTypes(dAtA, i, uint64(len(m.Title))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintTypes(dAtA []byte, offset int, v uint64) int { + offset -= sovTypes(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Plan) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Name) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = github_com_gogo_protobuf_types.SizeOfStdTime(m.Time) + n += 1 + l + sovTypes(uint64(l)) + if m.Height != 0 { + n += 1 + sovTypes(uint64(m.Height)) + } + l = len(m.Info) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + +func (m *SoftwareUpgradeProposal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Title) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = len(m.Description) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = m.Plan.Size() + n += 1 + l + sovTypes(uint64(l)) + return n +} + +func (m *CancelSoftwareUpgradeProposal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Title) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + l = len(m.Description) + if l > 0 { + n += 1 + l + sovTypes(uint64(l)) + } + return n +} + +func sovTypes(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTypes(x uint64) (n int) { + return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Plan) 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 ErrIntOverflowTypes + } + 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: Plan: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Plan: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + 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 ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Time", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.Time, dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Height |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Info", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + 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 ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Info = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *SoftwareUpgradeProposal) 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 ErrIntOverflowTypes + } + 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: SoftwareUpgradeProposal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SoftwareUpgradeProposal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + 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 ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Title = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + 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 ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Description = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Plan", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTypes + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Plan.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *CancelSoftwareUpgradeProposal) 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 ErrIntOverflowTypes + } + 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: CancelSoftwareUpgradeProposal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CancelSoftwareUpgradeProposal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + 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 ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Title = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTypes + } + 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 ErrInvalidLengthTypes + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTypes + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Description = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTypes(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthTypes + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTypes(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, ErrIntOverflowTypes + } + 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, ErrIntOverflowTypes + } + 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, ErrIntOverflowTypes + } + 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, ErrInvalidLengthTypes + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTypes + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTypes + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTypes = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTypes = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTypes = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/upgrade/internal/types/types.proto b/x/upgrade/internal/types/types.proto new file mode 100644 index 000000000000..f16ea5684e18 --- /dev/null +++ b/x/upgrade/internal/types/types.proto @@ -0,0 +1,42 @@ +syntax = "proto3"; +package cosmos_sdk.x.upgrade.v1; + +import "third_party/proto/gogoproto/gogo.proto"; +import "google/protobuf/timestamp.proto"; + +option go_package = "github.com/cosmos/cosmos-sdk/x/params/types"; +option (gogoproto.goproto_stringer_all) = false; +option (gogoproto.goproto_getters_all) = false; + +// Plan specifies information about a planned upgrade and when it should occur +message Plan { + // Sets the name for the upgrade. This name will be used by the upgraded version of the software to apply any + // special "on-upgrade" commands during the first BeginBlock method after the upgrade is applied. It is also used + // to detect whether a software version can handle a given upgrade. If no upgrade handler with this name has been + // set in the software, it will be assumed that the software is out-of-date when the upgrade Time or Height + // is reached and the software will exit. + string name = 1; + + // The time after which the upgrade must be performed. + // Leave set to its zero value to use a pre-defined Height instead. + google.protobuf.Timestamp time = 2 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; + + // The height at which the upgrade must be performed. + // Only used if Time is not set. + int64 height = 3; + + // Any application specific upgrade info to be included on-chain + // such as a git commit that validators could automatically upgrade to + string info = 4; +} + +message SoftwareUpgradeProposal { + string title = 1; + string description = 2; + Plan plan = 3 [(gogoproto.nullable) = false]; +} + +message CancelSoftwareUpgradeProposal { + string title = 1; + string description = 2; +} From 5d40bd5d6f0a67d8fa9499f109ec62ebc03b1a10 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 17 Feb 2020 14:40:24 -0500 Subject: [PATCH 02/11] Add doc comments --- x/upgrade/internal/types/types.proto | 2 ++ 1 file changed, 2 insertions(+) diff --git a/x/upgrade/internal/types/types.proto b/x/upgrade/internal/types/types.proto index f16ea5684e18..fd52d01e7cd0 100644 --- a/x/upgrade/internal/types/types.proto +++ b/x/upgrade/internal/types/types.proto @@ -30,12 +30,14 @@ message Plan { string info = 4; } +// SoftwareUpgradeProposal is a gov Content type for initiating a software upgrade message SoftwareUpgradeProposal { string title = 1; string description = 2; Plan plan = 3 [(gogoproto.nullable) = false]; } +// SoftwareUpgradeProposal is a gov Content type for cancelling a software upgrade message CancelSoftwareUpgradeProposal { string title = 1; string description = 2; From be2e00476387082afb52943fe074091679f923ad Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 17 Feb 2020 16:46:53 -0500 Subject: [PATCH 03/11] Add CHANGELOG entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa07e0f77e0a..3941d1683d72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -126,6 +126,8 @@ serialization instead of Amino. * The `MsgSubmitEvidence` message has been removed in favor of `MsgSubmitEvidenceBase`. The application-level codec must now define the concrete `MsgSubmitEvidence` type which must implement the module's `MsgSubmitEvidence` interface. +* (x/upgrade) [\#5659](https://github.com/cosmos/cosmos-sdk/pull/5659) Migrate the `x/upgrade` module to use Protocol +Buffers for state encoding. ### Improvements From 6b6470ffe07feca01534f9e459b904ab680f5c73 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 19 Feb 2020 09:34:28 -0500 Subject: [PATCH 04/11] Use appCodec for upgrade keeper in simapp, remove x/upgrade/internal, update CHANGELOG --- CHANGELOG.md | 4 +++- simapp/app.go | 2 +- x/upgrade/alias.go | 4 ++-- x/upgrade/client/cli/query.go | 2 +- x/upgrade/client/cli/tx.go | 2 +- x/upgrade/client/rest/query.go | 2 +- x/upgrade/client/rest/tx.go | 2 +- x/upgrade/{internal => keeper}/keeper/keeper.go | 2 +- x/upgrade/{internal => keeper}/keeper/querier.go | 2 +- x/upgrade/{internal => types}/types/codec.go | 0 x/upgrade/{internal => types}/types/handler.go | 0 x/upgrade/{internal => types}/types/keys.go | 0 x/upgrade/{internal => types}/types/plan.go | 0 x/upgrade/{internal => types}/types/plan_test.go | 0 x/upgrade/{internal => types}/types/proposal.go | 0 x/upgrade/{internal => types}/types/proposal_test.go | 0 x/upgrade/{internal => types}/types/querier.go | 0 x/upgrade/{internal => types}/types/types.pb.go | 0 x/upgrade/{internal => types}/types/types.proto | 0 19 files changed, 12 insertions(+), 10 deletions(-) rename x/upgrade/{internal => keeper}/keeper/keeper.go (98%) rename x/upgrade/{internal => keeper}/keeper/querier.go (96%) rename x/upgrade/{internal => types}/types/codec.go (100%) rename x/upgrade/{internal => types}/types/handler.go (100%) rename x/upgrade/{internal => types}/types/keys.go (100%) rename x/upgrade/{internal => types}/types/plan.go (100%) rename x/upgrade/{internal => types}/types/plan_test.go (100%) rename x/upgrade/{internal => types}/types/proposal.go (100%) rename x/upgrade/{internal => types}/types/proposal_test.go (100%) rename x/upgrade/{internal => types}/types/querier.go (100%) rename x/upgrade/{internal => types}/types/types.pb.go (100%) rename x/upgrade/{internal => types}/types/types.proto (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3941d1683d72..7e9979d32608 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -127,7 +127,9 @@ serialization instead of Amino. codec must now define the concrete `MsgSubmitEvidence` type which must implement the module's `MsgSubmitEvidence` interface. * (x/upgrade) [\#5659](https://github.com/cosmos/cosmos-sdk/pull/5659) Migrate the `x/upgrade` module to use Protocol -Buffers for state encoding. +Buffers for state serialization instead of Amino. + * The `internal` sub-package has been removed in order to expose the types proto file. + * The `x/upgrade` module now accepts a `codec.Marshaler` interface. ### Improvements diff --git a/simapp/app.go b/simapp/app.go index 8a9269912b3f..e7253c9a7874 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -189,7 +189,7 @@ func NewSimApp( app.CrisisKeeper = crisis.NewKeeper( app.subspaces[crisis.ModuleName], invCheckPeriod, app.SupplyKeeper, auth.FeeCollectorName, ) - app.UpgradeKeeper = upgrade.NewKeeper(skipUpgradeHeights, keys[upgrade.StoreKey], codec.NewHybridCodec(app.cdc)) + app.UpgradeKeeper = upgrade.NewKeeper(skipUpgradeHeights, keys[upgrade.StoreKey], appCodec) // create evidence keeper with router evidenceKeeper := evidence.NewKeeper( diff --git a/x/upgrade/alias.go b/x/upgrade/alias.go index d8089d35d543..ed63403b3479 100644 --- a/x/upgrade/alias.go +++ b/x/upgrade/alias.go @@ -3,8 +3,8 @@ package upgrade // nolint import ( - "github.com/cosmos/cosmos-sdk/x/upgrade/internal/keeper" - "github.com/cosmos/cosmos-sdk/x/upgrade/internal/types" + "github.com/cosmos/cosmos-sdk/x/upgrade/keeper/keeper" + "github.com/cosmos/cosmos-sdk/x/upgrade/types/types" ) const ( diff --git a/x/upgrade/client/cli/query.go b/x/upgrade/client/cli/query.go index 0b33a012071f..e166ecf983d3 100644 --- a/x/upgrade/client/cli/query.go +++ b/x/upgrade/client/cli/query.go @@ -8,7 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/codec" - upgrade "github.com/cosmos/cosmos-sdk/x/upgrade/internal/types" + upgrade "github.com/cosmos/cosmos-sdk/x/upgrade/types/types" ) // GetPlanCmd returns the query upgrade plan command diff --git a/x/upgrade/client/cli/tx.go b/x/upgrade/client/cli/tx.go index a06347bc1def..ce494af875d9 100644 --- a/x/upgrade/client/cli/tx.go +++ b/x/upgrade/client/cli/tx.go @@ -15,7 +15,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/gov" - upgrade "github.com/cosmos/cosmos-sdk/x/upgrade/internal/types" + upgrade "github.com/cosmos/cosmos-sdk/x/upgrade/types/types" ) const ( diff --git a/x/upgrade/client/rest/query.go b/x/upgrade/client/rest/query.go index bf9bdd341070..6e7617294b88 100644 --- a/x/upgrade/client/rest/query.go +++ b/x/upgrade/client/rest/query.go @@ -9,7 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/types/rest" - upgrade "github.com/cosmos/cosmos-sdk/x/upgrade/internal/types" + upgrade "github.com/cosmos/cosmos-sdk/x/upgrade/types/types" ) // RegisterRoutes registers REST routes for the upgrade module under the path specified by routeName. diff --git a/x/upgrade/client/rest/tx.go b/x/upgrade/client/rest/tx.go index 9354d9dd05a0..53f21714c417 100644 --- a/x/upgrade/client/rest/tx.go +++ b/x/upgrade/client/rest/tx.go @@ -13,7 +13,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" "github.com/cosmos/cosmos-sdk/x/gov" - "github.com/cosmos/cosmos-sdk/x/upgrade/internal/types" + "github.com/cosmos/cosmos-sdk/x/upgrade/types/types" ) func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router) { diff --git a/x/upgrade/internal/keeper/keeper.go b/x/upgrade/keeper/keeper/keeper.go similarity index 98% rename from x/upgrade/internal/keeper/keeper.go rename to x/upgrade/keeper/keeper/keeper.go index 35738e1f7a22..6ad261eb5cbc 100644 --- a/x/upgrade/internal/keeper/keeper.go +++ b/x/upgrade/keeper/keeper/keeper.go @@ -10,7 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/upgrade/internal/types" + "github.com/cosmos/cosmos-sdk/x/upgrade/types/types" ) type Keeper struct { diff --git a/x/upgrade/internal/keeper/querier.go b/x/upgrade/keeper/keeper/querier.go similarity index 96% rename from x/upgrade/internal/keeper/querier.go rename to x/upgrade/keeper/keeper/querier.go index 7bddfad34566..8e8e2314166c 100644 --- a/x/upgrade/internal/keeper/querier.go +++ b/x/upgrade/keeper/keeper/querier.go @@ -7,7 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/upgrade/internal/types" + "github.com/cosmos/cosmos-sdk/x/upgrade/types/types" ) // NewQuerier creates a querier for upgrade cli and REST endpoints diff --git a/x/upgrade/internal/types/codec.go b/x/upgrade/types/types/codec.go similarity index 100% rename from x/upgrade/internal/types/codec.go rename to x/upgrade/types/types/codec.go diff --git a/x/upgrade/internal/types/handler.go b/x/upgrade/types/types/handler.go similarity index 100% rename from x/upgrade/internal/types/handler.go rename to x/upgrade/types/types/handler.go diff --git a/x/upgrade/internal/types/keys.go b/x/upgrade/types/types/keys.go similarity index 100% rename from x/upgrade/internal/types/keys.go rename to x/upgrade/types/types/keys.go diff --git a/x/upgrade/internal/types/plan.go b/x/upgrade/types/types/plan.go similarity index 100% rename from x/upgrade/internal/types/plan.go rename to x/upgrade/types/types/plan.go diff --git a/x/upgrade/internal/types/plan_test.go b/x/upgrade/types/types/plan_test.go similarity index 100% rename from x/upgrade/internal/types/plan_test.go rename to x/upgrade/types/types/plan_test.go diff --git a/x/upgrade/internal/types/proposal.go b/x/upgrade/types/types/proposal.go similarity index 100% rename from x/upgrade/internal/types/proposal.go rename to x/upgrade/types/types/proposal.go diff --git a/x/upgrade/internal/types/proposal_test.go b/x/upgrade/types/types/proposal_test.go similarity index 100% rename from x/upgrade/internal/types/proposal_test.go rename to x/upgrade/types/types/proposal_test.go diff --git a/x/upgrade/internal/types/querier.go b/x/upgrade/types/types/querier.go similarity index 100% rename from x/upgrade/internal/types/querier.go rename to x/upgrade/types/types/querier.go diff --git a/x/upgrade/internal/types/types.pb.go b/x/upgrade/types/types/types.pb.go similarity index 100% rename from x/upgrade/internal/types/types.pb.go rename to x/upgrade/types/types/types.pb.go diff --git a/x/upgrade/internal/types/types.proto b/x/upgrade/types/types/types.proto similarity index 100% rename from x/upgrade/internal/types/types.proto rename to x/upgrade/types/types/types.proto From 211ae9be63326be38602e6e388a10f07231c3cf5 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 19 Feb 2020 09:56:20 -0500 Subject: [PATCH 05/11] Fix package organization --- x/upgrade/alias.go | 50 ++++++++++---------- x/upgrade/client/cli/query.go | 10 ++-- x/upgrade/client/cli/tx.go | 8 ++-- x/upgrade/client/rest/query.go | 10 ++-- x/upgrade/client/rest/tx.go | 8 ++-- x/upgrade/keeper/{keeper => }/keeper.go | 26 +++++----- x/upgrade/keeper/{keeper => }/querier.go | 10 ++-- x/upgrade/types/{types => }/codec.go | 0 x/upgrade/types/{types => }/handler.go | 0 x/upgrade/types/{types => }/keys.go | 0 x/upgrade/types/{types => }/plan.go | 0 x/upgrade/types/{types => }/plan_test.go | 0 x/upgrade/types/{types => }/proposal.go | 0 x/upgrade/types/{types => }/proposal_test.go | 0 x/upgrade/types/{types => }/querier.go | 0 x/upgrade/types/{types => }/types.pb.go | 0 x/upgrade/types/{types => }/types.proto | 2 +- 17 files changed, 62 insertions(+), 62 deletions(-) rename x/upgrade/keeper/{keeper => }/keeper.go (82%) rename x/upgrade/keeper/{keeper => }/querier.go (86%) rename x/upgrade/types/{types => }/codec.go (100%) rename x/upgrade/types/{types => }/handler.go (100%) rename x/upgrade/types/{types => }/keys.go (100%) rename x/upgrade/types/{types => }/plan.go (100%) rename x/upgrade/types/{types => }/plan_test.go (100%) rename x/upgrade/types/{types => }/proposal.go (100%) rename x/upgrade/types/{types => }/proposal_test.go (100%) rename x/upgrade/types/{types => }/querier.go (100%) rename x/upgrade/types/{types => }/types.pb.go (100%) rename x/upgrade/types/{types => }/types.proto (96%) diff --git a/x/upgrade/alias.go b/x/upgrade/alias.go index ed63403b3479..74b0231f4bec 100644 --- a/x/upgrade/alias.go +++ b/x/upgrade/alias.go @@ -3,39 +3,39 @@ package upgrade // nolint import ( - "github.com/cosmos/cosmos-sdk/x/upgrade/keeper/keeper" - "github.com/cosmos/cosmos-sdk/x/upgrade/types/types" + keeper2 "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" + types2 "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) const ( - ModuleName = types.ModuleName - RouterKey = types.RouterKey - StoreKey = types.StoreKey - QuerierKey = types.QuerierKey - PlanByte = types.PlanByte - DoneByte = types.DoneByte - ProposalTypeSoftwareUpgrade = types.ProposalTypeSoftwareUpgrade - ProposalTypeCancelSoftwareUpgrade = types.ProposalTypeCancelSoftwareUpgrade - QueryCurrent = types.QueryCurrent - QueryApplied = types.QueryApplied + ModuleName = types2.ModuleName + RouterKey = types2.RouterKey + StoreKey = types2.StoreKey + QuerierKey = types2.QuerierKey + PlanByte = types2.PlanByte + DoneByte = types2.DoneByte + ProposalTypeSoftwareUpgrade = types2.ProposalTypeSoftwareUpgrade + ProposalTypeCancelSoftwareUpgrade = types2.ProposalTypeCancelSoftwareUpgrade + QueryCurrent = types2.QueryCurrent + QueryApplied = types2.QueryApplied ) var ( // functions aliases - RegisterCodec = types.RegisterCodec - PlanKey = types.PlanKey - NewSoftwareUpgradeProposal = types.NewSoftwareUpgradeProposal - NewCancelSoftwareUpgradeProposal = types.NewCancelSoftwareUpgradeProposal - NewQueryAppliedParams = types.NewQueryAppliedParams - NewKeeper = keeper.NewKeeper - NewQuerier = keeper.NewQuerier + RegisterCodec = types2.RegisterCodec + PlanKey = types2.PlanKey + NewSoftwareUpgradeProposal = types2.NewSoftwareUpgradeProposal + NewCancelSoftwareUpgradeProposal = types2.NewCancelSoftwareUpgradeProposal + NewQueryAppliedParams = types2.NewQueryAppliedParams + NewKeeper = keeper2.NewKeeper + NewQuerier = keeper2.NewQuerier ) type ( - UpgradeHandler = types.UpgradeHandler // nolint - Plan = types.Plan - SoftwareUpgradeProposal = types.SoftwareUpgradeProposal - CancelSoftwareUpgradeProposal = types.CancelSoftwareUpgradeProposal - QueryAppliedParams = types.QueryAppliedParams - Keeper = keeper.Keeper + UpgradeHandler = types2.UpgradeHandler // nolint + Plan = types2.Plan + SoftwareUpgradeProposal = types2.SoftwareUpgradeProposal + CancelSoftwareUpgradeProposal = types2.CancelSoftwareUpgradeProposal + QueryAppliedParams = types2.QueryAppliedParams + Keeper = keeper2.Keeper ) diff --git a/x/upgrade/client/cli/query.go b/x/upgrade/client/cli/query.go index e166ecf983d3..c9022a4824bd 100644 --- a/x/upgrade/client/cli/query.go +++ b/x/upgrade/client/cli/query.go @@ -3,12 +3,12 @@ package cli import ( "encoding/binary" "fmt" + "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/codec" - upgrade "github.com/cosmos/cosmos-sdk/x/upgrade/types/types" ) // GetPlanCmd returns the query upgrade plan command @@ -22,7 +22,7 @@ func GetPlanCmd(storeName string, cdc *codec.Codec) *cobra.Command { cliCtx := context.NewCLIContext().WithCodec(cdc) // ignore height for now - res, _, err := cliCtx.Query(fmt.Sprintf("custom/%s/%s", upgrade.QuerierKey, upgrade.QueryCurrent)) + res, _, err := cliCtx.Query(fmt.Sprintf("custom/%s/%s", types.QuerierKey, types.QueryCurrent)) if err != nil { return err } @@ -31,7 +31,7 @@ func GetPlanCmd(storeName string, cdc *codec.Codec) *cobra.Command { return fmt.Errorf("no upgrade scheduled") } - var plan upgrade.Plan + var plan types.Plan err = cdc.UnmarshalJSON(res, &plan) if err != nil { return err @@ -53,13 +53,13 @@ func GetAppliedHeightCmd(storeName string, cdc *codec.Codec) *cobra.Command { cliCtx := context.NewCLIContext().WithCodec(cdc) name := args[0] - params := upgrade.NewQueryAppliedParams(name) + params := types.NewQueryAppliedParams(name) bz, err := cliCtx.Codec.MarshalJSON(params) if err != nil { return err } - res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", upgrade.QuerierKey, upgrade.QueryApplied), bz) + res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierKey, types.QueryApplied), bz) if err != nil { return err } diff --git a/x/upgrade/client/cli/tx.go b/x/upgrade/client/cli/tx.go index ce494af875d9..6d9e33b2d50a 100644 --- a/x/upgrade/client/cli/tx.go +++ b/x/upgrade/client/cli/tx.go @@ -3,6 +3,7 @@ package cli import ( "bufio" "fmt" + "github.com/cosmos/cosmos-sdk/x/upgrade/types" "time" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" @@ -15,7 +16,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/gov" - upgrade "github.com/cosmos/cosmos-sdk/x/upgrade/types/types" ) const ( @@ -65,8 +65,8 @@ func parseArgsToContent(cmd *cobra.Command, name string) (gov.Content, error) { return nil, err } - plan := upgrade.Plan{Name: name, Time: upgradeTime, Height: height, Info: info} - content := upgrade.NewSoftwareUpgradeProposal(title, description, plan) + plan := types.Plan{Name: name, Time: upgradeTime, Height: height, Info: info} + content := types.NewSoftwareUpgradeProposal(title, description, plan) return content, nil } @@ -151,7 +151,7 @@ func GetCmdSubmitCancelUpgradeProposal(cdc *codec.Codec) *cobra.Command { return err } - content := upgrade.NewCancelSoftwareUpgradeProposal(title, description) + content := types.NewCancelSoftwareUpgradeProposal(title, description) msg := gov.NewMsgSubmitProposal(content, deposit, from) if err := msg.ValidateBasic(); err != nil { diff --git a/x/upgrade/client/rest/query.go b/x/upgrade/client/rest/query.go index 6e7617294b88..859559e23079 100644 --- a/x/upgrade/client/rest/query.go +++ b/x/upgrade/client/rest/query.go @@ -3,13 +3,13 @@ package rest import ( "encoding/binary" "fmt" + "github.com/cosmos/cosmos-sdk/x/upgrade/types" "net/http" "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/types/rest" - upgrade "github.com/cosmos/cosmos-sdk/x/upgrade/types/types" ) // RegisterRoutes registers REST routes for the upgrade module under the path specified by routeName. @@ -22,7 +22,7 @@ func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router) { func getCurrentPlanHandler(cliCtx context.CLIContext) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, request *http.Request) { // ignore height for now - res, _, err := cliCtx.Query(fmt.Sprintf("custom/%s/%s", upgrade.QuerierKey, upgrade.QueryCurrent)) + res, _, err := cliCtx.Query(fmt.Sprintf("custom/%s/%s", types.QuerierKey, types.QueryCurrent)) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return @@ -32,7 +32,7 @@ func getCurrentPlanHandler(cliCtx context.CLIContext) func(http.ResponseWriter, return } - var plan upgrade.Plan + var plan types.Plan err = cliCtx.Codec.UnmarshalBinaryBare(res, &plan) if err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) @@ -47,14 +47,14 @@ func getDonePlanHandler(cliCtx context.CLIContext) func(http.ResponseWriter, *ht return func(w http.ResponseWriter, r *http.Request) { name := mux.Vars(r)["name"] - params := upgrade.NewQueryAppliedParams(name) + params := types.NewQueryAppliedParams(name) bz, err := cliCtx.Codec.MarshalJSON(params) if err != nil { rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) return } - res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", upgrade.QuerierKey, upgrade.QueryApplied), bz) + res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierKey, types.QueryApplied), bz) if err != nil { rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) return diff --git a/x/upgrade/client/rest/tx.go b/x/upgrade/client/rest/tx.go index 53f21714c417..dd5dff5e85a0 100644 --- a/x/upgrade/client/rest/tx.go +++ b/x/upgrade/client/rest/tx.go @@ -1,6 +1,7 @@ package rest import ( + types2 "github.com/cosmos/cosmos-sdk/x/upgrade/types" "net/http" "time" @@ -13,7 +14,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" "github.com/cosmos/cosmos-sdk/x/gov" - "github.com/cosmos/cosmos-sdk/x/upgrade/types/types" ) func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router) { @@ -76,8 +76,8 @@ func postPlanHandler(cliCtx context.CLIContext) http.HandlerFunc { } } - plan := types.Plan{Name: req.UpgradeName, Time: t, Height: req.UpgradeHeight, Info: req.UpgradeInfo} - content := types.NewSoftwareUpgradeProposal(req.Title, req.Description, plan) + plan := types2.Plan{Name: req.UpgradeName, Time: t, Height: req.UpgradeHeight, Info: req.UpgradeInfo} + content := types2.NewSoftwareUpgradeProposal(req.Title, req.Description, plan) msg := gov.NewMsgSubmitProposal(content, req.Deposit, fromAddr) if err := msg.ValidateBasic(); err != nil { rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) @@ -107,7 +107,7 @@ func cancelPlanHandler(cliCtx context.CLIContext) http.HandlerFunc { return } - content := types.NewCancelSoftwareUpgradeProposal(req.Title, req.Description) + content := types2.NewCancelSoftwareUpgradeProposal(req.Title, req.Description) msg := gov.NewMsgSubmitProposal(content, req.Deposit, fromAddr) if err := msg.ValidateBasic(); err != nil { rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) diff --git a/x/upgrade/keeper/keeper/keeper.go b/x/upgrade/keeper/keeper.go similarity index 82% rename from x/upgrade/keeper/keeper/keeper.go rename to x/upgrade/keeper/keeper.go index 6ad261eb5cbc..ec99cb083806 100644 --- a/x/upgrade/keeper/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -3,6 +3,7 @@ package keeper import ( "encoding/binary" "fmt" + types2 "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/tendermint/tendermint/libs/log" @@ -10,14 +11,13 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/upgrade/types/types" ) type Keeper struct { skipUpgradeHeights map[int64]bool storeKey sdk.StoreKey cdc codec.Marshaler - upgradeHandlers map[string]types.UpgradeHandler + upgradeHandlers map[string]types2.UpgradeHandler } // NewKeeper constructs an upgrade Keeper @@ -26,21 +26,21 @@ func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey sdk.StoreKey, cdc cod skipUpgradeHeights: skipUpgradeHeights, storeKey: storeKey, cdc: cdc, - upgradeHandlers: map[string]types.UpgradeHandler{}, + upgradeHandlers: map[string]types2.UpgradeHandler{}, } } // SetUpgradeHandler sets an UpgradeHandler for the upgrade specified by name. This handler will be called when the upgrade // with this name is applied. In order for an upgrade with the given name to proceed, a handler for this upgrade // must be set even if it is a no-op function. -func (k Keeper) SetUpgradeHandler(name string, upgradeHandler types.UpgradeHandler) { +func (k Keeper) SetUpgradeHandler(name string, upgradeHandler types2.UpgradeHandler) { k.upgradeHandlers[name] = upgradeHandler } // ScheduleUpgrade schedules an upgrade based on the specified plan. // If there is another Plan already scheduled, it will overwrite it // (implicitly cancelling the current plan) -func (k Keeper) ScheduleUpgrade(ctx sdk.Context, plan types.Plan) error { +func (k Keeper) ScheduleUpgrade(ctx sdk.Context, plan types2.Plan) error { if err := plan.ValidateBasic(); err != nil { return err } @@ -59,14 +59,14 @@ func (k Keeper) ScheduleUpgrade(ctx sdk.Context, plan types.Plan) error { bz := k.cdc.MustMarshalBinaryBare(&plan) store := ctx.KVStore(k.storeKey) - store.Set(types.PlanKey(), bz) + store.Set(types2.PlanKey(), bz) return nil } // GetDoneHeight returns the height at which the given upgrade was executed func (k Keeper) GetDoneHeight(ctx sdk.Context, name string) int64 { - store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte{types.DoneByte}) + store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte{types2.DoneByte}) bz := store.Get([]byte(name)) if len(bz) == 0 { return 0 @@ -78,19 +78,19 @@ func (k Keeper) GetDoneHeight(ctx sdk.Context, name string) int64 { // ClearUpgradePlan clears any schedule upgrade func (k Keeper) ClearUpgradePlan(ctx sdk.Context) { store := ctx.KVStore(k.storeKey) - store.Delete(types.PlanKey()) + store.Delete(types2.PlanKey()) } // Logger returns a module-specific logger. func (k Keeper) Logger(ctx sdk.Context) log.Logger { - return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) + return ctx.Logger().With("module", fmt.Sprintf("x/%s", types2.ModuleName)) } // GetUpgradePlan returns the currently scheduled Plan if any, setting havePlan to true if there is a scheduled // upgrade or false if there is none -func (k Keeper) GetUpgradePlan(ctx sdk.Context) (plan types.Plan, havePlan bool) { +func (k Keeper) GetUpgradePlan(ctx sdk.Context) (plan types2.Plan, havePlan bool) { store := ctx.KVStore(k.storeKey) - bz := store.Get(types.PlanKey()) + bz := store.Get(types2.PlanKey()) if bz == nil { return plan, false } @@ -101,7 +101,7 @@ func (k Keeper) GetUpgradePlan(ctx sdk.Context) (plan types.Plan, havePlan bool) // setDone marks this upgrade name as being done so the name can't be reused accidentally func (k Keeper) setDone(ctx sdk.Context, name string) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte{types.DoneByte}) + store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte{types2.DoneByte}) bz := make([]byte, 8) binary.BigEndian.PutUint64(bz, uint64(ctx.BlockHeight())) store.Set([]byte(name), bz) @@ -114,7 +114,7 @@ func (k Keeper) HasHandler(name string) bool { } // ApplyUpgrade will execute the handler associated with the Plan and mark the plan as done. -func (k Keeper) ApplyUpgrade(ctx sdk.Context, plan types.Plan) { +func (k Keeper) ApplyUpgrade(ctx sdk.Context, plan types2.Plan) { handler := k.upgradeHandlers[plan.Name] if handler == nil { panic("ApplyUpgrade should never be called without first checking HasHandler") diff --git a/x/upgrade/keeper/keeper/querier.go b/x/upgrade/keeper/querier.go similarity index 86% rename from x/upgrade/keeper/keeper/querier.go rename to x/upgrade/keeper/querier.go index 8e8e2314166c..9ed41f9e4dea 100644 --- a/x/upgrade/keeper/keeper/querier.go +++ b/x/upgrade/keeper/querier.go @@ -2,12 +2,12 @@ package keeper import ( "encoding/binary" + types2 "github.com/cosmos/cosmos-sdk/x/upgrade/types" abci "github.com/tendermint/tendermint/abci/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/upgrade/types/types" ) // NewQuerier creates a querier for upgrade cli and REST endpoints @@ -15,14 +15,14 @@ func NewQuerier(k Keeper) sdk.Querier { return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, error) { switch path[0] { - case types.QueryCurrent: + case types2.QueryCurrent: return queryCurrent(ctx, req, k) - case types.QueryApplied: + case types2.QueryApplied: return queryApplied(ctx, req, k) default: - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown %s query endpoint: %s", types.ModuleName, path[0]) + return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown %s query endpoint: %s", types2.ModuleName, path[0]) } } } @@ -42,7 +42,7 @@ func queryCurrent(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, err } func queryApplied(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { - var params types.QueryAppliedParams + var params types2.QueryAppliedParams err := k.cdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { diff --git a/x/upgrade/types/types/codec.go b/x/upgrade/types/codec.go similarity index 100% rename from x/upgrade/types/types/codec.go rename to x/upgrade/types/codec.go diff --git a/x/upgrade/types/types/handler.go b/x/upgrade/types/handler.go similarity index 100% rename from x/upgrade/types/types/handler.go rename to x/upgrade/types/handler.go diff --git a/x/upgrade/types/types/keys.go b/x/upgrade/types/keys.go similarity index 100% rename from x/upgrade/types/types/keys.go rename to x/upgrade/types/keys.go diff --git a/x/upgrade/types/types/plan.go b/x/upgrade/types/plan.go similarity index 100% rename from x/upgrade/types/types/plan.go rename to x/upgrade/types/plan.go diff --git a/x/upgrade/types/types/plan_test.go b/x/upgrade/types/plan_test.go similarity index 100% rename from x/upgrade/types/types/plan_test.go rename to x/upgrade/types/plan_test.go diff --git a/x/upgrade/types/types/proposal.go b/x/upgrade/types/proposal.go similarity index 100% rename from x/upgrade/types/types/proposal.go rename to x/upgrade/types/proposal.go diff --git a/x/upgrade/types/types/proposal_test.go b/x/upgrade/types/proposal_test.go similarity index 100% rename from x/upgrade/types/types/proposal_test.go rename to x/upgrade/types/proposal_test.go diff --git a/x/upgrade/types/types/querier.go b/x/upgrade/types/querier.go similarity index 100% rename from x/upgrade/types/types/querier.go rename to x/upgrade/types/querier.go diff --git a/x/upgrade/types/types/types.pb.go b/x/upgrade/types/types.pb.go similarity index 100% rename from x/upgrade/types/types/types.pb.go rename to x/upgrade/types/types.pb.go diff --git a/x/upgrade/types/types/types.proto b/x/upgrade/types/types.proto similarity index 96% rename from x/upgrade/types/types/types.proto rename to x/upgrade/types/types.proto index fd52d01e7cd0..8770158c4bdb 100644 --- a/x/upgrade/types/types/types.proto +++ b/x/upgrade/types/types.proto @@ -4,7 +4,7 @@ package cosmos_sdk.x.upgrade.v1; import "third_party/proto/gogoproto/gogo.proto"; import "google/protobuf/timestamp.proto"; -option go_package = "github.com/cosmos/cosmos-sdk/x/params/types"; +option go_package = "github.com/cosmos/cosmos-sdk/x/upgrade/types"; option (gogoproto.goproto_stringer_all) = false; option (gogoproto.goproto_getters_all) = false; From cfbd549eed0f4cf06e90e04283f6108686a9e88d Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 19 Feb 2020 14:48:00 -0500 Subject: [PATCH 06/11] Update x/upgrade/alias.go Co-Authored-By: Alexander Bezobchuk --- x/upgrade/alias.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/upgrade/alias.go b/x/upgrade/alias.go index 74b0231f4bec..6f7d2c525ee8 100644 --- a/x/upgrade/alias.go +++ b/x/upgrade/alias.go @@ -3,7 +3,7 @@ package upgrade // nolint import ( - keeper2 "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" + "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" types2 "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) From a73d592a3cabe7c31ccb66ab220c7ebf8cebeb29 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 19 Feb 2020 14:48:23 -0500 Subject: [PATCH 07/11] Update x/upgrade/client/rest/tx.go Co-Authored-By: Alexander Bezobchuk --- x/upgrade/client/rest/tx.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/upgrade/client/rest/tx.go b/x/upgrade/client/rest/tx.go index dd5dff5e85a0..699d13b6611b 100644 --- a/x/upgrade/client/rest/tx.go +++ b/x/upgrade/client/rest/tx.go @@ -1,7 +1,7 @@ package rest import ( - types2 "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/cosmos/cosmos-sdk/x/upgrade/types" "net/http" "time" From 9627f68985fbe4d058f4e026ca9e2eb1fcde1bb8 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 19 Feb 2020 14:48:31 -0500 Subject: [PATCH 08/11] Update x/upgrade/alias.go Co-Authored-By: Alexander Bezobchuk --- x/upgrade/alias.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/upgrade/alias.go b/x/upgrade/alias.go index 6f7d2c525ee8..881fcc987972 100644 --- a/x/upgrade/alias.go +++ b/x/upgrade/alias.go @@ -4,7 +4,7 @@ package upgrade import ( "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" - types2 "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) const ( From 0c54f2f7517947f02fa282eb838f8810a1f8ea72 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 19 Feb 2020 14:51:20 -0500 Subject: [PATCH 09/11] Fix imports --- x/upgrade/alias.go | 46 ++++++++++++++++++------------------- x/upgrade/client/rest/tx.go | 6 ++--- x/upgrade/keeper/keeper.go | 26 ++++++++++----------- x/upgrade/keeper/querier.go | 10 ++++---- 4 files changed, 44 insertions(+), 44 deletions(-) diff --git a/x/upgrade/alias.go b/x/upgrade/alias.go index 881fcc987972..bf0b6523b05e 100644 --- a/x/upgrade/alias.go +++ b/x/upgrade/alias.go @@ -8,34 +8,34 @@ import ( ) const ( - ModuleName = types2.ModuleName - RouterKey = types2.RouterKey - StoreKey = types2.StoreKey - QuerierKey = types2.QuerierKey - PlanByte = types2.PlanByte - DoneByte = types2.DoneByte - ProposalTypeSoftwareUpgrade = types2.ProposalTypeSoftwareUpgrade - ProposalTypeCancelSoftwareUpgrade = types2.ProposalTypeCancelSoftwareUpgrade - QueryCurrent = types2.QueryCurrent - QueryApplied = types2.QueryApplied + ModuleName = types.ModuleName + RouterKey = types.RouterKey + StoreKey = types.StoreKey + QuerierKey = types.QuerierKey + PlanByte = types.PlanByte + DoneByte = types.DoneByte + ProposalTypeSoftwareUpgrade = types.ProposalTypeSoftwareUpgrade + ProposalTypeCancelSoftwareUpgrade = types.ProposalTypeCancelSoftwareUpgrade + QueryCurrent = types.QueryCurrent + QueryApplied = types.QueryApplied ) var ( // functions aliases - RegisterCodec = types2.RegisterCodec - PlanKey = types2.PlanKey - NewSoftwareUpgradeProposal = types2.NewSoftwareUpgradeProposal - NewCancelSoftwareUpgradeProposal = types2.NewCancelSoftwareUpgradeProposal - NewQueryAppliedParams = types2.NewQueryAppliedParams - NewKeeper = keeper2.NewKeeper - NewQuerier = keeper2.NewQuerier + RegisterCodec = types.RegisterCodec + PlanKey = types.PlanKey + NewSoftwareUpgradeProposal = types.NewSoftwareUpgradeProposal + NewCancelSoftwareUpgradeProposal = types.NewCancelSoftwareUpgradeProposal + NewQueryAppliedParams = types.NewQueryAppliedParams + NewKeeper = keeper.NewKeeper + NewQuerier = keeper.NewQuerier ) type ( - UpgradeHandler = types2.UpgradeHandler // nolint - Plan = types2.Plan - SoftwareUpgradeProposal = types2.SoftwareUpgradeProposal - CancelSoftwareUpgradeProposal = types2.CancelSoftwareUpgradeProposal - QueryAppliedParams = types2.QueryAppliedParams - Keeper = keeper2.Keeper + UpgradeHandler = types.UpgradeHandler // nolint + Plan = types.Plan + SoftwareUpgradeProposal = types.SoftwareUpgradeProposal + CancelSoftwareUpgradeProposal = types.CancelSoftwareUpgradeProposal + QueryAppliedParams = types.QueryAppliedParams + Keeper = keeper.Keeper ) diff --git a/x/upgrade/client/rest/tx.go b/x/upgrade/client/rest/tx.go index 699d13b6611b..6cbc76ff2a40 100644 --- a/x/upgrade/client/rest/tx.go +++ b/x/upgrade/client/rest/tx.go @@ -76,8 +76,8 @@ func postPlanHandler(cliCtx context.CLIContext) http.HandlerFunc { } } - plan := types2.Plan{Name: req.UpgradeName, Time: t, Height: req.UpgradeHeight, Info: req.UpgradeInfo} - content := types2.NewSoftwareUpgradeProposal(req.Title, req.Description, plan) + plan := types.Plan{Name: req.UpgradeName, Time: t, Height: req.UpgradeHeight, Info: req.UpgradeInfo} + content := types.NewSoftwareUpgradeProposal(req.Title, req.Description, plan) msg := gov.NewMsgSubmitProposal(content, req.Deposit, fromAddr) if err := msg.ValidateBasic(); err != nil { rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) @@ -107,7 +107,7 @@ func cancelPlanHandler(cliCtx context.CLIContext) http.HandlerFunc { return } - content := types2.NewCancelSoftwareUpgradeProposal(req.Title, req.Description) + content := types.NewCancelSoftwareUpgradeProposal(req.Title, req.Description) msg := gov.NewMsgSubmitProposal(content, req.Deposit, fromAddr) if err := msg.ValidateBasic(); err != nil { rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error()) diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index ec99cb083806..03802b335c5d 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -3,7 +3,7 @@ package keeper import ( "encoding/binary" "fmt" - types2 "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/tendermint/tendermint/libs/log" @@ -17,7 +17,7 @@ type Keeper struct { skipUpgradeHeights map[int64]bool storeKey sdk.StoreKey cdc codec.Marshaler - upgradeHandlers map[string]types2.UpgradeHandler + upgradeHandlers map[string]types.UpgradeHandler } // NewKeeper constructs an upgrade Keeper @@ -26,21 +26,21 @@ func NewKeeper(skipUpgradeHeights map[int64]bool, storeKey sdk.StoreKey, cdc cod skipUpgradeHeights: skipUpgradeHeights, storeKey: storeKey, cdc: cdc, - upgradeHandlers: map[string]types2.UpgradeHandler{}, + upgradeHandlers: map[string]types.UpgradeHandler{}, } } // SetUpgradeHandler sets an UpgradeHandler for the upgrade specified by name. This handler will be called when the upgrade // with this name is applied. In order for an upgrade with the given name to proceed, a handler for this upgrade // must be set even if it is a no-op function. -func (k Keeper) SetUpgradeHandler(name string, upgradeHandler types2.UpgradeHandler) { +func (k Keeper) SetUpgradeHandler(name string, upgradeHandler types.UpgradeHandler) { k.upgradeHandlers[name] = upgradeHandler } // ScheduleUpgrade schedules an upgrade based on the specified plan. // If there is another Plan already scheduled, it will overwrite it // (implicitly cancelling the current plan) -func (k Keeper) ScheduleUpgrade(ctx sdk.Context, plan types2.Plan) error { +func (k Keeper) ScheduleUpgrade(ctx sdk.Context, plan types.Plan) error { if err := plan.ValidateBasic(); err != nil { return err } @@ -59,14 +59,14 @@ func (k Keeper) ScheduleUpgrade(ctx sdk.Context, plan types2.Plan) error { bz := k.cdc.MustMarshalBinaryBare(&plan) store := ctx.KVStore(k.storeKey) - store.Set(types2.PlanKey(), bz) + store.Set(types.PlanKey(), bz) return nil } // GetDoneHeight returns the height at which the given upgrade was executed func (k Keeper) GetDoneHeight(ctx sdk.Context, name string) int64 { - store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte{types2.DoneByte}) + store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte{types.DoneByte}) bz := store.Get([]byte(name)) if len(bz) == 0 { return 0 @@ -78,19 +78,19 @@ func (k Keeper) GetDoneHeight(ctx sdk.Context, name string) int64 { // ClearUpgradePlan clears any schedule upgrade func (k Keeper) ClearUpgradePlan(ctx sdk.Context) { store := ctx.KVStore(k.storeKey) - store.Delete(types2.PlanKey()) + store.Delete(types.PlanKey()) } // Logger returns a module-specific logger. func (k Keeper) Logger(ctx sdk.Context) log.Logger { - return ctx.Logger().With("module", fmt.Sprintf("x/%s", types2.ModuleName)) + return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) } // GetUpgradePlan returns the currently scheduled Plan if any, setting havePlan to true if there is a scheduled // upgrade or false if there is none -func (k Keeper) GetUpgradePlan(ctx sdk.Context) (plan types2.Plan, havePlan bool) { +func (k Keeper) GetUpgradePlan(ctx sdk.Context) (plan types.Plan, havePlan bool) { store := ctx.KVStore(k.storeKey) - bz := store.Get(types2.PlanKey()) + bz := store.Get(types.PlanKey()) if bz == nil { return plan, false } @@ -101,7 +101,7 @@ func (k Keeper) GetUpgradePlan(ctx sdk.Context) (plan types2.Plan, havePlan bool // setDone marks this upgrade name as being done so the name can't be reused accidentally func (k Keeper) setDone(ctx sdk.Context, name string) { - store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte{types2.DoneByte}) + store := prefix.NewStore(ctx.KVStore(k.storeKey), []byte{types.DoneByte}) bz := make([]byte, 8) binary.BigEndian.PutUint64(bz, uint64(ctx.BlockHeight())) store.Set([]byte(name), bz) @@ -114,7 +114,7 @@ func (k Keeper) HasHandler(name string) bool { } // ApplyUpgrade will execute the handler associated with the Plan and mark the plan as done. -func (k Keeper) ApplyUpgrade(ctx sdk.Context, plan types2.Plan) { +func (k Keeper) ApplyUpgrade(ctx sdk.Context, plan types.Plan) { handler := k.upgradeHandlers[plan.Name] if handler == nil { panic("ApplyUpgrade should never be called without first checking HasHandler") diff --git a/x/upgrade/keeper/querier.go b/x/upgrade/keeper/querier.go index 9ed41f9e4dea..2a3ff8bf6dff 100644 --- a/x/upgrade/keeper/querier.go +++ b/x/upgrade/keeper/querier.go @@ -2,7 +2,7 @@ package keeper import ( "encoding/binary" - types2 "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/cosmos/cosmos-sdk/x/upgrade/types" abci "github.com/tendermint/tendermint/abci/types" @@ -15,14 +15,14 @@ func NewQuerier(k Keeper) sdk.Querier { return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, error) { switch path[0] { - case types2.QueryCurrent: + case types.QueryCurrent: return queryCurrent(ctx, req, k) - case types2.QueryApplied: + case types.QueryApplied: return queryApplied(ctx, req, k) default: - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown %s query endpoint: %s", types2.ModuleName, path[0]) + return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown %s query endpoint: %s", types.ModuleName, path[0]) } } } @@ -42,7 +42,7 @@ func queryCurrent(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, err } func queryApplied(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) { - var params types2.QueryAppliedParams + var params types.QueryAppliedParams err := k.cdc.UnmarshalJSON(req.Data, ¶ms) if err != nil { From eaf71f3f43688dda64e69d4e08529e6d54ef9780 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 24 Feb 2020 10:47:37 -0500 Subject: [PATCH 10/11] Fix formatting --- x/upgrade/alias.go | 4 ++-- x/upgrade/client/rest/tx.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x/upgrade/alias.go b/x/upgrade/alias.go index bf0b6523b05e..c8ae7bf63157 100644 --- a/x/upgrade/alias.go +++ b/x/upgrade/alias.go @@ -3,8 +3,8 @@ package upgrade // nolint import ( - "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" - "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" + "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) const ( diff --git a/x/upgrade/client/rest/tx.go b/x/upgrade/client/rest/tx.go index 6cbc76ff2a40..cb33896dd89e 100644 --- a/x/upgrade/client/rest/tx.go +++ b/x/upgrade/client/rest/tx.go @@ -1,7 +1,7 @@ package rest import ( - "github.com/cosmos/cosmos-sdk/x/upgrade/types" + "github.com/cosmos/cosmos-sdk/x/upgrade/types" "net/http" "time" From 6feb7eda1f0ff0b7ae2a9c7c9e36afb9fb7ae8d9 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Mon, 24 Feb 2020 11:06:27 -0500 Subject: [PATCH 11/11] Attempt to reorder imports to satisgy GolangCI --- x/upgrade/client/cli/tx.go | 2 +- x/upgrade/client/rest/query.go | 2 +- x/upgrade/client/rest/tx.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x/upgrade/client/cli/tx.go b/x/upgrade/client/cli/tx.go index 6d9e33b2d50a..6e325aa9c042 100644 --- a/x/upgrade/client/cli/tx.go +++ b/x/upgrade/client/cli/tx.go @@ -3,7 +3,6 @@ package cli import ( "bufio" "fmt" - "github.com/cosmos/cosmos-sdk/x/upgrade/types" "time" authclient "github.com/cosmos/cosmos-sdk/x/auth/client" @@ -16,6 +15,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/gov" + "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) const ( diff --git a/x/upgrade/client/rest/query.go b/x/upgrade/client/rest/query.go index 859559e23079..8c3372b2a7aa 100644 --- a/x/upgrade/client/rest/query.go +++ b/x/upgrade/client/rest/query.go @@ -3,13 +3,13 @@ package rest import ( "encoding/binary" "fmt" - "github.com/cosmos/cosmos-sdk/x/upgrade/types" "net/http" "github.com/gorilla/mux" "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/types/rest" + "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) // RegisterRoutes registers REST routes for the upgrade module under the path specified by routeName. diff --git a/x/upgrade/client/rest/tx.go b/x/upgrade/client/rest/tx.go index cb33896dd89e..e67aa79bfc61 100644 --- a/x/upgrade/client/rest/tx.go +++ b/x/upgrade/client/rest/tx.go @@ -1,7 +1,6 @@ package rest import ( - "github.com/cosmos/cosmos-sdk/x/upgrade/types" "net/http" "time" @@ -14,6 +13,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/rest" "github.com/cosmos/cosmos-sdk/x/gov" + "github.com/cosmos/cosmos-sdk/x/upgrade/types" ) func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router) {