Skip to content

Commit

Permalink
node repo fix for bnb-chain/bnc-cosmos-sdk#150
Browse files Browse the repository at this point in the history
  • Loading branch information
ackratos authored and forcodedancing committed May 19, 2022
1 parent 537b2e2 commit 591b656
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
16 changes: 1 addition & 15 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,21 +242,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() {
Expand Down
23 changes: 23 additions & 0 deletions app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.BEP19Height)

// 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
Expand Down
12 changes: 10 additions & 2 deletions cmd/bnbchaind/init/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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})
Expand Down Expand Up @@ -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
},
Expand Down

0 comments on commit 591b656

Please sign in to comment.