From 40616a39fbbbe2e9d67bb68a399fbd5e7faa24d5 Mon Sep 17 00:00:00 2001 From: Facundo Medica <14063057+facundomedica@users.noreply.github.com> Date: Mon, 13 Mar 2023 14:15:39 -0300 Subject: [PATCH 1/7] fix: remove previous header in Prepare/Process Proposal + provide chain id in baseapp + fix context for verifying txs (#15303) ## Description ### Issue Some values (like chain ID) were being leaked from the previous block/initialization into PrepareProposal and ProcessProposal, these values are only available if: 1. The node has never been stopped since the genesis block (as these values are set on `InitChain`) 2. The node has already commited a block (as the previous header was being used for the new state of prepare and process proposal). So if a node is restarted, during the first prepare and process proposal these values won't be populated, and that will cause issues if they are being used. ### Solution Remove any previous header information from a previous block in the prepare and process proposal contexts, making things consistent at every height. - Added ChainID to baseapp - Use an empty header in Commit() with only the chain id set - Fix context for prepare and process proposal Closes: #15269 --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable) (cherry picked from commit 6a0358607411cd83d22c6f1deea69f399f803007) # Conflicts: # baseapp/abci_test.go # baseapp/baseapp.go # server/rollback.go # testutil/network/network.go --- baseapp/abci.go | 59 ++++++++++++++++++++++++------------- baseapp/abci_test.go | 12 +++++++- baseapp/baseapp.go | 10 +++++++ baseapp/options.go | 5 ++++ server/rollback.go | 7 ++++- server/util.go | 16 +++++++++- simapp/sim_test.go | 12 ++++---- simapp/test_helpers.go | 1 + tests/e2e/params/suite.go | 1 + testutil/network/network.go | 9 ++++++ 10 files changed, 103 insertions(+), 29 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index fb9ed37dd257..1b115b0b3235 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -34,6 +34,10 @@ 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("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 // req.InitialHeight is 1 by default. initHeader := tmproto.Header{ChainID: req.ChainId, Time: req.Time} @@ -54,8 +58,14 @@ 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. 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) // 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 @@ -148,6 +158,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("invalid chain-id on BeginBlock; expected: %s, got: %s", app.chainID, req.Header.ChainID)) + } + if app.cms.TracingEnabled() { app.cms.SetTracingContext(sdk.TraceContext( map[string]interface{}{"blockHeight": req.Header.Height}, @@ -250,15 +264,15 @@ 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) + + 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 { @@ -273,7 +287,7 @@ func (app *BaseApp) PrepareProposal(req abci.RequestPrepareProposal) (resp abci. } }() - resp = app.prepareProposal(ctx, req) + resp = app.prepareProposal(app.prepareProposalState.ctx, req) return resp } @@ -297,17 +311,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 { @@ -322,7 +335,7 @@ func (app *BaseApp) ProcessProposal(req abci.RequestProcessProposal) (resp abci. } }() - resp = app.processProposal(ctx, req) + resp = app.processProposal(app.processProposalState.ctx, req) return resp } @@ -436,8 +449,12 @@ func (app *BaseApp) Commit() abci.ResponseCommit { // NOTE: This is safe because Tendermint 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{ChainID: app.chainID} + app.setState(runTxPrepareProposal, emptyHeader) + app.setState(runTxProcessProposal, emptyHeader) // empty/reset the deliver state app.deliverState = nil @@ -955,6 +972,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() + // clear all context data set during InitChain to avoid inconsistent behavior + ctx = ctx.WithBlockHeader(cmtproto.Header{}) return ctx } return ctx diff --git a/baseapp/abci_test.go b/baseapp/abci_test.go index d2aee6d44247..8587044911cd 100644 --- a/baseapp/abci_test.go +++ b/baseapp/abci_test.go @@ -42,8 +42,13 @@ func TestABCI_Info(t *testing.T) { func TestABCI_InitChain(t *testing.T) { name := t.Name() db := dbm.NewMemDB() +<<<<<<< HEAD logger := defaultLogger() app := baseapp.NewBaseApp(name, logger, db, nil) +======= + logger := log.NewTestLogger(t) + app := baseapp.NewBaseApp(name, logger, db, nil, baseapp.SetChainID("test-chain-id")) +>>>>>>> 6a0358607 (fix: remove previous header in Prepare/Process Proposal + provide chain id in baseapp + fix context for verifying txs (#15303)) capKey := sdk.NewKVStoreKey("main") capKey2 := sdk.NewKVStoreKey("key2") @@ -62,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)) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 7f70a0d832e3..7da45a0c72b1 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -141,7 +141,13 @@ 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 +<<<<<<< HEAD abciListeners []ABCIListener +======= + abciListeners []storetypes.ABCIListener + + chainID string +>>>>>>> 6a0358607 (fix: remove previous header in Prepare/Process Proposal + provide chain id in baseapp + fix context for verifying txs (#15303)) } // NewBaseApp returns a reference to an initialized BaseApp. It accepts a @@ -349,7 +355,11 @@ func (app *BaseApp) Init() error { panic("cannot call initFromMainStore: baseapp already sealed") } +<<<<<<< HEAD emptyHeader := tmproto.Header{} +======= + emptyHeader := cmtproto.Header{ChainID: app.chainID} +>>>>>>> 6a0358607 (fix: remove previous header in Prepare/Process Proposal + provide chain id in baseapp + fix context for verifying txs (#15303)) // needed for the export command which inits from store but never calls initchain app.setState(runTxModeCheck, emptyHeader) diff --git a/baseapp/options.go b/baseapp/options.go index c3ba9f64960e..e669495f647d 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -91,6 +91,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/server/rollback.go b/server/rollback.go index 87196b9937ef..b266a2a408b5 100644 --- a/server/rollback.go +++ b/server/rollback.go @@ -3,10 +3,15 @@ package server import ( "fmt" +<<<<<<< HEAD tmcmd "github.com/cometbft/cometbft/cmd/cometbft/commands" +======= + cmtcmd "github.com/cometbft/cometbft/cmd/cometbft/commands" + "github.com/spf13/cobra" + +>>>>>>> 6a0358607 (fix: remove previous header in Prepare/Process Proposal + provide chain id in baseapp + fix context for verifying txs (#15303)) "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server/types" - "github.com/spf13/cobra" ) // NewRollbackCmd creates a command to rollback tendermint and multistore state by one height. diff --git a/server/util.go b/server/util.go index 25b6f2010ecb..a319ba2c3198 100644 --- a/server/util.go +++ b/server/util.go @@ -35,6 +35,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" ) // DONTCOVER @@ -435,7 +436,19 @@ 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)) + 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 { + 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)) } @@ -472,5 +485,6 @@ func DefaultBaseappOptions(appOpts types.AppOptions) []func(*baseapp.BaseApp) { ), ), baseapp.SetIAVLLazyLoading(cast.ToBool(appOpts.Get(FlagIAVLLazyLoading))), + baseapp.SetChainID(chainID), } } diff --git a/simapp/sim_test.go b/simapp/sim_test.go index 32ee379a208b..ce9d5374a53e 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -84,7 +84,7 @@ func TestFullAppSimulation(t *testing.T) { appOptions[flags.FlagHome] = DefaultNodeHome appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue - 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 @@ -129,7 +129,7 @@ func TestAppImportExport(t *testing.T) { appOptions[flags.FlagHome] = DefaultNodeHome appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue - 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 @@ -169,7 +169,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 @@ -245,7 +245,7 @@ func TestAppSimulationAfterImport(t *testing.T) { appOptions[flags.FlagHome] = DefaultNodeHome appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue - 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 @@ -290,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{ @@ -345,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", diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index dfa0aa4ec3e9..de9cc9cd919a 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().Viper.GetString(flags.FlagChainID)), ) } diff --git a/tests/e2e/params/suite.go b/tests/e2e/params/suite.go index bbb018f80259..bd4f45c94f2d 100644 --- a/tests/e2e/params/suite.go +++ b/tests/e2e/params/suite.go @@ -71,6 +71,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)) diff --git a/testutil/network/network.go b/testutil/network/network.go index 517151de9016..f8ef3346f870 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -30,6 +30,11 @@ import ( "cosmossdk.io/depinject" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" +<<<<<<< HEAD +======= + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/grpc/cmtservice" +>>>>>>> 6a0358607 (fix: remove previous header in Prepare/Process Proposal + provide chain id in baseapp + fix context for verifying txs (#15303)) "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -184,6 +189,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{}) @@ -546,6 +552,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 0ae0efad79dc7ba445fdb0a593ac67d17f697668 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Mon, 13 Mar 2023 14:51:21 -0300 Subject: [PATCH 2/7] fix conflicts --- baseapp/abci_test.go | 6 +----- baseapp/baseapp.go | 15 ++++----------- server/rollback.go | 4 ---- testutil/network/network.go | 6 ++---- 4 files changed, 7 insertions(+), 24 deletions(-) diff --git a/baseapp/abci_test.go b/baseapp/abci_test.go index 8587044911cd..7c9e88f317c9 100644 --- a/baseapp/abci_test.go +++ b/baseapp/abci_test.go @@ -7,6 +7,7 @@ import ( "strings" "testing" + "cosmossdk.io/log" dbm "github.com/cometbft/cometbft-db" abci "github.com/cometbft/cometbft/abci/types" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" @@ -42,13 +43,8 @@ func TestABCI_Info(t *testing.T) { func TestABCI_InitChain(t *testing.T) { name := t.Name() db := dbm.NewMemDB() -<<<<<<< HEAD - logger := defaultLogger() - app := baseapp.NewBaseApp(name, logger, db, nil) -======= logger := log.NewTestLogger(t) app := baseapp.NewBaseApp(name, logger, db, nil, baseapp.SetChainID("test-chain-id")) ->>>>>>> 6a0358607 (fix: remove previous header in Prepare/Process Proposal + provide chain id in baseapp + fix context for verifying txs (#15303)) capKey := sdk.NewKVStoreKey("main") capKey2 := sdk.NewKVStoreKey("key2") diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 7da45a0c72b1..605c36c5c7f5 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -11,6 +11,9 @@ import ( "github.com/cometbft/cometbft/crypto/tmhash" "github.com/cometbft/cometbft/libs/log" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/cosmos/gogoproto/proto" + "golang.org/x/exp/maps" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/snapshots" "github.com/cosmos/cosmos-sdk/store" @@ -19,8 +22,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/mempool" - "github.com/cosmos/gogoproto/proto" - "golang.org/x/exp/maps" ) type ( @@ -141,13 +142,9 @@ 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 -<<<<<<< HEAD abciListeners []ABCIListener -======= - abciListeners []storetypes.ABCIListener chainID string ->>>>>>> 6a0358607 (fix: remove previous header in Prepare/Process Proposal + provide chain id in baseapp + fix context for verifying txs (#15303)) } // NewBaseApp returns a reference to an initialized BaseApp. It accepts a @@ -355,11 +352,7 @@ func (app *BaseApp) Init() error { panic("cannot call initFromMainStore: baseapp already sealed") } -<<<<<<< HEAD - emptyHeader := tmproto.Header{} -======= - emptyHeader := cmtproto.Header{ChainID: app.chainID} ->>>>>>> 6a0358607 (fix: remove previous header in Prepare/Process Proposal + provide chain id in baseapp + fix context for verifying txs (#15303)) + emptyHeader := tmproto.Header{ChainID: app.chainID} // needed for the export command which inits from store but never calls initchain app.setState(runTxModeCheck, emptyHeader) diff --git a/server/rollback.go b/server/rollback.go index b266a2a408b5..ae2a7e0a08eb 100644 --- a/server/rollback.go +++ b/server/rollback.go @@ -3,13 +3,9 @@ package server import ( "fmt" -<<<<<<< HEAD tmcmd "github.com/cometbft/cometbft/cmd/cometbft/commands" -======= - cmtcmd "github.com/cometbft/cometbft/cmd/cometbft/commands" "github.com/spf13/cobra" ->>>>>>> 6a0358607 (fix: remove previous header in Prepare/Process Proposal + provide chain id in baseapp + fix context for verifying txs (#15303)) "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server/types" ) diff --git a/testutil/network/network.go b/testutil/network/network.go index f8ef3346f870..d6e1691a31ad 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -24,17 +24,15 @@ import ( "cosmossdk.io/math" tmlog "github.com/cometbft/cometbft/libs/log" + "github.com/cosmos/cosmos-sdk/testutil/configurator" "github.com/cosmos/cosmos-sdk/testutil/testdata" "cosmossdk.io/depinject" + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client" -<<<<<<< HEAD -======= "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/client/grpc/cmtservice" ->>>>>>> 6a0358607 (fix: remove previous header in Prepare/Process Proposal + provide chain id in baseapp + fix context for verifying txs (#15303)) "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" From 08e0b98acbead2548eb468bf44697e879bb01a78 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Mon, 13 Mar 2023 15:07:16 -0300 Subject: [PATCH 3/7] fix --- baseapp/abci.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index 1b115b0b3235..33b675fa4488 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -63,7 +63,7 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC // 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} + emptyHeader := tmproto.Header{ChainID: req.ChainId} app.setState(runTxPrepareProposal, emptyHeader) app.setState(runTxProcessProposal, emptyHeader) @@ -452,7 +452,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{ChainID: app.chainID} + emptyHeader := tmproto.Header{ChainID: app.chainID} app.setState(runTxPrepareProposal, emptyHeader) app.setState(runTxProcessProposal, emptyHeader) @@ -973,7 +973,7 @@ func (app *BaseApp) getContextForProposal(ctx sdk.Context, height int64) sdk.Con if height == 1 { ctx, _ = app.deliverState.ctx.CacheContext() // clear all context data set during InitChain to avoid inconsistent behavior - ctx = ctx.WithBlockHeader(cmtproto.Header{}) + ctx = ctx.WithBlockHeader(tmproto.Header{}) return ctx } return ctx From 10fbd46fae27d41b6875b4bcccedd003d626365a Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Mon, 13 Mar 2023 15:11:26 -0300 Subject: [PATCH 4/7] fix --- server/util.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/util.go b/server/util.go index a319ba2c3198..33262096da8d 100644 --- a/server/util.go +++ b/server/util.go @@ -20,6 +20,7 @@ import ( tmcli "github.com/cometbft/cometbft/libs/cli" tmflags "github.com/cometbft/cometbft/libs/cli/flags" tmlog "github.com/cometbft/cometbft/libs/log" + tmtypes "github.com/cometbft/cometbft/types" "github.com/spf13/cast" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -35,7 +36,6 @@ 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" ) // DONTCOVER @@ -440,7 +440,7 @@ func DefaultBaseappOptions(appOpts types.AppOptions) []func(*baseapp.BaseApp) { chainID := cast.ToString(appOpts.Get(flags.FlagChainID)) if chainID == "" { // fallback to genesis chain-id - appGenesis, err := genutiltypes.AppGenesisFromFile(filepath.Join(homeDir, "config", "genesis.json")) + appGenesis, err := tmtypes.GenesisDocFromFile(filepath.Join(homeDir, "config", "genesis.json")) if err != nil { panic(err) } From 304b462396048e8c95b457e863798e1b5935118a Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Mon, 13 Mar 2023 15:15:24 -0300 Subject: [PATCH 5/7] remove logger thingy --- baseapp/abci_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/baseapp/abci_test.go b/baseapp/abci_test.go index 7c9e88f317c9..0d7bc456af2f 100644 --- a/baseapp/abci_test.go +++ b/baseapp/abci_test.go @@ -7,7 +7,6 @@ import ( "strings" "testing" - "cosmossdk.io/log" dbm "github.com/cometbft/cometbft-db" abci "github.com/cometbft/cometbft/abci/types" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" @@ -43,7 +42,7 @@ func TestABCI_Info(t *testing.T) { func TestABCI_InitChain(t *testing.T) { name := t.Name() db := dbm.NewMemDB() - logger := log.NewTestLogger(t) + logger := defaultLogger() app := baseapp.NewBaseApp(name, logger, db, nil, baseapp.SetChainID("test-chain-id")) capKey := sdk.NewKVStoreKey("main") From f028809fef7263fbb38ef1de785304fe16cc6667 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Mon, 13 Mar 2023 15:40:53 -0300 Subject: [PATCH 6/7] fix integration test --- tests/integration/gov/module_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/integration/gov/module_test.go b/tests/integration/gov/module_test.go index f7216d34dedd..ef11534151b6 100644 --- a/tests/integration/gov/module_test.go +++ b/tests/integration/gov/module_test.go @@ -11,6 +11,8 @@ import ( "github.com/stretchr/testify/require" "cosmossdk.io/simapp" + + "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/server" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -25,7 +27,7 @@ func TestItCreatesModuleAccountOnInitBlock(t *testing.T) { appOptions[flags.FlagHome] = simapp.DefaultNodeHome appOptions[server.FlagInvCheckPeriod] = 5 - app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, appOptions) + app := simapp.NewSimApp(log.NewNopLogger(), db, nil, true, appOptions, baseapp.SetChainID("test-chain-id")) genesisState := simapp.GenesisStateWithSingleValidator(t, app) stateBytes, err := tmjson.Marshal(genesisState) From c0f1f61933191b2d6f747d20f6e70bf6815c92bd Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Mon, 13 Mar 2023 15:42:09 -0300 Subject: [PATCH 7/7] fix sims --- simapp/sim_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/simapp/sim_test.go b/simapp/sim_test.go index ce9d5374a53e..5f9c3ca12eab 100644 --- a/simapp/sim_test.go +++ b/simapp/sim_test.go @@ -294,6 +294,7 @@ func TestAppSimulationAfterImport(t *testing.T) { require.Equal(t, "SimApp", newApp.Name()) newApp.InitChain(abci.RequestInitChain{ + ChainId: SimAppChainID, AppStateBytes: exported.AppState, })