From 6ab0c3936a4873c6881d489cf2c11b833dd6f0aa Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Sun, 24 Mar 2019 21:55:59 -0400 Subject: [PATCH 1/9] #13 WIP on improvements to upgrade module --- app.go | 22 +++++- testnets/next/genesis.json | 15 +++- x/consortium/actions.go | 28 +++++-- x/consortium/client/cli/tx.go | 27 +++++-- x/consortium/keeper.go | 22 +++++- x/group/types.go | 2 +- x/proposal/client/cli/tx.go | 7 +- x/proposal/handler.go | 14 +++- x/proposal/keeper.go | 24 ++---- x/proposal/msgs.go | 28 ++++--- x/proposal/router.go | 2 +- x/upgrade/keeper.go | 145 +++++++++++++++++++++++----------- 12 files changed, 230 insertions(+), 106 deletions(-) diff --git a/app.go b/app.go index 9c591622d1..8c81ab32dd 100644 --- a/app.go +++ b/app.go @@ -11,7 +11,12 @@ import ( "github.com/regen-network/regen-ledger/x/group" "github.com/regen-network/regen-ledger/x/proposal" "github.com/regen-network/regen-ledger/x/upgrade" + "github.com/spf13/viper" + "github.com/tendermint/tendermint/libs/cli" "github.com/tendermint/tendermint/libs/log" + "io/ioutil" + "path/filepath" + //"os" "github.com/cosmos/cosmos-sdk/codec" @@ -152,7 +157,11 @@ func NewXrnApp(logger log.Logger, db dbm.DB, postgresUrl string) *xrnApp { app.espKeeper = esp.NewKeeper(app.espStoreKey, app.agentKeeper, app.geoKeeper, cdc) - app.upgradeKeeper = upgrade.NewKeeper(app.upgradeStoreKey, cdc, 1000) + app.upgradeKeeper = upgrade.NewKeeper(app.upgradeStoreKey, cdc) + app.upgradeKeeper.SetBeforeShutdowner(app.willUpgrade) + app.upgradeKeeper.SetUpgradeHandler("test3", func(ctx sdk.Context, plan upgrade.UpgradePlan) { + ctx.Logger().Info("In upgrade 3 handler!") + }) app.consortiumKeeper = consortium.NewKeeper(app.consortiumStoreKey, cdc, app.agentKeeper, app.upgradeKeeper) @@ -230,8 +239,8 @@ func (app *xrnApp) initChainer(ctx sdk.Context, req abci.RequestInitChain) abci. app.accountKeeper.SetAccount(ctx, acc) } - for _, group := range genesisState.Groups { - app.agentKeeper.CreateGroup(ctx, group) + for _, g := range genesisState.Groups { + app.agentKeeper.CreateGroup(ctx, g) } app.consortiumKeeper.SetValidators(ctx, req.Validators) @@ -242,6 +251,13 @@ func (app *xrnApp) initChainer(ctx sdk.Context, req abci.RequestInitChain) abci. return abci.ResponseInitChain{} } +func (app *xrnApp) willUpgrade(plan upgrade.UpgradePlan) { + if len(plan.Memo) != 0 { + home := viper.GetString(cli.HomeFlag) + _ = ioutil.WriteFile(filepath.Join(home, "data", "upgrade-info"), []byte(plan.Memo), 0644) + } +} + func (app *xrnApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock { app.upgradeKeeper.BeginBlocker(ctx, req) return abci.ResponseBeginBlock{} diff --git a/testnets/next/genesis.json b/testnets/next/genesis.json index 4b6024c291..794770e3dc 100644 --- a/testnets/next/genesis.json +++ b/testnets/next/genesis.json @@ -1,6 +1,6 @@ { "genesis_time": "2018-12-19T20:40:06.463846Z", - "chain_id": "xrn-test-2", + "chain_id": "xrn-test-next", "consensus_params": { "block_size": { "max_bytes": "22020096", @@ -60,7 +60,18 @@ "sequence": "0" } ], - "groups": [], + "groups": [ + { + "decision_threshold": "1", + "members": [ + { + "address": "xrn:1xrsmkqh305m09tc5x73v4t3wtcuqmf6cgy2taw", + "weight": "1" + } + ], + "memo": "Regen Consortium" + } + ], "auth": { "collected_fees": null, "params": { diff --git a/x/consortium/actions.go b/x/consortium/actions.go index ce8e4eb3d2..e979af77ce 100644 --- a/x/consortium/actions.go +++ b/x/consortium/actions.go @@ -8,7 +8,10 @@ import ( ) type ActionScheduleUpgrade struct { - UpgradeInfo upgrade.UpgradeInfo `json:"upgrade_info"` + Plan upgrade.UpgradePlan `json:"upgrade_plan"` +} + +type ActionCancelUpgrade struct { } /* @@ -24,16 +27,29 @@ type ActionChangeValidatorSet struct { func (action ActionScheduleUpgrade) Route() string { return "consortium" } -func (action ActionScheduleUpgrade) Type() string { return "upgrade" } +func (action ActionScheduleUpgrade) Type() string { return "consortium.upgrade" } func (action ActionScheduleUpgrade) ValidateBasic() sdk.Error { - if action.UpgradeInfo.Height <= 0 { - return sdk.ErrUnknownRequest("Upgrade height must be greater than 0") + return action.Plan.ValidateBasic() +} + +func (action ActionScheduleUpgrade) GetSignBytes() []byte { + b, err := json.Marshal(action) + if err != nil { + panic(err) } + return sdk.MustSortJSON(b) +} + +func (ActionCancelUpgrade) Route() string { return "consortium" } + +func (ActionCancelUpgrade) Type() string { return "consortium.cancel-upgrade" } + +func (ActionCancelUpgrade) ValidateBasic() sdk.Error { return nil } -func (action ActionScheduleUpgrade) GetSignBytes() []byte { +func (action ActionCancelUpgrade) GetSignBytes() []byte { b, err := json.Marshal(action) if err != nil { panic(err) @@ -43,7 +59,7 @@ func (action ActionScheduleUpgrade) GetSignBytes() []byte { func (action ActionChangeValidatorSet) Route() string { return "consortium" } -func (action ActionChangeValidatorSet) Type() string { return "changeValidatorSet" } +func (action ActionChangeValidatorSet) Type() string { return "consortium.changeValidatorSet" } func (action ActionChangeValidatorSet) ValidateBasic() sdk.Error { panic("implement me") diff --git a/x/consortium/client/cli/tx.go b/x/consortium/client/cli/tx.go index 43c7b5fe38..b49b737fd5 100644 --- a/x/consortium/client/cli/tx.go +++ b/x/consortium/client/cli/tx.go @@ -6,32 +6,43 @@ import ( proposalcli "github.com/regen-network/regen-ledger/x/proposal/client/cli" "github.com/regen-network/regen-ledger/x/upgrade" "github.com/spf13/cobra" - "strconv" + "time" "github.com/cosmos/cosmos-sdk/codec" ) func GetCmdProposeUpgrade(cdc *codec.Codec) *cobra.Command { + var timeStr string + var height int64 var memo string cmd := proposalcli.GetCmdPropose(cdc, func(cmd *cobra.Command, args []string) (action proposal.ProposalAction, e error) { - blockHeightStr := args[0] - blockHeight, err := strconv.ParseInt(blockHeightStr, 10, 64) - if err != nil { - return nil, err + name := args[0] + + var t time.Time + var err error + if len(timeStr) != 0 { + t, err = time.Parse(time.RFC3339, timeStr) + if err != nil { + panic(err) + } } return consortium.ActionScheduleUpgrade{ - UpgradeInfo: upgrade.UpgradeInfo{ - Height: blockHeight, + Plan: upgrade.UpgradePlan{ + Name: name, + Time: t, + Height: height, Memo: memo, }, }, nil }) cmd.Args = cobra.ExactArgs(1) - cmd.Use = "propose-upgrade [--upgrade-memo ]" + cmd.Use = "propose-upgrade [--upgrade-time