Merge PR #5659: Migrate upgrade module to protobuf

This commit is contained in:
Aaron Craelius 2020-02-24 12:14:19 -05:00 committed by GitHub
parent f7486b9395
commit df65016694
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 993 additions and 58 deletions

View File

@ -126,6 +126,10 @@ 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 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

View File

@ -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], appCodec)
// create evidence keeper with router
evidenceKeeper := evidence.NewKeeper(

View File

@ -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"
"github.com/cosmos/cosmos-sdk/x/upgrade/types"
)
const (

View File

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

View File

@ -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"
"github.com/cosmos/cosmos-sdk/x/upgrade/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 {

View File

@ -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"
"github.com/cosmos/cosmos-sdk/x/upgrade/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

View File

@ -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"
)
func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router) {

View File

@ -3,6 +3,7 @@ package keeper
import (
"encoding/binary"
"fmt"
"github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/tendermint/tendermint/libs/log"
@ -10,18 +11,17 @@ 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"
)
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)

View File

@ -2,12 +2,12 @@ package keeper
import (
"encoding/binary"
"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/internal/types"
)
// NewQuerier creates a querier for upgrade cli and REST endpoints

View File

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

View File

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

922
x/upgrade/types/types.pb.go Normal file
View File

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

View File

@ -0,0 +1,44 @@
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/upgrade/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;
}
// 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;
}