From fdb0e3ef618d2580e61349051bc66cf3132d3755 Mon Sep 17 00:00:00 2001 From: Cong Zhao Date: Wed, 19 Jun 2019 10:48:45 +0800 Subject: [PATCH] node repo fix for https://github.com/binance-chain/bnc-cosmos-sdk/pull/150 --- app/app.go | 16 +--------------- app/config/config.go | 23 +++++++++++++++++++++++ cmd/bnbchaind/init/snapshot.go | 12 ++++++++++-- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/app/app.go b/app/app.go index c7a28c1ed..0c5255a49 100644 --- a/app/app.go +++ b/app/app.go @@ -244,21 +244,7 @@ func NewBinanceChain(logger log.Logger, db dbm.DB, traceStore io.Writer, baseApp // setUpgradeConfig will overwrite default upgrade config func (app *BinanceChain) setUpgradeConfig() { - // register upgrade height - upgrade.Mgr.AddUpgradeHeight(upgrade.BEP6, app.upgradeConfig.BEP6Height) - upgrade.Mgr.AddUpgradeHeight(upgrade.BEP9, app.upgradeConfig.BEP9Height) - upgrade.Mgr.AddUpgradeHeight(upgrade.BEP10, app.upgradeConfig.BEP10Height) - upgrade.Mgr.AddUpgradeHeight(upgrade.BEP19, app.upgradeConfig.BEP10Height) - - // register store keys of upgrade - upgrade.Mgr.RegisterStoreKeys(upgrade.BEP9, common.TimeLockStoreKey.Name()) - - // register msg types of upgrade - upgrade.Mgr.RegisterMsgTypes(upgrade.BEP9, - timelock.TimeLockMsg{}.Type(), - timelock.TimeRelockMsg{}.Type(), - timelock.TimeUnlockMsg{}.Type(), - ) + app.upgradeConfig.SetUpgradeConfig() } func (app *BinanceChain) initRunningMode() { diff --git a/app/config/config.go b/app/config/config.go index 1f2d9f2b7..3d8d24459 100644 --- a/app/config/config.go +++ b/app/config/config.go @@ -12,6 +12,10 @@ import ( "github.com/tendermint/tendermint/libs/common" "github.com/cosmos/cosmos-sdk/server" + + commonPkg "github.com/binance-chain/node/common" + "github.com/binance-chain/node/common/upgrade" + "github.com/binance-chain/node/plugins/tokens/timelock" ) var configTemplate *template.Template @@ -308,6 +312,25 @@ func defaultUpgradeConfig() *UpgradeConfig { } } +// setUpgradeConfig will overwrite default upgrade config +func (upgradeConfig UpgradeConfig) SetUpgradeConfig() { + // register upgrade height + upgrade.Mgr.AddUpgradeHeight(upgrade.BEP6, upgradeConfig.BEP6Height) + upgrade.Mgr.AddUpgradeHeight(upgrade.BEP9, upgradeConfig.BEP9Height) + upgrade.Mgr.AddUpgradeHeight(upgrade.BEP10, upgradeConfig.BEP10Height) + upgrade.Mgr.AddUpgradeHeight(upgrade.BEP19, upgradeConfig.BEP10Height) + + // register store keys of upgrade + upgrade.Mgr.RegisterStoreKeys(upgrade.BEP9, commonPkg.TimeLockStoreKey.Name()) + + // register msg types of upgrade + upgrade.Mgr.RegisterMsgTypes(upgrade.BEP9, + timelock.TimeLockMsg{}.Type(), + timelock.TimeRelockMsg{}.Type(), + timelock.TimeUnlockMsg{}.Type(), + ) +} + func (context *BinanceChainContext) ParseAppConfigInPlace() error { // this piece of code should be consistent with bindFlagsLoadViper // vendor/github.com/tendermint/tendermint/libs/cli/setup.go:125 diff --git a/cmd/bnbchaind/init/snapshot.go b/cmd/bnbchaind/init/snapshot.go index b8855f248..f571ee563 100644 --- a/cmd/bnbchaind/init/snapshot.go +++ b/cmd/bnbchaind/init/snapshot.go @@ -17,6 +17,7 @@ import ( "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" + configPkg "github.com/binance-chain/node/app/config" "github.com/binance-chain/node/common" ) @@ -30,8 +31,12 @@ func SnapshotCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command { Short: "Take a snapshot for state sync", RunE: func(_ *cobra.Command, _ []string) error { logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) + config := ctx.Config config.SetRoot(viper.GetString(cli.HomeFlag)) + appCtx := configPkg.NewDefaultContext() + appCtx.ParseAppConfigInPlace() + appCtx.BinanceChainConfig.UpgradeConfig.SetUpgradeConfig() logger.Info("setup block db") blockDB, err := node.DefaultDBProvider(&node.DBContext{"blockstore", config}) @@ -79,8 +84,11 @@ func SnapshotCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command { helper := store.NewStateSyncHelper(logger, appDB, cms, cdc) - logger.Info("start take snapshot") - helper.ReloadSnapshotRoutine(viper.GetInt64(flagHeight), 0) + height := viper.GetInt64(flagHeight) + logger.Info("start take snapshot", "height", height) + + sdk.UpgradeMgr.SetHeight(height) + helper.ReloadSnapshotRoutine(height, 0) return nil },