diff --git a/CHANGELOG.md b/CHANGELOG.md index 64d777e01b..fdc9326206 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes +* (baseapp) [#24042](https://github.com/cosmos/cosmos-sdk/pull/24042) Fixed a data race inside BaseApp.getContext, found by end-to-end (e2e) tests. * (client/server) [#24059](https://github.com/cosmos/cosmos-sdk/pull/24059) Consistently set viper prefix in client and server. It defaults for the binary name for both client and server. * (client/keys) [#24041](https://github.com/cosmos/cosmos-sdk/pull/24041) `keys delete` won't terminate when a key is not found, but will log the error. * (baseapp) [#24027](https://github.com/cosmos/cosmos-sdk/pull/24027) Ensure that `BaseApp.Init` checks that the commit multistore is set to protect against nil dereferences. diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 45b80904c0..02f55de411 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -7,6 +7,7 @@ import ( "math" "slices" "strconv" + "sync" "github.com/cockroachdb/errors" abci "github.com/cometbft/cometbft/abci/types" @@ -61,6 +62,7 @@ var _ servertypes.ABCI = (*BaseApp)(nil) // BaseApp reflects the ABCI application implementation. type BaseApp struct { // initialized on creation + mu sync.Mutex // mu protects the fields below. logger log.Logger name string // application name from abci.BlockInfo db dbm.DB // common DB backend @@ -659,6 +661,9 @@ func (app *BaseApp) getBlockGasMeter(ctx sdk.Context) storetypes.GasMeter { // retrieve the context for the tx w/ txBytes and other memoized values. func (app *BaseApp) getContextForTx(mode execMode, txBytes []byte) sdk.Context { + app.mu.Lock() + defer app.mu.Unlock() + modeState := app.getState(mode) if modeState == nil { panic(fmt.Sprintf("state is nil for mode %v", mode)) diff --git a/baseapp/genesis.go b/baseapp/genesis.go index 4a6b0082b6..4662d1187b 100644 --- a/baseapp/genesis.go +++ b/baseapp/genesis.go @@ -12,7 +12,7 @@ var _ genesis.TxHandler = (*BaseApp)(nil) // ExecuteGenesisTx implements genesis.GenesisState from // cosmossdk.io/core/genesis to set initial state in genesis -func (ba BaseApp) ExecuteGenesisTx(tx []byte) error { +func (ba *BaseApp) ExecuteGenesisTx(tx []byte) error { res := ba.deliverTx(tx) if res.Code != types.CodeTypeOK {