From ad042399c5da3d9c704f12bc6c49f4050b098d38 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 6 Dec 2024 13:46:06 -0500 Subject: [PATCH 01/10] feat: include v2 upgrade height in binary --- app/app.go | 3 +-- cmd/celestia-appd/cmd/app_server.go | 34 +++++++++++++++++++++++++++-- pkg/appconsts/chain_ids.go | 2 ++ pkg/appconsts/upgrade_heights.go | 13 +++++++++++ 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 pkg/appconsts/upgrade_heights.go diff --git a/app/app.go b/app/app.go index eadd034ea1..21405c7530 100644 --- a/app/app.go +++ b/app/app.go @@ -179,8 +179,7 @@ type App struct { // call app.Info or app.InitChain to initialize the baseapp. // // NOTE: upgradeHeightV2 refers specifically to the height that a node will -// upgrade from v1 to v2. It will be deprecated in v3 in place for a dynamically -// signalling scheme +// upgrade from v1 to v2. func New( logger log.Logger, db dbm.DB, diff --git a/cmd/celestia-appd/cmd/app_server.go b/cmd/celestia-appd/cmd/app_server.go index b2bfecf844..a1d50b3760 100644 --- a/cmd/celestia-appd/cmd/app_server.go +++ b/cmd/celestia-appd/cmd/app_server.go @@ -1,11 +1,13 @@ package cmd import ( + "fmt" "io" "path/filepath" "github.com/celestiaorg/celestia-app/v3/app" "github.com/celestiaorg/celestia-app/v3/app/encoding" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server" @@ -44,10 +46,12 @@ func NewAppServer(logger log.Logger, db dbm.DB, traceStore io.Writer, appOptions } return app.New( - logger, db, traceStore, + logger, + db, + traceStore, cast.ToUint(appOptions.Get(server.FlagInvCheckPeriod)), encoding.MakeConfig(app.ModuleEncodingRegisters...), - cast.ToInt64(appOptions.Get(UpgradeHeightFlag)), + getUpgradeHeightV2(appOptions), appOptions, baseapp.SetPruning(pruningOpts), baseapp.SetMinGasPrices(cast.ToString(appOptions.Get(server.FlagMinGasPrices))), @@ -61,3 +65,29 @@ func NewAppServer(logger log.Logger, db dbm.DB, traceStore io.Writer, appOptions baseapp.SetSnapshot(snapshotStore, snapshottypes.NewSnapshotOptions(cast.ToUint64(appOptions.Get(server.FlagStateSyncSnapshotInterval)), cast.ToUint32(appOptions.Get(server.FlagStateSyncSnapshotKeepRecent)))), ) } + +func getUpgradeHeightV2(appOptions servertypes.AppOptions) int64 { + upgradeHeight := cast.ToInt64(appOptions.Get(UpgradeHeightFlag)) + if upgradeHeight != 0 { + fmt.Printf("upgrade height flag non-zero so using it: %d\n", upgradeHeight) + return upgradeHeight + } + + fmt.Printf("upgrade height flag zero\n") + + // TODO: this chainID doesn't always appear populated. + chainID := cast.ToString(appOptions.Get(flags.FlagChainID)) + fmt.Printf("chainID %v\n", chainID) + + switch chainID { + case appconsts.ArabicaChainID: + return appconsts.ArabicaUpgradeHeightV2 + case appconsts.MochaChainID: + return appconsts.MochaUpgradeHeightV2 + case appconsts.MainnetChainID: + return appconsts.MainnetUpgradeHeightV2 + default: + // default to the upgrade height provided by the flag + return upgradeHeight + } +} diff --git a/pkg/appconsts/chain_ids.go b/pkg/appconsts/chain_ids.go index 50c26932f9..056bc2606e 100644 --- a/pkg/appconsts/chain_ids.go +++ b/pkg/appconsts/chain_ids.go @@ -2,4 +2,6 @@ package appconsts const ( ArabicaChainID = "arabica-11" + MochaChainID = "mocha-4" + MainnetChainID = "celestia" ) diff --git a/pkg/appconsts/upgrade_heights.go b/pkg/appconsts/upgrade_heights.go new file mode 100644 index 0000000000..13ee0963f0 --- /dev/null +++ b/pkg/appconsts/upgrade_heights.go @@ -0,0 +1,13 @@ +package appconsts + +const ( + // ArabicaUpgradeHeightV2 is the block height at which the arabica-11 + // upgraded from app version 1 to 2. + ArabicaUpgradeHeightV2 = 1751707 + // MochaUpgradeHeightV2 is the block height at which the mocha-4 upgraded + // from app version 1 to 2. + MochaUpgradeHeightV2 = 2585031 + // MainnetUpgradeHeightV2 is the block height at which the celestia upgraded + // from app version 1 to 2. + MainnetUpgradeHeightV2 = 2371495 +) From 885e18f39cf2d88757370dfda3e14668657dcd3e Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 6 Dec 2024 14:07:33 -0500 Subject: [PATCH 02/10] debug: try another option of inferring chain ID --- app/app.go | 50 +++++++++++++++++++++++------ cmd/celestia-appd/cmd/app_server.go | 30 +---------------- scripts/arabica.sh | 2 +- 3 files changed, 43 insertions(+), 39 deletions(-) diff --git a/app/app.go b/app/app.go index 21405c7530..70b1fc309e 100644 --- a/app/app.go +++ b/app/app.go @@ -167,8 +167,9 @@ type App struct { manager *module.Manager configurator module.Configurator - // upgradeHeightV2 is used as a coordination mechanism for the height-based - // upgrade from v1 to v2. + + // upgradeHeightV2 is the height that a node will upgrade from app version 1 + // to 2. Do not use this value directly, instead use app.getUpgradeHeightV2(). upgradeHeightV2 int64 // MsgGateKeeper is used to define which messages are accepted for a given // app version. @@ -177,9 +178,6 @@ type App struct { // New returns a reference to an uninitialized app. Callers must subsequently // call app.Info or app.InitChain to initialize the baseapp. -// -// NOTE: upgradeHeightV2 refers specifically to the height that a node will -// upgrade from v1 to v2. func New( logger log.Logger, db dbm.DB, @@ -447,7 +445,7 @@ func (app *App) Name() string { return app.BaseApp.Name() } // BeginBlocker application updates every begin block func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock { - if req.Header.Height == app.upgradeHeightV2 { + if req.Header.Height == app.getUpgradeHeightV2() { app.BaseApp.Logger().Info("upgraded from app version 1 to 2") } return app.manager.BeginBlock(ctx, req) @@ -460,7 +458,7 @@ func (app *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.Respo // For v1 only we upgrade using an agreed upon height known ahead of time if currentVersion == v1 { // check that we are at the height before the upgrade - if req.Height == app.upgradeHeightV2-1 { + if req.Height == app.getUpgradeHeightV2()-1 { app.BaseApp.Logger().Info(fmt.Sprintf("upgrading from app version %v to 2", currentVersion)) app.SetInitialAppVersionInConsensusParams(ctx, v2) app.SetAppVersion(ctx, v2) @@ -828,13 +826,13 @@ func (app *App) OfferSnapshot(req abci.RequestOfferSnapshot) abci.ResponseOfferS } // If the app version is not set in the snapshot, this falls back to inferring the app version based on the upgrade height. - if app.upgradeHeightV2 == 0 { + if app.getUpgradeHeightV2() == 0 { app.Logger().Info("v2 upgrade height not set, assuming app version 2") app.mountKeysAndInit(v2) return app.BaseApp.OfferSnapshot(req) } - if req.Snapshot.Height >= uint64(app.upgradeHeightV2) { + if req.Snapshot.Height >= uint64(app.getUpgradeHeightV2()) { app.Logger().Info("snapshot height is greater than or equal to upgrade height, assuming app version 2") app.mountKeysAndInit(v2) return app.BaseApp.OfferSnapshot(req) @@ -848,3 +846,37 @@ func (app *App) OfferSnapshot(req abci.RequestOfferSnapshot) abci.ResponseOfferS func isSupportedAppVersion(appVersion uint64) bool { return appVersion == v1 || appVersion == v2 || appVersion == v3 } + +// getUpgradeHeightV2 returns the height that a node will upgrade from app +// version 1 to 2. If the upgrade height flag is not set, it will infer the +// value based on the chain ID. +func (app *App) getUpgradeHeightV2() int64 { + upgradeHeight := app.upgradeHeightV2 + if upgradeHeight != 0 { + fmt.Printf("upgrade height flag is not zero so using it: %d\n", upgradeHeight) + return upgradeHeight + } + + fmt.Printf("upgrade height flag is zero\n") + + // TODO: chainID here isn't always defined. For example if a node uses state + // sync (see arabica.sh) then it never has the ABCI method Init() invoked on + // it so the base app never gets the chain ID. + chainID := app.GetChainID() + fmt.Printf("chainID %v\n", chainID) + + switch chainID { + case appconsts.ArabicaChainID: + fmt.Printf("returning %v\n", appconsts.ArabicaUpgradeHeightV2) + return appconsts.ArabicaUpgradeHeightV2 + case appconsts.MochaChainID: + fmt.Printf("returning %v\n", appconsts.MochaUpgradeHeightV2) + return appconsts.MochaUpgradeHeightV2 + case appconsts.MainnetChainID: + fmt.Printf("returning %v\n", appconsts.MainnetUpgradeHeightV2) + return appconsts.MainnetUpgradeHeightV2 + default: + // default to the upgrade height provided by the flag + return upgradeHeight + } +} diff --git a/cmd/celestia-appd/cmd/app_server.go b/cmd/celestia-appd/cmd/app_server.go index a1d50b3760..1e373cf7c3 100644 --- a/cmd/celestia-appd/cmd/app_server.go +++ b/cmd/celestia-appd/cmd/app_server.go @@ -1,13 +1,11 @@ package cmd import ( - "fmt" "io" "path/filepath" "github.com/celestiaorg/celestia-app/v3/app" "github.com/celestiaorg/celestia-app/v3/app/encoding" - "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server" @@ -51,7 +49,7 @@ func NewAppServer(logger log.Logger, db dbm.DB, traceStore io.Writer, appOptions traceStore, cast.ToUint(appOptions.Get(server.FlagInvCheckPeriod)), encoding.MakeConfig(app.ModuleEncodingRegisters...), - getUpgradeHeightV2(appOptions), + cast.ToInt64(appOptions.Get(UpgradeHeightFlag)), appOptions, baseapp.SetPruning(pruningOpts), baseapp.SetMinGasPrices(cast.ToString(appOptions.Get(server.FlagMinGasPrices))), @@ -65,29 +63,3 @@ func NewAppServer(logger log.Logger, db dbm.DB, traceStore io.Writer, appOptions baseapp.SetSnapshot(snapshotStore, snapshottypes.NewSnapshotOptions(cast.ToUint64(appOptions.Get(server.FlagStateSyncSnapshotInterval)), cast.ToUint32(appOptions.Get(server.FlagStateSyncSnapshotKeepRecent)))), ) } - -func getUpgradeHeightV2(appOptions servertypes.AppOptions) int64 { - upgradeHeight := cast.ToInt64(appOptions.Get(UpgradeHeightFlag)) - if upgradeHeight != 0 { - fmt.Printf("upgrade height flag non-zero so using it: %d\n", upgradeHeight) - return upgradeHeight - } - - fmt.Printf("upgrade height flag zero\n") - - // TODO: this chainID doesn't always appear populated. - chainID := cast.ToString(appOptions.Get(flags.FlagChainID)) - fmt.Printf("chainID %v\n", chainID) - - switch chainID { - case appconsts.ArabicaChainID: - return appconsts.ArabicaUpgradeHeightV2 - case appconsts.MochaChainID: - return appconsts.MochaUpgradeHeightV2 - case appconsts.MainnetChainID: - return appconsts.MainnetUpgradeHeightV2 - default: - // default to the upgrade height provided by the flag - return upgradeHeight - } -} diff --git a/scripts/arabica.sh b/scripts/arabica.sh index d09b9d8441..e8cd91a8df 100755 --- a/scripts/arabica.sh +++ b/scripts/arabica.sh @@ -57,4 +57,4 @@ echo "Downloading genesis file..." celestia-appd download-genesis ${CHAIN_ID} echo "Starting celestia-appd..." -celestia-appd start --v2-upgrade-height 1751707 --force-no-bbr +celestia-appd start --force-no-bbr From 7ca80f3e70a3503bacd42e64253758367f3ba574 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 6 Dec 2024 15:48:26 -0500 Subject: [PATCH 03/10] debug: clientCtx has the chainID --- cmd/celestia-appd/cmd/start.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/celestia-appd/cmd/start.go b/cmd/celestia-appd/cmd/start.go index de97d4dfa0..0d9ab87e96 100644 --- a/cmd/celestia-appd/cmd/start.go +++ b/cmd/celestia-appd/cmd/start.go @@ -116,6 +116,8 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. if err != nil { return err } + fmt.Printf("serverCtx.Config.BaseConfig.ChainID %v\n", serverCtx.Config.BaseConfig.ChainID()) + fmt.Printf("clientCtx.ChainID %v\n", clientCtx.ChainID) withTM, _ := cmd.Flags().GetBool(flagWithTendermint) if !withTM { From a67461f9e4373d6cbb5676a67762e746e517bf98 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 6 Dec 2024 16:04:09 -0500 Subject: [PATCH 04/10] fix: found a place to set default upgrade height --- app/app.go | 47 ++++++++-------------------------- cmd/celestia-appd/cmd/start.go | 15 +++++++++++ 2 files changed, 26 insertions(+), 36 deletions(-) diff --git a/app/app.go b/app/app.go index 70b1fc309e..079545858c 100644 --- a/app/app.go +++ b/app/app.go @@ -169,7 +169,7 @@ type App struct { configurator module.Configurator // upgradeHeightV2 is the height that a node will upgrade from app version 1 - // to 2. Do not use this value directly, instead use app.getUpgradeHeightV2(). + // to 2. Do not use this value directly, instead use app.GetUpgradeHeightV2(). upgradeHeightV2 int64 // MsgGateKeeper is used to define which messages are accepted for a given // app version. @@ -445,7 +445,8 @@ func (app *App) Name() string { return app.BaseApp.Name() } // BeginBlocker application updates every begin block func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock { - if req.Header.Height == app.getUpgradeHeightV2() { + fmt.Printf("upgrade height: %v\n", app.GetUpgradeHeightV2()) + if req.Header.Height == app.GetUpgradeHeightV2() { app.BaseApp.Logger().Info("upgraded from app version 1 to 2") } return app.manager.BeginBlock(ctx, req) @@ -458,7 +459,7 @@ func (app *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.Respo // For v1 only we upgrade using an agreed upon height known ahead of time if currentVersion == v1 { // check that we are at the height before the upgrade - if req.Height == app.getUpgradeHeightV2()-1 { + if req.Height == app.GetUpgradeHeightV2()-1 { app.BaseApp.Logger().Info(fmt.Sprintf("upgrading from app version %v to 2", currentVersion)) app.SetInitialAppVersionInConsensusParams(ctx, v2) app.SetAppVersion(ctx, v2) @@ -826,13 +827,13 @@ func (app *App) OfferSnapshot(req abci.RequestOfferSnapshot) abci.ResponseOfferS } // If the app version is not set in the snapshot, this falls back to inferring the app version based on the upgrade height. - if app.getUpgradeHeightV2() == 0 { + if app.GetUpgradeHeightV2() == 0 { app.Logger().Info("v2 upgrade height not set, assuming app version 2") app.mountKeysAndInit(v2) return app.BaseApp.OfferSnapshot(req) } - if req.Snapshot.Height >= uint64(app.getUpgradeHeightV2()) { + if req.Snapshot.Height >= uint64(app.GetUpgradeHeightV2()) { app.Logger().Info("snapshot height is greater than or equal to upgrade height, assuming app version 2") app.mountKeysAndInit(v2) return app.BaseApp.OfferSnapshot(req) @@ -847,36 +848,10 @@ func isSupportedAppVersion(appVersion uint64) bool { return appVersion == v1 || appVersion == v2 || appVersion == v3 } -// getUpgradeHeightV2 returns the height that a node will upgrade from app -// version 1 to 2. If the upgrade height flag is not set, it will infer the -// value based on the chain ID. -func (app *App) getUpgradeHeightV2() int64 { - upgradeHeight := app.upgradeHeightV2 - if upgradeHeight != 0 { - fmt.Printf("upgrade height flag is not zero so using it: %d\n", upgradeHeight) - return upgradeHeight - } +func (app *App) GetUpgradeHeightV2() int64 { + return app.upgradeHeightV2 +} - fmt.Printf("upgrade height flag is zero\n") - - // TODO: chainID here isn't always defined. For example if a node uses state - // sync (see arabica.sh) then it never has the ABCI method Init() invoked on - // it so the base app never gets the chain ID. - chainID := app.GetChainID() - fmt.Printf("chainID %v\n", chainID) - - switch chainID { - case appconsts.ArabicaChainID: - fmt.Printf("returning %v\n", appconsts.ArabicaUpgradeHeightV2) - return appconsts.ArabicaUpgradeHeightV2 - case appconsts.MochaChainID: - fmt.Printf("returning %v\n", appconsts.MochaUpgradeHeightV2) - return appconsts.MochaUpgradeHeightV2 - case appconsts.MainnetChainID: - fmt.Printf("returning %v\n", appconsts.MainnetUpgradeHeightV2) - return appconsts.MainnetUpgradeHeightV2 - default: - // default to the upgrade height provided by the flag - return upgradeHeight - } +func (app *App) SetUpgradeHeightV2(upgradeHeightV2 int64) { + app.upgradeHeightV2 = upgradeHeightV2 } diff --git a/cmd/celestia-appd/cmd/start.go b/cmd/celestia-appd/cmd/start.go index 0d9ab87e96..7c01bc777e 100644 --- a/cmd/celestia-appd/cmd/start.go +++ b/cmd/celestia-appd/cmd/start.go @@ -14,6 +14,7 @@ import ( "strings" "time" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" @@ -264,6 +265,20 @@ func startInProcess(ctx *server.Context, clientCtx client.Context, appCreator sr return err } + fmt.Printf("clientCtx.ChainID %v\n", clientCtx.ChainID) + + switch clientCtx.ChainID { + case appconsts.ArabicaChainID: + fmt.Printf("Setting default value for upgrade height %v\n", appconsts.ArabicaUpgradeHeightV2) + ctx.Viper.SetDefault(UpgradeHeightFlag, appconsts.ArabicaUpgradeHeightV2) + case appconsts.MochaChainID: + fmt.Printf("Setting default value for upgrade height %v\n", appconsts.MochaUpgradeHeightV2) + ctx.Viper.SetDefault(UpgradeHeightFlag, appconsts.MochaUpgradeHeightV2) + case appconsts.MainnetChainID: + fmt.Printf("Setting default value for upgrade height %v\n", appconsts.MainnetUpgradeHeightV2) + ctx.Viper.SetDefault(UpgradeHeightFlag, appconsts.MainnetUpgradeHeightV2) + } + app := appCreator(ctx.Logger, db, traceWriter, ctx.Viper) nodeKey, err := p2p.LoadOrGenNodeKey(cfg.NodeKeyFile()) From 989e97db70cc4f679e773b46510db5717f18107f Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 6 Dec 2024 16:12:47 -0500 Subject: [PATCH 05/10] refactor: the fix --- app/app.go | 26 ++++++++++---------------- cmd/celestia-appd/cmd/start.go | 30 ++++++++++++++---------------- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/app/app.go b/app/app.go index 079545858c..eadd034ea1 100644 --- a/app/app.go +++ b/app/app.go @@ -167,9 +167,8 @@ type App struct { manager *module.Manager configurator module.Configurator - - // upgradeHeightV2 is the height that a node will upgrade from app version 1 - // to 2. Do not use this value directly, instead use app.GetUpgradeHeightV2(). + // upgradeHeightV2 is used as a coordination mechanism for the height-based + // upgrade from v1 to v2. upgradeHeightV2 int64 // MsgGateKeeper is used to define which messages are accepted for a given // app version. @@ -178,6 +177,10 @@ type App struct { // New returns a reference to an uninitialized app. Callers must subsequently // call app.Info or app.InitChain to initialize the baseapp. +// +// NOTE: upgradeHeightV2 refers specifically to the height that a node will +// upgrade from v1 to v2. It will be deprecated in v3 in place for a dynamically +// signalling scheme func New( logger log.Logger, db dbm.DB, @@ -445,8 +448,7 @@ func (app *App) Name() string { return app.BaseApp.Name() } // BeginBlocker application updates every begin block func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock { - fmt.Printf("upgrade height: %v\n", app.GetUpgradeHeightV2()) - if req.Header.Height == app.GetUpgradeHeightV2() { + if req.Header.Height == app.upgradeHeightV2 { app.BaseApp.Logger().Info("upgraded from app version 1 to 2") } return app.manager.BeginBlock(ctx, req) @@ -459,7 +461,7 @@ func (app *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.Respo // For v1 only we upgrade using an agreed upon height known ahead of time if currentVersion == v1 { // check that we are at the height before the upgrade - if req.Height == app.GetUpgradeHeightV2()-1 { + if req.Height == app.upgradeHeightV2-1 { app.BaseApp.Logger().Info(fmt.Sprintf("upgrading from app version %v to 2", currentVersion)) app.SetInitialAppVersionInConsensusParams(ctx, v2) app.SetAppVersion(ctx, v2) @@ -827,13 +829,13 @@ func (app *App) OfferSnapshot(req abci.RequestOfferSnapshot) abci.ResponseOfferS } // If the app version is not set in the snapshot, this falls back to inferring the app version based on the upgrade height. - if app.GetUpgradeHeightV2() == 0 { + if app.upgradeHeightV2 == 0 { app.Logger().Info("v2 upgrade height not set, assuming app version 2") app.mountKeysAndInit(v2) return app.BaseApp.OfferSnapshot(req) } - if req.Snapshot.Height >= uint64(app.GetUpgradeHeightV2()) { + if req.Snapshot.Height >= uint64(app.upgradeHeightV2) { app.Logger().Info("snapshot height is greater than or equal to upgrade height, assuming app version 2") app.mountKeysAndInit(v2) return app.BaseApp.OfferSnapshot(req) @@ -847,11 +849,3 @@ func (app *App) OfferSnapshot(req abci.RequestOfferSnapshot) abci.ResponseOfferS func isSupportedAppVersion(appVersion uint64) bool { return appVersion == v1 || appVersion == v2 || appVersion == v3 } - -func (app *App) GetUpgradeHeightV2() int64 { - return app.upgradeHeightV2 -} - -func (app *App) SetUpgradeHeightV2(upgradeHeightV2 int64) { - app.upgradeHeightV2 = upgradeHeightV2 -} diff --git a/cmd/celestia-appd/cmd/start.go b/cmd/celestia-appd/cmd/start.go index 7c01bc777e..90e316c4f6 100644 --- a/cmd/celestia-appd/cmd/start.go +++ b/cmd/celestia-appd/cmd/start.go @@ -117,8 +117,20 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. if err != nil { return err } - fmt.Printf("serverCtx.Config.BaseConfig.ChainID %v\n", serverCtx.Config.BaseConfig.ChainID()) - fmt.Printf("clientCtx.ChainID %v\n", clientCtx.ChainID) + + switch clientCtx.ChainID { + case appconsts.ArabicaChainID: + serverCtx.Logger.Info(fmt.Sprintf("Setting the default value for the --v2-upgrade-height flag to %v because chainID %v\n", appconsts.ArabicaUpgradeHeightV2, appconsts.ArabicaChainID)) + serverCtx.Viper.SetDefault(UpgradeHeightFlag, appconsts.ArabicaUpgradeHeightV2) + case appconsts.MochaChainID: + serverCtx.Logger.Info(fmt.Sprintf("Setting the default value for the --v2-upgrade-height flag to %v because chainID %v\n", appconsts.MochaUpgradeHeightV2, appconsts.MochaChainID)) + serverCtx.Viper.SetDefault(UpgradeHeightFlag, appconsts.MochaUpgradeHeightV2) + case appconsts.MainnetChainID: + serverCtx.Logger.Info(fmt.Sprintf("Setting the default value for the --v2-upgrade-height flag to %v because chainID %v\n", appconsts.MainnetChainID, appconsts.MainnetChainID)) + serverCtx.Viper.SetDefault(UpgradeHeightFlag, appconsts.MainnetUpgradeHeightV2) + default: + serverCtx.Logger.Info(fmt.Sprintf("No default value exists for the --v2-upgrade-height flag when chainID is %v", clientCtx.ChainID)) + } withTM, _ := cmd.Flags().GetBool(flagWithTendermint) if !withTM { @@ -265,20 +277,6 @@ func startInProcess(ctx *server.Context, clientCtx client.Context, appCreator sr return err } - fmt.Printf("clientCtx.ChainID %v\n", clientCtx.ChainID) - - switch clientCtx.ChainID { - case appconsts.ArabicaChainID: - fmt.Printf("Setting default value for upgrade height %v\n", appconsts.ArabicaUpgradeHeightV2) - ctx.Viper.SetDefault(UpgradeHeightFlag, appconsts.ArabicaUpgradeHeightV2) - case appconsts.MochaChainID: - fmt.Printf("Setting default value for upgrade height %v\n", appconsts.MochaUpgradeHeightV2) - ctx.Viper.SetDefault(UpgradeHeightFlag, appconsts.MochaUpgradeHeightV2) - case appconsts.MainnetChainID: - fmt.Printf("Setting default value for upgrade height %v\n", appconsts.MainnetUpgradeHeightV2) - ctx.Viper.SetDefault(UpgradeHeightFlag, appconsts.MainnetUpgradeHeightV2) - } - app := appCreator(ctx.Logger, db, traceWriter, ctx.Viper) nodeKey, err := p2p.LoadOrGenNodeKey(cfg.NodeKeyFile()) From 4d5a83708d098da33ef7dccd8237f6e29294341b Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 6 Dec 2024 16:19:07 -0500 Subject: [PATCH 06/10] testing --- app/app.go | 1 + cmd/celestia-appd/cmd/app_server.go | 4 +--- cmd/celestia-appd/cmd/start.go | 8 ++++---- scripts/arabica.sh | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/app.go b/app/app.go index eadd034ea1..a193db9b5c 100644 --- a/app/app.go +++ b/app/app.go @@ -456,6 +456,7 @@ func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.R // EndBlocker executes application updates at the end of every block. func (app *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock { + fmt.Printf("app.upgradeHeightV2 %v", app.upgradeHeightV2) res := app.manager.EndBlock(ctx, req) currentVersion := app.AppVersion() // For v1 only we upgrade using an agreed upon height known ahead of time diff --git a/cmd/celestia-appd/cmd/app_server.go b/cmd/celestia-appd/cmd/app_server.go index 1e373cf7c3..b2bfecf844 100644 --- a/cmd/celestia-appd/cmd/app_server.go +++ b/cmd/celestia-appd/cmd/app_server.go @@ -44,9 +44,7 @@ func NewAppServer(logger log.Logger, db dbm.DB, traceStore io.Writer, appOptions } return app.New( - logger, - db, - traceStore, + logger, db, traceStore, cast.ToUint(appOptions.Get(server.FlagInvCheckPeriod)), encoding.MakeConfig(app.ModuleEncodingRegisters...), cast.ToInt64(appOptions.Get(UpgradeHeightFlag)), diff --git a/cmd/celestia-appd/cmd/start.go b/cmd/celestia-appd/cmd/start.go index 90e316c4f6..d467995037 100644 --- a/cmd/celestia-appd/cmd/start.go +++ b/cmd/celestia-appd/cmd/start.go @@ -120,16 +120,16 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. switch clientCtx.ChainID { case appconsts.ArabicaChainID: - serverCtx.Logger.Info(fmt.Sprintf("Setting the default value for the --v2-upgrade-height flag to %v because chainID %v\n", appconsts.ArabicaUpgradeHeightV2, appconsts.ArabicaChainID)) + serverCtx.Logger.Info(fmt.Sprintf("Since the chainID is %v, configuring the default v2 upgrade height to %v", appconsts.ArabicaUpgradeHeightV2, appconsts.ArabicaChainID)) serverCtx.Viper.SetDefault(UpgradeHeightFlag, appconsts.ArabicaUpgradeHeightV2) case appconsts.MochaChainID: - serverCtx.Logger.Info(fmt.Sprintf("Setting the default value for the --v2-upgrade-height flag to %v because chainID %v\n", appconsts.MochaUpgradeHeightV2, appconsts.MochaChainID)) + serverCtx.Logger.Info(fmt.Sprintf("Since the chainID is %v, configuring the default v2 upgrade height to %v", appconsts.MochaUpgradeHeightV2, appconsts.MochaChainID)) serverCtx.Viper.SetDefault(UpgradeHeightFlag, appconsts.MochaUpgradeHeightV2) case appconsts.MainnetChainID: - serverCtx.Logger.Info(fmt.Sprintf("Setting the default value for the --v2-upgrade-height flag to %v because chainID %v\n", appconsts.MainnetChainID, appconsts.MainnetChainID)) + serverCtx.Logger.Info(fmt.Sprintf("Since the chainID is %v, configuring the default v2 upgrade height to %v", appconsts.MainnetChainID, appconsts.MainnetChainID)) serverCtx.Viper.SetDefault(UpgradeHeightFlag, appconsts.MainnetUpgradeHeightV2) default: - serverCtx.Logger.Info(fmt.Sprintf("No default value exists for the --v2-upgrade-height flag when chainID is %v", clientCtx.ChainID)) + serverCtx.Logger.Info(fmt.Sprintf("No default value exists for the v2 upgrade height when the chainID is %v", clientCtx.ChainID)) } withTM, _ := cmd.Flags().GetBool(flagWithTendermint) diff --git a/scripts/arabica.sh b/scripts/arabica.sh index e8cd91a8df..3bb5739138 100755 --- a/scripts/arabica.sh +++ b/scripts/arabica.sh @@ -57,4 +57,4 @@ echo "Downloading genesis file..." celestia-appd download-genesis ${CHAIN_ID} echo "Starting celestia-appd..." -celestia-appd start --force-no-bbr +celestia-appd start --force-no-bbr --v2-upgrade-height 2 From 2f37ee054825d5226f383b3f87b0c400d916f881 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 6 Dec 2024 17:04:14 -0500 Subject: [PATCH 07/10] hacky test --- cmd/celestia-appd/cmd/start.go | 8 ++-- cmd/celestia-appd/cmd/start_test.go | 67 +++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 cmd/celestia-appd/cmd/start_test.go diff --git a/cmd/celestia-appd/cmd/start.go b/cmd/celestia-appd/cmd/start.go index d467995037..9c8ee77abe 100644 --- a/cmd/celestia-appd/cmd/start.go +++ b/cmd/celestia-appd/cmd/start.go @@ -107,10 +107,10 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. return err }, RunE: func(cmd *cobra.Command, _ []string) error { - err := checkBBR(cmd) - if err != nil { - return err - } + // err := checkBBR(cmd) + // if err != nil { + // return err + // } serverCtx := server.GetServerContextFromCmd(cmd) clientCtx, err := client.GetClientQueryContext(cmd) diff --git a/cmd/celestia-appd/cmd/start_test.go b/cmd/celestia-appd/cmd/start_test.go new file mode 100644 index 0000000000..158cdc9a4a --- /dev/null +++ b/cmd/celestia-appd/cmd/start_test.go @@ -0,0 +1,67 @@ +package cmd + +import ( + "context" + "testing" + + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" + "github.com/celestiaorg/celestia-app/v3/test/util/testnode" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/server" + srvrtypes "github.com/cosmos/cosmos-sdk/server/types" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestStart(t *testing.T) { + tests := []struct { + name string + chainID string + expectedHeight int64 + }{ + { + name: "ArabicaChainID", + chainID: appconsts.ArabicaChainID, + expectedHeight: appconsts.ArabicaUpgradeHeightV2, + }, + { + name: "MochaChainID", + chainID: appconsts.MochaChainID, + expectedHeight: appconsts.MochaUpgradeHeightV2, + }, + { + name: "MainnetChainID", + chainID: appconsts.MainnetChainID, + expectedHeight: appconsts.MainnetUpgradeHeightV2, + }, + { + name: "UnknownChainID", + chainID: "unknown-chain-id", + expectedHeight: 0, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + appCreator := noOpAppCreator() + cmd := startCmd(appCreator, "/tmp") + + cmd.SetContext(context.Background()) + context, err := client.GetClientQueryContext(cmd) + require.NoError(t, err) + context = context.WithChainID(tt.chainID) + client.SetCmdClientContext(cmd, context) + serverCtx := server.NewDefaultContext() + server.SetCmdServerContext(cmd, serverCtx) + + cmd.ExecuteContext(context).RunE(cmd, []string{}) + + got := server.GetServerContextFromCmd(cmd) + assert.Equal(t, tt.expectedHeight, got.Viper.GetInt64(UpgradeHeightFlag)) + }) + } +} + +func noOpAppCreator() srvrtypes.AppCreator { + return testnode.DefaultAppCreator() +} From 5f978b2c3f3becf83b95cc308aae1d71efe868f1 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 6 Dec 2024 17:04:21 -0500 Subject: [PATCH 08/10] R2f37ee054825d5226f383b3f87b0c400d916f881evert "hacky test" This reverts commit 2f37ee054825d5226f383b3f87b0c400d916f881. --- cmd/celestia-appd/cmd/start.go | 8 ++-- cmd/celestia-appd/cmd/start_test.go | 67 ----------------------------- 2 files changed, 4 insertions(+), 71 deletions(-) delete mode 100644 cmd/celestia-appd/cmd/start_test.go diff --git a/cmd/celestia-appd/cmd/start.go b/cmd/celestia-appd/cmd/start.go index 9c8ee77abe..d467995037 100644 --- a/cmd/celestia-appd/cmd/start.go +++ b/cmd/celestia-appd/cmd/start.go @@ -107,10 +107,10 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. return err }, RunE: func(cmd *cobra.Command, _ []string) error { - // err := checkBBR(cmd) - // if err != nil { - // return err - // } + err := checkBBR(cmd) + if err != nil { + return err + } serverCtx := server.GetServerContextFromCmd(cmd) clientCtx, err := client.GetClientQueryContext(cmd) diff --git a/cmd/celestia-appd/cmd/start_test.go b/cmd/celestia-appd/cmd/start_test.go deleted file mode 100644 index 158cdc9a4a..0000000000 --- a/cmd/celestia-appd/cmd/start_test.go +++ /dev/null @@ -1,67 +0,0 @@ -package cmd - -import ( - "context" - "testing" - - "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" - "github.com/celestiaorg/celestia-app/v3/test/util/testnode" - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/server" - srvrtypes "github.com/cosmos/cosmos-sdk/server/types" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestStart(t *testing.T) { - tests := []struct { - name string - chainID string - expectedHeight int64 - }{ - { - name: "ArabicaChainID", - chainID: appconsts.ArabicaChainID, - expectedHeight: appconsts.ArabicaUpgradeHeightV2, - }, - { - name: "MochaChainID", - chainID: appconsts.MochaChainID, - expectedHeight: appconsts.MochaUpgradeHeightV2, - }, - { - name: "MainnetChainID", - chainID: appconsts.MainnetChainID, - expectedHeight: appconsts.MainnetUpgradeHeightV2, - }, - { - name: "UnknownChainID", - chainID: "unknown-chain-id", - expectedHeight: 0, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - appCreator := noOpAppCreator() - cmd := startCmd(appCreator, "/tmp") - - cmd.SetContext(context.Background()) - context, err := client.GetClientQueryContext(cmd) - require.NoError(t, err) - context = context.WithChainID(tt.chainID) - client.SetCmdClientContext(cmd, context) - serverCtx := server.NewDefaultContext() - server.SetCmdServerContext(cmd, serverCtx) - - cmd.ExecuteContext(context).RunE(cmd, []string{}) - - got := server.GetServerContextFromCmd(cmd) - assert.Equal(t, tt.expectedHeight, got.Viper.GetInt64(UpgradeHeightFlag)) - }) - } -} - -func noOpAppCreator() srvrtypes.AppCreator { - return testnode.DefaultAppCreator() -} From 7b129479c06cac4568e245028ab920500bfe1d34 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 6 Dec 2024 17:05:03 -0500 Subject: [PATCH 09/10] revert: unneeded changes --- app/app.go | 1 - scripts/arabica.sh | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/app.go b/app/app.go index a193db9b5c..eadd034ea1 100644 --- a/app/app.go +++ b/app/app.go @@ -456,7 +456,6 @@ func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.R // EndBlocker executes application updates at the end of every block. func (app *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock { - fmt.Printf("app.upgradeHeightV2 %v", app.upgradeHeightV2) res := app.manager.EndBlock(ctx, req) currentVersion := app.AppVersion() // For v1 only we upgrade using an agreed upon height known ahead of time diff --git a/scripts/arabica.sh b/scripts/arabica.sh index 3bb5739138..d09b9d8441 100755 --- a/scripts/arabica.sh +++ b/scripts/arabica.sh @@ -57,4 +57,4 @@ echo "Downloading genesis file..." celestia-appd download-genesis ${CHAIN_ID} echo "Starting celestia-appd..." -celestia-appd start --force-no-bbr --v2-upgrade-height 2 +celestia-appd start --v2-upgrade-height 1751707 --force-no-bbr From 8d02c3fca3e851eec2a5ae889629612dad8e89ba Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Fri, 6 Dec 2024 19:24:32 -0500 Subject: [PATCH 10/10] fix: log --- cmd/celestia-appd/cmd/start.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/celestia-appd/cmd/start.go b/cmd/celestia-appd/cmd/start.go index d467995037..c43e5f3d75 100644 --- a/cmd/celestia-appd/cmd/start.go +++ b/cmd/celestia-appd/cmd/start.go @@ -120,13 +120,13 @@ is performed. Note, when enabled, gRPC will also be automatically enabled. switch clientCtx.ChainID { case appconsts.ArabicaChainID: - serverCtx.Logger.Info(fmt.Sprintf("Since the chainID is %v, configuring the default v2 upgrade height to %v", appconsts.ArabicaUpgradeHeightV2, appconsts.ArabicaChainID)) + serverCtx.Logger.Info(fmt.Sprintf("Since the chainID is %v, configuring the default v2 upgrade height to %v", appconsts.ArabicaChainID, appconsts.ArabicaUpgradeHeightV2)) serverCtx.Viper.SetDefault(UpgradeHeightFlag, appconsts.ArabicaUpgradeHeightV2) case appconsts.MochaChainID: - serverCtx.Logger.Info(fmt.Sprintf("Since the chainID is %v, configuring the default v2 upgrade height to %v", appconsts.MochaUpgradeHeightV2, appconsts.MochaChainID)) + serverCtx.Logger.Info(fmt.Sprintf("Since the chainID is %v, configuring the default v2 upgrade height to %v", appconsts.MochaChainID, appconsts.MochaUpgradeHeightV2)) serverCtx.Viper.SetDefault(UpgradeHeightFlag, appconsts.MochaUpgradeHeightV2) case appconsts.MainnetChainID: - serverCtx.Logger.Info(fmt.Sprintf("Since the chainID is %v, configuring the default v2 upgrade height to %v", appconsts.MainnetChainID, appconsts.MainnetChainID)) + serverCtx.Logger.Info(fmt.Sprintf("Since the chainID is %v, configuring the default v2 upgrade height to %v", appconsts.MainnetChainID, appconsts.MainnetUpgradeHeightV2)) serverCtx.Viper.SetDefault(UpgradeHeightFlag, appconsts.MainnetUpgradeHeightV2) default: serverCtx.Logger.Info(fmt.Sprintf("No default value exists for the v2 upgrade height when the chainID is %v", clientCtx.ChainID))