fix(baseapp): fix BaseApp.getContext data races (#18383)

This commit is contained in:
Emmanuel T Odeke
2023-11-07 10:16:55 +00:00
committed by GitHub
parent 7e002550cc
commit c1b391631c
3 changed files with 7 additions and 1 deletions
+1
View File
@@ -72,6 +72,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Bug Fixes
* (baseapp) [#18383](https://github.com/cosmos/cosmos-sdk/pull/18383) Fixed a data race inside BaseApp.getContext, found by end-to-end (e2e) tests.
* (client/server) [#18345](https://github.com/cosmos/cosmos-sdk/pull/18345) Consistently set viper prefix in client and server. It defaults for the binary name for both client and server.
* (server) [#18254](https://github.com/cosmos/cosmos-sdk/pull/18254) Don't hardcode gRPC address to localhost.
* (x/slashing) [#18016](https://github.com/cosmos/cosmos-sdk/pull/18016) Fixed builder function for missed blocks key (`validatorMissedBlockBitArrayPrefixKey`) in slashing/migration/v4
+5
View File
@@ -6,6 +6,7 @@ import (
"math"
"sort"
"strconv"
"sync"
"github.com/cockroachdb/errors"
abci "github.com/cometbft/cometbft/abci/types"
@@ -59,6 +60,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
@@ -641,6 +643,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))
+1 -1
View File
@@ -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 {