From 5600addeff7528ae23253b242588dca2159a24c2 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 8 Mar 2023 11:14:38 -0300 Subject: [PATCH 01/23] fix: remove previous header to avoid inconsistencies in Prepare\/Process Proposal --- baseapp/abci.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 4ec863cc0eb0..36f176b401f4 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -450,8 +450,12 @@ func (app *BaseApp) Commit() abci.ResponseCommit { // NOTE: This is safe because CometBFT holds a lock on the mempool for // Commit. Use the header from this latest block. app.setState(runTxModeCheck, header) - app.setState(runTxPrepareProposal, header) - app.setState(runTxProcessProposal, header) + + // Reset state to the latest committed but with an empty header to avoid + // leaking the header from the last block. + emptyHeader := cmtproto.Header{} + app.setState(runTxPrepareProposal, emptyHeader) + app.setState(runTxProcessProposal, emptyHeader) // empty/reset the deliver state app.deliverState = nil @@ -969,6 +973,8 @@ func SplitABCIQueryPath(requestPath string) (path []string) { func (app *BaseApp) getContextForProposal(ctx sdk.Context, height int64) sdk.Context { if height == 1 { ctx, _ = app.deliverState.ctx.CacheContext() + // TODO: clear all context data set during InitChain to avoid inconsistent behavior + ctx = ctx.WithBlockHeader(cmtproto.Header{}).WithChainID("") return ctx } return ctx From a07fd6f99570800c6c58e9d0f2c38d90ebbadea6 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 8 Mar 2023 11:19:37 -0300 Subject: [PATCH 02/23] nit --- baseapp/abci.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 36f176b401f4..ba9cc069d153 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -57,8 +57,13 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC // initialize states with a correct header app.setState(runTxModeDeliver, initHeader) app.setState(runTxModeCheck, initHeader) - app.setState(runTxPrepareProposal, initHeader) - app.setState(runTxProcessProposal, initHeader) + + // Use an empty header for prepare and process proposal states. Although it + // doesn't matter what header we use here as they get overwritten for the + // first block (see getContextForProposal()) and cleaned up on every Commit(). + emptyHeader := cmtproto.Header{} + app.setState(runTxPrepareProposal, emptyHeader) + app.setState(runTxProcessProposal, emptyHeader) // Store the consensus params in the BaseApp's paramstore. Note, this must be // done after the deliver state and context have been set as it's persisted From fbe491fe5f865693712d6d940e5f0ac0b4dfc194 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 8 Mar 2023 14:48:39 -0300 Subject: [PATCH 03/23] get chain id from genesis --- baseapp/abci.go | 13 ++++++++++--- baseapp/baseapp.go | 2 ++ baseapp/options.go | 5 +++++ client/pruning/main.go | 13 +++++++++++++ server/rollback.go | 15 ++++++++++++++- server/start.go | 31 +++++++++++++++++++++++-------- server/util.go | 1 + 7 files changed, 68 insertions(+), 12 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index ba9cc069d153..acadaad3379d 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -37,6 +37,11 @@ const ( // InitChain implements the ABCI interface. It runs the initialization logic // directly on the CommitMultiStore. func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitChain) { + + if req.ChainId != app.chainID { + panic(fmt.Sprintf("ChainID on RequestInitChain {%s} does not match the app's ChainID {%s}", req.ChainId, app.chainID)) + } + // On a new chain, we consider the init chain block height as 0, even though // req.InitialHeight is 1 by default. initHeader := cmtproto.Header{ChainID: req.ChainId, Time: req.Time} @@ -277,7 +282,8 @@ func (app *BaseApp) PrepareProposal(req abci.RequestPrepareProposal) (resp abci. WithBlockTime(req.Time). WithProposer(req.ProposerAddress). WithConsensusParams(app.GetConsensusParams(ctx)). - WithBlockGasMeter(gasMeter) + WithBlockGasMeter(gasMeter). + WithChainID(app.chainID) defer func() { if err := recover(); err != nil { @@ -326,7 +332,8 @@ func (app *BaseApp) ProcessProposal(req abci.RequestProcessProposal) (resp abci. WithHeaderHash(req.Hash). WithProposer(req.ProposerAddress). WithConsensusParams(app.GetConsensusParams(ctx)). - WithBlockGasMeter(gasMeter) + WithBlockGasMeter(gasMeter). + WithChainID(app.chainID) defer func() { if err := recover(); err != nil { @@ -979,7 +986,7 @@ func (app *BaseApp) getContextForProposal(ctx sdk.Context, height int64) sdk.Con if height == 1 { ctx, _ = app.deliverState.ctx.CacheContext() // TODO: clear all context data set during InitChain to avoid inconsistent behavior - ctx = ctx.WithBlockHeader(cmtproto.Header{}).WithChainID("") + ctx = ctx.WithBlockHeader(cmtproto.Header{}) return ctx } return ctx diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index cff907546447..d98b11be67ec 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -145,6 +145,8 @@ type BaseApp struct { //nolint: maligned // abciListeners for hooking into the ABCI message processing of the BaseApp // and exposing the requests and responses to external consumers abciListeners []storetypes.ABCIListener + + chainID string } // NewBaseApp returns a reference to an initialized BaseApp. It accepts a diff --git a/baseapp/options.go b/baseapp/options.go index 39398826f60e..7ef64e96ea04 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -96,6 +96,11 @@ func SetMempool(mempool mempool.Mempool) func(*BaseApp) { return func(app *BaseApp) { app.SetMempool(mempool) } } +// SetChainID sets the chain ID in BaseApp. +func SetChainID(chainID string) func(*BaseApp) { + return func(app *BaseApp) { app.chainID = chainID } +} + func (app *BaseApp) SetName(name string) { if app.sealed { panic("SetName() on sealed BaseApp") diff --git a/client/pruning/main.go b/client/pruning/main.go index 462d6d944c83..b81ed85f7646 100644 --- a/client/pruning/main.go +++ b/client/pruning/main.go @@ -15,6 +15,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server" servertypes "github.com/cosmos/cosmos-sdk/server/types" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) const FlagAppDBBackend = "app-db-backend" @@ -62,6 +63,18 @@ func Cmd(appCreator servertypes.AppCreator) *cobra.Command { } logger := log.NewLogger(cmd.OutOrStdout()) + + ctx := server.GetServerContextFromCmd(cmd) + appGenesis, err := genutiltypes.AppGenesisFromFile(ctx.Config.GenesisFile()) + if err != nil { + return err + } + + // If the chain ID is not set, use the one from the genesis file + if !vp.IsSet(flags.FlagChainID) { + vp.Set(flags.FlagChainID, appGenesis.ChainID) + } + app := appCreator(logger, db, nil, vp) cms := app.CommitMultiStore() diff --git a/server/rollback.go b/server/rollback.go index 9be4dfa32c37..740d66193f8d 100644 --- a/server/rollback.go +++ b/server/rollback.go @@ -4,9 +4,11 @@ import ( "fmt" cmtcmd "github.com/cometbft/cometbft/cmd/cometbft/commands" + "github.com/spf13/cobra" + "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server/types" - "github.com/spf13/cobra" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) // NewRollbackCmd creates a command to rollback CometBFT and multistore state by one height. @@ -32,6 +34,17 @@ application. if err != nil { return err } + + appGenesis, err := genutiltypes.AppGenesisFromFile(cfg.GenesisFile()) + if err != nil { + return err + } + + // If the chain ID is not set, use the one from the genesis file + if !ctx.Viper.IsSet(flags.FlagChainID) { + ctx.Viper.Set(flags.FlagChainID, appGenesis.ChainID) + } + app := appCreator(ctx.Logger, db, nil, ctx.Viper) // rollback CometBFT state height, hash, err := cmtcmd.RollbackState(ctx.Config, removeBlock) diff --git a/server/start.go b/server/start.go index 5469c1923cf0..99ed41532af4 100644 --- a/server/start.go +++ b/server/start.go @@ -214,6 +214,16 @@ func startStandAlone(svrCtx *Context, appCreator types.AppCreator) error { return err } + appGenesis, err := genutiltypes.AppGenesisFromFile(svrCtx.Config.GenesisFile()) + if err != nil { + return err + } + + // If the chain ID is not set, use the one from the genesis file + if !svrCtx.Viper.IsSet(flags.FlagChainID) { + svrCtx.Viper.Set(flags.FlagChainID, appGenesis.ChainID) + } + app := appCreator(svrCtx.Logger, db, traceWriter, svrCtx.Viper) config, err := serverconfig.GetConfig(svrCtx.Viper) @@ -290,22 +300,27 @@ func startInProcess(svrCtx *Context, clientCtx client.Context, appCreator types. return err } - app := appCreator(svrCtx.Logger, db, traceWriter, svrCtx.Viper) - - nodeKey, err := p2p.LoadOrGenNodeKey(cfg.NodeKeyFile()) + appGenesis, err := genutiltypes.AppGenesisFromFile(cfg.GenesisFile()) if err != nil { return err } genDocProvider := func() (*cmttypes.GenesisDoc, error) { - appGenesis, err := genutiltypes.AppGenesisFromFile(cfg.GenesisFile()) - if err != nil { - return nil, err - } - return appGenesis.ToGenesisDoc() } + // If the chain ID is not set, use the one from the genesis file + if !svrCtx.Viper.IsSet(flags.FlagChainID) { + svrCtx.Viper.Set(flags.FlagChainID, appGenesis.ChainID) + } + + app := appCreator(svrCtx.Logger, db, traceWriter, svrCtx.Viper) + + nodeKey, err := p2p.LoadOrGenNodeKey(cfg.NodeKeyFile()) + if err != nil { + return err + } + var ( tmNode *node.Node gRPCOnly = svrCtx.Viper.GetBool(flagGRPCOnly) diff --git a/server/util.go b/server/util.go index f15c62fb8eed..01ac48d6c01e 100644 --- a/server/util.go +++ b/server/util.go @@ -479,5 +479,6 @@ func DefaultBaseappOptions(appOpts types.AppOptions) []func(*baseapp.BaseApp) { ), ), baseapp.SetIAVLLazyLoading(cast.ToBool(appOpts.Get(FlagIAVLLazyLoading))), + baseapp.SetChainID(cast.ToString(appOpts.Get(flags.FlagChainID))), } } From ac127593452943d853c6881e5c986744a6a08311 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 8 Mar 2023 14:59:11 -0300 Subject: [PATCH 04/23] progress --- baseapp/abci.go | 10 ++++------ baseapp/baseapp.go | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index acadaad3379d..6c21f21b8141 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -66,7 +66,7 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC // Use an empty header for prepare and process proposal states. Although it // doesn't matter what header we use here as they get overwritten for the // first block (see getContextForProposal()) and cleaned up on every Commit(). - emptyHeader := cmtproto.Header{} + emptyHeader := cmtproto.Header{ChainID: req.ChainId} app.setState(runTxPrepareProposal, emptyHeader) app.setState(runTxProcessProposal, emptyHeader) @@ -282,8 +282,7 @@ func (app *BaseApp) PrepareProposal(req abci.RequestPrepareProposal) (resp abci. WithBlockTime(req.Time). WithProposer(req.ProposerAddress). WithConsensusParams(app.GetConsensusParams(ctx)). - WithBlockGasMeter(gasMeter). - WithChainID(app.chainID) + WithBlockGasMeter(gasMeter) defer func() { if err := recover(); err != nil { @@ -332,8 +331,7 @@ func (app *BaseApp) ProcessProposal(req abci.RequestProcessProposal) (resp abci. WithHeaderHash(req.Hash). WithProposer(req.ProposerAddress). WithConsensusParams(app.GetConsensusParams(ctx)). - WithBlockGasMeter(gasMeter). - WithChainID(app.chainID) + WithBlockGasMeter(gasMeter) defer func() { if err := recover(); err != nil { @@ -465,7 +463,7 @@ func (app *BaseApp) Commit() abci.ResponseCommit { // Reset state to the latest committed but with an empty header to avoid // leaking the header from the last block. - emptyHeader := cmtproto.Header{} + emptyHeader := cmtproto.Header{ChainID: app.chainID} app.setState(runTxPrepareProposal, emptyHeader) app.setState(runTxProcessProposal, emptyHeader) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index d98b11be67ec..4e7982fade0d 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -352,7 +352,7 @@ func (app *BaseApp) Init() error { panic("cannot call initFromMainStore: baseapp already sealed") } - emptyHeader := cmtproto.Header{} + emptyHeader := cmtproto.Header{ChainID: app.chainID} // needed for the export command which inits from store but never calls initchain app.setState(runTxModeCheck, emptyHeader) From 233a4a42dcf6d96e7a0ee90c27c81042ae2ef791 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 8 Mar 2023 15:00:57 -0300 Subject: [PATCH 05/23] progress --- simapp/sim_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 0cd6cdc26ca5..099de39206be 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -332,6 +332,7 @@ func TestAppStateDeterminism(t *testing.T) { appOptions := make(simtestutil.AppOptionsMap, 0) appOptions[flags.FlagHome] = DefaultNodeHome appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue + appOptions[flags.ChainID] = SimAppChainID for i := 0; i < numSeeds; i++ { config.Seed = rand.Int63() From fe1cd5bf8afc954815397132199424883430af72 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 8 Mar 2023 15:13:09 -0300 Subject: [PATCH 06/23] progress --- simapp/sim_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 099de39206be..9b2d1503e2a8 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -82,6 +82,7 @@ func TestFullAppSimulation(t *testing.T) { appOptions := make(simtestutil.AppOptionsMap, 0) appOptions[flags.FlagHome] = DefaultNodeHome appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue + appOptions[flags.FlagChainID] = SimAppChainID app := NewSimApp(logger, db, nil, true, appOptions, fauxMerkleModeOpt) require.Equal(t, "SimApp", app.Name()) @@ -127,6 +128,7 @@ func TestAppImportExport(t *testing.T) { appOptions := make(simtestutil.AppOptionsMap, 0) appOptions[flags.FlagHome] = DefaultNodeHome appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue + appOptions[flags.FlagChainID] = SimAppChainID app := NewSimApp(logger, db, nil, true, appOptions, fauxMerkleModeOpt) require.Equal(t, "SimApp", app.Name()) @@ -244,6 +246,7 @@ func TestAppSimulationAfterImport(t *testing.T) { appOptions := make(simtestutil.AppOptionsMap, 0) appOptions[flags.FlagHome] = DefaultNodeHome appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue + appOptions[flags.FlagChainID] = SimAppChainID app := NewSimApp(logger, db, nil, true, appOptions, fauxMerkleModeOpt) require.Equal(t, "SimApp", app.Name()) @@ -332,7 +335,7 @@ func TestAppStateDeterminism(t *testing.T) { appOptions := make(simtestutil.AppOptionsMap, 0) appOptions[flags.FlagHome] = DefaultNodeHome appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue - appOptions[flags.ChainID] = SimAppChainID + appOptions[flags.FlagChainID] = SimAppChainID for i := 0; i < numSeeds; i++ { config.Seed = rand.Int63() From 257f4befb1415aace5a96b340435c3df137b787f Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 8 Mar 2023 15:45:06 -0300 Subject: [PATCH 07/23] progress --- simapp/sim_test.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 9b2d1503e2a8..8e575bbd6217 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -82,9 +82,8 @@ func TestFullAppSimulation(t *testing.T) { appOptions := make(simtestutil.AppOptionsMap, 0) appOptions[flags.FlagHome] = DefaultNodeHome appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue - appOptions[flags.FlagChainID] = SimAppChainID - app := NewSimApp(logger, db, nil, true, appOptions, fauxMerkleModeOpt) + app := NewSimApp(logger, db, nil, true, appOptions, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID)) require.Equal(t, "SimApp", app.Name()) // run randomized simulation @@ -128,9 +127,8 @@ func TestAppImportExport(t *testing.T) { appOptions := make(simtestutil.AppOptionsMap, 0) appOptions[flags.FlagHome] = DefaultNodeHome appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue - appOptions[flags.FlagChainID] = SimAppChainID - app := NewSimApp(logger, db, nil, true, appOptions, fauxMerkleModeOpt) + app := NewSimApp(logger, db, nil, true, appOptions, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID)) require.Equal(t, "SimApp", app.Name()) // Run randomized simulation @@ -170,7 +168,7 @@ func TestAppImportExport(t *testing.T) { require.NoError(t, os.RemoveAll(newDir)) }() - newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, appOptions, fauxMerkleModeOpt) + newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, appOptions, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID)) require.Equal(t, "SimApp", newApp.Name()) var genesisState GenesisState @@ -246,9 +244,8 @@ func TestAppSimulationAfterImport(t *testing.T) { appOptions := make(simtestutil.AppOptionsMap, 0) appOptions[flags.FlagHome] = DefaultNodeHome appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue - appOptions[flags.FlagChainID] = SimAppChainID - app := NewSimApp(logger, db, nil, true, appOptions, fauxMerkleModeOpt) + app := NewSimApp(logger, db, nil, true, appOptions, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID)) require.Equal(t, "SimApp", app.Name()) // Run randomized simulation @@ -293,7 +290,7 @@ func TestAppSimulationAfterImport(t *testing.T) { require.NoError(t, os.RemoveAll(newDir)) }() - newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, appOptions, fauxMerkleModeOpt) + newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, appOptions, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID)) require.Equal(t, "SimApp", newApp.Name()) newApp.InitChain(abci.RequestInitChain{ @@ -335,7 +332,6 @@ func TestAppStateDeterminism(t *testing.T) { appOptions := make(simtestutil.AppOptionsMap, 0) appOptions[flags.FlagHome] = DefaultNodeHome appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue - appOptions[flags.FlagChainID] = SimAppChainID for i := 0; i < numSeeds; i++ { config.Seed = rand.Int63() @@ -349,7 +345,7 @@ func TestAppStateDeterminism(t *testing.T) { } db := dbm.NewMemDB() - app := NewSimApp(logger, db, nil, true, appOptions, interBlockCacheOpt()) + app := NewSimApp(logger, db, nil, true, appOptions, interBlockCacheOpt(), baseapp.SetChainID(SimAppChainID)) fmt.Printf( "running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n", From 06d2021db0ac482142ed806fec8ee6b0309b3710 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 8 Mar 2023 15:53:02 -0300 Subject: [PATCH 08/23] progress --- simapp/test_helpers.go | 1 + 1 file changed, 1 insertion(+) diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index 3f53ffc9cf13..08d70f5f8f8d 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -231,6 +231,7 @@ func NewTestNetworkFixture() network.TestFixture { simtestutil.NewAppOptionsWithFlagHome(val.GetCtx().Config.RootDir), bam.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)), bam.SetMinGasPrices(val.GetAppConfig().MinGasPrices), + bam.SetChainID(val.GetCtx().Config.ChainID()), ) } From 4a793579eaa66e430332d06eed820fb01aa5ca11 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 8 Mar 2023 15:54:23 -0300 Subject: [PATCH 09/23] progress --- testutil/network/network.go | 1 + 1 file changed, 1 insertion(+) diff --git a/testutil/network/network.go b/testutil/network/network.go index aaf898023b7b..025108101831 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -211,6 +211,7 @@ func DefaultConfigWithAppConfig(appConfig depinject.Config) (Config, error) { nil, baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)), baseapp.SetMinGasPrices(val.GetAppConfig().MinGasPrices), + baseapp.SetChainID(cfg.ChainID), ) testdata.RegisterQueryServer(app.GRPCQueryRouter(), testdata.QueryImpl{}) From 71d93ca4d112d27137d3f1e4354793b80ee00094 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 8 Mar 2023 16:16:17 -0300 Subject: [PATCH 10/23] progress --- simapp/test_helpers.go | 2 +- testutil/network/network.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index 08d70f5f8f8d..fdd19ac7e230 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -231,7 +231,7 @@ func NewTestNetworkFixture() network.TestFixture { simtestutil.NewAppOptionsWithFlagHome(val.GetCtx().Config.RootDir), bam.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)), bam.SetMinGasPrices(val.GetAppConfig().MinGasPrices), - bam.SetChainID(val.GetCtx().Config.ChainID()), + bam.SetChainID(val.GetCtx().Viper.GetString(flags.FlagChainID)), ) } diff --git a/testutil/network/network.go b/testutil/network/network.go index 025108101831..14655c4ad31a 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -31,6 +31,7 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/grpc/cmtservice" "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/codec" @@ -572,6 +573,9 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) { WithTxConfig(cfg.TxConfig). WithAccountRetriever(cfg.AccountRetriever) + // Provide ChainID here since we can't modify it in the Comet config. + ctx.Viper.Set(flags.FlagChainID, cfg.ChainID) + network.Validators[i] = &Validator{ AppConfig: appCfg, ClientCtx: clientCtx, From 755611dc9151a0383d2d89d9cee36dec870bcbbc Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 8 Mar 2023 16:26:29 -0300 Subject: [PATCH 11/23] progress --- baseapp/abci.go | 1 - baseapp/abci_test.go | 9 +++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 6c21f21b8141..1f4ea2a5928d 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -37,7 +37,6 @@ const ( // InitChain implements the ABCI interface. It runs the initialization logic // directly on the CommitMultiStore. func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitChain) { - if req.ChainId != app.chainID { panic(fmt.Sprintf("ChainID on RequestInitChain {%s} does not match the app's ChainID {%s}", req.ChainId, app.chainID)) } diff --git a/baseapp/abci_test.go b/baseapp/abci_test.go index 9cccf7a35ecf..8758b18175ac 100644 --- a/baseapp/abci_test.go +++ b/baseapp/abci_test.go @@ -48,7 +48,7 @@ func TestABCI_InitChain(t *testing.T) { name := t.Name() db := dbm.NewMemDB() logger := log.NewTestLogger(t) - app := baseapp.NewBaseApp(name, logger, db, nil) + app := baseapp.NewBaseApp(name, logger, db, nil, baseapp.SetChainID("test-chain-id")) capKey := storetypes.NewKVStoreKey("main") capKey2 := storetypes.NewKVStoreKey("key2") @@ -67,8 +67,13 @@ func TestABCI_InitChain(t *testing.T) { Data: key, } + // initChain is nil and chain ID is wrong - panics + require.Panics(t, func() { + app.InitChain(abci.RequestInitChain{ChainId: "wrong-chain-id"}) + }) + // initChain is nil - nothing happens - app.InitChain(abci.RequestInitChain{}) + app.InitChain(abci.RequestInitChain{ChainId: "test-chain-id"}) res := app.Query(query) require.Equal(t, 0, len(res.Value)) From be89d620d2eb881e4cf268aa1418c78c0e002a02 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Wed, 8 Mar 2023 16:41:36 -0300 Subject: [PATCH 12/23] fix leak --- server/start.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/server/start.go b/server/start.go index 99ed41532af4..9966d4383bd5 100644 --- a/server/start.go +++ b/server/start.go @@ -300,18 +300,22 @@ func startInProcess(svrCtx *Context, clientCtx client.Context, appCreator types. return err } - appGenesis, err := genutiltypes.AppGenesisFromFile(cfg.GenesisFile()) - if err != nil { - return err - } - genDocProvider := func() (*cmttypes.GenesisDoc, error) { + appGenesis, err := genutiltypes.AppGenesisFromFile(cfg.GenesisFile()) + if err != nil { + return nil, err + } + return appGenesis.ToGenesisDoc() } // If the chain ID is not set, use the one from the genesis file if !svrCtx.Viper.IsSet(flags.FlagChainID) { - svrCtx.Viper.Set(flags.FlagChainID, appGenesis.ChainID) + gen, err := genDocProvider() + if err != nil { + return err + } + svrCtx.Viper.Set(flags.FlagChainID, gen.ChainID) } app := appCreator(svrCtx.Logger, db, traceWriter, svrCtx.Viper) From 09ae43acf015ae25c4986a779e3f1e71eafdf2bc Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Thu, 9 Mar 2023 16:49:37 -0300 Subject: [PATCH 13/23] cl++ --- CHANGELOG.md | 1 + baseapp/abci.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 193dea1b302b..fad49583c534 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -151,6 +151,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes +* (baseapp) [#15303](https://github.com/cosmos/cosmos-sdk/pull/15303) Remove previous block data from context before PrepareProposal + add ChainID to baseapp in order to pass it in the context. * (x/auth) [#15059](https://github.com/cosmos/cosmos-sdk/pull/15059) `ante.CountSubKeys` returns 0 when passing a nil `Pubkey`. * (x/capability) [#15030](https://github.com/cosmos/cosmos-sdk/pull/15030) Prevent `x/capability` from consuming `GasMeter` gas during `InitMemStore` * [#14995](https://github.com/cosmos/cosmos-sdk/pull/14995) Allow unknown fields in `ParseTypedEvent`. diff --git a/baseapp/abci.go b/baseapp/abci.go index 1f4ea2a5928d..395b4324933c 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -982,7 +982,7 @@ func SplitABCIQueryPath(requestPath string) (path []string) { func (app *BaseApp) getContextForProposal(ctx sdk.Context, height int64) sdk.Context { if height == 1 { ctx, _ = app.deliverState.ctx.CacheContext() - // TODO: clear all context data set during InitChain to avoid inconsistent behavior + // clear all context data set during InitChain to avoid inconsistent behavior ctx = ctx.WithBlockHeader(cmtproto.Header{}) return ctx } From a578ddb7c78543163581d959883aedae5e24270f Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Thu, 9 Mar 2023 21:33:51 -0300 Subject: [PATCH 14/23] add some extra checks and fix context for prepare and process proposal --- baseapp/abci.go | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 395b4324933c..71dda168ca8f 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -163,6 +163,10 @@ func (app *BaseApp) FilterPeerByID(info string) abci.ResponseQuery { // BeginBlock implements the ABCI application interface. func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeginBlock) { + if req.Header.ChainID != app.chainID { + panic(fmt.Sprintf("ChainID on RequestInitChain {%s} does not match the app's ChainID {%s}", req.ChainId, app.chainID)) + } + if app.cms.TracingEnabled() { app.cms.SetTracingContext(storetypes.TraceContext( map[string]interface{}{"blockHeight": req.Header.Height}, @@ -273,15 +277,16 @@ func (app *BaseApp) PrepareProposal(req abci.RequestPrepareProposal) (resp abci. panic("PrepareProposal called with invalid height") } - gasMeter := app.getBlockGasMeter(app.prepareProposalState.ctx) - ctx := app.getContextForProposal(app.prepareProposalState.ctx, req.Height) - - ctx = ctx.WithVoteInfos(app.voteInfos). + app.prepareProposalState.ctx = app.getContextForProposal(app.prepareProposalState.ctx, req.Height). + WithVoteInfos(app.voteInfos). WithBlockHeight(req.Height). WithBlockTime(req.Time). - WithProposer(req.ProposerAddress). - WithConsensusParams(app.GetConsensusParams(ctx)). - WithBlockGasMeter(gasMeter) + WithProposer(req.ProposerAddress) + + // TODO: I think that if I chain these 2 setters they won't be getting the right ctx. Is this correct? + app.prepareProposalState.ctx = app.prepareProposalState.ctx. + WithConsensusParams(app.GetConsensusParams(app.prepareProposalState.ctx)). + WithBlockGasMeter(app.getBlockGasMeter(app.prepareProposalState.ctx)) defer func() { if err := recover(); err != nil { @@ -296,7 +301,7 @@ func (app *BaseApp) PrepareProposal(req abci.RequestPrepareProposal) (resp abci. } }() - resp = app.prepareProposal(ctx, req) + resp = app.prepareProposal(app.prepareProposalState.ctx, req) return resp } @@ -320,17 +325,16 @@ func (app *BaseApp) ProcessProposal(req abci.RequestProcessProposal) (resp abci. panic("app.ProcessProposal is not set") } - gasMeter := app.getBlockGasMeter(app.processProposalState.ctx) - ctx := app.getContextForProposal(app.processProposalState.ctx, req.Height) - - ctx = ctx. + app.processProposalState.ctx = app.getContextForProposal(app.processProposalState.ctx, req.Height). WithVoteInfos(app.voteInfos). WithBlockHeight(req.Height). WithBlockTime(req.Time). WithHeaderHash(req.Hash). - WithProposer(req.ProposerAddress). - WithConsensusParams(app.GetConsensusParams(ctx)). - WithBlockGasMeter(gasMeter) + WithProposer(req.ProposerAddress) + + app.processProposalState.ctx = app.processProposalState.ctx. + WithConsensusParams(app.GetConsensusParams(app.processProposalState.ctx)). + WithBlockGasMeter(app.getBlockGasMeter(app.processProposalState.ctx)) defer func() { if err := recover(); err != nil { @@ -345,7 +349,7 @@ func (app *BaseApp) ProcessProposal(req abci.RequestProcessProposal) (resp abci. } }() - resp = app.processProposal(ctx, req) + resp = app.processProposal(app.processProposalState.ctx, req) return resp } From 630175a510abd3e0200d2a073fde856fa0193947 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Thu, 9 Mar 2023 21:36:49 -0300 Subject: [PATCH 15/23] add some extra checks and fix context for prepare and process proposal --- baseapp/abci.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 71dda168ca8f..f78953b57b3f 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -164,7 +164,7 @@ func (app *BaseApp) FilterPeerByID(info string) abci.ResponseQuery { // BeginBlock implements the ABCI application interface. func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeginBlock) { if req.Header.ChainID != app.chainID { - panic(fmt.Sprintf("ChainID on RequestInitChain {%s} does not match the app's ChainID {%s}", req.ChainId, app.chainID)) + panic(fmt.Sprintf("ChainID on RequestBeginBlock {%s} does not match the app's ChainID {%s}", req.Header.ChainID, app.chainID)) } if app.cms.TracingEnabled() { From 950cd219c304295cc242977a37c7ce11b635e483 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Thu, 9 Mar 2023 21:40:27 -0300 Subject: [PATCH 16/23] fix comment --- baseapp/abci.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index f78953b57b3f..bda6442ee094 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -62,9 +62,10 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC app.setState(runTxModeDeliver, initHeader) app.setState(runTxModeCheck, initHeader) - // Use an empty header for prepare and process proposal states. Although it - // doesn't matter what header we use here as they get overwritten for the - // first block (see getContextForProposal()) and cleaned up on every Commit(). + // Use an empty header for prepare and process proposal states. The header + // will be overwritten for the first block (see getContextForProposal()) and + // cleaned up on every Commit(). Only the ChainID is needed so it's set in + // the context. emptyHeader := cmtproto.Header{ChainID: req.ChainId} app.setState(runTxPrepareProposal, emptyHeader) app.setState(runTxProcessProposal, emptyHeader) From 966dba8f2674c85ba2d77a74d485757171e9ee2b Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Thu, 9 Mar 2023 22:01:20 -0300 Subject: [PATCH 17/23] fix e2e test in params --- tests/e2e/params/suite.go | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/e2e/params/suite.go b/tests/e2e/params/suite.go index febf4c5ff1f8..0d4c05df0fb4 100644 --- a/tests/e2e/params/suite.go +++ b/tests/e2e/params/suite.go @@ -72,6 +72,7 @@ func (s *E2ETestSuite) SetupSuite() { nil, baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)), baseapp.SetMinGasPrices(val.GetAppConfig().MinGasPrices), + baseapp.SetChainID(s.cfg.ChainID), ) s.Require().NoError(app.Load(false)) From 820e34eb694296d56c52c6be417282621ab5f1c0 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Fri, 10 Mar 2023 10:26:08 -0300 Subject: [PATCH 18/23] rm comment --- baseapp/abci.go | 1 - 1 file changed, 1 deletion(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index bda6442ee094..a6379aa61c93 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -284,7 +284,6 @@ func (app *BaseApp) PrepareProposal(req abci.RequestPrepareProposal) (resp abci. WithBlockTime(req.Time). WithProposer(req.ProposerAddress) - // TODO: I think that if I chain these 2 setters they won't be getting the right ctx. Is this correct? app.prepareProposalState.ctx = app.prepareProposalState.ctx. WithConsensusParams(app.GetConsensusParams(app.prepareProposalState.ctx)). WithBlockGasMeter(app.getBlockGasMeter(app.prepareProposalState.ctx)) From b17f1789fa680f83aecda199be2f6b28206a0216 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 10 Mar 2023 14:50:46 +0100 Subject: [PATCH 19/23] attempt to simplify (#15348) --- client/pruning/main.go | 12 ------------ server/start.go | 33 +++++++-------------------------- server/util.go | 14 +++++++++++++- 3 files changed, 20 insertions(+), 39 deletions(-) diff --git a/client/pruning/main.go b/client/pruning/main.go index b81ed85f7646..b15094a50d54 100644 --- a/client/pruning/main.go +++ b/client/pruning/main.go @@ -15,7 +15,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server" servertypes "github.com/cosmos/cosmos-sdk/server/types" - genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) const FlagAppDBBackend = "app-db-backend" @@ -64,17 +63,6 @@ func Cmd(appCreator servertypes.AppCreator) *cobra.Command { logger := log.NewLogger(cmd.OutOrStdout()) - ctx := server.GetServerContextFromCmd(cmd) - appGenesis, err := genutiltypes.AppGenesisFromFile(ctx.Config.GenesisFile()) - if err != nil { - return err - } - - // If the chain ID is not set, use the one from the genesis file - if !vp.IsSet(flags.FlagChainID) { - vp.Set(flags.FlagChainID, appGenesis.ChainID) - } - app := appCreator(logger, db, nil, vp) cms := app.CommitMultiStore() diff --git a/server/start.go b/server/start.go index 9966d4383bd5..5469c1923cf0 100644 --- a/server/start.go +++ b/server/start.go @@ -214,16 +214,6 @@ func startStandAlone(svrCtx *Context, appCreator types.AppCreator) error { return err } - appGenesis, err := genutiltypes.AppGenesisFromFile(svrCtx.Config.GenesisFile()) - if err != nil { - return err - } - - // If the chain ID is not set, use the one from the genesis file - if !svrCtx.Viper.IsSet(flags.FlagChainID) { - svrCtx.Viper.Set(flags.FlagChainID, appGenesis.ChainID) - } - app := appCreator(svrCtx.Logger, db, traceWriter, svrCtx.Viper) config, err := serverconfig.GetConfig(svrCtx.Viper) @@ -300,6 +290,13 @@ func startInProcess(svrCtx *Context, clientCtx client.Context, appCreator types. return err } + app := appCreator(svrCtx.Logger, db, traceWriter, svrCtx.Viper) + + nodeKey, err := p2p.LoadOrGenNodeKey(cfg.NodeKeyFile()) + if err != nil { + return err + } + genDocProvider := func() (*cmttypes.GenesisDoc, error) { appGenesis, err := genutiltypes.AppGenesisFromFile(cfg.GenesisFile()) if err != nil { @@ -309,22 +306,6 @@ func startInProcess(svrCtx *Context, clientCtx client.Context, appCreator types. return appGenesis.ToGenesisDoc() } - // If the chain ID is not set, use the one from the genesis file - if !svrCtx.Viper.IsSet(flags.FlagChainID) { - gen, err := genDocProvider() - if err != nil { - return err - } - svrCtx.Viper.Set(flags.FlagChainID, gen.ChainID) - } - - app := appCreator(svrCtx.Logger, db, traceWriter, svrCtx.Viper) - - nodeKey, err := p2p.LoadOrGenNodeKey(cfg.NodeKeyFile()) - if err != nil { - return err - } - var ( tmNode *node.Node gRPCOnly = svrCtx.Viper.GetBool(flagGRPCOnly) diff --git a/server/util.go b/server/util.go index 01ac48d6c01e..7c0a7cbcde6f 100644 --- a/server/util.go +++ b/server/util.go @@ -38,6 +38,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/mempool" "github.com/cosmos/cosmos-sdk/version" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) // ServerContextKey defines the context key used to retrieve a server.Context from @@ -442,7 +443,18 @@ func DefaultBaseappOptions(appOpts types.AppOptions) []func(*baseapp.BaseApp) { panic(err) } - snapshotDir := filepath.Join(cast.ToString(appOpts.Get(flags.FlagHome)), "data", "snapshots") + homeDir := cast.ToString(appOpts.Get(flags.FlagHome)) + if chainID := cast.ToString(appOpts.Get(flags.FlagChainID)); chainID == "" { + // fallback to genesis chain-id + appGenesis, err := genutiltypes.AppGenesisFromFile(filepath.Join(homeDir, "config", "genesis.json")) + if err != nil { + panic(err) + } + + chainID = appGenesis.ChainID + } + + snapshotDir := filepath.Join(homeDir, "data", "snapshots") if err = os.MkdirAll(snapshotDir, os.ModePerm); err != nil { panic(fmt.Errorf("failed to create snapshots directory: %w", err)) } From 3f23381a560a9e65550dacd3ff284cc4cb1804ec Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Fri, 10 Mar 2023 10:52:29 -0300 Subject: [PATCH 20/23] fix --- server/util.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/util.go b/server/util.go index 7c0a7cbcde6f..bd530211b875 100644 --- a/server/util.go +++ b/server/util.go @@ -444,7 +444,8 @@ func DefaultBaseappOptions(appOpts types.AppOptions) []func(*baseapp.BaseApp) { } homeDir := cast.ToString(appOpts.Get(flags.FlagHome)) - if chainID := cast.ToString(appOpts.Get(flags.FlagChainID)); chainID == "" { + chainID := cast.ToString(appOpts.Get(flags.FlagChainID)) + if chainID == "" { // fallback to genesis chain-id appGenesis, err := genutiltypes.AppGenesisFromFile(filepath.Join(homeDir, "config", "genesis.json")) if err != nil { @@ -491,6 +492,6 @@ func DefaultBaseappOptions(appOpts types.AppOptions) []func(*baseapp.BaseApp) { ), ), baseapp.SetIAVLLazyLoading(cast.ToBool(appOpts.Get(FlagIAVLLazyLoading))), - baseapp.SetChainID(cast.ToString(appOpts.Get(flags.FlagChainID))), + baseapp.SetChainID(chainID), } } From 3bcaa1552900b6fe2e320dabafe76c172ebf1e00 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Fri, 10 Mar 2023 11:20:56 -0300 Subject: [PATCH 21/23] rollback rollback.go --- server/rollback.go | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/server/rollback.go b/server/rollback.go index 740d66193f8d..7152019c2b36 100644 --- a/server/rollback.go +++ b/server/rollback.go @@ -8,7 +8,6 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server/types" - genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) // NewRollbackCmd creates a command to rollback CometBFT and multistore state by one height. @@ -35,16 +34,6 @@ application. return err } - appGenesis, err := genutiltypes.AppGenesisFromFile(cfg.GenesisFile()) - if err != nil { - return err - } - - // If the chain ID is not set, use the one from the genesis file - if !ctx.Viper.IsSet(flags.FlagChainID) { - ctx.Viper.Set(flags.FlagChainID, appGenesis.ChainID) - } - app := appCreator(ctx.Logger, db, nil, ctx.Viper) // rollback CometBFT state height, hash, err := cmtcmd.RollbackState(ctx.Config, removeBlock) From 52a64aa9f5a6de16b2a8d6065c2f410bcccbc48f Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Fri, 10 Mar 2023 16:59:35 -0300 Subject: [PATCH 22/23] suggestions from @alexanderbez --- CHANGELOG.md | 1 - baseapp/abci.go | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4ee6eb88fd1..534e4bc6cbf4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -148,7 +148,6 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes -* (baseapp) [#15303](https://github.com/cosmos/cosmos-sdk/pull/15303) Remove previous block data from context before PrepareProposal + add ChainID to baseapp in order to pass it in the context. * (x/auth) [#15059](https://github.com/cosmos/cosmos-sdk/pull/15059) `ante.CountSubKeys` returns 0 when passing a nil `Pubkey`. * (x/capability) [#15030](https://github.com/cosmos/cosmos-sdk/pull/15030) Prevent `x/capability` from consuming `GasMeter` gas during `InitMemStore` * [#14995](https://github.com/cosmos/cosmos-sdk/pull/14995) Allow unknown fields in `ParseTypedEvent`. diff --git a/baseapp/abci.go b/baseapp/abci.go index a6379aa61c93..b0de6ce94244 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -38,7 +38,7 @@ const ( // directly on the CommitMultiStore. func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitChain) { if req.ChainId != app.chainID { - panic(fmt.Sprintf("ChainID on RequestInitChain {%s} does not match the app's ChainID {%s}", req.ChainId, app.chainID)) + panic(fmt.Sprintf("invalid chain-id on InitChain; expected: %s, got: %s", app.chainID, req.ChainId)) } // On a new chain, we consider the init chain block height as 0, even though @@ -165,7 +165,7 @@ func (app *BaseApp) FilterPeerByID(info string) abci.ResponseQuery { // BeginBlock implements the ABCI application interface. func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeginBlock) { if req.Header.ChainID != app.chainID { - panic(fmt.Sprintf("ChainID on RequestBeginBlock {%s} does not match the app's ChainID {%s}", req.Header.ChainID, app.chainID)) + panic(fmt.Sprintf("invalid chain-id on BeginBlock; expected: %s, got: %s", app.chainID, req.Header.ChainID)) } if app.cms.TracingEnabled() { From f307b3bb16b00f7f83dbdec50e0d147c5fc7fb9a Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Mon, 13 Mar 2023 10:45:48 -0300 Subject: [PATCH 23/23] remove some unnecessary changes, like new lines --- client/pruning/main.go | 1 - server/rollback.go | 1 - 2 files changed, 2 deletions(-) diff --git a/client/pruning/main.go b/client/pruning/main.go index b15094a50d54..462d6d944c83 100644 --- a/client/pruning/main.go +++ b/client/pruning/main.go @@ -62,7 +62,6 @@ func Cmd(appCreator servertypes.AppCreator) *cobra.Command { } logger := log.NewLogger(cmd.OutOrStdout()) - app := appCreator(logger, db, nil, vp) cms := app.CommitMultiStore() diff --git a/server/rollback.go b/server/rollback.go index 7152019c2b36..ccd7e3213902 100644 --- a/server/rollback.go +++ b/server/rollback.go @@ -33,7 +33,6 @@ application. if err != nil { return err } - app := appCreator(ctx.Logger, db, nil, ctx.Viper) // rollback CometBFT state height, hash, err := cmtcmd.RollbackState(ctx.Config, removeBlock)