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

Co-authored-by: Alex | Interchain Labs <alex@interchainlabs.io>
Co-authored-by: Tyler <48813565+technicallyty@users.noreply.github.com>
This commit is contained in:
Hoang Do
2025-03-19 16:15:42 -04:00
committed by GitHub
co-authored by Alex | Interchain Labs Tyler
parent 6577e1eeef
commit ba35a41fdd
3 changed files with 7 additions and 1 deletions
+5
View File
@@ -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))
+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 {