Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate upgrade module to protobuf #5659

Merged
merged 11 commits into from
Feb 24, 2020
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions x/upgrade/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
10 changes: 5 additions & 5 deletions x/upgrade/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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
Expand All @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions x/upgrade/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions x/upgrade/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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())
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion x/upgrade/client/rest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ package keeper
import (
"encoding/binary"
"fmt"
"github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/tendermint/tendermint/libs/log"

"github.com/cosmos/cosmos-sdk/codec"
"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,
Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 0 additions & 22 deletions x/upgrade/internal/types/plan.go → x/upgrade/types/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
Expand Down Expand Up @@ -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}
}
Expand Down
File renamed without changes.
Loading